add kill command

This commit is contained in:
Tony Crisci 2018-01-20 14:10:11 -05:00
parent cc3c713889
commit c353e01c85
11 changed files with 77 additions and 3 deletions

View file

@ -355,6 +355,7 @@ struct sway_config {
struct { struct {
struct input_config *input_config; struct input_config *input_config;
struct seat_config *seat_config; struct seat_config *seat_config;
struct sway_seat *seat;
} handler_context; } handler_context;
}; };

View file

@ -43,4 +43,7 @@ void sway_input_manager_apply_input_config(struct sway_input_manager *input,
void sway_input_manager_apply_seat_config(struct sway_input_manager *input, void sway_input_manager_apply_seat_config(struct sway_input_manager *input,
struct seat_config *seat_config); struct seat_config *seat_config);
struct sway_seat *sway_input_manager_get_default_seat(
struct sway_input_manager *input);
#endif #endif

View file

@ -92,6 +92,7 @@ struct sway_view {
void (*set_position)(struct sway_view *view, void (*set_position)(struct sway_view *view,
double ox, double oy); double ox, double oy);
void (*set_activated)(struct sway_view *view, bool activated); void (*set_activated)(struct sway_view *view, bool activated);
void (*close)(struct sway_view *view);
} iface; } iface;
// only used for unmanaged views (shell specific) // only used for unmanaged views (shell specific)

View file

@ -132,6 +132,7 @@ static struct cmd_handler handlers[] = {
{ "exit", cmd_exit }, { "exit", cmd_exit },
{ "include", cmd_include }, { "include", cmd_include },
{ "input", cmd_input }, { "input", cmd_input },
{ "kill", cmd_kill },
{ "output", cmd_output }, { "output", cmd_output },
{ "seat", cmd_seat }, { "seat", cmd_seat },
{ "set", cmd_set }, { "set", cmd_set },

25
sway/commands/kill.c Normal file
View file

@ -0,0 +1,25 @@
#include "sway/input/input-manager.h"
#include "sway/input/seat.h"
#include "sway/view.h"
#include "sway/commands.h"
struct cmd_results *cmd_kill(int argc, char **argv) {
struct sway_seat *seat = config->handler_context.seat;
if (!seat) {
seat = sway_input_manager_get_default_seat(input_manager);
}
// TODO context for arbitrary sway containers (when we get criteria
// working) will make seat context not explicitly required
if (!seat) {
return cmd_results_new(CMD_FAILURE, NULL, "no seat context given");
}
struct sway_view *view = seat->focus->sway_view;
if (view->iface.close) {
view->iface.close(view);
}
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
}

View file

@ -51,6 +51,14 @@ static void set_activated(struct sway_view *view, bool activated) {
// no way to activate wl_shell // no way to activate wl_shell
} }
static void close(struct sway_view *view) {
if (!assert_wl_shell(view)) {
return;
}
wl_client_destroy(view->wlr_wl_shell_surface->client);
}
static void handle_commit(struct wl_listener *listener, void *data) { static void handle_commit(struct wl_listener *listener, void *data) {
struct sway_wl_shell_surface *sway_surface = struct sway_wl_shell_surface *sway_surface =
wl_container_of(listener, sway_surface, commit); wl_container_of(listener, sway_surface, commit);
@ -103,6 +111,7 @@ void handle_wl_shell_surface(struct wl_listener *listener, void *data) {
sway_view->iface.set_size = set_size; sway_view->iface.set_size = set_size;
sway_view->iface.set_position = set_position; sway_view->iface.set_position = set_position;
sway_view->iface.set_activated = set_activated; sway_view->iface.set_activated = set_activated;
sway_view->iface.close = close;
sway_view->wlr_wl_shell_surface = shell_surface; sway_view->wlr_wl_shell_surface = shell_surface;
sway_view->sway_wl_shell_surface = sway_surface; sway_view->sway_wl_shell_surface = sway_surface;
sway_view->surface = shell_surface->surface; sway_view->surface = shell_surface->surface;

View file

@ -57,6 +57,16 @@ static void set_activated(struct sway_view *view, bool activated) {
} }
} }
static void close(struct sway_view *view) {
if (!assert_xdg(view)) {
return;
}
struct wlr_xdg_surface_v6 *surface = view->wlr_xdg_surface_v6;
if (surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL) {
wlr_xdg_toplevel_v6_send_close(surface);
}
}
static void handle_commit(struct wl_listener *listener, void *data) { static void handle_commit(struct wl_listener *listener, void *data) {
struct sway_xdg_surface_v6 *sway_surface = struct sway_xdg_surface_v6 *sway_surface =
wl_container_of(listener, sway_surface, commit); wl_container_of(listener, sway_surface, commit);
@ -107,6 +117,7 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) {
sway_view->iface.set_size = set_size; sway_view->iface.set_size = set_size;
sway_view->iface.set_position = set_position; sway_view->iface.set_position = set_position;
sway_view->iface.set_activated = set_activated; sway_view->iface.set_activated = set_activated;
sway_view->iface.close = close;
sway_view->wlr_xdg_surface_v6 = xdg_surface; sway_view->wlr_xdg_surface_v6 = xdg_surface;
sway_view->sway_xdg_surface_v6 = sway_surface; sway_view->sway_xdg_surface_v6 = sway_surface;
sway_view->surface = xdg_surface->surface; sway_view->surface = xdg_surface->surface;

View file

@ -80,6 +80,13 @@ static void set_activated(struct sway_view *view, bool activated) {
wlr_xwayland_surface_activate(surface, activated); wlr_xwayland_surface_activate(surface, activated);
} }
static void close(struct sway_view *view) {
if (!assert_xwayland(view)) {
return;
}
wlr_xwayland_surface_close(view->wlr_xwayland_surface);
}
static void handle_commit(struct wl_listener *listener, void *data) { static void handle_commit(struct wl_listener *listener, void *data) {
struct sway_xwayland_surface *sway_surface = struct sway_xwayland_surface *sway_surface =
wl_container_of(listener, sway_surface, commit); wl_container_of(listener, sway_surface, commit);
@ -192,6 +199,7 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) {
sway_view->iface.set_size = set_size; sway_view->iface.set_size = set_size;
sway_view->iface.set_position = set_position; sway_view->iface.set_position = set_position;
sway_view->iface.set_activated = set_activated; sway_view->iface.set_activated = set_activated;
sway_view->iface.close = close;
sway_view->wlr_xwayland_surface = xsurface; sway_view->wlr_xwayland_surface = xsurface;
sway_view->sway_xwayland_surface = sway_surface; sway_view->sway_xwayland_surface = sway_surface;
sway_view->surface = xsurface->surface; sway_view->surface = xsurface->surface;

View file

@ -369,3 +369,14 @@ void sway_input_manager_configure_xcursor(struct sway_input_manager *input) {
sway_seat_configure_xcursor(seat); sway_seat_configure_xcursor(seat);
} }
} }
struct sway_seat *sway_input_manager_get_default_seat(
struct sway_input_manager *input) {
struct sway_seat *seat = NULL;
wl_list_for_each(seat, &input->seats, link) {
if (strcmp(seat->wlr_seat->name, "seat0") == 0) {
return seat;
}
}
return seat;
}

