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