bar_anybar.c (1931B)
1 void 2 managealtbar(Window win, XWindowAttributes *wa) 3 { 4 Monitor *m; 5 Bar *bar; 6 int i = 0; 7 if (!(m = recttomon(wa->x, wa->y, wa->width, wa->height))) 8 return; 9 for (bar = m->bar; bar && bar->win && bar->next; bar = bar->next); // find last bar 10 if (!bar) { 11 bar = m->bar = ecalloc(1, sizeof(Bar)); 12 bar->topbar = topbar; 13 } else if (bar && bar->win) { 14 i = bar->idx + 1; 15 bar->next = ecalloc(1, sizeof(Bar)); 16 #if BAR_ANYBAR_TOP_AND_BOTTOM_BARS_PATCH 17 bar->next->topbar = !bar->topbar; 18 #else 19 bar->next->topbar = topbar; 20 #endif // BAR_ANYBAR_TOP_AND_BOTTOM_BARS_PATCH 21 bar = bar->next; 22 } 23 bar->external = 1; 24 bar->showbar = 1; 25 bar->mon = m; 26 bar->idx = i; 27 bar->borderpx = 0; 28 bar->win = win; 29 bar->bw = wa->width; 30 bar->bh = wa->height; 31 updatebarpos(m); 32 arrange(m); 33 XSelectInput(dpy, win, EnterWindowMask|FocusChangeMask|PropertyChangeMask|StructureNotifyMask); 34 XMapWindow(dpy, win); 35 XMoveResizeWindow(dpy, bar->win, bar->bx, bar->by, bar->bw, bar->bh); 36 arrange(selmon); 37 XChangeProperty(dpy, root, netatom[NetClientList], XA_WINDOW, 32, PropModeAppend, 38 (unsigned char *) &win, 1); 39 } 40 41 void 42 spawnbar() 43 { 44 if (*altbarcmd) 45 system(altbarcmd); 46 } 47 48 void 49 unmanagealtbar(Window w) 50 { 51 Monitor *m = wintomon(w); 52 Bar *bar, *next, *prev = NULL; 53 54 if (!m) 55 return; 56 57 for (bar = m->bar; bar && bar->win; bar = next) { 58 next = bar->next; 59 if (bar->win == w) { 60 if (prev) 61 prev->next = next; 62 else 63 m->bar = next; 64 free(bar); 65 break; 66 } 67 prev = bar; 68 } 69 updatebarpos(m); 70 arrange(m); 71 } 72 73 int 74 wmclasscontains(Window win, const char *class, const char *name) 75 { 76 XClassHint ch = { NULL, NULL }; 77 int res = 1; 78 79 if (XGetClassHint(dpy, win, &ch)) { 80 if (ch.res_name && strstr(ch.res_name, name) == NULL) 81 res = 0; 82 if (ch.res_class && strstr(ch.res_class, class) == NULL) 83 res = 0; 84 } else 85 res = 0; 86 87 if (ch.res_class) 88 XFree(ch.res_class); 89 if (ch.res_name) 90 XFree(ch.res_name); 91 92 return res; 93 } 94