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  con = remanage_window(con);
426  tree_render();
427  } else {
428  DLOG("Ignoring request for con = %p.\n", con);
429  }
430  }
431 
432 out:
434 }
435 
436 /*
437  * Gets triggered upon a RandR screen change event, that is when the user
438  * changes the screen configuration in any way (mode, position, …)
439  *
440  */
441 static void handle_screen_change(xcb_generic_event_t *e) {
442  DLOG("RandR screen change\n");
443 
444  /* The geometry of the root window is used for “fullscreen global” and
445  * changes when new outputs are added. */
446  xcb_get_geometry_cookie_t cookie = xcb_get_geometry(conn, root);
447  xcb_get_geometry_reply_t *reply = xcb_get_geometry_reply(conn, cookie, NULL);
448  if (reply == NULL) {
449  ELOG("Could not get geometry of the root window, exiting\n");
450  exit(EXIT_FAILURE);
451  }
452  DLOG("root geometry reply: (%d, %d) %d x %d\n", reply->x, reply->y, reply->width, reply->height);
453 
454  croot->rect.width = reply->width;
455  croot->rect.height = reply->height;
456 
458 
460 
461  ipc_send_event("output", I3_IPC_EVENT_OUTPUT, "{\"change\":\"unspecified\"}");
462 }
463 
464 /*
465  * Our window decorations were unmapped. That means, the window will be killed
466  * now, so we better clean up before.
467  *
468  */
469 static void handle_unmap_notify_event(xcb_unmap_notify_event_t *event) {
470  DLOG("UnmapNotify for 0x%08x (received from 0x%08x), serial %d\n", event->window, event->event, event->sequence);
471  xcb_get_input_focus_cookie_t cookie;
472  Con *con = con_by_window_id(event->window);
473  if (con == NULL) {
474  /* This could also be an UnmapNotify for the frame. We need to
475  * decrement the ignore_unmap counter. */
476  con = con_by_frame_id(event->window);
477  if (con == NULL) {
478  LOG("Not a managed window, ignoring UnmapNotify event\n");
479  return;
480  }
481 
482  if (con->ignore_unmap > 0)
483  con->ignore_unmap--;
484  /* See the end of this function. */
485  cookie = xcb_get_input_focus(conn);
486  DLOG("ignore_unmap = %d for frame of container %p\n", con->ignore_unmap, con);
487  goto ignore_end;
488  }
489 
490  /* See the end of this function. */
491  cookie = xcb_get_input_focus(conn);
492 
493  if (con->ignore_unmap > 0) {
494  DLOG("ignore_unmap = %d, dec\n", con->ignore_unmap);
495  con->ignore_unmap--;
496  goto ignore_end;
497  }
498 
499  /* Since we close the container, we need to unset _NET_WM_DESKTOP and
500  * _NET_WM_STATE according to the spec. */
501  xcb_delete_property(conn, event->window, A__NET_WM_DESKTOP);
502  xcb_delete_property(conn, event->window, A__NET_WM_STATE);
503 
505  tree_render();
506 
507 ignore_end:
508  /* If the client (as opposed to i3) destroyed or unmapped a window, an
509  * EnterNotify event will follow (indistinguishable from an EnterNotify
510  * event caused by moving your mouse), causing i3 to set focus to whichever
511  * window is now visible.
512  *
513  * In a complex stacked or tabbed layout (take two v-split containers in a
514  * tabbed container), when the bottom window in tab2 is closed, the bottom
515  * window of tab1 is visible instead. X11 will thus send an EnterNotify
516  * event for the bottom window of tab1, while the focus should be set to
517  * the remaining window of tab2.
518  *
519  * Therefore, we ignore all EnterNotify events which have the same sequence
520  * as an UnmapNotify event. */
521  add_ignore_event(event->sequence, XCB_ENTER_NOTIFY);
522 
523  /* Since we just ignored the sequence of this UnmapNotify, we want to make
524  * sure that following events use a different sequence. When putting xterm
525  * into fullscreen and moving the pointer to a different window, without
526  * using GetInputFocus, subsequent (legitimate) EnterNotify events arrived
527  * with the same sequence and thus were ignored (see ticket #609). */
528  free(xcb_get_input_focus_reply(conn, cookie, NULL));
529 }
530 
531 /*
532  * A destroy notify event is sent when the window is not unmapped, but
533  * immediately destroyed (for example when starting a window and immediately
534  * killing the program which started it).
535  *
536  * We just pass on the event to the unmap notify handler (by copying the
537  * important fields in the event data structure).
538  *
539  */
540 static void handle_destroy_notify_event(xcb_destroy_notify_event_t *event) {
541  DLOG("destroy notify for 0x%08x, 0x%08x\n", event->event, event->window);
542 
543  xcb_unmap_notify_event_t unmap;
544  unmap.sequence = event->sequence;
545  unmap.event = event->event;
546  unmap.window = event->window;
547 
549 }
550 
551 static bool window_name_changed(i3Window *window, char *old_name) {
552  if ((old_name == NULL) && (window->name == NULL))
553  return false;
554 
555  /* Either the old or the new one is NULL, but not both. */
556  if ((old_name == NULL) ^ (window->name == NULL))
557  return true;
558 
559  return (strcmp(old_name, i3string_as_utf8(window->name)) != 0);
560 }
561 
562 /*
563  * Called when a window changes its title
564  *
565  */
566 static bool handle_windowname_change(Con *con, xcb_get_property_reply_t *prop) {
567  char *old_name = (con->window->name != NULL ? sstrdup(i3string_as_utf8(con->window->name)) : NULL);
568 
569  window_update_name(con->window, prop);
570 
571  con = remanage_window(con);
572 
574 
575  if (window_name_changed(con->window, old_name))
576  ipc_send_window_event("title", con);
577 
578  FREE(old_name);
579 
580  return true;
581 }
582 
583 /*
584  * Handles legacy window name updates (WM_NAME), see also src/window.c,
585  * window_update_name_legacy().
586  *
587  */
588 static bool handle_windowname_change_legacy(Con *con, xcb_get_property_reply_t *prop) {
589  char *old_name = (con->window->name != NULL ? sstrdup(i3string_as_utf8(con->window->name)) : NULL);
590 
591  window_update_name_legacy(con->window, prop);
592 
593  con = remanage_window(con);
594 
596 
597  if (window_name_changed(con->window, old_name))
598  ipc_send_window_event("title", con);
599 
600  FREE(old_name);
601 
602  return true;
603 }
604 
605 /*
606  * Called when a window changes its WM_WINDOW_ROLE.
607  *
608  */
609 static bool handle_windowrole_change(Con *con, xcb_get_property_reply_t *prop) {
610  window_update_role(con->window, prop);
611 
612  con = remanage_window(con);
613 
614  return true;
615 }
616 
617 /*
618  * Expose event means we should redraw our windows (= title bar)
619  *
620  */
621 static void handle_expose_event(xcb_expose_event_t *event) {
622  Con *parent;
623 
624  DLOG("window = %08x\n", event->window);
625 
626  if ((parent = con_by_frame_id(event->window)) == NULL) {
627  LOG("expose event for unknown window, ignoring\n");
628  return;
629  }
630 
631  /* Since we render to our surface on every change anyways, expose events
632  * only tell us that the X server lost (parts of) the window contents. */
633  draw_util_copy_surface(&(parent->frame_buffer), &(parent->frame),
634  0, 0, 0, 0, parent->rect.width, parent->rect.height);
635  xcb_flush(conn);
636 }
637 
638 #define _NET_WM_MOVERESIZE_SIZE_TOPLEFT 0
639 #define _NET_WM_MOVERESIZE_SIZE_TOP 1
640 #define _NET_WM_MOVERESIZE_SIZE_TOPRIGHT 2
641 #define _NET_WM_MOVERESIZE_SIZE_RIGHT 3
642 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT 4
643 #define _NET_WM_MOVERESIZE_SIZE_BOTTOM 5
644 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT 6
645 #define _NET_WM_MOVERESIZE_SIZE_LEFT 7
646 #define _NET_WM_MOVERESIZE_MOVE 8 /* movement only */
647 #define _NET_WM_MOVERESIZE_SIZE_KEYBOARD 9 /* size via keyboard */
648 #define _NET_WM_MOVERESIZE_MOVE_KEYBOARD 10 /* move via keyboard */
649 #define _NET_WM_MOVERESIZE_CANCEL 11 /* cancel operation */
650 
651 #define _NET_MOVERESIZE_WINDOW_X (1 << 8)
652 #define _NET_MOVERESIZE_WINDOW_Y (1 << 9)
653 #define _NET_MOVERESIZE_WINDOW_WIDTH (1 << 10)
654 #define _NET_MOVERESIZE_WINDOW_HEIGHT (1 << 11)
655 
656 /*
657  * Handle client messages (EWMH)
658  *
659  */
660 static void handle_client_message(xcb_client_message_event_t *event) {
661  /* If this is a startup notification ClientMessage, the library will handle
662  * it and call our monitor_event() callback. */
663  if (sn_xcb_display_process_event(sndisplay, (xcb_generic_event_t *)event))
664  return;
665 
666  LOG("ClientMessage for window 0x%08x\n", event->window);
667  if (event->type == A__NET_WM_STATE) {
668  if (event->format != 32 ||
669  (event->data.data32[1] != A__NET_WM_STATE_FULLSCREEN &&
670  event->data.data32[1] != A__NET_WM_STATE_DEMANDS_ATTENTION &&
671  event->data.data32[1] != A__NET_WM_STATE_STICKY)) {
672  DLOG("Unknown atom in clientmessage of type %d\n", event->data.data32[1]);
673  return;
674  }
675 
676  Con *con = con_by_window_id(event->window);
677  if (con == NULL) {
678  DLOG("Could not get window for client message\n");
679  return;
680  }
681 
682  if (event->data.data32[1] == A__NET_WM_STATE_FULLSCREEN) {
683  /* Check if the fullscreen state should be toggled */
684  if ((con->fullscreen_mode != CF_NONE &&
685  (event->data.data32[0] == _NET_WM_STATE_REMOVE ||
686  event->data.data32[0] == _NET_WM_STATE_TOGGLE)) ||
687  (con->fullscreen_mode == CF_NONE &&
688  (event->data.data32[0] == _NET_WM_STATE_ADD ||
689  event->data.data32[0] == _NET_WM_STATE_TOGGLE))) {
690  DLOG("toggling fullscreen\n");
692  }
693  } else if (event->data.data32[1] == A__NET_WM_STATE_DEMANDS_ATTENTION) {
694  /* Check if the urgent flag must be set or not */
695  if (event->data.data32[0] == _NET_WM_STATE_ADD) {
696  con_set_urgency(con, true);
697  con = remanage_window(con);
698  } else if (event->data.data32[0] == _NET_WM_STATE_REMOVE) {
699  con_set_urgency(con, false);
700  con = remanage_window(con);
701  } else if (event->data.data32[0] == _NET_WM_STATE_TOGGLE) {
702  con_set_urgency(con, !con->urgent);
703  con = remanage_window(con);
704  }
705  } else if (event->data.data32[1] == A__NET_WM_STATE_STICKY) {
706  DLOG("Received a client message to modify _NET_WM_STATE_STICKY.\n");
707  if (event->data.data32[0] == _NET_WM_STATE_ADD)
708  con->sticky = true;
709  else if (event->data.data32[0] == _NET_WM_STATE_REMOVE)
710  con->sticky = false;
711  else if (event->data.data32[0] == _NET_WM_STATE_TOGGLE)
712  con->sticky = !con->sticky;
713 
714  DLOG("New sticky status for con = %p is %i.\n", con, con->sticky);
715  ewmh_update_sticky(con->window->id, con->sticky);
718  }
719 
720  tree_render();
721  } else if (event->type == A__NET_ACTIVE_WINDOW) {
722  if (event->format != 32)
723  return;
724 
725  DLOG("_NET_ACTIVE_WINDOW: Window 0x%08x should be activated\n", event->window);
726 
727  Con *con = con_by_window_id(event->window);
728  if (con == NULL) {
729  DLOG("Could not get window for client message\n");
730  return;
731  }
732 
733  Con *ws = con_get_workspace(con);
734  if (ws == NULL) {
735  DLOG("Window is not being managed, ignoring _NET_ACTIVE_WINDOW\n");
736  return;
737  }
738 
739  if (con_is_internal(ws) && ws != workspace_get("__i3_scratch")) {
740  DLOG("Workspace is internal but not scratchpad, ignoring _NET_ACTIVE_WINDOW\n");
741  return;
742  }
743 
744  /* data32[0] indicates the source of the request (application or pager) */
745  if (event->data.data32[0] == 2) {
746  /* Always focus the con if it is from a pager, because this is most
747  * likely from some user action */
748  DLOG("This request came from a pager. Focusing con = %p\n", con);
749 
750  if (con_is_internal(ws)) {
751  scratchpad_show(con);
752  } else {
753  workspace_show(ws);
754  /* Re-set focus, even if unchanged from i3’s perspective. */
755  focused_id = XCB_NONE;
757  }
758  } else {
759  /* Request is from an application. */
760  if (con_is_internal(ws)) {
761  DLOG("Ignoring request to make con = %p active because it's on an internal workspace.\n", con);
762  return;
763  }
764 
765  if (config.focus_on_window_activation == FOWA_FOCUS || (config.focus_on_window_activation == FOWA_SMART && workspace_is_visible(ws))) {
766  DLOG("Focusing con = %p\n", con);
768  } else if (config.focus_on_window_activation == FOWA_URGENT || (config.focus_on_window_activation == FOWA_SMART && !workspace_is_visible(ws))) {
769  DLOG("Marking con = %p urgent\n", con);
770  con_set_urgency(con, true);
771  con = remanage_window(con);
772  } else
773  DLOG("Ignoring request for con = %p.\n", con);
774  }
775 
776  tree_render();
777  } else if (event->type == A_I3_SYNC) {
778  xcb_window_t window = event->data.data32[0];
779  uint32_t rnd = event->data.data32[1];
780  sync_respond(window, rnd);
781  } else if (event->type == A__NET_REQUEST_FRAME_EXTENTS) {
782  /*
783  * A client can request an estimate for the frame size which the window
784  * manager will put around it before actually mapping its window. Java
785  * does this (as of openjdk-7).
786  *
787  * Note that the calculation below is not entirely accurate — once you
788  * set a different border type, it’s off. We _could_ request all the
789  * window properties (which have to be set up at this point according
790  * to EWMH), but that seems rather elaborate. The standard explicitly
791  * says the application must cope with an estimate that is not entirely
792  * accurate.
793  */
794  DLOG("_NET_REQUEST_FRAME_EXTENTS for window 0x%08x\n", event->window);
795 
796  /* The reply data: approximate frame size */
797  Rect r = {
798  config.default_border_width, /* left */
799  config.default_border_width, /* right */
800  render_deco_height(), /* top */
801  config.default_border_width /* bottom */
802  };
803  xcb_change_property(
804  conn,
805  XCB_PROP_MODE_REPLACE,
806  event->window,
807  A__NET_FRAME_EXTENTS,
808  XCB_ATOM_CARDINAL, 32, 4,
809  &r);
810  xcb_flush(conn);
811  } else if (event->type == A_WM_CHANGE_STATE) {
812  /* http://tronche.com/gui/x/icccm/sec-4.html#s-4.1.4 */
813  if (event->data.data32[0] == XCB_ICCCM_WM_STATE_ICONIC) {
814  /* For compatibility reasons, Wine will request iconic state and cannot ensure that the WM has agreed on it;
815  * immediately revert to normal to avoid being stuck in a paused state. */
816  DLOG("Client has requested iconic state, rejecting. (window = %08x)\n", event->window);
817  long data[] = {XCB_ICCCM_WM_STATE_NORMAL, XCB_NONE};
818  xcb_change_property(conn, XCB_PROP_MODE_REPLACE, event->window,
819  A_WM_STATE, A_WM_STATE, 32, 2, data);
820  } else {
821  DLOG("Not handling WM_CHANGE_STATE request. (window = %08x, state = %d)\n", event->window, event->data.data32[0]);
822  }
823  } else if (event->type == A__NET_CURRENT_DESKTOP) {
824  /* This request is used by pagers and bars to change the current
825  * desktop likely as a result of some user action. We interpret this as
826  * a request to focus the given workspace. See
827  * https://standards.freedesktop.org/wm-spec/latest/ar01s03.html#idm140251368135008
828  * */
829  DLOG("Request to change current desktop to index %d\n", event->data.data32[0]);
830  Con *ws = ewmh_get_workspace_by_index(event->data.data32[0]);
831  if (ws == NULL) {
832  ELOG("Could not determine workspace for this index, ignoring request.\n");
833  return;
834  }
835 
836  DLOG("Handling request to focus workspace %s\n", ws->name);
837  workspace_show(ws);
838  tree_render();
839  } else if (event->type == A__NET_WM_DESKTOP) {
840  uint32_t index = event->data.data32[0];
841  DLOG("Request to move window %d to EWMH desktop index %d\n", event->window, index);
842 
843  Con *con = con_by_window_id(event->window);
844  if (con == NULL) {
845  DLOG("Couldn't find con for window %d, ignoring the request.\n", event->window);
846  return;
847  }
848 
849  if (index == NET_WM_DESKTOP_ALL) {
850  /* The window is requesting to be visible on all workspaces, so
851  * let's float it and make it sticky. */
852  DLOG("The window was requested to be visible on all workspaces, making it sticky and floating.\n");
853 
854  if (floating_enable(con, false)) {
855  con->floating = FLOATING_AUTO_ON;
856 
857  con->sticky = true;
858  ewmh_update_sticky(con->window->id, true);
860  }
861  } else {
862  Con *ws = ewmh_get_workspace_by_index(index);
863  if (ws == NULL) {
864  ELOG("Could not determine workspace for this index, ignoring request.\n");
865  return;
866  }
867 
868  con_move_to_workspace(con, ws, true, false, false);
869  }
870 
871  tree_render();
873  } else if (event->type == A__NET_CLOSE_WINDOW) {
874  /*
875  * Pagers wanting to close a window MUST send a _NET_CLOSE_WINDOW
876  * client message request to the root window.
877  * https://standards.freedesktop.org/wm-spec/wm-spec-latest.html#idm140200472668896
878  */
879  Con *con = con_by_window_id(event->window);
880  if (con) {
881  DLOG("Handling _NET_CLOSE_WINDOW request (con = %p)\n", con);
882 
883  if (event->data.data32[0])
884  last_timestamp = event->data.data32[0];
885 
886  tree_close_internal(con, KILL_WINDOW, false);
887  tree_render();
888  } else {
889  DLOG("Couldn't find con for _NET_CLOSE_WINDOW request. (window = %08x)\n", event->window);
890  }
891  } else if (event->type == A__NET_WM_MOVERESIZE) {
892  /*
893  * Client-side decorated Gtk3 windows emit this signal when being
894  * dragged by their GtkHeaderBar
895  */
896  Con *con = con_by_window_id(event->window);
897  if (!con || !con_is_floating(con)) {
898  DLOG("Couldn't find con for _NET_WM_MOVERESIZE request, or con not floating (window = %08x)\n", event->window);
899  return;
900  }
901  DLOG("Handling _NET_WM_MOVERESIZE request (con = %p)\n", con);
902  uint32_t direction = event->data.data32[2];
903  uint32_t x_root = event->data.data32[0];
904  uint32_t y_root = event->data.data32[1];
905  /* construct fake xcb_button_press_event_t */
906  xcb_button_press_event_t fake = {
907  .root_x = x_root,
908  .root_y = y_root,
909  .event_x = x_root - (con->rect.x),
910  .event_y = y_root - (con->rect.y)};
911  switch (direction) {
913  floating_drag_window(con->parent, &fake, false);
914  break;
916  floating_resize_window(con->parent, false, &fake);
917  break;
918  default:
919  DLOG("_NET_WM_MOVERESIZE direction %d not implemented\n", direction);
920  break;
921  }
922  } else if (event->type == A__NET_MOVERESIZE_WINDOW) {
923  DLOG("Received _NET_MOVE_RESIZE_WINDOW. Handling by faking a configure request.\n");
924 
925  void *_generated_event = scalloc(32, 1);
926  xcb_configure_request_event_t *generated_event = _generated_event;
927 
928  generated_event->window = event->window;
929  generated_event->response_type = XCB_CONFIGURE_REQUEST;
930 
931  generated_event->value_mask = 0;
932  if (event->data.data32[0] & _NET_MOVERESIZE_WINDOW_X) {
933  generated_event->value_mask |= XCB_CONFIG_WINDOW_X;
934  generated_event->x = event->data.data32[1];
935  }
936  if (event->data.data32[0] & _NET_MOVERESIZE_WINDOW_Y) {
937  generated_event->value_mask |= XCB_CONFIG_WINDOW_Y;
938  generated_event->y = event->data.data32[2];
939  }
940  if (event->data.data32[0] & _NET_MOVERESIZE_WINDOW_WIDTH) {
941  generated_event->value_mask |= XCB_CONFIG_WINDOW_WIDTH;
942  generated_event->width = event->data.data32[3];
943  }
944  if (event->data.data32[0] & _NET_MOVERESIZE_WINDOW_HEIGHT) {
945  generated_event->value_mask |= XCB_CONFIG_WINDOW_HEIGHT;
946  generated_event->height = event->data.data32[4];
947  }
948 
949  handle_configure_request(generated_event);
950  FREE(generated_event);
951  } else {
952  DLOG("Skipping client message for unhandled type %d\n", event->type);
953  }
954 }
955 
956 static bool handle_window_type(Con *con, xcb_get_property_reply_t *reply) {
957  window_update_type(con->window, reply);
958  return true;
959 }
960 
961 /*
962  * Handles the size hints set by a window, but currently only the part necessary for displaying
963  * clients proportionally inside their frames (mplayer for example)
964  *
965  * See ICCCM 4.1.2.3 for more details
966  *
967  */
968 static bool handle_normal_hints(Con *con, xcb_get_property_reply_t *reply) {
969  bool changed = window_update_normal_hints(con->window, reply, NULL);
970 
971  if (changed) {
972  Con *floating = con_inside_floating(con);
973  if (floating) {
974  floating_check_size(con, false);
975  tree_render();
976  }
977  }
978 
979  FREE(reply);
980  return true;
981 }
982 
983 /*
984  * Handles the WM_HINTS property for extracting the urgency state of the window.
985  *
986  */
987 static bool handle_hints(Con *con, xcb_get_property_reply_t *reply) {
988  bool urgency_hint;
989  window_update_hints(con->window, reply, &urgency_hint);
990  con_set_urgency(con, urgency_hint);
991  remanage_window(con);
992  tree_render();
993  return true;
994 }
995 
996 /*
997  * Handles the transient for hints set by a window, signalizing that this window is a popup window
998  * for some other window.
999  *
1000  * See ICCCM 4.1.2.6 for more details
1001  *
1002  */
1003 static bool handle_transient_for(Con *con, xcb_get_property_reply_t *prop) {
1004  window_update_transient_for(con->window, prop);
1005  return true;
1006 }
1007 
1008 /*
1009  * Handles changes of the WM_CLIENT_LEADER atom which specifies if this is a
1010  * toolwindow (or similar) and to which window it belongs (logical parent).
1011  *
1012  */
1013 static bool handle_clientleader_change(Con *con, xcb_get_property_reply_t *prop) {
1014  window_update_leader(con->window, prop);
1015  return true;
1016 }
1017 
1018 /*
1019  * Handles FocusIn events which are generated by clients (i3’s focus changes
1020  * don’t generate FocusIn events due to a different EventMask) and updates the
1021  * decorations accordingly.
1022  *
1023  */
1024 static void handle_focus_in(xcb_focus_in_event_t *event) {
1025  DLOG("focus change in, for window 0x%08x\n", event->event);
1026 
1027  if (event->event == root) {
1028  DLOG("Received focus in for root window, refocusing the focused window.\n");
1029  con_focus(focused);
1030  focused_id = XCB_NONE;
1032  }
1033 
1034  Con *con;
1035  if ((con = con_by_window_id(event->event)) == NULL || con->window == NULL)
1036  return;
1037  DLOG("That is con %p / %s\n", con, con->name);
1038 
1039  if (event->mode == XCB_NOTIFY_MODE_GRAB ||
1040  event->mode == XCB_NOTIFY_MODE_UNGRAB) {
1041  DLOG("FocusIn event for grab/ungrab, ignoring\n");
1042  return;
1043  }
1044 
1045  if (event->detail == XCB_NOTIFY_DETAIL_POINTER) {
1046  DLOG("notify detail is pointer, ignoring this event\n");
1047  return;
1048  }
1049 
1050  /* Floating windows should be refocused to ensure that they are on top of
1051  * other windows. */
1052  if (focused_id == event->event && !con_inside_floating(con)) {
1053  DLOG("focus matches the currently focused window, not doing anything\n");
1054  return;
1055  }
1056 
1057  /* Skip dock clients, they cannot get the i3 focus. */
1058  if (con->parent->type == CT_DOCKAREA) {
1059  DLOG("This is a dock client, not focusing.\n");
1060  return;
1061  }
1062 
1063  DLOG("focus is different / refocusing floating window: updating decorations\n");
1064 
1065  con_activate_unblock(con);
1066 
1067  /* We update focused_id because we don’t need to set focus again */
1068  focused_id = event->event;
1069  tree_render();
1070 }
1071 
1072 /*
1073  * Log FocusOut events.
1074  *
1075  */
1076 static void handle_focus_out(xcb_focus_in_event_t *event) {
1077  Con *con = con_by_window_id(event->event);
1078  const char *window_name, *mode, *detail;
1079 
1080  if (con != NULL) {
1081  window_name = con->name;
1082  if (window_name == NULL) {
1083  window_name = "<unnamed con>";
1084  }
1085  } else if (event->event == root) {
1086  window_name = "<the root window>";
1087  } else {
1088  window_name = "<unknown window>";
1089  }
1090 
1091  switch (event->mode) {
1092  case XCB_NOTIFY_MODE_NORMAL:
1093  mode = "Normal";
1094  break;
1095  case XCB_NOTIFY_MODE_GRAB:
1096  mode = "Grab";
1097  break;
1098  case XCB_NOTIFY_MODE_UNGRAB:
1099  mode = "Ungrab";
1100  break;
1101  case XCB_NOTIFY_MODE_WHILE_GRABBED:
1102  mode = "WhileGrabbed";
1103  break;
1104  default:
1105  mode = "<unknown>";
1106  break;
1107  }
1108 
1109  switch (event->detail) {
1110  case XCB_NOTIFY_DETAIL_ANCESTOR:
1111  detail = "Ancestor";
1112  break;
1113  case XCB_NOTIFY_DETAIL_VIRTUAL:
1114  detail = "Virtual";
1115  break;
1116  case XCB_NOTIFY_DETAIL_INFERIOR:
1117  detail = "Inferior";
1118  break;
1119  case XCB_NOTIFY_DETAIL_NONLINEAR:
1120  detail = "Nonlinear";
1121  break;
1122  case XCB_NOTIFY_DETAIL_NONLINEAR_VIRTUAL:
1123  detail = "NonlinearVirtual";
1124  break;
1125  case XCB_NOTIFY_DETAIL_POINTER:
1126  detail = "Pointer";
1127  break;
1128  case XCB_NOTIFY_DETAIL_POINTER_ROOT:
1129  detail = "PointerRoot";
1130  break;
1131  case XCB_NOTIFY_DETAIL_NONE:
1132  detail = "NONE";
1133  break;
1134  default:
1135  detail = "unknown";
1136  break;
1137  }
1138 
1139  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);
1140 }
1141 
1142 /*
1143  * Handles ConfigureNotify events for the root window, which are generated when
1144  * the monitor configuration changed.
1145  *
1146  */
1147 static void handle_configure_notify(xcb_configure_notify_event_t *event) {
1148  if (event->event != root) {
1149  DLOG("ConfigureNotify for non-root window 0x%08x, ignoring\n", event->event);
1150  return;
1151  }
1152  DLOG("ConfigureNotify for root window 0x%08x\n", event->event);
1153 
1154  if (force_xinerama) {
1155  return;
1156  }
1158 
1159  ipc_send_event("output", I3_IPC_EVENT_OUTPUT, "{\"change\":\"unspecified\"}");
1160 }
1161 
1162 /*
1163  * Handles SelectionClear events for the root window, which are generated when
1164  * we lose ownership of a selection.
1165  */
1166 static void handle_selection_clear(xcb_selection_clear_event_t *event) {
1167  if (event->selection != wm_sn) {
1168  DLOG("SelectionClear for unknown selection %d, ignoring\n", event->selection);
1169  return;
1170  }
1171  LOG("Lost WM_Sn selection, exiting.\n");
1172  exit(EXIT_SUCCESS);
1173 
1174  /* unreachable */
1175 }
1176 
1177 /*
1178  * Handles the WM_CLASS property for assignments and criteria selection.
1179  *
1180  */
1181 static bool handle_class_change(Con *con, xcb_get_property_reply_t *prop) {
1182  window_update_class(con->window, prop);
1183  con = remanage_window(con);
1184  return true;
1185 }
1186 
1187 /*
1188  * Handles the WM_CLIENT_MACHINE property for assignments and criteria selection.
1189  *
1190  */
1191 static bool handle_machine_change(Con *con, xcb_get_property_reply_t *prop) {
1192  window_update_machine(con->window, prop);
1193  con = remanage_window(con);
1194  return true;
1195 }
1196 
1197 /*
1198  * Handles the _MOTIF_WM_HINTS property of specifying window deocration settings.
1199  *
1200  */
1201 static bool handle_motif_hints_change(Con *con, xcb_get_property_reply_t *prop) {
1202  border_style_t motif_border_style;
1203  bool has_mwm_hints = window_update_motif_hints(con->window, prop, &motif_border_style);
1204 
1205  if (has_mwm_hints && motif_border_style != con->border_style) {
1206  DLOG("Update border style of con %p to %d\n", con, motif_border_style);
1207  con_set_border_style(con, motif_border_style, con->current_border_width);
1208 
1210  }
1211 
1212  return true;
1213 }
1214 
1215 /*
1216  * Handles the _NET_WM_STRUT_PARTIAL property for allocating space for dock clients.
1217  *
1218  */
1219 static bool handle_strut_partial_change(Con *con, xcb_get_property_reply_t *prop) {
1220  window_update_strut_partial(con->window, prop);
1221 
1222  /* we only handle this change for dock clients */
1223  if (con->parent == NULL || con->parent->type != CT_DOCKAREA) {
1224  return true;
1225  }
1226 
1227  Con *search_at = croot;
1228  Con *output = con_get_output(con);
1229  if (output != NULL) {
1230  DLOG("Starting search at output %s\n", output->name);
1231  search_at = output;
1232  }
1233 
1234  /* find out the desired position of this dock window */
1235  if (con->window->reserved.top > 0 && con->window->reserved.bottom == 0) {
1236  DLOG("Top dock client\n");
1237  con->window->dock = W_DOCK_TOP;
1238  } else if (con->window->reserved.top == 0 && con->window->reserved.bottom > 0) {
1239  DLOG("Bottom dock client\n");
1240  con->window->dock = W_DOCK_BOTTOM;
1241  } else {
1242  DLOG("Ignoring invalid reserved edges (_NET_WM_STRUT_PARTIAL), using position as fallback:\n");
1243  if (con->geometry.y < (search_at->rect.height / 2)) {
1244  DLOG("geom->y = %d < rect.height / 2 = %d, it is a top dock client\n",
1245  con->geometry.y, (search_at->rect.height / 2));
1246  con->window->dock = W_DOCK_TOP;
1247  } else {
1248  DLOG("geom->y = %d >= rect.height / 2 = %d, it is a bottom dock client\n",
1249  con->geometry.y, (search_at->rect.height / 2));
1250  con->window->dock = W_DOCK_BOTTOM;
1251  }
1252  }
1253 
1254  /* find the dockarea */
1255  Con *dockarea = con_for_window(search_at, con->window, NULL);
1256  assert(dockarea != NULL);
1257 
1258  /* attach the dock to the dock area */
1259  con_detach(con);
1260  con_attach(con, dockarea, true);
1261 
1262  tree_render();
1263 
1264  return true;
1265 }
1266 
1267 /*
1268  * Handles the _I3_FLOATING_WINDOW property to properly run assignments for
1269  * floating window changes.
1270  *
1271  * This is needed to correctly run the assignments after changes in floating
1272  * windows which are triggered by user commands (floating enable | disable). In
1273  * that case, we can't call run_assignments because it will modify the parser
1274  * state when it needs to parse the user-specified action, breaking the parser
1275  * state for the original command.
1276  *
1277  */
1278 static bool handle_i3_floating(Con *con, xcb_get_property_reply_t *prop) {
1279  DLOG("floating change for con %p\n", con);
1280 
1281  remanage_window(con);
1282 
1283  return true;
1284 }
1285 
1286 static bool handle_windowicon_change(Con *con, xcb_get_property_reply_t *prop) {
1287  window_update_icon(con->window, prop);
1288 
1290 
1291  return true;
1292 }
1293 
1294 /* Returns false if the event could not be processed (e.g. the window could not
1295  * be found), true otherwise */
1296 typedef bool (*cb_property_handler_t)(Con *con, xcb_get_property_reply_t *property);
1297 
1299  xcb_atom_t atom;
1300  uint32_t long_len;
1302 };
1303 
1304 static struct property_handler_t property_handlers[] = {
1305  {0, 128, handle_windowname_change},
1306  {0, UINT_MAX, handle_hints},
1308  {0, UINT_MAX, handle_normal_hints},
1309  {0, UINT_MAX, handle_clientleader_change},
1310  {0, UINT_MAX, handle_transient_for},
1311  {0, 128, handle_windowrole_change},
1312  {0, 128, handle_class_change},
1313  {0, UINT_MAX, handle_strut_partial_change},
1314  {0, UINT_MAX, handle_window_type},
1315  {0, UINT_MAX, handle_i3_floating},
1316  {0, 128, handle_machine_change},
1317  {0, 5 * sizeof(uint64_t), handle_motif_hints_change},
1318  {0, UINT_MAX, handle_windowicon_change}};
1319 #define NUM_HANDLERS (sizeof(property_handlers) / sizeof(struct property_handler_t))
1320 
1321 /*
1322  * Sets the appropriate atoms for the property handlers after the atoms were
1323  * received from X11
1324  *
1325  */
1327  sn_monitor_context_new(sndisplay, conn_screen, startup_monitor_event, NULL, NULL);
1328 
1329  property_handlers[0].atom = A__NET_WM_NAME;
1330  property_handlers[1].atom = XCB_ATOM_WM_HINTS;
1331  property_handlers[2].atom = XCB_ATOM_WM_NAME;
1332  property_handlers[3].atom = XCB_ATOM_WM_NORMAL_HINTS;
1333  property_handlers[4].atom = A_WM_CLIENT_LEADER;
1334  property_handlers[5].atom = XCB_ATOM_WM_TRANSIENT_FOR;
1335  property_handlers[6].atom = A_WM_WINDOW_ROLE;
1336  property_handlers[7].atom = XCB_ATOM_WM_CLASS;
1337  property_handlers[8].atom = A__NET_WM_STRUT_PARTIAL;
1338  property_handlers[9].atom = A__NET_WM_WINDOW_TYPE;
1339  property_handlers[10].atom = A_I3_FLOATING_WINDOW;
1340  property_handlers[11].atom = XCB_ATOM_WM_CLIENT_MACHINE;
1341  property_handlers[12].atom = A__MOTIF_WM_HINTS;
1342  property_handlers[13].atom = A__NET_WM_ICON;
1343 }
1344 
1345 static void property_notify(uint8_t state, xcb_window_t window, xcb_atom_t atom) {
1346  struct property_handler_t *handler = NULL;
1347  xcb_get_property_reply_t *propr = NULL;
1348  xcb_generic_error_t *err = NULL;
1349  Con *con;
1350 
1351  for (size_t c = 0; c < NUM_HANDLERS; c++) {
1352  if (property_handlers[c].atom != atom)
1353  continue;
1354 
1355  handler = &property_handlers[c];
1356  break;
1357  }
1358 
1359  if (handler == NULL) {
1360  /* DLOG("Unhandled property notify for atom %d (0x%08x)\n", atom, atom); */
1361  return;
1362  }
1363 
1364  if ((con = con_by_window_id(window)) == NULL || con->window == NULL) {
1365  DLOG("Received property for atom %d for unknown client\n", atom);
1366  return;
1367  }
1368 
1369  if (state != XCB_PROPERTY_DELETE) {
1370  xcb_get_property_cookie_t cookie = xcb_get_property(conn, 0, window, atom, XCB_GET_PROPERTY_TYPE_ANY, 0, handler->long_len);
1371  propr = xcb_get_property_reply(conn, cookie, &err);
1372  if (err != NULL) {
1373  DLOG("got error %d when getting property of atom %d\n", err->error_code, atom);
1374  FREE(err);
1375  return;
1376  }
1377  }
1378 
1379  /* the handler will free() the reply unless it returns false */
1380  if (!handler->cb(con, propr))
1381  FREE(propr);
1382 }
1383 
1384 /*
1385  * Takes an xcb_generic_event_t and calls the appropriate handler, based on the
1386  * event type.
1387  *
1388  */
1389 void handle_event(int type, xcb_generic_event_t *event) {
1390  if (type != XCB_MOTION_NOTIFY)
1391  DLOG("event type %d, xkb_base %d\n", type, xkb_base);
1392 
1393  if (randr_base > -1 &&
1394  type == randr_base + XCB_RANDR_SCREEN_CHANGE_NOTIFY) {
1395  handle_screen_change(event);
1396  return;
1397  }
1398 
1399  if (xkb_base > -1 && type == xkb_base) {
1400  DLOG("xkb event, need to handle it.\n");
1401 
1402  xcb_xkb_state_notify_event_t *state = (xcb_xkb_state_notify_event_t *)event;
1403  if (state->xkbType == XCB_XKB_NEW_KEYBOARD_NOTIFY) {
1404  DLOG("xkb new keyboard notify, sequence %d, time %d\n", state->sequence, state->time);
1405  xcb_key_symbols_free(keysyms);
1406  keysyms = xcb_key_symbols_alloc(conn);
1407  if (((xcb_xkb_new_keyboard_notify_event_t *)event)->changed & XCB_XKB_NKN_DETAIL_KEYCODES)
1408  (void)load_keymap();
1412  } else if (state->xkbType == XCB_XKB_MAP_NOTIFY) {
1413  if (event_is_ignored(event->sequence, type)) {
1414  DLOG("Ignoring map notify event for sequence %d.\n", state->sequence);
1415  } else {
1416  DLOG("xkb map notify, sequence %d, time %d\n", state->sequence, state->time);
1417  add_ignore_event(event->sequence, type);
1418  xcb_key_symbols_free(keysyms);
1419  keysyms = xcb_key_symbols_alloc(conn);
1423  (void)load_keymap();
1424  }
1425  } else if (state->xkbType == XCB_XKB_STATE_NOTIFY) {
1426  DLOG("xkb state group = %d\n", state->group);
1427  if (xkb_current_group == state->group)
1428  return;
1429  xkb_current_group = state->group;
1432  }
1433 
1434  return;
1435  }
1436 
1437  if (shape_supported && type == shape_base + XCB_SHAPE_NOTIFY) {
1438  xcb_shape_notify_event_t *shape = (xcb_shape_notify_event_t *)event;
1439 
1440  DLOG("shape_notify_event for window 0x%08x, shape_kind = %d, shaped = %d\n",
1441  shape->affected_window, shape->shape_kind, shape->shaped);
1442 
1443  Con *con = con_by_window_id(shape->affected_window);
1444  if (con == NULL) {
1445  LOG("Not a managed window 0x%08x, ignoring shape_notify_event\n",
1446  shape->affected_window);
1447  return;
1448  }
1449 
1450  if (shape->shape_kind == XCB_SHAPE_SK_BOUNDING ||
1451  shape->shape_kind == XCB_SHAPE_SK_INPUT) {
1452  x_set_shape(con, shape->shape_kind, shape->shaped);
1453  }
1454 
1455  return;
1456  }
1457 
1458  switch (type) {
1459  case XCB_KEY_PRESS:
1460  case XCB_KEY_RELEASE:
1461  handle_key_press((xcb_key_press_event_t *)event);
1462  break;
1463 
1464  case XCB_BUTTON_PRESS:
1465  case XCB_BUTTON_RELEASE:
1466  handle_button_press((xcb_button_press_event_t *)event);
1467  break;
1468 
1469  case XCB_MAP_REQUEST:
1470  handle_map_request((xcb_map_request_event_t *)event);
1471  break;
1472 
1473  case XCB_UNMAP_NOTIFY:
1474  handle_unmap_notify_event((xcb_unmap_notify_event_t *)event);
1475  break;
1476 
1477  case XCB_DESTROY_NOTIFY:
1478  handle_destroy_notify_event((xcb_destroy_notify_event_t *)event);
1479  break;
1480 
1481  case XCB_EXPOSE:
1482  if (((xcb_expose_event_t *)event)->count == 0) {
1483  handle_expose_event((xcb_expose_event_t *)event);
1484  }
1485 
1486  break;
1487 
1488  case XCB_MOTION_NOTIFY:
1489  handle_motion_notify((xcb_motion_notify_event_t *)event);
1490  break;
1491 
1492  /* Enter window = user moved their mouse over the window */
1493  case XCB_ENTER_NOTIFY:
1494  handle_enter_notify((xcb_enter_notify_event_t *)event);
1495  break;
1496 
1497  /* Client message are sent to the root window. The only interesting
1498  * client message for us is _NET_WM_STATE, we honour
1499  * _NET_WM_STATE_FULLSCREEN and _NET_WM_STATE_DEMANDS_ATTENTION */
1500  case XCB_CLIENT_MESSAGE:
1501  handle_client_message((xcb_client_message_event_t *)event);
1502  break;
1503 
1504  /* Configure request = window tried to change size on its own */
1505  case XCB_CONFIGURE_REQUEST:
1506  handle_configure_request((xcb_configure_request_event_t *)event);
1507  break;
1508 
1509  /* Mapping notify = keyboard mapping changed (Xmodmap), re-grab bindings */
1510  case XCB_MAPPING_NOTIFY:
1511  handle_mapping_notify((xcb_mapping_notify_event_t *)event);
1512  break;
1513 
1514  case XCB_FOCUS_IN:
1515  handle_focus_in((xcb_focus_in_event_t *)event);
1516  break;
1517 
1518  case XCB_FOCUS_OUT:
1519  handle_focus_out((xcb_focus_out_event_t *)event);
1520  break;
1521 
1522  case XCB_PROPERTY_NOTIFY: {
1523  xcb_property_notify_event_t *e = (xcb_property_notify_event_t *)event;
1524  last_timestamp = e->time;
1525  property_notify(e->state, e->window, e->atom);
1526  break;
1527  }
1528 
1529  case XCB_CONFIGURE_NOTIFY:
1530  handle_configure_notify((xcb_configure_notify_event_t *)event);
1531  break;
1532 
1533  case XCB_SELECTION_CLEAR:
1534  handle_selection_clear((xcb_selection_clear_event_t *)event);
1535  break;
1536 
1537  default:
1538  /* DLOG("Unhandled event of type %d\n", type); */
1539  break;
1540  }
1541 }
focused
struct Con * focused
Definition: tree.c:13
remanage_window
Con * remanage_window(Con *con)
Remanages a window: performs a swallow check and runs assignments.
Definition: manage.c:709
Ignore_Event::response_type
int response_type
Definition: data.h:268
handle_clientleader_change
static bool handle_clientleader_change(Con *con, xcb_get_property_reply_t *prop)
Definition: handlers.c:1013
ipc_send_window_event
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,...
Definition: ipc.c:1634
window_update_name_legacy
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
con_by_window_id
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
handle_enter_notify
static void handle_enter_notify(xcb_enter_notify_event_t *event)
Definition: handlers.c:122
force_xinerama
bool force_xinerama
Definition: main.c:107
fake_absolute_configure_notify
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
i3string_as_utf8
const char * i3string_as_utf8(i3String *str)
Returns the UTF-8 encoded version of the i3String.
handle_windowname_change_legacy
static bool handle_windowname_change_legacy(Con *con, xcb_get_property_reply_t *prop)
Definition: handlers.c:588
handle_button_press
void handle_button_press(xcb_button_press_event_t *event)
The button press X callback.
Definition: click.c:361
SLIST_INSERT_HEAD
#define SLIST_INSERT_HEAD(head, elm, field)
Definition: queue.h:138
ewmh_get_workspace_by_index
Con * ewmh_get_workspace_by_index(uint32_t idx)
Returns the workspace container as enumerated by the EWMH desktop model.
Definition: ewmh.c:353
randr_base
int randr_base
Definition: handlers.c:20
xcb_numlock_mask
unsigned int xcb_numlock_mask
Definition: xcb.c:12
conn_screen
int conn_screen
Definition: main.c:56
ipc_send_event
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
window_name_changed
static bool window_name_changed(i3Window *window, char *old_name)
Definition: handlers.c:551
manage_window
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
handle_configure_request
static void handle_configure_request(xcb_configure_request_event_t *event)
Definition: handlers.c:287
SLIST_HEAD
static SLIST_HEAD(ignore_head, Ignore_Event)
Definition: handlers.c:28
handle_motif_hints_change
static bool handle_motif_hints_change(Con *con, xcb_get_property_reply_t *prop)
Definition: handlers.c:1201
handle_transient_for
static bool handle_transient_for(Con *con, xcb_get_property_reply_t *prop)
Definition: handlers.c:1003
Config::disable_focus_follows_mouse
bool disable_focus_follows_mouse
By default, focus follows mouse.
Definition: configuration.h:126
con_is_leaf
bool con_is_leaf(Con *con)
Returns true when this node is a leaf node (has no children)
Definition: con.c:361
handle_map_request
static void handle_map_request(xcb_map_request_event_t *event)
Definition: handlers.c:268
DONT_KILL_WINDOW
@ DONT_KILL_WINDOW
Definition: data.h:73
Con::rect
struct Rect rect
Definition: data.h:710
all.h
con_is_floating
bool con_is_floating(Con *con)
Returns true if the node is floating.
Definition: con.c:596
Ignore_Event
Definition: data.h:266
scratchpad_show
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
handle_unmap_notify_event
static void handle_unmap_notify_event(xcb_unmap_notify_event_t *event)
Definition: handlers.c:469
wm_sn
xcb_atom_t wm_sn
Definition: main.c:70
Con::name
char * name
Definition: data.h:720
window_update_hints
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
root
xcb_window_t root
Definition: main.c:67
x_set_shape
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:1521
Con::window
struct Window * window
Definition: data.h:746
NUM_HANDLERS
#define NUM_HANDLERS
Definition: handlers.c:1319
XCB_NUM_LOCK
#define XCB_NUM_LOCK
Definition: xcb.h:22
FREE
#define FREE(pointer)
Definition: util.h:47
COPY_MASK_MEMBER
#define COPY_MASK_MEMBER(mask_member, event_member)
handle_strut_partial_change
static bool handle_strut_partial_change(Con *con, xcb_get_property_reply_t *prop)
Definition: handlers.c:1219
Rect
Stores a rectangle, for example the size of a window, the child window etc.
Definition: data.h:207
con_set_border_style
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
SLIST_FIRST
#define SLIST_FIRST(head)
Definition: queue.h:109
con_detach
void con_detach(Con *con)
Detaches the given container from its current parent.
Definition: con.c:230
Ignore_Event::added
time_t added
Definition: data.h:269
_NET_MOVERESIZE_WINDOW_WIDTH
#define _NET_MOVERESIZE_WINDOW_WIDTH
Definition: handlers.c:653
window_update_strut_partial
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
Ignore_Event::sequence
int sequence
Definition: data.h:267
Con
A 'Con' represents everything from the X11 root window down to a single X11 window.
Definition: data.h:671
y
#define y(x,...)
Definition: commands.c:18
workspace_is_visible
bool workspace_is_visible(Con *ws)
Returns true if the workspace is currently visible.
Definition: workspace.c:314
KILL_WINDOW
@ KILL_WINDOW
Definition: data.h:74
handle_windowrole_change
static bool handle_windowrole_change(Con *con, xcb_get_property_reply_t *prop)
Definition: handlers.c:609
xkb_base
int xkb_base
Definition: handlers.c:21
handle_mapping_notify
static void handle_mapping_notify(xcb_mapping_notify_event_t *event)
Definition: handlers.c:249
tree_close_internal
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
handle_windowicon_change
static bool handle_windowicon_change(Con *con, xcb_get_property_reply_t *prop)
Definition: handlers.c:1286
property_handler_t::cb
cb_property_handler_t cb
Definition: handlers.c:1301
Window::id
xcb_window_t id
Definition: data.h:447
Rect::y
uint32_t y
Definition: data.h:209
border_style_t
border_style_t
Definition: data.h:65
window_update_normal_hints
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
aio_get_mod_mask_for
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,...
sndisplay
SnDisplay * sndisplay
Definition: main.c:59
Window
A 'Window' is a type which contains an xcb_window_t and all the related information (hints like _NET_...
Definition: data.h:446
window_update_class
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
LOG
#define LOG(fmt,...)
Definition: libi3.h:95
xoutput::con
Con * con
Pointer to the Con which represents this output.
Definition: data.h:433
Con::fullscreen_mode
fullscreen_mode_t fullscreen_mode
Definition: data.h:762
Con::deco_rect
struct Rect deco_rect
Definition: data.h:716
handle_client_message
static void handle_client_message(xcb_client_message_event_t *event)
Definition: handlers.c:660
Window::dock
enum Window::@11 dock
Whether the window says it is a dock window.
floating_reposition
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
Con::border_style
border_style_t border_style
Definition: data.h:785
sync_respond
void sync_respond(xcb_window_t window, uint32_t rnd)
Definition: sync.c:12
randr_query_outputs
void randr_query_outputs(void)
(Re-)queries the outputs via RandR and stores them in the list of outputs.
Definition: randr.c:912
translate_keysyms
void translate_keysyms(void)
Translates keysymbols to keycodes for all bindings which use keysyms.
Definition: bindings.c:434
sstrdup
char * sstrdup(const char *str)
Safe-wrapper around strdup which exits if malloc returns NULL (meaning that there is no more memory a...
Rect::width
uint32_t width
Definition: data.h:210
floating_check_size
void floating_check_size(Con *floating_con, bool prefer_height)
Called when a floating window is created or resized.
Definition: floating.c:75
output_primary_name
char * output_primary_name(Output *output)
Retrieves the primary name of an output.
Definition: output.c:53
Con::ignore_unmap
uint8_t ignore_unmap
This counter contains the number of UnmapNotify events for this container (or, more precisely,...
Definition: data.h:683
SLIST_END
#define SLIST_END(head)
Definition: queue.h:110
con_border_style_rect
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
_NET_MOVERESIZE_WINDOW_HEIGHT
#define _NET_MOVERESIZE_WINDOW_HEIGHT
Definition: handlers.c:654
con_get_output
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
handle_windowname_change
static bool handle_windowname_change(Con *con, xcb_get_property_reply_t *prop)
Definition: handlers.c:566
window_update_machine
void window_update_machine(i3Window *win, xcb_get_property_reply_t *prop)
Updates the WM_CLIENT_MACHINE.
Definition: window.c:560
floating_enable
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
ELOG
#define ELOG(fmt,...)
Definition: libi3.h:100
workspace_show
void workspace_show(Con *workspace)
Switches to the given workspace.
Definition: workspace.c:428
con_is_internal
bool con_is_internal(Con *con)
Returns true if the container is internal, such as __i3_scratch.
Definition: con.c:588
Con::border_width
int border_width
Definition: data.h:743
Con::current_border_width
int current_border_width
Definition: data.h:744
rect_contains
bool rect_contains(Rect rect, uint32_t x, uint32_t y)
Definition: util.c:32
Window::name
i3String * name
The name of the window.
Definition: data.h:463
handle_normal_hints
static bool handle_normal_hints(Con *con, xcb_get_property_reply_t *reply)
Definition: handlers.c:968
TAILQ_FOREACH_REVERSE
#define TAILQ_FOREACH_REVERSE(var, head, headname, field)
Definition: queue.h:352
property_handlers
static struct property_handler_t property_handlers[]
Definition: handlers.c:1304
startup_monitor_event
void startup_monitor_event(SnMonitorEvent *event, void *userdata)
Called by libstartup-notification when something happens.
Definition: startup.c:208
window_update_type
void window_update_type(i3Window *window, xcb_get_property_reply_t *reply)
Updates the _NET_WM_WINDOW_TYPE property.
Definition: window.c:295
Con::urgent
bool urgent
Definition: data.h:676
x_push_changes
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:1231
property_handler_t
Definition: handlers.c:1298
SLIST_REMOVE
#define SLIST_REMOVE(head, elm, type, field)
Definition: queue.h:154
Rect::height
uint32_t height
Definition: data.h:211
handle_event
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:1389
Con::floating
enum Con::@19 floating
floating? (= not in tiling layout) This cannot be simply a bool because we want to keep track of whet...
window_update_transient_for
void window_update_transient_for(i3Window *win, xcb_get_property_reply_t *prop)
Updates the TRANSIENT_FOR (logical parent window).
Definition: window.c:224
event_is_ignored
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
state
static cmdp_state state
Definition: commands_parser.c:144
L_DEFAULT
@ L_DEFAULT
Definition: data.h:106
handle_configure_notify
static void handle_configure_notify(xcb_configure_notify_event_t *event)
Definition: handlers.c:1147
handle_selection_clear
static void handle_selection_clear(xcb_selection_clear_event_t *event)
Definition: handlers.c:1166
scalloc
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...
Rect::x
uint32_t x
Definition: data.h:208
handle_screen_change
static void handle_screen_change(xcb_generic_event_t *e)
Definition: handlers.c:441
output_push_sticky_windows
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
con_by_frame_id
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
handle_class_change
static bool handle_class_change(Con *con, xcb_get_property_reply_t *prop)
Definition: handlers.c:1181
con_inside_floating
Con * con_inside_floating(Con *con)
Checks if the given container is either floating or inside some floating container.
Definition: con.c:620
layout_t
layout_t
Container layouts.
Definition: data.h:105
ewmh_update_sticky
void ewmh_update_sticky(xcb_window_t window, bool sticky)
Set or remove _NET_WM_STATE_STICKY on the window.
Definition: ewmh.c:279
_NET_WM_STATE_TOGGLE
#define _NET_WM_STATE_TOGGLE
Definition: xcb.h:19
last_timestamp
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
handle_i3_floating
static bool handle_i3_floating(Con *con, xcb_get_property_reply_t *prop)
Definition: handlers.c:1278
Con::geometry
struct Rect geometry
the geometry this window requested when getting mapped
Definition: data.h:718
L_SPLITV
@ L_SPLITV
Definition: data.h:111
scratchpad_fix_resolution
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
Con::parent
struct Con * parent
Definition: data.h:706
con_set_urgency
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
focused_id
xcb_window_t focused_id
Stores the X11 window ID of the currently focused window.
Definition: x.c:20
cb_property_handler_t
bool(* cb_property_handler_t)(Con *con, xcb_get_property_reply_t *property)
Definition: handlers.c:1296
con_attach
void con_attach(Con *con, Con *parent, bool ignore_focus)
Attaches the given container to the given parent.
Definition: con.c:222
property_handlers_init
void property_handlers_init(void)
Sets the appropriate atoms for the property handlers after the atoms were received from X11.
Definition: handlers.c:1326
con_for_window
Con * con_for_window(Con *con, i3Window *window, Match **store_match)
Returns the first container below 'con' which wants to swallow this window TODO: priority.
Definition: con.c:890
CF_NONE
@ CF_NONE
Definition: data.h:657
handle_focus_out
static void handle_focus_out(xcb_focus_in_event_t *event)
Definition: handlers.c:1076
window_update_role
void window_update_role(i3Window *win, xcb_get_property_reply_t *prop)
Updates the WM_WINDOW_ROLE.
Definition: window.c:274
Config::default_border_width
int default_border_width
Definition: configuration.h:116
_NET_WM_MOVERESIZE_SIZE_LEFT
#define _NET_WM_MOVERESIZE_SIZE_LEFT
Definition: handlers.c:645
reservedpx::top
uint32_t top
Definition: data.h:222
config
Config config
Definition: config.c:19
Con::frame
surface_t frame
Definition: data.h:686
workspace_get
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
check_crossing_screen_boundary
static void check_crossing_screen_boundary(uint32_t x, uint32_t y)
Definition: handlers.c:88
ewmh_update_wm_desktop
void ewmh_update_wm_desktop(void)
Updates _NET_WM_DESKTOP for all windows.
Definition: ewmh.c:184
croot
struct Con * croot
Definition: tree.c:12
load_keymap
bool load_keymap(void)
Loads the XKB keymap from the X11 server and feeds it to xkbcommon.
Definition: bindings.c:956
_NET_WM_MOVERESIZE_MOVE
#define _NET_WM_MOVERESIZE_MOVE
Definition: handlers.c:646
output_get_content
Con * output_get_content(Con *output)
Returns the output container below the given output container.
Definition: output.c:16
handle_hints
static bool handle_hints(Con *con, xcb_get_property_reply_t *reply)
Definition: handlers.c:987
floating_resize_window
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
con_toggle_fullscreen
void con_toggle_fullscreen(Con *con, int fullscreen_mode)
Toggles fullscreen mode for the given container.
Definition: con.c:1095
property_handler_t::atom
xcb_atom_t atom
Definition: handlers.c:1299
handle_machine_change
static bool handle_machine_change(Con *con, xcb_get_property_reply_t *prop)
Definition: handlers.c:1191
_NET_MOVERESIZE_WINDOW_Y
#define _NET_MOVERESIZE_WINDOW_Y
Definition: handlers.c:652
_NET_WM_STATE_REMOVE
#define _NET_WM_STATE_REMOVE
Definition: xcb.h:17
ungrab_all_keys
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
window_update_name
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
Match
A "match" is a data structure which acts like a mask or expression to match certain windows or not.
Definition: data.h:557
keysyms
xcb_key_symbols_t * keysyms
Definition: main.c:81
Con::sticky
bool sticky
Definition: data.h:767
window_update_motif_hints
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
Config::focus_on_window_activation
enum Config::@4 focus_on_window_activation
Behavior when a window sends a NET_ACTIVE_WINDOW message.
con_descend_focused
Con * con_descend_focused(Con *con)
Returns the focused con inside this client, descending the tree as far as possible.
Definition: con.c:1590
TAILQ_FIRST
#define TAILQ_FIRST(head)
Definition: queue.h:336
tree_render
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
L_SPLITH
@ L_SPLITH
Definition: data.h:112
con_move_to_workspace
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
handle_expose_event
static void handle_expose_event(xcb_expose_event_t *event)
Definition: handlers.c:621
Con::frame_buffer
surface_t frame_buffer
Definition: data.h:687
_NET_MOVERESIZE_WINDOW_X
#define _NET_MOVERESIZE_WINDOW_X
Definition: handlers.c:651
_NET_WM_MOVERESIZE_SIZE_TOPLEFT
#define _NET_WM_MOVERESIZE_SIZE_TOPLEFT
Definition: handlers.c:638
SLIST_FOREACH
#define SLIST_FOREACH(var, head, field)
Definition: queue.h:114
con_activate_unblock
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
handle_motion_notify
static void handle_motion_notify(xcb_motion_notify_event_t *event)
Definition: handlers.c:195
property_handler_t::long_len
uint32_t long_len
Definition: handlers.c:1300
Con::layout
layout_t layout
Definition: data.h:783
xoutput
An Output is a physical output on your graphics driver.
Definition: data.h:413
DLOG
#define DLOG(fmt,...)
Definition: libi3.h:105
grab_all_keys
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
con_get_fullscreen_covering_ws
Con * con_get_fullscreen_covering_ws(Con *ws)
Returns the fullscreen node that covers the given workspace if it exists.
Definition: con.c:573
add_ignore_event
void add_ignore_event(const int sequence, const int response_type)
Adds the given sequence to the list of events which are ignored.
window_update_leader
void window_update_leader(i3Window *win, xcb_get_property_reply_t *prop)
Updates the CLIENT_LEADER (logical parent window).
Definition: window.c:199
shape_supported
bool shape_supported
Definition: main.c:105
con_focus
void con_focus(Con *con)
Sets input focus to the given container.
Definition: con.c:246
SLIST_NEXT
#define SLIST_NEXT(elm, field)
Definition: queue.h:112
xkb_current_group
int xkb_current_group
Definition: handlers.c:22
get_output_containing
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
reservedpx::bottom
uint32_t bottom
Definition: data.h:223
Window::reserved
struct reservedpx reserved
Pixels the window reserves.
Definition: data.h:507
window_update_icon
void window_update_icon(i3Window *win, xcb_get_property_reply_t *prop)
Updates the _NET_WM_ICON.
Definition: window.c:574
_NET_WM_STATE_ADD
#define _NET_WM_STATE_ADD
Definition: xcb.h:18
handle_window_type
static bool handle_window_type(Con *con, xcb_get_property_reply_t *reply)
Definition: handlers.c:956
CF_OUTPUT
@ CF_OUTPUT
Definition: data.h:658
floating_drag_window
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
handle_destroy_notify_event
static void handle_destroy_notify_event(xcb_destroy_notify_event_t *event)
Definition: handlers.c:540
NET_WM_DESKTOP_ALL
#define NET_WM_DESKTOP_ALL
Definition: workspace.h:25
render_deco_height
int render_deco_height(void)
Returns the height for the decorations.
Definition: render.c:27
draw_util_copy_surface
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.
con_get_workspace
Con * con_get_workspace(Con *con)
Gets the workspace container this node is on.
Definition: con.c:477
shape_base
int shape_base
Definition: handlers.c:23
handle_focus_in
static void handle_focus_in(xcb_focus_in_event_t *event)
Definition: handlers.c:1024
conn
xcb_connection_t * conn
XCB connection and root screen.
Definition: main.c:54
handle_key_press
void handle_key_press(xcb_key_press_event_t *event)
There was a key press.
Definition: key_press.c:18
property_notify
static void property_notify(uint8_t state, xcb_window_t window, xcb_atom_t atom)
Definition: handlers.c:1345
smalloc
void * smalloc(size_t size)
Safe-wrapper around malloc which exits if malloc returns NULL (meaning that there is no more memory a...
Con::type
enum Con::@18 type