xwm: moveresize events

This commit is contained in:
Tony Crisci 2017-10-27 10:48:09 -04:00
parent 4a106648c4
commit 6a4290b86a
4 changed files with 131 additions and 1 deletions

View File

@ -34,6 +34,8 @@ struct roots_xwayland_surface {
// TODO: Maybe destroy listener should go in roots_view // TODO: Maybe destroy listener should go in roots_view
struct wl_listener destroy; struct wl_listener destroy;
struct wl_listener request_configure; struct wl_listener request_configure;
struct wl_listener request_move;
struct wl_listener request_resize;
struct wl_listener map_notify; struct wl_listener map_notify;
struct wl_listener unmap_notify; struct wl_listener unmap_notify;
}; };

View File

@ -104,6 +104,8 @@ struct wlr_xwayland_surface {
struct { struct {
struct wl_signal destroy; struct wl_signal destroy;
struct wl_signal request_configure; struct wl_signal request_configure;
struct wl_signal request_move;
struct wl_signal request_resize;
struct wl_signal map_notify; struct wl_signal map_notify;
struct wl_signal unmap_notify; struct wl_signal unmap_notify;
struct wl_signal set_title; struct wl_signal set_title;
@ -126,6 +128,16 @@ struct wlr_xwayland_surface_configure_event {
uint16_t width, height; 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); void wlr_xwayland_destroy(struct wlr_xwayland *wlr_xwayland);
struct wlr_xwayland *wlr_xwayland_create(struct wl_display *wl_display, struct wlr_xwayland *wlr_xwayland_create(struct wl_display *wl_display,
struct wlr_compositor *compositor); struct wlr_compositor *compositor);

View File

@ -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); 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) { static void handle_map_notify(struct wl_listener *listener, void *data) {
struct roots_xwayland_surface *roots_surface = struct roots_xwayland_surface *roots_surface =
wl_container_of(listener, roots_surface, map_notify); 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; roots_surface->unmap_notify.notify = handle_unmap_notify;
wl_signal_add(&surface->events.unmap_notify, &roots_surface->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)); struct roots_view *view = calloc(1, sizeof(struct roots_view));
if (view == NULL) { if (view == NULL) {
free(roots_surface); free(roots_surface);

View File

@ -82,6 +82,8 @@ static struct wlr_xwayland_surface *wlr_xwayland_surface_create(
surface->state = wlr_list_create(); surface->state = wlr_list_create();
wl_signal_init(&surface->events.destroy); wl_signal_init(&surface->events.destroy);
wl_signal_init(&surface->events.request_configure); 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.map_notify);
wl_signal_init(&surface->events.unmap_notify); wl_signal_init(&surface->events.unmap_notify);
wl_signal_init(&surface->events.set_class); 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, static void handle_net_wm_moveresize_message(struct wlr_xwm *xwm,
xcb_client_message_event_t *ev) { 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, 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 32, // format
1, &xwm->window); 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, xcb_set_selection_owner(xwm->xcb_conn,
xwm->window, xwm->window,
xwm->atoms[WM_S0], xwm->atoms[WM_S0],