i3
bindings.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  * bindings.c: Functions for configuring, finding and, running bindings.
8  */
9 #include "all.h"
10 
11 #include <math.h>
12 
13 #include <xkbcommon/xkbcommon-x11.h>
14 #include <xkbcommon/xkbcommon.h>
15 
16 static struct xkb_context *xkb_context;
17 static struct xkb_keymap *xkb_keymap;
18 
20 
21 /*
22  * The name of the default mode.
23  *
24  */
25 const char *DEFAULT_BINDING_MODE = "default";
26 
27 /*
28  * Returns the mode specified by `name` or creates a new mode and adds it to
29  * the list of modes.
30  *
31  */
32 static struct Mode *mode_from_name(const char *name, bool pango_markup) {
33  struct Mode *mode;
34 
35  /* Try to find the mode in the list of modes and return it */
36  SLIST_FOREACH (mode, &modes, modes) {
37  if (strcmp(mode->name, name) == 0) {
38  return mode;
39  }
40  }
41 
42  /* If the mode was not found, create a new one */
43  mode = scalloc(1, sizeof(struct Mode));
44  mode->name = sstrdup(name);
45  mode->pango_markup = pango_markup;
46  mode->bindings = scalloc(1, sizeof(struct bindings_head));
47  TAILQ_INIT(mode->bindings);
48  SLIST_INSERT_HEAD(&modes, mode, modes);
49 
50  return mode;
51 }
52 
53 /*
54  * Adds a binding from config parameters given as strings and returns a
55  * pointer to the binding structure. Returns NULL if the input code could not
56  * be parsed.
57  *
58  */
59 Binding *configure_binding(const char *bindtype, const char *modifiers, const char *input_code,
60  const char *release, const char *border, const char *whole_window,
61  const char *exclude_titlebar, const char *command, const char *modename,
62  bool pango_markup) {
63  Binding *new_binding = scalloc(1, sizeof(Binding));
64  DLOG("Binding %p bindtype %s, modifiers %s, input code %s, release %s\n", new_binding, bindtype, modifiers, input_code, release);
65  new_binding->release = (release != NULL ? B_UPON_KEYRELEASE : B_UPON_KEYPRESS);
66  new_binding->border = (border != NULL);
67  new_binding->whole_window = (whole_window != NULL);
68  new_binding->exclude_titlebar = (exclude_titlebar != NULL);
69  if (strcmp(bindtype, "bindsym") == 0) {
70  new_binding->input_type = (strncasecmp(input_code, "button", (sizeof("button") - 1)) == 0
71  ? B_MOUSE
72  : B_KEYBOARD);
73 
74  new_binding->symbol = sstrdup(input_code);
75  } else {
76  long keycode;
77  if (!parse_long(input_code, &keycode, 10)) {
78  ELOG("Could not parse \"%s\" as an input code, ignoring this binding.\n", input_code);
79  FREE(new_binding);
80  return NULL;
81  }
82 
83  new_binding->keycode = keycode;
84  new_binding->input_type = B_KEYBOARD;
85  }
86  new_binding->command = sstrdup(command);
87  new_binding->event_state_mask = event_state_from_str(modifiers);
88  int group_bits_set = 0;
89  if ((new_binding->event_state_mask >> 16) & I3_XKB_GROUP_MASK_1)
90  group_bits_set++;
91  if ((new_binding->event_state_mask >> 16) & I3_XKB_GROUP_MASK_2)
92  group_bits_set++;
93  if ((new_binding->event_state_mask >> 16) & I3_XKB_GROUP_MASK_3)
94  group_bits_set++;
95  if ((new_binding->event_state_mask >> 16) & I3_XKB_GROUP_MASK_4)
96  group_bits_set++;
97  if (group_bits_set > 1)
98  ELOG("Keybinding has more than one Group specified, but your X server is always in precisely one group. The keybinding can never trigger.\n");
99 
100  struct Mode *mode = mode_from_name(modename, pango_markup);
101  TAILQ_INSERT_TAIL(mode->bindings, new_binding, bindings);
102 
103  TAILQ_INIT(&(new_binding->keycodes_head));
104 
105  return new_binding;
106 }
107 
108 static bool binding_in_current_group(const Binding *bind) {
109  /* If no bits are set, the binding should be installed in every group. */
110  if ((bind->event_state_mask >> 16) == I3_XKB_GROUP_MASK_ANY)
111  return true;
112  switch (xkb_current_group) {
113  case XCB_XKB_GROUP_1:
114  return ((bind->event_state_mask >> 16) & I3_XKB_GROUP_MASK_1);
115  case XCB_XKB_GROUP_2:
116  return ((bind->event_state_mask >> 16) & I3_XKB_GROUP_MASK_2);
117  case XCB_XKB_GROUP_3:
118  return ((bind->event_state_mask >> 16) & I3_XKB_GROUP_MASK_3);
119  case XCB_XKB_GROUP_4:
120  return ((bind->event_state_mask >> 16) & I3_XKB_GROUP_MASK_4);
121  default:
122  ELOG("BUG: xkb_current_group (= %d) outside of [XCB_XKB_GROUP_1..XCB_XKB_GROUP_4]\n", xkb_current_group);
123  return false;
124  }
125 }
126 
127 static void grab_keycode_for_binding(xcb_connection_t *conn, Binding *bind, uint32_t keycode) {
128  /* Grab the key in all combinations */
129 #define GRAB_KEY(modifier) \
130  do { \
131  xcb_grab_key(conn, 0, root, modifier, keycode, XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC); \
132  } while (0)
133  const int mods = (bind->event_state_mask & 0xFFFF);
134  DLOG("Binding %p Grabbing keycode %d with event state mask 0x%x (mods 0x%x)\n",
135  bind, keycode, bind->event_state_mask, mods);
136  GRAB_KEY(mods);
137  /* Also bind the key with active NumLock */
138  GRAB_KEY(mods | xcb_numlock_mask);
139  /* Also bind the key with active CapsLock */
140  GRAB_KEY(mods | XCB_MOD_MASK_LOCK);
141  /* Also bind the key with active NumLock+CapsLock */
142  GRAB_KEY(mods | xcb_numlock_mask | XCB_MOD_MASK_LOCK);
143 }
144 
145 /*
146  * Grab the bound keys (tell X to send us keypress events for those keycodes)
147  *
148  */
149 void grab_all_keys(xcb_connection_t *conn) {
150  Binding *bind;
151  TAILQ_FOREACH (bind, bindings, bindings) {
152  if (bind->input_type != B_KEYBOARD)
153  continue;
154 
155  if (!binding_in_current_group(bind))
156  continue;
157 
158  /* The easy case: the user specified a keycode directly. */
159  if (bind->keycode > 0) {
160  grab_keycode_for_binding(conn, bind, bind->keycode);
161  continue;
162  }
163 
164  struct Binding_Keycode *binding_keycode;
165  TAILQ_FOREACH (binding_keycode, &(bind->keycodes_head), keycodes) {
166  const int keycode = binding_keycode->keycode;
167  const int mods = (binding_keycode->modifiers & 0xFFFF);
168  DLOG("Binding %p Grabbing keycode %d with mods %d\n", bind, keycode, mods);
169  xcb_grab_key(conn, 0, root, mods, keycode, XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC);
170  }
171  }
172 }
173 
174 /*
175  * Release the button grabs on all managed windows and regrab them,
176  * reevaluating which buttons need to be grabbed.
177  *
178  */
179 void regrab_all_buttons(xcb_connection_t *conn) {
180  int *buttons = bindings_get_buttons_to_grab();
181  xcb_grab_server(conn);
182 
183  Con *con;
184  TAILQ_FOREACH (con, &all_cons, all_cons) {
185  if (con->window == NULL)
186  continue;
187 
188  xcb_ungrab_button(conn, XCB_BUTTON_INDEX_ANY, con->window->id, XCB_BUTTON_MASK_ANY);
189  xcb_grab_buttons(conn, con->window->id, buttons);
190  }
191 
192  FREE(buttons);
193  xcb_ungrab_server(conn);
194 }
195 
196 /*
197  * Returns a pointer to the Binding with the specified modifiers and
198  * keycode or NULL if no such binding exists.
199  *
200  */
201 static Binding *get_binding(i3_event_state_mask_t state_filtered, bool is_release, uint16_t input_code, input_type_t input_type) {
202  Binding *bind;
203  Binding *result = NULL;
204 
205  if (!is_release) {
206  /* On a press event, we first reset all B_UPON_KEYRELEASE_IGNORE_MODS
207  * bindings back to B_UPON_KEYRELEASE */
208  TAILQ_FOREACH (bind, bindings, bindings) {
209  if (bind->input_type != input_type)
210  continue;
211  if (bind->release == B_UPON_KEYRELEASE_IGNORE_MODS)
212  bind->release = B_UPON_KEYRELEASE;
213  }
214  }
215 
216  const uint32_t xkb_group_state = (state_filtered & 0xFFFF0000);
217  const uint32_t modifiers_state = (state_filtered & 0x0000FFFF);
218  TAILQ_FOREACH (bind, bindings, bindings) {
219  if (bind->input_type != input_type) {
220  continue;
221  }
222 
223  const uint32_t xkb_group_mask = (bind->event_state_mask & 0xFFFF0000);
224  const bool groups_match = ((xkb_group_state & xkb_group_mask) == xkb_group_mask);
225  if (!groups_match) {
226  DLOG("skipping binding %p because XKB groups do not match\n", bind);
227  continue;
228  }
229 
230  /* For keyboard bindings where a symbol was specified by the user, we
231  * need to look in the array of translated keycodes for the event’s
232  * keycode */
233  bool found_keycode = false;
234  if (input_type == B_KEYBOARD && bind->symbol != NULL) {
235  xcb_keycode_t input_keycode = (xcb_keycode_t)input_code;
236  struct Binding_Keycode *binding_keycode;
237  TAILQ_FOREACH (binding_keycode, &(bind->keycodes_head), keycodes) {
238  const uint32_t modifiers_mask = (binding_keycode->modifiers & 0x0000FFFF);
239  const bool mods_match = (modifiers_mask == modifiers_state);
240  DLOG("binding_keycode->modifiers = %d, modifiers_mask = %d, modifiers_state = %d, mods_match = %s\n",
241  binding_keycode->modifiers, modifiers_mask, modifiers_state, (mods_match ? "yes" : "no"));
242  if (binding_keycode->keycode == input_keycode &&
243  (mods_match || (bind->release == B_UPON_KEYRELEASE_IGNORE_MODS && is_release))) {
244  found_keycode = true;
245  break;
246  }
247  }
248  } else {
249  /* This case is easier: The user specified a keycode */
250  if (bind->keycode != input_code) {
251  continue;
252  }
253 
254  struct Binding_Keycode *binding_keycode;
255  TAILQ_FOREACH (binding_keycode, &(bind->keycodes_head), keycodes) {
256  const uint32_t modifiers_mask = (binding_keycode->modifiers & 0x0000FFFF);
257  const bool mods_match = (modifiers_mask == modifiers_state);
258  DLOG("binding_keycode->modifiers = %d, modifiers_mask = %d, modifiers_state = %d, mods_match = %s\n",
259  binding_keycode->modifiers, modifiers_mask, modifiers_state, (mods_match ? "yes" : "no"));
260  if (mods_match || (bind->release == B_UPON_KEYRELEASE_IGNORE_MODS && is_release)) {
261  found_keycode = true;
262  break;
263  }
264  }
265  }
266  if (!found_keycode) {
267  continue;
268  }
269 
270  /* If this binding is a release binding, it matches the key which the
271  * user pressed. We therefore mark it as B_UPON_KEYRELEASE_IGNORE_MODS
272  * for later, so that the user can release the modifiers before the
273  * actual key or button and the release event will still be matched. */
274  if (bind->release == B_UPON_KEYRELEASE && !is_release) {
275  bind->release = B_UPON_KEYRELEASE_IGNORE_MODS;
276  DLOG("marked bind %p as B_UPON_KEYRELEASE_IGNORE_MODS\n", bind);
277  if (result) {
278  break;
279  }
280  continue;
281  }
282 
283  /* Check if the binding is for a press or a release event */
284  if ((bind->release == B_UPON_KEYPRESS && is_release)) {
285  continue;
286  }
287 
288  if (is_release) {
289  return bind;
290  } else if (!result) {
291  /* Continue looping to mark needed B_UPON_KEYRELEASE_IGNORE_MODS. */
292  result = bind;
293  }
294  }
295 
296  return result;
297 }
298 
299 /*
300  * Returns a pointer to the Binding that matches the given xcb button or key
301  * event or NULL if no such binding exists.
302  *
303  */
304 Binding *get_binding_from_xcb_event(xcb_generic_event_t *event) {
305  const bool is_release = (event->response_type == XCB_KEY_RELEASE ||
306  event->response_type == XCB_BUTTON_RELEASE);
307 
308  const input_type_t input_type = ((event->response_type == XCB_BUTTON_RELEASE ||
309  event->response_type == XCB_BUTTON_PRESS)
310  ? B_MOUSE
311  : B_KEYBOARD);
312 
313  const uint16_t event_state = ((xcb_key_press_event_t *)event)->state;
314  const uint16_t event_detail = ((xcb_key_press_event_t *)event)->detail;
315 
316  /* Remove the CapsLock bit */
317  i3_event_state_mask_t state_filtered = event_state & ~XCB_MOD_MASK_LOCK;
318  DLOG("(removed capslock, state = 0x%x)\n", state_filtered);
319  /* Transform the keyboard_group from bit 13 and bit 14 into an
320  * i3_xkb_group_mask_t, so that get_binding() can just bitwise AND the
321  * configured bindings against |state_filtered|.
322  *
323  * These bits are only set because we set the XKB client flags
324  * XCB_XKB_PER_CLIENT_FLAG_GRABS_USE_XKB_STATE and
325  * XCB_XKB_PER_CLIENT_FLAG_LOOKUP_STATE_WHEN_GRABBED. See also doc/kbproto
326  * section 2.2.2:
327  * https://www.x.org/releases/X11R7.7/doc/kbproto/xkbproto.html#Computing_A_State_Field_from_an_XKB_State */
328  switch ((event_state & 0x6000) >> 13) {
329  case XCB_XKB_GROUP_1:
330  state_filtered |= (I3_XKB_GROUP_MASK_1 << 16);
331  break;
332  case XCB_XKB_GROUP_2:
333  state_filtered |= (I3_XKB_GROUP_MASK_2 << 16);
334  break;
335  case XCB_XKB_GROUP_3:
336  state_filtered |= (I3_XKB_GROUP_MASK_3 << 16);
337  break;
338  case XCB_XKB_GROUP_4:
339  state_filtered |= (I3_XKB_GROUP_MASK_4 << 16);
340  break;
341  }
342  state_filtered &= ~0x6000;
343  DLOG("(transformed keyboard group, state = 0x%x)\n", state_filtered);
344  return get_binding(state_filtered, is_release, event_detail, input_type);
345 }
346 
347 struct resolve {
348  /* The binding which we are resolving. */
350 
351  /* |bind|’s keysym (translated to xkb_keysym_t), e.g. XKB_KEY_R. */
352  xkb_keysym_t keysym;
353 
354  /* The xkb state built from the user-provided modifiers and group. */
356 
357  /* Like |xkb_state|, just without the shift modifier, if shift was specified. */
359 
360  /* Like |xkb_state|, but with NumLock. */
362 
363  /* Like |xkb_state|, but with NumLock, just without the shift modifier, if shift was specified. */
365 };
366 
367 #define ADD_TRANSLATED_KEY(code, mods) \
368  do { \
369  struct Binding_Keycode *binding_keycode = smalloc(sizeof(struct Binding_Keycode)); \
370  binding_keycode->modifiers = (mods); \
371  binding_keycode->keycode = (code); \
372  TAILQ_INSERT_TAIL(&(bind->keycodes_head), binding_keycode, keycodes); \
373  } while (0)
374 
375 /*
376  * add_keycode_if_matches is called for each keycode in the keymap and will add
377  * the keycode to |data->bind| if the keycode can result in the keysym
378  * |data->resolving|.
379  *
380  */
381 static void add_keycode_if_matches(struct xkb_keymap *keymap, xkb_keycode_t key, void *data) {
382  const struct resolve *resolving = data;
383  struct xkb_state *numlock_state = resolving->xkb_state_numlock;
384  xkb_keysym_t sym = xkb_state_key_get_one_sym(resolving->xkb_state, key);
385  if (sym != resolving->keysym) {
386  /* Check if Shift was specified, and try resolving the symbol without
387  * shift, so that “bindsym $mod+Shift+a nop” actually works. */
388  const xkb_layout_index_t layout = xkb_state_key_get_layout(resolving->xkb_state, key);
389  if (layout == XKB_LAYOUT_INVALID)
390  return;
391  if (xkb_state_key_get_level(resolving->xkb_state, key, layout) > 1)
392  return;
393  /* Skip the Shift fallback for keypad keys, otherwise one cannot bind
394  * KP_1 independent of KP_End. */
395  if (sym >= XKB_KEY_KP_Space && sym <= XKB_KEY_KP_Equal)
396  return;
397  numlock_state = resolving->xkb_state_numlock_no_shift;
398  sym = xkb_state_key_get_one_sym(resolving->xkb_state_no_shift, key);
399  if (sym != resolving->keysym)
400  return;
401  }
402  Binding *bind = resolving->bind;
403 
405 
406  /* Also bind the key with active CapsLock */
407  ADD_TRANSLATED_KEY(key, bind->event_state_mask | XCB_MOD_MASK_LOCK);
408 
409  /* If this binding is not explicitly for NumLock, check whether we need to
410  * add a fallback. */
412  /* Check whether the keycode results in the same keysym when NumLock is
413  * active. If so, grab the key with NumLock as well, so that users don’t
414  * need to duplicate every key binding with an additional Mod2 specified.
415  */
416  xkb_keysym_t sym_numlock = xkb_state_key_get_one_sym(numlock_state, key);
417  if (sym_numlock == resolving->keysym) {
418  /* Also bind the key with active NumLock */
420 
421  /* Also bind the key with active NumLock+CapsLock */
422  ADD_TRANSLATED_KEY(key, bind->event_state_mask | xcb_numlock_mask | XCB_MOD_MASK_LOCK);
423  } else {
424  DLOG("Skipping automatic numlock fallback, key %d resolves to 0x%x with numlock\n",
425  key, sym_numlock);
426  }
427  }
428 }
429 
430 /*
431  * Translates keysymbols to keycodes for all bindings which use keysyms.
432  *
433  */
434 void translate_keysyms(void) {
435  struct xkb_state *dummy_state = NULL;
436  struct xkb_state *dummy_state_no_shift = NULL;
437  struct xkb_state *dummy_state_numlock = NULL;
438  struct xkb_state *dummy_state_numlock_no_shift = NULL;
439  bool has_errors = false;
440 
441  if ((dummy_state = xkb_state_new(xkb_keymap)) == NULL ||
442  (dummy_state_no_shift = xkb_state_new(xkb_keymap)) == NULL ||
443  (dummy_state_numlock = xkb_state_new(xkb_keymap)) == NULL ||
444  (dummy_state_numlock_no_shift = xkb_state_new(xkb_keymap)) == NULL) {
445  ELOG("Could not create XKB state, cannot translate keysyms.\n");
446  goto out;
447  }
448 
449  Binding *bind;
450  TAILQ_FOREACH (bind, bindings, bindings) {
451  if (bind->input_type == B_MOUSE) {
452  long button;
453  if (!parse_long(bind->symbol + (sizeof("button") - 1), &button, 10)) {
454  ELOG("Could not translate string to button: \"%s\"\n", bind->symbol);
455  }
456 
457  xcb_keycode_t key = button;
458  bind->keycode = key;
459  DLOG("Binding Mouse button, Keycode = %d\n", key);
460  }
461 
462  xkb_layout_index_t group = XCB_XKB_GROUP_1;
463  if ((bind->event_state_mask >> 16) & I3_XKB_GROUP_MASK_2)
464  group = XCB_XKB_GROUP_2;
465  else if ((bind->event_state_mask >> 16) & I3_XKB_GROUP_MASK_3)
466  group = XCB_XKB_GROUP_3;
467  else if ((bind->event_state_mask >> 16) & I3_XKB_GROUP_MASK_4)
468  group = XCB_XKB_GROUP_4;
469 
470  DLOG("Binding %p group = %d, event_state_mask = %d, &2 = %s, &3 = %s, &4 = %s\n",
471  bind,
472  group,
473  bind->event_state_mask,
474  (bind->event_state_mask & I3_XKB_GROUP_MASK_2) ? "yes" : "no",
475  (bind->event_state_mask & I3_XKB_GROUP_MASK_3) ? "yes" : "no",
476  (bind->event_state_mask & I3_XKB_GROUP_MASK_4) ? "yes" : "no");
477  (void)xkb_state_update_mask(
478  dummy_state,
479  (bind->event_state_mask & 0x1FFF) /* xkb_mod_mask_t base_mods, */,
480  0 /* xkb_mod_mask_t latched_mods, */,
481  0 /* xkb_mod_mask_t locked_mods, */,
482  0 /* xkb_layout_index_t base_group, */,
483  0 /* xkb_layout_index_t latched_group, */,
484  group /* xkb_layout_index_t locked_group, */);
485 
486  (void)xkb_state_update_mask(
487  dummy_state_no_shift,
488  (bind->event_state_mask & 0x1FFF) ^ XCB_KEY_BUT_MASK_SHIFT /* xkb_mod_mask_t base_mods, */,
489  0 /* xkb_mod_mask_t latched_mods, */,
490  0 /* xkb_mod_mask_t locked_mods, */,
491  0 /* xkb_layout_index_t base_group, */,
492  0 /* xkb_layout_index_t latched_group, */,
493  group /* xkb_layout_index_t locked_group, */);
494 
495  (void)xkb_state_update_mask(
496  dummy_state_numlock,
497  (bind->event_state_mask & 0x1FFF) | xcb_numlock_mask /* xkb_mod_mask_t base_mods, */,
498  0 /* xkb_mod_mask_t latched_mods, */,
499  0 /* xkb_mod_mask_t locked_mods, */,
500  0 /* xkb_layout_index_t base_group, */,
501  0 /* xkb_layout_index_t latched_group, */,
502  group /* xkb_layout_index_t locked_group, */);
503 
504  (void)xkb_state_update_mask(
505  dummy_state_numlock_no_shift,
506  ((bind->event_state_mask & 0x1FFF) | xcb_numlock_mask) ^ XCB_KEY_BUT_MASK_SHIFT /* xkb_mod_mask_t base_mods, */,
507  0 /* xkb_mod_mask_t latched_mods, */,
508  0 /* xkb_mod_mask_t locked_mods, */,
509  0 /* xkb_layout_index_t base_group, */,
510  0 /* xkb_layout_index_t latched_group, */,
511  group /* xkb_layout_index_t locked_group, */);
512 
513  if (bind->keycode > 0) {
514  /* We need to specify modifiers for the keycode binding (numlock
515  * fallback). */
516  while (!TAILQ_EMPTY(&(bind->keycodes_head))) {
517  struct Binding_Keycode *first = TAILQ_FIRST(&(bind->keycodes_head));
518  TAILQ_REMOVE(&(bind->keycodes_head), first, keycodes);
519  FREE(first);
520  }
521 
523 
524  /* Also bind the key with active CapsLock */
525  ADD_TRANSLATED_KEY(bind->keycode, bind->event_state_mask | XCB_MOD_MASK_LOCK);
526 
527  /* If this binding is not explicitly for NumLock, check whether we need to
528  * add a fallback. */
530  /* Check whether the keycode results in the same keysym when NumLock is
531  * active. If so, grab the key with NumLock as well, so that users don’t
532  * need to duplicate every key binding with an additional Mod2 specified.
533  */
534  xkb_keysym_t sym = xkb_state_key_get_one_sym(dummy_state, bind->keycode);
535  xkb_keysym_t sym_numlock = xkb_state_key_get_one_sym(dummy_state_numlock, bind->keycode);
536  if (sym == sym_numlock) {
537  /* Also bind the key with active NumLock */
539 
540  /* Also bind the key with active NumLock+CapsLock */
541  ADD_TRANSLATED_KEY(bind->keycode, bind->event_state_mask | xcb_numlock_mask | XCB_MOD_MASK_LOCK);
542  } else {
543  DLOG("Skipping automatic numlock fallback, key %d resolves to 0x%x with numlock\n",
544  bind->keycode, sym_numlock);
545  }
546  }
547 
548  continue;
549  }
550 
551  /* We need to translate the symbol to a keycode */
552  const xkb_keysym_t keysym = xkb_keysym_from_name(bind->symbol, XKB_KEYSYM_NO_FLAGS);
553  if (keysym == XKB_KEY_NoSymbol) {
554  ELOG("Could not translate string to key symbol: \"%s\"\n",
555  bind->symbol);
556  continue;
557  }
558 
559  struct resolve resolving = {
560  .bind = bind,
561  .keysym = keysym,
562  .xkb_state = dummy_state,
563  .xkb_state_no_shift = dummy_state_no_shift,
564  .xkb_state_numlock = dummy_state_numlock,
565  .xkb_state_numlock_no_shift = dummy_state_numlock_no_shift,
566  };
567  while (!TAILQ_EMPTY(&(bind->keycodes_head))) {
568  struct Binding_Keycode *first = TAILQ_FIRST(&(bind->keycodes_head));
569  TAILQ_REMOVE(&(bind->keycodes_head), first, keycodes);
570  FREE(first);
571  }
572  xkb_keymap_key_for_each(xkb_keymap, add_keycode_if_matches, &resolving);
573  char *keycodes = sstrdup("");
574  int num_keycodes = 0;
575  struct Binding_Keycode *binding_keycode;
576  TAILQ_FOREACH (binding_keycode, &(bind->keycodes_head), keycodes) {
577  char *tmp;
578  sasprintf(&tmp, "%s %d", keycodes, binding_keycode->keycode);
579  free(keycodes);
580  keycodes = tmp;
581  num_keycodes++;
582 
583  /* check for duplicate bindings */
584  Binding *check;
585  TAILQ_FOREACH (check, bindings, bindings) {
586  if (check == bind)
587  continue;
588  if (check->symbol != NULL)
589  continue;
590  if (check->keycode != binding_keycode->keycode ||
591  check->event_state_mask != binding_keycode->modifiers ||
592  check->release != bind->release)
593  continue;
594  has_errors = true;
595  ELOG("Duplicate keybinding in config file:\n keysym = %s, keycode = %d, state_mask = 0x%x\n", bind->symbol, check->keycode, bind->event_state_mask);
596  }
597  }
598  DLOG("state=0x%x, cfg=\"%s\", sym=0x%x → keycodes%s (%d)\n",
599  bind->event_state_mask, bind->symbol, keysym, keycodes, num_keycodes);
600  free(keycodes);
601  }
602 
603 out:
604  xkb_state_unref(dummy_state);
605  xkb_state_unref(dummy_state_no_shift);
606  xkb_state_unref(dummy_state_numlock);
607  xkb_state_unref(dummy_state_numlock_no_shift);
608 
609  if (has_errors) {
611  }
612 }
613 
614 #undef ADD_TRANSLATED_KEY
615 
616 /*
617  * Switches the key bindings to the given mode, if the mode exists
618  *
619  */
620 void switch_mode(const char *new_mode) {
621  struct Mode *mode;
622 
623  DLOG("Switching to mode %s\n", new_mode);
624 
625  SLIST_FOREACH (mode, &modes, modes) {
626  if (strcmp(mode->name, new_mode) != 0)
627  continue;
628 
630  bindings = mode->bindings;
631  current_binding_mode = mode->name;
634 
635  /* Reset all B_UPON_KEYRELEASE_IGNORE_MODS bindings to avoid possibly
636  * activating one of them. */
637  Binding *bind;
638  TAILQ_FOREACH (bind, bindings, bindings) {
639  if (bind->release == B_UPON_KEYRELEASE_IGNORE_MODS)
640  bind->release = B_UPON_KEYRELEASE;
641  }
642 
643  char *event_msg;
644  sasprintf(&event_msg, "{\"change\":\"%s\", \"pango_markup\":%s}",
645  mode->name, (mode->pango_markup ? "true" : "false"));
646 
647  ipc_send_event("mode", I3_IPC_EVENT_MODE, event_msg);
648  FREE(event_msg);
649 
650  return;
651  }
652 
653  ELOG("Mode not found\n");
654 }
655 
656 static int reorder_binding_cmp(const void *a, const void *b) {
657  Binding *first = *((Binding **)a);
658  Binding *second = *((Binding **)b);
659  if (first->event_state_mask < second->event_state_mask) {
660  return 1;
661  } else if (first->event_state_mask == second->event_state_mask) {
662  return 0;
663  } else {
664  return -1;
665  }
666 }
667 
668 static void reorder_bindings_of_mode(struct Mode *mode) {
669  /* Copy the bindings into an array, so that we can use qsort(3). */
670  int n = 0;
671  Binding *current;
672  TAILQ_FOREACH (current, mode->bindings, bindings) {
673  n++;
674  }
675  Binding **tmp = scalloc(n, sizeof(Binding *));
676  n = 0;
677  TAILQ_FOREACH (current, mode->bindings, bindings) {
678  tmp[n++] = current;
679  }
680 
681  qsort(tmp, n, sizeof(Binding *), reorder_binding_cmp);
682 
683  struct bindings_head *reordered = scalloc(1, sizeof(struct bindings_head));
684  TAILQ_INIT(reordered);
685  for (int i = 0; i < n; i++) {
686  current = tmp[i];
687  TAILQ_REMOVE(mode->bindings, current, bindings);
688  TAILQ_INSERT_TAIL(reordered, current, bindings);
689  }
690  free(tmp);
691  assert(TAILQ_EMPTY(mode->bindings));
692  /* Free the old bindings_head, which is now empty. */
693  free(mode->bindings);
694  mode->bindings = reordered;
695 }
696 
697 /*
698  * Reorders bindings by event_state_mask descendingly so that get_binding()
699  * correctly matches more specific bindings before more generic bindings. Take
700  * the following binding configuration as an example:
701  *
702  * bindsym n nop lower-case n pressed
703  * bindsym Shift+n nop upper-case n pressed
704  *
705  * Without reordering, the first binding’s event_state_mask of 0x0 would match
706  * the actual event_stat_mask of 0x1 and hence trigger instead of the second
707  * keybinding.
708  *
709  */
710 void reorder_bindings(void) {
711  struct Mode *mode;
712  SLIST_FOREACH (mode, &modes, modes) {
713  const bool current_mode = (mode->bindings == bindings);
715  if (current_mode)
716  bindings = mode->bindings;
717  }
718 }
719 
720 /*
721  * Returns true if a is a key binding for the same key as b.
722  *
723  */
724 static bool binding_same_key(Binding *a, Binding *b) {
725  /* Check if the input types are different */
726  if (a->input_type != b->input_type) {
727  return false;
728  }
729 
730  /* Check if one is using keysym while the other is using bindsym. */
731  if ((a->symbol == NULL && b->symbol != NULL) ||
732  (a->symbol != NULL && b->symbol == NULL)) {
733  return false;
734  }
735 
736  /* If a is NULL, b has to be NULL, too (see previous conditional).
737  * If the keycodes differ, it can't be a duplicate. */
738  if (a->symbol != NULL &&
739  strcasecmp(a->symbol, b->symbol) != 0) {
740  return false;
741  }
742 
743  /* Check if the keycodes or modifiers are different. If so, they
744  * can't be duplicate */
745  if (a->keycode != b->keycode ||
747  a->release != b->release) {
748  return false;
749  }
750 
751  return true;
752 }
753 
754 /*
755  * Checks for duplicate key bindings (the same keycode or keysym is configured
756  * more than once). If a duplicate binding is found, a message is printed to
757  * stderr and the has_errors variable is set to true, which will start
758  * i3-nagbar.
759  *
760  */
762  Binding *bind, *current;
763  TAILQ_FOREACH (current, bindings, bindings) {
764  TAILQ_FOREACH (bind, bindings, bindings) {
765  /* Abort when we reach the current keybinding, only check the
766  * bindings before */
767  if (bind == current) {
768  break;
769  }
770 
771  if (!binding_same_key(bind, current)) {
772  continue;
773  }
774 
775  context->has_errors = true;
776  if (current->keycode != 0) {
777  ELOG("Duplicate keybinding in config file:\n state mask 0x%x with keycode %d, command \"%s\"\n",
778  current->event_state_mask, current->keycode, current->command);
779  } else {
780  ELOG("Duplicate keybinding in config file:\n state mask 0x%x with keysym %s, command \"%s\"\n",
781  current->event_state_mask, current->symbol, current->command);
782  }
783  }
784  }
785 }
786 
787 /*
788  * Creates a dynamically allocated copy of bind.
789  */
790 static Binding *binding_copy(Binding *bind) {
791  Binding *ret = smalloc(sizeof(Binding));
792  *ret = *bind;
793  if (bind->symbol != NULL)
794  ret->symbol = sstrdup(bind->symbol);
795  if (bind->command != NULL)
796  ret->command = sstrdup(bind->command);
797  TAILQ_INIT(&(ret->keycodes_head));
798  struct Binding_Keycode *binding_keycode;
799  TAILQ_FOREACH (binding_keycode, &(bind->keycodes_head), keycodes) {
800  struct Binding_Keycode *ret_binding_keycode = smalloc(sizeof(struct Binding_Keycode));
801  *ret_binding_keycode = *binding_keycode;
802  TAILQ_INSERT_TAIL(&(ret->keycodes_head), ret_binding_keycode, keycodes);
803  }
804 
805  return ret;
806 }
807 
808 /*
809  * Frees the binding. If bind is null, it simply returns.
810  */
811 void binding_free(Binding *bind) {
812  if (bind == NULL) {
813  return;
814  }
815 
816  while (!TAILQ_EMPTY(&(bind->keycodes_head))) {
817  struct Binding_Keycode *first = TAILQ_FIRST(&(bind->keycodes_head));
818  TAILQ_REMOVE(&(bind->keycodes_head), first, keycodes);
819  FREE(first);
820  }
821 
822  FREE(bind->symbol);
823  FREE(bind->command);
824  FREE(bind);
825 }
826 
827 /*
828  * Runs the given binding and handles parse errors. If con is passed, it will
829  * execute the command binding with that container selected by criteria.
830  * Returns a CommandResult for running the binding's command. Free with
831  * command_result_free().
832  *
833  */
835  char *command;
836 
837  /* We need to copy the binding and command since “reload” may be part of
838  * the command, and then the memory that bind points to may not contain the
839  * same data anymore. */
840  if (con == NULL)
841  command = sstrdup(bind->command);
842  else
843  sasprintf(&command, "[con_id=\"%p\"] %s", con, bind->command);
844 
845  Binding *bind_cp = binding_copy(bind);
846  CommandResult *result = parse_command(command, NULL, NULL);
847  free(command);
848 
849  if (result->needs_tree_render)
850  tree_render();
851 
852  if (result->parse_error) {
853  char *pageraction;
854  sasprintf(&pageraction, "i3-sensible-pager \"%s\"\n", errorfilename);
855  char *argv[] = {
856  NULL, /* will be replaced by the executable path */
857  "-f",
859  "-t",
860  "error",
861  "-m",
862  "The configured command for this shortcut could not be run successfully.",
863  "-b",
864  "show errors",
865  pageraction,
866  NULL};
868  free(pageraction);
869  }
870 
871  ipc_send_binding_event("run", bind_cp);
872  binding_free(bind_cp);
873 
874  return result;
875 }
876 
877 static int fill_rmlvo_from_root(struct xkb_rule_names *xkb_names) {
878  xcb_intern_atom_reply_t *atom_reply;
879  size_t content_max_words = 256;
880 
881  atom_reply = xcb_intern_atom_reply(
882  conn, xcb_intern_atom(conn, 0, strlen("_XKB_RULES_NAMES"), "_XKB_RULES_NAMES"), NULL);
883  if (atom_reply == NULL)
884  return -1;
885 
886  xcb_get_property_cookie_t prop_cookie;
887  xcb_get_property_reply_t *prop_reply;
888  prop_cookie = xcb_get_property_unchecked(conn, false, root, atom_reply->atom,
889  XCB_GET_PROPERTY_TYPE_ANY, 0, content_max_words);
890  prop_reply = xcb_get_property_reply(conn, prop_cookie, NULL);
891  if (prop_reply == NULL) {
892  free(atom_reply);
893  return -1;
894  }
895  if (xcb_get_property_value_length(prop_reply) > 0 && prop_reply->bytes_after > 0) {
896  /* We received an incomplete value. Ask again but with a properly
897  * adjusted size. */
898  content_max_words += ceil(prop_reply->bytes_after / 4.0);
899  /* Repeat the request, with adjusted size */
900  free(prop_reply);
901  prop_cookie = xcb_get_property_unchecked(conn, false, root, atom_reply->atom,
902  XCB_GET_PROPERTY_TYPE_ANY, 0, content_max_words);
903  prop_reply = xcb_get_property_reply(conn, prop_cookie, NULL);
904  if (prop_reply == NULL) {
905  free(atom_reply);
906  return -1;
907  }
908  }
909  if (xcb_get_property_value_length(prop_reply) == 0) {
910  free(atom_reply);
911  free(prop_reply);
912  return -1;
913  }
914 
915  const char *walk = (const char *)xcb_get_property_value(prop_reply);
916  int remaining = xcb_get_property_value_length(prop_reply);
917  for (int i = 0; i < 5 && remaining > 0; i++) {
918  const int len = strnlen(walk, remaining);
919  switch (i) {
920  case 0:
921  sasprintf((char **)&(xkb_names->rules), "%.*s", len, walk);
922  break;
923  case 1:
924  sasprintf((char **)&(xkb_names->model), "%.*s", len, walk);
925  break;
926  case 2:
927  sasprintf((char **)&(xkb_names->layout), "%.*s", len, walk);
928  break;
929  case 3:
930  sasprintf((char **)&(xkb_names->variant), "%.*s", len, walk);
931  break;
932  case 4:
933  sasprintf((char **)&(xkb_names->options), "%.*s", len, walk);
934  break;
935  }
936  DLOG("component %d of _XKB_RULES_NAMES is \"%.*s\"\n", i, len, walk);
937  walk += (len + 1);
938  remaining -= (len + 1);
939  }
940 
941  free(atom_reply);
942  free(prop_reply);
943  return 0;
944 }
945 
946 /*
947  * Loads the XKB keymap from the X11 server and feeds it to xkbcommon.
948  *
949  */
950 bool load_keymap(void) {
951  if (xkb_context == NULL) {
952  if ((xkb_context = xkb_context_new(0)) == NULL) {
953  ELOG("Could not create xkbcommon context\n");
954  return false;
955  }
956  }
957 
958  struct xkb_keymap *new_keymap = NULL;
959  int32_t device_id;
960  if (xkb_supported && (device_id = xkb_x11_get_core_keyboard_device_id(conn)) > -1) {
961  if ((new_keymap = xkb_x11_keymap_new_from_device(xkb_context, conn, device_id, 0)) == NULL) {
962  ELOG("xkb_x11_keymap_new_from_device failed\n");
963  return false;
964  }
965  } else {
966  /* Likely there is no XKB support on this server, possibly because it
967  * is a VNC server. */
968  LOG("No XKB / core keyboard device? Assembling keymap from local RMLVO.\n");
969  struct xkb_rule_names names = {
970  .rules = NULL,
971  .model = NULL,
972  .layout = NULL,
973  .variant = NULL,
974  .options = NULL};
975  if (fill_rmlvo_from_root(&names) == -1) {
976  ELOG("Could not get _XKB_RULES_NAMES atom from root window, falling back to defaults.\n");
977  /* Using NULL for the fields of xkb_rule_names. */
978  }
979  new_keymap = xkb_keymap_new_from_names(xkb_context, &names, 0);
980  free((char *)names.rules);
981  free((char *)names.model);
982  free((char *)names.layout);
983  free((char *)names.variant);
984  free((char *)names.options);
985  if (new_keymap == NULL) {
986  ELOG("xkb_keymap_new_from_names failed\n");
987  return false;
988  }
989  }
990  xkb_keymap_unref(xkb_keymap);
991  xkb_keymap = new_keymap;
992 
993  return true;
994 }
995 
996 /*
997  * Returns a list of buttons that should be grabbed on a window.
998  * This list will always contain 1–3, all higher buttons will only be returned
999  * if there is a whole-window binding for it on some window in the current
1000  * config.
1001  * The list is terminated by a 0.
1002  */
1004  /* Let's make the reasonable assumption that there's no more than 25
1005  * buttons. */
1006  int num_max = 25;
1007 
1008  int buffer[num_max];
1009  int num = 0;
1010 
1011  /* We always return buttons 1 through 3. */
1012  buffer[num++] = 1;
1013  buffer[num++] = 2;
1014  buffer[num++] = 3;
1015 
1016  Binding *bind;
1017  TAILQ_FOREACH (bind, bindings, bindings) {
1018  if (num + 1 == num_max)
1019  break;
1020 
1021  /* We are only interested in whole window mouse bindings. */
1022  if (bind->input_type != B_MOUSE || !bind->whole_window)
1023  continue;
1024 
1025  long button;
1026  if (!parse_long(bind->symbol + (sizeof("button") - 1), &button, 10)) {
1027  ELOG("Could not parse button number, skipping this binding. Please report this bug in i3.\n");
1028  continue;
1029  }
1030 
1031  /* Avoid duplicates. */
1032  for (int i = 0; i < num; i++) {
1033  if (buffer[i] == button)
1034  continue;
1035  }
1036 
1037  buffer[num++] = button;
1038  }
1039  buffer[num++] = 0;
1040 
1041  int *buttons = scalloc(num, sizeof(int));
1042  memcpy(buttons, buffer, num * sizeof(int));
1043 
1044  return buttons;
1045 }
void binding_free(Binding *bind)
Frees the binding.
Definition: bindings.c:811
static struct xkb_context * xkb_context
Definition: bindings.c:16
static Binding * binding_copy(Binding *bind)
Definition: bindings.c:790
void check_for_duplicate_bindings(struct context *context)
Checks for duplicate key bindings (the same keycode or keysym is configured more than once).
Definition: bindings.c:761
static Binding * get_binding(i3_event_state_mask_t state_filtered, bool is_release, uint16_t input_code, input_type_t input_type)
Definition: bindings.c:201
static bool binding_same_key(Binding *a, Binding *b)
Definition: bindings.c:724
bool load_keymap(void)
Loads the XKB keymap from the X11 server and feeds it to xkbcommon.
Definition: bindings.c:950
static int reorder_binding_cmp(const void *a, const void *b)
Definition: bindings.c:656
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 struct Mode * mode_from_name(const char *name, bool pango_markup)
Definition: bindings.c:32
static void add_keycode_if_matches(struct xkb_keymap *keymap, xkb_keycode_t key, void *data)
Definition: bindings.c:381
CommandResult * run_binding(Binding *bind, Con *con)
Runs the given binding and handles parse errors.
Definition: bindings.c:834
const char * DEFAULT_BINDING_MODE
The name of the default mode.
Definition: bindings.c:25
static struct xkb_keymap * xkb_keymap
Definition: bindings.c:17
void regrab_all_buttons(xcb_connection_t *conn)
Release the button grabs on all managed windows and regrab them, reevaluating which buttons need to b...
Definition: bindings.c:179
int * bindings_get_buttons_to_grab(void)
Returns a list of buttons that should be grabbed on a window.
Definition: bindings.c:1003
void switch_mode(const char *new_mode)
Switches the key bindings to the given mode, if the mode exists.
Definition: bindings.c:620
static int fill_rmlvo_from_root(struct xkb_rule_names *xkb_names)
Definition: bindings.c:877
#define GRAB_KEY(modifier)
Binding * get_binding_from_xcb_event(xcb_generic_event_t *event)
Returns a pointer to the Binding that matches the given xcb event or NULL if no such binding exists.
Definition: bindings.c:304
static void grab_keycode_for_binding(xcb_connection_t *conn, Binding *bind, uint32_t keycode)
Definition: bindings.c:127
pid_t command_error_nagbar_pid
Definition: bindings.c:19
Binding * configure_binding(const char *bindtype, const char *modifiers, const char *input_code, const char *release, const char *border, const char *whole_window, const char *exclude_titlebar, const char *command, const char *modename, bool pango_markup)
Adds a binding from config parameters given as strings and returns a pointer to the binding structure...
Definition: bindings.c:59
#define ADD_TRANSLATED_KEY(code, mods)
Definition: bindings.c:367
static void reorder_bindings_of_mode(struct Mode *mode)
Definition: bindings.c:668
void reorder_bindings(void)
Reorders bindings by event_state_mask descendingly so that get_binding() correctly matches more speci...
Definition: bindings.c:710
static bool binding_in_current_group(const Binding *bind)
Definition: bindings.c:108
void translate_keysyms(void)
Translates keysymbols to keycodes for all bindings which use keysyms.
Definition: bindings.c:434
CommandResult * parse_command(const char *input, yajl_gen gen, ipc_client *client)
Parses and executes the given command.
Config config
Definition: config.c:19
struct modes_head modes
Definition: config.c:20
char * current_configpath
Definition: config.c:18
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
static char * current_mode
i3_event_state_mask_t event_state_from_str(const char *str)
A utility function to convert a string containing the group and modifiers to the corresponding bit ma...
void start_config_error_nagbar(const char *configpath, bool has_errors)
Launch nagbar to indicate errors in the configuration file.
int xkb_current_group
Definition: handlers.c:22
void ipc_send_binding_event(const char *event_type, Binding *bind)
For the binding events, we send the serialized binding struct.
Definition: ipc.c:1642
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
char * errorfilename
Definition: log.c:38
bool xkb_supported
Definition: main.c:104
xcb_connection_t * conn
XCB connection and root screen.
Definition: main.c:54
xcb_window_t root
Definition: main.c:67
const char * current_binding_mode
Definition: main.c:88
struct bindings_head * bindings
Definition: main.c:87
struct all_cons_head all_cons
Definition: tree.c:15
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
void start_nagbar(pid_t *nagbar_pid, char *argv[])
Starts an i3-nagbar instance with the given parameters.
Definition: util.c:354
bool parse_long(const char *str, long *out, int base)
Converts a string into a long using strtol().
Definition: util.c:409
unsigned int xcb_numlock_mask
Definition: xcb.c:12
void xcb_grab_buttons(xcb_connection_t *conn, xcb_window_t window, int *buttons)
Grab the specified buttons on a window when managing it.
Definition: xcb.c:279
@ I3_XKB_GROUP_MASK_2
Definition: data.h:115
@ I3_XKB_GROUP_MASK_3
Definition: data.h:116
@ I3_XKB_GROUP_MASK_4
Definition: data.h:117
@ I3_XKB_GROUP_MASK_1
Definition: data.h:114
@ I3_XKB_GROUP_MASK_ANY
Definition: data.h:113
uint32_t i3_event_state_mask_t
The lower 16 bits contain a xcb_key_but_mask_t, the higher 16 bits contain an i3_xkb_group_mask_t.
Definition: data.h:126
input_type_t
Binding input types.
Definition: data.h:104
@ B_KEYBOARD
Definition: data.h:105
@ B_MOUSE
Definition: data.h:106
char * sstrdup(const char *str)
Safe-wrapper around strdup which exits if malloc returns NULL (meaning that there is no more memory a...
#define DLOG(fmt,...)
Definition: libi3.h:105
#define LOG(fmt,...)
Definition: libi3.h:95
void * smalloc(size_t size)
Safe-wrapper around malloc which exits if malloc returns NULL (meaning that there is no more memory a...
#define ELOG(fmt,...)
Definition: libi3.h:100
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...
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...
#define SLIST_FOREACH(var, head, field)
Definition: queue.h:114
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:347
#define TAILQ_INIT(head)
Definition: queue.h:360
#define SLIST_INSERT_HEAD(head, elm, field)
Definition: queue.h:138
#define TAILQ_INSERT_TAIL(head, elm, field)
Definition: queue.h:376
#define TAILQ_FIRST(head)
Definition: queue.h:336
#define TAILQ_REMOVE(head, elm, field)
Definition: queue.h:402
#define TAILQ_EMPTY(head)
Definition: queue.h:344
#define FREE(pointer)
Definition: util.h:47
struct xkb_state * xkb_state_numlock_no_shift
Definition: bindings.c:364
struct xkb_state * xkb_state
Definition: bindings.c:355
struct xkb_state * xkb_state_numlock
Definition: bindings.c:361
Binding * bind
Definition: bindings.c:349
xkb_keysym_t keysym
Definition: bindings.c:352
struct xkb_state * xkb_state_no_shift
Definition: bindings.c:358
A struct that contains useful information about the result of a command as a whole (e....
Used during the config file lexing/parsing to keep the state of the lexer in order to provide useful ...
Definition: configuration.h:33
bool has_errors
Definition: configuration.h:34
The configuration file can contain multiple sets of bindings.
Definition: configuration.h:92
char * name
Definition: configuration.h:93
struct bindings_head * bindings
Definition: configuration.h:95
bool pango_markup
Definition: configuration.h:94
i3Font font
Stores a resolved keycode (from a keysym), including the modifier mask.
Definition: data.h:260
i3_event_state_mask_t modifiers
Definition: data.h:262
xcb_keycode_t keycode
Definition: data.h:261
Holds a keybinding, consisting of a keycode combined with modifiers and the command which is executed...
Definition: data.h:276
bool whole_window
If this is true for a mouse binding, the binding should be executed when the button is pressed over a...
Definition: data.h:302
char * command
Command, like in command mode.
Definition: data.h:327
bool border
If this is true for a mouse binding, the binding should be executed when the button is pressed over t...
Definition: data.h:297
uint32_t keycode
Keycode to bind.
Definition: data.h:309
char * symbol
Symbol the user specified in configfile, if any.
Definition: data.h:319
enum Binding::@10 release
If true, the binding should be executed upon a KeyRelease event, not a KeyPress (the default).
bool exclude_titlebar
If this is true for a mouse binding, the binding should only be executed if the button press was not ...
Definition: data.h:306
i3_event_state_mask_t event_state_mask
Bitmask which is applied against event->state for KeyPress and KeyRelease events to determine whether...
Definition: data.h:314
input_type_t input_type
Definition: data.h:279
xcb_window_t id
Definition: data.h:395
A 'Con' represents everything from the X11 root window down to a single X11 window.
Definition: data.h:613
struct Window * window
Definition: data.h:685
char * pattern
The pattern/name used to load the font.
Definition: libi3.h:71