about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorarg@10ksloc.org <unknown>2006-08-03 12:12:26 +0200
committerarg@10ksloc.org <unknown>2006-08-03 12:12:26 +0200
commitb35575574be53a1b3be42d7037d2f432a19a3890 (patch)
tree6be2344c68ec6590fa816bbd578e0f36fe21c0b8
parent666b4563a0064dd7aa27159813124837d306f81c (diff)
downloaddwm-b35575574be53a1b3be42d7037d2f432a19a3890.tar.gz
removed TLast tag enum, now tags is simple defined as char *[] array, the rest is calculated correctly, rules take an int array for the tags
-rw-r--r--client.c4
-rw-r--r--config.arg.h52
-rw-r--r--config.default.h48
-rw-r--r--draw.c4
-rw-r--r--dwm.h5
-rw-r--r--event.c2
-rw-r--r--main.c3
-rw-r--r--tag.c19
8 files changed, 66 insertions, 71 deletions
diff --git a/client.c b/client.c
index f4ed1a0..91d031e 100644
--- a/client.c
+++ b/client.c
@@ -16,7 +16,7 @@ resizetitle(Client *c)
 	int i;
 
 	c->tw = 0;
-	for(i = 0; i < TLast; i++)
+	for(i = 0; i < ntags; i++)
 		if(c->tags[i])
 			c->tw += textw(tags[i]);
 	c->tw += textw(c->name);
@@ -211,6 +211,7 @@ manage(Window w, XWindowAttributes *wa)
 	XSetWindowAttributes twa;
 
 	c = emallocz(sizeof(Client));
+	c->tags = emallocz(ntags * sizeof(Bool));
 	c->win = w;
 	c->x = c->tx = wa->x;
 	c->y = c->ty = wa->y;
@@ -429,6 +430,7 @@ unmanage(Client *c)
 		if(!sel)
 			sel = clients;
 	}
+	free(c->tags);
 	free(c);
 
 	XSync(dpy, False);
diff --git a/config.arg.h b/config.arg.h
index a3d312c..00a1d13 100644
--- a/config.arg.h
+++ b/config.arg.h
@@ -3,18 +3,11 @@
  * See LICENSE file for license details.
  */
 
-enum { Tfnord, Tdev, Tnet, Twork, Tmisc, TLast };
 #define TAGS \
-const char *tags[TLast] = { \
-	[Tfnord] = "fnord", \
-	[Tdev] = "dev", \
-	[Tnet] = "net", \
-	[Twork] = "work", \
-	[Tmisc] = "misc", \
-};
+const char *tags[] = { "fnord", "dev", "net", "work", "misc", NULL };
 
 #define DEFMODE			dotile /* dofloat */
-#define DEFTAG			Tdev
+#define DEFTAG			1 /* index */
 #define FONT			"-*-terminus-medium-*-*-*-13-*-*-*-*-*-iso10646-*"
 #define BGCOLOR			"#0a2c2d"
 #define FGCOLORs="p">)

func init() {
	register("save", Save)
}

