]> git.lizzy.rs Git - bspwm.git/blobdiff - ewmh.c
Add the proper *quit* binding to the panel
[bspwm.git] / ewmh.c
diff --git a/ewmh.c b/ewmh.c
index f4014b03c11a13cb8554c68a534b6aa248929605..192cff12082284f351a11f3c9b9dd340db836108 100644 (file)
--- a/ewmh.c
+++ b/ewmh.c
@@ -1,5 +1,6 @@
 #include <stdio.h>
 #include <string.h>
+#include <unistd.h>
 #include <xcb/xcb_ewmh.h>
 #include "types.h"
 #include "bspwm.h"
@@ -14,12 +15,6 @@ void ewmh_init(void)
         err("Can't initialize EWMH atoms.\n");
 }
 
-void ewmh_update_wm_name(void)
-{
-    if (wm_name != NULL)
-        xcb_ewmh_set_wm_name(ewmh, root, strlen(wm_name), wm_name);
-}
-
 void ewmh_update_active_window(void)
 {
     xcb_window_t win = (mon->desk->focus == NULL ? XCB_NONE : mon->desk->focus->client->window);
@@ -38,20 +33,19 @@ uint32_t ewmh_get_desktop_index(desktop_t *d)
         for (desktop_t *cd = m->desk_head; cd != NULL; cd = cd->next, i++)
             if (d == cd)
                 return i;
-
     return 0;
 }
 
-bool ewmh_locate_desktop(uint32_t i, desktop_location_t *loc)
+bool ewmh_locate_desktop(uint32_t i, coordinates_t *loc)
 {
     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;
+                loc->node = NULL;
                 return true;
             }
-
     return false;
 }
 
@@ -67,32 +61,33 @@ void ewmh_set_wm_desktop(node_t *n, desktop_t *d)
     xcb_ewmh_set_wm_desktop(ewmh, n->client->window, i);
 }
 
+void ewmh_update_wm_desktops(void)
+{
+    for (monitor_t *m = mon_head; m != NULL; m = m->next)
+        for (desktop_t *d = m->desk_head; d != NULL; d = d->next) {
+            uint32_t i = ewmh_get_desktop_index(d);
+            for (node_t *n = first_extrema(d->root); n != NULL; n = next_leaf(n, d->root))
+                xcb_ewmh_set_wm_desktop(ewmh, n->client->window, i);
+        }
+}
+
 void ewmh_update_desktop_names(void)
 {
     char names[MAXLEN];
-    monitor_t *m = mon_head;
     unsigned int pos, i;
     pos = i = 0;
 
-    while (m != NULL) {
-        desktop_t *d = m->desk_head;
-
-        while (d != NULL && i < num_desktops) {
+    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++;
-            d = d->next;
-            i++;
+            pos++, i++;
         }
 
-        m = m->next;
-    }
-
     if (i != num_desktops)
         return;
-
     pos--;
 
     xcb_ewmh_set_desktop_names(ewmh, default_screen, pos, names);
@@ -102,6 +97,7 @@ 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;
     }
 
@@ -110,11 +106,21 @@ void ewmh_update_client_list(void)
 
     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))
+            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);
+}
+
+void ewmh_set_supporting(xcb_window_t win)
+{
+    pid_t wm_pid = getpid();
+    xcb_ewmh_set_supporting_wm_check(ewmh, root, win);
+    xcb_ewmh_set_supporting_wm_check(ewmh, win, win);
+    xcb_ewmh_set_wm_name(ewmh, win, strlen(WM_NAME), WM_NAME);
+    xcb_ewmh_set_wm_pid(ewmh, win, wm_pid);
 }