dwm.c
changeset 1290 06d46acfe156
parent 1289 064cfe1e8f84
child 1291 6a5c4371eb25
equal deleted inserted replaced
1289:064cfe1e8f84 1290:06d46acfe156
   205 
   205 
   206 /* variables */
   206 /* variables */
   207 static char stext[256];
   207 static char stext[256];
   208 static int screen, sx, sy, sw, sh;
   208 static int screen, sx, sy, sw, sh;
   209 static int by, bh, blw, wx, wy, ww, wh;
   209 static int by, bh, blw, wx, wy, ww, wh;
   210 static uint seltags = 0;
   210 static uint seltags = 0, sellt = 0;
   211 static int (*xerrorxlib)(Display *, XErrorEvent *);
   211 static int (*xerrorxlib)(Display *, XErrorEvent *);
   212 static uint numlockmask = 0;
   212 static uint numlockmask = 0;
   213 static void (*handler[LASTEvent]) (XEvent *) = {
   213 static void (*handler[LASTEvent]) (XEvent *) = {
   214 	[ButtonPress] = buttonpress,
   214 	[ButtonPress] = buttonpress,
   215 	[ConfigureRequest] = configurerequest,
   215 	[ConfigureRequest] = configurerequest,
   232 static Client *sel = NULL;
   232 static Client *sel = NULL;
   233 static Client *stack = NULL;
   233 static Client *stack = NULL;
   234 static Cursor cursor[CurLast];
   234 static Cursor cursor[CurLast];
   235 static Display *dpy;
   235 static Display *dpy;
   236 static DC dc = {0};
   236 static DC dc = {0};
   237 static Layout *lt = NULL;
   237 static Layout *lt[] = { NULL, NULL };
   238 static Window root, barwin;
   238 static Window root, barwin;
   239 /* configuration, allows nested code to access above variables */
   239 /* configuration, allows nested code to access above variables */
   240 #include "config.h"
   240 #include "config.h"
   241 
   241 
   242 /* compile-time check if all tags fit into an uint bit array. */
   242 /* compile-time check if all tags fit into an uint bit array. */
   272 arrange(void) {
   272 arrange(void) {
   273 	Client *c;
   273 	Client *c;
   274 
   274 
   275 	for(c = clients; c; c = c->next)
   275 	for(c = clients; c; c = c->next)
   276 		if(c->tags & tagset[seltags]) { /* is visible */
   276 		if(c->tags & tagset[seltags]) { /* is visible */
   277 			if(!lt->arrange || c->isfloating)
   277 			if(!lt[sellt]->arrange || c->isfloating)
   278 				resize(c, c->x, c->y, c->w, c->h, True);
   278 				resize(c, c->x, c->y, c->w, c->h, True);
   279 			c->isbanned = False;
   279 			c->isbanned = False;
   280 		}
   280 		}
   281 		else if(!c->isbanned) {
   281 		else if(!c->isbanned) {
   282 			XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
   282 			XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
   283 			c->isbanned = True;
   283 			c->isbanned = True;
   284 		}
   284 		}
   285 
   285 
   286 	focus(NULL);
   286 	focus(NULL);
   287 	if(lt->arrange)
   287 	if(lt[sellt]->arrange)
   288 		lt->arrange();
   288 		lt[sellt]->arrange();
   289 	restack();
   289 	restack();
   290 }
   290 }
   291 
   291 
   292 void
   292 void
   293 attach(Client *c) {
   293 attach(Client *c) {
   353 	Arg a = {.i = ~0};
   353 	Arg a = {.i = ~0};
   354 	Layout foo = { "", NULL };
   354 	Layout foo = { "", NULL };
   355 
   355 
   356 	close(STDIN_FILENO);
   356 	close(STDIN_FILENO);
   357 	view(&a);
   357 	view(&a);
   358 	lt = &foo;
   358 	lt[sellt] = &foo;
   359 	while(stack)
   359 	while(stack)
   360 		unmanage(stack);
   360 		unmanage(stack);
   361 	if(dc.font.set)
   361 	if(dc.font.set)
   362 		XFreeFontSet(dpy, dc.font.set);
   362 		XFreeFontSet(dpy, dc.font.set);
   363 	else
   363 	else
   411 	XWindowChanges wc;
   411 	XWindowChanges wc;
   412 
   412 
   413 	if((c = getclient(ev->window))) {
   413 	if((c = getclient(ev->window))) {
   414 		if(ev->value_mask & CWBorderWidth)
   414 		if(ev->value_mask & CWBorderWidth)
   415 			c->bw = ev->border_width;
   415 			c->bw = ev->border_width;
   416 		else if(c->isfloating || !lt->arrange) {
   416 		else if(c->isfloating || !lt[sellt]->arrange) {
   417 			if(ev->value_mask & CWX)
   417 			if(ev->value_mask & CWX)
   418 				c->x = sx + ev->x;
   418 				c->x = sx + ev->x;
   419 			if(ev->value_mask & CWY)
   419 			if(ev->value_mask & CWY)
   420 				c->y = sy + ev->y;
   420 				c->y = sy + ev->y;
   421 			if(ev->value_mask & CWWidth)
   421 			if(ev->value_mask & CWWidth)
   498 		}
   498 		}
   499 		dc.x += dc.w;
   499 		dc.x += dc.w;
   500 	}
   500 	}
   501 	if(blw > 0) {
   501 	if(blw > 0) {
   502 		dc.w = blw;
   502 		dc.w = blw;
   503 		drawtext(lt->symbol, dc.norm, False);
   503 		drawtext(lt[sellt]->symbol, dc.norm, False);
   504 		x = dc.x + dc.w;
   504 		x = dc.x + dc.w;
   505 	}
   505 	}
   506 	else
   506 	else
   507 		x = dc.x;
   507 		x = dc.x;
   508 	dc.w = TEXTW(stext);
   508 	dc.w = TEXTW(stext);
  1007 					nx = wx + ww - c->w - 2 * c->bw;
  1007 					nx = wx + ww - c->w - 2 * c->bw;
  1008 				if(abs(wy - ny) < snap)
  1008 				if(abs(wy - ny) < snap)
  1009 					ny = wy;
  1009 					ny = wy;
  1010 				else if(abs((wy + wh) - (ny + c->h + 2 * c->bw)) < snap)
  1010 				else if(abs((wy + wh) - (ny + c->h + 2 * c->bw)) < snap)
  1011 					ny = wy + wh - c->h - 2 * c->bw;
  1011 					ny = wy + wh - c->h - 2 * c->bw;
  1012 				if(!c->isfloating && lt->arrange && (abs(nx - c->x) > snap || abs(ny - c->y) > snap))
  1012 				if(!c->isfloating && lt[sellt]->arrange && (abs(nx - c->x) > snap || abs(ny - c->y) > snap))
  1013 					togglefloating(NULL);
  1013 					togglefloating(NULL);
  1014 			}
  1014 			}
  1015 			if(!lt->arrange || c->isfloating)
  1015 			if(!lt[sellt]->arrange || c->isfloating)
  1016 				resize(c, nx, ny, c->w, c->h, False);
  1016 				resize(c, nx, ny, c->w, c->h, False);
  1017 			break;
  1017 			break;
  1018 		}
  1018 		}
  1019 	}
  1019 	}
  1020 }
  1020 }
  1164 			nw = MAX(ev.xmotion.x - ocx - 2 * c->bw + 1, 1);
  1164 			nw = MAX(ev.xmotion.x - ocx - 2 * c->bw + 1, 1);
  1165 			nh = MAX(ev.xmotion.y - ocy - 2 * c->bw + 1, 1);
  1165 			nh = MAX(ev.xmotion.y - ocy - 2 * c->bw + 1, 1);
  1166 
  1166 
  1167 			if(snap && nw >= wx && nw <= wx + ww
  1167 			if(snap && nw >= wx && nw <= wx + ww
  1168 			        && nh >= wy && nh <= wy + wh) {
  1168 			        && nh >= wy && nh <= wy + wh) {
  1169 				if(!c->isfloating && lt->arrange
  1169 				if(!c->isfloating && lt[sellt]->arrange
  1170 				   && (abs(nw - c->w) > snap || abs(nh - c->h) > snap))
  1170 				   && (abs(nw - c->w) > snap || abs(nh - c->h) > snap))
  1171 					togglefloating(NULL);
  1171 					togglefloating(NULL);
  1172 			}
  1172 			}
  1173 			if(!lt->arrange || c->isfloating)
  1173 			if(!lt[sellt]->arrange || c->isfloating)
  1174 				resize(c, c->x, c->y, nw, nh, True);
  1174 				resize(c, c->x, c->y, nw, nh, True);
  1175 			break;
  1175 			break;
  1176 		}
  1176 		}
  1177 	}
  1177 	}
  1178 }
  1178 }
  1184 	XWindowChanges wc;
  1184 	XWindowChanges wc;
  1185 
  1185 
  1186 	drawbar();
  1186 	drawbar();
  1187 	if(!sel)
  1187 	if(!sel)
  1188 		return;
  1188 		return;
  1189 	if(sel->isfloating || !lt->arrange)
  1189 	if(sel->isfloating || !lt[sellt]->arrange)
  1190 		XRaiseWindow(dpy, sel->win);
  1190 		XRaiseWindow(dpy, sel->win);
  1191 	if(lt->arrange) {
  1191 	if(lt[sellt]->arrange) {
  1192 		wc.stack_mode = Below;
  1192 		wc.stack_mode = Below;
  1193 		wc.sibling = barwin;
  1193 		wc.sibling = barwin;
  1194 		for(c = stack; c; c = c->snext)
  1194 		for(c = stack; c; c = c->snext)
  1195 			if(!c->isfloating && !c->isbanned) {
  1195 			if(!c->isfloating && !c->isbanned) {
  1196 				XConfigureWindow(dpy, c->win, CWSibling|CWStackMode, &wc);
  1196 				XConfigureWindow(dpy, c->win, CWSibling|CWStackMode, &wc);
  1296 			PropModeReplace, (unsigned char *)data, 2);
  1296 			PropModeReplace, (unsigned char *)data, 2);
  1297 }
  1297 }
  1298 
  1298 
  1299 void
  1299 void
  1300 setlayout(const Arg *arg) {
  1300 setlayout(const Arg *arg) {
  1301 	static Layout *prevlt = &layouts[1 % LENGTH(layouts)];
  1301 	sellt ^= 1;
  1302 
  1302 	if(arg && arg->v && arg->v != lt[sellt])
  1303 	if(!arg || !arg->v || arg->v == lt)
  1303 		lt[sellt] = (Layout *)arg->v;
  1304 		lt = prevlt;
       
  1305 	else {
       
  1306 		prevlt = lt;
       
  1307 		lt = (Layout *)arg->v;
       
  1308 	}
       
  1309 	if(sel)
  1304 	if(sel)
  1310 		arrange();
  1305 		arrange();
  1311 	else
  1306 	else
  1312 		drawbar();
  1307 		drawbar();
  1313 }
  1308 }
  1315 /* arg > 1.0 will set mfact absolutly */
  1310 /* arg > 1.0 will set mfact absolutly */
  1316 void
  1311 void
  1317 setmfact(const Arg *arg) {
  1312 setmfact(const Arg *arg) {
  1318 	float f;
  1313 	float f;
  1319 
  1314 
  1320 	if(!arg || !lt->arrange)
  1315 	if(!arg || !lt[sellt]->arrange)
  1321 		return;
  1316 		return;
  1322 	f = arg->f < 1.0 ? arg->f + mfact : arg->f - 1.0;
  1317 	f = arg->f < 1.0 ? arg->f + mfact : arg->f - 1.0;
  1323 	if(f < 0.1 || f > 0.9)
  1318 	if(f < 0.1 || f > 0.9)
  1324 		return;
  1319 		return;
  1325 	mfact = f;
  1320 	mfact = f;
  1339 	sx = 0;
  1334 	sx = 0;
  1340 	sy = 0;
  1335 	sy = 0;
  1341 	sw = DisplayWidth(dpy, screen);
  1336 	sw = DisplayWidth(dpy, screen);
  1342 	sh = DisplayHeight(dpy, screen);
  1337 	sh = DisplayHeight(dpy, screen);
  1343 	bh = dc.h = dc.font.height + 2;
  1338 	bh = dc.h = dc.font.height + 2;
  1344 	lt = layouts;
  1339 	lt[0] = &layouts[0];
       
  1340 	lt[1] = &layouts[1 % LENGTH(layouts)];
  1345 	updategeom();
  1341 	updategeom();
  1346 
  1342 
  1347 	/* init atoms */
  1343 	/* init atoms */
  1348 	wmatom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False);
  1344 	wmatom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False);
  1349 	wmatom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
  1345 	wmatom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
  1689 
  1685 
  1690 void
  1686 void
  1691 zoom(const Arg *arg) {
  1687 zoom(const Arg *arg) {
  1692 	Client *c = sel;
  1688 	Client *c = sel;
  1693 
  1689 
  1694 	if(!lt->arrange || lt->arrange == monocle || (sel && sel->isfloating))
  1690 	if(!lt[sellt]->arrange || lt[sellt]->arrange == monocle || (sel && sel->isfloating))
  1695 		return;
  1691 		return;
  1696 	if(c == nexttiled(clients))
  1692 	if(c == nexttiled(clients))
  1697 		if(!c || !(c = nexttiled(c->next)))
  1693 		if(!c || !(c = nexttiled(c->next)))
  1698 			return;
  1694 			return;
  1699 	detach(c);
  1695 	detach(c);