func Save(aerc *widgets.Aerc, args []string) error {
	if len(args) < 2 {
		return errors.New("Usage: :save <path>")
	}

	mv := aerc.SelectedTab().(*widgets.MessageViewer)
	p := mv.CurrentPart()

	p.Store.FetchBodyPart(p.Msg.Uid, p.Index, func(reader io.Reader) {
		// email parts are encoded as 7bit (plaintext), quoted-printable, or base64
		switch p.Part.Encoding {
		case "base64":
			reader = base64.NewDecoder(base64.StdEncoding, reader)
		case "quoted-printable":
			reader = quotedprintable.NewReader(reader)
		}

		target, err := homedir.Expand(args[1])
		if err != nil {
			aerc.PushError(" " + err.Error())
			return
		}

		f, err := os.Create(target)
		if err != nil {
			aerc.PushError(" " + err.Error())
			return
		}
		defer f.Close()

		_, err = io.Copy(f, reader)
		if err != nil {
			aerc.PushError(" " + err.Error())
			return
		}

		aerc.PushStatus("Saved to "+target, 10*time.Second)
	})

	return nil
}
DKEY|ShiftMask, XK_1, replacetag, { .i = 1 } }, \ + { MODKEY|ShiftMask, XK_2, replacetag, { .i = 2 } }, \ + { MODKEY|ShiftMask, XK_3, replacetag, { .i = 3 } }, \ + { MODKEY|ShiftMask, XK_4, replacetag, { .i = 4 } }, \ { MODKEY|ShiftMask, XK_c, killclient, { 0 } }, \ { MODKEY|ShiftMask, XK_q, quit, { 0 } }, \ { MODKEY|ShiftMask, XK_Return, spawn, { .argv = term } }, \ }; #define RULES \ + const unsigned int firefox[] = { 2 }; \ static Rule rule[] = { \ - /* class:instance tags isfloat */ \ - { "Firefox.*", { [Tnet] = True }, False }, \ - { "Gimp.*", { 0 }, True}, \ + /* class:instance tags isfloat */ \ + { "Firefox.*", firefox, False }, \ + { "Gimp.*", NULL, True}, \ }; diff --git a/draw.c b/draw.c index 506a862..dffb490 100644 --- a/draw.c +++ b/draw.c @@ -114,7 +114,7 @@ drawstatus() drawtext(NULL, !istile, False); dc.w = 0; - for(i = 0; i < TLast; i++) { + for(i = 0; i < ntags; i++) { dc.x += dc.w; dc.w = textw(tags[i]); if(istile) @@ -153,7 +153,7 @@ drawtitle(Client *c) dc.x = dc.y = 0; dc.w = 0; - for(i = 0; i < TLast; i++) { + for(i = 0; i < ntags; i++) { if(c->tags[i]) { dc.x += dc.w; dc.w = textw(tags[i]); diff --git a/dwm.h b/dwm.h index c44da29..25971ac 100644 --- a/dwm.h +++ b/dwm.h @@ -60,16 +60,17 @@ struct Client { unsigned int border; Bool isfloat; Bool ismax; - Bool tags[TLast]; + Bool *tags; Client *next; Client *prev; Window win; Window title; }; -extern const char *tags[TLast]; +extern const char *tags[]; extern char stext[1024]; extern int tsel, screen, sx, sy, sw, sh, bx, by, bw, bh, mw; +extern unsigned int ntags; extern void (*handler[LASTEvent])(XEvent *); extern void (*arrange)(Arg *); extern Atom wmatom[WMLast], netatom[NetLast]; diff --git a/event.c b/event.c index 0c159c7..88e1b10 100644 --- a/event.c +++ b/event.c @@ -105,7 +105,7 @@ buttonpress(XEvent *e) switch(ev->button) { default: x = 0; - for(a.i = 0; a.i < TLast; a.i++) { + for(a.i = 0; a.i < ntags; a.i++) { x += textw(tags[a.i]); if(ev->x < x) { view(&a); diff --git a/main.c b/main.c index 33a2a9a..9ea09bf 100644 --- a/main.c +++ b/main.c @@ -85,6 +85,7 @@ xerrorstart(Display *dsply, XErrorEvent *ee) char stext[1024]; int tsel = DEFTAG; int screen, sx, sy, sw, sh, bx, by, bw, bh, mw; +unsigned int ntags; Atom wmatom[WMLast], netatom[NetLast]; Bool running = True; Bool issel = True; @@ -210,6 +211,8 @@ main(int argc, char *argv[]) grabkeys(); + for(ntags = 0; tags[ntags]; ntags++); + /* style */ dc.bg = getcolor(BGCOLOR); dc.fg = getcolor(FGCOLOR); diff --git a/tag.c b/tag.c index 9022371..b20e71e 100644 --- a/tag.c +++ b/tag.c @@ -13,7 +13,7 @@ typedef struct { const char *pattern; - Bool tags[TLast]; + const unsigned int *tags; Bool isfloat; } Rule; @@ -145,7 +145,7 @@ replacetag(Arg *arg) if(!sel) return; - for(i = 0; i < TLast; i++) + for(i = 0; i < ntags; i++) sel->tags[i] = False; appendtag(arg); } @@ -155,7 +155,7 @@ settags(Client *c) { char classinst[256]; static unsigned int len = sizeof(rule) / sizeof(rule[0]); - unsigned int i, j; + unsigned int i, j, n; regex_t regex; regmatch_t tmp; Bool matched = False; @@ -168,10 +168,11 @@ settags(Client *c) for(i = 0; !matched && i < len; i++) { if(!regcomp(&regex, rule[i].pattern, 0)) { if(!regexec(&regex, classinst, 1, &tmp, 0)) { - for(j = 0; j < TLast; j++) { - if((c->tags[j] = rule[i].tags[j])) - matched = True; - } + n = rule[i].tags ? + sizeof(rule[i].tags) / sizeof(rule[i].tags[0]) : 0; + matched = n != 0; + for(j = 0; j < n; j++) + c->tags[rule[i].tags[j]] = True; c->isfloat = rule[i].isfloat; } regfree(&regex); @@ -204,13 +205,13 @@ view(Arg *arg) void viewnext(Arg *arg) { - arg->i = (tsel < TLast-1) ? tsel+1 : 0; + arg->i = (tsel < ntags-1) ? tsel+1 : 0; view(arg); } void viewprev(Arg *arg) { - arg->i = (tsel > 0) ? tsel-1 : TLast-1; + arg->i = (tsel > 0) ? tsel-1 : ntags-1; view(arg); }