diff options
| author | anselm@anselm1 <unknown> | 2008-04-20 18:28:21 +0100 |
|---|---|---|
| committer | anselm@anselm1 <unknown> | 2008-04-20 18:28:21 +0100 |
| commit | 874837f653433315bd2733823a0a1efe6f76b373 (patch) | |
| tree | e36c41a1222e1e4c8d0b32106486c26df6fc984e /dwm.c | |
| parent | applied Ph's patch regarding geom and lt initialization (diff) | |
| download | dwm-874837f653433315bd2733823a0a1efe6f76b373.tar.gz dwm-874837f653433315bd2733823a0a1efe6f76b373.zip | |
applied Ph's MIN/MAX patch, nice work!
Diffstat (limited to '')
| -rw-r--r-- | dwm.c | 53 |
1 files changed, 22 insertions, 31 deletions
| @@ -41,6 +41,8 @@ | |||
| 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]) |
| @@ -601,9 +603,8 @@ drawtext(const char *text, unsigned long col[ColLast], Bool invert) { | |||
| 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; |
| @@ -880,10 +881,8 @@ initfont(const char *fontstr) { | |||
| 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 | } |
| @@ -1008,10 +1007,8 @@ manage(Window w, XWindowAttributes *wa) { | |||
| 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 | ||
| @@ -1177,10 +1174,8 @@ resize(Client *c, int x, int y, int w, int h, Bool sizehints) { | |||
| 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; |
| @@ -1206,14 +1201,14 @@ resize(Client *c, int x, int y, int w, int h, Bool sizehints) { | |||
| 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; |
| @@ -1266,10 +1261,8 @@ resizemouse(Client *c) { | |||
| 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) |
| @@ -1520,13 +1513,11 @@ setup(void) { | |||
| 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; |
