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)
78 for (monitor_t *m = mon_head; m != NULL; m = m->next)
79 for (desktop_t *d = m->desk_head; d != NULL; d = d->next) {
80 for (j = 0; d->name[j] != '\0' && (i + j) < sizeof(names); j++)
81 names[i + j] = d->name[j];
83 if (i < sizeof(names))
91 xcb_ewmh_set_desktop_names(ewmh, default_screen, names_len, names);
94 void ewmh_update_client_list(void)
96 if (num_clients == 0) {
97 xcb_ewmh_set_client_list(ewmh, default_screen, 0, NULL);
98 xcb_ewmh_set_client_list_stacking(ewmh, default_screen, 0, NULL);
102 xcb_window_t wins[num_clients];
105 for (monitor_t *m = mon_head; m != NULL; m = m->next)
106 for (desktop_t *d = m->desk_head; d != NULL; d = d->next)
107 for (node_t *n = first_extrema(d->root); n != NULL; n = next_leaf(n, d->root))
108 wins[i++] = n->client->window;
110 xcb_ewmh_set_client_list(ewmh, default_screen, num_clients, wins);
111 xcb_ewmh_set_client_list_stacking(ewmh, default_screen, num_clients, wins);
114 bool ewmh_wm_state_add(client_t *c, xcb_atom_t state)
116 if (c->num_states >= MAX_STATE)
118 for (int i = 0; i < c->num_states; i++)
119 if (c->wm_state[i] == state)
121 c->wm_state[c->num_states] = state;
123 xcb_ewmh_set_wm_state(ewmh, c->window, c->num_states, c->wm_state);
127 bool ewmh_wm_state_remove(client_t *c, xcb_atom_t state)
129 for (int i = 0; i < c->num_states; i++)
130 if (c->wm_state[i] == state)
132 for (int j = i; j < (c->num_states - 1); j++)
133 c->wm_state[j] = c->wm_state[j + 1];
135 xcb_ewmh_set_wm_state(ewmh, c->window, c->num_states, c->wm_state);
141 void ewmh_set_supporting(xcb_window_t win)
143 pid_t wm_pid = getpid();
144 xcb_ewmh_set_supporting_wm_check(ewmh, root, win);
145 xcb_ewmh_set_supporting_wm_check(ewmh, win, win);
146 xcb_ewmh_set_wm_name(ewmh, win, strlen(WM_NAME), WM_NAME);
147 xcb_ewmh_set_wm_pid(ewmh, win, wm_pid);