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_VIEWPORT, which is an array of pairs of cardinals that
66 * define the top left corner of each desktop's viewport.
68 void ewmh_update_desktop_viewport(void) {
71 /* count number of desktops */
72 TAILQ_FOREACH(output, &(croot->nodes_head), nodes) {
74 TAILQ_FOREACH(ws, &(output_get_content(output)->nodes_head), nodes) {
75 if (STARTS_WITH(ws->name, "__"))
82 uint32_t viewports[num_desktops * 2];
84 int current_position = 0;
85 /* fill the viewport buffer */
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 viewports[current_position++] = output->rect.x;
93 viewports[current_position++] = output->rect.y;
97 xcb_change_property(conn, XCB_PROP_MODE_REPLACE, root,
98 A__NET_DESKTOP_VIEWPORT, XCB_ATOM_CARDINAL, 32, current_position, &viewports);
102 * Updates _NET_ACTIVE_WINDOW with the currently focused window.
104 * EWMH: The window ID of the currently active window or None if no window has
108 void ewmh_update_active_window(xcb_window_t window) {
109 xcb_change_property(conn, XCB_PROP_MODE_REPLACE, root,
110 A__NET_ACTIVE_WINDOW, XCB_ATOM_WINDOW, 32, 1, &window);
114 * i3 currently does not support _NET_WORKAREA, because it does not correspond
115 * to i3’s concept of workspaces. See also:
116 * http://bugs.i3wm.org/539
117 * http://bugs.i3wm.org/301
118 * http://bugs.i3wm.org/1038
120 * We need to actively delete this property because some display managers (e.g.
123 * EWMH: Contains a geometry for each desktop. These geometries specify an area
124 * that is completely contained within the viewport. Work area SHOULD be used by
125 * desktop applications to place desktop icons appropriately.
128 void ewmh_update_workarea(void) {
129 xcb_delete_property(conn, root, A__NET_WORKAREA);
133 * Updates the _NET_CLIENT_LIST hint.
136 void ewmh_update_client_list(xcb_window_t *list, int num_windows) {
139 XCB_PROP_MODE_REPLACE,
149 * Updates the _NET_CLIENT_LIST_STACKING hint.
152 void ewmh_update_client_list_stacking(xcb_window_t *stack, int num_windows) {
155 XCB_PROP_MODE_REPLACE,
157 A__NET_CLIENT_LIST_STACKING,
165 * Set up the EWMH hints on the root window.
168 void ewmh_setup_hints(void) {
169 xcb_atom_t supported_atoms[] = {
170 #define xmacro(atom) A_##atom,
171 #include "atoms.xmacro"
175 /* Set up the window manager’s name. According to EWMH, section "Root Window
176 * Properties", to indicate that an EWMH-compliant window manager is
177 * present, a child window has to be created (and kept alive as long as the
178 * window manager is running) which has the _NET_SUPPORTING_WM_CHECK and
180 xcb_window_t child_window = xcb_generate_id(conn);
183 XCB_COPY_FROM_PARENT, /* depth */
184 child_window, /* window id */
186 0, 0, 1, 1, /* dimensions (x, y, w, h) */
188 XCB_WINDOW_CLASS_INPUT_ONLY, /* window class */
189 XCB_COPY_FROM_PARENT, /* visual */
192 xcb_change_property(conn, XCB_PROP_MODE_REPLACE, child_window, A__NET_SUPPORTING_WM_CHECK, XCB_ATOM_WINDOW, 32, 1, &child_window);
193 xcb_change_property(conn, XCB_PROP_MODE_REPLACE, child_window, A__NET_WM_NAME, A_UTF8_STRING, 8, strlen("i3"), "i3");
194 xcb_change_property(conn, XCB_PROP_MODE_REPLACE, root, A__NET_SUPPORTING_WM_CHECK, XCB_ATOM_WINDOW, 33, 1, &child_window);
196 /* I’m not entirely sure if we need to keep _NET_WM_NAME on root. */
197 xcb_change_property(conn, XCB_PROP_MODE_REPLACE, root, A__NET_WM_NAME, A_UTF8_STRING, 8, strlen("i3"), "i3");
199 xcb_change_property(conn, XCB_PROP_MODE_REPLACE, root, A__NET_SUPPORTED, XCB_ATOM_ATOM, 32, 20, supported_atoms);