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