Add support for closing windows

This commit is contained in:
project-repo 2020-08-25 15:15:31 +02:00
commit 73e8db1fa3
6 changed files with 29 additions and 0 deletions

View file

@ -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 "

View file

@ -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

View file

@ -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;

1
view.h
View file

@ -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,

View file

@ -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,

View file

@ -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,