X-Git-Url: https://git.xinqibao.xyz/dwm.git/blobdiff_plain/e6ede461a97fccf00411d581cdd93158b73cd97d..5a3a2d6b637a41125f9128722aa9cb4c8c97888b:/dwm.c?ds=sidebyside

diff --git a/dwm.c b/dwm.c
index 053984d..ed7fc0d 100644
--- a/dwm.c
+++ b/dwm.c
@@ -178,6 +178,7 @@ void scan(void);
 void setclientstate(Client *c, long state);
 void setgeom(const char *arg);
 void setlayout(const char *arg);
+void setmfact(const char *arg);
 void setup(void);
 void spawn(const char *arg);
 void tag(const char *arg);
@@ -259,7 +260,7 @@ applyrules(Client *c) {
 	XGetClassHint(dpy, c->win, &ch);
 	for(i = 0; i < LENGTH(rules); i++) {
 		r = &rules[i];
-		if(r->title && strstr(c->name, r->title)
+		if((r->title && strstr(c->name, r->title))
 		|| (ch.res_class && r->class && strstr(ch.res_class, r->class))
 		|| (ch.res_name && r->instance && strstr(ch.res_name, r->instance)))
 		{
@@ -322,6 +323,10 @@ buttonpress(XEvent *e) {
 	XButtonPressedEvent *ev = &e->xbutton;
 
 	if(ev->window == barwin) {
+		if((ev->x < bgw) && ev->button == Button1) {
+			setgeom(NULL);
+			return;
+		}
 		x = bgw;
 		for(i = 0; i < LENGTH(tags); i++) {
 			x += textw(tags[i]);
@@ -341,6 +346,8 @@ buttonpress(XEvent *e) {
 				return;
 			}
 		}
+		if((ev->x < x + blw) && ev->button == Button1) 
+			setlayout(NULL);
 	}
 	else if((c = getclient(ev->window))) {
 		focus(c);
@@ -426,7 +433,7 @@ configurenotify(XEvent *e) {
 	if(ev->window == root && (ev->width != sw || ev->height != sh)) {
 		sw = ev->width;
 		sh = ev->height;
-		setgeom(NULL);
+		setgeom(geom->symbol);
 	}
 }
 
@@ -517,9 +524,11 @@ drawbar(void) {
 	Client *c;
 
 	dc.x = 0;
-	dc.w = bgw;
-	drawtext(geom->symbol, dc.norm, False);
-	dc.x += bgw;
+	if(bgw > 0) {
+		dc.w = bgw;
+		drawtext(geom->symbol, dc.norm, False);
+		dc.x += bgw;
+	}
 	for(c = stack; c && !isvisible(c); c = c->snext);
 	for(i = 0; i < LENGTH(tags); i++) {
 		dc.w = textw(tags[i]);
@@ -533,9 +542,13 @@ drawbar(void) {
 		}
 		dc.x += dc.w;
 	}
-	dc.w = blw;
-	drawtext(lt->symbol, dc.norm, False);
-	x = dc.x + dc.w;
+	if(blw > 0) {
+		dc.w = blw;
+		drawtext(lt->symbol, dc.norm, False);
+		x = dc.x + dc.w;
+	}
+	else
+		x = dc.x;
 	dc.w = textw(stext);
 	dc.x = bw - dc.w;
 	if(dc.x < x) {
@@ -860,7 +873,7 @@ unsigned int
 idxoftag(const char *t) {
 	unsigned int i;
 
-	for(i = 0; (i < LENGTH(tags)) && strcmp(tags[i], t); i++);
+	for(i = 0; (i < LENGTH(tags)) && t && strcmp(tags[i], t); i++);
 	return (i < LENGTH(tags)) ? i : 0;
 }
 
@@ -1411,12 +1424,18 @@ void
 setgeom(const char *arg) {
 	unsigned int i;
 
-	for(i = 0; arg && i < LENGTH(geoms); i++)
-		if(!strcmp(geoms[i].symbol, arg))
-			break;
-	if(i == LENGTH(geoms))
-		return;
-	geom = &geoms[i];
+	if(!arg) {
+		if(++geom == &geoms[LENGTH(geoms)])
+			geom = &geoms[0];
+	}
+	else {
+		for(i = 0; i < LENGTH(geoms); i++)
+			if(!strcmp(geoms[i].symbol, arg))
+				break;
+		if(i == LENGTH(geoms))
+			return;
+		geom = &geoms[i];
+	}
 	geom->apply();
 	updatebarpos();
 	arrange();
@@ -1424,20 +1443,18 @@ setgeom(const char *arg) {
 
 void
 setlayout(const char *arg) {
-	static Layout *revert = 0;
 	unsigned int i;
 
-	if(!arg)
-		return;
-	for(i = 0; i < LENGTH(layouts); i++)
-		if(!strcmp(arg, layouts[i].symbol))
-			break;
-	if(i == LENGTH(layouts))
-		return;
-	if(revert && &layouts[i] == lt)
-		lt = revert;
+	if(!arg) {
+		if(++lt == &layouts[LENGTH(layouts)])
+			lt = &layouts[0];
+	}
 	else {
-		revert = lt;
+		for(i = 0; i < LENGTH(layouts); i++)
+			if(!strcmp(arg, layouts[i].symbol))
+				break;
+		if(i == LENGTH(layouts))
+			return;
 		lt = &layouts[i];
 	}
 	if(sel)
@@ -1446,6 +1463,26 @@ setlayout(const char *arg) {
 		drawbar();
 }
 
+void
+setmfact(const char *arg) {
+	double delta;
+
+	if(!arg)
+		return;
+	delta = strtod(arg, NULL);
+	if(arg[0] == '-' || arg[0] == '+') {
+		if(mfact + delta < 0.1 || mfact + delta > 0.9)
+			return;
+		mfact += delta;
+	}
+	else {
+		if(delta < 0.1 || delta > 0.9)
+			return;
+		mfact = delta;
+	}
+	setgeom(geom->symbol);
+}
+
 void
 setup(void) {
 	unsigned int i, w;
@@ -1502,12 +1539,12 @@ setup(void) {
 	lt = &layouts[0];
 
 	/* init bar */
-	for(blw = i = 0; i < LENGTH(layouts); i++) {
+	for(blw = i = 0; LENGTH(layouts) > 1 && i < LENGTH(layouts); i++) {
 		w = textw(layouts[i].symbol);
 		if(w > blw)
 			blw = w;
 	}
-	for(bgw = i = 0; i < LENGTH(geoms); i++) {
+	for(bgw = i = 0; LENGTH(geoms) > 1 && i < LENGTH(geoms); i++) {
 		w = textw(geoms[i].symbol);
 		if(w > bgw)
 			bgw = w;