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