diff options
author | Ryan Dwyer <ryandwyer1@gmail.com> | 2018-07-19 16:33:27 +1000 |
---|---|---|
committer | Ryan Dwyer <ryandwyer1@gmail.com> | 2018-07-19 16:33:27 +1000 |
commit | a173b79c5493d196f1414ab379d393c5f07840bc (patch) | |
tree | faa1056133c74674058b13d5226b14c64687ef9b | |
parent | Merge pull request #2300 from emersion/override-redirect-updates (diff) | |
download | sway-a173b79c5493d196f1414ab379d393c5f07840bc.tar.gz sway-a173b79c5493d196f1414ab379d393c5f07840bc.tar.zst sway-a173b79c5493d196f1414ab379d393c5f07840bc.zip |
Implement focus output command
-rw-r--r-- | sway/commands/focus.c | 45 |
1 files changed, 44 insertions, 1 deletions
diff --git a/sway/commands/focus.c b/sway/commands/focus.c index b24d5007..2426a7f4 100644 --- a/sway/commands/focus.c +++ b/sway/commands/focus.c | |||
@@ -4,9 +4,11 @@ | |||
4 | #include "sway/commands.h" | 4 | #include "sway/commands.h" |
5 | #include "sway/input/input-manager.h" | 5 | #include "sway/input/input-manager.h" |
6 | #include "sway/input/seat.h" | 6 | #include "sway/input/seat.h" |
7 | #include "sway/output.h" | ||
7 | #include "sway/tree/arrange.h" | 8 | #include "sway/tree/arrange.h" |
8 | #include "sway/tree/view.h" | 9 | #include "sway/tree/view.h" |
9 | #include "sway/tree/workspace.h" | 10 | #include "sway/tree/workspace.h" |
11 | #include "stringop.h" | ||
10 | 12 | ||
11 | static bool parse_movement_direction(const char *name, | 13 | static bool parse_movement_direction(const char *name, |
12 | enum movement_direction *out) { | 14 | enum movement_direction *out) { |
@@ -44,6 +46,43 @@ static struct cmd_results *focus_mode(struct sway_container *con, | |||
44 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 46 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); |
45 | } | 47 | } |
46 | 48 | ||
49 | static struct cmd_results *focus_output(struct sway_container *con, | ||
50 | struct sway_seat *seat, int argc, char **argv) { | ||
51 | if (!argc) { | ||
52 | return cmd_results_new(CMD_INVALID, "focus", | ||
53 | "Expected 'focus output <direction|name>'"); | ||
54 | } | ||
55 | char *identifier = join_args(argv, argc); | ||
56 | struct sway_container *output = output_by_name(identifier); | ||
57 | |||
58 | if (!output) { | ||
59 | enum movement_direction direction; | ||
60 | if (strcmp(identifier, "left") == 0) { | ||
61 | direction = MOVE_LEFT; | ||
62 | } else if (strcmp(identifier, "right") == 0) { | ||
63 | direction = MOVE_RIGHT; | ||
64 | } else if (strcmp(identifier, "up") == 0) { | ||
65 | direction = MOVE_UP; | ||
66 | } else if (strcmp(identifier, "down") == 0) { | ||
67 | direction = MOVE_DOWN; | ||
68 | } else { | ||
69 | free(identifier); | ||
70 | return cmd_results_new(CMD_INVALID, "focus", | ||
71 | "There is no output with that name"); | ||
72 | } | ||
73 | struct sway_container *focus = seat_get_focus(seat); | ||
74 | focus = container_parent(focus, C_OUTPUT); | ||
75 | output = container_get_in_direction(focus, seat, direction); | ||
76 | } | ||
77 | |||
78 | free(identifier); | ||
79 | if (output) { | ||
80 | seat_set_focus(seat, seat_get_focus_inactive(seat, output)); | ||
81 | } | ||
82 | |||
83 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
84 | } | ||
85 | |||
47 | struct cmd_results *cmd_focus(int argc, char **argv) { | 86 | struct cmd_results *cmd_focus(int argc, char **argv) { |
48 | struct sway_container *con = config->handler_context.current_container; | 87 | struct sway_container *con = config->handler_context.current_container; |
49 | struct sway_seat *seat = config->handler_context.seat; | 88 | struct sway_seat *seat = config->handler_context.seat; |
@@ -65,7 +104,11 @@ struct cmd_results *cmd_focus(int argc, char **argv) { | |||
65 | return focus_mode(con, seat, !container_is_floating(con)); | 104 | return focus_mode(con, seat, !container_is_floating(con)); |
66 | } | 105 | } |
67 | 106 | ||
68 | // TODO: focus output <direction|name> | 107 | if (strcmp(argv[0], "output") == 0) { |
108 | argc--; argv++; | ||
109 | return focus_output(con, seat, argc, argv); | ||
110 | } | ||
111 | |||
69 | enum movement_direction direction = 0; | 112 | enum movement_direction direction = 0; |
70 | if (!parse_movement_direction(argv[0], &direction)) { | 113 | if (!parse_movement_direction(argv[0], &direction)) { |
71 | return cmd_results_new(CMD_INVALID, "focus", | 114 | return cmd_results_new(CMD_INVALID, "focus", |