]> git.lizzy.rs Git - bspwm.git/blob - ewmh.c
Remove window borders whenever possible
[bspwm.git] / ewmh.c
1 #include <stdio.h>
2 #include <string.h>
3 #include <xcb/xcb_ewmh.h>
4 #include "types.h"
5 #include "bspwm.h"
6 #include "settings.h"
7 #include "tree.h"
8 #include "ewmh.h"
9
10 void ewmh_init(void)
11 {
12     ewmh = (xcb_ewmh_connection_t *) malloc(sizeof(xcb_ewmh_connection_t));
13     xcb_intern_atom_cookie_t *ewmh_cookies;
14     ewmh_cookies = xcb_ewmh_init_atoms(dpy, ewmh);
15     xcb_ewmh_init_atoms_replies(ewmh, ewmh_cookies, NULL);
16 }
17
18 void ewmh_update_wm_name(void)
19 {
20     if (wm_name != NULL)
21         xcb_ewmh_set_wm_name(ewmh, screen->root, strlen(wm_name), wm_name);
22 }
23
24 void ewmh_update_active_window(void)
25 {
26     xcb_window_t win = (desk->focus == NULL ? XCB_NONE : desk->focus->client->window);
27     xcb_ewmh_set_active_window(ewmh, default_screen, win);
28 }
29
30 void ewmh_update_number_of_desktops(void)
31 {
32     xcb_ewmh_set_number_of_desktops(ewmh, default_screen, num_desktops);
33 }
34
35 void ewmh_update_current_desktop(void)
36 {
37    desktop_t *d = desk_head;
38    unsigned int i = 0, cd = 0;
39
40    while (d != NULL && i < num_desktops) {
41        if (desk == d)
42            cd = i;
43        i++;
44        d = d->next;
45    }
46
47    xcb_ewmh_set_current_desktop(ewmh, default_screen, cd);
48 }
49
50 void ewmh_update_desktop_names(void)
51 {
52    char names[MAXLEN];
53    desktop_t *d = desk_head;
54    unsigned int pos, i;
55
56    pos = i = 0;
57
58    while (d != NULL && i < num_desktops) {
59        for (unsigned int j = 0; j < strlen(d->name); j++)
60            names[pos + j] = d->name[j];
61        pos += strlen(d->name);
62        names[pos] = '\0';
63        pos++;
64        d = d->next;
65        i++;
66    }
67
68    if (i != num_desktops)
69        return;
70
71    pos--;
72
73    xcb_ewmh_set_desktop_names(ewmh, default_screen, pos, names);
74 }
75
76 void ewmh_update_client_list(void)
77 {
78     if (num_clients == 0) {
79         xcb_ewmh_set_client_list(ewmh, default_screen, 0, NULL);
80         return;
81     }
82
83     xcb_window_t wins[num_clients];
84     desktop_t *d = desk_head;
85     unsigned int i = 0;
86
87     while (d != NULL && i < num_clients) {
88         node_t *n = first_extrema(d->root);
89         while (n != NULL) {
90             wins[i++] = n->client->window;
91             n = next_leaf(n);
92         }
93         d = d->next;
94     }
95
96     if (i != num_clients)
97         return;
98
99     xcb_ewmh_set_client_list(ewmh, default_screen, num_clients, wins);
100 }