removed the _DWM_PROPERTIES handling, reverted ban/unban to XMoveWindow(), and changed argument of setlayout to layout[N].symbol check
36672d04
6 file(s) · +23 −101
| 1 | 1 | /* See LICENSE file for copyright and license details. */ |
|
| 2 | 2 | #include "dwm.h" |
|
| 3 | 3 | #include <stdlib.h> |
|
| 4 | - | #include <string.h> |
|
| 5 | 4 | #include <X11/Xatom.h> |
|
| 6 | 5 | #include <X11/Xutil.h> |
|
| 7 | 6 | ||
| 8 | 7 | /* static */ |
|
| 9 | - | ||
| 10 | - | static char buf[128]; |
|
| 11 | 8 | ||
| 12 | 9 | static void |
|
| 13 | 10 | attachstack(Client *c) { |
|
| 102 | 99 | ban(Client *c) { |
|
| 103 | 100 | if(c->isbanned) |
|
| 104 | 101 | return; |
|
| 105 | - | XUnmapWindow(dpy, c->win); |
|
| 106 | - | setclientstate(c, IconicState); |
|
| 102 | + | XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y); |
|
| 107 | 103 | c->isbanned = True; |
|
| 108 | - | c->unmapped++; |
|
| 109 | 104 | } |
|
| 110 | 105 | ||
| 111 | 106 | void |
|
| 181 | 176 | XKillClient(dpy, sel->win); |
|
| 182 | 177 | } |
|
| 183 | 178 | ||
| 184 | - | Bool |
|
| 185 | - | getprops(Client *c) { |
|
| 186 | - | unsigned int i; |
|
| 187 | - | Bool result = False; |
|
| 188 | - | ||
| 189 | - | if(gettextprop(c->win, dwmprops, buf, sizeof buf)) { |
|
| 190 | - | for(i = 0; i < ntags && i < sizeof buf - 1 && buf[i] != '\0'; i++) |
|
| 191 | - | if((c->tags[i] = buf[i] == '1')) |
|
| 192 | - | result = True; |
|
| 193 | - | if(i < sizeof buf - 1 && buf[i] != '\0') |
|
| 194 | - | c->isfloating = buf[i] == '1'; |
|
| 195 | - | } |
|
| 196 | - | return result; |
|
| 197 | - | } |
|
| 198 | - | ||
| 199 | 179 | void |
|
| 200 | 180 | manage(Window w, XWindowAttributes *wa) { |
|
| 201 | 181 | unsigned int i; |
|
| 242 | 222 | if(t) |
|
| 243 | 223 | for(i = 0; i < ntags; i++) |
|
| 244 | 224 | c->tags[i] = t->tags[i]; |
|
| 245 | - | if(!getprops(c)) |
|
| 246 | - | applyrules(c); |
|
| 225 | + | applyrules(c); |
|
| 247 | 226 | if(!c->isfloating) |
|
| 248 | 227 | c->isfloating = (rettrans == Success) || c->isfixed; |
|
| 249 | - | setprops(c); |
|
| 250 | 228 | attach(c); |
|
| 251 | 229 | attachstack(c); |
|
| 252 | 230 | XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h); /* some windows require this */ |
|
| 253 | 231 | ban(c); |
|
| 232 | + | XMapWindow(dpy, c->win); |
|
| 254 | 233 | arrange(); |
|
| 255 | 234 | } |
|
| 256 | 235 | ||
| 318 | 297 | } |
|
| 319 | 298 | ||
| 320 | 299 | void |
|
| 321 | - | setprops(Client *c) { |
|
| 322 | - | unsigned int i; |
|
| 323 | - | ||
| 324 | - | for(i = 0; i < ntags && i < sizeof buf - 1; i++) |
|
| 325 | - | buf[i] = c->tags[i] ? '1' : '0'; |
|
| 326 | - | if(i < sizeof buf - 1) |
|
| 327 | - | buf[i++] = c->isfloating ? '1' : '0'; |
|
| 328 | - | buf[i] = '\0'; |
|
| 329 | - | XChangeProperty(dpy, c->win, dwmprops, XA_STRING, 8, |
|
| 330 | - | PropModeReplace, (unsigned char *)buf, i); |
|
| 331 | - | } |
|
| 332 | - | ||
| 333 | - | void |
|
| 334 | 300 | unban(Client *c) { |
|
| 335 | 301 | if(!c->isbanned) |
|
| 336 | 302 | return; |
|
| 337 | - | XMapWindow(dpy, c->win); |
|
| 338 | - | setclientstate(c, NormalState); |
|
| 303 | + | XMoveWindow(dpy, c->win, c->x, c->y); |
|
| 339 | 304 | c->isbanned = False; |
|
| 340 | 305 | } |
|
| 341 | 306 | ||
| 342 | 307 | void |
|
| 343 | - | unmanage(Client *c, long state) { |
|
| 308 | + | unmanage(Client *c) { |
|
| 344 | 309 | XWindowChanges wc; |
|
| 345 | 310 | ||
| 346 | 311 | wc.border_width = c->oldborder; |
|
| 353 | 318 | if(sel == c) |
|
| 354 | 319 | focus(NULL); |
|
| 355 | 320 | XUngrabButton(dpy, AnyButton, AnyModifier, c->win); |
|
| 356 | - | setclientstate(c, state); |
|
| 321 | + | setclientstate(c, WithdrawnState); |
|
| 357 | 322 | free(c->tags); |
|
| 358 | 323 | free(c); |
|
| 359 | 324 | XSync(dpy, False); |
|
| 360 | 325 | XSetErrorHandler(xerror); |
|
| 361 | 326 | XUngrabServer(dpy); |
|
| 362 | - | if(state != NormalState) |
|
| 363 | - | arrange(); |
|
| 327 | + | arrange(); |
|
| 364 | 328 | } |
|
| 365 | 329 | ||
| 366 | 330 | void |
|
| 20 | 20 | # flags |
|
| 21 | 21 | CFLAGS = -Os ${INCS} -DVERSION=\"${VERSION}\" |
|
| 22 | 22 | LDFLAGS = -s ${LIBS} |
|
| 23 | - | #CFLAGS = -g -Wall -O2 ${INCS} -DVERSION=\"${VERSION}\" |
|
| 24 | - | #LDFLAGS = -g ${LIBS} |
|
| 23 | + | CFLAGS = -g -Wall -O2 ${INCS} -DVERSION=\"${VERSION}\" |
|
| 24 | + | LDFLAGS = -g ${LIBS} |
|
| 25 | 25 | ||
| 26 | 26 | # Solaris |
|
| 27 | 27 | #CFLAGS = -fast ${INCS} -DVERSION=\"${VERSION}\" |
| 48 | 48 | int rx, ry, rw, rh; /* revert geometry */ |
|
| 49 | 49 | int basew, baseh, incw, inch, maxw, maxh, minw, minh; |
|
| 50 | 50 | int minax, maxax, minay, maxay; |
|
| 51 | - | int unmapped; |
|
| 52 | 51 | long flags; |
|
| 53 | 52 | unsigned int border, oldborder; |
|
| 54 | 53 | Bool isbanned, isfixed, ismax, isfloating; |
|
| 81 | 80 | extern unsigned int bh, blw, bpos; /* bar height, bar layout label width, bar position */ |
|
| 82 | 81 | extern unsigned int ntags, numlockmask; /* number of tags, numlock mask */ |
|
| 83 | 82 | extern void (*handler[LASTEvent])(XEvent *); /* event handler */ |
|
| 84 | - | extern Atom dwmprops, wmatom[WMLast], netatom[NetLast]; |
|
| 83 | + | extern Atom wmatom[WMLast], netatom[NetLast]; |
|
| 85 | 84 | extern Bool selscreen, *seltags; /* seltags is array of Bool */ |
|
| 86 | 85 | extern Client *clients, *sel, *stack; /* global client list and stack */ |
|
| 87 | 86 | extern Cursor cursor[CurLast]; |
|
| 96 | 95 | void detach(Client *c); /* detaches c from global client list */ |
|
| 97 | 96 | void focus(Client *c); /* focus c if visible && !NULL, or focus top visible */ |
|
| 98 | 97 | void killclient(const char *arg); /* kill sel nicely */ |
|
| 99 | - | Bool getprops(Client *c); /* gets client properties */ |
|
| 100 | 98 | void manage(Window w, XWindowAttributes *wa); /* manage new client */ |
|
| 101 | 99 | void resize(Client *c, int x, int y, |
|
| 102 | 100 | int w, int h, Bool sizehints); /* resize with given coordinates c*/ |
|
| 103 | - | void setprops(Client *c); /* sets client properties */ |
|
| 104 | 101 | void unban(Client *c); /* unbans c */ |
|
| 105 | - | void unmanage(Client *c, long state); /* unmanage c */ |
|
| 102 | + | void unmanage(Client *c); /* unmanage c */ |
|
| 106 | 103 | void updatesizehints(Client *c); /* update the size hint variables of c */ |
|
| 107 | 104 | void updatetitle(Client *c); /* update the name of c */ |
|
| 108 | 105 | ||
| 131 | 128 | Bool isarrange(void (*func)()); /* returns True if func is the layout function in use */ |
|
| 132 | 129 | Bool isfloating(void); /* returns True if floating layout is enabled */ |
|
| 133 | 130 | Bool isvisible(Client *c); /* returns True if client is visible */ |
|
| 134 | - | void getdwmprops(void); /* gets dwm properties */ |
|
| 135 | 131 | Client *nexttiled(Client *c); /* returns tiled successor of c */ |
|
| 136 | 132 | void restack(void); /* restores z layers of all clients */ |
|
| 137 | 133 | void setlayout(const char *arg); /* sets layout, NULL means next layout */ |
|
| 221 | 221 | XDestroyWindowEvent *ev = &e->xdestroywindow; |
|
| 222 | 222 | ||
| 223 | 223 | if((c = getclient(ev->window))) |
|
| 224 | - | unmanage(c, WithdrawnState); |
|
| 224 | + | unmanage(c); |
|
| 225 | 225 | } |
|
| 226 | 226 | ||
| 227 | 227 | static void |
|
| 332 | 332 | Client *c; |
|
| 333 | 333 | XUnmapEvent *ev = &e->xunmap; |
|
| 334 | 334 | ||
| 335 | - | if((c = getclient(ev->window)) && (ev->event == root)) { |
|
| 336 | - | if(ev->send_event || c->unmapped-- == 0) |
|
| 337 | - | unmanage(c, WithdrawnState); |
|
| 338 | - | } |
|
| 335 | + | if((c = getclient(ev->window))) |
|
| 336 | + | unmanage(c); |
|
| 339 | 337 | } |
|
| 340 | 338 | ||
| 341 | 339 | /* extern */ |
|
| 20 | 20 | unsigned int bh, ntags; |
|
| 21 | 21 | unsigned int bpos = BARPOS; |
|
| 22 | 22 | unsigned int numlockmask = 0; |
|
| 23 | - | Atom dwmprops, wmatom[WMLast], netatom[NetLast]; |
|
| 23 | + | Atom wmatom[WMLast], netatom[NetLast]; |
|
| 24 | 24 | Bool *seltags; |
|
| 25 | 25 | Bool selscreen = True; |
|
| 26 | 26 | Client *clients = NULL; |
|
| 42 | 42 | close(STDIN_FILENO); |
|
| 43 | 43 | while(stack) { |
|
| 44 | 44 | unban(stack); |
|
| 45 | - | unmanage(stack, NormalState); |
|
| 45 | + | unmanage(stack); |
|
| 46 | 46 | } |
|
| 47 | 47 | if(dc.font.set) |
|
| 48 | 48 | XFreeFontSet(dpy, dc.font.set); |
|
| 165 | 165 | XSetWindowAttributes wa; |
|
| 166 | 166 | ||
| 167 | 167 | /* init atoms */ |
|
| 168 | - | dwmprops = XInternAtom(dpy, "_DWM_PROPERTIES", False); |
|
| 169 | 168 | wmatom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False); |
|
| 170 | 169 | wmatom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False); |
|
| 171 | 170 | wmatom[WMName] = XInternAtom(dpy, "WM_NAME", False); |
|
| 231 | 230 | XSetFont(dpy, dc.gc, dc.font.xfont->fid); |
|
| 232 | 231 | /* multihead support */ |
|
| 233 | 232 | selscreen = XQueryPointer(dpy, root, &w, &w, &i, &i, &i, &i, &mask); |
|
| 234 | - | getdwmprops(); |
|
| 235 | 233 | } |
|
| 236 | 234 | ||
| 237 | 235 | /* |
|
| 3 | 3 | #include <regex.h> |
|
| 4 | 4 | #include <stdio.h> |
|
| 5 | 5 | #include <stdlib.h> |
|
| 6 | - | #include <string.h> |
|
| 7 | - | #include <X11/Xatom.h> |
|
| 8 | 6 | #include <X11/Xutil.h> |
|
| 9 | 7 | ||
| 10 | 8 | /* static */ |
|
| 28 | 26 | TAGS |
|
| 29 | 27 | RULES |
|
| 30 | 28 | ||
| 31 | - | static char buf[512]; |
|
| 32 | 29 | static unsigned int nrules = 0; |
|
| 33 | 30 | static unsigned int nlayouts = 0; |
|
| 34 | 31 | static unsigned int ltidx = 0; /* default */ |
|
| 53 | 50 | resize(c, c->x, c->y, c->w, c->h, True); |
|
| 54 | 51 | } |
|
| 55 | 52 | ||
| 56 | - | static void |
|
| 57 | - | setdwmprops(void) { |
|
| 58 | - | unsigned int i; |
|
| 59 | - | ||
| 60 | - | for(i = 0; i < ntags && i < sizeof buf - 1; i++) |
|
| 61 | - | buf[i] = seltags[i] ? '1' : '0'; |
|
| 62 | - | if(i < sizeof buf - 1) |
|
| 63 | - | buf[i++] = (char)ltidx + '0'; |
|
| 64 | - | buf[i] = '\0'; |
|
| 65 | - | XChangeProperty(dpy, root, dwmprops, XA_STRING, 8, |
|
| 66 | - | PropModeReplace, (unsigned char *)buf, i); |
|
| 67 | - | } |
|
| 68 | - | ||
| 69 | 53 | LAYOUTS |
|
| 70 | 54 | ||
| 71 | 55 | /* extern */ |
|
| 74 | 58 | ||
| 75 | 59 | void |
|
| 76 | 60 | applyrules(Client *c) { |
|
| 61 | + | static char buf[512]; |
|
| 77 | 62 | unsigned int i, j; |
|
| 78 | 63 | regmatch_t tmp; |
|
| 79 | 64 | Bool matched = False; |
|
| 215 | 200 | return False; |
|
| 216 | 201 | } |
|
| 217 | 202 | ||
| 218 | - | void |
|
| 219 | - | getdwmprops(void) { |
|
| 220 | - | unsigned int i; |
|
| 221 | - | ||
| 222 | - | if(gettextprop(root, dwmprops, buf, sizeof buf)) { |
|
| 223 | - | for(i = 0; i < ntags && i < sizeof buf - 1 && buf[i] != '\0'; i++) |
|
| 224 | - | seltags[i] = buf[i] == '1'; |
|
| 225 | - | if(i < sizeof buf - 1 && buf[i] != '\0') { |
|
| 226 | - | if((unsigned int)(buf[i] - '0') < nlayouts) |
|
| 227 | - | ltidx = buf[i] - '0'; |
|
| 228 | - | } |
|
| 229 | - | } |
|
| 230 | - | } |
|
| 231 | - | ||
| 232 | 203 | Client * |
|
| 233 | 204 | nexttiled(Client *c) { |
|
| 234 | 205 | for(; c && (c->isfloating || !isvisible(c)); c = c->next); |
|
| 266 | 237 | ||
| 267 | 238 | void |
|
| 268 | 239 | setlayout(const char *arg) { |
|
| 269 | - | int i; |
|
| 240 | + | unsigned int i; |
|
| 270 | 241 | ||
| 271 | 242 | if(!arg) { |
|
| 272 | 243 | if(++ltidx == nlayouts) |
|
| 273 | 244 | ltidx = 0;; |
|
| 274 | 245 | } |
|
| 275 | 246 | else { |
|
| 276 | - | i = atoi(arg); |
|
| 277 | - | if(i < 0 || i >= nlayouts) |
|
| 247 | + | for(i = 0; i < nlayouts; i++) |
|
| 248 | + | if(arg == layouts[i].symbol) |
|
| 249 | + | break; |
|
| 250 | + | if(i == nlayouts) |
|
| 278 | 251 | return; |
|
| 279 | 252 | ltidx = i; |
|
| 280 | 253 | } |
|
| 282 | 255 | arrange(); |
|
| 283 | 256 | else |
|
| 284 | 257 | drawstatus(); |
|
| 285 | - | setdwmprops(); |
|
| 286 | 258 | } |
|
| 287 | 259 | ||
| 288 | 260 | void |
|
| 296 | 268 | i = idxoftag(arg); |
|
| 297 | 269 | if(i >= 0 && i < ntags) |
|
| 298 | 270 | sel->tags[i] = True; |
|
| 299 | - | setprops(sel); |
|
| 300 | 271 | arrange(); |
|
| 301 | 272 | } |
|
| 302 | 273 | ||
| 315 | 286 | if(!sel || isfloating()) |
|
| 316 | 287 | return; |
|
| 317 | 288 | sel->isfloating = !sel->isfloating; |
|
| 318 | - | if(sel->isfloating) { |
|
| 289 | + | if(sel->isfloating) |
|
| 319 | 290 | resize(sel, sel->x, sel->y, sel->w, sel->h, True); |
|
| 320 | - | setprops(sel); |
|
| 321 | - | } |
|
| 322 | 291 | arrange(); |
|
| 323 | 292 | } |
|
| 324 | 293 | ||
| 352 | 321 | for(j = 0; j < ntags && !sel->tags[j]; j++); |
|
| 353 | 322 | if(j == ntags) |
|
| 354 | 323 | sel->tags[i] = True; |
|
| 355 | - | setprops(sel); |
|
| 356 | 324 | arrange(); |
|
| 357 | 325 | } |
|
| 358 | 326 | ||
| 365 | 333 | for(j = 0; j < ntags && !seltags[j]; j++); |
|
| 366 | 334 | if(j == ntags) |
|
| 367 | 335 | seltags[i] = True; /* cannot toggle last view */ |
|
| 368 | - | setdwmprops(); |
|
| 369 | 336 | arrange(); |
|
| 370 | 337 | } |
|
| 371 | 338 | ||
| 404 | 371 | i = idxoftag(arg); |
|
| 405 | 372 | if(i >= 0 && i < ntags) |
|
| 406 | 373 | seltags[i] = True; |
|
| 407 | - | setdwmprops(); |
|
| 408 | 374 | arrange(); |
|
| 409 | 375 | } |
|