diff options
-rw-r--r-- | sway/commands.c | 2 | ||||
-rw-r--r-- | sway/commands/focus.c | 41 |
2 files changed, 41 insertions, 2 deletions
diff --git a/sway/commands.c b/sway/commands.c index a3e6a500..73c968ea 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -103,6 +103,7 @@ static struct cmd_handler handlers[] = { | |||
103 | { "exec_always", cmd_exec_always }, | 103 | { "exec_always", cmd_exec_always }, |
104 | { "floating_maximum_size", cmd_floating_maximum_size }, | 104 | { "floating_maximum_size", cmd_floating_maximum_size }, |
105 | { "floating_minimum_size", cmd_floating_minimum_size }, | 105 | { "floating_minimum_size", cmd_floating_minimum_size }, |
106 | { "focus", cmd_focus }, | ||
106 | { "focus_follows_mouse", cmd_focus_follows_mouse }, | 107 | { "focus_follows_mouse", cmd_focus_follows_mouse }, |
107 | { "focus_wrapping", cmd_focus_wrapping }, | 108 | { "focus_wrapping", cmd_focus_wrapping }, |
108 | { "font", cmd_font }, | 109 | { "font", cmd_font }, |
@@ -137,7 +138,6 @@ static struct cmd_handler command_handlers[] = { | |||
137 | { "border", cmd_border }, | 138 | { "border", cmd_border }, |
138 | { "exit", cmd_exit }, | 139 | { "exit", cmd_exit }, |
139 | { "floating", cmd_floating }, | 140 | { "floating", cmd_floating }, |
140 | { "focus", cmd_focus }, | ||
141 | { "fullscreen", cmd_fullscreen }, | 141 | { "fullscreen", cmd_fullscreen }, |
142 | { "kill", cmd_kill }, | 142 | { "kill", cmd_kill }, |
143 | { "layout", cmd_layout }, | 143 | { "layout", cmd_layout }, |
diff --git a/sway/commands/focus.c b/sway/commands/focus.c index b24d5007..9cd8bfae 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,7 +46,40 @@ 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 (!parse_movement_direction(identifier, &direction) || | ||
61 | direction == MOVE_PARENT || direction == MOVE_CHILD) { | ||
62 | free(identifier); | ||
63 | return cmd_results_new(CMD_INVALID, "focus", | ||
64 | "There is no output with that name"); | ||
65 | } | ||
66 | struct sway_container *focus = seat_get_focus(seat); | ||
67 | focus = container_parent(focus, C_OUTPUT); | ||
68 | output = container_get_in_direction(focus, seat, direction); | ||
69 | } | ||
70 | |||
71 | free(identifier); | ||
72 | if (output) { | ||
73 | seat_set_focus(seat, seat_get_focus_inactive(seat, output)); | ||
74 | } | ||
75 | |||
76 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
77 | } | ||
78 | |||
47 | struct cmd_results *cmd_focus(int argc, char **argv) { | 79 | struct cmd_results *cmd_focus(int argc, char **argv) { |
80 | if (config->reading || !config->active) { | ||
81 | return cmd_results_new(CMD_DEFER, NULL, NULL); | ||
82 | } | ||
48 | struct sway_container *con = config->handler_context.current_container; | 83 | struct sway_container *con = config->handler_context.current_container; |
49 | struct sway_seat *seat = config->handler_context.seat; | 84 | struct sway_seat *seat = config->handler_context.seat; |
50 | if (con->type < C_WORKSPACE) { | 85 | if (con->type < C_WORKSPACE) { |
@@ -65,7 +100,11 @@ struct cmd_results *cmd_focus(int argc, char **argv) { | |||
65 | return focus_mode(con, seat, !container_is_floating(con)); | 100 | return focus_mode(con, seat, !container_is_floating(con)); |
66 | } | 101 | } |
67 | 102 | ||
68 | // TODO: focus output <direction|name> | 103 | if (strcmp(argv[0], "output") == 0) { |
104 | argc--; argv++; | ||
105 | return focus_output(con, seat, argc, argv); | ||
106 | } | ||
107 | |||
69 | enum movement_direction direction = 0; | 108 | enum movement_direction direction = 0; |
70 | if (!parse_movement_direction(argv[0], &direction)) { | 109 | if (!parse_movement_direction(argv[0], &direction)) { |
71 | return cmd_results_new(CMD_INVALID, "focus", | 110 | return cmd_results_new(CMD_INVALID, "focus", |