i3
handlers.c
Go to the documentation of this file.
1 /*
2  * vim:ts=4:sw=4:expandtab
3  *
4  * i3 - an improved dynamic tiling window manager
5  * © 2009 Michael Stapelberg and contributors (see also: LICENSE)
6  *
7  * handlers.c: Small handlers for various events (keypresses, focus changes,
8  * …).
9  *
10  */
11 #include "all.h"
12 
13 #include <sys/time.h>
14 #include <time.h>
15 
16 #include <xcb/randr.h>
17 #define SN_API_NOT_YET_FROZEN 1
18 #include <libsn/sn-monitor.h>
19 
20 int randr_base = -1;
21 int xkb_base = -1;
23 int shape_base = -1;
24 
25 /* After mapping/unmapping windows, a notify event is generated. However, we don’t want it,
26  since it’d trigger an infinite loop of switching between the different windows when
27  changing workspaces */
28 static SLIST_HEAD(ignore_head, Ignore_Event) ignore_events;
29 
30 /*
31  * Adds the given sequence to the list of events which are ignored.
32  * If this ignore should only affect a specific response_type, pass
33  * response_type, otherwise, pass -1.
34  *
35  * Every ignored sequence number gets garbage collected after 5 seconds.
36  *
37  */
38 void add_ignore_event(const int sequence, const int response_type) {
39  struct Ignore_Event *event = smalloc(sizeof(struct Ignore_Event));
40 
41  event->sequence = sequence;
42  event->response_type = response_type;
43  event->added = time(NULL);
44 
45  SLIST_INSERT_HEAD(&ignore_events, event, ignore_events);
46 }
47 
48 /*
49  * Checks if the given sequence is ignored and returns true if so.
50  *
51  */
52 bool event_is_ignored(const int sequence, const int response_type) {
53  struct Ignore_Event *event;
54  time_t now = time(NULL);
55  for (event = SLIST_FIRST(&ignore_events); event != SLIST_END(&ignore_events);) {
56  if ((now - event->added) > 5) {
57  struct Ignore_Event *save = event;
58  event = SLIST_NEXT(event, ignore_events);
59  SLIST_REMOVE(&ignore_events, save, Ignore_Event, ignore_events);
60  free(save);
61  } else
62  event = SLIST_NEXT(event, ignore_events);
63  }
64 
65  SLIST_FOREACH (event, &ignore_events, ignore_events) {
66  if (event->sequence != sequence)
67  continue;
68 
69  if (event->response_type != -1 &&
70  event->response_type != response_type)
71  continue;
72 
73  /* Instead of removing & freeing a sequence number we better wait until
74  * it gets garbage collected. It may generate multiple events (there
75  * are multiple enter_notifies for one configure_request, for example). */
76  return true;
77  }
78 
79  return false;
80 }
81 
82 /*
83  * Called with coordinates of an enter_notify event or motion_notify event
84  * to check if the user crossed virtual screen boundaries and adjust the
85  * current workspace, if so.
86  *
87  */
88 static void check_crossing_screen_boundary(uint32_t x, uint32_t y) {
89  Output *output;
90 
91  /* If the user disable focus follows mouse, we have nothing to do here */
93  return;
94 
95  if ((output = get_output_containing(x, y)) == NULL) {
96  ELOG("ERROR: No such screen\n");
97  return;
98  }
99 
100  if (output->con == NULL) {
101  ELOG("ERROR: The screen is not recognized by i3 (no container associated)\n");
102  return;
103  }
104 
105  /* Focus the output on which the user moved their cursor */
106  Con *old_focused = focused;
107  Con *next = con_descend_focused(output_get_content(output->con));
108  /* Since we are switching outputs, this *must* be a different workspace, so
109  * call workspace_show() */
111  con_focus(next);
112 
113  /* If the focus changed, we re-render to get updated decorations */
114  if (old_focused != focused)
115  tree_render();
116 }
117 
118 /*
119  * When the user moves the mouse pointer onto a window, this callback gets called.
120  *
121  */
122 static void handle_enter_notify(xcb_enter_notify_event_t *event) {
123  Con *con;
124 
125  last_timestamp = event->time;
126 
127  DLOG("enter_notify for %08x, mode = %d, detail %d, serial %d\n",
128  event->event, event->mode, event->detail, event->sequence);
129  DLOG("coordinates %d, %d\n", event->event_x, event->event_y);
130  if (event->mode != XCB_NOTIFY_MODE_NORMAL) {
131  DLOG("This was not a normal notify, ignoring\n");
132  return;
133  }
134  /* Some events are not interesting, because they were not generated
135  * actively by the user, but by reconfiguration of windows */
136  if (event_is_ignored(event->sequence, XCB_ENTER_NOTIFY)) {
137  DLOG("Event ignored\n");
138  return;
139  }
140 
141  bool enter_child = false;
142  /* Get container by frame or by child window */
143  if ((con = con_by_frame_id(event->event)) == NULL) {
144  con = con_by_window_id(event->event);
145  enter_child = true;
146  }
147 
148  /* If we cannot find the container, the user moved their cursor to the root
149  * window. In this case and if they used it to a dock, we need to focus the
150  * workspace on the correct output. */
151  if (con == NULL || con->parent->type == CT_DOCKAREA) {
152  DLOG("Getting screen at %d x %d\n", event->root_x, event->root_y);
153  check_crossing_screen_boundary(event->root_x, event->root_y);
154  return;
155  }
156 
157  /* see if the user entered the window on a certain window decoration */
158  layout_t layout = (enter_child ? con->parent->layout : con->layout);
159  if (layout == L_DEFAULT) {
160  Con *child;
161  TAILQ_FOREACH_REVERSE (child, &(con->nodes_head), nodes_head, nodes) {
162  if (rect_contains(child->deco_rect, event->event_x, event->event_y)) {
163  LOG("using child %p / %s instead!\n", child, child->name);
164  con = child;
165  break;
166  }
167  }
168  }
169 
171  return;
172 
173  /* if this container is already focused, there is nothing to do. */
174  if (con == focused)
175  return;
176 
177  /* Get the currently focused workspace to check if the focus change also
178  * involves changing workspaces. If so, we need to call workspace_show() to
179  * correctly update state and send the IPC event. */
180  Con *ws = con_get_workspace(con);
181  if (ws != con_get_workspace(focused))
182  workspace_show(ws);
183 
184  focused_id = XCB_NONE;
186  tree_render();
187 }
188 
189 /*
190  * When the user moves the mouse but does not change the active window
191  * (e.g. when having no windows opened but moving mouse on the root screen
192  * and crossing virtual screen boundaries), this callback gets called.
193  *
194  */
195 static void handle_motion_notify(xcb_motion_notify_event_t *event) {
196  last_timestamp = event->time;
197 
198  /* Skip events where the pointer was over a child window, we are only
199  * interested in events on the root window. */
200  if (event->child != XCB_NONE)
201  return;
202 
203  Con *con;
204  if ((con = con_by_frame_id(event->event)) == NULL) {
205  DLOG("MotionNotify for an unknown container, checking if it crosses screen boundaries.\n");
206  check_crossing_screen_boundary(event->root_x, event->root_y);
207  return;
208  }
209 
211  return;
212 
213  if (con->layout != L_DEFAULT && con->layout != L_SPLITV && con->layout != L_SPLITH)
214  return;
215 
216  /* see over which rect the user is */
217  if (con->window != NULL) {
218  if (rect_contains(con->deco_rect, event->event_x, event->event_y)) {
219  /* We found the rect, let’s see if this window is focused */
220  if (TAILQ_FIRST(&(con->parent->focus_head)) == con)
221  return;
222 
223  con_focus(con);
225  return;
226  }
227  } else {
228  Con *current;
229  TAILQ_FOREACH_REVERSE (current, &(con->nodes_head), nodes_head, nodes) {
230  if (!rect_contains(current->deco_rect, event->event_x, event->event_y))
231  continue;
232 
233  /* We found the rect, let’s see if this window is focused */
234  if (TAILQ_FIRST(&(con->focus_head)) == current)
235  return;
236 
237  con_focus(current);
239  return;
240  }
241  }
242 }
243 
244 /*
245  * Called when the keyboard mapping changes (for example by using Xmodmap),
246  * we need to update our key bindings then (re-translate symbols).
247  *
248  */
249 static void handle_mapping_notify(xcb_mapping_notify_event_t *event) {
250  if (event->request != XCB_MAPPING_KEYBOARD &&
251  event->request != XCB_MAPPING_MODIFIER)
252  return;
253 
254  DLOG("Received mapping_notify for keyboard or modifier mapping, re-grabbing keys\n");
255  xcb_refresh_keyboard_mapping(keysyms, event);
256 
258 
262 }
263 
264 /*
265  * A new window appeared on the screen (=was mapped), so let’s manage it.
266  *
267  */
268 static void handle_map_request(xcb_map_request_event_t *event) {
269  xcb_get_window_attributes_cookie_t cookie;
270 
271  cookie = xcb_get_window_attributes_unchecked(conn, event->window);
272 
273  DLOG("window = 0x%08x, serial is %d.\n", event->window, event->sequence);
274  add_ignore_event(event->sequence, -1);
275 
276  manage_window(event->window, cookie, false);
277 }
278 
279 /*
280  * Configure requests are received when the application wants to resize windows
281  * on their own.
282  *
283  * We generate a synthetic configure notify event to signalize the client its
284  * "new" position.
285  *
286  */
287 static void handle_configure_request(xcb_configure_request_event_t *event) {
288  Con *con;
289 
290  DLOG("window 0x%08x wants to be at %dx%d with %dx%d\n",
291  event->window, event->x, event->y, event->width, event->height);
292 
293  /* For unmanaged windows, we just execute the configure request. As soon as
294  * it gets mapped, we will take over anyways. */
295  if ((con = con_by_window_id(event->window)) == NULL) {
296  DLOG("Configure request for unmanaged window, can do that.\n");
297 
298  uint32_t mask = 0;
299  uint32_t values[7];
300  int c = 0;
301 #define COPY_MASK_MEMBER(mask_member, event_member) \
302  do { \
303  if (event->value_mask & mask_member) { \
304  mask |= mask_member; \
305  values[c++] = event->event_member; \
306  } \
307  } while (0)
308 
309  COPY_MASK_MEMBER(XCB_CONFIG_WINDOW_X, x);
310  COPY_MASK_MEMBER(XCB_CONFIG_WINDOW_Y, y);
311  COPY_MASK_MEMBER(XCB_CONFIG_WINDOW_WIDTH, width);
312  COPY_MASK_MEMBER(XCB_CONFIG_WINDOW_HEIGHT, height);
313  COPY_MASK_MEMBER(XCB_CONFIG_WINDOW_BORDER_WIDTH, border_width);
314  COPY_MASK_MEMBER(XCB_CONFIG_WINDOW_SIBLING, sibling);
315  COPY_MASK_MEMBER(XCB_CONFIG_WINDOW_STACK_MODE, stack_mode);
316 
317  xcb_configure_window(conn, event->window, mask, values);
318  xcb_flush(conn);
319 
320  return;
321  }
322 
323  DLOG("Configure request!\n");
324 
325  Con *workspace = con_get_workspace(con);
326  if (workspace && (strcmp(workspace->name, "__i3_scratch") == 0)) {
327  DLOG("This is a scratchpad container, ignoring ConfigureRequest\n");
328  goto out;
329  }
330  Con *fullscreen = con_get_fullscreen_covering_ws(workspace);
331 
332  if (fullscreen != con && con_is_floating(con) && con_is_leaf(con)) {
333  /* we actually need to apply the size/position changes to the *parent*
334  * container */
335  Rect bsr = con_border_style_rect(con);
336  Con *floatingcon = con->parent;
337  Rect newrect = floatingcon->rect;
338 
339  if (event->value_mask & XCB_CONFIG_WINDOW_X) {
340  newrect.x = event->x + (-1) * bsr.x;
341  DLOG("proposed x = %d, new x is %d\n", event->x, newrect.x);
342  }
343  if (event->value_mask & XCB_CONFIG_WINDOW_Y) {
344  newrect.y = event->y + (-1) * bsr.y;
345  DLOG("proposed y = %d, new y is %d\n", event->y, newrect.y);
346  }
347  if (event->value_mask & XCB_CONFIG_WINDOW_WIDTH) {
348  newrect.width = event->width + (-1) * bsr.width;
349  newrect.width += con->border_width * 2;
350  DLOG("proposed width = %d, new width is %d (x11 border %d)\n",
351  event->width, newrect.width, con->border_width);
352  }
353  if (event->value_mask & XCB_CONFIG_WINDOW_HEIGHT) {
354  newrect.height = event->height + (-1) * bsr.height;
355  newrect.height += con->border_width * 2;
356  DLOG("proposed height = %d, new height is %d (x11 border %d)\n",
357  event->height, newrect.height, con->border_width);
358  }
359 
360  DLOG("Container is a floating leaf node, will do that.\n");
361  floating_reposition(floatingcon, newrect);
362  return;
363  }
364 
365  /* Dock windows can be reconfigured in their height and moved to another output. */
366  if (con->parent && con->parent->type == CT_DOCKAREA) {
367  DLOG("Reconfiguring dock window (con = %p).\n", con);
368  if (event->value_mask & XCB_CONFIG_WINDOW_HEIGHT) {
369  DLOG("Dock client wants to change height to %d, we can do that.\n", event->height);
370 
371  con->geometry.height = event->height;
372  tree_render();
373  }
374 
375  if (event->value_mask & XCB_CONFIG_WINDOW_X || event->value_mask & XCB_CONFIG_WINDOW_Y) {
376  int16_t x = event->value_mask & XCB_CONFIG_WINDOW_X ? event->x : (int16_t)con->geometry.x;
377  int16_t y = event->value_mask & XCB_CONFIG_WINDOW_Y ? event->y : (int16_t)con->geometry.y;
378 
379  Con *current_output = con_get_output(con);
380  Output *target = get_output_containing(x, y);
381  if (target != NULL && current_output != target->con) {
382  DLOG("Dock client is requested to be moved to output %s, moving it there.\n", output_primary_name(target));
383  Match *match;
384  Con *nc = con_for_window(target->con, con->window, &match);
385  DLOG("Dock client will be moved to container %p.\n", nc);
386  con_detach(con);
387  con_attach(con, nc, false);
388 
389  tree_render();
390  } else {
391  DLOG("Dock client will not be moved, we only support moving it to another output.\n");
392  }
393  }
394  goto out;
395  }
396 
397  if (event->value_mask & XCB_CONFIG_WINDOW_STACK_MODE) {
398  DLOG("window 0x%08x wants to be stacked %d\n", event->window, event->stack_mode);
399 
400  /* Emacs and IntelliJ Idea “request focus” by stacking their window
401  * above all others. */
402  if (event->stack_mode != XCB_STACK_MODE_ABOVE) {
403  DLOG("stack_mode != XCB_STACK_MODE_ABOVE, ignoring ConfigureRequest\n");
404  goto out;
405  }
406 
407  if (fullscreen || !con_is_leaf(con)) {
408  DLOG("fullscreen or not a leaf, ignoring ConfigureRequest\n");
409  goto out;
410  }
411 
412  if (workspace == NULL) {
413  DLOG("Window is not being managed, ignoring ConfigureRequest\n");
414  goto out;
415  }
416 
417  if (config.focus_on_window_activation == FOWA_FOCUS || (config.focus_on_window_activation == FOWA_SMART && workspace_is_visible(workspace))) {
418  DLOG("Focusing con = %p\n", con);
419  workspace_show(workspace);
421  tree_render();
422  } else if (config.focus_on_window_activation == FOWA_URGENT || (config.focus_on_window_activation == FOWA_SMART && !workspace_is_visible(workspace))) {
423  DLOG("Marking con = %p urgent\n", con);
424  con_set_urgency(con, true);
425  tree_render();
426  } else {
427  DLOG("Ignoring request for con = %p.\n", con);
428  }
429  }
430 
431 out:
433 }
434 
435 /*
436  * Gets triggered upon a RandR screen change event, that is when the user
437  * changes the screen configuration in any way (mode, position, …)
438  *
439  */
440 static void handle_screen_change(xcb_generic_event_t *e) {
441  DLOG("RandR screen change\n");
442 
443  /* The geometry of the root window is used for “fullscreen global” and
444  * changes when new outputs are added. */
445  xcb_get_geometry_cookie_t cookie = xcb_get_geometry(conn, root);
446  xcb_get_geometry_reply_t *reply = xcb_get_geometry_reply(conn, cookie, NULL);
447  if (reply == NULL) {
448  ELOG("Could not get geometry of the root window, exiting\n");
449  exit(EXIT_FAILURE);
450  }
451  DLOG("root geometry reply: (%d, %d) %d x %d\n", reply->x, reply->y, reply->width, reply->height);
452 
453  croot->rect.width = reply->width;
454  croot->rect.height = reply->height;
455 
457 
459 
460  ipc_send_event("output", I3_IPC_EVENT_OUTPUT, "{\"change\":\"unspecified\"}");
461 }
462 
463 /*
464  * Our window decorations were unmapped. That means, the window will be killed
465  * now, so we better clean up before.
466  *
467  */
468 static void handle_unmap_notify_event(xcb_unmap_notify_event_t *event) {
469  DLOG("UnmapNotify for 0x%08x (received from 0x%08x), serial %d\n", event->window, event->event, event->sequence);
470  xcb_get_input_focus_cookie_t cookie;
471  Con *con = con_by_window_id(event->window);
472  if (con == NULL) {
473  /* This could also be an UnmapNotify for the frame. We need to
474  * decrement the ignore_unmap counter. */
475  con = con_by_frame_id(event->window);
476  if (con == NULL) {
477  LOG("Not a managed window, ignoring UnmapNotify event\n");
478  return;
479  }
480 
481  if (con->ignore_unmap > 0)
482  con->ignore_unmap--;
483  /* See the end of this function. */
484  cookie = xcb_get_input_focus(conn);
485  DLOG("ignore_unmap = %d for frame of container %p\n", con->ignore_unmap, con);
486  goto ignore_end;
487  }
488 
489  /* See the end of this function. */
490  cookie = xcb_get_input_focus(conn);
491 
492  if (con->ignore_unmap > 0) {
493  DLOG("ignore_unmap = %d, dec\n", con->ignore_unmap);
494  con->ignore_unmap--;
495  goto ignore_end;
496  }
497 
498  /* Since we close the container, we need to unset _NET_WM_DESKTOP and
499  * _NET_WM_STATE according to the spec. */
500  xcb_delete_property(conn, event->window, A__NET_WM_DESKTOP);
501  xcb_delete_property(conn, event->window, A__NET_WM_STATE);
502 
504  tree_render();
505 
506 ignore_end:
507  /* If the client (as opposed to i3) destroyed or unmapped a window, an
508  * EnterNotify event will follow (indistinguishable from an EnterNotify
509  * event caused by moving your mouse), causing i3 to set focus to whichever
510  * window is now visible.
511  *
512  * In a complex stacked or tabbed layout (take two v-split containers in a
513  * tabbed container), when the bottom window in tab2 is closed, the bottom
514  * window of tab1 is visible instead. X11 will thus send an EnterNotify
515  * event for the bottom window of tab1, while the focus should be set to
516  * the remaining window of tab2.
517  *
518  * Therefore, we ignore all EnterNotify events which have the same sequence
519  * as an UnmapNotify event. */
520  add_ignore_event(event->sequence, XCB_ENTER_NOTIFY);
521 
522  /* Since we just ignored the sequence of this UnmapNotify, we want to make
523  * sure that following events use a different sequence. When putting xterm
524  * into fullscreen and moving the pointer to a different window, without
525  * using GetInputFocus, subsequent (legitimate) EnterNotify events arrived
526  * with the same sequence and thus were ignored (see ticket #609). */
527  free(xcb_get_input_focus_reply(conn, cookie, NULL));
528 }
529 
530 /*
531  * A destroy notify event is sent when the window is not unmapped, but
532  * immediately destroyed (for example when starting a window and immediately
533  * killing the program which started it).
534  *
535  * We just pass on the event to the unmap notify handler (by copying the
536  * important fields in the event data structure).
537  *
538  */
539 static void handle_destroy_notify_event(xcb_destroy_notify_event_t *event) {
540  DLOG("destroy notify for 0x%08x, 0x%08x\n", event->event, event->window);
541 
542  xcb_unmap_notify_event_t unmap;
543  unmap.sequence = event->sequence;
544  unmap.event = event->event;
545  unmap.window = event->window;
546 
548 }
549 
550 static bool window_name_changed(i3Window *window, char *old_name) {
551  if ((old_name == NULL) && (window->name == NULL))
552  return false;
553 
554  /* Either the old or the new one is NULL, but not both. */
555  if ((old_name == NULL) ^ (window->name == NULL))
556  return true;
557 
558  return (strcmp(old_name, i3string_as_utf8(window->name)) != 0);
559 }
560 
561 /*
562  * Called when a window changes its title
563  *
564  */
565 static bool handle_windowname_change(Con *con, xcb_get_property_reply_t *prop) {
566  char *old_name = (con->window->name != NULL ? sstrdup(i3string_as_utf8(con->window->name)) : NULL);
567 
568  window_update_name(con->window, prop);
569 
570  con = remanage_window(con);
571 
573 
574  if (window_name_changed(con->window, old_name))
575  ipc_send_window_event("title", con);
576 
577  FREE(old_name);
578 
579  return true;
580 }
581 
582 /*
583  * Handles legacy window name updates (WM_NAME), see also src/window.c,
584  * window_update_name_legacy().
585  *
586  */
587 static bool handle_windowname_change_legacy(Con *con, xcb_get_property_reply_t *prop) {
588  char *old_name = (con->window->name != NULL ? sstrdup(i3string_as_utf8(con->window->name)) : NULL);
589 
590  window_update_name_legacy(con->window, prop);
591 
592  con = remanage_window(con);
593 
595 
596  if (window_name_changed(con->window, old_name))
597  ipc_send_window_event("title", con);
598 
599  FREE(old_name);
600 
601  return true;
602 }
603 
604 /*
605  * Called when a window changes its WM_WINDOW_ROLE.
606  *
607  */
608 static bool handle_windowrole_change(Con *con, xcb_get_property_reply_t *prop) {
609  window_update_role(con->window, prop);
610 
611  con = remanage_window(con);
612 
613  return true;
614 }
615 
616 /*
617  * Expose event means we should redraw our windows (= title bar)
618  *
619  */
620 static void handle_expose_event(xcb_expose_event_t *event) {
621  Con *parent;
622 
623  DLOG("window = %08x\n", event->window);
624 
625  if ((parent = con_by_frame_id(event->window)) == NULL) {
626  LOG("expose event for unknown window, ignoring\n");
627  return;
628  }
629 
630  /* Since we render to our surface on every change anyways, expose events
631  * only tell us that the X server lost (parts of) the window contents. */
632  draw_util_copy_surface(&(parent->frame_buffer), &(parent->frame),
633  0, 0, 0, 0, parent->rect.width, parent->rect.height);
634  xcb_flush(conn);
635 }
636 
637 #define _NET_WM_MOVERESIZE_SIZE_TOPLEFT 0
638 #define _NET_WM_MOVERESIZE_SIZE_TOP 1
639 #define _NET_WM_MOVERESIZE_SIZE_TOPRIGHT 2
640 #define _NET_WM_MOVERESIZE_SIZE_RIGHT 3
641 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT 4
642 #define _NET_WM_MOVERESIZE_SIZE_BOTTOM 5
643 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT 6
644 #define _NET_WM_MOVERESIZE_SIZE_LEFT 7
645 #define _NET_WM_MOVERESIZE_MOVE 8 /* movement only */
646 #define _NET_WM_MOVERESIZE_SIZE_KEYBOARD 9 /* size via keyboard */
647 #define _NET_WM_MOVERESIZE_MOVE_KEYBOARD 10 /* move via keyboard */
648 #define _NET_WM_MOVERESIZE_CANCEL 11 /* cancel operation */
649 
650 #define _NET_MOVERESIZE_WINDOW_X (1 << 8)
651 #define _NET_MOVERESIZE_WINDOW_Y (1 << 9)
652 #define _NET_MOVERESIZE_WINDOW_WIDTH (1 << 10)
653 #define _NET_MOVERESIZE_WINDOW_HEIGHT (1 << 11)
654 
655 /*
656  * Handle client messages (EWMH)
657  *
658  */
659 static void handle_client_message(xcb_client_message_event_t *event) {
660  /* If this is a startup notification ClientMessage, the library will handle
661  * it and call our monitor_event() callback. */
662  if (sn_xcb_display_process_event(sndisplay, (xcb_generic_event_t *)event))
663  return;
664 
665  LOG("ClientMessage for window 0x%08x\n", event->window);
666  if (event->type == A__NET_WM_STATE) {
667  if (event->format != 32 ||
668  (event->data.data32[1] != A__NET_WM_STATE_FULLSCREEN &&
669  event->data.data32[1] != A__NET_WM_STATE_DEMANDS_ATTENTION &&
670  event->data.data32[1] != A__NET_WM_STATE_STICKY)) {
671  DLOG("Unknown atom in clientmessage of type %d\n", event->data.data32[1]);
672  return;
673  }
674 
675  Con *con = con_by_window_id(event->window);
676  if (con == NULL) {
677  DLOG("Could not get window for client message\n");
678  return;
679  }
680 
681  if (event->data.data32[1] == A__NET_WM_STATE_FULLSCREEN) {
682  /* Check if the fullscreen state should be toggled */
683  if ((con->fullscreen_mode != CF_NONE &&
684  (event->data.data32[0] == _NET_WM_STATE_REMOVE ||
685  event->data.data32[0] == _NET_WM_STATE_TOGGLE)) ||
686  (con->fullscreen_mode == CF_NONE &&
687  (event->data.data32[0] == _NET_WM_STATE_ADD ||
688  event->data.data32[0] == _NET_WM_STATE_TOGGLE))) {
689  DLOG("toggling fullscreen\n");
691  }
692  } else if (event->data.data32[1] == A__NET_WM_STATE_DEMANDS_ATTENTION) {
693  /* Check if the urgent flag must be set or not */
694  if (event->data.data32[0] == _NET_WM_STATE_ADD)
695  con_set_urgency(con, true);
696  else if (event->data.data32[0] == _NET_WM_STATE_REMOVE)
697  con_set_urgency(con, false);
698  else if (event->data.data32[0] == _NET_WM_STATE_TOGGLE)
699  con_set_urgency(con, !con->urgent);
700  } else if (event->data.data32[1] == A__NET_WM_STATE_STICKY) {
701  DLOG("Received a client message to modify _NET_WM_STATE_STICKY.\n");
702  if (event->data.data32[0] == _NET_WM_STATE_ADD)
703  con->sticky = true;
704  else if (event->data.data32[0] == _NET_WM_STATE_REMOVE)
705  con->sticky = false;
706  else if (event->data.data32[0] == _NET_WM_STATE_TOGGLE)
707  con->sticky = !con->sticky;
708 
709  DLOG("New sticky status for con = %p is %i.\n", con, con->sticky);
710  ewmh_update_sticky(con->window->id, con->sticky);
713  }
714 
715  tree_render();
716  } else if (event->type == A__NET_ACTIVE_WINDOW) {
717  if (event->format != 32)
718  return;
719 
720  DLOG("_NET_ACTIVE_WINDOW: Window 0x%08x should be activated\n", event->window);
721 
722  Con *con = con_by_window_id(event->window);
723  if (con == NULL) {
724  DLOG("Could not get window for client message\n");
725  return;
726  }
727 
728  Con *ws = con_get_workspace(con);
729  if (ws == NULL) {
730  DLOG("Window is not being managed, ignoring _NET_ACTIVE_WINDOW\n");
731  return;
732  }
733 
734  if (con_is_internal(ws) && ws != workspace_get("__i3_scratch")) {
735  DLOG("Workspace is internal but not scratchpad, ignoring _NET_ACTIVE_WINDOW\n");
736  return;
737  }
738 
739  /* data32[0] indicates the source of the request (application or pager) */
740  if (event->data.data32[0] == 2) {
741  /* Always focus the con if it is from a pager, because this is most
742  * likely from some user action */
743  DLOG("This request came from a pager. Focusing con = %p\n", con);
744 
745  if (con_is_internal(ws)) {
746  scratchpad_show(con);
747  } else {
748  workspace_show(ws);
749  /* Re-set focus, even if unchanged from i3’s perspective. */
750  focused_id = XCB_NONE;
752  }
753  } else {
754  /* Request is from an application. */
755  if (con_is_internal(ws)) {
756  DLOG("Ignoring request to make con = %p active because it's on an internal workspace.\n", con);
757  return;
758  }
759 
760  if (config.focus_on_window_activation == FOWA_FOCUS || (config.focus_on_window_activation == FOWA_SMART && workspace_is_visible(ws))) {
761  DLOG("Focusing con = %p\n", con);
763  } else if (config.focus_on_window_activation == FOWA_URGENT || (config.focus_on_window_activation == FOWA_SMART && !workspace_is_visible(ws))) {
764  DLOG("Marking con = %p urgent\n", con);
765  con_set_urgency(con, true);
766  } else
767  DLOG("Ignoring request for con = %p.\n", con);
768  }
769 
770  tree_render();
771  } else if (event->type == A_I3_SYNC) {
772  xcb_window_t window = event->data.data32[0];
773  uint32_t rnd = event->data.data32[1];
774  sync_respond(window, rnd);
775  } else if (event->type == A__NET_REQUEST_FRAME_EXTENTS) {
776  /*
777  * A client can request an estimate for the frame size which the window
778  * manager will put around it before actually mapping its window. Java
779  * does this (as of openjdk-7).
780  *
781  * Note that the calculation below is not entirely accurate — once you
782  * set a different border type, it’s off. We _could_ request all the
783  * window properties (which have to be set up at this point according
784  * to EWMH), but that seems rather elaborate. The standard explicitly
785  * says the application must cope with an estimate that is not entirely
786  * accurate.
787  */
788  DLOG("_NET_REQUEST_FRAME_EXTENTS for window 0x%08x\n", event->window);
789 
790  /* The reply data: approximate frame size */
791  Rect r = {
792  config.default_border_width, /* left */
793  config.default_border_width, /* right */
794  render_deco_height(), /* top */
795  config.default_border_width /* bottom */
796  };
797  xcb_change_property(
798  conn,
799  XCB_PROP_MODE_REPLACE,
800  event->window,
801  A__NET_FRAME_EXTENTS,
802  XCB_ATOM_CARDINAL, 32, 4,
803  &r);
804  xcb_flush(conn);
805  } else if (event->type == A_WM_CHANGE_STATE) {
806  /* http://tronche.com/gui/x/icccm/sec-4.html#s-4.1.4 */
807  if (event->data.data32[0] == XCB_ICCCM_WM_STATE_ICONIC) {
808  /* For compatibility reasons, Wine will request iconic state and cannot ensure that the WM has agreed on it;
809  * immediately revert to normal to avoid being stuck in a paused state. */
810  DLOG("Client has requested iconic state, rejecting. (window = %08x)\n", event->window);
811  long data[] = {XCB_ICCCM_WM_STATE_NORMAL, XCB_NONE};
812  xcb_change_property(conn, XCB_PROP_MODE_REPLACE, event->window,
813  A_WM_STATE, A_WM_STATE, 32, 2, data);
814  } else {
815  DLOG("Not handling WM_CHANGE_STATE request. (window = %08x, state = %d)\n", event->window, event->data.data32[0]);
816  }
817  } else if (event->type == A__NET_CURRENT_DESKTOP) {
818  /* This request is used by pagers and bars to change the current
819  * desktop likely as a result of some user action. We interpret this as
820  * a request to focus the given workspace. See
821  * https://standards.freedesktop.org/wm-spec/latest/ar01s03.html#idm140251368135008
822  * */
823  DLOG("Request to change current desktop to index %d\n", event->data.data32[0]);
824  Con *ws = ewmh_get_workspace_by_index(event->data.data32[0]);
825  if (ws == NULL) {
826  ELOG("Could not determine workspace for this index, ignoring request.\n");
827  return;
828  }
829 
830  DLOG("Handling request to focus workspace %s\n", ws->name);
831  workspace_show(ws);
832  tree_render();
833  } else if (event->type == A__NET_WM_DESKTOP) {
834  uint32_t index = event->data.data32[0];
835  DLOG("Request to move window %d to EWMH desktop index %d\n", event->window, index);
836 
837  Con *con = con_by_window_id(event->window);
838  if (con == NULL) {
839  DLOG("Couldn't find con for window %d, ignoring the request.\n", event->window);
840  return;
841  }
842 
843  if (index == NET_WM_DESKTOP_ALL) {
844  /* The window is requesting to be visible on all workspaces, so
845  * let's float it and make it sticky. */
846  DLOG("The window was requested to be visible on all workspaces, making it sticky and floating.\n");
847 
848  if (floating_enable(con, false)) {
849  con->floating = FLOATING_AUTO_ON;
850 
851  con->sticky = true;
852  ewmh_update_sticky(con->window->id, true);
854  }
855  } else {
856  Con *ws = ewmh_get_workspace_by_index(index);
857  if (ws == NULL) {
858  ELOG("Could not determine workspace for this index, ignoring request.\n");
859  return;
860  }
861 
862  con_move_to_workspace(con, ws, true, false, false);
863  }
864 
865  tree_render();
867  } else if (event->type == A__NET_CLOSE_WINDOW) {
868  /*
869  * Pagers wanting to close a window MUST send a _NET_CLOSE_WINDOW
870  * client message request to the root window.
871  * https://standards.freedesktop.org/wm-spec/wm-spec-latest.html#idm140200472668896
872  */
873  Con *con = con_by_window_id(event->window);
874  if (con) {
875  DLOG("Handling _NET_CLOSE_WINDOW request (con = %p)\n", con);
876 
877  if (event->data.data32[0])
878  last_timestamp = event->data.data32[0];
879 
880  tree_close_internal(con, KILL_WINDOW, false);
881  tree_render();
882  } else {
883  DLOG("Couldn't find con for _NET_CLOSE_WINDOW request. (window = %08x)\n", event->window);
884  }
885  } else if (event->type == A__NET_WM_MOVERESIZE) {
886  /*
887  * Client-side decorated Gtk3 windows emit this signal when being
888  * dragged by their GtkHeaderBar
889  */
890  Con *con = con_by_window_id(event->window);
891  if (!con || !con_is_floating(con)) {
892  DLOG("Couldn't find con for _NET_WM_MOVERESIZE request, or con not floating (window = %08x)\n", event->window);
893  return;
894  }
895  DLOG("Handling _NET_WM_MOVERESIZE request (con = %p)\n", con);
896  uint32_t direction = event->data.data32[2];
897  uint32_t x_root = event->data.data32[0];
898  uint32_t y_root = event->data.data32[1];
899  /* construct fake xcb_button_press_event_t */
900  xcb_button_press_event_t fake = {
901  .root_x = x_root,
902  .root_y = y_root,
903  .event_x = x_root - (con->rect.x),
904  .event_y = y_root - (con->rect.y)};
905  switch (direction) {
907  floating_drag_window(con->parent, &fake, false);
908  break;
910  floating_resize_window(con->parent, false, &fake);
911  break;
912  default:
913  DLOG("_NET_WM_MOVERESIZE direction %d not implemented\n", direction);
914  break;
915  }
916  } else if (event->type == A__NET_MOVERESIZE_WINDOW) {
917  DLOG("Received _NET_MOVE_RESIZE_WINDOW. Handling by faking a configure request.\n");
918 
919  void *_generated_event = scalloc(32, 1);
920  xcb_configure_request_event_t *generated_event = _generated_event;
921 
922  generated_event->window = event->window;
923  generated_event->response_type = XCB_CONFIGURE_REQUEST;
924 
925  generated_event->value_mask = 0;
926  if (event->data.data32[0] & _NET_MOVERESIZE_WINDOW_X) {
927  generated_event->value_mask |= XCB_CONFIG_WINDOW_X;
928  generated_event->x = event->data.data32[1];
929  }
930  if (event->data.data32[0] & _NET_MOVERESIZE_WINDOW_Y) {
931  generated_event->value_mask |= XCB_CONFIG_WINDOW_Y;
932  generated_event->y = event->data.data32[2];
933  }
934  if (event->data.data32[0] & _NET_MOVERESIZE_WINDOW_WIDTH) {
935  generated_event->value_mask |= XCB_CONFIG_WINDOW_WIDTH;
936  generated_event->width = event->data.data32[3];
937  }
938  if (event->data.data32[0] & _NET_MOVERESIZE_WINDOW_HEIGHT) {
939  generated_event->value_mask |= XCB_CONFIG_WINDOW_HEIGHT;
940  generated_event->height = event->data.data32[4];
941  }
942 
943  handle_configure_request(generated_event);
944  FREE(generated_event);
945  } else {
946  DLOG("Skipping client message for unhandled type %d\n", event->type);
947  }
948 }
949 
950 static bool handle_window_type(Con *con, xcb_get_property_reply_t *reply) {
951  window_update_type(con->window, reply);
952  return true;
953 }
954 
955 /*
956  * Handles the size hints set by a window, but currently only the part necessary for displaying
957  * clients proportionally inside their frames (mplayer for example)
958  *
959  * See ICCCM 4.1.2.3 for more details
960  *
961  */
962 static bool handle_normal_hints(Con *con, xcb_get_property_reply_t *reply) {
963  bool changed = window_update_normal_hints(con->window, reply, NULL);
964 
965  if (changed) {
966  Con *floating = con_inside_floating(con);
967  if (floating) {
968  floating_check_size(con, false);
969  tree_render();
970  }
971  }
972 
973  FREE(reply);
974  return true;
975 }
976 
977 /*
978  * Handles the WM_HINTS property for extracting the urgency state of the window.
979  *
980  */
981 static bool handle_hints(Con *con, xcb_get_property_reply_t *reply) {
982  bool urgency_hint;
983  window_update_hints(con->window, reply, &urgency_hint);
984  con_set_urgency(con, urgency_hint);
985  tree_render();
986  return true;
987 }
988 
989 /*
990  * Handles the transient for hints set by a window, signalizing that this window is a popup window
991  * for some other window.
992  *
993  * See ICCCM 4.1.2.6 for more details
994  *
995  */
996 static bool handle_transient_for(Con *con, xcb_get_property_reply_t *prop) {
998  return true;
999 }
1000 
1001 /*
1002  * Handles changes of the WM_CLIENT_LEADER atom which specifies if this is a
1003  * toolwindow (or similar) and to which window it belongs (logical parent).
1004  *
1005  */
1006 static bool handle_clientleader_change(Con *con, xcb_get_property_reply_t *prop) {
1007  window_update_leader(con->window, prop);
1008  return true;
1009 }
1010 
1011 /*
1012  * Handles FocusIn events which are generated by clients (i3’s focus changes
1013  * don’t generate FocusIn events due to a different EventMask) and updates the
1014  * decorations accordingly.
1015  *
1016  */
1017 static void handle_focus_in(xcb_focus_in_event_t *event) {
1018  DLOG("focus change in, for window 0x%08x\n", event->event);
1019 
1020  if (event->event == root) {
1021  DLOG("Received focus in for root window, refocusing the focused window.\n");
1022  con_focus(focused);
1023  focused_id = XCB_NONE;
1025  }
1026 
1027  Con *con;
1028  if ((con = con_by_window_id(event->event)) == NULL || con->window == NULL)
1029  return;
1030  DLOG("That is con %p / %s\n", con, con->name);
1031 
1032  if (event->mode == XCB_NOTIFY_MODE_GRAB ||
1033  event->mode == XCB_NOTIFY_MODE_UNGRAB) {
1034  DLOG("FocusIn event for grab/ungrab, ignoring\n");
1035  return;
1036  }
1037 
1038  if (event->detail == XCB_NOTIFY_DETAIL_POINTER) {
1039  DLOG("notify detail is pointer, ignoring this event\n");
1040  return;
1041  }
1042 
1043  /* Floating windows should be refocused to ensure that they are on top of
1044  * other windows. */
1045  if (focused_id == event->event && !con_inside_floating(con)) {
1046  DLOG("focus matches the currently focused window, not doing anything\n");
1047  return;
1048  }
1049 
1050  /* Skip dock clients, they cannot get the i3 focus. */
1051  if (con->parent->type == CT_DOCKAREA) {
1052  DLOG("This is a dock client, not focusing.\n");
1053  return;
1054  }
1055 
1056  DLOG("focus is different / refocusing floating window: updating decorations\n");
1057 
1058  con_activate_unblock(con);
1059 
1060  /* We update focused_id because we don’t need to set focus again */
1061  focused_id = event->event;
1062  tree_render();
1063 }
1064 
1065 /*
1066  * Log FocusOut events.
1067  *
1068  */
1069 static void handle_focus_out(xcb_focus_in_event_t *event) {
1070  Con *con = con_by_window_id(event->event);
1071  const char *window_name, *mode, *detail;
1072 
1073  if (con != NULL) {
1074  window_name = con->name;
1075  if (window_name == NULL) {
1076  window_name = "<unnamed con>";
1077  }
1078  } else if (event->event == root) {
1079  window_name = "<the root window>";
1080  } else {
1081  window_name = "<unknown window>";
1082  }
1083 
1084  switch (event->mode) {
1085  case XCB_NOTIFY_MODE_NORMAL:
1086  mode = "Normal";
1087  break;
1088  case XCB_NOTIFY_MODE_GRAB:
1089  mode = "Grab";
1090  break;
1091  case XCB_NOTIFY_MODE_UNGRAB:
1092  mode = "Ungrab";
1093  break;
1094  case XCB_NOTIFY_MODE_WHILE_GRABBED:
1095  mode = "WhileGrabbed";
1096  break;
1097  default:
1098  mode = "<unknown>";
1099  break;
1100  }
1101 
1102  switch (event->detail) {
1103  case XCB_NOTIFY_DETAIL_ANCESTOR:
1104  detail = "Ancestor";
1105  break;
1106  case XCB_NOTIFY_DETAIL_VIRTUAL:
1107  detail = "Virtual";
1108  break;
1109  case XCB_NOTIFY_DETAIL_INFERIOR:
1110  detail = "Inferior";
1111  break;
1112  case XCB_NOTIFY_DETAIL_NONLINEAR:
1113  detail = "Nonlinear";
1114  break;
1115  case XCB_NOTIFY_DETAIL_NONLINEAR_VIRTUAL:
1116  detail = "NonlinearVirtual";
1117  break;
1118  case XCB_NOTIFY_DETAIL_POINTER:
1119  detail = "Pointer";
1120  break;
1121  case XCB_NOTIFY_DETAIL_POINTER_ROOT:
1122  detail = "PointerRoot";
1123  break;
1124  case XCB_NOTIFY_DETAIL_NONE:
1125  detail = "NONE";
1126  break;
1127  default:
1128  detail = "unknown";
1129  break;
1130  }
1131 
1132  DLOG("focus change out: window 0x%08x (con %p, %s) lost focus with detail=%s, mode=%s\n", event->event, con, window_name, detail, mode);
1133 }
1134 
1135 /*
1136  * Handles ConfigureNotify events for the root window, which are generated when
1137  * the monitor configuration changed.
1138  *
1139  */
1140 static void handle_configure_notify(xcb_configure_notify_event_t *event) {
1141  if (event->event != root) {
1142  DLOG("ConfigureNotify for non-root window 0x%08x, ignoring\n", event->event);
1143  return;
1144  }
1145  DLOG("ConfigureNotify for root window 0x%08x\n", event->event);
1146 
1147  if (force_xinerama) {
1148  return;
1149  }
1151 
1152  ipc_send_event("output", I3_IPC_EVENT_OUTPUT, "{\"change\":\"unspecified\"}");
1153 }
1154 
1155 /*
1156  * Handles SelectionClear events for the root window, which are generated when
1157  * we lose ownership of a selection.
1158  */
1159 static void handle_selection_clear(xcb_selection_clear_event_t *event) {
1160  if (event->selection != wm_sn) {
1161  DLOG("SelectionClear for unknown selection %d, ignoring\n", event->selection);
1162  return;
1163  }
1164  LOG("Lost WM_Sn selection, exiting.\n");
1165  exit(EXIT_SUCCESS);
1166 
1167  /* unreachable */
1168 }
1169 
1170 /*
1171  * Handles the WM_CLASS property for assignments and criteria selection.
1172  *
1173  */
1174 static bool handle_class_change(Con *con, xcb_get_property_reply_t *prop) {
1175  window_update_class(con->window, prop);
1176  con = remanage_window(con);
1177  return true;
1178 }
1179 
1180 /*
1181  * Handles the WM_CLIENT_MACHINE property for assignments and criteria selection.
1182  *
1183  */
1184 static bool handle_machine_change(Con *con, xcb_get_property_reply_t *prop) {
1185  window_update_machine(con->window, prop);
1186  con = remanage_window(con);
1187  return true;
1188 }
1189 
1190 /*
1191  * Handles the _MOTIF_WM_HINTS property of specifying window deocration settings.
1192  *
1193  */
1194 static bool handle_motif_hints_change(Con *con, xcb_get_property_reply_t *prop) {
1195  border_style_t motif_border_style;
1196  bool has_mwm_hints = window_update_motif_hints(con->window, prop, &motif_border_style);
1197 
1198  if (has_mwm_hints && motif_border_style != con->border_style) {
1199  DLOG("Update border style of con %p to %d\n", con, motif_border_style);
1200  con_set_border_style(con, motif_border_style, con->current_border_width);
1201 
1203  }
1204 
1205  return true;
1206 }
1207 
1208 /*
1209  * Handles the _NET_WM_STRUT_PARTIAL property for allocating space for dock clients.
1210  *
1211  */
1212 static bool handle_strut_partial_change(Con *con, xcb_get_property_reply_t *prop) {
1213  window_update_strut_partial(con->window, prop);
1214 
1215  /* we only handle this change for dock clients */
1216  if (con->parent == NULL || con->parent->type != CT_DOCKAREA) {
1217  return true;
1218  }
1219 
1220  Con *search_at = croot;
1221  Con *output = con_get_output(con);
1222  if (output != NULL) {
1223  DLOG("Starting search at output %s\n", output->name);
1224  search_at = output;
1225  }
1226 
1227  /* find out the desired position of this dock window */
1228  if (con->window->reserved.top > 0 && con->window->reserved.bottom == 0) {
1229  DLOG("Top dock client\n");
1230  con->window->dock = W_DOCK_TOP;
1231  } else if (con->window->reserved.top == 0 && con->window->reserved.bottom > 0) {
1232  DLOG("Bottom dock client\n");
1233  con->window->dock = W_DOCK_BOTTOM;
1234  } else {
1235  DLOG("Ignoring invalid reserved edges (_NET_WM_STRUT_PARTIAL), using position as fallback:\n");
1236  if (con->geometry.y < (search_at->rect.height / 2)) {
1237  DLOG("geom->y = %d < rect.height / 2 = %d, it is a top dock client\n",
1238  con->geometry.y, (search_at->rect.height / 2));
1239  con->window->dock = W_DOCK_TOP;
1240  } else {
1241  DLOG("geom->y = %d >= rect.height / 2 = %d, it is a bottom dock client\n",
1242  con->geometry.y, (search_at->rect.height / 2));
1243  con->window->dock = W_DOCK_BOTTOM;
1244  }
1245  }
1246 
1247  /* find the dockarea */
1248  Con *dockarea = con_for_window(search_at, con->window, NULL);
1249  assert(dockarea != NULL);
1250 
1251  /* attach the dock to the dock area */
1252  con_detach(con);
1253  con_attach(con, dockarea, true);
1254 
1255  tree_render();
1256 
1257  return true;
1258 }
1259 
1260 /*
1261  * Handles the _I3_FLOATING_WINDOW property to properly run assignments for
1262  * floating window changes.
1263  *
1264  * This is needed to correctly run the assignments after changes in floating
1265  * windows which are triggered by user commands (floating enable | disable). In
1266  * that case, we can't call run_assignments because it will modify the parser
1267  * state when it needs to parse the user-specified action, breaking the parser
1268  * state for the original command.
1269  *
1270  */
1271 static bool handle_i3_floating(Con *con, xcb_get_property_reply_t *prop) {
1272  DLOG("floating change for con %p\n", con);
1273 
1274  remanage_window(con);
1275 
1276  return true;
1277 }
1278 
1279 static bool handle_windowicon_change(Con *con, xcb_get_property_reply_t *prop) {
1280  window_update_icon(con->window, prop);
1281 
1283 
1284  return true;
1285 }
1286 
1287 /* Returns false if the event could not be processed (e.g. the window could not
1288  * be found), true otherwise */
1289 typedef bool (*cb_property_handler_t)(Con *con, xcb_get_property_reply_t *property);
1290 
1292  xcb_atom_t atom;
1293  uint32_t long_len;
1295 };
1296 
1298  {0, 128, handle_windowname_change},
1299  {0, UINT_MAX, handle_hints},
1301  {0, UINT_MAX, handle_normal_hints},
1302  {0, UINT_MAX, handle_clientleader_change},
1303  {0, UINT_MAX, handle_transient_for},
1304  {0, 128, handle_windowrole_change},
1305  {0, 128, handle_class_change},
1306  {0, UINT_MAX, handle_strut_partial_change},
1307  {0, UINT_MAX, handle_window_type},
1308  {0, UINT_MAX, handle_i3_floating},
1309  {0, 128, handle_machine_change},
1310  {0, 5 * sizeof(uint64_t), handle_motif_hints_change},
1311  {0, UINT_MAX, handle_windowicon_change}};
1312 #define NUM_HANDLERS (sizeof(property_handlers) / sizeof(struct property_handler_t))
1313 
1314 /*
1315  * Sets the appropriate atoms for the property handlers after the atoms were
1316  * received from X11
1317  *
1318  */
1320  sn_monitor_context_new(sndisplay, conn_screen, startup_monitor_event, NULL, NULL);
1321 
1322  property_handlers[0].atom = A__NET_WM_NAME;
1323  property_handlers[1].atom = XCB_ATOM_WM_HINTS;
1324  property_handlers[2].atom = XCB_ATOM_WM_NAME;
1325  property_handlers[3].atom = XCB_ATOM_WM_NORMAL_HINTS;
1326  property_handlers[4].atom = A_WM_CLIENT_LEADER;
1327  property_handlers[5].atom = XCB_ATOM_WM_TRANSIENT_FOR;
1328  property_handlers[6].atom = A_WM_WINDOW_ROLE;
1329  property_handlers[7].atom = XCB_ATOM_WM_CLASS;
1330  property_handlers[8].atom = A__NET_WM_STRUT_PARTIAL;
1331  property_handlers[9].atom = A__NET_WM_WINDOW_TYPE;
1332  property_handlers[10].atom = A_I3_FLOATING_WINDOW;
1333  property_handlers[11].atom = XCB_ATOM_WM_CLIENT_MACHINE;
1334  property_handlers[12].atom = A__MOTIF_WM_HINTS;
1335  property_handlers[13].atom = A__NET_WM_ICON;
1336 }
1337 
1338 static void property_notify(uint8_t state, xcb_window_t window, xcb_atom_t atom) {
1339  struct property_handler_t *handler = NULL;
1340  xcb_get_property_reply_t *propr = NULL;
1341  xcb_generic_error_t *err = NULL;
1342  Con *con;
1343 
1344  for (size_t c = 0; c < NUM_HANDLERS; c++) {
1345  if (property_handlers[c].atom != atom)
1346  continue;
1347 
1348  handler = &property_handlers[c];
1349  break;
1350  }
1351 
1352  if (handler == NULL) {
1353  /* DLOG("Unhandled property notify for atom %d (0x%08x)\n", atom, atom); */
1354  return;
1355  }
1356 
1357  if ((con = con_by_window_id(window)) == NULL || con->window == NULL) {
1358  DLOG("Received property for atom %d for unknown client\n", atom);
1359  return;
1360  }
1361 
1362  if (state != XCB_PROPERTY_DELETE) {
1363  xcb_get_property_cookie_t cookie = xcb_get_property(conn, 0, window, atom, XCB_GET_PROPERTY_TYPE_ANY, 0, handler->long_len);
1364  propr = xcb_get_property_reply(conn, cookie, &err);
1365  if (err != NULL) {
1366  DLOG("got error %d when getting property of atom %d\n", err->error_code, atom);
1367  FREE(err);
1368  return;
1369  }
1370  }
1371 
1372  /* the handler will free() the reply unless it returns false */
1373  if (!handler->cb(con, propr))
1374  FREE(propr);
1375 }
1376 
1377 /*
1378  * Takes an xcb_generic_event_t and calls the appropriate handler, based on the
1379  * event type.
1380  *
1381  */
1382 void handle_event(int type, xcb_generic_event_t *event) {
1383  if (type != XCB_MOTION_NOTIFY)
1384  DLOG("event type %d, xkb_base %d\n", type, xkb_base);
1385 
1386  if (randr_base > -1 &&
1387  type == randr_base + XCB_RANDR_SCREEN_CHANGE_NOTIFY) {
1388  handle_screen_change(event);
1389  return;
1390  }
1391 
1392  if (xkb_base > -1 && type == xkb_base) {
1393  DLOG("xkb event, need to handle it.\n");
1394 
1395  xcb_xkb_state_notify_event_t *state = (xcb_xkb_state_notify_event_t *)event;
1396  if (state->xkbType == XCB_XKB_NEW_KEYBOARD_NOTIFY) {
1397  DLOG("xkb new keyboard notify, sequence %d, time %d\n", state->sequence, state->time);
1398  xcb_key_symbols_free(keysyms);
1399  keysyms = xcb_key_symbols_alloc(conn);
1400  if (((xcb_xkb_new_keyboard_notify_event_t *)event)->changed & XCB_XKB_NKN_DETAIL_KEYCODES)
1401  (void)load_keymap();
1405  } else if (state->xkbType == XCB_XKB_MAP_NOTIFY) {
1406  if (event_is_ignored(event->sequence, type)) {
1407  DLOG("Ignoring map notify event for sequence %d.\n", state->sequence);
1408  } else {
1409  DLOG("xkb map notify, sequence %d, time %d\n", state->sequence, state->time);
1410  add_ignore_event(event->sequence, type);
1411  xcb_key_symbols_free(keysyms);
1412  keysyms = xcb_key_symbols_alloc(conn);
1416  (void)load_keymap();
1417  }
1418  } else if (state->xkbType == XCB_XKB_STATE_NOTIFY) {
1419  DLOG("xkb state group = %d\n", state->group);
1420  if (xkb_current_group == state->group)
1421  return;
1422  xkb_current_group = state->group;
1425  }
1426 
1427  return;
1428  }
1429 
1430  if (shape_supported && type == shape_base + XCB_SHAPE_NOTIFY) {
1431  xcb_shape_notify_event_t *shape = (xcb_shape_notify_event_t *)event;
1432 
1433  DLOG("shape_notify_event for window 0x%08x, shape_kind = %d, shaped = %d\n",
1434  shape->affected_window, shape->shape_kind, shape->shaped);
1435 
1436  Con *con = con_by_window_id(shape->affected_window);
1437  if (con == NULL) {
1438  LOG("Not a managed window 0x%08x, ignoring shape_notify_event\n",
1439  shape->affected_window);
1440  return;
1441  }
1442 
1443  if (shape->shape_kind == XCB_SHAPE_SK_BOUNDING ||
1444  shape->shape_kind == XCB_SHAPE_SK_INPUT) {
1445  x_set_shape(con, shape->shape_kind, shape->shaped);
1446  }
1447 
1448  return;
1449  }
1450 
1451  switch (type) {
1452  case XCB_KEY_PRESS:
1453  case XCB_KEY_RELEASE:
1454  handle_key_press((xcb_key_press_event_t *)event);
1455  break;
1456 
1457  case XCB_BUTTON_PRESS:
1458  case XCB_BUTTON_RELEASE:
1459  handle_button_press((xcb_button_press_event_t *)event);
1460  break;
1461 
1462  case XCB_MAP_REQUEST:
1463  handle_map_request((xcb_map_request_event_t *)event);
1464  break;
1465 
1466  case XCB_UNMAP_NOTIFY:
1467  handle_unmap_notify_event((xcb_unmap_notify_event_t *)event);
1468  break;
1469 
1470  case XCB_DESTROY_NOTIFY:
1471  handle_destroy_notify_event((xcb_destroy_notify_event_t *)event);
1472  break;
1473 
1474  case XCB_EXPOSE:
1475  if (((xcb_expose_event_t *)event)->count == 0) {
1476  handle_expose_event((xcb_expose_event_t *)event);
1477  }
1478 
1479  break;
1480 
1481  case XCB_MOTION_NOTIFY:
1482  handle_motion_notify((xcb_motion_notify_event_t *)event);
1483  break;
1484 
1485  /* Enter window = user moved their mouse over the window */
1486  case XCB_ENTER_NOTIFY:
1487  handle_enter_notify((xcb_enter_notify_event_t *)event);
1488  break;
1489 
1490  /* Client message are sent to the root window. The only interesting
1491  * client message for us is _NET_WM_STATE, we honour
1492  * _NET_WM_STATE_FULLSCREEN and _NET_WM_STATE_DEMANDS_ATTENTION */
1493  case XCB_CLIENT_MESSAGE:
1494  handle_client_message((xcb_client_message_event_t *)event);
1495  break;
1496 
1497  /* Configure request = window tried to change size on its own */
1498  case XCB_CONFIGURE_REQUEST:
1499  handle_configure_request((xcb_configure_request_event_t *)event);
1500  break;
1501 
1502  /* Mapping notify = keyboard mapping changed (Xmodmap), re-grab bindings */
1503  case XCB_MAPPING_NOTIFY:
1504  handle_mapping_notify((xcb_mapping_notify_event_t *)event);
1505  break;
1506 
1507  case XCB_FOCUS_IN:
1508  handle_focus_in((xcb_focus_in_event_t *)event);
1509  break;
1510 
1511  case XCB_FOCUS_OUT:
1512  handle_focus_out((xcb_focus_out_event_t *)event);
1513  break;
1514 
1515  case XCB_PROPERTY_NOTIFY: {
1516  xcb_property_notify_event_t *e = (xcb_property_notify_event_t *)event;
1517  last_timestamp = e->time;
1518  property_notify(e->state, e->window, e->atom);
1519  break;
1520  }
1521 
1522  case XCB_CONFIGURE_NOTIFY:
1523  handle_configure_notify((xcb_configure_notify_event_t *)event);
1524  break;
1525 
1526  case XCB_SELECTION_CLEAR:
1527  handle_selection_clear((xcb_selection_clear_event_t *)event);
1528  break;
1529 
1530  default:
1531  /* DLOG("Unhandled event of type %d\n", type); */
1532  break;
1533  }
1534 }
Rect con_border_style_rect(Con *con)
Returns a "relative" Rect which contains the amount of pixels that need to be added to the original R...
Definition: con.c:1773
An Output is a physical output on your graphics driver.
Definition: data.h:413
#define _NET_MOVERESIZE_WINDOW_Y
Definition: handlers.c:651
#define _NET_WM_MOVERESIZE_SIZE_LEFT
Definition: handlers.c:644
void con_detach(Con *con)
Detaches the given container from its current parent.
Definition: con.c:230
#define ELOG(fmt,...)
Definition: libi3.h:100
void window_update_hints(i3Window *win, xcb_get_property_reply_t *prop, bool *urgency_hint)
Updates the WM_HINTS (we only care about the input focus handling part).
Definition: window.c:434
#define _NET_MOVERESIZE_WINDOW_WIDTH
Definition: handlers.c:652
i3String * name
The name of the window.
Definition: data.h:463
static bool handle_normal_hints(Con *con, xcb_get_property_reply_t *reply)
Definition: handlers.c:962
#define SLIST_END(head)
Definition: queue.h:110
void startup_monitor_event(SnMonitorEvent *event, void *userdata)
Called by libstartup-notification when something happens.
Definition: startup.c:212
bool sticky
Definition: data.h:767
border_style_t
Definition: data.h:65
uint32_t y
Definition: data.h:209
void handle_event(int type, xcb_generic_event_t *event)
Takes an xcb_generic_event_t and calls the appropriate handler, based on the event type...
Definition: handlers.c:1382
int xkb_current_group
Definition: handlers.c:22
SnDisplay * sndisplay
Definition: main.c:59
char * output_primary_name(Output *output)
Retrieves the primary name of an output.
Definition: output.c:53
Definition: data.h:112
void handle_button_press(xcb_button_press_event_t *event)
The button press X callback.
Definition: click.c:352
char * name
Definition: data.h:720
#define _NET_WM_STATE_REMOVE
Definition: xcb.h:17
void con_set_border_style(Con *con, border_style_t border_style, int border_width)
Sets the given border style on con, correctly keeping the position/size of a floating window...
Definition: con.c:1845
static bool handle_strut_partial_change(Con *con, xcb_get_property_reply_t *prop)
Definition: handlers.c:1212
void output_push_sticky_windows(Con *old_focus)
Iterates over all outputs and pushes sticky windows to the currently visible workspace on that output...
Definition: output.c:77
A "match" is a data structure which acts like a mask or expression to match certain windows or not...
Definition: data.h:557
#define TAILQ_FIRST(head)
Definition: queue.h:336
struct Window * window
Definition: data.h:746
static bool handle_clientleader_change(Con *con, xcb_get_property_reply_t *prop)
Definition: handlers.c:1006
#define NUM_HANDLERS
Definition: handlers.c:1312
uint32_t long_len
Definition: handlers.c:1293
Con * output_get_content(Con *output)
Returns the output container below the given output container.
Definition: output.c:16
Con * ewmh_get_workspace_by_index(uint32_t idx)
Returns the workspace container as enumerated by the EWMH desktop model.
Definition: ewmh.c:353
xcb_timestamp_t last_timestamp
The last timestamp we got from X11 (timestamps are included in some events and are used for some thin...
Definition: main.c:64
uint32_t bottom
Definition: data.h:223
Stores a rectangle, for example the size of a window, the child window etc.
Definition: data.h:207
bool disable_focus_follows_mouse
By default, focus follows mouse.
int render_deco_height(void)
Returns the height for the decorations.
Definition: render.c:27
layout_t
Container layouts.
Definition: data.h:105
xcb_window_t focused_id
Stores the X11 window ID of the currently focused window.
Definition: x.c:20
static void handle_destroy_notify_event(xcb_destroy_notify_event_t *event)
Definition: handlers.c:539
#define NET_WM_DESKTOP_ALL
Definition: workspace.h:25
#define y(x,...)
Definition: commands.c:18
bool workspace_is_visible(Con *ws)
Returns true if the workspace is currently visible.
Definition: workspace.c:314
int shape_base
Definition: handlers.c:23
int randr_base
Definition: handlers.c:20
void window_update_leader(i3Window *win, xcb_get_property_reply_t *prop)
Updates the CLIENT_LEADER (logical parent window).
Definition: window.c:199
static void handle_focus_out(xcb_focus_in_event_t *event)
Definition: handlers.c:1069
int current_border_width
Definition: data.h:744
uint32_t height
Definition: data.h:211
static bool window_name_changed(i3Window *window, char *old_name)
Definition: handlers.c:550
void con_focus(Con *con)
Sets input focus to the given container.
Definition: con.c:246
static bool handle_transient_for(Con *con, xcb_get_property_reply_t *prop)
Definition: handlers.c:996
static bool handle_machine_change(Con *con, xcb_get_property_reply_t *prop)
Definition: handlers.c:1184
cb_property_handler_t cb
Definition: handlers.c:1294
Con * workspace_get(const char *num)
Returns a pointer to the workspace with the given number (starting at 0), creating the workspace if n...
Definition: workspace.c:131
bool con_is_leaf(Con *con)
Returns true when this node is a leaf node (has no children)
Definition: con.c:361
static void handle_enter_notify(xcb_enter_notify_event_t *event)
Definition: handlers.c:122
static void handle_map_request(xcb_map_request_event_t *event)
Definition: handlers.c:268
static void handle_unmap_notify_event(xcb_unmap_notify_event_t *event)
Definition: handlers.c:468
int border_width
Definition: data.h:743
void window_update_class(i3Window *win, xcb_get_property_reply_t *prop)
Updates the WM_CLASS (consisting of the class and instance) for the given window. ...
Definition: window.c:34
#define _NET_WM_STATE_ADD
Definition: xcb.h:18
void window_update_transient_for(i3Window *win, xcb_get_property_reply_t *prop)
Updates the TRANSIENT_FOR (logical parent window).
Definition: window.c:224
bool event_is_ignored(const int sequence, const int response_type)
Checks if the given sequence is ignored and returns true if so.
Definition: handlers.c:52
static void handle_configure_notify(xcb_configure_notify_event_t *event)
Definition: handlers.c:1140
enum Con::@18 type
static void handle_focus_in(xcb_focus_in_event_t *event)
Definition: handlers.c:1017
bool tree_close_internal(Con *con, kill_window_t kill_window, bool dont_kill_parent)
Closes the given container including all children.
Definition: tree.c:191
bool floating_reposition(Con *con, Rect newrect)
Repositions the CT_FLOATING_CON to have the coordinates specified by newrect, but only if the coordin...
Definition: floating.c:742
#define SLIST_REMOVE(head, elm, type, field)
Definition: queue.h:154
Con * con_inside_floating(Con *con)
Checks if the given container is either floating or inside some floating container.
Definition: con.c:620
uint32_t aio_get_mod_mask_for(uint32_t keysym, xcb_key_symbols_t *symbols)
All-in-one function which returns the modifier mask (XCB_MOD_MASK_*) for the given keysymbol...
bool window_update_motif_hints(i3Window *win, xcb_get_property_reply_t *prop, border_style_t *motif_border_style)
Updates the MOTIF_WM_HINTS.
Definition: window.c:518
static bool handle_i3_floating(Con *con, xcb_get_property_reply_t *prop)
Definition: handlers.c:1271
Con * con_by_window_id(xcb_window_t window)
Returns the container with the given client window ID or NULL if no such container exists...
Definition: con.c:671
#define SLIST_FIRST(head)
Definition: queue.h:109
void ipc_send_event(const char *event, uint32_t message_type, const char *payload)
Sends the specified event to all IPC clients which are currently connected and subscribed to this kin...
Definition: ipc.c:147
static bool handle_windowname_change(Con *con, xcb_get_property_reply_t *prop)
Definition: handlers.c:565
void handle_key_press(xcb_key_press_event_t *event)
There was a key press.
Definition: key_press.c:18
void window_update_machine(i3Window *win, xcb_get_property_reply_t *prop)
Updates the WM_CLIENT_MACHINE.
Definition: window.c:560
static SLIST_HEAD(ignore_head, Ignore_Event)
Definition: handlers.c:28
enum Config::@4 focus_on_window_activation
Behavior when a window sends a NET_ACTIVE_WINDOW message.
int xkb_base
Definition: handlers.c:21
void grab_all_keys(xcb_connection_t *conn)
Grab the bound keys (tell X to send us keypress events for those keycodes)
Definition: bindings.c:149
void manage_window(xcb_window_t window, xcb_get_window_attributes_cookie_t cookie, bool needs_to_be_mapped)
Do some sanity checks and then reparent the window.
Definition: manage.c:106
static void handle_mapping_notify(xcb_mapping_notify_event_t *event)
Definition: handlers.c:249
Output * get_output_containing(unsigned int x, unsigned int y)
Returns the active (!) output which contains the coordinates x, y or NULL if there is no output which...
Definition: randr.c:121
void window_update_type(i3Window *window, xcb_get_property_reply_t *reply)
Updates the _NET_WM_WINDOW_TYPE property.
Definition: window.c:295
void x_push_changes(Con *con)
Pushes all changes (state of each node, see x_push_node() and the window stack) to X11...
Definition: x.c:1228
struct reservedpx reserved
Pixels the window reserves.
Definition: data.h:507
void con_toggle_fullscreen(Con *con, int fullscreen_mode)
Toggles fullscreen mode for the given container.
Definition: con.c:1095
int sequence
Definition: data.h:267
#define _NET_WM_MOVERESIZE_SIZE_TOPLEFT
Definition: handlers.c:637
void floating_drag_window(Con *con, const xcb_button_press_event_t *event, bool use_threshold)
Called when the user clicked on the titlebar of a floating window.
Definition: floating.c:590
static void handle_configure_request(xcb_configure_request_event_t *event)
Definition: handlers.c:287
void window_update_icon(i3Window *win, xcb_get_property_reply_t *prop)
Updates the _NET_WM_ICON.
Definition: window.c:574
#define SLIST_NEXT(elm, field)
Definition: queue.h:112
Con * con_get_workspace(Con *con)
Gets the workspace container this node is on.
Definition: con.c:477
Con * con_get_output(Con *con)
Gets the output container (first container with CT_OUTPUT in hierarchy) this node is on...
Definition: con.c:463
static cmdp_state state
bool con_is_floating(Con *con)
Returns true if the node is floating.
Definition: con.c:596
void * smalloc(size_t size)
Safe-wrapper around malloc which exits if malloc returns NULL (meaning that there is no more memory a...
void window_update_name(i3Window *win, xcb_get_property_reply_t *prop)
Updates the name by using _NET_WM_NAME (encoded in UTF-8) for the given window.
Definition: window.c:67
bool rect_contains(Rect rect, uint32_t x, uint32_t y)
Definition: util.c:32
xcb_window_t root
Definition: main.c:67
void * scalloc(size_t num, size_t size)
Safe-wrapper around calloc which exits if malloc returns NULL (meaning that there is no more memory a...
static bool handle_windowicon_change(Con *con, xcb_get_property_reply_t *prop)
Definition: handlers.c:1279
void sync_respond(xcb_window_t window, uint32_t rnd)
Definition: sync.c:12
const char * i3string_as_utf8(i3String *str)
Returns the UTF-8 encoded version of the i3String.
void window_update_name_legacy(i3Window *win, xcb_get_property_reply_t *prop)
Updates the name by using WM_NAME (encoded in COMPOUND_TEXT).
Definition: window.c:103
static struct property_handler_t property_handlers[]
Definition: handlers.c:1297
Con * con_by_frame_id(xcb_window_t frame)
Returns the container with the given frame ID or NULL if no such container exists.
Definition: con.c:711
fullscreen_mode_t fullscreen_mode
Definition: data.h:762
void fake_absolute_configure_notify(Con *con)
Generates a configure_notify_event with absolute coordinates (relative to the X root window...
Definition: xcb.c:63
void x_set_shape(Con *con, xcb_shape_sk_t kind, bool enable)
Enables or disables nonrectangular shape of the container frame.
Definition: x.c:1518
Con * remanage_window(Con *con)
Remanages a window: performs a swallow check and runs assignments.
Definition: manage.c:690
void con_move_to_workspace(Con *con, Con *workspace, bool fix_coordinates, bool dont_warp, bool ignore_focus)
Moves the given container to the currently focused container on the given workspace.
Definition: con.c:1466
Definition: data.h:657
void con_activate_unblock(Con *con)
Activates the container like in con_activate but removes fullscreen restrictions and properly warps t...
Definition: con.c:297
#define _NET_MOVERESIZE_WINDOW_HEIGHT
Definition: handlers.c:653
#define FREE(pointer)
Definition: util.h:47
bool force_xinerama
Definition: main.c:107
void con_set_urgency(Con *con, bool urgent)
Set urgency flag to the container, all the parent containers and the workspace.
Definition: con.c:2273
uint32_t top
Definition: data.h:222
#define SLIST_INSERT_HEAD(head, elm, field)
Definition: queue.h:138
#define COPY_MASK_MEMBER(mask_member, event_member)
int conn_screen
Definition: main.c:56
static void check_crossing_screen_boundary(uint32_t x, uint32_t y)
Definition: handlers.c:88
void window_update_role(i3Window *win, xcb_get_property_reply_t *prop)
Updates the WM_WINDOW_ROLE.
Definition: window.c:274
bool con_is_internal(Con *con)
Returns true if the container is internal, such as __i3_scratch.
Definition: con.c:588
#define SLIST_FOREACH(var, head, field)
Definition: queue.h:114
time_t added
Definition: data.h:269
struct Con * croot
Definition: tree.c:12
void add_ignore_event(const int sequence, const int response_type)
Adds the given sequence to the list of events which are ignored.
void workspace_show(Con *workspace)
Switches to the given workspace.
Definition: workspace.c:428
surface_t frame
Definition: data.h:686
void window_update_strut_partial(i3Window *win, xcb_get_property_reply_t *prop)
Updates the _NET_WM_STRUT_PARTIAL (reserved pixels at the screen edges)
Definition: window.c:249
void floating_check_size(Con *floating_con, bool prefer_height)
Called when a floating window is created or resized.
Definition: floating.c:75
#define _NET_WM_STATE_TOGGLE
Definition: xcb.h:19
static bool handle_hints(Con *con, xcb_get_property_reply_t *reply)
Definition: handlers.c:981
void floating_resize_window(Con *con, const bool proportional, const xcb_button_press_event_t *event)
Called when the user clicked on a floating window while holding the floating_modifier and the right m...
Definition: floating.c:688
bool floating_enable(Con *con, bool automatic)
Enables floating mode for the given container by detaching it from its parent, creating a new contain...
Definition: floating.c:232
bool(* cb_property_handler_t)(Con *con, xcb_get_property_reply_t *property)
Definition: handlers.c:1289
static void handle_motion_notify(xcb_motion_notify_event_t *event)
Definition: handlers.c:195
struct Rect rect
Definition: data.h:710
void property_handlers_init(void)
Sets the appropriate atoms for the property handlers after the atoms were received from X11...
Definition: handlers.c:1319
Con * con_for_window(Con *con, i3Window *window, Match **store_match)
Returns the first container below &#39;con&#39; which wants to swallow this window TODO: priority.
Definition: con.c:890
void ewmh_update_wm_desktop(void)
Updates _NET_WM_DESKTOP for all windows.
Definition: ewmh.c:184
void draw_util_copy_surface(surface_t *src, surface_t *dest, double src_x, double src_y, double dest_x, double dest_y, double width, double height)
Copies a surface onto another surface.
bool load_keymap(void)
Loads the XKB keymap from the X11 server and feeds it to xkbcommon.
Definition: bindings.c:954
int default_border_width
static bool handle_windowrole_change(Con *con, xcb_get_property_reply_t *prop)
Definition: handlers.c:608
#define _NET_WM_MOVERESIZE_MOVE
Definition: handlers.c:645
xcb_connection_t * conn
XCB connection and root screen.
Definition: main.c:54
xcb_atom_t atom
Definition: handlers.c:1292
xcb_window_t id
Definition: data.h:447
xcb_key_symbols_t * keysyms
Definition: main.c:81
Con * con_descend_focused(Con *con)
Returns the focused con inside this client, descending the tree as far as possible.
Definition: con.c:1590
uint32_t x
Definition: data.h:208
void tree_render(void)
Renders the tree, that is rendering all outputs using render_con() and pushing the changes to X11 usi...
Definition: tree.c:451
border_style_t border_style
Definition: data.h:785
A &#39;Window&#39; is a type which contains an xcb_window_t and all the related information (hints like _NET_...
Definition: data.h:446
static void handle_expose_event(xcb_expose_event_t *event)
Definition: handlers.c:620
surface_t frame_buffer
Definition: data.h:687
#define _NET_MOVERESIZE_WINDOW_X
Definition: handlers.c:650
enum Window::@11 dock
Whether the window says it is a dock window.
struct Rect geometry
the geometry this window requested when getting mapped
Definition: data.h:718
enum Con::@19 floating
floating? (= not in tiling layout) This cannot be simply a bool because we want to keep track of whet...
void randr_query_outputs(void)
(Re-)queries the outputs via RandR and stores them in the list of outputs.
Definition: randr.c:912
void translate_keysyms(void)
Translates keysymbols to keycodes for all bindings which use keysyms.
Definition: bindings.c:434
static void handle_screen_change(xcb_generic_event_t *e)
Definition: handlers.c:440
static void handle_selection_clear(xcb_selection_clear_event_t *event)
Definition: handlers.c:1159
layout_t layout
Definition: data.h:783
uint8_t ignore_unmap
This counter contains the number of UnmapNotify events for this container (or, more precisely...
Definition: data.h:683
void scratchpad_fix_resolution(void)
When starting i3 initially (and after each change to the connected outputs), this function fixes the ...
Definition: scratchpad.c:247
uint32_t width
Definition: data.h:210
char * sstrdup(const char *str)
Safe-wrapper around strdup which exits if malloc returns NULL (meaning that there is no more memory a...
bool shape_supported
Definition: main.c:105
static bool handle_window_type(Con *con, xcb_get_property_reply_t *reply)
Definition: handlers.c:950
A &#39;Con&#39; represents everything from the X11 root window down to a single X11 window.
Definition: data.h:671
bool urgent
Definition: data.h:676
bool scratchpad_show(Con *con)
Either shows the top-most scratchpad window (con == NULL) or shows the specified con (if it is scratc...
Definition: scratchpad.c:85
#define DLOG(fmt,...)
Definition: libi3.h:105
void con_attach(Con *con, Con *parent, bool ignore_focus)
Attaches the given container to the given parent.
Definition: con.c:222
xcb_atom_t wm_sn
Definition: main.c:70
static void property_notify(uint8_t state, xcb_window_t window, xcb_atom_t atom)
Definition: handlers.c:1338
struct Con * focused
Definition: tree.c:13
Config config
Definition: config.c:19
int response_type
Definition: data.h:268
bool window_update_normal_hints(i3Window *win, xcb_get_property_reply_t *reply, xcb_get_geometry_reply_t *geom)
Updates the WM_NORMAL_HINTS.
Definition: window.c:313
Con * con
Pointer to the Con which represents this output.
Definition: data.h:433
static bool handle_class_change(Con *con, xcb_get_property_reply_t *prop)
Definition: handlers.c:1174
#define LOG(fmt,...)
Definition: libi3.h:95
static void handle_client_message(xcb_client_message_event_t *event)
Definition: handlers.c:659
void ungrab_all_keys(xcb_connection_t *conn)
Ungrabs all keys, to be called before re-grabbing the keys because of a mapping_notify event or a con...
Definition: config.c:29
unsigned int xcb_numlock_mask
Definition: xcb.c:12
Definition: data.h:111
struct Con * parent
Definition: data.h:706
void ipc_send_window_event(const char *property, Con *con)
For the window events we send, along the usual "change" field, also the window container, in "container".
Definition: ipc.c:1633
Con * con_get_fullscreen_covering_ws(Con *ws)
Returns the fullscreen node that covers the given workspace if it exists.
Definition: con.c:573
struct Rect deco_rect
Definition: data.h:716
void ewmh_update_sticky(xcb_window_t window, bool sticky)
Set or remove _NET_WM_STATE_STICKY on the window.
Definition: ewmh.c:279
#define TAILQ_FOREACH_REVERSE(var, head, headname, field)
Definition: queue.h:352
static bool handle_motif_hints_change(Con *con, xcb_get_property_reply_t *prop)
Definition: handlers.c:1194
#define XCB_NUM_LOCK
Definition: xcb.h:22
static bool handle_windowname_change_legacy(Con *con, xcb_get_property_reply_t *prop)
Definition: handlers.c:587