From e5ee01254b442ae2f742a7044c56753fef13de76 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Tue, 24 Oct 2017 21:07:46 -0400 Subject: xwm: map and unmap notify --- rootston/xwayland.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'rootston/xwayland.c') diff --git a/rootston/xwayland.c b/rootston/xwayland.c index 1149b966..d43618c3 100644 --- a/rootston/xwayland.c +++ b/rootston/xwayland.c @@ -44,6 +44,8 @@ static void handle_destroy(struct wl_listener *listener, void *data) { struct roots_xwayland_surface *roots_surface = wl_container_of(listener, roots_surface, destroy); wl_list_remove(&roots_surface->destroy.link); + wl_list_remove(&roots_surface->map_notify.link); + wl_list_remove(&roots_surface->unmap_notify.link); view_destroy(roots_surface->view); free(roots_surface); } @@ -62,6 +64,34 @@ static void handle_request_configure(struct wl_listener *listener, void *data) { xwayland_surface, event->x, event->y, event->width, event->height); } +static void handle_map_notify(struct wl_listener *listener, void *data) { + struct roots_xwayland_surface *roots_surface = + wl_container_of(listener, roots_surface, map_notify); + struct roots_view *view = roots_surface->view; + struct wlr_xwayland_surface *xsurface = view->xwayland_surface; + struct roots_desktop *desktop = view->desktop; + + view->wlr_surface = xsurface->surface; + view->x = (double)xsurface->x; + view->y = (double)xsurface->y; + + wlr_list_push(desktop->views, roots_surface->view); +} + +static void handle_unmap_notify(struct wl_listener *listener, void *data) { + struct roots_xwayland_surface *roots_surface = + wl_container_of(listener, roots_surface, unmap_notify); + struct roots_desktop *desktop = roots_surface->view->desktop; + roots_surface->view->wlr_surface = NULL; + + for (size_t i = 0; i < desktop->views->length; i++) { + if (desktop->views->items[i] == roots_surface->view) { + wlr_list_del(desktop->views, i); + break; + } + } +} + void handle_xwayland_surface(struct wl_listener *listener, void *data) { struct roots_desktop *desktop = wl_container_of(listener, desktop, xwayland_surface); @@ -77,10 +107,17 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) { } roots_surface->destroy.notify = handle_destroy; wl_signal_add(&surface->events.destroy, &roots_surface->destroy); + roots_surface->request_configure.notify = handle_request_configure; wl_signal_add(&surface->events.request_configure, &roots_surface->request_configure); + roots_surface->map_notify.notify = handle_map_notify; + wl_signal_add(&surface->events.map_notify, &roots_surface->map_notify); + + roots_surface->unmap_notify.notify = handle_unmap_notify; + wl_signal_add(&surface->events.unmap_notify, &roots_surface->unmap_notify); + struct roots_view *view = calloc(1, sizeof(struct roots_view)); if (view == NULL) { free(roots_surface); -- cgit v1.2.3 From 0d1dd84a48cbfec848866cfbe4e62652765d7c98 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Wed, 25 Oct 2017 08:39:28 -0400 Subject: xwm: improve activation and dont send focus twice --- include/wlr/xwayland.h | 2 +- rootston/xwayland.c | 8 +--- xwayland/xwm.c | 114 ++++++++++++++++++++++++++++--------------------- 3 files changed, 69 insertions(+), 55 deletions(-) (limited to 'rootston/xwayland.c') diff --git a/include/wlr/xwayland.h b/include/wlr/xwayland.h index efee3d9f..e7598d4c 100644 --- a/include/wlr/xwayland.h +++ b/include/wlr/xwayland.h @@ -125,7 +125,7 @@ void wlr_xwayland_destroy(struct wlr_xwayland *wlr_xwayland); struct wlr_xwayland *wlr_xwayland_create(struct wl_display *wl_display, struct wlr_compositor *compositor); void wlr_xwayland_surface_activate(struct wlr_xwayland *wlr_xwayland, - struct wlr_xwayland_surface *surface); + struct wlr_xwayland_surface *surface, bool activated); void wlr_xwayland_surface_configure(struct wlr_xwayland *wlr_xwayland, struct wlr_xwayland_surface *surface, int16_t x, int16_t y, uint16_t width, uint16_t height); diff --git a/rootston/xwayland.c b/rootston/xwayland.c index d43618c3..221c659d 100644 --- a/rootston/xwayland.c +++ b/rootston/xwayland.c @@ -11,12 +11,8 @@ 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); - } + struct wlr_xwayland *xwayland = view->desktop->xwayland; + wlr_xwayland_surface_activate(xwayland, view->xwayland_surface, active); } static void resize(struct roots_view *view, uint32_t width, uint32_t height) { diff --git a/xwayland/xwm.c b/xwayland/xwm.c index 7827295e..f39f8391 100644 --- a/xwayland/xwm.c +++ b/xwayland/xwm.c @@ -86,9 +86,69 @@ static struct wlr_xwayland_surface *wlr_xwayland_surface_create( return surface; } +static void xwm_set_net_active_window(struct wlr_xwm *xwm, + xcb_window_t window) { + xcb_change_property(xwm->xcb_conn, XCB_PROP_MODE_REPLACE, + xwm->screen->root, xwm->atoms[_NET_ACTIVE_WINDOW], + xwm->atoms[WINDOW], 32, 1, &window); +} + +static void xwm_send_focus_window(struct wlr_xwm *xwm, + struct wlr_xwayland_surface *surface) { + if (surface) { + xcb_client_message_event_t client_message; + client_message.response_type = XCB_CLIENT_MESSAGE; + client_message.format = 32; + client_message.window = surface->window_id; + client_message.type = xwm->atoms[WM_PROTOCOLS]; + client_message.data.data32[0] = xwm->atoms[WM_TAKE_FOCUS]; + client_message.data.data32[1] = XCB_TIME_CURRENT_TIME; + + xcb_send_event(xwm->xcb_conn, 0, surface->window_id, + XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT, (char*)&client_message); + + xcb_set_input_focus(xwm->xcb_conn, XCB_INPUT_FOCUS_POINTER_ROOT, + surface->window_id, XCB_CURRENT_TIME); + + uint32_t values[1]; + values[0] = XCB_STACK_MODE_ABOVE; + xcb_configure_window_checked(xwm->xcb_conn, surface->window_id, + XCB_CONFIG_WINDOW_STACK_MODE, values); + } else { + xcb_set_input_focus_checked(xwm->xcb_conn, + XCB_INPUT_FOCUS_POINTER_ROOT, + XCB_NONE, XCB_CURRENT_TIME); + } +} + + +void xwm_surface_activate(struct wlr_xwm *xwm, + struct wlr_xwayland_surface *xsurface) { + if (xwm->focus_surface == xsurface) { + return; + } + + if (xsurface) { + xwm_set_net_active_window(xwm, xsurface->window_id); + } else { + xwm_set_net_active_window(xwm, XCB_WINDOW_NONE); + } + + xwm_send_focus_window(xwm, xsurface); + + xwm->focus_surface = xsurface; + + xcb_flush(xwm->xcb_conn); +} + + static void wlr_xwayland_surface_destroy(struct wlr_xwayland_surface *surface) { wl_signal_emit(&surface->events.destroy, surface); + if (surface == surface->xwm->focus_surface) { + xwm_surface_activate(surface->xwm, NULL); + } + wl_list_remove(&surface->link); if (surface->surface_id) { @@ -707,56 +767,14 @@ static void handle_compositor_surface_create(struct wl_listener *listener, } } -static void xwm_set_net_active_window(struct wlr_xwm *xwm, - xcb_window_t window) { - xcb_change_property(xwm->xcb_conn, XCB_PROP_MODE_REPLACE, - xwm->screen->root, xwm->atoms[_NET_ACTIVE_WINDOW], - xwm->atoms[WINDOW], 32, 1, &window); -} - -static void xwm_send_focus_window(struct wlr_xwm *xwm, - struct wlr_xwayland_surface *surface) { - if (surface) { - xcb_client_message_event_t client_message; - client_message.response_type = XCB_CLIENT_MESSAGE; - client_message.format = 32; - client_message.window = surface->window_id; - client_message.type = xwm->atoms[WM_PROTOCOLS]; - client_message.data.data32[0] = xwm->atoms[WM_TAKE_FOCUS]; - client_message.data.data32[1] = XCB_TIME_CURRENT_TIME; - - xcb_send_event(xwm->xcb_conn, 0, surface->window_id, - XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT, (char*)&client_message); - - xcb_set_input_focus(xwm->xcb_conn, XCB_INPUT_FOCUS_POINTER_ROOT, - surface->window_id, XCB_CURRENT_TIME); - - uint32_t values[1]; - values[0] = XCB_STACK_MODE_ABOVE; - xcb_configure_window_checked(xwm->xcb_conn, surface->window_id, - XCB_CONFIG_WINDOW_STACK_MODE, values); - } else { - xcb_set_input_focus_checked(xwm->xcb_conn, - XCB_INPUT_FOCUS_POINTER_ROOT, - XCB_NONE, XCB_CURRENT_TIME); - } -} - void wlr_xwayland_surface_activate(struct wlr_xwayland *wlr_xwayland, - struct wlr_xwayland_surface *surface) { - struct wlr_xwm *xwm = wlr_xwayland->xwm; - - if (surface) { - xwm_set_net_active_window(xwm, surface->window_id); - } else { - xwm_set_net_active_window(xwm, XCB_WINDOW_NONE); + struct wlr_xwayland_surface *surface, bool activated) { + struct wlr_xwayland_surface *focused = wlr_xwayland->xwm->focus_surface; + if (activated) { + xwm_surface_activate(wlr_xwayland->xwm, surface); + } else if (focused == surface) { + xwm_surface_activate(wlr_xwayland->xwm, NULL); } - - xwm_send_focus_window(xwm, surface); - - xwm->focus_surface = surface; - - xcb_flush(xwm->xcb_conn); } void wlr_xwayland_surface_configure(struct wlr_xwayland *wlr_xwayland, -- cgit v1.2.3 From 6a4290b86ac282a899221834465df81bdd9d6bc9 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Fri, 27 Oct 2017 10:48:09 -0400 Subject: xwm: moveresize events --- include/rootston/view.h | 2 ++ include/wlr/xwayland.h | 12 ++++++++++ rootston/xwayland.c | 57 +++++++++++++++++++++++++++++++++++++++++++++ xwayland/xwm.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 131 insertions(+), 1 deletion(-) (limited to 'rootston/xwayland.c') diff --git a/include/rootston/view.h b/include/rootston/view.h index 1a0de6de..53a2e133 100644 --- a/include/rootston/view.h +++ b/include/rootston/view.h @@ -34,6 +34,8 @@ struct roots_xwayland_surface { // TODO: Maybe destroy listener should go in roots_view struct wl_listener destroy; struct wl_listener request_configure; + struct wl_listener request_move; + struct wl_listener request_resize; struct wl_listener map_notify; struct wl_listener unmap_notify; }; diff --git a/include/wlr/xwayland.h b/include/wlr/xwayland.h index 6198ff22..b108028f 100644 --- a/include/wlr/xwayland.h +++ b/include/wlr/xwayland.h @@ -104,6 +104,8 @@ struct wlr_xwayland_surface { struct { struct wl_signal destroy; struct wl_signal request_configure; + struct wl_signal request_move; + struct wl_signal request_resize; struct wl_signal map_notify; struct wl_signal unmap_notify; struct wl_signal set_title; @@ -126,6 +128,16 @@ struct wlr_xwayland_surface_configure_event { uint16_t width, height; }; +// TODO: maybe add a seat to these +struct wlr_xwayland_move_event { + struct wlr_xwayland_surface *surface; +}; + +struct wlr_xwayland_resize_event { + struct wlr_xwayland_surface *surface; + uint32_t edges; +}; + void wlr_xwayland_destroy(struct wlr_xwayland *wlr_xwayland); struct wlr_xwayland *wlr_xwayland_create(struct wl_display *wl_display, struct wlr_compositor *compositor); diff --git a/rootston/xwayland.c b/rootston/xwayland.c index 221c659d..9a6e33fd 100644 --- a/rootston/xwayland.c +++ b/rootston/xwayland.c @@ -60,6 +60,57 @@ static void handle_request_configure(struct wl_listener *listener, void *data) { xwayland_surface, event->x, event->y, event->width, event->height); } +// XXX Needs deep refactoring to get this better. We need to select the correct +// seat based on seat pointer focus, but interactive moving and resizing is not +// yet seat aware. Even then, we can only guess because X11 events don't give us +// enough wayland info to know for sure. +static struct wlr_cursor *guess_cursor_for_view(struct roots_view *view) { + struct roots_input *input = view->desktop->server->input; + size_t len = sizeof(input->input_events) / sizeof(*input->input_events); + for (size_t i = 0; i < len; i++) { + struct wlr_cursor *cursor = input->input_events[i].cursor; + if (cursor) { + int width = view->xwayland_surface->surface->current->width; + int height = view->xwayland_surface->surface->current->height; + if (cursor->x > view->x && cursor->y > view->y && + cursor->x < view->x + width && + cursor->y < view->y + height) { + return cursor; + } + } + } + + return NULL; +} + +static void handle_request_move(struct wl_listener *listener, void *data) { + struct roots_xwayland_surface *roots_surface = + wl_container_of(listener, roots_surface, request_move); + struct roots_view *view = roots_surface->view; + struct roots_input *input = view->desktop->server->input; + struct wlr_cursor *cursor = guess_cursor_for_view(view); + + if (!cursor || input->mode != ROOTS_CURSOR_PASSTHROUGH) { + return; + } + + view_begin_move(input, cursor, view); +} + +static void handle_request_resize(struct wl_listener *listener, void *data) { + struct roots_xwayland_surface *roots_surface = + wl_container_of(listener, roots_surface, request_resize); + struct roots_view *view = roots_surface->view; + struct roots_input *input = view->desktop->server->input; + struct wlr_cursor *cursor = guess_cursor_for_view(view); + struct wlr_xwayland_resize_event *e = data; + + if (!cursor || input->mode != ROOTS_CURSOR_PASSTHROUGH) { + return; + } + view_begin_resize(input, cursor, view, e->edges); +} + static void handle_map_notify(struct wl_listener *listener, void *data) { struct roots_xwayland_surface *roots_surface = wl_container_of(listener, roots_surface, map_notify); @@ -114,6 +165,12 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) { roots_surface->unmap_notify.notify = handle_unmap_notify; wl_signal_add(&surface->events.unmap_notify, &roots_surface->unmap_notify); + roots_surface->request_move.notify = handle_request_move; + wl_signal_add(&surface->events.request_move, &roots_surface->request_move); + + roots_surface->request_resize.notify = handle_request_resize; + wl_signal_add(&surface->events.request_resize, &roots_surface->request_resize); + struct roots_view *view = calloc(1, sizeof(struct roots_view)); if (view == NULL) { free(roots_surface); diff --git a/xwayland/xwm.c b/xwayland/xwm.c index b52dfcf7..2caae3a7 100644 --- a/xwayland/xwm.c +++ b/xwayland/xwm.c @@ -82,6 +82,8 @@ static struct wlr_xwayland_surface *wlr_xwayland_surface_create( surface->state = wlr_list_create(); wl_signal_init(&surface->events.destroy); wl_signal_init(&surface->events.request_configure); + wl_signal_init(&surface->events.request_move); + wl_signal_init(&surface->events.request_resize); wl_signal_init(&surface->events.map_notify); wl_signal_init(&surface->events.unmap_notify); wl_signal_init(&surface->events.set_class); @@ -706,9 +708,58 @@ static void handle_surface_id_message(struct wlr_xwm *xwm, } } +#define _NET_WM_MOVERESIZE_SIZE_TOPLEFT 0 +#define _NET_WM_MOVERESIZE_SIZE_TOP 1 +#define _NET_WM_MOVERESIZE_SIZE_TOPRIGHT 2 +#define _NET_WM_MOVERESIZE_SIZE_RIGHT 3 +#define _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT 4 +#define _NET_WM_MOVERESIZE_SIZE_BOTTOM 5 +#define _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT 6 +#define _NET_WM_MOVERESIZE_SIZE_LEFT 7 +#define _NET_WM_MOVERESIZE_MOVE 8 // movement only +#define _NET_WM_MOVERESIZE_SIZE_KEYBOARD 9 // size via keyboard +#define _NET_WM_MOVERESIZE_MOVE_KEYBOARD 10 // move via keyboard +#define _NET_WM_MOVERESIZE_CANCEL 11 // cancel operation + static void handle_net_wm_moveresize_message(struct wlr_xwm *xwm, xcb_client_message_event_t *ev) { - wlr_log(L_DEBUG, "TODO: handle moveresize"); + // same as xdg-toplevel-v6 + // TODO need a common enum for this + static const int map[] = { + 5, 1, 9, 8, 10, 2, 6, 4 + }; + + struct wlr_xwayland_surface *xsurface = lookup_surface(xwm, ev->window); + if (!xsurface) { + return; + } + + // TODO: we should probably add input or seat info to this but we would just + // be guessing + struct wlr_xwayland_resize_event resize_event; + struct wlr_xwayland_move_event move_event; + + int detail = ev->data.data32[2]; + switch (detail) { + case _NET_WM_MOVERESIZE_MOVE: + move_event.surface = xsurface; + wl_signal_emit(&xsurface->events.request_move, &move_event); + break; + case _NET_WM_MOVERESIZE_SIZE_TOPLEFT: + case _NET_WM_MOVERESIZE_SIZE_TOP: + case _NET_WM_MOVERESIZE_SIZE_TOPRIGHT: + case _NET_WM_MOVERESIZE_SIZE_RIGHT: + case _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT: + case _NET_WM_MOVERESIZE_SIZE_BOTTOM: + case _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT: + case _NET_WM_MOVERESIZE_SIZE_LEFT: + resize_event.surface = xsurface; + resize_event.edges = map[detail]; + wl_signal_emit(&xsurface->events.request_resize, &resize_event); + break; + case _NET_WM_MOVERESIZE_CANCEL: + break; + } } static void handle_client_message(struct wlr_xwm *xwm, @@ -980,6 +1031,14 @@ static void xwm_create_wm_window(struct wlr_xwm *xwm) { 32, // format 1, &xwm->window); + xcb_change_property(xwm->xcb_conn, + XCB_PROP_MODE_REPLACE, + xwm->window, + xwm->atoms[_NET_SUPPORTING_WM_CHECK], + XCB_ATOM_WINDOW, + 32, // format + 1, &xwm->window); + xcb_set_selection_owner(xwm->xcb_conn, xwm->window, xwm->atoms[WM_S0], -- cgit v1.2.3