aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sway/commands.c1
-rw-r--r--sway/commands/focus.c32
-rw-r--r--sway/ipc-server.c1
-rw-r--r--sway/meson.build1
4 files changed, 35 insertions, 0 deletions
diff --git a/sway/commands.c b/sway/commands.c
index d8d29a1c..bc2a85d7 100644
--- a/sway/commands.c
+++ b/sway/commands.c
@@ -132,6 +132,7 @@ static struct cmd_handler handlers[] = {
132 { "exec", cmd_exec }, 132 { "exec", cmd_exec },
133 { "exec_always", cmd_exec_always }, 133 { "exec_always", cmd_exec_always },
134 { "exit", cmd_exit }, 134 { "exit", cmd_exit },
135 { "focus", cmd_focus },
135 { "include", cmd_include }, 136 { "include", cmd_include },
136 { "input", cmd_input }, 137 { "input", cmd_input },
137 { "kill", cmd_kill }, 138 { "kill", cmd_kill },
diff --git a/sway/commands/focus.c b/sway/commands/focus.c
new file mode 100644
index 00000000..5286851f
--- /dev/null
+++ b/sway/commands/focus.c
@@ -0,0 +1,32 @@
1#include <wlr/util/log.h>
2#include "log.h"
3#include "sway/input/input-manager.h"
4#include "sway/input/seat.h"
5#include "sway/view.h"
6#include "sway/commands.h"
7
8struct cmd_results *cmd_focus(int argc, char **argv) {
9 swayc_t *con = config->handler_context.current_container;
10 struct sway_seat *seat = config->handler_context.seat;
11
12 if (!sway_assert(seat, "'focus' command called without seat context")) {
13 return cmd_results_new(CMD_FAILURE, "focus",
14 "Command 'focus' called without seat context (this is a bug in sway)");
15 }
16
17 if (config->reading) {
18 return cmd_results_new(CMD_FAILURE, "focus",
19 "Command 'focus' cannot be used in the config file");
20 }
21 if (con == NULL) {
22 wlr_log(L_DEBUG, "no container to focus");
23 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
24 }
25
26 if (argc == 0) {
27 sway_seat_set_focus(seat, con);
28 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
29 }
30
31 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
32}
diff --git a/sway/ipc-server.c b/sway/ipc-server.c
index a16a2b80..ee259c99 100644
--- a/sway/ipc-server.c
+++ b/sway/ipc-server.c
@@ -336,6 +336,7 @@ void ipc_client_handle_command(struct ipc_client *client) {
336 case IPC_COMMAND: 336 case IPC_COMMAND:
337 { 337 {
338 config_clear_handler_context(config); 338 config_clear_handler_context(config);
339 config->handler_context.seat = input_manager_current_seat(input_manager);
339 struct cmd_results *results = handle_command(buf); 340 struct cmd_results *results = handle_command(buf);
340 const char *json = cmd_results_to_json(results); 341 const char *json = cmd_results_to_json(results);
341 char reply[256]; 342 char reply[256];
diff --git a/sway/meson.build b/sway/meson.build
index 271d4a99..8d5a97d2 100644
--- a/sway/meson.build
+++ b/sway/meson.build
@@ -10,6 +10,7 @@ sway_sources = files(
10 'commands/exit.c', 10 'commands/exit.c',
11 'commands/exec.c', 11 'commands/exec.c',
12 'commands/exec_always.c', 12 'commands/exec_always.c',
13 'commands/focus.c',
13 'commands/kill.c', 14 'commands/kill.c',
14 'commands/include.c', 15 'commands/include.c',
15 'commands/input.c', 16 'commands/input.c',