diff options
author | Tony Crisci <tony@dubstepdish.com> | 2018-01-20 14:10:11 -0500 |
---|---|---|
committer | Tony Crisci <tony@dubstepdish.com> | 2018-01-20 14:10:11 -0500 |
commit | c353e01c85049cfbc09510657e453b6aa5fd9c2d (patch) | |
tree | c6ef14cfc08861ff8c62675ca1fbbbb00e9197cf | |
parent | seat config handler context (diff) | |
download | sway-c353e01c85049cfbc09510657e453b6aa5fd9c2d.tar.gz sway-c353e01c85049cfbc09510657e453b6aa5fd9c2d.tar.zst sway-c353e01c85049cfbc09510657e453b6aa5fd9c2d.zip |
add kill command
-rw-r--r-- | include/sway/config.h | 1 | ||||
-rw-r--r-- | include/sway/input/input-manager.h | 3 | ||||
-rw-r--r-- | include/sway/view.h | 1 | ||||
-rw-r--r-- | sway/commands.c | 1 | ||||
-rw-r--r-- | sway/commands/kill.c | 25 | ||||
-rw-r--r-- | sway/desktop/wl_shell.c | 9 | ||||
-rw-r--r-- | sway/desktop/xdg_shell_v6.c | 11 | ||||
-rw-r--r-- | sway/desktop/xwayland.c | 8 | ||||
-rw-r--r-- | sway/input/input-manager.c | 11 | ||||
-rw-r--r-- | sway/input/keyboard.c | 9 | ||||
-rw-r--r-- | sway/meson.build | 1 |
11 files changed, 77 insertions, 3 deletions
diff --git a/include/sway/config.h b/include/sway/config.h index 27fae0c6..be29082e 100644 --- a/include/sway/config.h +++ b/include/sway/config.h | |||
@@ -355,6 +355,7 @@ struct sway_config { | |||
355 | struct { | 355 | struct { |
356 | struct input_config *input_config; | 356 | struct input_config *input_config; |
357 | struct seat_config *seat_config; | 357 | struct seat_config *seat_config; |
358 | struct sway_seat *seat; | ||
358 | } handler_context; | 359 | } handler_context; |
359 | }; | 360 | }; |
360 | 361 | ||
diff --git a/include/sway/input/input-manager.h b/include/sway/input/input-manager.h index 58a93fe3..2bf297ce 100644 --- a/include/sway/input/input-manager.h +++ b/include/sway/input/input-manager.h | |||
@@ -43,4 +43,7 @@ void sway_input_manager_apply_input_config(struct sway_input_manager *input, | |||
43 | void sway_input_manager_apply_seat_config(struct sway_input_manager *input, | 43 | void sway_input_manager_apply_seat_config(struct sway_input_manager *input, |
44 | struct seat_config *seat_config); | 44 | struct seat_config *seat_config); |
45 | 45 | ||
46 | struct sway_seat *sway_input_manager_get_default_seat( | ||
47 | struct sway_input_manager *input); | ||
48 | |||
46 | #endif | 49 | #endif |
diff --git a/include/sway/view.h b/include/sway/view.h index 08c5480b..240ffaa5 100644 --- a/include/sway/view.h +++ b/include/sway/view.h | |||
@@ -92,6 +92,7 @@ struct sway_view { | |||
92 | void (*set_position)(struct sway_view *view, | 92 | void (*set_position)(struct sway_view *view, |
93 | double ox, double oy); | 93 | double ox, double oy); |
94 | void (*set_activated)(struct sway_view *view, bool activated); | 94 | void (*set_activated)(struct sway_view *view, bool activated); |
95 | void (*close)(struct sway_view *view); | ||
95 | } iface; | 96 | } iface; |
96 | 97 | ||
97 | // only used for unmanaged views (shell specific) | 98 | // only used for unmanaged views (shell specific) |
diff --git a/sway/commands.c b/sway/commands.c index 414ef809..28943963 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -132,6 +132,7 @@ static struct cmd_handler handlers[] = { | |||
132 | { "exit", cmd_exit }, | 132 | { "exit", cmd_exit }, |
133 | { "include", cmd_include }, | 133 | { "include", cmd_include }, |
134 | { "input", cmd_input }, | 134 | { "input", cmd_input }, |
135 | { "kill", cmd_kill }, | ||
135 | { "output", cmd_output }, | 136 | { "output", cmd_output }, |
136 | { "seat", cmd_seat }, | 137 | { "seat", cmd_seat }, |
137 | { "set", cmd_set }, | 138 | { "set", cmd_set }, |
diff --git a/sway/commands/kill.c b/sway/commands/kill.c new file mode 100644 index 00000000..4bbf94e5 --- /dev/null +++ b/sway/commands/kill.c | |||
@@ -0,0 +1,25 @@ | |||
1 | #include "sway/input/input-manager.h" | ||
2 | #include "sway/input/seat.h" | ||
3 | #include "sway/view.h" | ||
4 | #include "sway/commands.h" | ||
5 | |||
6 | struct cmd_results *cmd_kill(int argc, char **argv) { | ||
7 | struct sway_seat *seat = config->handler_context.seat; | ||
8 | if (!seat) { | ||
9 | seat = sway_input_manager_get_default_seat(input_manager); | ||
10 | } | ||
11 | |||
12 | // TODO context for arbitrary sway containers (when we get criteria | ||
13 | // working) will make seat context not explicitly required | ||
14 | if (!seat) { | ||
15 | return cmd_results_new(CMD_FAILURE, NULL, "no seat context given"); | ||
16 | } | ||
17 | |||
18 | struct sway_view *view = seat->focus->sway_view; | ||
19 | |||
20 | if (view->iface.close) { | ||
21 | view->iface.close(view); | ||
22 | } | ||
23 | |||
24 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
25 | } | ||
diff --git a/sway/desktop/wl_shell.c b/sway/desktop/wl_shell.c index e34f5160..0cde6583 100644 --- a/sway/desktop/wl_shell.c +++ b/sway/desktop/wl_shell.c | |||
@@ -51,6 +51,14 @@ static void set_activated(struct sway_view *view, bool activated) { | |||
51 | // no way to activate wl_shell | 51 | // no way to activate wl_shell |
52 | } | 52 | } |
53 | 53 | ||
54 | static void close(struct sway_view *view) { | ||
55 | if (!assert_wl_shell(view)) { | ||
56 | return; | ||
57 | } | ||
58 | |||
59 | wl_client_destroy(view->wlr_wl_shell_surface->client); | ||
60 | } | ||
61 | |||
54 | static void handle_commit(struct wl_listener *listener, void *data) { | 62 | static void handle_commit(struct wl_listener *listener, void *data) { |
55 | struct sway_wl_shell_surface *sway_surface = | 63 | struct sway_wl_shell_surface *sway_surface = |
56 | wl_container_of(listener, sway_surface, commit); | 64 | wl_container_of(listener, sway_surface, commit); |
@@ -103,6 +111,7 @@ void handle_wl_shell_surface(struct wl_listener *listener, void *data) { | |||
103 | sway_view->iface.set_size = set_size; | 111 | sway_view->iface.set_size = set_size; |
104 | sway_view->iface.set_position = set_position; | 112 | sway_view->iface.set_position = set_position; |
105 | sway_view->iface.set_activated = set_activated; | 113 | sway_view->iface.set_activated = set_activated; |
114 | sway_view->iface.close = close; | ||
106 | sway_view->wlr_wl_shell_surface = shell_surface; | 115 | sway_view->wlr_wl_shell_surface = shell_surface; |
107 | sway_view->sway_wl_shell_surface = sway_surface; | 116 | sway_view->sway_wl_shell_surface = sway_surface; |
108 | sway_view->surface = shell_surface->surface; | 117 | sway_view->surface = shell_surface->surface; |
diff --git a/sway/desktop/xdg_shell_v6.c b/sway/desktop/xdg_shell_v6.c index df48345c..4b50093f 100644 --- a/sway/desktop/xdg_shell_v6.c +++ b/sway/desktop/xdg_shell_v6.c | |||
@@ -57,6 +57,16 @@ static void set_activated(struct sway_view *view, bool activated) { | |||
57 | } | 57 | } |
58 | } | 58 | } |
59 | 59 | ||
60 | static void close(struct sway_view *view) { | ||
61 | if (!assert_xdg(view)) { | ||
62 | return; | ||
63 | } | ||
64 | struct wlr_xdg_surface_v6 *surface = view->wlr_xdg_surface_v6; | ||
65 | if (surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL) { | ||
66 | wlr_xdg_toplevel_v6_send_close(surface); | ||
67 | } | ||
68 | } | ||
69 | |||
60 | static void handle_commit(struct wl_listener *listener, void *data) { | 70 | static void handle_commit(struct wl_listener *listener, void *data) { |
61 | struct sway_xdg_surface_v6 *sway_surface = | 71 | struct sway_xdg_surface_v6 *sway_surface = |
62 | wl_container_of(listener, sway_surface, commit); | 72 | wl_container_of(listener, sway_surface, commit); |
@@ -107,6 +117,7 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) { | |||
107 | sway_view->iface.set_size = set_size; | 117 | sway_view->iface.set_size = set_size; |
108 | sway_view->iface.set_position = set_position; | 118 | sway_view->iface.set_position = set_position; |
109 | sway_view->iface.set_activated = set_activated; | 119 | sway_view->iface.set_activated = set_activated; |
120 | sway_view->iface.close = close; | ||
110 | sway_view->wlr_xdg_surface_v6 = xdg_surface; | 121 | sway_view->wlr_xdg_surface_v6 = xdg_surface; |
111 | sway_view->sway_xdg_surface_v6 = sway_surface; | 122 | sway_view->sway_xdg_surface_v6 = sway_surface; |
112 | sway_view->surface = xdg_surface->surface; | 123 | sway_view->surface = xdg_surface->surface; |
diff --git a/sway/desktop/xwayland.c b/sway/desktop/xwayland.c index a4d9687d..7603d3ca 100644 --- a/sway/desktop/xwayland.c +++ b/sway/desktop/xwayland.c | |||
@@ -80,6 +80,13 @@ static void set_activated(struct sway_view *view, bool activated) { | |||
80 | wlr_xwayland_surface_activate(surface, activated); | 80 | wlr_xwayland_surface_activate(surface, activated); |
81 | } | 81 | } |
82 | 82 | ||
83 | static void close(struct sway_view *view) { | ||
84 | if (!assert_xwayland(view)) { | ||
85 | return; | ||
86 | } | ||
87 | wlr_xwayland_surface_close(view->wlr_xwayland_surface); | ||
88 | } | ||
89 | |||
83 | static void handle_commit(struct wl_listener *listener, void *data) { | 90 | static void handle_commit(struct wl_listener *listener, void *data) { |
84 | struct sway_xwayland_surface *sway_surface = | 91 | struct sway_xwayland_surface *sway_surface = |
85 | wl_container_of(listener, sway_surface, commit); | 92 | wl_container_of(listener, sway_surface, commit); |
@@ -192,6 +199,7 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) { | |||
192 | sway_view->iface.set_size = set_size; | 199 | sway_view->iface.set_size = set_size; |
193 | sway_view->iface.set_position = set_position; | 200 | sway_view->iface.set_position = set_position; |
194 | sway_view->iface.set_activated = set_activated; | 201 | sway_view->iface.set_activated = set_activated; |
202 | sway_view->iface.close = close; | ||
195 | sway_view->wlr_xwayland_surface = xsurface; | 203 | sway_view->wlr_xwayland_surface = xsurface; |
196 | sway_view->sway_xwayland_surface = sway_surface; | 204 | sway_view->sway_xwayland_surface = sway_surface; |
197 | sway_view->surface = xsurface->surface; | 205 | sway_view->surface = xsurface->surface; |
diff --git a/sway/input/input-manager.c b/sway/input/input-manager.c index 26cf5035..7b19991b 100644 --- a/sway/input/input-manager.c +++ b/sway/input/input-manager.c | |||
@@ -369,3 +369,14 @@ void sway_input_manager_configure_xcursor(struct sway_input_manager *input) { | |||
369 | sway_seat_configure_xcursor(seat); | 369 | sway_seat_configure_xcursor(seat); |
370 | } | 370 | } |
371 | } | 371 | } |
372 | |||
373 | struct sway_seat *sway_input_manager_get_default_seat( | ||
374 | struct sway_input_manager *input) { | ||
375 | struct sway_seat *seat = NULL; | ||
376 | wl_list_for_each(seat, &input->seats, link) { | ||
377 | if (strcmp(seat->wlr_seat->name, "seat0") == 0) { | ||
378 | return seat; | ||
379 | } | ||
380 | } | ||
381 | return seat; | ||
382 | } | ||
diff --git a/sway/input/keyboard.c b/sway/input/keyboard.c index 5827a1ca..6dc57d46 100644 --- a/sway/input/keyboard.c +++ b/sway/input/keyboard.c | |||
@@ -89,9 +89,12 @@ static bool binding_matches_key_state(struct sway_binding *binding, | |||
89 | return false; | 89 | return false; |
90 | } | 90 | } |
91 | 91 | ||
92 | static void binding_execute_command(struct sway_binding *binding) { | 92 | static void keyboard_execute_command(struct sway_keyboard *keyboard, |
93 | struct sway_binding *binding) { | ||
93 | wlr_log(L_DEBUG, "running command for binding: %s", | 94 | wlr_log(L_DEBUG, "running command for binding: %s", |
94 | binding->command); | 95 | binding->command); |
96 | config_clear_handler_context(config); | ||
97 | config->handler_context.seat = keyboard->seat_device->sway_seat; | ||
95 | struct cmd_results *results = handle_command(binding->command); | 98 | struct cmd_results *results = handle_command(binding->command); |
96 | if (results->status != CMD_SUCCESS) { | 99 | if (results->status != CMD_SUCCESS) { |
97 | wlr_log(L_DEBUG, "could not run command for binding: %s", | 100 | wlr_log(L_DEBUG, "could not run command for binding: %s", |
@@ -160,7 +163,7 @@ static bool keyboard_execute_bindsym(struct sway_keyboard *keyboard, | |||
160 | } | 163 | } |
161 | 164 | ||
162 | if (match) { | 165 | if (match) { |
163 | binding_execute_command(binding); | 166 | keyboard_execute_command(keyboard, binding); |
164 | return true; | 167 | return true; |
165 | } | 168 | } |
166 | } | 169 | } |
@@ -267,7 +270,7 @@ static bool keyboard_execute_bindcode(struct sway_keyboard *keyboard, | |||
267 | for (int i = 0; i < keycode_bindings->length; ++i) { | 270 | for (int i = 0; i < keycode_bindings->length; ++i) { |
268 | struct sway_binding *binding = keycode_bindings->items[i]; | 271 | struct sway_binding *binding = keycode_bindings->items[i]; |
269 | if (binding_matches_keycodes(wlr_keyboard, binding, event)) { | 272 | if (binding_matches_keycodes(wlr_keyboard, binding, event)) { |
270 | binding_execute_command(binding); | 273 | keyboard_execute_command(keyboard, binding); |
271 | return true; | 274 | return true; |
272 | } | 275 | } |
273 | } | 276 | } |
diff --git a/sway/meson.build b/sway/meson.build index 30ec166b..d5dead42 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/kill.c', | ||
13 | 'commands/include.c', | 14 | 'commands/include.c', |
14 | 'commands/input.c', | 15 | 'commands/input.c', |
15 | 'commands/seat.c', | 16 | 'commands/seat.c', |