Add close command, add close for xwayland

This commit is contained in:
emersion 2017-10-06 15:39:39 +02:00
parent 8ff548cdba
commit 972e9dbd1b
No known key found for this signature in database
GPG key ID: 0FDE7BE0E88F5E48
6 changed files with 28 additions and 8 deletions

View file

@ -81,7 +81,7 @@ struct roots_input {
struct wlr_seat *wl_seat;
enum roots_cursor_mode mode;
struct roots_view *active_view;
struct roots_view *active_view, *last_active_view;
int offs_x, offs_y;
int view_x, view_y, view_width, view_height;
float view_rotation;

View file

@ -65,11 +65,13 @@ struct roots_view {
void (*get_input_bounds)(struct roots_view *view, struct wlr_box *box);
void (*activate)(struct roots_view *view, bool active);
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_input_bounds(struct roots_view *view, struct wlr_box *box);
void view_activate(struct roots_view *view, bool active);
void view_resize(struct roots_view *view, uint32_t width, uint32_t height);
void view_close(struct roots_view *view);
#endif

View file

@ -133,6 +133,7 @@ static void set_view_focus(struct roots_input *input,
if (!view) {
return;
}
input->last_active_view = view;
size_t index = 0;
for (size_t i = 0; i < desktop->views->length; ++i) {

View file

@ -58,6 +58,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,
double sx, double sy, double *sub_x, double *sub_y) {
struct wlr_subsurface *subsurface;

View file

@ -28,6 +28,10 @@ static void keyboard_binding_execute(struct roots_keyboard *keyboard,
struct roots_server *server = keyboard->input->server;
if (strcmp(command, "exit") == 0) {
wl_display_terminate(server->wl_display);
} 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();

View file

@ -9,13 +9,6 @@
#include "rootston/desktop.h"
#include "rootston/server.h"
static void resize(struct roots_view *view, uint32_t width, uint32_t height) {
assert(view->type == ROOTS_XWAYLAND_VIEW);
struct wlr_xwayland_surface *xwayland_surface = view->xwayland_surface;
wlr_xwayland_surface_configure(view->desktop->xwayland, xwayland_surface,
xwayland_surface->x, xwayland_surface->y, width, height);
}
static void handle_destroy(struct wl_listener *listener, void *data) {
struct roots_xwayland_surface *roots_surface =
wl_container_of(listener, roots_surface, destroy);
@ -39,6 +32,7 @@ static void handle_request_configure(struct wl_listener *listener, void *data) {
}
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);
@ -47,6 +41,18 @@ static void activate(struct roots_view *view, bool active) {
}
}
static void resize(struct roots_view *view, uint32_t width, uint32_t height) {
assert(view->type == ROOTS_XWAYLAND_VIEW);
struct wlr_xwayland_surface *xwayland_surface = view->xwayland_surface;
wlr_xwayland_surface_configure(view->desktop->xwayland, xwayland_surface,
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);
}
void handle_xwayland_surface(struct wl_listener *listener, void *data) {
struct roots_desktop *desktop =
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->activate = activate;
view->resize = resize;
view->close = close;
roots_surface->view = view;
list_add(desktop->views, view);
}