i3
x.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  * x.c: Interface to X11, transfers our in-memory state to X11 (see also
8  * render.c). Basically a big state machine.
9  *
10  */
11 #include "all.h"
12 
13 #ifndef MAX
14 #define MAX(x, y) ((x) > (y) ? (x) : (y))
15 #endif
16 
17 xcb_window_t ewmh_window;
18 
19 /* Stores the X11 window ID of the currently focused window */
20 xcb_window_t focused_id = XCB_NONE;
21 
22 /* Because 'focused_id' might be reset to force input focus, we separately keep
23  * track of the X11 window ID to be able to always tell whether the focused
24  * window actually changed. */
25 static xcb_window_t last_focused = XCB_NONE;
26 
27 /* Stores coordinates to warp mouse pointer to if set */
28 static Rect *warp_to;
29 
30 /*
31  * Describes the X11 state we may modify (map state, position, window stack).
32  * There is one entry per container. The state represents the current situation
33  * as X11 sees it (with the exception of the order in the state_head CIRCLEQ,
34  * which represents the order that will be pushed to X11, while old_state_head
35  * represents the current order). It will be updated in x_push_changes().
36  *
37  */
38 typedef struct con_state {
39  xcb_window_t id;
40  bool mapped;
41  bool unmap_now;
43  bool is_hidden;
44 
46  Con *con;
47 
48  /* For reparenting, we have a flag (need_reparent) and the X ID of the old
49  * frame this window was in. The latter is necessary because we need to
50  * ignore UnmapNotify events (by changing the window event mask). */
52  xcb_window_t old_frame;
53 
56 
57  bool initial;
58 
59  char *name;
60 
63 
66 
69 } con_state;
70 
72 state_head =
73  CIRCLEQ_HEAD_INITIALIZER(state_head);
74 
76 old_state_head =
77  CIRCLEQ_HEAD_INITIALIZER(old_state_head);
78 
80 initial_mapping_head =
81  TAILQ_HEAD_INITIALIZER(initial_mapping_head);
82 
83 /*
84  * Returns the container state for the given frame. This function always
85  * returns a container state (otherwise, there is a bug in the code and the
86  * container state of a container for which x_con_init() was not called was
87  * requested).
88  *
89  */
90 static con_state *state_for_frame(xcb_window_t window) {
92  CIRCLEQ_FOREACH(state, &state_head, state)
93  if (state->id == window)
94  return state;
95 
96  /* TODO: better error handling? */
97  ELOG("No state found\n");
98  assert(false);
99  return NULL;
100 }
101 
102 /*
103  * Initializes the X11 part for the given container. Called exactly once for
104  * every container from con_new().
105  *
106  */
107 void x_con_init(Con *con) {
108  /* TODO: maybe create the window when rendering first? we could then even
109  * get the initial geometry right */
110 
111  uint32_t mask = 0;
112  uint32_t values[5];
113 
114  xcb_visualid_t visual = get_visualid_by_depth(con->depth);
115  xcb_colormap_t win_colormap;
116  if (con->depth != root_depth) {
117  /* We need to create a custom colormap. */
118  win_colormap = xcb_generate_id(conn);
119  xcb_create_colormap(conn, XCB_COLORMAP_ALLOC_NONE, win_colormap, root, visual);
120  con->colormap = win_colormap;
121  } else {
122  /* Use the default colormap. */
123  win_colormap = colormap;
124  con->colormap = XCB_NONE;
125  }
126 
127  /* We explicitly set a background color and border color (even though we
128  * don’t even have a border) because the X11 server requires us to when
129  * using 32 bit color depths, see
130  * https://stackoverflow.com/questions/3645632 */
131  mask |= XCB_CW_BACK_PIXEL;
132  values[0] = root_screen->black_pixel;
133 
134  mask |= XCB_CW_BORDER_PIXEL;
135  values[1] = root_screen->black_pixel;
136 
137  /* our own frames should not be managed */
138  mask |= XCB_CW_OVERRIDE_REDIRECT;
139  values[2] = 1;
140 
141  /* see include/xcb.h for the FRAME_EVENT_MASK */
142  mask |= XCB_CW_EVENT_MASK;
143  values[3] = FRAME_EVENT_MASK & ~XCB_EVENT_MASK_ENTER_WINDOW;
144 
145  mask |= XCB_CW_COLORMAP;
146  values[4] = win_colormap;
147 
148  Rect dims = {-15, -15, 10, 10};
149  xcb_window_t frame_id = create_window(conn, dims, con->depth, visual, XCB_WINDOW_CLASS_INPUT_OUTPUT, XCURSOR_CURSOR_POINTER, false, mask, values);
150  draw_util_surface_init(conn, &(con->frame), frame_id, get_visualtype_by_id(visual), dims.width, dims.height);
151  xcb_change_property(conn,
152  XCB_PROP_MODE_REPLACE,
153  con->frame.id,
154  XCB_ATOM_WM_CLASS,
155  XCB_ATOM_STRING,
156  8,
157  (strlen("i3-frame") + 1) * 2,
158  "i3-frame\0i3-frame\0");
159 
160  struct con_state *state = scalloc(1, sizeof(struct con_state));
161  state->id = con->frame.id;
162  state->mapped = false;
163  state->initial = true;
164  DLOG("Adding window 0x%08x to lists\n", state->id);
165  CIRCLEQ_INSERT_HEAD(&state_head, state, state);
168  DLOG("adding new state for window id 0x%08x\n", state->id);
169 }
170 
171 /*
172  * Re-initializes the associated X window state for this container. You have
173  * to call this when you assign a client to an empty container to ensure that
174  * its state gets updated correctly.
175  *
176  */
177 void x_reinit(Con *con) {
178  struct con_state *state;
179 
180  if ((state = state_for_frame(con->frame.id)) == NULL) {
181  ELOG("window state not found\n");
182  return;
183  }
184 
185  DLOG("resetting state %p to initial\n", state);
186  state->initial = true;
187  state->child_mapped = false;
188  state->con = con;
189  memset(&(state->window_rect), 0, sizeof(Rect));
190 }
191 
192 /*
193  * Reparents the child window of the given container (necessary for sticky
194  * containers). The reparenting happens in the next call of x_push_changes().
195  *
196  */
197 void x_reparent_child(Con *con, Con *old) {
198  struct con_state *state;
199  if ((state = state_for_frame(con->frame.id)) == NULL) {
200  ELOG("window state for con not found\n");
201  return;
202  }
203 
204  state->need_reparent = true;
205  state->old_frame = old->frame.id;
206 }
207 
208 /*
209  * Moves a child window from Container src to Container dest.
210  *
211  */
212 void x_move_win(Con *src, Con *dest) {
213  struct con_state *state_src, *state_dest;
214 
215  if ((state_src = state_for_frame(src->frame.id)) == NULL) {
216  ELOG("window state for src not found\n");
217  return;
218  }
219 
220  if ((state_dest = state_for_frame(dest->frame.id)) == NULL) {
221  ELOG("window state for dest not found\n");
222  return;
223  }
224 
225  state_dest->con = state_src->con;
226  state_src->con = NULL;
227 
228  Rect zero = {0, 0, 0, 0};
229  if (memcmp(&(state_dest->window_rect), &(zero), sizeof(Rect)) == 0) {
230  memcpy(&(state_dest->window_rect), &(state_src->window_rect), sizeof(Rect));
231  DLOG("COPYING RECT\n");
232  }
233 }
234 
235 /*
236  * Kills the window decoration associated with the given container.
237  *
238  */
239 void x_con_kill(Con *con) {
240  con_state *state;
241 
242  if (con->colormap != XCB_NONE) {
243  xcb_free_colormap(conn, con->colormap);
244  }
245 
248  xcb_destroy_window(conn, con->frame.id);
249  xcb_free_pixmap(conn, con->frame_buffer.id);
250  state = state_for_frame(con->frame.id);
251  CIRCLEQ_REMOVE(&state_head, state, state);
254  FREE(state->name);
255  free(state);
256 
257  /* Invalidate focused_id to correctly focus new windows with the same ID */
258  focused_id = last_focused = XCB_NONE;
259 }
260 
261 /*
262  * Returns true if the client supports the given protocol atom (like WM_DELETE_WINDOW)
263  *
264  */
265 bool window_supports_protocol(xcb_window_t window, xcb_atom_t atom) {
266  xcb_get_property_cookie_t cookie;
267  xcb_icccm_get_wm_protocols_reply_t protocols;
268  bool result = false;
269 
270  cookie = xcb_icccm_get_wm_protocols(conn, window, A_WM_PROTOCOLS);
271  if (xcb_icccm_get_wm_protocols_reply(conn, cookie, &protocols, NULL) != 1)
272  return false;
273 
274  /* Check if the client’s protocols have the requested atom set */
275  for (uint32_t i = 0; i < protocols.atoms_len; i++)
276  if (protocols.atoms[i] == atom)
277  result = true;
278 
279  xcb_icccm_get_wm_protocols_reply_wipe(&protocols);
280 
281  return result;
282 }
283 
284 /*
285  * Kills the given X11 window using WM_DELETE_WINDOW (if supported).
286  *
287  */
288 void x_window_kill(xcb_window_t window, kill_window_t kill_window) {
289  /* if this window does not support WM_DELETE_WINDOW, we kill it the hard way */
290  if (!window_supports_protocol(window, A_WM_DELETE_WINDOW)) {
291  if (kill_window == KILL_WINDOW) {
292  LOG("Killing specific window 0x%08x\n", window);
293  xcb_destroy_window(conn, window);
294  } else {
295  LOG("Killing the X11 client which owns window 0x%08x\n", window);
296  xcb_kill_client(conn, window);
297  }
298  return;
299  }
300 
301  /* Every X11 event is 32 bytes long. Therefore, XCB will copy 32 bytes.
302  * In order to properly initialize these bytes, we allocate 32 bytes even
303  * though we only need less for an xcb_configure_notify_event_t */
304  void *event = scalloc(32, 1);
305  xcb_client_message_event_t *ev = event;
306 
307  ev->response_type = XCB_CLIENT_MESSAGE;
308  ev->window = window;
309  ev->type = A_WM_PROTOCOLS;
310  ev->format = 32;
311  ev->data.data32[0] = A_WM_DELETE_WINDOW;
312  ev->data.data32[1] = XCB_CURRENT_TIME;
313 
314  LOG("Sending WM_DELETE to the client\n");
315  xcb_send_event(conn, false, window, XCB_EVENT_MASK_NO_EVENT, (char *)ev);
316  xcb_flush(conn);
317  free(event);
318 }
319 
320 static void x_draw_title_border(Con *con, struct deco_render_params *p) {
321  assert(con->parent != NULL);
322 
323  Rect *dr = &(con->deco_rect);
324  adjacent_t borders_to_hide = con_adjacent_borders(con) & config.hide_edge_borders;
325  int deco_diff_l = borders_to_hide & ADJ_LEFT_SCREEN_EDGE ? 0 : con->current_border_width;
326  int deco_diff_r = borders_to_hide & ADJ_RIGHT_SCREEN_EDGE ? 0 : con->current_border_width;
327  if (con->parent->layout == L_TABBED ||
328  (con->parent->layout == L_STACKED && TAILQ_NEXT(con, nodes) != NULL)) {
329  deco_diff_l = 0;
330  deco_diff_r = 0;
331  }
332 
334  dr->x, dr->y, dr->width, 1);
335 
337  dr->x + deco_diff_l, dr->y + dr->height - 1, dr->width - (deco_diff_l + deco_diff_r), 1);
338 }
339 
341  assert(con->parent != NULL);
342 
343  Rect *dr = &(con->deco_rect);
344 
345  /* Redraw the right border to cut off any text that went past it.
346  * This is necessary when the text was drawn using XCB since cutting text off
347  * automatically does not work there. For pango rendering, this isn't necessary. */
348  if (!font_is_pango()) {
349  /* We actually only redraw the far right two pixels as that is the
350  * distance we keep from the edge (not the entire border width).
351  * Redrawing the entire border would cause text to be cut off. */
353  dr->x + dr->width - 2 * logical_px(1),
354  dr->y,
355  2 * logical_px(1),
356  dr->height);
357  }
358 
359  /* Draw a 1px separator line before and after every tab, so that tabs can
360  * be easily distinguished. */
361  if (con->parent->layout == L_TABBED) {
362  /* Left side */
364  dr->x, dr->y, 1, dr->height);
365 
366  /* Right side */
368  dr->x + dr->width - 1, dr->y, 1, dr->height);
369  }
370 
371  /* Redraw the border. */
372  x_draw_title_border(con, p);
373 }
374 
375 /*
376  * Draws the decoration of the given container onto its parent.
377  *
378  */
379 void x_draw_decoration(Con *con) {
380  Con *parent = con->parent;
381  bool leaf = con_is_leaf(con);
382 
383  /* This code needs to run for:
384  * • leaf containers
385  * • non-leaf containers which are in a stacked/tabbed container
386  *
387  * It does not need to run for:
388  * • direct children of outputs or dockareas
389  * • floating containers (they don’t have a decoration)
390  */
391  if ((!leaf &&
392  parent->layout != L_STACKED &&
393  parent->layout != L_TABBED) ||
394  parent->type == CT_OUTPUT ||
395  parent->type == CT_DOCKAREA ||
396  con->type == CT_FLOATING_CON)
397  return;
398 
399  /* Skip containers whose height is 0 (for example empty dockareas) */
400  if (con->rect.height == 0)
401  return;
402 
403  /* Skip containers whose pixmap has not yet been created (can happen when
404  * decoration rendering happens recursively for a window for which
405  * x_push_node() was not yet called) */
406  if (leaf && con->frame_buffer.id == XCB_NONE)
407  return;
408 
409  /* 1: build deco_params and compare with cache */
410  struct deco_render_params *p = scalloc(1, sizeof(struct deco_render_params));
411 
412  /* Find out which Qubes label to use */
413  qube_label_t label = QUBE_DOM0;
414  struct Window *win = con->window;
415  if (win != NULL) {
416  DLOG("con->qubes_label is %d\n", win->qubes_label);
417  if (win->qubes_label >= 0 && win->qubes_label < QUBE_NUM_LABELS) {
418  label = win->qubes_label;
419  }
420  }
421 
422  /* find out which colors to use */
423  if (con->urgent)
424  p->color = &config.client[label].urgent;
425  else if (con == focused || con_inside_focused(con))
426  p->color = &config.client[label].focused;
427  else if (con == TAILQ_FIRST(&(parent->focus_head)))
428  p->color = &config.client[label].focused_inactive;
429  else
430  p->color = &config.client[label].unfocused;
431 
432  p->border_style = con_border_style(con);
433 
434  Rect *r = &(con->rect);
435  Rect *w = &(con->window_rect);
436  p->con_rect = (struct width_height){r->width, r->height};
437  p->con_window_rect = (struct width_height){w->width, w->height};
438  p->con_deco_rect = con->deco_rect;
440  p->con_is_leaf = con_is_leaf(con);
441  p->parent_layout = con->parent->layout;
442 
443  if (con->deco_render_params != NULL &&
444  (con->window == NULL || !con->window->name_x_changed) &&
445  !parent->pixmap_recreated &&
446  !con->pixmap_recreated &&
447  !con->mark_changed &&
448  memcmp(p, con->deco_render_params, sizeof(struct deco_render_params)) == 0) {
449  free(p);
450  goto copy_pixmaps;
451  }
452 
453  Con *next = con;
454  while ((next = TAILQ_NEXT(next, nodes))) {
455  FREE(next->deco_render_params);
456  }
457 
458  FREE(con->deco_render_params);
459  con->deco_render_params = p;
460 
461  if (con->window != NULL && con->window->name_x_changed)
462  con->window->name_x_changed = false;
463 
464  parent->pixmap_recreated = false;
465  con->pixmap_recreated = false;
466  con->mark_changed = false;
467 
468  /* 2: draw the client.background, but only for the parts around the window_rect */
469  if (con->window != NULL) {
470  /* top area */
472  0, 0, r->width, w->y);
473  /* bottom area */
475  0, w->y + w->height, r->width, r->height - (w->y + w->height));
476  /* left area */
478  0, 0, w->x, r->height);
479  /* right area */
481  w->x + w->width, 0, r->width - (w->x + w->width), r->height);
482  }
483 
484  /* 3: draw a rectangle in border color around the client */
485  if (p->border_style != BS_NONE && p->con_is_leaf) {
486  /* We might hide some borders adjacent to the screen-edge */
487  adjacent_t borders_to_hide = ADJ_NONE;
488  borders_to_hide = con_adjacent_borders(con) & config.hide_edge_borders;
489 
490  Rect br = con_border_style_rect(con);
491 
492  /* These rectangles represent the border around the child window
493  * (left, bottom and right part). We don’t just fill the whole
494  * rectangle because some childs are not freely resizable and we want
495  * their background color to "shine through". */
496  if (!(borders_to_hide & ADJ_LEFT_SCREEN_EDGE)) {
497  draw_util_rectangle(&(con->frame_buffer), p->color->child_border, 0, 0, br.x, r->height);
498  }
499  if (!(borders_to_hide & ADJ_RIGHT_SCREEN_EDGE)) {
501  p->color->child_border, r->width + (br.width + br.x), 0,
502  -(br.width + br.x), r->height);
503  }
504  if (!(borders_to_hide & ADJ_LOWER_SCREEN_EDGE)) {
506  p->color->child_border, br.x, r->height + (br.height + br.y),
507  r->width + br.width, -(br.height + br.y));
508  }
509  /* pixel border needs an additional line at the top */
510  if (p->border_style == BS_PIXEL && !(borders_to_hide & ADJ_UPPER_SCREEN_EDGE)) {
512  p->color->child_border, br.x, 0, r->width + br.width, br.y);
513  }
514 
515  /* Highlight the side of the border at which the next window will be
516  * opened if we are rendering a single window within a split container
517  * (which is undistinguishable from a single window outside a split
518  * container otherwise. */
519  if (TAILQ_NEXT(con, nodes) == NULL &&
520  TAILQ_PREV(con, nodes_head, nodes) == NULL &&
521  con->parent->type != CT_FLOATING_CON) {
522  if (p->parent_layout == L_SPLITH) {
524  r->width + (br.width + br.x), br.y, -(br.width + br.x), r->height + br.height);
525  } else if (p->parent_layout == L_SPLITV) {
527  br.x, r->height + (br.height + br.y), r->width + br.width, -(br.height + br.y));
528  }
529  }
530  }
531 
532  /* if this is a borderless/1pixel window, we don’t need to render the
533  * decoration. */
534  if (p->border_style != BS_NORMAL)
535  goto copy_pixmaps;
536 
537  /* If the parent hasn't been set up yet, skip the decoration rendering
538  * for now. */
539  if (parent->frame_buffer.id == XCB_NONE)
540  goto copy_pixmaps;
541 
542  /* For the first child, we clear the parent pixmap to ensure there's no
543  * garbage left on there. This is important to avoid tearing when using
544  * transparency. */
545  if (con == TAILQ_FIRST(&(con->parent->nodes_head))) {
548  }
549 
550  /* 4: paint the bar */
552  con->deco_rect.x, con->deco_rect.y, con->deco_rect.width, con->deco_rect.height);
553 
554  /* 5: draw two unconnected horizontal lines in border color */
555  x_draw_title_border(con, p);
556 
557  /* 6: draw the title */
558  int text_offset_y = (con->deco_rect.height - config.font.height) / 2;
559 
560  if (win == NULL) {
561  i3String *title;
562  if (con->title_format == NULL) {
563  char *_title;
564  char *tree = con_get_tree_representation(con);
565  sasprintf(&_title, "i3: %s", tree);
566  free(tree);
567 
568  title = i3string_from_utf8(_title);
569  FREE(_title);
570  } else {
571  title = con_parse_title_format(con);
572  }
573 
574  draw_util_text(title, &(parent->frame_buffer),
575  p->color->text, p->color->background,
576  con->deco_rect.x + logical_px(2),
577  con->deco_rect.y + text_offset_y,
578  con->deco_rect.width - 2 * logical_px(2));
579  I3STRING_FREE(title);
580 
581  goto after_title;
582  }
583 
584  int mark_width = 0;
585  if (config.show_marks && !TAILQ_EMPTY(&(con->marks_head))) {
586  char *formatted_mark = sstrdup("");
587  bool had_visible_mark = false;
588 
589  mark_t *mark;
590  TAILQ_FOREACH(mark, &(con->marks_head), marks) {
591  if (mark->name[0] == '_')
592  continue;
593  had_visible_mark = true;
594 
595  char *buf;
596  sasprintf(&buf, "%s[%s]", formatted_mark, mark->name);
597  free(formatted_mark);
598  formatted_mark = buf;
599  }
600 
601  if (had_visible_mark) {
602  i3String *mark = i3string_from_utf8(formatted_mark);
603  mark_width = predict_text_width(mark);
604 
605  draw_util_text(mark, &(parent->frame_buffer),
606  p->color->text, p->color->background,
607  con->deco_rect.x + con->deco_rect.width - mark_width - logical_px(2),
608  con->deco_rect.y + text_offset_y, mark_width);
609 
610  I3STRING_FREE(mark);
611  }
612 
613  FREE(formatted_mark);
614  }
615 
616  /* set window title, include qubes vmname */
617  i3String *title = con->title_format == NULL ? win->name : con_parse_title_format(con);
618  if (title == NULL) {
619  goto copy_pixmaps;
620  }
621 
622  char *title_buf;
623  sasprintf(&title_buf, "[%s] %s", i3string_as_utf8(win->qubes_vmname), i3string_as_utf8(title));
624  if (con->title_format != NULL)
625  I3STRING_FREE(title);
626  title = i3string_from_utf8(title_buf);
627  FREE(title_buf);
628 
629  draw_util_text(title, &(parent->frame_buffer),
630  p->color->text, p->color->background,
631  con->deco_rect.x + logical_px(2),
632  con->deco_rect.y + text_offset_y,
633  con->deco_rect.width - mark_width - 2 * logical_px(2));
634  I3STRING_FREE(title);
635 
636 after_title:
638 copy_pixmaps:
639  draw_util_copy_surface(&(con->frame_buffer), &(con->frame), 0, 0, 0, 0, con->rect.width, con->rect.height);
640 }
641 
642 /*
643  * Recursively calls x_draw_decoration. This cannot be done in x_push_node
644  * because x_push_node uses focus order to recurse (see the comment above)
645  * while drawing the decoration needs to happen in the actual order.
646  *
647  */
648 void x_deco_recurse(Con *con) {
649  Con *current;
650  bool leaf = TAILQ_EMPTY(&(con->nodes_head)) &&
651  TAILQ_EMPTY(&(con->floating_head));
653 
654  if (!leaf) {
655  TAILQ_FOREACH(current, &(con->nodes_head), nodes)
656  x_deco_recurse(current);
657 
658  TAILQ_FOREACH(current, &(con->floating_head), floating_windows)
659  x_deco_recurse(current);
660 
661  if (state->mapped) {
662  draw_util_copy_surface(&(con->frame_buffer), &(con->frame), 0, 0, 0, 0, con->rect.width, con->rect.height);
663  }
664  }
665 
666  if ((con->type != CT_ROOT && con->type != CT_OUTPUT) &&
667  (!leaf || con->mapped))
668  x_draw_decoration(con);
669 }
670 
671 /*
672  * Sets or removes the _NET_WM_STATE_HIDDEN property on con if necessary.
673  *
674  */
675 static void set_hidden_state(Con *con) {
676  if (con->window == NULL) {
677  return;
678  }
679 
681  bool should_be_hidden = con_is_hidden(con);
682  if (should_be_hidden == state->is_hidden)
683  return;
684 
685  if (should_be_hidden) {
686  DLOG("setting _NET_WM_STATE_HIDDEN for con = %p\n", con);
687  xcb_add_property_atom(conn, con->window->id, A__NET_WM_STATE, A__NET_WM_STATE_HIDDEN);
688  } else {
689  DLOG("removing _NET_WM_STATE_HIDDEN for con = %p\n", con);
690  xcb_remove_property_atom(conn, con->window->id, A__NET_WM_STATE, A__NET_WM_STATE_HIDDEN);
691  }
692 
693  state->is_hidden = should_be_hidden;
694 }
695 
696 /*
697  * This function pushes the properties of each node of the layout tree to
698  * X11 if they have changed (like the map state, position of the window, …).
699  * It recursively traverses all children of the given node.
700  *
701  */
702 void x_push_node(Con *con) {
703  Con *current;
704  con_state *state;
705  Rect rect = con->rect;
706 
707  //DLOG("Pushing changes for node %p / %s\n", con, con->name);
708  state = state_for_frame(con->frame.id);
709 
710  if (state->name != NULL) {
711  DLOG("pushing name %s for con %p\n", state->name, con);
712 
713  xcb_change_property(conn, XCB_PROP_MODE_REPLACE, con->frame.id,
714  XCB_ATOM_WM_NAME, XCB_ATOM_STRING, 8, strlen(state->name), state->name);
715  FREE(state->name);
716  }
717 
718  if (con->window == NULL) {
719  /* Calculate the height of all window decorations which will be drawn on to
720  * this frame. */
721  uint32_t max_y = 0, max_height = 0;
722  TAILQ_FOREACH(current, &(con->nodes_head), nodes) {
723  Rect *dr = &(current->deco_rect);
724  if (dr->y >= max_y && dr->height >= max_height) {
725  max_y = dr->y;
726  max_height = dr->height;
727  }
728  }
729  rect.height = max_y + max_height;
730  if (rect.height == 0)
731  con->mapped = false;
732  }
733 
734  /* reparent the child window (when the window was moved due to a sticky
735  * container) */
736  if (state->need_reparent && con->window != NULL) {
737  DLOG("Reparenting child window\n");
738 
739  /* Temporarily set the event masks to XCB_NONE so that we won’t get
740  * UnmapNotify events (otherwise the handler would close the container).
741  * These events are generated automatically when reparenting. */
742  uint32_t values[] = {XCB_NONE};
743  xcb_change_window_attributes(conn, state->old_frame, XCB_CW_EVENT_MASK, values);
744  xcb_change_window_attributes(conn, con->window->id, XCB_CW_EVENT_MASK, values);
745 
746  xcb_reparent_window(conn, con->window->id, con->frame.id, 0, 0);
747 
748  values[0] = FRAME_EVENT_MASK;
749  xcb_change_window_attributes(conn, state->old_frame, XCB_CW_EVENT_MASK, values);
750  values[0] = CHILD_EVENT_MASK;
751  xcb_change_window_attributes(conn, con->window->id, XCB_CW_EVENT_MASK, values);
752 
753  state->old_frame = XCB_NONE;
754  state->need_reparent = false;
755 
756  con->ignore_unmap++;
757  DLOG("ignore_unmap for reparenting of con %p (win 0x%08x) is now %d\n",
758  con, con->window->id, con->ignore_unmap);
759  }
760 
761  /* The pixmap of a borderless leaf container will not be used except
762  * for the titlebar in a stack or tabs (issue #1013). */
763  bool is_pixmap_needed = (con->border_style != BS_NONE ||
764  !con_is_leaf(con) ||
765  con->parent->layout == L_STACKED ||
766  con->parent->layout == L_TABBED);
767 
768  /* The root con and output cons will never require a pixmap. In particular for the
769  * __i3 output, this will likely not work anyway because it might be ridiculously
770  * large, causing an XCB_ALLOC error. */
771  if (con->type == CT_ROOT || con->type == CT_OUTPUT)
772  is_pixmap_needed = false;
773 
774  bool fake_notify = false;
775  /* Set new position if rect changed (and if height > 0) or if the pixmap
776  * needs to be recreated */
777  if ((is_pixmap_needed && con->frame_buffer.id == XCB_NONE) || (memcmp(&(state->rect), &rect, sizeof(Rect)) != 0 &&
778  rect.height > 0)) {
779  /* We first create the new pixmap, then render to it, set it as the
780  * background and only afterwards change the window size. This reduces
781  * flickering. */
782 
783  /* As the pixmap only depends on the size and not on the position, it
784  * is enough to check if width/height have changed. Also, we don’t
785  * create a pixmap at all when the window is actually not visible
786  * (height == 0) or when it is not needed. */
787  bool has_rect_changed = (state->rect.width != rect.width || state->rect.height != rect.height);
788 
789  /* Check if the container has an unneeded pixmap left over from
790  * previously having a border or titlebar. */
791  if (!is_pixmap_needed && con->frame_buffer.id != XCB_NONE) {
793  xcb_free_pixmap(conn, con->frame_buffer.id);
794  con->frame_buffer.id = XCB_NONE;
795  }
796 
797  if (is_pixmap_needed && (has_rect_changed || con->frame_buffer.id == XCB_NONE)) {
798  if (con->frame_buffer.id == XCB_NONE) {
799  con->frame_buffer.id = xcb_generate_id(conn);
800  } else {
802  xcb_free_pixmap(conn, con->frame_buffer.id);
803  }
804 
805  uint16_t win_depth = root_depth;
806  if (con->window)
807  win_depth = con->window->depth;
808 
809  /* Ensure we have valid dimensions for our surface. */
810  // TODO This is probably a bug in the condition above as we should never enter this path
811  // for height == 0. Also, we should probably handle width == 0 the same way.
812  int width = MAX((int32_t)rect.width, 1);
813  int height = MAX((int32_t)rect.height, 1);
814 
815  xcb_create_pixmap(conn, win_depth, con->frame_buffer.id, con->frame.id, width, height);
817  get_visualtype_by_id(get_visualid_by_depth(win_depth)), width, height);
818 
819  /* For the graphics context, we disable GraphicsExposure events.
820  * Those will be sent when a CopyArea request cannot be fulfilled
821  * properly due to parts of the source being unmapped or otherwise
822  * unavailable. Since we always copy from pixmaps to windows, this
823  * is not a concern for us. */
824  xcb_change_gc(conn, con->frame_buffer.gc, XCB_GC_GRAPHICS_EXPOSURES, (uint32_t[]){0});
825 
826  draw_util_surface_set_size(&(con->frame), width, height);
827  con->pixmap_recreated = true;
828 
829  /* Don’t render the decoration for windows inside a stack which are
830  * not visible right now */
831  // TODO Should this work the same way for L_TABBED?
832  if (!con->parent ||
833  con->parent->layout != L_STACKED ||
834  TAILQ_FIRST(&(con->parent->focus_head)) == con)
835  /* Render the decoration now to make the correct decoration visible
836  * from the very first moment. Later calls will be cached, so this
837  * doesn’t hurt performance. */
838  x_deco_recurse(con);
839  }
840 
841  DLOG("setting rect (%d, %d, %d, %d)\n", rect.x, rect.y, rect.width, rect.height);
842  /* flush to ensure that the following commands are sent in a single
843  * buffer and will be processed directly afterwards (the contents of a
844  * window get lost when resizing it, therefore we want to provide it as
845  * fast as possible) */
846  xcb_flush(conn);
847  xcb_set_window_rect(conn, con->frame.id, rect);
848  if (con->frame_buffer.id != XCB_NONE) {
849  draw_util_copy_surface(&(con->frame_buffer), &(con->frame), 0, 0, 0, 0, con->rect.width, con->rect.height);
850  }
851  xcb_flush(conn);
852 
853  memcpy(&(state->rect), &rect, sizeof(Rect));
854  fake_notify = true;
855  }
856 
857  /* dito, but for child windows */
858  if (con->window != NULL &&
859  memcmp(&(state->window_rect), &(con->window_rect), sizeof(Rect)) != 0) {
860  DLOG("setting window rect (%d, %d, %d, %d)\n",
861  con->window_rect.x, con->window_rect.y, con->window_rect.width, con->window_rect.height);
863  memcpy(&(state->window_rect), &(con->window_rect), sizeof(Rect));
864  fake_notify = true;
865  }
866 
867  /* Map if map state changed, also ensure that the child window
868  * is changed if we are mapped and there is a new, unmapped child window.
869  * Unmaps are handled in x_push_node_unmaps(). */
870  if ((state->mapped != con->mapped || (con->window != NULL && !state->child_mapped)) &&
871  con->mapped) {
872  xcb_void_cookie_t cookie;
873 
874  if (con->window != NULL) {
875  /* Set WM_STATE_NORMAL because GTK applications don’t want to
876  * drag & drop if we don’t. Also, xprop(1) needs it. */
877  long data[] = {XCB_ICCCM_WM_STATE_NORMAL, XCB_NONE};
878  xcb_change_property(conn, XCB_PROP_MODE_REPLACE, con->window->id,
879  A_WM_STATE, A_WM_STATE, 32, 2, data);
880  }
881 
882  uint32_t values[1];
883  if (!state->child_mapped && con->window != NULL) {
884  cookie = xcb_map_window(conn, con->window->id);
885 
886  /* We are interested in EnterNotifys as soon as the window is
887  * mapped */
888  values[0] = CHILD_EVENT_MASK;
889  xcb_change_window_attributes(conn, con->window->id, XCB_CW_EVENT_MASK, values);
890  DLOG("mapping child window (serial %d)\n", cookie.sequence);
891  state->child_mapped = true;
892  }
893 
894  cookie = xcb_map_window(conn, con->frame.id);
895 
896  values[0] = FRAME_EVENT_MASK;
897  xcb_change_window_attributes(conn, con->frame.id, XCB_CW_EVENT_MASK, values);
898 
899  /* copy the pixmap contents to the frame window immediately after mapping */
900  if (con->frame_buffer.id != XCB_NONE) {
901  draw_util_copy_surface(&(con->frame_buffer), &(con->frame), 0, 0, 0, 0, con->rect.width, con->rect.height);
902  }
903  xcb_flush(conn);
904 
905  DLOG("mapping container %08x (serial %d)\n", con->frame.id, cookie.sequence);
906  state->mapped = con->mapped;
907  }
908 
909  state->unmap_now = (state->mapped != con->mapped) && !con->mapped;
910 
911  if (fake_notify) {
912  DLOG("Sending fake configure notify\n");
914  }
915 
916  set_hidden_state(con);
917 
918  /* Handle all children and floating windows of this node. We recurse
919  * in focus order to display the focused client in a stack first when
920  * switching workspaces (reduces flickering). */
921  TAILQ_FOREACH(current, &(con->focus_head), focused) {
922  x_push_node(current);
923  }
924 }
925 
926 /*
927  * Same idea as in x_push_node(), but this function only unmaps windows. It is
928  * necessary to split this up to handle new fullscreen clients properly: The
929  * new window needs to be mapped and focus needs to be set *before* the
930  * underlying windows are unmapped. Otherwise, focus will revert to the
931  * PointerRoot and will then be set to the new window, generating unnecessary
932  * FocusIn/FocusOut events.
933  *
934  */
935 static void x_push_node_unmaps(Con *con) {
936  Con *current;
937  con_state *state;
938 
939  //DLOG("Pushing changes (with unmaps) for node %p / %s\n", con, con->name);
940  state = state_for_frame(con->frame.id);
941 
942  /* map/unmap if map state changed, also ensure that the child window
943  * is changed if we are mapped *and* in initial state (meaning the
944  * container was empty before, but now got a child) */
945  if (state->unmap_now) {
946  xcb_void_cookie_t cookie;
947  if (con->window != NULL) {
948  /* Set WM_STATE_WITHDRAWN, it seems like Java apps need it */
949  long data[] = {XCB_ICCCM_WM_STATE_WITHDRAWN, XCB_NONE};
950  xcb_change_property(conn, XCB_PROP_MODE_REPLACE, con->window->id,
951  A_WM_STATE, A_WM_STATE, 32, 2, data);
952  }
953 
954  cookie = xcb_unmap_window(conn, con->frame.id);
955  DLOG("unmapping container %p / %s (serial %d)\n", con, con->name, cookie.sequence);
956  /* we need to increase ignore_unmap for this container (if it
957  * contains a window) and for every window "under" this one which
958  * contains a window */
959  if (con->window != NULL) {
960  con->ignore_unmap++;
961  DLOG("ignore_unmap for con %p (frame 0x%08x) now %d\n", con, con->frame.id, con->ignore_unmap);
962  }
963  state->mapped = con->mapped;
964  }
965 
966  /* handle all children and floating windows of this node */
967  TAILQ_FOREACH(current, &(con->nodes_head), nodes)
968  x_push_node_unmaps(current);
969 
970  TAILQ_FOREACH(current, &(con->floating_head), floating_windows)
971  x_push_node_unmaps(current);
972 }
973 
974 /*
975  * Returns true if the given container is currently attached to its parent.
976  *
977  * TODO: Remove once #1185 has been fixed
978  */
979 static bool is_con_attached(Con *con) {
980  if (con->parent == NULL)
981  return false;
982 
983  Con *current;
984  TAILQ_FOREACH(current, &(con->parent->nodes_head), nodes) {
985  if (current == con)
986  return true;
987  }
988 
989  return false;
990 }
991 
992 /*
993  * Pushes all changes (state of each node, see x_push_node() and the window
994  * stack) to X11.
995  *
996  * NOTE: We need to push the stack first so that the windows have the correct
997  * stacking order. This is relevant for workspace switching where we map the
998  * windows because mapping may generate EnterNotify events. When they are
999  * generated in the wrong order, this will cause focus problems when switching
1000  * workspaces.
1001  *
1002  */
1003 void x_push_changes(Con *con) {
1004  con_state *state;
1005  xcb_query_pointer_cookie_t pointercookie;
1006 
1007  /* If we need to warp later, we request the pointer position as soon as possible */
1008  if (warp_to) {
1009  pointercookie = xcb_query_pointer(conn, root);
1010  }
1011 
1012  DLOG("-- PUSHING WINDOW STACK --\n");
1013  //DLOG("Disabling EnterNotify\n");
1014  /* We need to keep SubstructureRedirect around, otherwise clients can send
1015  * ConfigureWindow requests and get them applied directly instead of having
1016  * them become ConfigureRequests that i3 handles. */
1017  uint32_t values[1] = {XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT};
1018  CIRCLEQ_FOREACH_REVERSE(state, &state_head, state) {
1019  if (state->mapped)
1020  xcb_change_window_attributes(conn, state->id, XCB_CW_EVENT_MASK, values);
1021  }
1022  //DLOG("Done, EnterNotify disabled\n");
1023  bool order_changed = false;
1024  bool stacking_changed = false;
1025 
1026  /* count first, necessary to (re)allocate memory for the bottom-to-top
1027  * stack afterwards */
1028  int cnt = 0;
1029  CIRCLEQ_FOREACH_REVERSE(state, &state_head, state)
1030  if (con_has_managed_window(state->con))
1031  cnt++;
1032 
1033  /* The bottom-to-top window stack of all windows which are managed by i3.
1034  * Used for x_get_window_stack(). */
1035  static xcb_window_t *client_list_windows = NULL;
1036  static int client_list_count = 0;
1037 
1038  if (cnt != client_list_count) {
1039  client_list_windows = srealloc(client_list_windows, sizeof(xcb_window_t) * cnt);
1040  client_list_count = cnt;
1041  }
1042 
1043  xcb_window_t *walk = client_list_windows;
1044 
1045  /* X11 correctly represents the stack if we push it from bottom to top */
1046  CIRCLEQ_FOREACH_REVERSE(state, &state_head, state) {
1047  if (con_has_managed_window(state->con))
1048  memcpy(walk++, &(state->con->window->id), sizeof(xcb_window_t));
1049 
1050  //DLOG("stack: 0x%08x\n", state->id);
1051  con_state *prev = CIRCLEQ_PREV(state, state);
1052  con_state *old_prev = CIRCLEQ_PREV(state, old_state);
1053  if (prev != old_prev)
1054  order_changed = true;
1055  if ((state->initial || order_changed) && prev != CIRCLEQ_END(&state_head)) {
1056  stacking_changed = true;
1057  //DLOG("Stacking 0x%08x above 0x%08x\n", prev->id, state->id);
1058  uint32_t mask = 0;
1059  mask |= XCB_CONFIG_WINDOW_SIBLING;
1060  mask |= XCB_CONFIG_WINDOW_STACK_MODE;
1061  uint32_t values[] = {state->id, XCB_STACK_MODE_ABOVE};
1062 
1063  xcb_configure_window(conn, prev->id, mask, values);
1064  }
1065  state->initial = false;
1066  }
1067 
1068  /* If we re-stacked something (or a new window appeared), we need to update
1069  * the _NET_CLIENT_LIST and _NET_CLIENT_LIST_STACKING hints */
1070  if (stacking_changed) {
1071  DLOG("Client list changed (%i clients)\n", cnt);
1072  ewmh_update_client_list_stacking(client_list_windows, client_list_count);
1073 
1074  walk = client_list_windows;
1075 
1076  /* reorder by initial mapping */
1078  if (con_has_managed_window(state->con))
1079  *walk++ = state->con->window->id;
1080  }
1081 
1082  ewmh_update_client_list(client_list_windows, client_list_count);
1083  }
1084 
1085  DLOG("PUSHING CHANGES\n");
1086  x_push_node(con);
1087 
1088  if (warp_to) {
1089  xcb_query_pointer_reply_t *pointerreply = xcb_query_pointer_reply(conn, pointercookie, NULL);
1090  if (!pointerreply) {
1091  ELOG("Could not query pointer position, not warping pointer\n");
1092  } else {
1093  int mid_x = warp_to->x + (warp_to->width / 2);
1094  int mid_y = warp_to->y + (warp_to->height / 2);
1095 
1096  Output *current = get_output_containing(pointerreply->root_x, pointerreply->root_y);
1097  Output *target = get_output_containing(mid_x, mid_y);
1098  if (current != target) {
1099  /* Ignore MotionNotify events generated by warping */
1100  xcb_change_window_attributes(conn, root, XCB_CW_EVENT_MASK, (uint32_t[]){XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT});
1101  xcb_warp_pointer(conn, XCB_NONE, root, 0, 0, 0, 0, mid_x, mid_y);
1102  xcb_change_window_attributes(conn, root, XCB_CW_EVENT_MASK, (uint32_t[]){ROOT_EVENT_MASK});
1103  }
1104 
1105  free(pointerreply);
1106  }
1107  warp_to = NULL;
1108  }
1109 
1110  //DLOG("Re-enabling EnterNotify\n");
1111  values[0] = FRAME_EVENT_MASK;
1112  CIRCLEQ_FOREACH_REVERSE(state, &state_head, state) {
1113  if (state->mapped)
1114  xcb_change_window_attributes(conn, state->id, XCB_CW_EVENT_MASK, values);
1115  }
1116  //DLOG("Done, EnterNotify re-enabled\n");
1117 
1118  x_deco_recurse(con);
1119 
1120  xcb_window_t to_focus = focused->frame.id;
1121  if (focused->window != NULL)
1122  to_focus = focused->window->id;
1123 
1124  if (focused_id != to_focus) {
1125  if (!focused->mapped) {
1126  DLOG("Not updating focus (to %p / %s), focused window is not mapped.\n", focused, focused->name);
1127  /* Invalidate focused_id to correctly focus new windows with the same ID */
1128  focused_id = XCB_NONE;
1129  } else {
1130  if (focused->window != NULL &&
1133  DLOG("Updating focus by sending WM_TAKE_FOCUS to window 0x%08x (focused: %p / %s)\n",
1134  to_focus, focused, focused->name);
1135  send_take_focus(to_focus, last_timestamp);
1136 
1138 
1139  if (to_focus != last_focused && is_con_attached(focused))
1140  ipc_send_window_event("focus", focused);
1141  } else {
1142  DLOG("Updating focus (focused: %p / %s) to X11 window 0x%08x\n", focused, focused->name, to_focus);
1143  /* We remove XCB_EVENT_MASK_FOCUS_CHANGE from the event mask to get
1144  * no focus change events for our own focus changes. We only want
1145  * these generated by the clients. */
1146  if (focused->window != NULL) {
1147  values[0] = CHILD_EVENT_MASK & ~(XCB_EVENT_MASK_FOCUS_CHANGE);
1148  xcb_change_window_attributes(conn, focused->window->id, XCB_CW_EVENT_MASK, values);
1149  }
1150  xcb_set_input_focus(conn, XCB_INPUT_FOCUS_POINTER_ROOT, to_focus, last_timestamp);
1151  if (focused->window != NULL) {
1152  values[0] = CHILD_EVENT_MASK;
1153  xcb_change_window_attributes(conn, focused->window->id, XCB_CW_EVENT_MASK, values);
1154  }
1155 
1157 
1158  if (to_focus != XCB_NONE && to_focus != last_focused && focused->window != NULL && is_con_attached(focused))
1159  ipc_send_window_event("focus", focused);
1160  }
1161 
1163  }
1164  }
1165 
1166  if (focused_id == XCB_NONE) {
1167  /* If we still have no window to focus, we focus the EWMH window instead. We use this rather than the
1168  * root window in order to avoid an X11 fallback mechanism causing a ghosting effect (see #1378). */
1169  DLOG("Still no window focused, better set focus to the EWMH support window (%d)\n", ewmh_window);
1170  xcb_set_input_focus(conn, XCB_INPUT_FOCUS_POINTER_ROOT, ewmh_window, last_timestamp);
1171  ewmh_update_active_window(XCB_WINDOW_NONE);
1173  }
1174 
1175  xcb_flush(conn);
1176  DLOG("ENDING CHANGES\n");
1177 
1178  /* Disable EnterWindow events for windows which will be unmapped in
1179  * x_push_node_unmaps() now. Unmapping windows happens when switching
1180  * workspaces. We want to avoid getting EnterNotifies during that phase
1181  * because they would screw up our focus. One of these cases is having a
1182  * stack with two windows. If the first window is focused and gets
1183  * unmapped, the second one appears under the cursor and therefore gets an
1184  * EnterNotify event. */
1185  values[0] = FRAME_EVENT_MASK & ~XCB_EVENT_MASK_ENTER_WINDOW;
1186  CIRCLEQ_FOREACH_REVERSE(state, &state_head, state) {
1187  if (!state->unmap_now)
1188  continue;
1189  xcb_change_window_attributes(conn, state->id, XCB_CW_EVENT_MASK, values);
1190  }
1191 
1192  /* Push all pending unmaps */
1193  x_push_node_unmaps(con);
1194 
1195  /* save the current stack as old stack */
1196  CIRCLEQ_FOREACH(state, &state_head, state) {
1199  }
1200  //CIRCLEQ_FOREACH(state, &old_state_head, old_state) {
1201  // DLOG("old stack: 0x%08x\n", state->id);
1202  //}
1203 
1204  xcb_flush(conn);
1205 }
1206 
1207 /*
1208  * Raises the specified container in the internal stack of X windows. The
1209  * next call to x_push_changes() will make the change visible in X11.
1210  *
1211  */
1212 void x_raise_con(Con *con) {
1213  con_state *state;
1214  state = state_for_frame(con->frame.id);
1215  //DLOG("raising in new stack: %p / %s / %s / xid %08x\n", con, con->name, con->window ? con->window->name_json : "", state->id);
1216 
1217  CIRCLEQ_REMOVE(&state_head, state, state);
1218  CIRCLEQ_INSERT_HEAD(&state_head, state, state);
1219 }
1220 
1221 /*
1222  * Sets the WM_NAME property (so, no UTF8, but used only for debugging anyways)
1223  * of the given name. Used for properly tagging the windows for easily spotting
1224  * i3 windows in xwininfo -root -all.
1225  *
1226  */
1227 void x_set_name(Con *con, const char *name) {
1228  struct con_state *state;
1229 
1230  if ((state = state_for_frame(con->frame.id)) == NULL) {
1231  ELOG("window state not found\n");
1232  return;
1233  }
1234 
1235  FREE(state->name);
1236  state->name = sstrdup(name);
1237 }
1238 
1239 /*
1240  * Set up the I3_SHMLOG_PATH atom.
1241  *
1242  */
1244  if (*shmlogname == '\0') {
1245  xcb_delete_property(conn, root, A_I3_SHMLOG_PATH);
1246  } else {
1247  xcb_change_property(conn, XCB_PROP_MODE_REPLACE, root,
1248  A_I3_SHMLOG_PATH, A_UTF8_STRING, 8,
1249  strlen(shmlogname), shmlogname);
1250  }
1251 }
1252 
1253 /*
1254  * Sets up i3 specific atoms (I3_SOCKET_PATH and I3_CONFIG_PATH)
1255  *
1256  */
1257 void x_set_i3_atoms(void) {
1258  pid_t pid = getpid();
1259  xcb_change_property(conn, XCB_PROP_MODE_REPLACE, root, A_I3_SOCKET_PATH, A_UTF8_STRING, 8,
1260  (current_socketpath == NULL ? 0 : strlen(current_socketpath)),
1262  xcb_change_property(conn, XCB_PROP_MODE_REPLACE, root, A_I3_PID, XCB_ATOM_CARDINAL, 32, 1, &pid);
1263  xcb_change_property(conn, XCB_PROP_MODE_REPLACE, root, A_I3_CONFIG_PATH, A_UTF8_STRING, 8,
1266 }
1267 
1268 /*
1269  * Set warp_to coordinates. This will trigger on the next call to
1270  * x_push_changes().
1271  *
1272  */
1273 void x_set_warp_to(Rect *rect) {
1275  warp_to = rect;
1276 }
1277 
1278 /*
1279  * Applies the given mask to the event mask of every i3 window decoration X11
1280  * window. This is useful to disable EnterNotify while resizing so that focus
1281  * is untouched.
1282  *
1283  */
1284 void x_mask_event_mask(uint32_t mask) {
1285  uint32_t values[] = {FRAME_EVENT_MASK & mask};
1286 
1287  con_state *state;
1288  CIRCLEQ_FOREACH_REVERSE(state, &state_head, state) {
1289  if (state->mapped)
1290  xcb_change_window_attributes(conn, state->id, XCB_CW_EVENT_MASK, values);
1291  }
1292 }
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:1656
xcb_window_t focused_id
Stores the X11 window ID of the currently focused window.
Definition: x.c:20
static char ** marks
Definition: load_layout.c:34
static xcb_window_t last_focused
Definition: x.c:25
initial_mapping_order
Definition: x.c:68
struct _i3String i3String
Opaque data structure for storing strings.
Definition: libi3.h:48
xcb_window_t root
Definition: main.c:59
int sasprintf(char **strp, const char *fmt,...)
Safe-wrapper around asprintf which exits if it returns -1 (meaning that there is no more memory avail...
bool unmap_now
Definition: x.c:41
#define CHILD_EVENT_MASK
The XCB_CW_EVENT_MASK for the child (= real window)
Definition: xcb.h:35
xcb_window_t old_frame
Definition: x.c:52
Con * focused
Definition: tree.c:13
void xcb_add_property_atom(xcb_connection_t *conn, xcb_window_t window, xcb_atom_t property, xcb_atom_t atom)
Add an atom to a list of atoms the given property defines.
Definition: xcb.c:265
void fake_absolute_configure_notify(Con *con)
Generates a configure_notify_event with absolute coordinates (relative to the X root window...
Definition: xcb.c:75
initial_mapping_head
Definition: x.c:80
struct Colortriple urgent
#define TAILQ_HEAD_INITIALIZER(head)
Definition: queue.h:324
#define CIRCLEQ_REMOVE(head, elm, field)
Definition: queue.h:534
#define CIRCLEQ_INSERT_HEAD(head, elm, field)
Definition: queue.h:512
char * title_format
The format with which the window&#39;s name should be displayed.
Definition: data.h:675
old_state
Definition: x.c:65
A &#39;Window&#39; is a type which contains an xcb_window_t and all the related information (hints like _NET_...
Definition: data.h:427
void x_mask_event_mask(uint32_t mask)
Applies the given mask to the event mask of every i3 window decoration X11 window.
Definition: x.c:1284
bool name_x_changed
Flag to force re-rendering the decoration upon changes.
Definition: data.h:458
Definition: x.c:38
char * current_socketpath
Definition: ipc.c:23
#define FRAME_EVENT_MASK
The XCB_CW_EVENT_MASK for its frame.
Definition: xcb.h:40
#define TAILQ_HEAD(name, type)
Definition: queue.h:318
Definition: data.h:73
i3String * qubes_vmname
The name of the qubes vm.
Definition: data.h:447
const char * i3string_as_utf8(i3String *str)
Returns the UTF-8 encoded version of the i3String.
uint8_t ignore_unmap
This counter contains the number of UnmapNotify events for this container (or, more precisely...
Definition: data.h:638
char * sstrdup(const char *str)
Safe-wrapper around strdup which exits if malloc returns NULL (meaning that there is no more memory a...
#define CIRCLEQ_FOREACH_REVERSE(var, head, field)
Definition: queue.h:476
void x_window_kill(xcb_window_t window, kill_window_t kill_window)
Kills the given X11 window using WM_DELETE_WINDOW (if supported).
Definition: x.c:288
#define TAILQ_EMPTY(head)
Definition: queue.h:344
int border_style
Definition: data.h:211
static bool is_con_attached(Con *con)
Definition: x.c:979
#define ELOG(fmt,...)
Definition: libi3.h:99
A &#39;Con&#39; represents everything from the X11 root window down to a single X11 window.
Definition: data.h:626
#define TAILQ_PREV(elm, headname, field)
Definition: queue.h:342
#define LOG(fmt,...)
Definition: libi3.h:94
uint32_t width
Definition: data.h:129
i3String * i3string_from_utf8(const char *from_utf8)
Build an i3String from an UTF-8 encoded string.
Definition: data.h:93
struct Rect rect
Definition: data.h:662
xcb_connection_t * conn
XCB connection and root screen.
Definition: main.c:46
void draw_util_surface_set_size(surface_t *surface, int width, int height)
Resize the surface to the given size.
bool initial
Definition: x.c:57
bool font_is_pango(void)
Returns true if and only if the current font is a pango font.
int qubes_label
The qubes label.
Definition: data.h:450
struct Window * window
Definition: data.h:694
#define TAILQ_INSERT_TAIL(head, elm, field)
Definition: queue.h:376
bool con_is_leaf(Con *con)
Returns true when this node is a leaf node (has no children)
Definition: con.c:303
#define CIRCLEQ_END(head)
Definition: queue.h:465
bool urgent
Definition: data.h:631
struct width_height con_rect
Definition: data.h:212
color_t indicator
Definition: configuration.h:58
uint16_t depth
Definition: data.h:783
bool mark_changed
Definition: data.h:686
#define MAX(x, y)
Definition: x.c:14
void draw_util_clear_surface(surface_t *surface, color_t color)
Clears a surface with the given color.
void x_push_node(Con *con)
This function pushes the properties of each node of the layout tree to X11 if they have changed (like...
Definition: x.c:702
color_t background
Definition: data.h:215
state_head
Definition: x.c:72
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:1391
state
Definition: x.c:62
enum Con::@20 type
void xcb_remove_property_atom(xcb_connection_t *conn, xcb_window_t window, xcb_atom_t property, xcb_atom_t atom)
Remove an atom from a list of atoms the given property defines without removing any other potentially...
Definition: xcb.c:275
Rect window_rect
Definition: x.c:55
xcb_screen_t * root_screen
Definition: main.c:58
Definition: data.h:62
void x_deco_recurse(Con *con)
Recursively calls x_draw_decoration.
Definition: x.c:648
void x_set_i3_atoms(void)
Sets up i3 specific atoms (I3_SOCKET_PATH and I3_CONFIG_PATH)
Definition: x.c:1257
struct Config::config_client client[QUBE_NUM_LABELS]
void x_draw_decoration(Con *con)
Draws the decoration of the given container onto its parent.
Definition: x.c:379
xcb_window_t create_window(xcb_connection_t *conn, Rect dims, uint16_t depth, xcb_visualid_t visual, uint16_t window_class, enum xcursor_cursor_t cursor, bool map, uint32_t mask, uint32_t *values)
Convenience wrapper around xcb_create_window which takes care of depth, generating an ID and checking...
Definition: xcb.c:19
bool child_mapped
Definition: x.c:42
surface_t frame
Definition: data.h:641
int predict_text_width(i3String *text)
Predict the text width in pixels for the given text.
#define FREE(pointer)
Definition: util.h:50
int height
The height of the font, built from font_ascent + font_descent.
Definition: libi3.h:67
color_t background
Definition: configuration.h:56
Definition: data.h:63
xcb_visualid_t get_visualid_by_depth(uint16_t depth)
Get visualid with specified depth.
Definition: xcb.c:242
void ewmh_update_client_list(xcb_window_t *list, int num_windows)
Updates the _NET_CLIENT_LIST hint.
Definition: ewmh.c:245
bool needs_take_focus
Whether the application needs to receive WM_TAKE_FOCUS.
Definition: data.h:464
struct Colortriple focused_inactive
#define CIRCLEQ_ENTRY(type)
Definition: queue.h:454
xcb_visualtype_t * get_visualtype_by_id(xcb_visualid_t visual_id)
Get visual type specified by visualid.
Definition: xcb.c:221
#define I3STRING_FREE(str)
Securely i3string_free by setting the pointer to NULL to prevent accidentally using freed memory...
Definition: libi3.h:228
old_state_head
Definition: x.c:76
nodes_head
Definition: data.h:707
#define CIRCLEQ_HEAD(name, type)
Definition: queue.h:442
#define CIRCLEQ_HEAD_INITIALIZER(head)
Definition: queue.h:448
xcb_window_t ewmh_window
The EWMH support window that is used to indicate that an EWMH-compliant window manager is present...
Definition: x.c:17
uint32_t x
Definition: data.h:175
struct Colortriple unfocused
void x_set_name(Con *con, const char *name)
Sets the WM_NAME property (so, no UTF8, but used only for debugging anyways) of the given name...
Definition: x.c:1227
static con_state * state_for_frame(xcb_window_t window)
Definition: x.c:90
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:347
#define TAILQ_FIRST(head)
Definition: queue.h:336
adjacent_t con_adjacent_borders(Con *con)
Returns adjacent borders of the window.
Definition: con.c:1707
bool pixmap_recreated
Definition: data.h:643
Stores a width/height pair, used as part of deco_render_params to check whether the rects width/heigh...
Definition: data.h:198
static Con * to_focus
Definition: load_layout.c:23
static void x_draw_title_border(Con *con, struct deco_render_params *p)
Definition: x.c:320
void x_con_kill(Con *con)
Kills the window decoration associated with the given container.
Definition: x.c:239
floating_head
Definition: data.h:704
static void x_draw_decoration_after_title(Con *con, struct deco_render_params *p)
Definition: x.c:340
void ewmh_update_active_window(xcb_window_t window)
Updates _NET_ACTIVE_WINDOW with the currently focused window.
Definition: ewmh.c:205
char * name
Definition: data.h:672
xcb_window_t id
Definition: data.h:428
void x_move_win(Con *src, Con *dest)
Moves a child window from Container src to Container dest.
Definition: x.c:212
bool con_has_managed_window(Con *con)
Returns true when this con is a leaf node with a managed X11 window (e.g., excluding dock containers)...
Definition: con.c:311
layout_t layout
Definition: data.h:736
#define TAILQ_REMOVE(head, elm, field)
Definition: queue.h:402
bool mapped
Definition: data.h:627
char * current_configpath
Definition: config.c:15
bool is_hidden
Definition: x.c:43
xcb_colormap_t colormap
Definition: main.c:66
struct width_height con_window_rect
Definition: data.h:213
Rect con_deco_rect
Definition: data.h:214
static void x_push_node_unmaps(Con *con)
Definition: x.c:935
struct Rect window_rect
Definition: data.h:665
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...
struct Colortriple focused
void x_set_warp_to(Rect *rect)
Set warp_to coordinates.
Definition: x.c:1273
i3String * name
The name of the window.
Definition: data.h:444
qube_label_t
Qubes colors.
Definition: data.h:148
kill_window_t
parameter to specify whether tree_close_internal() and x_window_kill() should kill only this specific...
Definition: data.h:68
uint32_t y
Definition: data.h:176
hide_edge_borders_mode_t hide_edge_borders
Remove borders if they are adjacent to the screen edge.
#define COLOR_TRANSPARENT
Definition: libi3.h:412
uint16_t depth
Depth of the window.
Definition: data.h:488
void send_take_focus(xcb_window_t window, xcb_timestamp_t timestamp)
Sends the WM_TAKE_FOCUS ClientMessage to the given window.
Definition: xcb.c:94
char * name
Definition: data.h:616
void draw_util_surface_free(xcb_connection_t *conn, surface_t *surface)
Destroys the surface.
Definition: data.h:97
An Output is a physical output on your graphics driver.
Definition: data.h:392
void * srealloc(void *ptr, size_t size)
Safe-wrapper around realloc which exits if realloc returns NULL (meaning that there is no more memory...
color_t child_border
Definition: configuration.h:59
char * con_get_tree_representation(Con *con)
Create a string representing the subtree under con.
Definition: con.c:2233
void xcb_set_window_rect(xcb_connection_t *conn, xcb_window_t window, Rect r)
Configures the given window to have the size/position specified by given rect.
Definition: xcb.c:117
uint32_t height
Definition: data.h:178
adjacent_t
describes if the window is adjacent to the output (physical screen) edges.
Definition: data.h:73
int logical_px(const int logical)
Convert a logical amount of pixels (e.g.
uint32_t width
Definition: data.h:177
char * name
Definition: x.c:59
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.
void x_con_init(Con *con)
Initializes the X11 part for the given container.
Definition: x.c:107
int con_border_style(Con *con)
Use this function to get a container’s border style.
Definition: con.c:1736
#define QUBE_NUM_LABELS
Definition: data.h:160
uint32_t height
Definition: data.h:130
bool mapped
Definition: x.c:40
bool show_marks
Specifies whether or not marks should be displayed in the window decoration.
bool need_reparent
Definition: x.c:51
xcb_drawable_t id
Definition: libi3.h:552
struct Rect deco_rect
Definition: data.h:668
#define DLOG(fmt,...)
Definition: libi3.h:104
static void set_hidden_state(Con *con)
Definition: x.c:675
Definition: data.h:615
#define CIRCLEQ_INSERT_TAIL(head, elm, field)
Definition: queue.h:523
Definition: data.h:94
#define TAILQ_NEXT(elm, field)
Definition: queue.h:338
char * shmlogname
Definition: log.c:46
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:1003
void update_shmlog_atom()
Set up the SHMLOG_PATH atom.
Definition: x.c:1243
#define ROOT_EVENT_MASK
Definition: xcb.h:49
void ewmh_update_client_list_stacking(xcb_window_t *stack, int num_windows)
Updates the _NET_CLIENT_LIST_STACKING hint.
Definition: ewmh.c:261
border_style_t border_style
Definition: data.h:737
Definition: data.h:98
bool window_supports_protocol(xcb_window_t window, xcb_atom_t atom)
Returns true if the client supports the given protocol atom (like WM_DELETE_WINDOW) ...
Definition: x.c:265
void draw_util_text(i3String *text, surface_t *surface, color_t fg_color, color_t bg_color, int x, int y, int max_width)
Draw the given text using libi3.
void x_raise_con(Con *con)
Raises the specified container in the internal stack of X windows.
Definition: x.c:1212
xcb_window_t id
Definition: x.c:39
static Rect * warp_to
Definition: x.c:28
#define TAILQ_ENTRY(type)
Definition: queue.h:327
#define CIRCLEQ_PREV(elm, field)
Definition: queue.h:467
bool con_is_leaf
Definition: data.h:217
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:56
Con * con
The con for which this state is.
Definition: x.c:46
#define CIRCLEQ_FOREACH(var, head, field)
Definition: queue.h:471
int current_border_width
Definition: data.h:692
Config config
Definition: config.c:17
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:102
color_t border
Definition: configuration.h:55
xcb_colormap_t colormap
Definition: data.h:786
Definition: data.h:64
Stores the parameters for rendering a window decoration.
Definition: data.h:209
layout_t parent_layout
Definition: data.h:216
i3Font font
Definition: configuration.h:98
struct deco_render_params * deco_render_params
Cache for the decoration rendering.
Definition: data.h:700
color_t text
Definition: configuration.h:57
Stores a rectangle, for example the size of a window, the child window etc.
Definition: data.h:174
marks_head
Definition: data.h:684
Rect rect
Definition: x.c:54
bool doesnt_accept_focus
Whether this window accepts focus.
Definition: data.h:468
xcb_gcontext_t gc
Definition: libi3.h:555
uint8_t root_depth
Definition: main.c:64
surface_t frame_buffer
Definition: data.h:642
void draw_util_surface_init(xcb_connection_t *conn, surface_t *surface, xcb_drawable_t drawable, xcb_visualtype_t *visual, int width, int height)
Initialize the surface to represent the given drawable.
void x_reparent_child(Con *con, Con *old)
Reparents the child window of the given container (necessary for sticky containers).
Definition: x.c:197
void draw_util_rectangle(surface_t *surface, color_t color, double x, double y, double w, double h)
Draws a filled rectangle.
i3String * con_parse_title_format(Con *con)
Returns the window title considering the current title format.
Definition: con.c:2296
struct Con * parent
Definition: data.h:658
struct Colortriple * color
Definition: data.h:210
warping_t mouse_warping
By default, when switching focus to a window on a different output (e.g.
focus_head
Definition: data.h:710
bool con_inside_focused(Con *con)
Checks if the given container is inside a focused container.
Definition: con.c:567
void x_reinit(Con *con)
Re-initializes the associated X window state for this container.
Definition: x.c:177
bool con_is_hidden(Con *con)
This will only return true for containers which have some parent with a tabbed / stacked parent of wh...
Definition: con.c:346