2 #define I3__FILE__ "ewmh.c"
4 * vim:ts=4:sw=4:expandtab
6 * i3 - an improved dynamic tiling window manager
7 * © 2009-2011 Michael Stapelberg and contributors (see also: LICENSE)
9 * ewmh.c: Get/set certain EWMH properties easily.
15 * Updates _NET_CURRENT_DESKTOP with the current desktop number.
17 * EWMH: The index of the current desktop. This is always an integer between 0
18 * and _NET_NUMBER_OF_DESKTOPS - 1.
21 void ewmh_update_current_desktop(void) {
22 Con *focused_ws = con_get_workspace(focused);
25 /* We count to get the index of this workspace because named workspaces
26 * don’t have the ->num property */
27 TAILQ_FOREACH(output, &(croot->nodes_head), nodes) {
29 TAILQ_FOREACH(ws, &(output_get_content(output)->nodes_head), nodes) {
30 if (STARTS_WITH(ws->name, "__"))
33 if (ws == focused_ws) {
34 xcb_change_property(conn, XCB_PROP_MODE_REPLACE, root,
35 A__NET_CURRENT_DESKTOP, XCB_ATOM_CARDINAL, 32, 1, &idx);
44 * Updates _NET_NUMBER_OF_DESKTOPS which we interpret as the number of
45 * noninternal workspaces.
47 void ewmh_update_number_of_desktops(void) {
51 TAILQ_FOREACH(output, &(croot->nodes_head), nodes) {
53 TAILQ_FOREACH(ws, &(output_get_content(output)->nodes_head), nodes) {
54 if (STARTS_WITH(ws->name, "__"))
60 xcb_change_property(conn, XCB_PROP_MODE_REPLACE, root,
61 A__NET_NUMBER_OF_DESKTOPS, XCB_ATOM_CARDINAL, 32, 1, &idx);
65 * Updates _NET_DESKTOP_NAMES: "The names of all virtual desktops. This is a
66 * list of NULL-terminated strings in UTF-8 encoding"
68 void ewmh_update_desktop_names(void) {
72 /* count the size of the property message to set */
73 TAILQ_FOREACH(output, &(croot->nodes_head), nodes) {
75 TAILQ_FOREACH(ws, &(output_get_content(output)->nodes_head), nodes) {
76 if (STARTS_WITH(ws->name, "__"))
78 msg_length += strlen(ws->name) + 1;
82 char desktop_names[msg_length];
83 int current_position = 0;
85 /* fill the buffer with the names of the i3 workspaces */
86 TAILQ_FOREACH(output, &(croot->nodes_head), nodes) {
88 TAILQ_FOREACH(ws, &(output_get_content(output)->nodes_head), nodes) {
89 if (STARTS_WITH(ws->name, "__"))
92 for (size_t i = 0; i < strlen(ws->name) + 1; i++) {
93 desktop_names[current_position++] = ws->name[i];
98 xcb_change_property(conn, XCB_PROP_MODE_REPLACE, root,
99 A__NET_DESKTOP_NAMES, A_UTF8_STRING, 8, msg_length, desktop_names);
103 * Updates _NET_DESKTOP_VIEWPORT, which is an array of pairs of cardinals that
104 * define the top left corner of each desktop's viewport.
106 void ewmh_update_desktop_viewport(void) {
108 int num_desktops = 0;
109 /* count number of desktops */
110 TAILQ_FOREACH(output, &(croot->nodes_head), nodes) {
112 TAILQ_FOREACH(ws, &(output_get_content(output)->nodes_head), nodes) {
113 if (STARTS_WITH(ws->name, "__"))
120 uint32_t viewports[num_desktops * 2];
122 int current_position = 0;
123 /* fill the viewport buffer */
124 TAILQ_FOREACH(output, &(croot->nodes_head), nodes) {
126 TAILQ_FOREACH(ws, &(output_get_content(output)->nodes_head), nodes) {
127 if (STARTS_WITH(ws->name, "__"))
130 viewports[current_position++] = output->rect.x;
131 viewports[current_position++] = output->rect.y;
135 xcb_change_property(conn, XCB_PROP_MODE_REPLACE, root,
136 A__NET_DESKTOP_VIEWPORT, XCB_ATOM_CARDINAL, 32, current_position, &viewports);
140 * Updates _NET_ACTIVE_WINDOW with the currently focused window.
142 * EWMH: The window ID of the currently active window or None if no window has
146 void ewmh_update_active_window(xcb_window_t window) {
147 xcb_change_property(conn, XCB_PROP_MODE_REPLACE, root,
148 A__NET_ACTIVE_WINDOW, XCB_ATOM_WINDOW, 32, 1, &window);
152 * i3 currently does not support _NET_WORKAREA, because it does not correspond
153 * to i3’s concept of workspaces. See also:
154 * http://bugs.i3wm.org/539
155 * http://bugs.i3wm.org/301
156 * http://bugs.i3wm.org/1038
158 * We need to actively delete this property because some display managers (e.g.
161 * EWMH: Contains a geometry for each desktop. These geometries specify an area
162 * that is completely contained within the viewport. Work area SHOULD be used by
163 * desktop applications to place desktop icons appropriately.
166 void ewmh_update_workarea(void) {
167 xcb_delete_property(conn, root, A__NET_WORKAREA);
171 * Updates the _NET_CLIENT_LIST hint.
174 void ewmh_update_client_list(xcb_window_t *list, int num_windows) {
177 XCB_PROP_MODE_REPLACE,
187 * Updates the _NET_CLIENT_LIST_STACKING hint.
190 void ewmh_update_client_list_stacking(xcb_window_t *stack, int num_windows) {
193 XCB_PROP_MODE_REPLACE,
195 A__NET_CLIENT_LIST_STACKING,
203 * Set up the EWMH hints on the root window.
206 void ewmh_setup_hints(void) {
207 xcb_atom_t supported_atoms[] = {
208 #define xmacro(atom) A_##atom,
209 #include "atoms.xmacro"
213 /* Set up the window manager’s name. According to EWMH, section "Root Window
214 * Properties", to indicate that an EWMH-compliant window manager is
215 * present, a child window has to be created (and kept alive as long as the
216 * window manager is running) which has the _NET_SUPPORTING_WM_CHECK and
218 xcb_window_t child_window = xcb_generate_id(conn);
221 XCB_COPY_FROM_PARENT, /* depth */
222 child_window, /* window id */
224 0, 0, 1, 1, /* dimensions (x, y, w, h) */
226 XCB_WINDOW_CLASS_INPUT_ONLY, /* window class */
227 XCB_COPY_FROM_PARENT, /* visual */
230 xcb_change_property(conn, XCB_PROP_MODE_REPLACE, child_window, A__NET_SUPPORTING_WM_CHECK, XCB_ATOM_WINDOW, 32, 1, &child_window);
231 xcb_change_property(conn, XCB_PROP_MODE_REPLACE, child_window, A__NET_WM_NAME, A_UTF8_STRING, 8, strlen("i3"), "i3");
232 xcb_change_property(conn, XCB_PROP_MODE_REPLACE, root, A__NET_SUPPORTING_WM_CHECK, XCB_ATOM_WINDOW, 32, 1, &child_window);
234 /* I’m not entirely sure if we need to keep _NET_WM_NAME on root. */
235 xcb_change_property(conn, XCB_PROP_MODE_REPLACE, root, A__NET_WM_NAME, A_UTF8_STRING, 8, strlen("i3"), "i3");
237 /* only send the first 24 atoms (last one is _NET_CLOSE_WINDOW) increment that number when adding supported atoms */
238 xcb_change_property(conn, XCB_PROP_MODE_REPLACE, root, A__NET_SUPPORTED, XCB_ATOM_ATOM, 32, 24, supported_atoms);