i3
commands.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  * commands.c: all command functions (see commands_parser.c)
8  *
9  */
10 #include "all.h"
11 
12 #include <stdint.h>
13 #include <float.h>
14 #include <stdarg.h>
15 #include <unistd.h>
16 #include <fcntl.h>
17 
18 #include "shmlog.h"
19 
20 // Macros to make the YAJL API a bit easier to use.
21 #define y(x, ...) (cmd_output->json_gen != NULL ? yajl_gen_##x(cmd_output->json_gen, ##__VA_ARGS__) : 0)
22 #define ystr(str) (cmd_output->json_gen != NULL ? yajl_gen_string(cmd_output->json_gen, (unsigned char *)str, strlen(str)) : 0)
23 #define ysuccess(success) \
24  do { \
25  if (cmd_output->json_gen != NULL) { \
26  y(map_open); \
27  ystr("success"); \
28  y(bool, success); \
29  y(map_close); \
30  } \
31  } while (0)
32 #define yerror(format, ...) \
33  do { \
34  if (cmd_output->json_gen != NULL) { \
35  char *message; \
36  sasprintf(&message, format, ##__VA_ARGS__); \
37  y(map_open); \
38  ystr("success"); \
39  y(bool, false); \
40  ystr("error"); \
41  ystr(message); \
42  y(map_close); \
43  free(message); \
44  } \
45  } while (0)
46 
49 #define HANDLE_INVALID_MATCH \
50  do { \
51  if (current_match->error != NULL) { \
52  yerror("Invalid match: %s", current_match->error); \
53  return; \
54  } \
55  } while (0)
56 
62 #define HANDLE_EMPTY_MATCH \
63  do { \
64  HANDLE_INVALID_MATCH; \
65  \
66  if (match_is_empty(current_match)) { \
67  while (!TAILQ_EMPTY(&owindows)) { \
68  owindow *ow = TAILQ_FIRST(&owindows); \
69  TAILQ_REMOVE(&owindows, ow, owindows); \
70  free(ow); \
71  } \
72  owindow *ow = smalloc(sizeof(owindow)); \
73  ow->con = focused; \
74  TAILQ_INIT(&owindows); \
75  TAILQ_INSERT_TAIL(&owindows, ow, owindows); \
76  } \
77  } while (0)
78 
79 /*
80  * Checks whether we switched to a new workspace and returns false in that case,
81  * signaling that further workspace switching should be done by the calling function
82  * If not, calls workspace_back_and_forth() if workspace_auto_back_and_forth is set
83  * and return true, signaling that no further workspace switching should occur in the calling function.
84  *
85  */
86 static bool maybe_back_and_forth(struct CommandResultIR *cmd_output, const char *name) {
88 
89  /* If we switched to a different workspace, do nothing */
90  if (strcmp(ws->name, name) != 0)
91  return false;
92 
93  DLOG("This workspace is already focused.\n");
96  cmd_output->needs_tree_render = true;
97  }
98  return true;
99 }
100 
101 /*
102  * Return the passed workspace unless it is the current one and auto back and
103  * forth is enabled, in which case the back_and_forth workspace is returned.
104  */
106  Con *current, *baf;
107 
109  return workspace;
110 
111  current = con_get_workspace(focused);
112 
113  if (current == workspace) {
115  if (baf != NULL) {
116  DLOG("Substituting workspace with back_and_forth, as it is focused.\n");
117  return baf;
118  }
119  }
120 
121  return workspace;
122 }
123 
124 /*******************************************************************************
125  * Criteria functions.
126  ******************************************************************************/
127 
128 /*
129  * Helper data structure for an operation window (window on which the operation
130  * will be performed). Used to build the TAILQ owindows.
131  *
132  */
133 typedef struct owindow {
134  Con *con;
135 
137  owindows;
139 
140 typedef TAILQ_HEAD(owindows_head, owindow) owindows_head;
141 
142 static owindows_head owindows;
143 
144 /*
145  * Initializes the specified 'Match' data structure and the initial state of
146  * commands.c for matching target windows of a command.
147  *
148  */
150  Con *con;
151  owindow *ow;
152 
153  DLOG("Initializing criteria, current_match = %p\n", current_match);
156  while (!TAILQ_EMPTY(&owindows)) {
157  ow = TAILQ_FIRST(&owindows);
158  TAILQ_REMOVE(&owindows, ow, owindows);
159  free(ow);
160  }
161  TAILQ_INIT(&owindows);
162  /* copy all_cons */
164  ow = smalloc(sizeof(owindow));
165  ow->con = con;
166  TAILQ_INSERT_TAIL(&owindows, ow, owindows);
167  }
168 }
169 
170 /*
171  * A match specification just finished (the closing square bracket was found),
172  * so we filter the list of owindows.
173  *
174  */
176  owindow *next, *current;
177 
178  DLOG("match specification finished, matching...\n");
179  /* copy the old list head to iterate through it and start with a fresh
180  * list which will contain only matching windows */
181  struct owindows_head old = owindows;
182  TAILQ_INIT(&owindows);
183  for (next = TAILQ_FIRST(&old); next != TAILQ_END(&old);) {
184  /* make a copy of the next pointer and advance the pointer to the
185  * next element as we are going to invalidate the element’s
186  * next/prev pointers by calling TAILQ_INSERT_TAIL later */
187  current = next;
188  next = TAILQ_NEXT(next, owindows);
189 
190  DLOG("checking if con %p / %s matches\n", current->con, current->con->name);
191 
192  /* We use this flag to prevent matching on window-less containers if
193  * only window-specific criteria were specified. */
194  bool accept_match = false;
195 
196  if (current_match->con_id != NULL) {
197  accept_match = true;
198 
199  if (current_match->con_id == current->con) {
200  DLOG("con_id matched.\n");
201  } else {
202  DLOG("con_id does not match.\n");
203  FREE(current);
204  continue;
205  }
206  }
207 
208  if (current_match->mark != NULL && !TAILQ_EMPTY(&(current->con->marks_head))) {
209  accept_match = true;
210  bool matched_by_mark = false;
211 
212  mark_t *mark;
213  TAILQ_FOREACH(mark, &(current->con->marks_head), marks) {
214  if (!regex_matches(current_match->mark, mark->name))
215  continue;
216 
217  DLOG("match by mark\n");
218  matched_by_mark = true;
219  break;
220  }
221 
222  if (!matched_by_mark) {
223  DLOG("mark does not match.\n");
224  FREE(current);
225  continue;
226  }
227  }
228 
229  if (current->con->window != NULL) {
230  if (match_matches_window(current_match, current->con->window)) {
231  DLOG("matches window!\n");
232  accept_match = true;
233  } else {
234  DLOG("doesn't match\n");
235  FREE(current);
236  continue;
237  }
238  }
239 
240  if (accept_match) {
241  TAILQ_INSERT_TAIL(&owindows, current, owindows);
242  } else {
243  FREE(current);
244  continue;
245  }
246  }
247 
248  TAILQ_FOREACH(current, &owindows, owindows) {
249  DLOG("matching: %p / %s\n", current->con, current->con->name);
250  }
251 }
252 
253 /*
254  * Interprets a ctype=cvalue pair and adds it to the current match
255  * specification.
256  *
257  */
258 void cmd_criteria_add(I3_CMD, const char *ctype, const char *cvalue) {
259  match_parse_property(current_match, ctype, cvalue);
260 }
261 
262 static void move_matches_to_workspace(Con *ws) {
263  owindow *current;
264  TAILQ_FOREACH(current, &owindows, owindows) {
265  DLOG("matching: %p / %s\n", current->con, current->con->name);
266  con_move_to_workspace(current->con, ws, true, false, false);
267  }
268 }
269 
270 #define CHECK_MOVE_CON_TO_WORKSPACE \
271  do { \
272  HANDLE_EMPTY_MATCH; \
273  if (TAILQ_EMPTY(&owindows)) { \
274  yerror("Nothing to move: specified criteria don't match any window"); \
275  return; \
276  } else { \
277  bool found = false; \
278  owindow *current = TAILQ_FIRST(&owindows); \
279  while (current) { \
280  owindow *next = TAILQ_NEXT(current, owindows); \
281  \
282  if (current->con->type == CT_WORKSPACE && !con_has_children(current->con)) { \
283  TAILQ_REMOVE(&owindows, current, owindows); \
284  } else { \
285  found = true; \
286  } \
287  \
288  current = next; \
289  } \
290  if (!found) { \
291  yerror("Nothing to move: workspace empty"); \
292  return; \
293  } \
294  } \
295  } while (0)
296 
297 /*
298  * Implementation of 'move [window|container] [to] workspace
299  * next|prev|next_on_output|prev_on_output|current'.
300  *
301  */
302 void cmd_move_con_to_workspace(I3_CMD, const char *which) {
303  DLOG("which=%s\n", which);
304 
306 
307  /* get the workspace */
308  Con *ws;
309  if (strcmp(which, "next") == 0)
310  ws = workspace_next();
311  else if (strcmp(which, "prev") == 0)
312  ws = workspace_prev();
313  else if (strcmp(which, "next_on_output") == 0)
315  else if (strcmp(which, "prev_on_output") == 0)
317  else if (strcmp(which, "current") == 0)
319  else {
320  yerror("BUG: called with which=%s", which);
321  return;
322  }
323 
325 
326  cmd_output->needs_tree_render = true;
327  // XXX: default reply for now, make this a better reply
328  ysuccess(true);
329 }
330 
331 /*
332  * Implementation of 'move [window|container] [to] workspace back_and_forth'.
333  *
334  */
337  if (ws == NULL) {
338  yerror("No workspace was previously active.");
339  return;
340  }
341 
343 
345 
346  cmd_output->needs_tree_render = true;
347  // XXX: default reply for now, make this a better reply
348  ysuccess(true);
349 }
350 
351 /*
352  * Implementation of 'move [--no-auto-back-and-forth] [window|container] [to] workspace <name>'.
353  *
354  */
355 void cmd_move_con_to_workspace_name(I3_CMD, const char *name, const char *no_auto_back_and_forth) {
356  if (strncasecmp(name, "__", strlen("__")) == 0) {
357  yerror("You cannot move containers to i3-internal workspaces (\"%s\").", name);
358  return;
359  }
360 
362 
363  LOG("should move window to workspace %s\n", name);
364  /* get the workspace */
365  Con *ws = workspace_get(name, NULL);
366 
367  if (no_auto_back_and_forth == NULL) {
369  }
370 
372 
373  cmd_output->needs_tree_render = true;
374  // XXX: default reply for now, make this a better reply
375  ysuccess(true);
376 }
377 
378 /*
379  * Implementation of 'move [--no-auto-back-and-forth] [window|container] [to] workspace number <name>'.
380  *
381  */
382 void cmd_move_con_to_workspace_number(I3_CMD, const char *which, const char *no_auto_back_and_forth) {
384 
385  LOG("should move window to workspace %s\n", which);
386 
387  long parsed_num = ws_name_to_number(which);
388  if (parsed_num == -1) {
389  LOG("Could not parse initial part of \"%s\" as a number.\n", which);
390  yerror("Could not parse number \"%s\"", which);
391  return;
392  }
393 
394  Con *ws = get_existing_workspace_by_num(parsed_num);
395  if (!ws) {
396  ws = workspace_get(which, NULL);
397  }
398 
399  if (no_auto_back_and_forth == NULL) {
401  }
402 
404 
405  cmd_output->needs_tree_render = true;
406  // XXX: default reply for now, make this a better reply
407  ysuccess(true);
408 }
409 
410 /*
411  * Convert a string direction ("left", "right", etc.) to a direction_t. Assumes
412  * valid direction string.
413  */
414 static direction_t parse_direction(const char *str) {
415  if (strcmp(str, "left") == 0) {
416  return D_LEFT;
417  } else if (strcmp(str, "right") == 0) {
418  return D_RIGHT;
419  } else if (strcmp(str, "up") == 0) {
420  return D_UP;
421  } else if (strcmp(str, "down") == 0) {
422  return D_DOWN;
423  } else {
424  ELOG("Invalid direction. This is a parser bug.\n");
425  assert(false);
426  }
427 }
428 
429 static void cmd_resize_floating(I3_CMD, const char *direction_str, Con *floating_con, int px) {
430  Rect old_rect = floating_con->rect;
431  Con *focused_con = con_descend_focused(floating_con);
432 
433  direction_t direction;
434  if (strcmp(direction_str, "height") == 0) {
435  direction = D_DOWN;
436  } else if (strcmp(direction_str, "width") == 0) {
437  direction = D_RIGHT;
438  } else {
439  direction = parse_direction(direction_str);
440  }
441  orientation_t orientation = orientation_from_direction(direction);
442 
443  /* ensure that resize will take place even if pixel increment is smaller than
444  * height increment or width increment.
445  * fixes #1011 */
446  const i3Window *window = focused_con->window;
447  if (window != NULL) {
448  if (orientation == VERT) {
449  if (px < 0) {
450  px = (-px < window->height_increment) ? -window->height_increment : px;
451  } else {
452  px = (px < window->height_increment) ? window->height_increment : px;
453  }
454  } else {
455  if (px < 0) {
456  px = (-px < window->width_increment) ? -window->width_increment : px;
457  } else {
458  px = (px < window->width_increment) ? window->width_increment : px;
459  }
460  }
461  }
462 
463  if (orientation == VERT) {
464  floating_con->rect.height += px;
465  } else {
466  floating_con->rect.width += px;
467  }
468  floating_check_size(floating_con, orientation == VERT);
469 
470  /* Did we actually resize anything or did the size constraints prevent us?
471  * If we could not resize, exit now to not move the window. */
472  if (rect_equals(old_rect, floating_con->rect)) {
473  return;
474  }
475 
476  if (direction == D_UP) {
477  floating_con->rect.y -= (floating_con->rect.height - old_rect.height);
478  } else if (direction == D_LEFT) {
479  floating_con->rect.x -= (floating_con->rect.width - old_rect.width);
480  }
481 
482  /* If this is a scratchpad window, don't auto center it from now on. */
483  if (floating_con->scratchpad_state == SCRATCHPAD_FRESH) {
484  floating_con->scratchpad_state = SCRATCHPAD_CHANGED;
485  }
486 }
487 
488 static bool cmd_resize_tiling_direction(I3_CMD, Con *current, const char *direction, int px, int ppt) {
489  Con *second = NULL;
490  Con *first = current;
491  direction_t search_direction = parse_direction(direction);
492 
493  bool res = resize_find_tiling_participants(&first, &second, search_direction, false);
494  if (!res) {
495  yerror("No second container found in this direction.");
496  return false;
497  }
498 
499  if (ppt) {
500  /* For backwards compatibility, 'X px or Y ppt' means that ppt is
501  * preferred. */
502  px = 0;
503  }
504  return resize_neighboring_cons(first, second, px, ppt);
505 }
506 
507 static bool cmd_resize_tiling_width_height(I3_CMD, Con *current, const char *direction, int px, double ppt) {
508  LOG("width/height resize\n");
509 
510  /* get the appropriate current container (skip stacked/tabbed cons) */
511  Con *dummy = NULL;
512  direction_t search_direction = (strcmp(direction, "width") == 0 ? D_LEFT : D_DOWN);
513  bool search_result = resize_find_tiling_participants(&current, &dummy, search_direction, true);
514  if (search_result == false) {
515  yerror("Failed to find appropriate tiling containers for resize operation");
516  return false;
517  }
518 
519  /* get the default percentage */
520  int children = con_num_children(current->parent);
521  LOG("ins. %d children\n", children);
522  double percentage = 1.0 / children;
523  LOG("default percentage = %f\n", percentage);
524 
525  /* Ensure all the other children have a percentage set. */
526  Con *child;
527  TAILQ_FOREACH(child, &(current->parent->nodes_head), nodes) {
528  LOG("child->percent = %f (child %p)\n", child->percent, child);
529  if (child->percent == 0.0)
530  child->percent = percentage;
531  }
532 
533  double new_current_percent;
534  double subtract_percent;
535  if (ppt != 0.0) {
536  new_current_percent = current->percent + ppt;
537  } else {
538  /* Convert px change to change in percentages */
539  ppt = (double)px / (double)con_rect_size_in_orientation(current->parent);
540  new_current_percent = current->percent + ppt;
541  }
542  subtract_percent = ppt / (children - 1);
543  if (ppt < 0.0 && new_current_percent < percent_for_1px(current)) {
544  yerror("Not resizing, container would end with less than 1px");
545  return false;
546  }
547 
548  LOG("new_current_percent = %f\n", new_current_percent);
549  LOG("subtract_percent = %f\n", subtract_percent);
550  /* Ensure that the new percentages are positive. */
551  if (subtract_percent >= 0.0) {
552  TAILQ_FOREACH(child, &(current->parent->nodes_head), nodes) {
553  if (child == current) {
554  continue;
555  }
556  if (child->percent - subtract_percent < percent_for_1px(child)) {
557  yerror("Not resizing, already at minimum size (child %p would end up with a size of %.f", child, child->percent - subtract_percent);
558  return false;
559  }
560  }
561  }
562 
563  current->percent = new_current_percent;
564  LOG("current->percent after = %f\n", current->percent);
565 
566  TAILQ_FOREACH(child, &(current->parent->nodes_head), nodes) {
567  if (child == current)
568  continue;
569  child->percent -= subtract_percent;
570  LOG("child->percent after (%p) = %f\n", child, child->percent);
571  }
572 
573  return true;
574 }
575 
576 /*
577  * Implementation of 'resize grow|shrink <direction> [<px> px] [or <ppt> ppt]'.
578  *
579  */
580 void cmd_resize(I3_CMD, const char *way, const char *direction, long resize_px, long resize_ppt) {
581  DLOG("resizing in way %s, direction %s, px %ld or ppt %ld\n", way, direction, resize_px, resize_ppt);
582  if (strcmp(way, "shrink") == 0) {
583  resize_px *= -1;
584  resize_ppt *= -1;
585  }
586 
588 
589  owindow *current;
590  TAILQ_FOREACH(current, &owindows, owindows) {
591  /* Don't handle dock windows (issue #1201) */
592  if (current->con->window && current->con->window->dock) {
593  DLOG("This is a dock window. Not resizing (con = %p)\n)", current->con);
594  continue;
595  }
596 
597  Con *floating_con;
598  if ((floating_con = con_inside_floating(current->con))) {
599  cmd_resize_floating(current_match, cmd_output, direction, floating_con, resize_px);
600  } else {
601  if (strcmp(direction, "width") == 0 ||
602  strcmp(direction, "height") == 0) {
603  const double ppt = (double)resize_ppt / 100.0;
605  current->con, direction,
606  resize_px, ppt)) {
607  yerror("Cannot resize.");
608  return;
609  }
610  } else {
612  current->con, direction,
613  resize_px, resize_ppt)) {
614  yerror("Cannot resize.");
615  return;
616  }
617  }
618  }
619  }
620 
621  cmd_output->needs_tree_render = true;
622  // XXX: default reply for now, make this a better reply
623  ysuccess(true);
624 }
625 
626 static bool resize_set_tiling(I3_CMD, Con *target, orientation_t resize_orientation, bool is_ppt, long target_size) {
627  direction_t search_direction;
628  char *mode;
629  if (resize_orientation == HORIZ) {
630  search_direction = D_LEFT;
631  mode = "width";
632  } else {
633  search_direction = D_DOWN;
634  mode = "height";
635  }
636 
637  /* Get the appropriate current container (skip stacked/tabbed cons) */
638  Con *dummy;
639  resize_find_tiling_participants(&target, &dummy, search_direction, true);
640 
641  /* Calculate new size for the target container */
642  double ppt = 0.0;
643  int px = 0;
644  if (is_ppt) {
645  ppt = (double)target_size / 100.0 - target->percent;
646  } else {
647  px = target_size - (resize_orientation == HORIZ ? target->rect.width : target->rect.height);
648  }
649 
650  /* Perform resizing and report failure if not possible */
652  target, mode, px, ppt);
653 }
654 
655 /*
656  * Implementation of 'resize set <width> [px | ppt] <height> [px | ppt]'.
657  *
658  */
659 void cmd_resize_set(I3_CMD, long cwidth, const char *mode_width, long cheight, const char *mode_height) {
660  DLOG("resizing to %ld %s x %ld %s\n", cwidth, mode_width, cheight, mode_height);
661  if (cwidth < 0 || cheight < 0) {
662  yerror("Dimensions cannot be negative.");
663  return;
664  }
665 
667 
668  owindow *current;
669  bool success = true;
670  TAILQ_FOREACH(current, &owindows, owindows) {
671  Con *floating_con;
672  if ((floating_con = con_inside_floating(current->con))) {
673  Con *output = con_get_output(floating_con);
674  if (cwidth == 0) {
675  cwidth = floating_con->rect.width;
676  } else if (mode_width && strcmp(mode_width, "ppt") == 0) {
677  cwidth = output->rect.width * ((double)cwidth / 100.0);
678  }
679  if (cheight == 0) {
680  cheight = floating_con->rect.height;
681  } else if (mode_height && strcmp(mode_height, "ppt") == 0) {
682  cheight = output->rect.height * ((double)cheight / 100.0);
683  }
684  floating_resize(floating_con, cwidth, cheight);
685  } else {
686  if (current->con->window && current->con->window->dock) {
687  DLOG("This is a dock window. Not resizing (con = %p)\n)", current->con);
688  continue;
689  }
690 
691  if (cwidth > 0) {
692  bool is_ppt = mode_width && strcmp(mode_width, "ppt") == 0;
693  success &= resize_set_tiling(current_match, cmd_output, current->con,
694  HORIZ, is_ppt, cwidth);
695  }
696  if (cheight > 0) {
697  bool is_ppt = mode_height && strcmp(mode_height, "ppt") == 0;
698  success &= resize_set_tiling(current_match, cmd_output, current->con,
699  VERT, is_ppt, cheight);
700  }
701  }
702  }
703 
704  cmd_output->needs_tree_render = true;
705  ysuccess(success);
706 }
707 
708 static int border_width_from_style(border_style_t border_style, long border_width, Con *con) {
709  if (border_style == BS_NONE) {
710  return 0;
711  }
712  if (border_width >= 0) {
713  return logical_px(border_width);
714  }
715 
716  const bool is_floating = con_inside_floating(con) != NULL;
717  /* Load the configured defaults. */
718  if (is_floating && border_style == config.default_floating_border) {
720  } else if (!is_floating && border_style == config.default_border) {
722  } else {
723  /* Use some hardcoded values. */
724  return logical_px(border_style == BS_NORMAL ? 2 : 1);
725  }
726 }
727 
728 /*
729  * Implementation of 'border normal|pixel [<n>]', 'border none|1pixel|toggle'.
730  *
731  */
732 void cmd_border(I3_CMD, const char *border_style_str, long border_width) {
733  DLOG("border style should be changed to %s with border width %ld\n", border_style_str, border_width);
734  owindow *current;
735 
737 
738  TAILQ_FOREACH(current, &owindows, owindows) {
739  DLOG("matching: %p / %s\n", current->con, current->con->name);
740 
741  border_style_t border_style;
742  if (strcmp(border_style_str, "toggle") == 0) {
743  border_style = (current->con->border_style + 1) % 3;
744  } else if (strcmp(border_style_str, "normal") == 0) {
745  border_style = BS_NORMAL;
746  } else if (strcmp(border_style_str, "pixel") == 0) {
747  border_style = BS_PIXEL;
748  } else if (strcmp(border_style_str, "none") == 0) {
749  border_style = BS_NONE;
750  } else {
751  yerror("BUG: called with border_style=%s", border_style_str);
752  return;
753  }
754 
755  const int con_border_width = border_width_from_style(border_style, border_width, current->con);
756  con_set_border_style(current->con, border_style, con_border_width);
757  }
758 
759  cmd_output->needs_tree_render = true;
760  ysuccess(true);
761 }
762 
763 /*
764  * Implementation of 'nop <comment>'.
765  *
766  */
767 void cmd_nop(I3_CMD, const char *comment) {
768  LOG("-------------------------------------------------\n");
769  LOG(" NOP: %s\n", comment);
770  LOG("-------------------------------------------------\n");
771  ysuccess(true);
772 }
773 
774 /*
775  * Implementation of 'append_layout <path>'.
776  *
777  */
778 void cmd_append_layout(I3_CMD, const char *cpath) {
779  LOG("Appending layout \"%s\"\n", cpath);
780 
781  /* Make sure we allow paths like '~/.i3/layout.json' */
782  char *path = resolve_tilde(cpath);
783 
784  char *buf = NULL;
785  ssize_t len;
786  if ((len = slurp(path, &buf)) < 0) {
787  yerror("Could not slurp \"%s\".", path);
788  /* slurp already logged an error. */
789  goto out;
790  }
791 
792  if (!json_validate(buf, len)) {
793  ELOG("Could not parse \"%s\" as JSON, not loading.\n", path);
794  yerror("Could not parse \"%s\" as JSON.", path);
795  goto out;
796  }
797 
798  json_content_t content = json_determine_content(buf, len);
799  LOG("JSON content = %d\n", content);
800  if (content == JSON_CONTENT_UNKNOWN) {
801  ELOG("Could not determine the contents of \"%s\", not loading.\n", path);
802  yerror("Could not determine the contents of \"%s\".", path);
803  goto out;
804  }
805 
806  Con *parent = focused;
807  if (content == JSON_CONTENT_WORKSPACE) {
808  parent = output_get_content(con_get_output(parent));
809  } else {
810  /* We need to append the layout to a split container, since a leaf
811  * container must not have any children (by definition).
812  * Note that we explicitly check for workspaces, since they are okay for
813  * this purpose, but con_accepts_window() returns false for workspaces. */
814  while (parent->type != CT_WORKSPACE && !con_accepts_window(parent))
815  parent = parent->parent;
816  }
817  DLOG("Appending to parent=%p instead of focused=%p\n", parent, focused);
818  char *errormsg = NULL;
819  tree_append_json(parent, buf, len, &errormsg);
820  if (errormsg != NULL) {
821  yerror(errormsg);
822  free(errormsg);
823  /* Note that we continue executing since tree_append_json() has
824  * side-effects — user-provided layouts can be partly valid, partly
825  * invalid, leading to half of the placeholder containers being
826  * created. */
827  } else {
828  ysuccess(true);
829  }
830 
831  // XXX: This is a bit of a kludge. Theoretically, render_con(parent,
832  // false); should be enough, but when sending 'workspace 4; append_layout
833  // /tmp/foo.json', the needs_tree_render == true of the workspace command
834  // is not executed yet and will be batched with append_layout’s
835  // needs_tree_render after the parser finished. We should check if that is
836  // necessary at all.
837  render_con(croot, false);
838 
840 
841  if (content == JSON_CONTENT_WORKSPACE)
842  ipc_send_workspace_event("restored", parent, NULL);
843 
844  cmd_output->needs_tree_render = true;
845 out:
846  free(path);
847  free(buf);
848 }
849 
850 /*
851  * Implementation of 'workspace next|prev|next_on_output|prev_on_output'.
852  *
853  */
854 void cmd_workspace(I3_CMD, const char *which) {
855  Con *ws;
856 
857  DLOG("which=%s\n", which);
858 
860  yerror("Cannot switch workspace while in global fullscreen");
861  return;
862  }
863 
864  if (strcmp(which, "next") == 0)
865  ws = workspace_next();
866  else if (strcmp(which, "prev") == 0)
867  ws = workspace_prev();
868  else if (strcmp(which, "next_on_output") == 0)
870  else if (strcmp(which, "prev_on_output") == 0)
872  else {
873  yerror("BUG: called with which=%s", which);
874  return;
875  }
876 
877  workspace_show(ws);
878 
879  cmd_output->needs_tree_render = true;
880  // XXX: default reply for now, make this a better reply
881  ysuccess(true);
882 }
883 
884 /*
885  * Implementation of 'workspace [--no-auto-back-and-forth] number <name>'
886  *
887  */
888 void cmd_workspace_number(I3_CMD, const char *which, const char *_no_auto_back_and_forth) {
889  const bool no_auto_back_and_forth = (_no_auto_back_and_forth != NULL);
890 
892  yerror("Cannot switch workspace while in global fullscreen");
893  return;
894  }
895 
896  long parsed_num = ws_name_to_number(which);
897  if (parsed_num == -1) {
898  yerror("Could not parse initial part of \"%s\" as a number.", which);
899  return;
900  }
901 
902  Con *workspace = get_existing_workspace_by_num(parsed_num);
903  if (!workspace) {
904  LOG("There is no workspace with number %ld, creating a new one.\n", parsed_num);
905  ysuccess(true);
906  workspace_show_by_name(which);
907  cmd_output->needs_tree_render = true;
908  return;
909  }
910  if (!no_auto_back_and_forth && maybe_back_and_forth(cmd_output, workspace->name)) {
911  ysuccess(true);
912  return;
913  }
914  workspace_show(workspace);
915 
916  cmd_output->needs_tree_render = true;
917  // XXX: default reply for now, make this a better reply
918  ysuccess(true);
919 }
920 
921 /*
922  * Implementation of 'workspace back_and_forth'.
923  *
924  */
927  yerror("Cannot switch workspace while in global fullscreen");
928  return;
929  }
930 
932 
933  cmd_output->needs_tree_render = true;
934  // XXX: default reply for now, make this a better reply
935  ysuccess(true);
936 }
937 
938 /*
939  * Implementation of 'workspace [--no-auto-back-and-forth] <name>'
940  *
941  */
942 void cmd_workspace_name(I3_CMD, const char *name, const char *_no_auto_back_and_forth) {
943  const bool no_auto_back_and_forth = (_no_auto_back_and_forth != NULL);
944 
945  if (strncasecmp(name, "__", strlen("__")) == 0) {
946  yerror("You cannot switch to the i3-internal workspaces (\"%s\").", name);
947  return;
948  }
949 
951  yerror("Cannot switch workspace while in global fullscreen");
952  return;
953  }
954 
955  DLOG("should switch to workspace %s\n", name);
956  if (!no_auto_back_and_forth && maybe_back_and_forth(cmd_output, name)) {
957  ysuccess(true);
958  return;
959  }
961 
962  cmd_output->needs_tree_render = true;
963  // XXX: default reply for now, make this a better reply
964  ysuccess(true);
965 }
966 
967 /*
968  * Implementation of 'mark [--add|--replace] [--toggle] <mark>'
969  *
970  */
971 void cmd_mark(I3_CMD, const char *mark, const char *mode, const char *toggle) {
973 
974  owindow *current = TAILQ_FIRST(&owindows);
975  if (current == NULL) {
976  yerror("Given criteria don't match a window");
977  return;
978  }
979 
980  /* Marks must be unique, i.e., no two windows must have the same mark. */
981  if (current != TAILQ_LAST(&owindows, owindows_head)) {
982  yerror("A mark must not be put onto more than one window");
983  return;
984  }
985 
986  DLOG("matching: %p / %s\n", current->con, current->con->name);
987 
988  mark_mode_t mark_mode = (mode == NULL || strcmp(mode, "--replace") == 0) ? MM_REPLACE : MM_ADD;
989  if (toggle != NULL) {
990  con_mark_toggle(current->con, mark, mark_mode);
991  } else {
992  con_mark(current->con, mark, mark_mode);
993  }
994 
995  cmd_output->needs_tree_render = true;
996  // XXX: default reply for now, make this a better reply
997  ysuccess(true);
998 }
999 
1000 /*
1001  * Implementation of 'unmark [mark]'
1002  *
1003  */
1004 void cmd_unmark(I3_CMD, const char *mark) {
1006  con_unmark(NULL, mark);
1007  } else {
1008  owindow *current;
1009  TAILQ_FOREACH(current, &owindows, owindows) {
1010  con_unmark(current->con, mark);
1011  }
1012  }
1013 
1014  cmd_output->needs_tree_render = true;
1015  // XXX: default reply for now, make this a better reply
1016  ysuccess(true);
1017 }
1018 
1019 /*
1020  * Implementation of 'mode <string>'.
1021  *
1022  */
1023 void cmd_mode(I3_CMD, const char *mode) {
1024  DLOG("mode=%s\n", mode);
1025  switch_mode(mode);
1026 
1027  // XXX: default reply for now, make this a better reply
1028  ysuccess(true);
1029 }
1030 
1031 /*
1032  * Implementation of 'move [window|container] [to] output <str>'.
1033  *
1034  */
1035 void cmd_move_con_to_output(I3_CMD, const char *name) {
1036  DLOG("Should move window to output \"%s\".\n", name);
1038 
1039  owindow *current;
1040  bool had_error = false;
1041  TAILQ_FOREACH(current, &owindows, owindows) {
1042  DLOG("matching: %p / %s\n", current->con, current->con->name);
1043 
1044  had_error |= !con_move_to_output_name(current->con, name, true);
1045  }
1046 
1047  cmd_output->needs_tree_render = true;
1048  ysuccess(!had_error);
1049 }
1050 
1051 /*
1052  * Implementation of 'move [container|window] [to] mark <str>'.
1053  *
1054  */
1055 void cmd_move_con_to_mark(I3_CMD, const char *mark) {
1056  DLOG("moving window to mark \"%s\"\n", mark);
1057 
1059 
1060  bool result = true;
1061  owindow *current;
1062  TAILQ_FOREACH(current, &owindows, owindows) {
1063  DLOG("moving matched window %p / %s to mark \"%s\"\n", current->con, current->con->name, mark);
1064  result &= con_move_to_mark(current->con, mark);
1065  }
1066 
1067  cmd_output->needs_tree_render = true;
1068  ysuccess(result);
1069 }
1070 
1071 /*
1072  * Implementation of 'floating enable|disable|toggle'
1073  *
1074  */
1075 void cmd_floating(I3_CMD, const char *floating_mode) {
1076  owindow *current;
1077 
1078  DLOG("floating_mode=%s\n", floating_mode);
1079 
1081 
1082  TAILQ_FOREACH(current, &owindows, owindows) {
1083  DLOG("matching: %p / %s\n", current->con, current->con->name);
1084  if (strcmp(floating_mode, "toggle") == 0) {
1085  DLOG("should toggle mode\n");
1086  toggle_floating_mode(current->con, false);
1087  } else {
1088  DLOG("should switch mode to %s\n", floating_mode);
1089  if (strcmp(floating_mode, "enable") == 0) {
1090  floating_enable(current->con, false);
1091  } else {
1092  floating_disable(current->con);
1093  }
1094  }
1095  }
1096 
1097  cmd_output->needs_tree_render = true;
1098  // XXX: default reply for now, make this a better reply
1099  ysuccess(true);
1100 }
1101 
1102 /*
1103  * Implementation of 'move workspace to [output] <str>'.
1104  *
1105  */
1106 void cmd_move_workspace_to_output(I3_CMD, const char *name) {
1107  DLOG("should move workspace to output %s\n", name);
1108 
1110 
1111  owindow *current;
1112  TAILQ_FOREACH(current, &owindows, owindows) {
1113  Con *ws = con_get_workspace(current->con);
1114  if (con_is_internal(ws)) {
1115  continue;
1116  }
1117 
1118  Output *current_output = get_output_for_con(ws);
1119  Output *target_output = get_output_from_string(current_output, name);
1120  if (!target_output) {
1121  yerror("Could not get output from string \"%s\"", name);
1122  return;
1123  }
1124 
1125  workspace_move_to_output(ws, target_output);
1126  }
1127 
1128  cmd_output->needs_tree_render = true;
1129  ysuccess(true);
1130 }
1131 
1132 /*
1133  * Implementation of 'split v|h|t|vertical|horizontal|toggle'.
1134  *
1135  */
1136 void cmd_split(I3_CMD, const char *direction) {
1138 
1139  owindow *current;
1140  LOG("splitting in direction %c\n", direction[0]);
1141  TAILQ_FOREACH(current, &owindows, owindows) {
1142  if (con_is_docked(current->con)) {
1143  ELOG("Cannot split a docked container, skipping.\n");
1144  continue;
1145  }
1146 
1147  DLOG("matching: %p / %s\n", current->con, current->con->name);
1148  if (direction[0] == 't') {
1149  layout_t current_layout;
1150  if (current->con->type == CT_WORKSPACE) {
1151  current_layout = current->con->layout;
1152  } else {
1153  current_layout = current->con->parent->layout;
1154  }
1155  /* toggling split orientation */
1156  if (current_layout == L_SPLITH) {
1157  tree_split(current->con, VERT);
1158  } else {
1159  tree_split(current->con, HORIZ);
1160  }
1161  } else {
1162  tree_split(current->con, (direction[0] == 'v' ? VERT : HORIZ));
1163  }
1164  }
1165 
1166  cmd_output->needs_tree_render = true;
1167  // XXX: default reply for now, make this a better reply
1168  ysuccess(true);
1169 }
1170 
1171 /*
1172  * Implementation of 'kill [window|client]'.
1173  *
1174  */
1175 void cmd_kill(I3_CMD, const char *kill_mode_str) {
1176  if (kill_mode_str == NULL)
1177  kill_mode_str = "window";
1178 
1179  DLOG("kill_mode=%s\n", kill_mode_str);
1180 
1181  int kill_mode;
1182  if (strcmp(kill_mode_str, "window") == 0)
1183  kill_mode = KILL_WINDOW;
1184  else if (strcmp(kill_mode_str, "client") == 0)
1185  kill_mode = KILL_CLIENT;
1186  else {
1187  yerror("BUG: called with kill_mode=%s", kill_mode_str);
1188  return;
1189  }
1190 
1192 
1193  owindow *current;
1194  TAILQ_FOREACH(current, &owindows, owindows) {
1195  con_close(current->con, kill_mode);
1196  }
1197 
1198  cmd_output->needs_tree_render = true;
1199  // XXX: default reply for now, make this a better reply
1200  ysuccess(true);
1201 }
1202 
1203 /*
1204  * Implementation of 'exec [--no-startup-id] <command>'.
1205  *
1206  */
1207 void cmd_exec(I3_CMD, const char *nosn, const char *command) {
1208  bool no_startup_id = (nosn != NULL);
1209 
1211 
1212  int count = 0;
1213  owindow *current;
1214  TAILQ_FOREACH(current, &owindows, owindows) {
1215  count++;
1216  }
1217 
1218  if (count > 1) {
1219  LOG("WARNING: Your criteria for the exec command match %d containers, "
1220  "so the command will execute this many times.\n",
1221  count);
1222  }
1223 
1224  TAILQ_FOREACH(current, &owindows, owindows) {
1225  DLOG("should execute %s, no_startup_id = %d\n", command, no_startup_id);
1226  start_application(command, no_startup_id);
1227  }
1228 
1229  ysuccess(true);
1230 }
1231 
1232 #define CMD_FOCUS_WARN_CHILDREN \
1233  do { \
1234  int count = 0; \
1235  owindow *current; \
1236  TAILQ_FOREACH(current, &owindows, owindows) { \
1237  count++; \
1238  } \
1239  \
1240  if (count > 1) { \
1241  LOG("WARNING: Your criteria for the focus command matches %d containers, " \
1242  "while only exactly one container can be focused at a time.\n", \
1243  count); \
1244  } \
1245  } while (0)
1246 
1247 /*
1248  * Implementation of 'focus left|right|up|down|next|prev'.
1249  *
1250  */
1251 void cmd_focus_direction(I3_CMD, const char *direction_str) {
1254 
1255  direction_t direction;
1256  position_t position;
1257  bool auto_direction = true;
1258  if (strcmp(direction_str, "prev") == 0) {
1259  position = BEFORE;
1260  } else if (strcmp(direction_str, "next") == 0) {
1261  position = AFTER;
1262  } else {
1263  auto_direction = false;
1264  direction = parse_direction(direction_str);
1265  }
1266 
1267  owindow *current;
1268  TAILQ_FOREACH(current, &owindows, owindows) {
1269  Con *ws = con_get_workspace(current->con);
1270  if (!ws || con_is_internal(ws)) {
1271  continue;
1272  }
1273  if (auto_direction) {
1274  orientation_t o = con_orientation(current->con->parent);
1275  direction = direction_from_orientation_position(o, position);
1276  }
1277  tree_next(current->con, direction);
1278  }
1279 
1280  cmd_output->needs_tree_render = true;
1281  // XXX: default reply for now, make this a better reply
1282  ysuccess(true);
1283 }
1284 
1285 /*
1286  * Implementation of 'focus next|prev sibling'
1287  *
1288  */
1289 void cmd_focus_sibling(I3_CMD, const char *direction_str) {
1292 
1293  const position_t direction = (STARTS_WITH(direction_str, "prev")) ? BEFORE : AFTER;
1294  owindow *current;
1295  TAILQ_FOREACH(current, &owindows, owindows) {
1296  Con *ws = con_get_workspace(current->con);
1297  if (!ws || con_is_internal(ws)) {
1298  continue;
1299  }
1300  Con *next = get_tree_next_sibling(current->con, direction);
1301  if (next) {
1302  if (next->type == CT_WORKSPACE) {
1303  /* On the workspace level, we need to make sure that the
1304  * workspace change happens properly. However, workspace_show
1305  * descends focus so we also have to put focus on the workspace
1306  * itself to maintain consistency. See #3997. */
1307  workspace_show(next);
1308  con_focus(next);
1309  } else {
1310  con_activate(next);
1311  }
1312  }
1313  }
1314 
1315  cmd_output->needs_tree_render = true;
1316  // XXX: default reply for now, make this a better reply
1317  ysuccess(true);
1318 }
1319 
1320 /*
1321  * Implementation of 'focus tiling|floating|mode_toggle'.
1322  *
1323  */
1324 void cmd_focus_window_mode(I3_CMD, const char *window_mode) {
1325  DLOG("window_mode = %s\n", window_mode);
1326 
1327  bool to_floating = false;
1328  if (strcmp(window_mode, "mode_toggle") == 0) {
1329  to_floating = !con_inside_floating(focused);
1330  } else if (strcmp(window_mode, "floating") == 0) {
1331  to_floating = true;
1332  } else if (strcmp(window_mode, "tiling") == 0) {
1333  to_floating = false;
1334  }
1335 
1336  Con *ws = con_get_workspace(focused);
1337  Con *current;
1338  bool success = false;
1339  TAILQ_FOREACH(current, &(ws->focus_head), focused) {
1340  if ((to_floating && current->type != CT_FLOATING_CON) ||
1341  (!to_floating && current->type == CT_FLOATING_CON))
1342  continue;
1343 
1345  success = true;
1346  break;
1347  }
1348 
1349  if (success) {
1350  cmd_output->needs_tree_render = true;
1351  ysuccess(true);
1352  } else {
1353  yerror("Failed to find a %s container in workspace.", to_floating ? "floating" : "tiling");
1354  }
1355 }
1356 
1357 /*
1358  * Implementation of 'focus parent|child'.
1359  *
1360  */
1361 void cmd_focus_level(I3_CMD, const char *level) {
1362  DLOG("level = %s\n", level);
1363  bool success = false;
1364 
1365  /* Focusing the parent can only be allowed if the newly
1366  * focused container won't escape the fullscreen container. */
1367  if (strcmp(level, "parent") == 0) {
1368  if (focused && focused->parent) {
1370  success = level_up();
1371  else
1372  ELOG("'focus parent': Currently in fullscreen, not going up\n");
1373  }
1374  }
1375 
1376  /* Focusing a child should always be allowed. */
1377  else
1378  success = level_down();
1379 
1380  cmd_output->needs_tree_render = success;
1381  // XXX: default reply for now, make this a better reply
1382  ysuccess(success);
1383 }
1384 
1385 /*
1386  * Implementation of 'focus'.
1387  *
1388  */
1390  DLOG("current_match = %p\n", current_match);
1391 
1393  ELOG("You have to specify which window/container should be focused.\n");
1394  ELOG("Example: [class=\"urxvt\" title=\"irssi\"] focus\n");
1395 
1396  yerror("You have to specify which window/container should be focused");
1397  return;
1398  } else if (TAILQ_EMPTY(&owindows)) {
1399  yerror("No window matches given criteria");
1400  return;
1401  }
1402 
1404 
1405  Con *__i3_scratch = workspace_get("__i3_scratch", NULL);
1406  owindow *current;
1407  TAILQ_FOREACH(current, &owindows, owindows) {
1408  Con *ws = con_get_workspace(current->con);
1409  /* If no workspace could be found, this was a dock window.
1410  * Just skip it, you cannot focus dock windows. */
1411  if (!ws)
1412  continue;
1413 
1414  /* In case this is a scratchpad window, call scratchpad_show(). */
1415  if (ws == __i3_scratch) {
1416  scratchpad_show(current->con);
1417  /* While for the normal focus case we can change focus multiple
1418  * times and only a single window ends up focused, we could show
1419  * multiple scratchpad windows. So, rather break here. */
1420  break;
1421  }
1422 
1423  LOG("focusing %p / %s\n", current->con, current->con->name);
1424  con_activate_unblock(current->con);
1425  }
1426 
1427  cmd_output->needs_tree_render = true;
1428  ysuccess(true);
1429 }
1430 
1431 /*
1432  * Implementation of 'fullscreen enable|toggle [global]' and
1433  * 'fullscreen disable'
1434  *
1435  */
1436 void cmd_fullscreen(I3_CMD, const char *action, const char *fullscreen_mode) {
1437  fullscreen_mode_t mode = strcmp(fullscreen_mode, "global") == 0 ? CF_GLOBAL : CF_OUTPUT;
1438  DLOG("%s fullscreen, mode = %s\n", action, fullscreen_mode);
1439  owindow *current;
1440 
1442 
1443  TAILQ_FOREACH(current, &owindows, owindows) {
1444  DLOG("matching: %p / %s\n", current->con, current->con->name);
1445  if (strcmp(action, "toggle") == 0) {
1446  con_toggle_fullscreen(current->con, mode);
1447  } else if (strcmp(action, "enable") == 0) {
1448  con_enable_fullscreen(current->con, mode);
1449  } else if (strcmp(action, "disable") == 0) {
1450  con_disable_fullscreen(current->con);
1451  }
1452  }
1453 
1454  cmd_output->needs_tree_render = true;
1455  // XXX: default reply for now, make this a better reply
1456  ysuccess(true);
1457 }
1458 
1459 /*
1460  * Implementation of 'sticky enable|disable|toggle'.
1461  *
1462  */
1463 void cmd_sticky(I3_CMD, const char *action) {
1464  DLOG("%s sticky on window\n", action);
1466 
1467  owindow *current;
1468  TAILQ_FOREACH(current, &owindows, owindows) {
1469  if (current->con->window == NULL) {
1470  ELOG("only containers holding a window can be made sticky, skipping con = %p\n", current->con);
1471  continue;
1472  }
1473  DLOG("setting sticky for container = %p / %s\n", current->con, current->con->name);
1474 
1475  bool sticky = false;
1476  if (strcmp(action, "enable") == 0)
1477  sticky = true;
1478  else if (strcmp(action, "disable") == 0)
1479  sticky = false;
1480  else if (strcmp(action, "toggle") == 0)
1481  sticky = !current->con->sticky;
1482 
1483  current->con->sticky = sticky;
1484  ewmh_update_sticky(current->con->window->id, sticky);
1485  }
1486 
1487  /* A window we made sticky might not be on a visible workspace right now, so we need to make
1488  * sure it gets pushed to the front now. */
1490 
1492 
1493  cmd_output->needs_tree_render = true;
1494  ysuccess(true);
1495 }
1496 
1497 /*
1498  * Implementation of 'move <direction> [<pixels> [px]]'.
1499  *
1500  */
1501 void cmd_move_direction(I3_CMD, const char *direction_str, long move_px) {
1502  owindow *current;
1504 
1505  Con *initially_focused = focused;
1506  direction_t direction = parse_direction(direction_str);
1507 
1508  TAILQ_FOREACH(current, &owindows, owindows) {
1509  DLOG("moving in direction %s, px %ld\n", direction_str, move_px);
1510  if (con_is_floating(current->con)) {
1511  DLOG("floating move with %ld pixels\n", move_px);
1512  Rect newrect = current->con->parent->rect;
1513 
1514  switch (direction) {
1515  case D_LEFT:
1516  newrect.x -= move_px;
1517  break;
1518  case D_RIGHT:
1519  newrect.x += move_px;
1520  break;
1521  case D_UP:
1522  newrect.y -= move_px;
1523  break;
1524  case D_DOWN:
1525  newrect.y += move_px;
1526  break;
1527  }
1528 
1529  cmd_output->needs_tree_render = floating_reposition(current->con->parent, newrect);
1530  } else {
1531  tree_move(current->con, direction);
1532  cmd_output->needs_tree_render = true;
1533  }
1534  }
1535 
1536  /* The move command should not disturb focus. con_exists is called because
1537  * tree_move calls tree_flatten. */
1538  if (focused != initially_focused && con_exists(initially_focused)) {
1539  con_activate(initially_focused);
1540  }
1541 
1542  // XXX: default reply for now, make this a better reply
1543  ysuccess(true);
1544 }
1545 
1546 /*
1547  * Implementation of 'layout default|stacked|stacking|tabbed|splitv|splith'.
1548  *
1549  */
1550 void cmd_layout(I3_CMD, const char *layout_str) {
1552 
1553  layout_t layout;
1554  if (!layout_from_name(layout_str, &layout)) {
1555  yerror("Unknown layout \"%s\", this is a mismatch between code and parser spec.", layout_str);
1556  return;
1557  }
1558 
1559  DLOG("changing layout to %s (%d)\n", layout_str, layout);
1560 
1561  owindow *current;
1562  TAILQ_FOREACH(current, &owindows, owindows) {
1563  if (con_is_docked(current->con)) {
1564  ELOG("cannot change layout of a docked container, skipping it.\n");
1565  continue;
1566  }
1567 
1568  DLOG("matching: %p / %s\n", current->con, current->con->name);
1569  con_set_layout(current->con, layout);
1570  }
1571 
1572  cmd_output->needs_tree_render = true;
1573  // XXX: default reply for now, make this a better reply
1574  ysuccess(true);
1575 }
1576 
1577 /*
1578  * Implementation of 'layout toggle [all|split]'.
1579  *
1580  */
1581 void cmd_layout_toggle(I3_CMD, const char *toggle_mode) {
1582  owindow *current;
1583 
1584  if (toggle_mode == NULL)
1585  toggle_mode = "default";
1586 
1587  DLOG("toggling layout (mode = %s)\n", toggle_mode);
1588 
1589  /* check if the match is empty, not if the result is empty */
1591  con_toggle_layout(focused, toggle_mode);
1592  else {
1593  TAILQ_FOREACH(current, &owindows, owindows) {
1594  DLOG("matching: %p / %s\n", current->con, current->con->name);
1595  con_toggle_layout(current->con, toggle_mode);
1596  }
1597  }
1598 
1599  cmd_output->needs_tree_render = true;
1600  // XXX: default reply for now, make this a better reply
1601  ysuccess(true);
1602 }
1603 
1604 /*
1605  * Implementation of 'exit'.
1606  *
1607  */
1609  LOG("Exiting due to user command.\n");
1610  exit(EXIT_SUCCESS);
1611 
1612  /* unreached */
1613 }
1614 
1615 /*
1616  * Implementation of 'reload'.
1617  *
1618  */
1620  LOG("reloading\n");
1624  x_set_i3_atoms();
1625  /* Send an IPC event just in case the ws names have changed */
1626  ipc_send_workspace_event("reload", NULL, NULL);
1627  /* Send an update event for the barconfig just in case it has changed */
1628  update_barconfig();
1629 
1630  // XXX: default reply for now, make this a better reply
1631  ysuccess(true);
1632 }
1633 
1634 /*
1635  * Implementation of 'restart'.
1636  *
1637  */
1639  LOG("restarting i3\n");
1640  int exempt_fd = -1;
1641  if (cmd_output->client != NULL) {
1642  exempt_fd = cmd_output->client->fd;
1643  LOG("Carrying file descriptor %d across restart\n", exempt_fd);
1644  int flags;
1645  if ((flags = fcntl(exempt_fd, F_GETFD)) < 0 ||
1646  fcntl(exempt_fd, F_SETFD, flags & ~FD_CLOEXEC) < 0) {
1647  ELOG("Could not disable FD_CLOEXEC on fd %d\n", exempt_fd);
1648  }
1649  char *fdstr = NULL;
1650  sasprintf(&fdstr, "%d", exempt_fd);
1651  setenv("_I3_RESTART_FD", fdstr, 1);
1652  }
1654  unlink(config.ipc_socket_path);
1655  /* We need to call this manually since atexit handlers don’t get called
1656  * when exec()ing */
1658  i3_restart(false);
1659  /* unreached */
1660  assert(false);
1661 }
1662 
1663 /*
1664  * Implementation of 'open'.
1665  *
1666  */
1668  LOG("opening new container\n");
1669  Con *con = tree_open_con(NULL, NULL);
1670  con->layout = L_SPLITH;
1671  con_activate(con);
1672 
1673  y(map_open);
1674  ystr("success");
1675  y(bool, true);
1676  ystr("id");
1677  y(integer, (uintptr_t)con);
1678  y(map_close);
1679 
1680  cmd_output->needs_tree_render = true;
1681 }
1682 
1683 /*
1684  * Implementation of 'focus output <output>'.
1685  *
1686  */
1687 void cmd_focus_output(I3_CMD, const char *name) {
1689 
1690  if (TAILQ_EMPTY(&owindows)) {
1691  ysuccess(true);
1692  return;
1693  }
1694 
1695  Output *current_output = get_output_for_con(TAILQ_FIRST(&owindows)->con);
1696  Output *output = get_output_from_string(current_output, name);
1697 
1698  if (!output) {
1699  yerror("Output %s not found.", name);
1700  return;
1701  }
1702 
1703  /* get visible workspace on output */
1704  Con *ws = NULL;
1705  GREP_FIRST(ws, output_get_content(output->con), workspace_is_visible(child));
1706  if (!ws) {
1707  yerror("BUG: No workspace found on output.");
1708  return;
1709  }
1710 
1711  workspace_show(ws);
1712 
1713  cmd_output->needs_tree_render = true;
1714  ysuccess(true);
1715 }
1716 
1717 /*
1718  * Implementation of 'move [window|container] [to] [absolute] position <px> [px] <px> [px]
1719  *
1720  */
1721 void cmd_move_window_to_position(I3_CMD, long x, long y) {
1722  bool has_error = false;
1723 
1724  owindow *current;
1726 
1727  TAILQ_FOREACH(current, &owindows, owindows) {
1728  if (!con_is_floating(current->con)) {
1729  ELOG("Cannot change position. The window/container is not floating\n");
1730 
1731  if (!has_error) {
1732  yerror("Cannot change position of a window/container because it is not floating.");
1733  has_error = true;
1734  }
1735 
1736  continue;
1737  }
1738 
1739  Rect newrect = current->con->parent->rect;
1740 
1741  DLOG("moving to position %ld %ld\n", x, y);
1742  newrect.x = x;
1743  newrect.y = y;
1744 
1745  if (!floating_reposition(current->con->parent, newrect)) {
1746  yerror("Cannot move window/container out of bounds.");
1747  has_error = true;
1748  }
1749  }
1750 
1751  if (!has_error)
1752  ysuccess(true);
1753 }
1754 
1755 /*
1756  * Implementation of 'move [window|container] [to] [absolute] position center
1757  *
1758  */
1759 void cmd_move_window_to_center(I3_CMD, const char *method) {
1760  bool has_error = false;
1762 
1763  owindow *current;
1764  TAILQ_FOREACH(current, &owindows, owindows) {
1765  Con *floating_con = con_inside_floating(current->con);
1766  if (floating_con == NULL) {
1767  ELOG("con %p / %s is not floating, cannot move it to the center.\n",
1768  current->con, current->con->name);
1769 
1770  if (!has_error) {
1771  yerror("Cannot change position of a window/container because it is not floating.");
1772  has_error = true;
1773  }
1774 
1775  continue;
1776  }
1777 
1778  if (strcmp(method, "absolute") == 0) {
1779  DLOG("moving to absolute center\n");
1780  floating_center(floating_con, croot->rect);
1781 
1782  floating_maybe_reassign_ws(floating_con);
1783  cmd_output->needs_tree_render = true;
1784  }
1785 
1786  if (strcmp(method, "position") == 0) {
1787  DLOG("moving to center\n");
1788  floating_center(floating_con, con_get_workspace(floating_con)->rect);
1789 
1790  cmd_output->needs_tree_render = true;
1791  }
1792  }
1793 
1794  // XXX: default reply for now, make this a better reply
1795  if (!has_error)
1796  ysuccess(true);
1797 }
1798 
1799 /*
1800  * Implementation of 'move [window|container] [to] position mouse'
1801  *
1802  */
1805 
1806  owindow *current;
1807  TAILQ_FOREACH(current, &owindows, owindows) {
1808  Con *floating_con = con_inside_floating(current->con);
1809  if (floating_con == NULL) {
1810  DLOG("con %p / %s is not floating, cannot move it to the mouse position.\n",
1811  current->con, current->con->name);
1812  continue;
1813  }
1814 
1815  DLOG("moving floating container %p / %s to cursor position\n", floating_con, floating_con->name);
1816  floating_move_to_pointer(floating_con);
1817  }
1818 
1819  cmd_output->needs_tree_render = true;
1820  ysuccess(true);
1821 }
1822 
1823 /*
1824  * Implementation of 'move scratchpad'.
1825  *
1826  */
1828  DLOG("should move window to scratchpad\n");
1829  owindow *current;
1830 
1832 
1833  TAILQ_FOREACH(current, &owindows, owindows) {
1834  DLOG("matching: %p / %s\n", current->con, current->con->name);
1835  scratchpad_move(current->con);
1836  }
1837 
1838  cmd_output->needs_tree_render = true;
1839  // XXX: default reply for now, make this a better reply
1840  ysuccess(true);
1841 }
1842 
1843 /*
1844  * Implementation of 'scratchpad show'.
1845  *
1846  */
1848  DLOG("should show scratchpad window\n");
1849  owindow *current;
1850  bool result = false;
1851 
1853  result = scratchpad_show(NULL);
1854  } else {
1855  TAILQ_FOREACH(current, &owindows, owindows) {
1856  DLOG("matching: %p / %s\n", current->con, current->con->name);
1857  result |= scratchpad_show(current->con);
1858  }
1859  }
1860 
1861  cmd_output->needs_tree_render = true;
1862 
1863  ysuccess(result);
1864 }
1865 
1866 /*
1867  * Implementation of 'swap [container] [with] id|con_id|mark <arg>'.
1868  *
1869  */
1870 void cmd_swap(I3_CMD, const char *mode, const char *arg) {
1872 
1873  owindow *match = TAILQ_FIRST(&owindows);
1874  if (match == NULL) {
1875  yerror("No match found for swapping.");
1876  return;
1877  }
1878  if (match->con == NULL) {
1879  yerror("Match %p has no container.", match);
1880  return;
1881  }
1882 
1883  Con *con;
1884  if (strcmp(mode, "id") == 0) {
1885  long target;
1886  if (!parse_long(arg, &target, 0)) {
1887  yerror("Failed to parse %s into a window id.", arg);
1888  return;
1889  }
1890 
1891  con = con_by_window_id(target);
1892  } else if (strcmp(mode, "con_id") == 0) {
1893  long target;
1894  if (!parse_long(arg, &target, 0)) {
1895  yerror("Failed to parse %s into a container id.", arg);
1896  return;
1897  }
1898 
1899  con = con_by_con_id(target);
1900  } else if (strcmp(mode, "mark") == 0) {
1901  con = con_by_mark(arg);
1902  } else {
1903  yerror("Unhandled swap mode \"%s\". This is a bug.", mode);
1904  return;
1905  }
1906 
1907  if (con == NULL) {
1908  yerror("Could not find container for %s = %s", mode, arg);
1909  return;
1910  }
1911 
1912  if (match != TAILQ_LAST(&owindows, owindows_head)) {
1913  LOG("More than one container matched the swap command, only using the first one.");
1914  }
1915 
1916  DLOG("Swapping %p with %p.\n", match->con, con);
1917  bool result = con_swap(match->con, con);
1918 
1919  cmd_output->needs_tree_render = true;
1920  // XXX: default reply for now, make this a better reply
1921  ysuccess(result);
1922 }
1923 
1924 /*
1925  * Implementation of 'title_format <format>'
1926  *
1927  */
1928 void cmd_title_format(I3_CMD, const char *format) {
1929  DLOG("setting title_format to \"%s\"\n", format);
1931 
1932  owindow *current;
1933  TAILQ_FOREACH(current, &owindows, owindows) {
1934  DLOG("setting title_format for %p / %s\n", current->con, current->con->name);
1935  FREE(current->con->title_format);
1936 
1937  /* If we only display the title without anything else, we can skip the parsing step,
1938  * so we remove the title format altogether. */
1939  if (strcasecmp(format, "%title") != 0) {
1940  current->con->title_format = sstrdup(format);
1941 
1942  if (current->con->window != NULL) {
1943  i3String *formatted_title = con_parse_title_format(current->con);
1944  ewmh_update_visible_name(current->con->window->id, i3string_as_utf8(formatted_title));
1945  I3STRING_FREE(formatted_title);
1946  }
1947  } else {
1948  if (current->con->window != NULL) {
1949  /* We can remove _NET_WM_VISIBLE_NAME since we don't display a custom title. */
1950  ewmh_update_visible_name(current->con->window->id, NULL);
1951  }
1952  }
1953 
1954  if (current->con->window != NULL) {
1955  /* Make sure the window title is redrawn immediately. */
1956  current->con->window->name_x_changed = true;
1957  } else {
1958  /* For windowless containers we also need to force the redrawing. */
1959  FREE(current->con->deco_render_params);
1960  }
1961  }
1962 
1963  cmd_output->needs_tree_render = true;
1964  ysuccess(true);
1965 }
1966 
1967 /*
1968  * Implementation of 'rename workspace [<name>] to <name>'
1969  *
1970  */
1971 void cmd_rename_workspace(I3_CMD, const char *old_name, const char *new_name) {
1972  if (strncasecmp(new_name, "__", strlen("__")) == 0) {
1973  yerror("Cannot rename workspace to \"%s\": names starting with __ are i3-internal.", new_name);
1974  return;
1975  }
1976  if (old_name) {
1977  LOG("Renaming workspace \"%s\" to \"%s\"\n", old_name, new_name);
1978  } else {
1979  LOG("Renaming current workspace to \"%s\"\n", new_name);
1980  }
1981 
1982  Con *workspace;
1983  if (old_name) {
1984  workspace = get_existing_workspace_by_name(old_name);
1985  } else {
1986  workspace = con_get_workspace(focused);
1987  old_name = workspace->name;
1988  }
1989 
1990  if (!workspace) {
1991  yerror("Old workspace \"%s\" not found", old_name);
1992  return;
1993  }
1994 
1995  Con *check_dest = get_existing_workspace_by_name(new_name);
1996 
1997  /* If check_dest == workspace, the user might be changing the case of the
1998  * workspace, or it might just be a no-op. */
1999  if (check_dest != NULL && check_dest != workspace) {
2000  yerror("New workspace \"%s\" already exists", new_name);
2001  return;
2002  }
2003 
2004  /* Change the name and try to parse it as a number. */
2005  /* old_name might refer to workspace->name, so copy it before free()ing */
2006  char *old_name_copy = sstrdup(old_name);
2007  FREE(workspace->name);
2008  workspace->name = sstrdup(new_name);
2009 
2010  workspace->num = ws_name_to_number(new_name);
2011  LOG("num = %d\n", workspace->num);
2012 
2013  /* By re-attaching, the sort order will be correct afterwards. */
2014  Con *previously_focused = focused;
2015  Con *previously_focused_content = focused->type == CT_WORKSPACE ? focused->parent : NULL;
2016  Con *parent = workspace->parent;
2017  con_detach(workspace);
2018  con_attach(workspace, parent, false);
2019  ipc_send_workspace_event("rename", workspace, NULL);
2020 
2021  /* Move the workspace to the correct output if it has an assignment */
2022  struct Workspace_Assignment *assignment = NULL;
2024  if (assignment->output == NULL)
2025  continue;
2026  if (strcmp(assignment->name, workspace->name) != 0 && (!name_is_digits(assignment->name) || ws_name_to_number(assignment->name) != workspace->num)) {
2027  continue;
2028  }
2029 
2030  Output *target_output = get_output_by_name(assignment->output, true);
2031  if (!target_output) {
2032  LOG("Could not get output named \"%s\"\n", assignment->output);
2033  continue;
2034  }
2035  if (!output_triggers_assignment(target_output, assignment)) {
2036  continue;
2037  }
2038  workspace_move_to_output(workspace, target_output);
2039 
2040  break;
2041  }
2042 
2043  bool can_restore_focus = previously_focused != NULL;
2044  /* NB: If previously_focused is a workspace we can't work directly with it
2045  * since it might have been cleaned up by workspace_show() already,
2046  * depending on the focus order/number of other workspaces on the output.
2047  * Instead, we loop through the available workspaces and only focus
2048  * previously_focused if we still find it. */
2049  if (previously_focused_content) {
2050  Con *workspace = NULL;
2051  GREP_FIRST(workspace, previously_focused_content, child == previously_focused);
2052  can_restore_focus &= (workspace != NULL);
2053  }
2054 
2055  if (can_restore_focus) {
2056  /* Restore the previous focus since con_attach messes with the focus. */
2057  workspace_show(con_get_workspace(previously_focused));
2058  con_focus(previously_focused);
2059  }
2060 
2061  /* Let back-and-forth work after renaming the previous workspace.
2062  * See #3694. */
2063  if (previous_workspace_name && !strcmp(previous_workspace_name, old_name_copy)) {
2065  previous_workspace_name = sstrdup(new_name);
2066  }
2067 
2068  cmd_output->needs_tree_render = true;
2069  ysuccess(true);
2070 
2072 
2073  startup_sequence_rename_workspace(old_name_copy, new_name);
2074  free(old_name_copy);
2075 }
2076 
2077 /*
2078  * Implementation of 'bar mode dock|hide|invisible|toggle [<bar_id>]'
2079  *
2080  */
2081 static bool cmd_bar_mode(const char *bar_mode, const char *bar_id) {
2082  int mode = M_DOCK;
2083  bool toggle = false;
2084  if (strcmp(bar_mode, "dock") == 0)
2085  mode = M_DOCK;
2086  else if (strcmp(bar_mode, "hide") == 0)
2087  mode = M_HIDE;
2088  else if (strcmp(bar_mode, "invisible") == 0)
2089  mode = M_INVISIBLE;
2090  else if (strcmp(bar_mode, "toggle") == 0)
2091  toggle = true;
2092  else {
2093  ELOG("Unknown bar mode \"%s\", this is a mismatch between code and parser spec.\n", bar_mode);
2094  return false;
2095  }
2096 
2097  bool changed_sth = false;
2098  Barconfig *current = NULL;
2099  TAILQ_FOREACH(current, &barconfigs, configs) {
2100  if (bar_id && strcmp(current->id, bar_id) != 0)
2101  continue;
2102 
2103  if (toggle)
2104  mode = (current->mode + 1) % 2;
2105 
2106  DLOG("Changing bar mode of bar_id '%s' to '%s (%d)'\n", current->id, bar_mode, mode);
2107  current->mode = mode;
2108  changed_sth = true;
2109 
2110  if (bar_id)
2111  break;
2112  }
2113 
2114  if (bar_id && !changed_sth) {
2115  DLOG("Changing bar mode of bar_id %s failed, bar_id not found.\n", bar_id);
2116  return false;
2117  }
2118 
2119  return true;
2120 }
2121 
2122 /*
2123  * Implementation of 'bar hidden_state hide|show|toggle [<bar_id>]'
2124  *
2125  */
2126 static bool cmd_bar_hidden_state(const char *bar_hidden_state, const char *bar_id) {
2127  int hidden_state = S_SHOW;
2128  bool toggle = false;
2129  if (strcmp(bar_hidden_state, "hide") == 0)
2130  hidden_state = S_HIDE;
2131  else if (strcmp(bar_hidden_state, "show") == 0)
2132  hidden_state = S_SHOW;
2133  else if (strcmp(bar_hidden_state, "toggle") == 0)
2134  toggle = true;
2135  else {
2136  ELOG("Unknown bar state \"%s\", this is a mismatch between code and parser spec.\n", bar_hidden_state);
2137  return false;
2138  }
2139 
2140  bool changed_sth = false;
2141  Barconfig *current = NULL;
2142  TAILQ_FOREACH(current, &barconfigs, configs) {
2143  if (bar_id && strcmp(current->id, bar_id) != 0)
2144  continue;
2145 
2146  if (toggle)
2147  hidden_state = (current->hidden_state + 1) % 2;
2148 
2149  DLOG("Changing bar hidden_state of bar_id '%s' to '%s (%d)'\n", current->id, bar_hidden_state, hidden_state);
2150  current->hidden_state = hidden_state;
2151  changed_sth = true;
2152 
2153  if (bar_id)
2154  break;
2155  }
2156 
2157  if (bar_id && !changed_sth) {
2158  DLOG("Changing bar hidden_state of bar_id %s failed, bar_id not found.\n", bar_id);
2159  return false;
2160  }
2161 
2162  return true;
2163 }
2164 
2165 /*
2166  * Implementation of 'bar (hidden_state hide|show|toggle)|(mode dock|hide|invisible|toggle) [<bar_id>]'
2167  *
2168  */
2169 void cmd_bar(I3_CMD, const char *bar_type, const char *bar_value, const char *bar_id) {
2170  bool ret;
2171  if (strcmp(bar_type, "mode") == 0)
2172  ret = cmd_bar_mode(bar_value, bar_id);
2173  else if (strcmp(bar_type, "hidden_state") == 0)
2174  ret = cmd_bar_hidden_state(bar_value, bar_id);
2175  else {
2176  ELOG("Unknown bar option type \"%s\", this is a mismatch between code and parser spec.\n", bar_type);
2177  ret = false;
2178  }
2179 
2180  ysuccess(ret);
2181  if (!ret)
2182  return;
2183 
2184  update_barconfig();
2185 }
2186 
2187 /*
2188  * Implementation of 'shmlog <size>|toggle|on|off'
2189  *
2190  */
2191 void cmd_shmlog(I3_CMD, const char *argument) {
2192  if (!strcmp(argument, "toggle"))
2193  /* Toggle shm log, if size is not 0. If it is 0, set it to default. */
2195  else if (!strcmp(argument, "on"))
2197  else if (!strcmp(argument, "off"))
2198  shmlog_size = 0;
2199  else {
2200  long new_size = 0;
2201  if (!parse_long(argument, &new_size, 0)) {
2202  yerror("Failed to parse %s into a shmlog size.", argument);
2203  return;
2204  }
2205  /* If shm logging now, restart logging with the new size. */
2206  if (shmlog_size > 0) {
2207  shmlog_size = 0;
2208  LOG("Restarting shm logging...\n");
2209  init_logging();
2210  }
2211  shmlog_size = (int)new_size;
2212  }
2213  LOG("%s shm logging\n", shmlog_size > 0 ? "Enabling" : "Disabling");
2214  init_logging();
2216  ysuccess(true);
2217 }
2218 
2219 /*
2220  * Implementation of 'debuglog toggle|on|off'
2221  *
2222  */
2223 void cmd_debuglog(I3_CMD, const char *argument) {
2224  bool logging = get_debug_logging();
2225  if (!strcmp(argument, "toggle")) {
2226  LOG("%s debug logging\n", logging ? "Disabling" : "Enabling");
2227  set_debug_logging(!logging);
2228  } else if (!strcmp(argument, "on") && !logging) {
2229  LOG("Enabling debug logging\n");
2230  set_debug_logging(true);
2231  } else if (!strcmp(argument, "off") && logging) {
2232  LOG("Disabling debug logging\n");
2233  set_debug_logging(false);
2234  }
2235  // XXX: default reply for now, make this a better reply
2236  ysuccess(true);
2237 }
2238 
2243 void cmd_gaps(I3_CMD, const char *type, const char *scope, const char *mode, const char *value) {
2244  int pixels = logical_px(atoi(value));
2245  Con *workspace = con_get_workspace(focused);
2246 
2247 #define CMD_GAPS(type) \
2248  do { \
2249  int current_value = config.gaps.type; \
2250  if (strcmp(scope, "current") == 0) \
2251  current_value += workspace->gaps.type; \
2252  \
2253  bool reset = false; \
2254  if (!strcmp(mode, "plus")) \
2255  current_value += pixels; \
2256  else if (!strcmp(mode, "minus")) \
2257  current_value -= pixels; \
2258  else if (!strcmp(mode, "set")) { \
2259  current_value = pixels; \
2260  reset = true; \
2261  } else if (!strcmp(mode, "toggle")) { \
2262  current_value = !current_value * pixels; \
2263  reset = true; \
2264  } else { \
2265  ELOG("Invalid mode %s when changing gaps", mode); \
2266  ysuccess(false); \
2267  return; \
2268  } \
2269  \
2270  if (current_value < 0) \
2271  current_value = 0; \
2272  \
2273  if (!strcmp(scope, "all")) { \
2274  Con *output, *cur_ws = NULL; \
2275  TAILQ_FOREACH(output, &(croot->nodes_head), nodes) { \
2276  Con *content = output_get_content(output); \
2277  TAILQ_FOREACH(cur_ws, &(content->nodes_head), nodes) { \
2278  if (reset) \
2279  cur_ws->gaps.type = 0; \
2280  else if (current_value + cur_ws->gaps.type < 0) \
2281  cur_ws->gaps.type = -current_value; \
2282  } \
2283  } \
2284  \
2285  config.gaps.type = current_value; \
2286  } else { \
2287  workspace->gaps.type = current_value - config.gaps.type; \
2288  } \
2289  } while (0)
2290 
2291  if (!strcmp(type, "inner")) {
2292  CMD_GAPS(inner);
2293  } else if (!strcmp(type, "outer")) {
2294  CMD_GAPS(top);
2295  CMD_GAPS(bottom);
2296  CMD_GAPS(right);
2297  CMD_GAPS(left);
2298  } else if (!strcmp(type, "vertical")) {
2299  CMD_GAPS(top);
2300  CMD_GAPS(bottom);
2301  } else if (!strcmp(type, "horizontal")) {
2302  CMD_GAPS(right);
2303  CMD_GAPS(left);
2304  } else if (!strcmp(type, "top")) {
2305  CMD_GAPS(top);
2306  } else if (!strcmp(type, "bottom")) {
2307  CMD_GAPS(bottom);
2308  } else if (!strcmp(type, "right")) {
2309  CMD_GAPS(right);
2310  } else if (!strcmp(type, "left")) {
2311  CMD_GAPS(left);
2312  } else {
2313  ELOG("Invalid type %s when changing gaps", type);
2314  ysuccess(false);
2315  return;
2316  }
2317 
2318  cmd_output->needs_tree_render = true;
2319  // XXX: default reply for now, make this a better reply
2320  ysuccess(true);
2321 }
cmd_fullscreen
void cmd_fullscreen(I3_CMD, const char *action, const char *fullscreen_mode)
Implementation of 'fullscreen [enable|disable|toggle] [global]'.
Definition: commands.c:1436
Con::parent
struct Con * parent
Definition: data.h:672
get_existing_workspace_by_num
Con * get_existing_workspace_by_num(int num)
Returns the workspace with the given number or NULL if such a workspace does not exist.
Definition: workspace.c:44
workspace_show
void workspace_show(Con *workspace)
Switches to the given workspace.
Definition: workspace.c:446
con_by_window_id
Con * con_by_window_id(xcb_window_t window)
Returns the container with the given client window ID or NULL if no such container exists.
Definition: con.c:647
Workspace_Assignment::output
char * output
Definition: data.h:228
LOG
#define LOG(fmt,...)
Definition: libi3.h:94
VERT
@ VERT
Definition: data.h:62
resolve_tilde
char * resolve_tilde(const char *path)
This function resolves ~ in pathnames.
con_get_fullscreen_con
Con * con_get_fullscreen_con(Con *con, fullscreen_mode_t fullscreen_mode)
Returns the first fullscreen node below this node.
Definition: con.c:502
CHECK_MOVE_CON_TO_WORKSPACE
#define CHECK_MOVE_CON_TO_WORKSPACE
Definition: commands.c:270
I3STRING_FREE
#define I3STRING_FREE(str)
Securely i3string_free by setting the pointer to NULL to prevent accidentally using freed memory.
Definition: libi3.h:236
Workspace_Assignment
Stores which workspace (by name or number) goes to which output and its gaps config.
Definition: data.h:226
startup_sequence_rename_workspace
void startup_sequence_rename_workspace(const char *old_name, const char *new_name)
Renames workspaces that are mentioned in the startup sequences.
Definition: startup.c:265
update_barconfig
void update_barconfig(void)
Sends the current bar configuration as an event to all barconfig_update listeners.
Definition: config.c:35
config_error_nagbar_pid
pid_t config_error_nagbar_pid
Definition: config_parser.c:47
get_debug_logging
bool get_debug_logging(void)
Checks if debug logging is active.
Definition: log.c:206
cmd_workspace_number
void cmd_workspace_number(I3_CMD, const char *which, const char *_no_auto_back_and_forth)
Implementation of 'workspace [–no-auto-back-and-forth] number <number>'.
Definition: commands.c:888
i3String
struct _i3String i3String
Opaque data structure for storing strings.
Definition: libi3.h:48
Rect::y
uint32_t y
Definition: data.h:178
TAILQ_INIT
#define TAILQ_INIT(head)
Definition: queue.h:360
cmd_exec
void cmd_exec(I3_CMD, const char *nosn, const char *command)
Implementation of 'exec [–no-startup-id] <command>'.
Definition: commands.c:1207
shmlog.h
Window::name_x_changed
bool name_x_changed
Flag to force re-rendering the decoration upon changes.
Definition: data.h:455
cmd_bar
void cmd_bar(I3_CMD, const char *bar_type, const char *bar_value, const char *bar_id)
Implementation of 'bar (hidden_state hide|show|toggle)|(mode dock|hide|invisible|toggle) [<bar_id>]'.
Definition: commands.c:2169
AFTER
@ AFTER
Definition: data.h:64
orientation_t
orientation_t
Definition: data.h:60
cmd_layout
void cmd_layout(I3_CMD, const char *layout_str)
Implementation of 'layout default|stacked|stacking|tabbed|splitv|splith'.
Definition: commands.c:1550
i3string_as_utf8
const char * i3string_as_utf8(i3String *str)
Returns the UTF-8 encoded version of the i3String.
Con::deco_render_params
struct deco_render_params * deco_render_params
Cache for the decoration rendering.
Definition: data.h:714
json_validate
bool json_validate(const char *buf, const size_t len)
Returns true if the provided JSON could be parsed by yajl.
Definition: load_layout.c:580
Con::rect
struct Rect rect
Definition: data.h:676
Con::scratchpad_state
enum Con::@22 scratchpad_state
Barconfig
Holds the status bar configuration (i3bar).
Definition: configuration.h:273
maybe_auto_back_and_forth_workspace
static Con * maybe_auto_back_and_forth_workspace(Con *workspace)
Definition: commands.c:105
scratchpad_show
bool scratchpad_show(Con *con)
Either shows the top-most scratchpad window (con == NULL) or shows the specified con (if it is scratc...
Definition: scratchpad.c:85
match_init
void match_init(Match *match)
Initializes the Match data structure.
Definition: match.c:26
i3_restart
void i3_restart(bool forget_layout)
Restart i3 in-place appends -a to argument list to disable autostart.
Definition: util.c:286
con_mark_toggle
void con_mark_toggle(Con *con, const char *mark, mark_mode_t mode)
Toggles the mark on a container.
Definition: con.c:728
percent_for_1px
double percent_for_1px(Con *con)
Calculate the minimum percent needed for the given container to be at least 1 pixel.
Definition: resize.c:129
TAILQ_HEAD
typedef TAILQ_HEAD(owindows_head, owindow)
Definition: commands.c:140
shmlog_size
int shmlog_size
Definition: log.c:49
floating_resize
void floating_resize(Con *floating_con, uint32_t x, uint32_t y)
Sets size of the CT_FLOATING_CON to specified dimensions.
Definition: floating.c:771
get_output_for_con
Output * get_output_for_con(Con *con)
Returns the output for the given con.
Definition: output.c:55
cmd_floating
void cmd_floating(I3_CMD, const char *floating_mode)
Implementation of 'floating enable|disable|toggle'.
Definition: commands.c:1075
ewmh_update_visible_name
void ewmh_update_visible_name(xcb_window_t window, const char *name)
Updates _NET_WM_VISIBLE_NAME.
Definition: ewmh.c:214
D_LEFT
@ D_LEFT
Definition: data.h:58
con_move_to_output_name
bool con_move_to_output_name(Con *con, const char *name, bool fix_coordinates)
Moves the given container to the currently focused container on the visible workspace on the output s...
Definition: con.c:1425
con_is_floating
bool con_is_floating(Con *con)
Returns true if the node is floating.
Definition: con.c:575
set_debug_logging
void set_debug_logging(const bool _debug_logging)
Set debug logging.
Definition: log.c:214
border_style_t
border_style_t
Definition: data.h:65
cmd_move_direction
void cmd_move_direction(I3_CMD, const char *direction_str, long move_px)
Implementation of 'move <direction> [<pixels> [px]]'.
Definition: commands.c:1501
MM_REPLACE
@ MM_REPLACE
Definition: data.h:97
workspace_prev
Con * workspace_prev(void)
Returns the previous workspace.
Definition: workspace.c:651
Window::dock
enum Window::@13 dock
Whether the window says it is a dock window.
Barconfig::id
char * id
Automatically generated ID for this bar config.
Definition: configuration.h:276
Window::width_increment
int width_increment
Definition: data.h:493
workspace_next_on_output
Con * workspace_next_on_output(void)
Returns the next workspace on the same output.
Definition: workspace.c:717
cmd_resize_set
void cmd_resize_set(I3_CMD, long cwidth, const char *mode_width, long cheight, const char *mode_height)
Implementation of 'resize set <width> [px | ppt] <height> [px | ppt]'.
Definition: commands.c:659
KILL_CLIENT
@ KILL_CLIENT
Definition: data.h:73
cmd_gaps
void cmd_gaps(I3_CMD, const char *type, const char *scope, const char *mode, const char *value)
Implementation of 'gaps inner|outer|top|right|bottom|left|horizontal|vertical current|all set|plus|mi...
Definition: commands.c:2243
cmd_mode
void cmd_mode(I3_CMD, const char *mode)
Implementation of 'mode <string>'.
Definition: commands.c:1023
Window
A 'Window' is a type which contains an xcb_window_t and all the related information (hints like _NET_...
Definition: data.h:430
floating_enable
void floating_enable(Con *con, bool automatic)
Enables floating mode for the given container by detaching it from its parent, creating a new contain...
Definition: floating.c:224
command_error_nagbar_pid
pid_t command_error_nagbar_pid
Definition: bindings.c:17
cmd_exit
void cmd_exit(I3_CMD)
Implementation of 'exit'.
Definition: commands.c:1608
cmd_layout_toggle
void cmd_layout_toggle(I3_CMD, const char *toggle_mode)
Implementation of 'layout toggle [all|split]'.
Definition: commands.c:1581
Con::layout
layout_t layout
Definition: data.h:750
Config::default_border
border_style_t default_border
The default border style for new windows.
Definition: configuration.h:212
orientation_from_direction
orientation_t orientation_from_direction(direction_t direction)
Convert a direction to its corresponding orientation.
Definition: util.c:482
TAILQ_EMPTY
#define TAILQ_EMPTY(head)
Definition: queue.h:344
cmd_resize_floating
static void cmd_resize_floating(I3_CMD, const char *direction_str, Con *floating_con, int px)
Definition: commands.c:429
BS_PIXEL
@ BS_PIXEL
Definition: data.h:67
all_cons
struct all_cons_head all_cons
Definition: tree.c:15
layout_t
layout_t
Container layouts.
Definition: data.h:103
con_by_con_id
Con * con_by_con_id(long target)
Returns the container with the given container ID or NULL if no such container exists.
Definition: con.c:660
ws_assignments
struct ws_assignments_head ws_assignments
Definition: main.c:87
con_detach
void con_detach(Con *con)
Detaches the given container from its current parent.
Definition: con.c:206
ewmh_update_desktop_properties
void ewmh_update_desktop_properties(void)
Updates all the EWMH desktop properties.
Definition: ewmh.c:116
floating_disable
void floating_disable(Con *con)
Disables floating mode for the given container by re-attaching the container to its old parent.
Definition: floating.c:424
cmd_move_con_to_workspace_back_and_forth
void cmd_move_con_to_workspace_back_and_forth(I3_CMD)
Implementation of 'move [window|container] [to] workspace back_and_forth'.
Definition: commands.c:335
cmd_move_con_to_workspace
void cmd_move_con_to_workspace(I3_CMD, const char *which)
Implementation of 'move [window|container] [to] workspace next|prev|next_on_output|prev_on_output'.
Definition: commands.c:302
Config::default_floating_border_width
int default_floating_border_width
Definition: configuration.h:107
cmd_append_layout
void cmd_append_layout(I3_CMD, const char *cpath)
Implementation of 'append_layout <path>'.
Definition: commands.c:778
direction_from_orientation_position
direction_t direction_from_orientation_position(orientation_t orientation, position_t position)
Convert orientation and position to the corresponding direction.
Definition: util.c:498
L_SPLITH
@ L_SPLITH
Definition: data.h:110
ws_name_to_number
long ws_name_to_number(const char *name)
Parses the workspace name as a number.
Definition: util.c:106
match_is_empty
bool match_is_empty(Match *match)
Check if a match is empty.
Definition: match.c:39
all.h
init_logging
void init_logging(void)
Initializes logging by creating an error logfile in /tmp (or XDG_RUNTIME_DIR, see get_process_filenam...
Definition: log.c:85
tree_next
void tree_next(Con *con, direction_t direction)
Changes focus in the given direction.
Definition: tree.c:585
con_swap
bool con_swap(Con *first, Con *second)
Swaps the two containers.
Definition: con.c:2360
cmd_scratchpad_show
void cmd_scratchpad_show(I3_CMD)
Implementation of 'scratchpad show'.
Definition: commands.c:1847
CF_OUTPUT
@ CF_OUTPUT
Definition: data.h:623
y
#define y(x,...)
Definition: commands.c:21
mark_t::name
char * name
Definition: data.h:627
output_triggers_assignment
bool output_triggers_assignment(Output *output, struct Workspace_Assignment *assignment)
Returns true if the first output assigned to a workspace with the given workspace assignment is the s...
Definition: workspace.c:118
DLOG
#define DLOG(fmt,...)
Definition: libi3.h:104
owindow
struct owindow owindow
con_set_layout
void con_set_layout(Con *con, layout_t layout)
This function changes the layout of a given container.
Definition: con.c:1783
cmd_resize_tiling_direction
static bool cmd_resize_tiling_direction(I3_CMD, Con *current, const char *direction, int px, int ppt)
Definition: commands.c:488
ELOG
#define ELOG(fmt,...)
Definition: libi3.h:99
maybe_back_and_forth
static bool maybe_back_and_forth(struct CommandResultIR *cmd_output, const char *name)
Definition: commands.c:86
cmd_move_con_to_workspace_name
void cmd_move_con_to_workspace_name(I3_CMD, const char *name, const char *no_auto_back_and_forth)
Implementation of 'move [–no-auto-back-and-forth] [window|container] [to] workspace <name>'.
Definition: commands.c:355
Con::window
struct Window * window
Definition: data.h:708
con_activate
void con_activate(Con *con)
Sets input focus to the given container and raises it to the top.
Definition: con.c:263
con_disable_fullscreen
void con_disable_fullscreen(Con *con)
Disables fullscreen mode for the given container, if necessary.
Definition: con.c:1133
workspace_show_by_name
void workspace_show_by_name(const char *num)
Looks up the workspace by name and switches to it.
Definition: workspace.c:578
floating_maybe_reassign_ws
bool floating_maybe_reassign_ws(Con *con)
Checks if con’s coordinates are within its workspace and re-assigns it to the actual workspace if not...
Definition: floating.c:494
Con::focus_head
focus_head
Definition: data.h:724
MM_ADD
@ MM_ADD
Definition: data.h:98
floating_center
void floating_center(Con *con, Rect rect)
Centers a floating con above the specified rect.
Definition: floating.c:533
cmd_focus_window_mode
void cmd_focus_window_mode(I3_CMD, const char *window_mode)
Implementation of 'focus tiling|floating|mode_toggle'.
Definition: commands.c:1324
mark_t
Definition: data.h:626
cmd_title_format
void cmd_title_format(I3_CMD, const char *format)
Implementation of 'title_format <format>'.
Definition: commands.c:1928
TAILQ_FIRST
#define TAILQ_FIRST(head)
Definition: queue.h:336
Config::ipc_socket_path
char * ipc_socket_path
Definition: configuration.h:100
cmd_move_window_to_position
void cmd_move_window_to_position(I3_CMD, long x, long y)
Implementation of 'move [window|container] [to] [absolute] position <px> [px] <px> [px].
Definition: commands.c:1721
JSON_CONTENT_WORKSPACE
@ JSON_CONTENT_WORKSPACE
Definition: load_layout.h:27
get_existing_workspace_by_name
Con * get_existing_workspace_by_name(const char *name)
Returns the workspace with the given name or NULL if such a workspace does not exist.
Definition: workspace.c:30
GREP_FIRST
#define GREP_FIRST(dest, head, condition)
Definition: util.h:38
Config::default_border_width
int default_border_width
Definition: configuration.h:106
resize_set_tiling
static bool resize_set_tiling(I3_CMD, Con *target, orientation_t resize_orientation, bool is_ppt, long target_size)
Definition: commands.c:626
sstrdup
char * sstrdup(const char *str)
Safe-wrapper around strdup which exits if malloc returns NULL (meaning that there is no more memory a...
FREE
#define FREE(pointer)
Definition: util.h:47
HANDLE_EMPTY_MATCH
#define HANDLE_EMPTY_MATCH
When the command did not include match criteria (!), we use the currently focused container.
Definition: commands.c:62
level_up
bool level_up(void)
Moves focus one level up.
Definition: tree.c:386
D_RIGHT
@ D_RIGHT
Definition: data.h:59
floating_reposition
bool floating_reposition(Con *con, Rect newrect)
Repositions the CT_FLOATING_CON to have the coordinates specified by newrect, but only if the coordin...
Definition: floating.c:744
resize_find_tiling_participants
bool resize_find_tiling_participants(Con **current, Con **other, direction_t direction, bool both_sides)
Definition: resize.c:70
con_orientation
orientation_t con_orientation(Con *con)
Returns the orientation of the given container (for stacked containers, vertical orientation is used ...
Definition: con.c:1443
con_enable_fullscreen
void con_enable_fullscreen(Con *con, fullscreen_mode_t fullscreen_mode)
Enables fullscreen mode for the given container, if necessary.
Definition: con.c:1087
Window::height_increment
int height_increment
Definition: data.h:494
TAILQ_NEXT
#define TAILQ_NEXT(elm, field)
Definition: queue.h:338
D_DOWN
@ D_DOWN
Definition: data.h:61
owindow::con
Con * con
Definition: commands.c:136
con_close
void con_close(Con *con, kill_window_t kill_window)
Closes the given container.
Definition: con.c:307
con_rect_size_in_orientation
uint32_t con_rect_size_in_orientation(Con *con)
Returns given container's rect size depending on its orientation.
Definition: con.c:2480
con_fullscreen_permits_focusing
bool con_fullscreen_permits_focusing(Con *con)
Returns true if changing the focus to con would be allowed considering the fullscreen focus constrain...
Definition: con.c:2084
cmd_focus
void cmd_focus(I3_CMD)
Implementation of 'focus'.
Definition: commands.c:1389
Con::percent
double percent
Definition: data.h:702
sasprintf
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...
owindow::owindows
owindows
Definition: commands.c:139
workspace_back_and_forth
void workspace_back_and_forth(void)
Focuses the previously focused workspace.
Definition: workspace.c:829
con_toggle_layout
void con_toggle_layout(Con *con, const char *toggle_mode)
This function toggles the layout of a given container.
Definition: con.c:1868
CommandResultIR::needs_tree_render
bool needs_tree_render
Definition: commands_parser.h:35
owindow
Definition: commands.c:133
current_match
static Match current_match
Definition: commands_parser.c:174
floating_check_size
void floating_check_size(Con *floating_con, bool prefer_height)
Called when a floating window is created or resized.
Definition: floating.c:73
xoutput
An Output is a physical output on your graphics driver.
Definition: data.h:395
con_num_children
int con_num_children(Con *con)
Returns the number of children of this container.
Definition: con.c:922
con_mark
void con_mark(Con *con, const char *mark, mark_mode_t mode)
Assigns a mark to the container.
Definition: con.c:743
cmd_split
void cmd_split(I3_CMD, const char *direction)
Implementation of 'split v|h|t|vertical|horizontal|toggle'.
Definition: commands.c:1136
position_t
position_t
Definition: data.h:63
con_get_output
Con * con_get_output(Con *con)
Gets the output container (first container with CT_OUTPUT in hierarchy) this node is on.
Definition: con.c:439
cmd_restart
void cmd_restart(I3_CMD)
Implementation of 'restart'.
Definition: commands.c:1638
cmd_workspace
void cmd_workspace(I3_CMD, const char *which)
Implementation of 'workspace next|prev|next_on_output|prev_on_output'.
Definition: commands.c:854
cmd_sticky
void cmd_sticky(I3_CMD, const char *action)
Implementation of 'sticky enable|disable|toggle'.
Definition: commands.c:1463
con_is_internal
bool con_is_internal(Con *con)
Returns true if the container is internal, such as __i3_scratch.
Definition: con.c:567
cmd_reload
void cmd_reload(I3_CMD)
Implementation of 'reload'.
Definition: commands.c:1619
con_unmark
void con_unmark(Con *con, const char *name)
Removes marks from containers.
Definition: con.c:773
json_determine_content
json_content_t json_determine_content(const char *buf, const size_t len)
Definition: load_layout.c:607
Con::num
int num
the workspace number, if this Con is of type CT_WORKSPACE and the workspace is not a named workspace ...
Definition: data.h:667
Con::nodes_head
nodes_head
Definition: data.h:721
Rect::width
uint32_t width
Definition: data.h:179
TAILQ_LAST
#define TAILQ_LAST(head, headname)
Definition: queue.h:339
cmd_kill
void cmd_kill(I3_CMD, const char *kill_mode_str)
Implementation of 'kill [window|client]'.
Definition: commands.c:1175
kill_nagbar
void kill_nagbar(pid_t *nagbar_pid, bool wait_for_it)
Kills the i3-nagbar process, if *nagbar_pid != -1.
Definition: util.c:413
BEFORE
@ BEFORE
Definition: data.h:63
toggle_floating_mode
void toggle_floating_mode(Con *con, bool automatic)
Calls floating_enable() for tiling containers and floating_disable() for floating containers.
Definition: floating.c:461
cmd_swap
void cmd_swap(I3_CMD, const char *mode, const char *arg)
Implementation of 'swap [container] [with] id|con_id|mark <arg>'.
Definition: commands.c:1870
match_free
void match_free(Match *match)
Frees the given match.
Definition: match.c:241
Config::default_floating_border
border_style_t default_floating_border
The default border style for new floating windows.
Definition: configuration.h:215
CommandResultIR
Holds an intermediate represenation of the result of a call to any command.
Definition: commands_parser.h:21
tree_open_con
Con * tree_open_con(Con *con, i3Window *window)
Opens an empty container in the current container.
Definition: tree.c:149
cmd_shmlog
void cmd_shmlog(I3_CMD, const char *argument)
Implementation of 'shmlog <size>|toggle|on|off'.
Definition: commands.c:2191
con_by_mark
Con * con_by_mark(const char *mark)
Returns the container with the given mark or NULL if no such container exists.
Definition: con.c:698
workspace_prev_on_output
Con * workspace_prev_on_output(void)
Returns the previous workspace on the same output.
Definition: workspace.c:772
restore_open_placeholder_windows
void restore_open_placeholder_windows(Con *parent)
Open placeholder windows for all children of parent.
Definition: restore_layout.c:252
Con::type
enum Con::@20 type
cmd_open
void cmd_open(I3_CMD)
Implementation of 'open'.
Definition: commands.c:1667
default_shmlog_size
const int default_shmlog_size
Definition: main.c:71
cmd_focus_sibling
void cmd_focus_sibling(I3_CMD, const char *direction_str)
Implementation of 'focus next|prev sibling'.
Definition: commands.c:1289
Window::id
xcb_window_t id
Definition: data.h:431
match_parse_property
void match_parse_property(Match *match, const char *ctype, const char *cvalue)
Interprets a ctype=cvalue pair and adds it to the given match specification.
Definition: match.c:256
workspace_back_and_forth_get
Con * workspace_back_and_forth_get(void)
Returns the previously focused workspace con, or NULL if unavailable.
Definition: workspace.c:842
cmd_move_con_to_workspace_number
void cmd_move_con_to_workspace_number(I3_CMD, const char *which, const char *no_auto_back_and_forth)
Implementation of 'move [–no-auto-back-and-forth] [window|container] [to] workspace number <number>'.
Definition: commands.c:382
rect_equals
bool rect_equals(Rect a, Rect b)
Definition: util.c:56
layout_from_name
bool layout_from_name(const char *layout_str, layout_t *out)
Set 'out' to the layout_t value for the given layout.
Definition: util.c:79
smalloc
void * smalloc(size_t size)
Safe-wrapper around malloc which exits if malloc returns NULL (meaning that there is no more memory a...
cmd_rename_workspace
void cmd_rename_workspace(I3_CMD, const char *old_name, const char *new_name)
Implementation of 'rename workspace <name> to <name>'.
Definition: commands.c:1971
yerror
#define yerror(format,...)
Definition: commands.c:32
cmd_focus_level
void cmd_focus_level(I3_CMD, const char *level)
Implementation of 'focus parent|child'.
Definition: commands.c:1361
cmd_criteria_add
void cmd_criteria_add(I3_CMD, const char *ctype, const char *cvalue)
Interprets a ctype=cvalue pair and adds it to the current match specification.
Definition: commands.c:258
focused
struct Con * focused
Definition: tree.c:13
ysuccess
#define ysuccess(success)
Definition: commands.c:23
con_inside_floating
Con * con_inside_floating(Con *con)
Checks if the given container is either floating or inside some floating container.
Definition: con.c:599
cmd_resize_tiling_width_height
static bool cmd_resize_tiling_width_height(I3_CMD, Con *current, const char *direction, int px, double ppt)
Definition: commands.c:507
ewmh_update_sticky
void ewmh_update_sticky(xcb_window_t window, bool sticky)
Set or remove _NET_WM_STATE_STICKY on the window.
Definition: ewmh.c:277
x_set_i3_atoms
void x_set_i3_atoms(void)
Sets up i3 specific atoms (I3_SOCKET_PATH and I3_CONFIG_PATH)
Definition: x.c:1411
parse_long
bool parse_long(const char *str, long *out, int base)
Converts a string into a long using strtol().
Definition: util.c:435
Workspace_Assignment::name
char * name
Definition: data.h:227
cmd_criteria_init
void cmd_criteria_init(I3_CMD)
Initializes the specified 'Match' data structure and the initial state of commands....
marks
struct pending_marks * marks
output_push_sticky_windows
void output_push_sticky_windows(Con *old_focus)
Iterates over all outputs and pushes sticky windows to the currently visible workspace on that output...
Definition: output.c:75
xoutput::con
Con * con
Pointer to the Con which represents this output.
Definition: data.h:416
level_down
bool level_down(void)
Moves focus one level down.
Definition: tree.c:409
fullscreen_mode_t
fullscreen_mode_t
Fullscreen modes.
Definition: data.h:622
con_move_to_mark
bool con_move_to_mark(Con *con, const char *mark)
Moves the given container to the given mark.
Definition: con.c:1329
con_attach
void con_attach(Con *con, Con *parent, bool ignore_focus)
Attaches the given container to the given parent.
Definition: con.c:198
CMD_GAPS
#define CMD_GAPS(type)
cmd_move_workspace_to_output
void cmd_move_workspace_to_output(I3_CMD, const char *name)
Implementation of 'move workspace to [output] <str>'.
Definition: commands.c:1106
workspace_next
Con * workspace_next(void)
Returns the next workspace.
Definition: workspace.c:588
config
Config config
Definition: config.c:17
cmd_debuglog
void cmd_debuglog(I3_CMD, const char *argument)
Implementation of 'debuglog toggle|on|off'.
Definition: commands.c:2223
JSON_CONTENT_UNKNOWN
@ JSON_CONTENT_UNKNOWN
Definition: load_layout.h:18
purge_zerobyte_logfile
void purge_zerobyte_logfile(void)
Deletes the unused log files.
Definition: log.c:355
tree_move
void tree_move(Con *con, direction_t direction)
Moves the given container in the given direction.
Definition: move.c:249
previous_workspace_name
char * previous_workspace_name
Stores a copy of the name of the last used workspace for the workspace back-and-forth switching.
Definition: workspace.c:19
TAILQ_FOREACH
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:347
cmd_mark
void cmd_mark(I3_CMD, const char *mark, const char *mode, const char *toggle)
Implementation of 'mark [–add|–replace] [–toggle] <mark>'.
Definition: commands.c:971
ewmh_update_wm_desktop
void ewmh_update_wm_desktop(void)
Updates _NET_WM_DESKTOP for all windows.
Definition: ewmh.c:182
BS_NONE
@ BS_NONE
Definition: data.h:66
cmd_criteria_match_windows
void cmd_criteria_match_windows(I3_CMD)
A match specification just finished (the closing square bracket was found), so we filter the list of ...
Definition: commands.c:175
cmd_move_window_to_center
void cmd_move_window_to_center(I3_CMD, const char *method)
Implementation of 'move [window|container] [to] [absolute] position center.
Definition: commands.c:1759
switch_mode
void switch_mode(const char *new_mode)
Switches the key bindings to the given mode, if the mode exists.
Definition: bindings.c:618
cmd_bar_hidden_state
static bool cmd_bar_hidden_state(const char *bar_hidden_state, const char *bar_id)
Definition: commands.c:2126
con_toggle_fullscreen
void con_toggle_fullscreen(Con *con, int fullscreen_mode)
Toggles fullscreen mode for the given container.
Definition: con.c:1033
Con::sticky
bool sticky
Definition: data.h:734
STARTS_WITH
#define STARTS_WITH(string, needle)
Definition: util.h:25
floating_move_to_pointer
void floating_move_to_pointer(Con *con)
Moves the given floating con to the current pointer position.
Definition: floating.c:542
move_matches_to_workspace
static void move_matches_to_workspace(Con *ws)
Definition: commands.c:262
cmd_nop
void cmd_nop(I3_CMD, const char *comment)
Implementation of 'nop <comment>'.
Definition: commands.c:767
Con::border_style
border_style_t border_style
Definition: data.h:751
TAILQ_ENTRY
#define TAILQ_ENTRY(type)
Definition: queue.h:327
I3_CMD
#define I3_CMD
The beginning of the prototype for every cmd_ function.
Definition: commands.h:17
cmd_resize
void cmd_resize(I3_CMD, const char *way, const char *direction, long resize_px, long resize_ppt)
Implementation of 'resize grow|shrink <direction> [<px> px] [or <ppt> ppt]'.
Definition: commands.c:580
tree_split
void tree_split(Con *con, orientation_t orientation)
Splits (horizontally or vertically) the given container by creating a new container which contains th...
Definition: tree.c:327
Barconfig::hidden_state
enum Barconfig::@10 hidden_state
get_output_from_string
Output * get_output_from_string(Output *current_output, const char *output_str)
Returns an 'output' corresponding to one of left/right/down/up or a specific output name.
Definition: output.c:31
border_width_from_style
static int border_width_from_style(border_style_t border_style, long border_width, Con *con)
Definition: commands.c:708
CMD_FOCUS_WARN_CHILDREN
#define CMD_FOCUS_WARN_CHILDREN
Definition: commands.c:1232
TAILQ_REMOVE
#define TAILQ_REMOVE(head, elm, field)
Definition: queue.h:402
TAILQ_END
#define TAILQ_END(head)
Definition: queue.h:337
C_RELOAD
@ C_RELOAD
Definition: configuration.h:421
get_tree_next_sibling
Con * get_tree_next_sibling(Con *con, position_t direction)
Get the previous / next sibling.
Definition: tree.c:627
con_descend_focused
Con * con_descend_focused(Con *con)
Returns the focused con inside this client, descending the tree as far as possible.
Definition: con.c:1516
scratchpad_move
void scratchpad_move(Con *con)
Moves the specified window to the __i3_scratch workspace, making it floating and setting the appropri...
Definition: scratchpad.c:19
con_parse_title_format
i3String * con_parse_title_format(Con *con)
Returns the window title considering the current title format.
Definition: con.c:2316
Con
A 'Con' represents everything from the X11 root window down to a single X11 window.
Definition: data.h:637
cmd_move_window_to_mouse
void cmd_move_window_to_mouse(I3_CMD)
Implementation of 'move [window|container] [to] position mouse'.
Definition: commands.c:1803
barconfigs
struct barconfig_head barconfigs
Definition: config.c:19
con_move_to_workspace
void con_move_to_workspace(Con *con, Con *workspace, bool fix_coordinates, bool dont_warp, bool ignore_focus)
Moves the given container to the currently focused container on the given workspace.
Definition: con.c:1392
mark_mode_t
mark_mode_t
Definition: data.h:97
con_exists
bool con_exists(Con *con)
Returns true if the given container (still) exists.
Definition: con.c:676
cmd_move_con_to_output
void cmd_move_con_to_output(I3_CMD, const char *name)
Implementation of 'move [window|container] [to] output <str>'.
Definition: commands.c:1035
load_configuration
bool load_configuration(const char *override_configpath, config_load_t load_type)
(Re-)loads the configuration file (sets useful defaults before).
Definition: config.c:174
ipc_send_workspace_event
void ipc_send_workspace_event(const char *change, Con *current, Con *old)
For the workspace events we send, along with the usual "change" field, also the workspace container i...
Definition: ipc.c:1627
logical_px
int logical_px(const int logical)
Convert a logical amount of pixels (e.g.
cmd_move_con_to_mark
void cmd_move_con_to_mark(I3_CMD, const char *mark)
Implementation of 'move [window|container] [to] mark <str>'.
Definition: commands.c:1055
con_accepts_window
bool con_accepts_window(Con *con)
Returns true if this node accepts a window (if the node swallows windows, it might already have swall...
Definition: con.c:420
BS_NORMAL
@ BS_NORMAL
Definition: data.h:65
Con::marks_head
marks_head
Definition: data.h:698
con_activate_unblock
void con_activate_unblock(Con *con)
Activates the container like in con_activate but removes fullscreen restrictions and properly warps t...
Definition: con.c:273
update_shmlog_atom
void update_shmlog_atom(void)
Set up the SHMLOG_PATH atom.
Definition: x.c:1397
render_con
void render_con(Con *con, bool already_inset)
"Renders" the given container (and its children), meaning that all rects are updated correctly.
Definition: render.c:42
cmd_unmark
void cmd_unmark(I3_CMD, const char *mark)
Implementation of 'unmark [mark]'.
Definition: commands.c:1004
Match::mark
struct regex * mark
Definition: data.h:534
KILL_WINDOW
@ KILL_WINDOW
Definition: data.h:72
Match::con_id
Con * con_id
Definition: data.h:554
regex_matches
bool regex_matches(struct regex *regex, const char *input)
Checks if the given regular expression matches the given input and returns true if it does.
Definition: regex.c:73
slurp
ssize_t slurp(const char *path, char **buf)
Slurp reads path in its entirety into buf, returning the length of the file or -1 if the file could n...
Definition: util.c:453
cmd_workspace_back_and_forth
void cmd_workspace_back_and_forth(I3_CMD)
Implementation of 'workspace back_and_forth'.
Definition: commands.c:925
CF_GLOBAL
@ CF_GLOBAL
Definition: data.h:624
workspace_get
Con * workspace_get(const char *num, bool *created)
Returns a pointer to the workspace with the given number (starting at 0), creating the workspace if n...
Definition: workspace.c:129
Rect::height
uint32_t height
Definition: data.h:180
resize_neighboring_cons
bool resize_neighboring_cons(Con *first, Con *second, int px, int ppt)
Resize the two given containers using the given amount of pixels or percentage points.
Definition: resize.c:144
json_content_t
json_content_t
Definition: load_layout.h:15
ipc_shutdown
void ipc_shutdown(shutdown_reason_t reason, int exempt_fd)
Calls shutdown() on each socket and closes it.
Definition: ipc.c:206
tree_append_json
void tree_append_json(Con *con, const char *buf, const size_t len, char **errormsg)
Definition: load_layout.c:640
TAILQ_INSERT_TAIL
#define TAILQ_INSERT_TAIL(head, elm, field)
Definition: queue.h:376
ystr
#define ystr(str)
Definition: commands.c:22
con_focus
void con_focus(Con *con)
Sets input focus to the given container.
Definition: con.c:222
get_output_by_name
Output * get_output_by_name(const char *name, const bool require_active)
Returns the output with the given name or NULL.
Definition: randr.c:47
croot
struct Con * croot
Definition: tree.c:12
con_set_border_style
void con_set_border_style(Con *con, int border_style, int border_width)
Sets the given border style on con, correctly keeping the position/size of a floating window.
Definition: con.c:1741
Con::name
char * name
Definition: data.h:686
HORIZ
@ HORIZ
Definition: data.h:61
Config::workspace_auto_back_and_forth
bool workspace_auto_back_and_forth
Automatic workspace back and forth switching.
Definition: configuration.h:179
Rect::x
uint32_t x
Definition: data.h:177
Con::title_format
char * title_format
The format with which the window's name should be displayed.
Definition: data.h:689
cmd_border
void cmd_border(I3_CMD, const char *border_style_str, long border_width)
Implementation of 'border normal|pixel [<n>]', 'border none|1pixel|toggle'.
Definition: commands.c:732
match_matches_window
bool match_matches_window(Match *match, i3Window *window)
Check if a match data structure matches the given window.
Definition: match.c:87
D_UP
@ D_UP
Definition: data.h:60
SHUTDOWN_REASON_RESTART
@ SHUTDOWN_REASON_RESTART
Definition: ipc.h:103
workspace_is_visible
bool workspace_is_visible(Con *ws)
Returns true if the workspace is currently visible.
Definition: workspace.c:333
cmd_focus_output
void cmd_focus_output(I3_CMD, const char *name)
Implementation of 'focus output <output>'.
Definition: commands.c:1687
workspace_move_to_output
void workspace_move_to_output(Con *ws, Output *output)
Move the given workspace to the specified output.
Definition: workspace.c:993
con_get_workspace
Con * con_get_workspace(Con *con)
Gets the workspace container this node is on.
Definition: con.c:453
cmd_focus_direction
void cmd_focus_direction(I3_CMD, const char *direction_str)
Implementation of 'focus left|right|up|down'.
Definition: commands.c:1251
cmd_workspace_name
void cmd_workspace_name(I3_CMD, const char *name, const char *_no_auto_back_and_forth)
Implementation of 'workspace [–no-auto-back-and-forth] <name>'.
Definition: commands.c:942
start_application
void start_application(const char *command, bool no_startup_id)
Starts the given application by passing it through a shell.
Definition: startup.c:133
cmd_bar_mode
static bool cmd_bar_mode(const char *bar_mode, const char *bar_id)
Definition: commands.c:2081
output_get_content
Con * output_get_content(Con *output)
Returns the output container below the given output container.
Definition: output.c:16
Barconfig::mode
enum Barconfig::@9 mode
Bar display mode (hide unless modifier is pressed or show in dock mode or always hide in invisible mo...
con_is_docked
bool con_is_docked(Con *con)
Returns true if the container is a docked container.
Definition: con.c:584
direction_t
direction_t
Definition: data.h:56
parse_direction
static direction_t parse_direction(const char *str)
Definition: commands.c:414
Rect
Stores a rectangle, for example the size of a window, the child window etc.
Definition: data.h:176
cmd_move_scratchpad
void cmd_move_scratchpad(I3_CMD)
Implementation of 'move scratchpad'.
Definition: commands.c:1827