diff --git a/keybinding.c b/keybinding.c index ce80ba5..2add7bd 100644 --- a/keybinding.c +++ b/keybinding.c @@ -549,6 +549,11 @@ keybinding_split_output(struct cg_output *output, bool vertical) { } } +static void +keybinding_close_view(struct cg_view *view) { + view->impl->close(view); +} + static void keybinding_split_vertical(struct cg_server *server) { keybinding_split_output(server->curr_output, true); @@ -964,6 +969,9 @@ run_action(enum keybinding_action action, struct cg_server *server, case KEYBINDING_CONFIGURE_OUTPUT: keybinding_configure_output(server, data.o_cfg); break; + case KEYBINDING_CLOSE_VIEW: + keybinding_close_view(server->curr_output->workspaces[server->curr_output->curr_workspace]->focused_tile->view); + break; default: { wlr_log(WLR_ERROR, "run_action was called with a value not present in \"enum " diff --git a/keybinding.h b/keybinding.h index cd48840..03ff491 100644 --- a/keybinding.h +++ b/keybinding.h @@ -14,6 +14,7 @@ struct cg_server; * in keybinding.c */ enum keybinding_action { KEYBINDING_RUN_COMMAND, // data.c is the string to execute + KEYBINDING_CLOSE_VIEW, KEYBINDING_SPLIT_VERTICAL, KEYBINDING_SPLIT_HORIZONTAL, KEYBINDING_CHANGE_TTY, // data.u is the desired tty diff --git a/parse.c b/parse.c index ff1f8c0..c7cccb4 100644 --- a/parse.c +++ b/parse.c @@ -364,6 +364,8 @@ parse_command(struct cg_server *server, struct keybinding *keybinding, keybinding->action = KEYBINDING_SPLIT_HORIZONTAL; } else if(strcmp(action, "quit") == 0) { keybinding->action = KEYBINDING_QUIT; + } else if(strcmp(action, "close") == 0) { + keybinding->action = KEYBINDING_CLOSE_VIEW; } else if(strcmp(action, "focus") == 0) { keybinding->action = KEYBINDING_CYCLE_TILES; keybinding->data.b = false; diff --git a/view.h b/view.h index b7cc426..8ddfa0b 100644 --- a/view.h +++ b/view.h @@ -39,6 +39,7 @@ struct cg_view_impl { int *height_out); bool (*is_primary)(const struct cg_view *view); void (*activate)(struct cg_view *view, bool activate); + void (*close)(struct cg_view *view); void (*maximize)(struct cg_view *view, int width, int height); void (*destroy)(struct cg_view *view); void (*for_each_surface)(struct cg_view *view, diff --git a/xdg_shell.c b/xdg_shell.c index a6d850c..94506a8 100644 --- a/xdg_shell.c +++ b/xdg_shell.c @@ -214,6 +214,15 @@ activate(struct cg_view *view, bool activate) { wlr_xdg_toplevel_set_activated(xdg_shell_view->xdg_surface, activate); } +static void +close(struct cg_view *view) { + struct cg_xdg_shell_view *xdg_shell_view = xdg_shell_view_from_view(view); + struct wlr_xdg_surface *surface=xdg_shell_view->xdg_surface; + if(surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL) { + wlr_xdg_toplevel_send_close(surface); + } +} + static void maximize(struct cg_view *view, int width, int height) { struct cg_xdg_shell_view *xdg_shell_view = xdg_shell_view_from_view(view); @@ -317,6 +326,7 @@ static const struct cg_view_impl xdg_shell_view_impl = { .get_geometry = get_geometry, .is_primary = is_primary, .activate = activate, + .close = close, .maximize = maximize, .destroy = destroy, .for_each_surface = for_each_surface, diff --git a/xwayland.c b/xwayland.c index 9256945..0fece9a 100644 --- a/xwayland.c +++ b/xwayland.c @@ -73,6 +73,12 @@ activate(struct cg_view *view, bool activate) { wlr_xwayland_surface_activate(xwayland_view->xwayland_surface, activate); } +static void +close(struct cg_view *view) { + struct cg_xwayland_view *xwayland_view = xwayland_view_from_view(view); + wlr_xwayland_surface_close(xwayland_view->xwayland_surface); +} + static void maximize(struct cg_view *view, int width, int height) { struct cg_xwayland_view *xwayland_view = xwayland_view_from_view(view); @@ -198,6 +204,7 @@ static const struct cg_view_impl xwayland_view_impl = { .get_geometry = get_geometry, .is_primary = is_primary, .activate = activate, + .close = close, .maximize = maximize, .destroy = destroy, .for_each_surface = for_each_surface,