4 * i3 - an improved dynamic tiling window manager
6 * © 2009 Michael Stapelberg and contributors
8 * See file LICENSE for license information.
27 bool focus_window_in_container(xcb_connection_t *conn, Container *container, direction_t direction) {
28 /* If this container is empty, we’re done */
29 if (container->currently_focused == NULL)
32 /* Get the previous/next client or wrap around */
33 Client *candidate = NULL;
34 if (direction == D_UP) {
35 if ((candidate = CIRCLEQ_PREV_OR_NULL(&(container->clients), container->currently_focused, clients)) == NULL)
36 candidate = CIRCLEQ_LAST(&(container->clients));
38 else if (direction == D_DOWN) {
39 if ((candidate = CIRCLEQ_NEXT_OR_NULL(&(container->clients), container->currently_focused, clients)) == NULL)
40 candidate = CIRCLEQ_FIRST(&(container->clients));
41 } else LOG("Direction not implemented!\n");
43 /* If we could not switch, the container contains exactly one client. We return false */
44 if (candidate == container->currently_focused)
48 set_focus(conn, candidate, true);
53 typedef enum { THING_WINDOW, THING_CONTAINER } thing_t;
55 static void focus_thing(xcb_connection_t *conn, direction_t direction, thing_t thing) {
56 LOG("focusing direction %d\n", direction);
58 int new_row = current_row,
59 new_col = current_col;
61 Container *container = CUR_CELL;
62 Workspace *t_ws = c_ws;
64 /* There always is a container. If not, current_col or current_row is wrong */
65 assert(container != NULL);
67 if (container->workspace->fullscreen_client != NULL) {
68 LOG("You're in fullscreen mode. Won't switch focus\n");
72 /* TODO: for horizontal default layout, this has to be expanded to LEFT/RIGHT */
73 if (direction == D_UP || direction == D_DOWN) {
74 if (thing == THING_WINDOW)
75 /* Let’s see if we can perform up/down focus in the current container */
76 if (focus_window_in_container(conn, container, direction))
79 if (direction == D_DOWN && cell_exists(current_col, current_row+1))
81 else if (direction == D_UP && cell_exists(current_col, current_row-1))
84 /* Let’s see if there is a screen down/up there to which we can switch */
85 LOG("container is at %d with height %d\n", container->y, container->height);
87 int destination_y = (direction == D_UP ? (container->y - 1) : (container->y + container->height + 1));
88 if ((screen = get_screen_containing(container->x, destination_y)) == NULL) {
89 LOG("Wrapping screen around vertically\n");
90 /* No screen found? Then wrap */
91 screen = get_screen_most((direction == D_UP ? D_DOWN : D_UP));
93 t_ws = &(workspaces[screen->current_workspace]);
94 new_row = (direction == D_UP ? (t_ws->rows - 1) : 0);
96 } else if (direction == D_LEFT || direction == D_RIGHT) {
97 if (direction == D_RIGHT && cell_exists(current_col+1, current_row))
99 else if (direction == D_LEFT && cell_exists(current_col-1, current_row))
102 /* Let’s see if there is a screen left/right here to which we can switch */
103 LOG("container is at %d with width %d\n", container->x, container->width);
105 int destination_x = (direction == D_LEFT ? (container->x - 1) : (container->x + container->width + 1));
106 if ((screen = get_screen_containing(destination_x, container->y)) == NULL) {
107 LOG("Wrapping screen around horizontally\n");
108 screen = get_screen_most((direction == D_LEFT ? D_RIGHT : D_LEFT));
110 t_ws = &(workspaces[screen->current_workspace]);
111 new_col = (direction == D_LEFT ? (t_ws->cols - 1) : 0);
114 LOG("direction unhandled\n");
118 /* Bounds checking */
119 if (new_col >= t_ws->cols)
120 new_col = (t_ws->cols - 1);
121 if (new_row >= t_ws->rows)
122 new_row = (t_ws->rows - 1);
124 if (t_ws->table[new_col][new_row]->currently_focused != NULL)
125 set_focus(conn, t_ws->table[new_col][new_row]->currently_focused, true);
129 * Tries to move the window inside its current container.
131 * Returns true if the window could be moved, false otherwise.
134 static bool move_current_window_in_container(xcb_connection_t *conn, Client *client,
135 direction_t direction) {
136 assert(client->container != NULL);
138 Client *other = (direction == D_UP ? CIRCLEQ_PREV(client, clients) :
139 CIRCLEQ_NEXT(client, clients));
141 if (other == CIRCLEQ_END(&(client->container->clients)))
144 LOG("i can do that\n");
145 /* We can move the client inside its current container */
146 CIRCLEQ_REMOVE(&(client->container->clients), client, clients);
147 if (direction == D_UP)
148 CIRCLEQ_INSERT_BEFORE(&(client->container->clients), other, client, clients);
149 else CIRCLEQ_INSERT_AFTER(&(client->container->clients), other, client, clients);
155 * Moves the current window or whole container to the given direction, creating a column/row if
159 static void move_current_window(xcb_connection_t *conn, direction_t direction) {
160 LOG("moving window to direction %s\n", (direction == D_UP ? "up" : (direction == D_DOWN ? "down" :
161 (direction == D_LEFT ? "left" : "right"))));
162 /* Get current window */
163 Container *container = CUR_CELL,
166 /* There has to be a container, see focus_window() */
167 assert(container != NULL);
169 /* If there is no window or the dock window is focused, we’re done */
170 if (container->currently_focused == NULL ||
171 container->currently_focused->dock)
174 /* As soon as the client is moved away, the last focused client in the old
175 * container needs to get focus, if any. Therefore, we save it here. */
176 Client *current_client = container->currently_focused;
177 Client *to_focus = get_last_focused_client(conn, container, current_client);
179 if (to_focus == NULL) {
180 to_focus = CIRCLEQ_NEXT_OR_NULL(&(container->clients), current_client, clients);
181 if (to_focus == NULL)
182 to_focus = CIRCLEQ_PREV_OR_NULL(&(container->clients), current_client, clients);
187 /* If we’re at the left-most position, move the rest of the table right */
188 if (current_col == 0) {
189 expand_table_cols_at_head(c_ws);
192 new = CUR_TABLE[--current_col][current_row];
195 if (current_col == (c_ws->cols-1))
196 expand_table_cols(c_ws);
198 new = CUR_TABLE[++current_col][current_row];
201 if (move_current_window_in_container(conn, current_client, D_UP))
204 /* if we’re at the up-most position, move the rest of the table down */
205 if (current_row == 0) {
206 expand_table_rows_at_head(c_ws);
209 new = CUR_TABLE[current_col][--current_row];
212 if (move_current_window_in_container(conn, current_client, D_DOWN))
215 if (current_row == (c_ws->rows-1))
216 expand_table_rows(c_ws);
218 new = CUR_TABLE[current_col][++current_row];
222 /* Remove it from the old container and put it into the new one */
223 remove_client_from_container(conn, current_client, container);
225 if (new->currently_focused != NULL)
226 CIRCLEQ_INSERT_AFTER(&(new->clients), new->currently_focused, current_client, clients);
227 else CIRCLEQ_INSERT_TAIL(&(new->clients), current_client, clients);
228 SLIST_INSERT_HEAD(&(new->workspace->focus_stack), current_client, focus_clients);
230 /* Update data structures */
231 current_client->container = new;
232 container->currently_focused = to_focus;
233 new->currently_focused = current_client;
235 Workspace *workspace = container->workspace;
237 /* delete all empty columns/rows */
238 cleanup_table(conn, workspace);
240 /* Fix colspan/rowspan if it’d overlap */
241 fix_colrowspan(conn, workspace);
245 set_focus(conn, current_client, true);
248 static void move_current_container(xcb_connection_t *conn, direction_t direction) {
249 LOG("moving container to direction %s\n", (direction == D_UP ? "up" : (direction == D_DOWN ? "down" :
250 (direction == D_LEFT ? "left" : "right"))));
251 /* Get current window */
252 Container *container = CUR_CELL,
255 Container **old = &CUR_CELL;
257 /* There has to be a container, see focus_window() */
258 assert(container != NULL);
262 /* If we’re at the left-most position, move the rest of the table right */
263 if (current_col == 0) {
264 expand_table_cols_at_head(c_ws);
266 old = &CUR_TABLE[current_col+1][current_row];
268 new = CUR_TABLE[--current_col][current_row];
271 if (current_col == (c_ws->cols-1))
272 expand_table_cols(c_ws);
274 new = CUR_TABLE[++current_col][current_row];
277 /* if we’re at the up-most position, move the rest of the table down */
278 if (current_row == 0) {
279 expand_table_rows_at_head(c_ws);
281 old = &CUR_TABLE[current_col][current_row+1];
283 new = CUR_TABLE[current_col][--current_row];
286 if (current_row == (c_ws->rows-1))
287 expand_table_rows(c_ws);
289 new = CUR_TABLE[current_col][++current_row];
293 LOG("old = %d,%d and new = %d,%d\n", container->col, container->row, new->col, new->row);
295 /* Swap the containers */
300 new->col = container->col;
301 new->row = container->row;
303 CUR_CELL = container;
304 container->col = col;
305 container->row = row;
307 Workspace *workspace = container->workspace;
309 /* delete all empty columns/rows */
310 cleanup_table(conn, workspace);
312 /* Fix colspan/rowspan if it’d overlap */
313 fix_colrowspan(conn, workspace);
319 * "Snaps" the current container (not possible for windows, because it works at table base)
320 * to the given direction, that is, adjusts cellspan/rowspan
323 static void snap_current_container(xcb_connection_t *conn, direction_t direction) {
324 LOG("snapping container to direction %d\n", direction);
326 Container *container = CUR_CELL;
328 assert(container != NULL);
332 /* Snap to the left is actually a move to the left and then a snap right */
333 if (!cell_exists(container->col - 1, container->row) ||
334 CUR_TABLE[container->col-1][container->row]->currently_focused != NULL) {
335 LOG("cannot snap to left - the cell is already used\n");
339 move_current_window(conn, D_LEFT);
340 snap_current_container(conn, D_RIGHT);
343 /* Check if the cell is used */
344 int new_col = container->col + container->colspan;
345 if (!cell_exists(new_col, container->row) ||
346 CUR_TABLE[new_col][container->row]->currently_focused != NULL) {
347 LOG("cannot snap to right - the cell is already used\n");
351 /* Check if there are other cells with rowspan, which are in our way.
352 * If so, reduce their rowspan. */
353 for (int i = container->row-1; i >= 0; i--) {
354 LOG("we got cell %d, %d with rowspan %d\n",
355 new_col, i, CUR_TABLE[new_col][i]->rowspan);
356 while ((CUR_TABLE[new_col][i]->rowspan-1) >= (container->row - i))
357 CUR_TABLE[new_col][i]->rowspan--;
358 LOG("new rowspan = %d\n", CUR_TABLE[new_col][i]->rowspan);
361 container->colspan++;
365 if (!cell_exists(container->col, container->row - 1) ||
366 CUR_TABLE[container->col][container->row-1]->currently_focused != NULL) {
367 LOG("cannot snap to top - the cell is already used\n");
371 move_current_window(conn, D_UP);
372 snap_current_container(conn, D_DOWN);
375 LOG("snapping down\n");
376 int new_row = container->row + container->rowspan;
377 if (!cell_exists(container->col, new_row) ||
378 CUR_TABLE[container->col][new_row]->currently_focused != NULL) {
379 LOG("cannot snap down - the cell is already used\n");
383 for (int i = container->col-1; i >= 0; i--) {
384 LOG("we got cell %d, %d with colspan %d\n",
385 i, new_row, CUR_TABLE[i][new_row]->colspan);
386 while ((CUR_TABLE[i][new_row]->colspan-1) >= (container->col - i))
387 CUR_TABLE[i][new_row]->colspan--;
388 LOG("new colspan = %d\n", CUR_TABLE[i][new_row]->colspan);
392 container->rowspan++;
401 * Moves the currently selected window to the given workspace
404 static void move_current_window_to_workspace(xcb_connection_t *conn, int workspace) {
405 LOG("Moving current window to workspace %d\n", workspace);
407 Container *container = CUR_CELL;
409 assert(container != NULL);
411 /* t_ws (to workspace) is just a container pointer to the workspace we’re switching to */
412 Workspace *t_ws = &(workspaces[workspace-1]);
414 Client *current_client = container->currently_focused;
415 if (current_client == NULL) {
416 LOG("No currently focused client in current container.\n");
419 Client *to_focus = CIRCLEQ_NEXT_OR_NULL(&(container->clients), current_client, clients);
420 if (to_focus == NULL)
421 to_focus = CIRCLEQ_PREV_OR_NULL(&(container->clients), current_client, clients);
423 if (t_ws->screen == NULL) {
424 LOG("initializing new workspace, setting num to %d\n", workspace-1);
425 t_ws->screen = container->workspace->screen;
426 /* Copy the dimensions from the virtual screen */
427 memcpy(&(t_ws->rect), &(container->workspace->screen->rect), sizeof(Rect));
429 /* Check if there is already a fullscreen client on the destination workspace and
430 * stop moving if so. */
431 if (current_client->fullscreen && (t_ws->fullscreen_client != NULL)) {
432 LOG("Not moving: Fullscreen client already existing on destination workspace.\n");
437 Container *to_container = t_ws->table[t_ws->current_col][t_ws->current_row];
439 assert(to_container != NULL);
441 remove_client_from_container(conn, current_client, container);
442 if (container->workspace->fullscreen_client == current_client)
443 container->workspace->fullscreen_client = NULL;
445 CIRCLEQ_INSERT_TAIL(&(to_container->clients), current_client, clients);
446 SLIST_INSERT_HEAD(&(to_container->workspace->focus_stack), current_client, focus_clients);
447 if (current_client->fullscreen)
448 t_ws->fullscreen_client = current_client;
451 current_client->container = to_container;
452 container->currently_focused = to_focus;
453 to_container->currently_focused = current_client;
455 /* If we’re moving it to an invisible screen, we need to unmap it */
456 if (to_container->workspace->screen->current_workspace != to_container->workspace->num) {
457 LOG("This workspace is not visible, unmapping\n");
458 xcb_unmap_window(conn, current_client->frame);
461 /* delete all empty columns/rows */
462 cleanup_table(conn, container->workspace);
468 * Switches to the given workspace
471 void show_workspace(xcb_connection_t *conn, int workspace) {
473 bool need_warp = false;
474 xcb_window_t root = xcb_setup_roots_iterator(xcb_get_setup(conn)).data->root;
475 /* t_ws (to workspace) is just a convenience pointer to the workspace we’re switching to */
476 Workspace *t_ws = &(workspaces[workspace-1]);
478 LOG("show_workspace(%d)\n", workspace);
480 /* Store current_row/current_col */
481 c_ws->current_row = current_row;
482 c_ws->current_col = current_col;
484 /* Check if the workspace has not been used yet */
485 if (t_ws->screen == NULL) {
486 LOG("initializing new workspace, setting num to %d\n", workspace);
487 t_ws->screen = c_ws->screen;
488 /* Copy the dimensions from the virtual screen */
489 memcpy(&(t_ws->rect), &(t_ws->screen->rect), sizeof(Rect));
492 if (c_ws->screen != t_ws->screen) {
493 /* We need to switch to the other screen first */
494 LOG("moving over to other screen.\n");
496 /* Store the old client */
497 Client *old_client = CUR_CELL->currently_focused;
499 c_ws = &(workspaces[t_ws->screen->current_workspace]);
500 current_col = c_ws->current_col;
501 current_row = c_ws->current_row;
502 if (CUR_CELL->currently_focused != NULL)
505 Rect *dims = &(c_ws->screen->rect);
506 xcb_warp_pointer(conn, XCB_NONE, root, 0, 0, 0, 0,
507 dims->x + (dims->width / 2), dims->y + (dims->height / 2));
510 /* Re-decorate the old client, it’s not focused anymore */
511 if ((old_client != NULL) && !old_client->dock)
512 redecorate_window(conn, old_client);
513 else xcb_flush(conn);
516 /* Check if we need to change something or if we’re already there */
517 if (c_ws->screen->current_workspace == (workspace-1)) {
518 if (CUR_CELL->currently_focused != NULL) {
519 set_focus(conn, CUR_CELL->currently_focused, true);
521 warp_pointer_into(conn, CUR_CELL->currently_focused);
528 t_ws->screen->current_workspace = workspace-1;
530 /* TODO: does grabbing the server actually bring us any (speed)advantages? */
531 //xcb_grab_server(conn);
533 ignore_enter_notify_forall(conn, c_ws, true);
535 /* Unmap all clients of the current workspace */
536 int unmapped_clients = 0;
538 CIRCLEQ_FOREACH(client, &(c_ws->table[cols][rows]->clients), clients) {
539 xcb_unmap_window(conn, client->frame);
543 /* If we did not unmap any clients, the workspace is empty and we can destroy it */
544 if (unmapped_clients == 0)
547 /* Unmap the stack windows on the current workspace, if any */
548 struct Stack_Window *stack_win;
549 SLIST_FOREACH(stack_win, &stack_wins, stack_windows)
550 if (stack_win->container->workspace == c_ws)
551 xcb_unmap_window(conn, stack_win->window);
553 ignore_enter_notify_forall(conn, c_ws, false);
555 c_ws = &workspaces[workspace-1];
556 current_row = c_ws->current_row;
557 current_col = c_ws->current_col;
558 LOG("new current row = %d, current col = %d\n", current_row, current_col);
560 ignore_enter_notify_forall(conn, c_ws, true);
562 /* Map all clients on the new workspace */
564 CIRCLEQ_FOREACH(client, &(c_ws->table[cols][rows]->clients), clients)
565 xcb_map_window(conn, client->frame);
567 /* Map all stack windows, if any */
568 SLIST_FOREACH(stack_win, &stack_wins, stack_windows)
569 if (stack_win->container->workspace == c_ws)
570 xcb_map_window(conn, stack_win->window);
572 ignore_enter_notify_forall(conn, c_ws, false);
574 /* Restore focus on the new workspace */
575 if (CUR_CELL->currently_focused != NULL) {
576 set_focus(conn, CUR_CELL->currently_focused, true);
578 warp_pointer_into(conn, CUR_CELL->currently_focused);
581 } else xcb_set_input_focus(conn, XCB_INPUT_FOCUS_POINTER_ROOT, root, XCB_CURRENT_TIME);
583 //xcb_ungrab_server(conn);
589 * Checks if the given window class and title match the given client
590 * Window title is passed as "normal" string and as UCS-2 converted string for
591 * matching _NET_WM_NAME capable clients as well as those using legacy hints.
594 static bool client_matches_class_name(Client *client, char *to_class, char *to_title,
595 char *to_title_ucs, int to_title_ucs_len) {
596 /* Check if the given class is part of the window class */
597 if (strcasestr(client->window_class, to_class) == NULL)
600 /* If no title was given, we’re done */
601 if (to_title == NULL)
604 if (client->name_len > -1) {
605 /* UCS-2 converted window titles */
606 if (memmem(client->name, (client->name_len * 2), to_title_ucs, (to_title_ucs_len * 2)) == NULL)
610 if (strcasestr(client->name, to_title) == NULL)
618 * Jumps to the given window class / title.
619 * Title is matched using strstr, that is, matches if it appears anywhere
620 * in the string. Regular expressions seem to be a bit overkill here. However,
621 * if we need them for something else somewhen, we may introduce them here, too.
624 static void jump_to_window(xcb_connection_t *conn, const char *arguments) {
625 char *to_class, *to_title, *to_title_ucs = NULL;
626 int to_title_ucs_len;
628 /* The first character is a quote, this was checked before */
629 to_class = sstrdup(arguments+1);
630 /* The last character is a quote, we just set it to NULL */
631 to_class[strlen(to_class)-1] = '\0';
633 /* If a title was specified, split both strings at the slash */
634 if ((to_title = strstr(to_class, "/")) != NULL) {
635 *(to_title++) = '\0';
636 /* Convert to UCS-2 */
637 to_title_ucs = convert_utf8_to_ucs2(to_title, &to_title_ucs_len);
640 LOG("Should jump to class \"%s\" / title \"%s\"\n", to_class, to_title);
641 for (int workspace = 0; workspace < 10; workspace++) {
642 if (workspaces[workspace].screen == NULL)
645 FOR_TABLE(&(workspaces[workspace])) {
646 Container *con = workspaces[workspace].table[cols][rows];
649 CIRCLEQ_FOREACH(client, &(con->clients), clients) {
650 LOG("Checking client with class=%s, name=%s\n", client->window_class, client->name);
651 if (!client_matches_class_name(client, to_class, to_title, to_title_ucs, to_title_ucs_len))
654 set_focus(conn, client, true);
666 * Jump directly to the specified workspace, row and col.
667 * Great for reaching windows that you always keep in the same spot (hello irssi, I'm looking at you)
670 static void jump_to_container(xcb_connection_t *conn, const char *arguments) {
674 result = sscanf(arguments, "%d %d %d", &ws, &col, &row);
675 LOG("Jump called with %d parameters (\"%s\")\n", result, arguments);
677 /* No match? Either no arguments were specified, or no numbers */
679 LOG("At least one valid argument required\n");
683 /* Move to the target workspace */
684 show_workspace(conn, ws);
689 LOG("Boundary-checking col %d, row %d... (max cols %d, max rows %d)\n", col, row, c_ws->cols, c_ws->rows);
691 /* Move to row/col */
692 if (row >= c_ws->rows)
693 row = c_ws->rows - 1;
694 if (col >= c_ws->cols)
695 col = c_ws->cols - 1;
697 LOG("Jumping to col %d, row %d\n", col, row);
698 if (c_ws->table[col][row]->currently_focused != NULL)
699 set_focus(conn, c_ws->table[col][row]->currently_focused, true);
703 * Travels the focus stack by the given number of times (or once, if no argument
704 * was specified). That is, selects the window you were in before you focused
705 * the current window.
708 static void travel_focus_stack(xcb_connection_t *conn, const char *arguments) {
709 /* Start count at -1 to always skip the first element */
710 int times, count = -1;
713 if (sscanf(arguments, "%u", ×) != 1) {
714 LOG("No or invalid argument given (\"%s\"), using default of 1 times\n", arguments);
718 Workspace *ws = CUR_CELL->workspace;
720 SLIST_FOREACH(current, &(ws->focus_stack), focus_clients) {
721 if (++count < times) {
727 set_focus(conn, current, true);
733 * Parses a command, see file CMDMODE for more information
736 void parse_command(xcb_connection_t *conn, const char *command) {
737 LOG("--- parsing command \"%s\" ---\n", command);
738 /* Hmm, just to be sure */
739 if (command[0] == '\0')
742 /* Is it an <exec>? Then execute the given command. */
743 if (STARTS_WITH(command, "exec ")) {
744 LOG("starting \"%s\"\n", command + strlen("exec "));
745 start_application(command+strlen("exec "));
749 /* Is it an <exit>? */
750 if (STARTS_WITH(command, "exit")) {
751 LOG("User issued exit-command, exiting without error.\n");
755 /* Is it <restart>? Then restart in place. */
756 if (STARTS_WITH(command, "restart")) {
757 LOG("restarting \"%s\"...\n", start_argv[0]);
758 execvp(start_argv[0], start_argv);
762 if (STARTS_WITH(command, "kill")) {
763 if (CUR_CELL->currently_focused == NULL) {
764 LOG("There is no window to kill\n");
768 LOG("Killing current window\n");
769 kill_window(conn, CUR_CELL->currently_focused);
773 /* Is it a jump to a specified workspae, row, col? */
774 if (STARTS_WITH(command, "jump ")) {
775 const char *arguments = command + strlen("jump ");
776 if (arguments[0] == '"')
777 jump_to_window(conn, arguments);
778 else jump_to_container(conn, arguments);
782 /* Should we travel the focus stack? */
783 if (STARTS_WITH(command, "focus")) {
784 const char *arguments = command + strlen("focus");
785 travel_focus_stack(conn, arguments);
789 /* Is it 'f' for fullscreen? */
790 if (command[0] == 'f') {
791 if (CUR_CELL->currently_focused == NULL)
793 toggle_fullscreen(conn, CUR_CELL->currently_focused);
797 /* Is it just 's' for stacking or 'd' for default? */
798 if ((command[0] == 's' || command[0] == 'd') && (command[1] == '\0')) {
799 LOG("Switching mode for current container\n");
800 switch_layout_mode(conn, CUR_CELL, (command[0] == 's' ? MODE_STACK : MODE_DEFAULT));
804 enum { WITH_WINDOW, WITH_CONTAINER } with = WITH_WINDOW;
806 /* Is it a <with>? */
807 if (command[0] == 'w') {
809 /* TODO: implement */
810 if (command[0] == 'c') {
811 with = WITH_CONTAINER;
814 LOG("not yet implemented.\n");
819 /* It's a normal <cmd> */
821 enum { ACTION_FOCUS, ACTION_MOVE, ACTION_SNAP } action = ACTION_FOCUS;
822 direction_t direction;
823 int times = strtol(command, &rest, 10);
825 LOG("Invalid command (\"%s\")\n", command);
830 /* No rest? This was a tag number, not a times specification */
831 show_workspace(conn, times);
835 if (*rest == 'm' || *rest == 's') {
836 action = (*rest == 'm' ? ACTION_MOVE : ACTION_SNAP);
840 int workspace = strtol(rest, &rest, 10);
843 LOG("Invalid command (\"%s\")\n", command);
848 move_current_window_to_workspace(conn, workspace);
852 /* Now perform action to <where> */
853 while (*rest != '\0') {
856 else if (*rest == 'j')
858 else if (*rest == 'k')
860 else if (*rest == 'l')
863 LOG("unknown direction: %c\n", *rest);
867 if (action == ACTION_FOCUS)
868 focus_thing(conn, direction, (with == WITH_WINDOW ? THING_WINDOW : THING_CONTAINER));
869 else if (action == ACTION_MOVE) {
870 if (with == WITH_WINDOW)
871 move_current_window(conn, direction);
872 else move_current_container(conn, direction);
874 else if (action == ACTION_SNAP)
875 snap_current_container(conn, direction);
880 LOG("--- done ---\n");