tags should be persistent now during X server run
9e56e1de
4 file(s) · +33 −7
| 81 | 81 | extern unsigned int bh, blw, bpos; /* bar height, bar layout label width, bar position */ |
|
| 82 | 82 | extern unsigned int ntags, numlockmask; /* number of tags, numlock mask */ |
|
| 83 | 83 | extern void (*handler[LASTEvent])(XEvent *); /* event handler */ |
|
| 84 | - | extern Atom wmatom[WMLast], netatom[NetLast]; |
|
| 84 | + | extern Atom dwmtags, wmatom[WMLast], netatom[NetLast]; |
|
| 85 | 85 | extern Bool selscreen, *seltag; /* seltag is array of Bool */ |
|
| 86 | 86 | extern Client *clients, *sel, *stack; /* global client list and stack */ |
|
| 87 | 87 | extern Cursor cursor[CurLast]; |
| 2 | 2 | #include "dwm.h" |
|
| 3 | 3 | #include <stdlib.h> |
|
| 4 | 4 | ||
| 5 | + | /* static */ |
|
| 6 | + | ||
| 5 | 7 | typedef struct { |
|
| 6 | 8 | const char *symbol; |
|
| 7 | 9 | void (*arrange)(void); |
|
| 10 | 12 | unsigned int blw = 0; |
|
| 11 | 13 | static Layout *lt = NULL; |
|
| 12 | 14 | ||
| 13 | - | /* static */ |
|
| 14 | - | ||
| 15 | 15 | static void |
|
| 16 | - | floating(void) { |
|
| 16 | + | floating(void) { /* default floating layout */ |
|
| 17 | 17 | Client *c; |
|
| 18 | 18 | ||
| 19 | 19 | for(c = clients; c; c = c->next) |
|
| 19 | 19 | unsigned int bh, ntags; |
|
| 20 | 20 | unsigned int bpos = BARPOS; |
|
| 21 | 21 | unsigned int numlockmask = 0; |
|
| 22 | - | Atom wmatom[WMLast], netatom[NetLast]; |
|
| 22 | + | Atom dwmtags, wmatom[WMLast], netatom[NetLast]; |
|
| 23 | 23 | Bool *seltag; |
|
| 24 | 24 | Bool selscreen = True; |
|
| 25 | 25 | Client *clients = NULL; |
|
| 139 | 139 | XSetWindowAttributes wa; |
|
| 140 | 140 | ||
| 141 | 141 | /* init atoms */ |
|
| 142 | + | dwmtags = XInternAtom(dpy, "__DWM_TAGS", False); |
|
| 142 | 143 | wmatom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False); |
|
| 143 | 144 | wmatom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False); |
|
| 144 | 145 | wmatom[WMState] = XInternAtom(dpy, "WM_STATE", False); |
|
| 3 | 3 | #include <regex.h> |
|
| 4 | 4 | #include <stdio.h> |
|
| 5 | 5 | #include <stdlib.h> |
|
| 6 | + | #include <string.h> |
|
| 7 | + | #include <X11/Xatom.h> |
|
| 6 | 8 | #include <X11/Xutil.h> |
|
| 7 | 9 | ||
| 8 | 10 | /* static */ |
|
| 23 | 25 | ||
| 24 | 26 | static Regs *regs = NULL; |
|
| 25 | 27 | static unsigned int nrules = 0; |
|
| 28 | + | static char prop[512]; |
|
| 26 | 29 | ||
| 27 | 30 | /* extern */ |
|
| 28 | 31 | ||
| 65 | 68 | ||
| 66 | 69 | void |
|
| 67 | 70 | settags(Client *c, Client *trans) { |
|
| 68 | - | char prop[512]; |
|
| 69 | 71 | unsigned int i, j; |
|
| 70 | 72 | regmatch_t tmp; |
|
| 71 | 73 | Bool matched = trans != NULL; |
|
| 72 | 74 | XClassHint ch = { 0 }; |
|
| 75 | + | XTextProperty name; |
|
| 73 | 76 | ||
| 74 | - | if(matched) |
|
| 77 | + | if(matched) { |
|
| 75 | 78 | for(i = 0; i < ntags; i++) |
|
| 76 | 79 | c->tags[i] = trans->tags[i]; |
|
| 80 | + | return; |
|
| 81 | + | } |
|
| 77 | 82 | else { |
|
| 83 | + | /* check if window has set a property */ |
|
| 84 | + | name.nitems = 0; |
|
| 85 | + | XGetTextProperty(dpy, c->win, &name, dwmtags); |
|
| 86 | + | if(name.nitems && name.encoding == XA_STRING) { |
|
| 87 | + | strncpy(prop, (char *)name.value, sizeof prop - 1); |
|
| 88 | + | prop[sizeof prop - 1] = '\0'; |
|
| 89 | + | XFree(name.value); |
|
| 90 | + | for(i = 0; i < ntags && i < sizeof prop - 1 && prop[i] != '\0'; i++) |
|
| 91 | + | if((c->tags[i] = prop[i] == '+')) |
|
| 92 | + | matched = True; |
|
| 93 | + | } |
|
| 94 | + | if(matched) |
|
| 95 | + | return; |
|
| 96 | + | /* rule matching */ |
|
| 78 | 97 | XGetClassHint(dpy, c->win, &ch); |
|
| 79 | 98 | snprintf(prop, sizeof prop, "%s:%s:%s", |
|
| 80 | 99 | ch.res_class ? ch.res_class : "", |
|
| 110 | 129 | i = arg ? atoi(arg) : 0; |
|
| 111 | 130 | if(i >= 0 && i < ntags) |
|
| 112 | 131 | sel->tags[i] = True; |
|
| 132 | + | if(sel) { |
|
| 133 | + | for(i = 0; i < ntags && i < sizeof prop - 1; i++) |
|
| 134 | + | prop[i] = sel->tags[i] ? '+' : '-'; |
|
| 135 | + | prop[i] = '\0'; |
|
| 136 | + | XChangeProperty(dpy, sel->win, dwmtags, XA_STRING, 8, PropModeReplace, (unsigned char *)prop, i); |
|
| 137 | + | } |
|
| 113 | 138 | arrange(); |
|
| 114 | 139 | } |
|
| 115 | 140 | ||