Merge pull request #224 from emersion/rootston-commands
Add command to close views
This commit is contained in:
commit
b351e0a950
|
@ -81,7 +81,7 @@ struct roots_input {
|
||||||
struct wlr_seat *wl_seat;
|
struct wlr_seat *wl_seat;
|
||||||
|
|
||||||
enum roots_cursor_mode mode;
|
enum roots_cursor_mode mode;
|
||||||
struct roots_view *active_view;
|
struct roots_view *active_view, *last_active_view;
|
||||||
int offs_x, offs_y;
|
int offs_x, offs_y;
|
||||||
int view_x, view_y, view_width, view_height;
|
int view_x, view_y, view_width, view_height;
|
||||||
float view_rotation;
|
float view_rotation;
|
||||||
|
|
|
@ -65,11 +65,13 @@ struct roots_view {
|
||||||
void (*get_input_bounds)(struct roots_view *view, struct wlr_box *box);
|
void (*get_input_bounds)(struct roots_view *view, struct wlr_box *box);
|
||||||
void (*activate)(struct roots_view *view, bool active);
|
void (*activate)(struct roots_view *view, bool active);
|
||||||
void (*resize)(struct roots_view *view, uint32_t width, uint32_t height);
|
void (*resize)(struct roots_view *view, uint32_t width, uint32_t height);
|
||||||
|
void (*close)(struct roots_view *view);
|
||||||
};
|
};
|
||||||
|
|
||||||
void view_get_size(struct roots_view *view, struct wlr_box *box);
|
void view_get_size(struct roots_view *view, struct wlr_box *box);
|
||||||
void view_get_input_bounds(struct roots_view *view, struct wlr_box *box);
|
void view_get_input_bounds(struct roots_view *view, struct wlr_box *box);
|
||||||
void view_activate(struct roots_view *view, bool active);
|
void view_activate(struct roots_view *view, bool active);
|
||||||
void view_resize(struct roots_view *view, uint32_t width, uint32_t height);
|
void view_resize(struct roots_view *view, uint32_t width, uint32_t height);
|
||||||
|
void view_close(struct roots_view *view);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -172,4 +172,9 @@ void wlr_xdg_toplevel_v6_set_fullscreen(struct wlr_xdg_surface_v6 *surface,
|
||||||
void wlr_xdg_toplevel_v6_set_resizing(struct wlr_xdg_surface_v6 *surface,
|
void wlr_xdg_toplevel_v6_set_resizing(struct wlr_xdg_surface_v6 *surface,
|
||||||
bool resizing);
|
bool resizing);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request that this toplevel surface closes.
|
||||||
|
*/
|
||||||
|
void wlr_xdg_toplevel_v6_send_close(struct wlr_xdg_surface_v6 *surface);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -133,6 +133,7 @@ static void set_view_focus(struct roots_input *input,
|
||||||
if (!view) {
|
if (!view) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
input->last_active_view = view;
|
||||||
|
|
||||||
size_t index = 0;
|
size_t index = 0;
|
||||||
for (size_t i = 0; i < desktop->views->length; ++i) {
|
for (size_t i = 0; i < desktop->views->length; ++i) {
|
||||||
|
|
|
@ -16,6 +16,16 @@
|
||||||
|
|
||||||
void view_destroy(struct roots_view *view) {
|
void view_destroy(struct roots_view *view) {
|
||||||
struct roots_desktop *desktop = view->desktop;
|
struct roots_desktop *desktop = view->desktop;
|
||||||
|
|
||||||
|
struct roots_input *input = desktop->server->input;
|
||||||
|
if (input->active_view == view) {
|
||||||
|
input->active_view = NULL;
|
||||||
|
input->mode = ROOTS_CURSOR_PASSTHROUGH;
|
||||||
|
}
|
||||||
|
if (input->last_active_view == view) {
|
||||||
|
input->last_active_view = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
for (size_t i = 0; i < desktop->views->length; ++i) {
|
for (size_t i = 0; i < desktop->views->length; ++i) {
|
||||||
struct roots_view *_view = desktop->views->items[i];
|
struct roots_view *_view = desktop->views->items[i];
|
||||||
if (view == _view) {
|
if (view == _view) {
|
||||||
|
@ -58,6 +68,12 @@ void view_resize(struct roots_view *view, uint32_t width, uint32_t height) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void view_close(struct roots_view *view) {
|
||||||
|
if (view->close) {
|
||||||
|
view->close(view);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static struct wlr_subsurface *subsurface_at(struct wlr_surface *surface,
|
static struct wlr_subsurface *subsurface_at(struct wlr_surface *surface,
|
||||||
double sx, double sy, double *sub_x, double *sub_y) {
|
double sx, double sy, double *sub_x, double *sub_y) {
|
||||||
struct wlr_subsurface *subsurface;
|
struct wlr_subsurface *subsurface;
|
||||||
|
|
|
@ -21,19 +21,28 @@ static ssize_t keyboard_pressed_keysym_index(struct roots_keyboard *keyboard,
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const char *exec_prefix = "exec ";
|
||||||
|
|
||||||
static void keyboard_binding_execute(struct roots_keyboard *keyboard,
|
static void keyboard_binding_execute(struct roots_keyboard *keyboard,
|
||||||
char *command) {
|
const char *command) {
|
||||||
struct roots_server *server = keyboard->input->server;
|
struct roots_server *server = keyboard->input->server;
|
||||||
if (strcmp(command, "exit") == 0) {
|
if (strcmp(command, "exit") == 0) {
|
||||||
wl_display_terminate(server->wl_display);
|
wl_display_terminate(server->wl_display);
|
||||||
} else {
|
} else if (strcmp(command, "close") == 0) {
|
||||||
|
if (keyboard->input->last_active_view != NULL) {
|
||||||
|
view_close(keyboard->input->last_active_view);
|
||||||
|
}
|
||||||
|
} else if (strncmp(exec_prefix, command, strlen(exec_prefix)) == 0) {
|
||||||
|
const char *shell_cmd = command + strlen(exec_prefix);
|
||||||
pid_t pid = fork();
|
pid_t pid = fork();
|
||||||
if (pid < 0) {
|
if (pid < 0) {
|
||||||
wlr_log(L_ERROR, "cannot execute binding command: fork() failed");
|
wlr_log(L_ERROR, "cannot execute binding command: fork() failed");
|
||||||
return;
|
return;
|
||||||
} else if (pid == 0) {
|
} else if (pid == 0) {
|
||||||
execl("/bin/sh", "/bin/sh", "-c", command, (void *)NULL);
|
execl("/bin/sh", "/bin/sh", "-c", shell_cmd, (void *)NULL);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
wlr_log(L_ERROR, "unknown binding command: %s", command);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,7 @@ meta-key = Logo
|
||||||
|
|
||||||
# Keybindings
|
# Keybindings
|
||||||
# Maps key combinations with commands to execute
|
# Maps key combinations with commands to execute
|
||||||
# The special command "exit" stops the compositor
|
# Use the prefix "exec" to execute a shell command
|
||||||
[bindings]
|
[bindings]
|
||||||
Logo+q = exit
|
Logo+Shift+e = exit # Stop the compositor
|
||||||
|
Logo+q = close # Close the current view
|
||||||
|
|
|
@ -17,6 +17,12 @@ static void resize(struct roots_view *view, uint32_t width, uint32_t height) {
|
||||||
height);
|
height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void close(struct roots_view *view) {
|
||||||
|
assert(view->type == ROOTS_WL_SHELL_VIEW);
|
||||||
|
struct wlr_wl_shell_surface *surf = view->wl_shell_surface;
|
||||||
|
wl_client_destroy(surf->client);
|
||||||
|
}
|
||||||
|
|
||||||
static void handle_request_move(struct wl_listener *listener, void *data) {
|
static void handle_request_move(struct wl_listener *listener, void *data) {
|
||||||
struct roots_wl_shell_surface *roots_surface =
|
struct roots_wl_shell_surface *roots_surface =
|
||||||
wl_container_of(listener, roots_surface, request_move);
|
wl_container_of(listener, roots_surface, request_move);
|
||||||
|
@ -88,6 +94,7 @@ void handle_wl_shell_surface(struct wl_listener *listener, void *data) {
|
||||||
view->roots_wl_shell_surface = roots_surface;
|
view->roots_wl_shell_surface = roots_surface;
|
||||||
view->wlr_surface = surface->surface;
|
view->wlr_surface = surface->surface;
|
||||||
view->resize = resize;
|
view->resize = resize;
|
||||||
|
view->close = close;
|
||||||
view->desktop = desktop;
|
view->desktop = desktop;
|
||||||
roots_surface->view = view;
|
roots_surface->view = view;
|
||||||
list_add(desktop->views, view);
|
list_add(desktop->views, view);
|
||||||
|
|
|
@ -33,6 +33,14 @@ static void resize(struct roots_view *view, uint32_t width, uint32_t height) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void close(struct roots_view *view) {
|
||||||
|
assert(view->type == ROOTS_XDG_SHELL_V6_VIEW);
|
||||||
|
struct wlr_xdg_surface_v6 *surf = view->xdg_surface_v6;
|
||||||
|
if (surf->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL) {
|
||||||
|
wlr_xdg_toplevel_v6_send_close(surf);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void handle_request_move(struct wl_listener *listener, void *data) {
|
static void handle_request_move(struct wl_listener *listener, void *data) {
|
||||||
struct roots_xdg_surface_v6 *roots_xdg_surface =
|
struct roots_xdg_surface_v6 *roots_xdg_surface =
|
||||||
wl_container_of(listener, roots_xdg_surface, request_move);
|
wl_container_of(listener, roots_xdg_surface, request_move);
|
||||||
|
@ -107,6 +115,7 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) {
|
||||||
view->get_size = get_size;
|
view->get_size = get_size;
|
||||||
view->activate = activate;
|
view->activate = activate;
|
||||||
view->resize = resize;
|
view->resize = resize;
|
||||||
|
view->close = close;
|
||||||
view->desktop = desktop;
|
view->desktop = desktop;
|
||||||
roots_surface->view = view;
|
roots_surface->view = view;
|
||||||
list_add(desktop->views, view);
|
list_add(desktop->views, view);
|
||||||
|
|
|
@ -9,6 +9,16 @@
|
||||||
#include "rootston/desktop.h"
|
#include "rootston/desktop.h"
|
||||||
#include "rootston/server.h"
|
#include "rootston/server.h"
|
||||||
|
|
||||||
|
static void activate(struct roots_view *view, bool active) {
|
||||||
|
assert(view->type == ROOTS_XWAYLAND_VIEW);
|
||||||
|
if (active) {
|
||||||
|
wlr_xwayland_surface_activate(view->desktop->xwayland,
|
||||||
|
view->xwayland_surface);
|
||||||
|
} else {
|
||||||
|
wlr_xwayland_surface_activate(view->desktop->xwayland, NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void resize(struct roots_view *view, uint32_t width, uint32_t height) {
|
static void resize(struct roots_view *view, uint32_t width, uint32_t height) {
|
||||||
assert(view->type == ROOTS_XWAYLAND_VIEW);
|
assert(view->type == ROOTS_XWAYLAND_VIEW);
|
||||||
struct wlr_xwayland_surface *xwayland_surface = view->xwayland_surface;
|
struct wlr_xwayland_surface *xwayland_surface = view->xwayland_surface;
|
||||||
|
@ -16,6 +26,11 @@ static void resize(struct roots_view *view, uint32_t width, uint32_t height) {
|
||||||
xwayland_surface->x, xwayland_surface->y, width, height);
|
xwayland_surface->x, xwayland_surface->y, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void close(struct roots_view *view) {
|
||||||
|
assert(view->type == ROOTS_XWAYLAND_VIEW);
|
||||||
|
wlr_xwayland_surface_close(view->desktop->xwayland, view->xwayland_surface);
|
||||||
|
}
|
||||||
|
|
||||||
static void handle_destroy(struct wl_listener *listener, void *data) {
|
static void handle_destroy(struct wl_listener *listener, void *data) {
|
||||||
struct roots_xwayland_surface *roots_surface =
|
struct roots_xwayland_surface *roots_surface =
|
||||||
wl_container_of(listener, roots_surface, destroy);
|
wl_container_of(listener, roots_surface, destroy);
|
||||||
|
@ -38,15 +53,6 @@ static void handle_request_configure(struct wl_listener *listener, void *data) {
|
||||||
xwayland_surface, event->x, event->y, event->width, event->height);
|
xwayland_surface, event->x, event->y, event->width, event->height);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void activate(struct roots_view *view, bool active) {
|
|
||||||
if (active) {
|
|
||||||
wlr_xwayland_surface_activate(view->desktop->xwayland,
|
|
||||||
view->xwayland_surface);
|
|
||||||
} else {
|
|
||||||
wlr_xwayland_surface_activate(view->desktop->xwayland, NULL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void handle_xwayland_surface(struct wl_listener *listener, void *data) {
|
void handle_xwayland_surface(struct wl_listener *listener, void *data) {
|
||||||
struct roots_desktop *desktop =
|
struct roots_desktop *desktop =
|
||||||
wl_container_of(listener, desktop, xwayland_surface);
|
wl_container_of(listener, desktop, xwayland_surface);
|
||||||
|
@ -82,6 +88,7 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) {
|
||||||
view->desktop = desktop;
|
view->desktop = desktop;
|
||||||
view->activate = activate;
|
view->activate = activate;
|
||||||
view->resize = resize;
|
view->resize = resize;
|
||||||
|
view->close = close;
|
||||||
roots_surface->view = view;
|
roots_surface->view = view;
|
||||||
list_add(desktop->views, view);
|
list_add(desktop->views, view);
|
||||||
}
|
}
|
||||||
|
|
|
@ -807,3 +807,8 @@ void wlr_xdg_toplevel_v6_set_resizing(struct wlr_xdg_surface_v6 *surface,
|
||||||
|
|
||||||
wlr_xdg_surface_v6_schedule_configure(surface, false);
|
wlr_xdg_surface_v6_schedule_configure(surface, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void wlr_xdg_toplevel_v6_send_close(struct wlr_xdg_surface_v6 *surface) {
|
||||||
|
assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL);
|
||||||
|
zxdg_toplevel_v6_send_close(surface->toplevel_state->resource);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue