10 ewmh = malloc(sizeof(xcb_ewmh_connection_t));
11 if (xcb_ewmh_init_atoms_replies(ewmh, xcb_ewmh_init_atoms(dpy, ewmh), NULL) == 0)
12 err("Can't initialize EWMH atoms.\n");
15 void ewmh_update_active_window(void)
17 xcb_window_t win = (mon->desk->focus == NULL ? XCB_NONE : mon->desk->focus->client->window);
18 xcb_ewmh_set_active_window(ewmh, default_screen, win);
21 void ewmh_update_number_of_desktops(void)
23 xcb_ewmh_set_number_of_desktops(ewmh, default_screen, num_desktops);
26 uint32_t ewmh_get_desktop_index(desktop_t *d)
29 for (monitor_t *m = mon_head; m != NULL; m = m->next)
30 for (desktop_t *cd = m->desk_head; cd != NULL; cd = cd->next, i++)
36 bool ewmh_locate_desktop(uint32_t i, coordinates_t *loc)
38 for (monitor_t *m = mon_head; m != NULL; m = m->next)
39 for (desktop_t *d = m->desk_head; d != NULL; d = d->next, i--)
49 void ewmh_update_current_desktop(void)
51 uint32_t i = ewmh_get_desktop_index(mon->desk);
52 xcb_ewmh_set_current_desktop(ewmh, default_screen, i);
55 void ewmh_set_wm_desktop(node_t *n, desktop_t *d)
57 uint32_t i = ewmh_get_desktop_index(d);
58 xcb_ewmh_set_wm_desktop(ewmh, n->client->window, i);
61 void ewmh_update_wm_desktops(void)
63 for (monitor_t *m = mon_head; m != NULL; m = m->next)
64 for (desktop_t *d = m->desk_head; d != NULL; d = d->next) {
65 uint32_t i = ewmh_get_desktop_index(d);
66 for (node_t *n = first_extrema(d->root); n != NULL; n = next_leaf(n, d->root))
67 xcb_ewmh_set_wm_desktop(ewmh, n->client->window, i);
71 void ewmh_update_desktop_names(void)
77 for (monitor_t *m = mon_head; m != NULL; m = m->next)
78 for (desktop_t *d = m->desk_head; d != NULL && i < num_desktops; d = d->next) {
79 for (unsigned int j = 0; j < strlen(d->name); j++)
80 names[pos + j] = d->name[j];
81 pos += strlen(d->name);
86 if (i != num_desktops)
90 xcb_ewmh_set_desktop_names(ewmh, default_screen, pos, names);
93 void ewmh_update_client_list(void)
95 if (num_clients == 0) {
96 xcb_ewmh_set_client_list(ewmh, default_screen, 0, NULL);
97 xcb_ewmh_set_client_list_stacking(ewmh, default_screen, 0, NULL);
101 xcb_window_t wins[num_clients];
104 for (monitor_t *m = mon_head; m != NULL; m = m->next)
105 for (desktop_t *d = m->desk_head; d != NULL; d = d->next)
106 for (node_t *n = first_extrema(d->root); n != NULL; n = next_leaf(n, d->root))
107 wins[i++] = n->client->window;
109 if (i != num_clients)
112 xcb_ewmh_set_client_list(ewmh, default_screen, num_clients, wins);
113 xcb_ewmh_set_client_list_stacking(ewmh, default_screen, num_clients, wins);
116 void ewmh_set_supporting(xcb_window_t win)
118 pid_t wm_pid = getpid();
119 xcb_ewmh_set_supporting_wm_check(ewmh, root, win);
120 xcb_ewmh_set_supporting_wm_check(ewmh, win, win);
121 xcb_ewmh_set_wm_name(ewmh, win, strlen(WM_NAME), WM_NAME);
122 xcb_ewmh_set_wm_pid(ewmh, win, wm_pid);