]> git.lizzy.rs Git - bspwm.git/blobdiff - ewmh.c
Reset stacking client list whenever appropriate
[bspwm.git] / ewmh.c
diff --git a/ewmh.c b/ewmh.c
index 4de6a4b2664f2ff2359a1b537b29929898ba156d..d18ad385a26590a99fb6e6fbd25fd65e793ca273 100644 (file)
--- a/ewmh.c
+++ b/ewmh.c
@@ -9,21 +9,20 @@
 
 void ewmh_init(void)
 {
-    ewmh = (xcb_ewmh_connection_t *) malloc(sizeof(xcb_ewmh_connection_t));
-    xcb_intern_atom_cookie_t *ewmh_cookies;
-    ewmh_cookies = xcb_ewmh_init_atoms(dpy, ewmh);
-    xcb_ewmh_init_atoms_replies(ewmh, ewmh_cookies, NULL);
+    ewmh = malloc(sizeof(xcb_ewmh_connection_t));
+    if (xcb_ewmh_init_atoms_replies(ewmh, xcb_ewmh_init_atoms(dpy, ewmh), NULL) == 0)
+        err("Can't initialize EWMH atoms.\n");
 }
 
 void ewmh_update_wm_name(void)
 {
     if (wm_name != NULL)
-        xcb_ewmh_set_wm_name(ewmh, screen->root, strlen(wm_name), wm_name);
+        xcb_ewmh_set_wm_name(ewmh, root, strlen(wm_name), wm_name);
 }
 
 void ewmh_update_active_window(void)
 {
-    xcb_window_t win = (desk->focus == NULL ? XCB_NONE : desk->focus->client->window);
+    xcb_window_t win = (mon->desk->focus == NULL ? XCB_NONE : mon->desk->focus->client->window);
     xcb_ewmh_set_active_window(ewmh, default_screen, win);
 }
 
@@ -32,69 +31,83 @@ void ewmh_update_number_of_desktops(void)
     xcb_ewmh_set_number_of_desktops(ewmh, default_screen, num_desktops);
 }
 
-void ewmh_update_current_desktop(void)
+uint32_t ewmh_get_desktop_index(desktop_t *d)
 {
-   desktop_t *d = desk_head;
-   unsigned int i = 0, cd = 0;
-
-   while (d != NULL && i < num_desktops) {
-       if (desk == d)
-           cd = i;
-       i++;
-       d = d->next;
-   }
+    uint32_t i = 0;
+    for (monitor_t *m = mon_head; m != NULL; m = m->next)
+        for (desktop_t *cd = m->desk_head; cd != NULL; cd = cd->next, i++)
+            if (d == cd)
+                return i;
 
-   xcb_ewmh_set_current_desktop(ewmh, default_screen, cd);
+    return 0;
 }
 
-void ewmh_update_desktop_names(void)
+bool ewmh_locate_desktop(uint32_t i, desktop_location_t *loc)
 {
-   char names[MAXLEN];
-   desktop_t *d = desk_head;
-   unsigned int pos, i;
+    for (monitor_t *m = mon_head; m != NULL; m = m->next)
+        for (desktop_t *d = m->desk_head; d != NULL; d = d->next, i--)
+            if (i == 0) {
+                loc->monitor = m;
+                loc->desktop = d;
+                return true;
+            }
+
+    return false;
+}
 
-   pos = i = 0;
+void ewmh_update_current_desktop(void)
+{
+    uint32_t i = ewmh_get_desktop_index(mon->desk);
+    xcb_ewmh_set_current_desktop(ewmh, default_screen, i);
+}
 
-   while (d != NULL && i < num_desktops) {
-       for (unsigned int j = 0; j < strlen(d->name); j++)
-           names[pos + j] = d->name[j];
-       pos += strlen(d->name);
-       names[pos] = '\0';
-       pos++;
-       d = d->next;
-       i++;
-   }
+void ewmh_set_wm_desktop(node_t *n, desktop_t *d)
+{
+    uint32_t i = ewmh_get_desktop_index(d);
+    xcb_ewmh_set_wm_desktop(ewmh, n->client->window, i);
+}
 
-   if (i != num_desktops)
-       return;
+void ewmh_update_desktop_names(void)
+{
+    char names[MAXLEN];
+    unsigned int pos, i;
+    pos = i = 0;
+
+    for (monitor_t *m = mon_head; m != NULL; m = m->next)
+        for (desktop_t *d = m->desk_head; d != NULL && i < num_desktops; d = d->next) {
+            for (unsigned int j = 0; j < strlen(d->name); j++)
+                names[pos + j] = d->name[j];
+            pos += strlen(d->name);
+            names[pos] = '\0';
+            pos++, i++;
+        }
 
-   pos--;
+    if (i != num_desktops)
+        return;
+    pos--;
 
-   xcb_ewmh_set_desktop_names(ewmh, default_screen, pos, names);
+    xcb_ewmh_set_desktop_names(ewmh, default_screen, pos, names);
 }
 
 void ewmh_update_client_list(void)
 {
     if (num_clients == 0) {
         xcb_ewmh_set_client_list(ewmh, default_screen, 0, NULL);
+        xcb_ewmh_set_client_list_stacking(ewmh, default_screen, 0, NULL);
         return;
     }
 
     xcb_window_t wins[num_clients];
-    desktop_t *d = desk_head;
     unsigned int i = 0;
 
-    while (d != NULL && i < num_clients) {
-        node_t *n = first_extrema(d->root);
-        while (n != NULL) {
-            wins[i++] = n->client->window;
-            n = next_leaf(n);
-        }
-        d = d->next;
-    }
+    for (monitor_t *m = mon_head; m != NULL; m = m->next)
+        for (desktop_t *d = m->desk_head; d != NULL; d = d->next)
+            for (node_t *n = first_extrema(d->root); n != NULL; n = next_leaf(n, d->root))
+                wins[i++] = n->client->window;
 
     if (i != num_clients)
         return;
 
     xcb_ewmh_set_client_list(ewmh, default_screen, num_clients, wins);
+    xcb_ewmh_set_client_list_stacking(ewmh, default_screen, num_clients, wins);
 }