dwm.c
changeset 1178 e0095dbfc0af
parent 1177 22d8c2fb999f
child 1179 6fad217390c6
equal deleted inserted replaced
1177:22d8c2fb999f 1178:e0095dbfc0af
    39 #include <X11/Xlib.h>
    39 #include <X11/Xlib.h>
    40 #include <X11/Xproto.h>
    40 #include <X11/Xproto.h>
    41 #include <X11/Xutil.h>
    41 #include <X11/Xutil.h>
    42 
    42 
    43 /* macros */
    43 /* macros */
       
    44 #define MAX(a, b) ((a)>(b)?(a):(b))
       
    45 #define MIN(a, b) ((a)<(b)?(a):(b))
    44 #define BUTTONMASK		(ButtonPressMask|ButtonReleaseMask)
    46 #define BUTTONMASK		(ButtonPressMask|ButtonReleaseMask)
    45 #define CLEANMASK(mask)		(mask & ~(numlockmask|LockMask))
    47 #define CLEANMASK(mask)		(mask & ~(numlockmask|LockMask))
    46 #define LENGTH(x)		(sizeof x / sizeof x[0])
    48 #define LENGTH(x)		(sizeof x / sizeof x[0])
    47 #define MAXTAGLEN		16
    49 #define MAXTAGLEN		16
    48 #define MOUSEMASK		(BUTTONMASK|PointerMotionMask)
    50 #define MOUSEMASK		(BUTTONMASK|PointerMotionMask)
   599 	XSetForeground(dpy, dc.gc, col[invert ? ColFG : ColBG]);
   601 	XSetForeground(dpy, dc.gc, col[invert ? ColFG : ColBG]);
   600 	XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1);
   602 	XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1);
   601 	if(!text)
   603 	if(!text)
   602 		return;
   604 		return;
   603 	w = 0;
   605 	w = 0;
   604 	olen = len = strlen(text);
   606 	olen = strlen(text);
   605 	if(len >= sizeof buf)
   607 	len = MIN(olen, sizeof buf - 1);
   606 		len = sizeof buf - 1;
       
   607 	memcpy(buf, text, len);
   608 	memcpy(buf, text, len);
   608 	buf[len] = 0;
   609 	buf[len] = 0;
   609 	h = dc.font.ascent + dc.font.descent;
   610 	h = dc.font.ascent + dc.font.descent;
   610 	y = dc.y + (dc.h / 2) - (h / 2) + dc.font.ascent;
   611 	y = dc.y + (dc.h / 2) - (h / 2) + dc.font.ascent;
   611 	x = dc.x + (h / 2);
   612 	x = dc.x + (h / 2);
   878 		char **font_names;
   879 		char **font_names;
   879 		dc.font.ascent = dc.font.descent = 0;
   880 		dc.font.ascent = dc.font.descent = 0;
   880 		font_extents = XExtentsOfFontSet(dc.font.set);
   881 		font_extents = XExtentsOfFontSet(dc.font.set);
   881 		n = XFontsOfFontSet(dc.font.set, &xfonts, &font_names);
   882 		n = XFontsOfFontSet(dc.font.set, &xfonts, &font_names);
   882 		for(i = 0, dc.font.ascent = 0, dc.font.descent = 0; i < n; i++) {
   883 		for(i = 0, dc.font.ascent = 0, dc.font.descent = 0; i < n; i++) {
   883 			if(dc.font.ascent < (*xfonts)->ascent)
   884 			dc.font.ascent = MAX(dc.font.ascent, (*xfonts)->ascent);
   884 				dc.font.ascent = (*xfonts)->ascent;
   885 			dc.font.descent = MAX(dc.font.descent,(*xfonts)->descent);
   885 			if(dc.font.descent < (*xfonts)->descent)
       
   886 				dc.font.descent = (*xfonts)->descent;
       
   887 			xfonts++;
   886 			xfonts++;
   888 		}
   887 		}
   889 	}
   888 	}
   890 	else {
   889 	else {
   891 		if(dc.font.xfont)
   890 		if(dc.font.xfont)
  1006 	else {
  1005 	else {
  1007 		if(c->x + c->w + 2 * c->bw > wx + ww)
  1006 		if(c->x + c->w + 2 * c->bw > wx + ww)
  1008 			c->x = wx + ww - c->w - 2 * c->bw;
  1007 			c->x = wx + ww - c->w - 2 * c->bw;
  1009 		if(c->y + c->h + 2 * c->bw > wy + wh)
  1008 		if(c->y + c->h + 2 * c->bw > wy + wh)
  1010 			c->y = wy + wh - c->h - 2 * c->bw;
  1009 			c->y = wy + wh - c->h - 2 * c->bw;
  1011 		if(c->x < wx)
  1010 		c->x = MAX(c->x, wx);
  1012 			c->x = wx;
  1011 		c->y = MAX(c->y, wy);
  1013 		if(c->y < wy)
       
  1014 			c->y = wy;
       
  1015 		c->bw = BORDERPX;
  1012 		c->bw = BORDERPX;
  1016 	}
  1013 	}
  1017 
  1014 
  1018 	wc.border_width = c->bw;
  1015 	wc.border_width = c->bw;
  1019 	XConfigureWindow(dpy, w, CWBorderWidth, &wc);
  1016 	XConfigureWindow(dpy, w, CWBorderWidth, &wc);
  1175 resize(Client *c, int x, int y, int w, int h, Bool sizehints) {
  1172 resize(Client *c, int x, int y, int w, int h, Bool sizehints) {
  1176 	XWindowChanges wc;
  1173 	XWindowChanges wc;
  1177 
  1174 
  1178 	if(sizehints) {
  1175 	if(sizehints) {
  1179 		/* set minimum possible */
  1176 		/* set minimum possible */
  1180 		if(w < 1)
  1177 		w = MAX(1, w);
  1181 			w = 1;
  1178 		h = MAX(1, h);
  1182 		if(h < 1)
       
  1183 			h = 1;
       
  1184 
  1179 
  1185 		/* temporarily remove base dimensions */
  1180 		/* temporarily remove base dimensions */
  1186 		w -= c->basew;
  1181 		w -= c->basew;
  1187 		h -= c->baseh;
  1182 		h -= c->baseh;
  1188 
  1183 
  1204 
  1199 
  1205 		/* restore base dimensions */
  1200 		/* restore base dimensions */
  1206 		w += c->basew;
  1201 		w += c->basew;
  1207 		h += c->baseh;
  1202 		h += c->baseh;
  1208 
  1203 
  1209 		if(c->minw > 0 && w < c->minw)
  1204 		w = MAX(w, c->minw);
  1210 			w = c->minw;
  1205 		h = MAX(h, c->minh);
  1211 		if(c->minh > 0 && h < c->minh)
  1206 		
  1212 			h = c->minh;
  1207 		if (c->maxw)
  1213 		if(c->maxw > 0 && w > c->maxw)
  1208 			w = MIN(w, c->maxw);
  1214 			w = c->maxw;
  1209 
  1215 		if(c->maxh > 0 && h > c->maxh)
  1210 		if (c->maxh)
  1216 			h = c->maxh;
  1211 			h = MIN(h, c->maxh);
  1217 	}
  1212 	}
  1218 	if(w <= 0 || h <= 0)
  1213 	if(w <= 0 || h <= 0)
  1219 		return;
  1214 		return;
  1220 	if(x > sx + sw)
  1215 	if(x > sx + sw)
  1221 		x = sw - w - 2 * c->bw;
  1216 		x = sw - w - 2 * c->bw;
  1264 		case MapRequest:
  1259 		case MapRequest:
  1265 			handler[ev.type](&ev);
  1260 			handler[ev.type](&ev);
  1266 			break;
  1261 			break;
  1267 		case MotionNotify:
  1262 		case MotionNotify:
  1268 			XSync(dpy, False);
  1263 			XSync(dpy, False);
  1269 			if((nw = ev.xmotion.x - ocx - 2 * c->bw + 1) <= 0)
  1264 			nw = MAX(ev.xmotion.x - ocx - 2 * c->bw + 1, 1);
  1270 				nw = 1;
  1265 			nh = MAX(ev.xmotion.y - ocy - 2 * c->bw + 1, 1);
  1271 			if((nh = ev.xmotion.y - ocy - 2 * c->bw + 1) <= 0)
       
  1272 				nh = 1;
       
  1273 			if(!c->isfloating && !lt->isfloating && (abs(nw - c->w) > SNAP || abs(nh - c->h) > SNAP))
  1266 			if(!c->isfloating && !lt->isfloating && (abs(nw - c->w) > SNAP || abs(nh - c->h) > SNAP))
  1274 				togglefloating(NULL);
  1267 				togglefloating(NULL);
  1275 			if((lt->isfloating) || c->isfloating)
  1268 			if((lt->isfloating) || c->isfloating)
  1276 				resize(c, c->x, c->y, nw, nh, True);
  1269 				resize(c, c->x, c->y, nw, nh, True);
  1277 			break;
  1270 			break;
  1518 	seltags[0] = prevtags[0] = True;
  1511 	seltags[0] = prevtags[0] = True;
  1519 
  1512 
  1520 	/* init bar */
  1513 	/* init bar */
  1521 	for(blw = i = 0; LENGTH(layouts) > 1 && i < LENGTH(layouts); i++) {
  1514 	for(blw = i = 0; LENGTH(layouts) > 1 && i < LENGTH(layouts); i++) {
  1522 		w = textw(layouts[i].symbol);
  1515 		w = textw(layouts[i].symbol);
  1523 		if(w > blw)
  1516 		blw = MAX(blw, w);
  1524 			blw = w;
       
  1525 	}
  1517 	}
  1526 	for(bgw = i = 0; LENGTH(geoms) > 1 && i < LENGTH(geoms); i++) {
  1518 	for(bgw = i = 0; LENGTH(geoms) > 1 && i < LENGTH(geoms); i++) {
  1527 		w = textw(geoms[i].symbol);
  1519 		w = textw(geoms[i].symbol);
  1528 		if(w > bgw)
  1520 		bgw = MAX(bgw, w);
  1529 			bgw = w;
       
  1530 	}
  1521 	}
  1531 
  1522 
  1532 	wa.override_redirect = 1;
  1523 	wa.override_redirect = 1;
  1533 	wa.background_pixmap = ParentRelative;
  1524 	wa.background_pixmap = ParentRelative;
  1534 	wa.event_mask = ButtonPressMask|ExposureMask;
  1525 	wa.event_mask = ButtonPressMask|ExposureMask;