View file

@ -89,9 +89,12 @@ static bool binding_matches_key_state(struct sway_binding *binding,
return false; return false;
} }
static void binding_execute_command(struct sway_binding *binding) { static void keyboard_execute_command(struct sway_keyboard *keyboard,
struct sway_binding *binding) {
wlr_log(L_DEBUG, "running command for binding: %s", wlr_log(L_DEBUG, "running command for binding: %s",
binding->command); binding->command);
config_clear_handler_context(config);
config->handler_context.seat = keyboard->seat_device->sway_seat;
struct cmd_results *results = handle_command(binding->command); struct cmd_results *results = handle_command(binding->command);
if (results->status != CMD_SUCCESS) { if (results->status != CMD_SUCCESS) {
wlr_log(L_DEBUG, "could not run command for binding: %s", wlr_log(L_DEBUG, "could not run command for binding: %s",
@ -160,7 +163,7 @@ static bool keyboard_execute_bindsym(struct sway_keyboard *keyboard,
} }
if (match) { if (match) {
binding_execute_command(binding); keyboard_execute_command(keyboard, binding);
return true; return true;
} }
} }
@ -267,7 +270,7 @@ static bool keyboard_execute_bindcode(struct sway_keyboard *keyboard,
for (int i = 0; i < keycode_bindings->length; ++i) { for (int i = 0; i < keycode_bindings->length; ++i) {
struct sway_binding *binding = keycode_bindings->items[i]; struct sway_binding *binding = keycode_bindings->items[i];
if (binding_matches_keycodes(wlr_keyboard, binding, event)) { if (binding_matches_keycodes(wlr_keyboard, binding, event)) {
binding_execute_command(binding); keyboard_execute_command(keyboard, binding);
return true; return true;
} }
} }

View file

@ -10,6 +10,7 @@ sway_sources = files(
'commands/exit.c', 'commands/exit.c',
'commands/exec.c', 'commands/exec.c',
'commands/exec_always.c', 'commands/exec_always.c',
'commands/kill.c',
'commands/include.c', 'commands/include.c',
'commands/input.c', 'commands/input.c',
'commands/seat.c', 'commands/seat.c',