From 0f7f6b1373438675b5f4d6a6ca0b4b88b472e322 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Tue, 24 Oct 2017 08:49:10 -0400 Subject: [PATCH 01/32] xwm: refactor xwm init --- xwayland/xwm.c | 136 ++++++++++++++++++++++++------------------------- 1 file changed, 66 insertions(+), 70 deletions(-) diff --git a/xwayland/xwm.c b/xwayland/xwm.c index f58acb73..c278f1bd 100644 --- a/xwayland/xwm.c +++ b/xwayland/xwm.c @@ -638,70 +638,6 @@ static void create_surface_handler(struct wl_listener *listener, void *data) { } } -static void xcb_get_resources(struct wlr_xwm *xwm) { - size_t i; - xcb_intern_atom_cookie_t cookies[ATOM_LAST]; - - for (i = 0; i < ATOM_LAST; i++) { - cookies[i] = xcb_intern_atom(xwm->xcb_conn, 0, strlen(atom_map[i]), atom_map[i]); - } - for (i = 0; i < ATOM_LAST; i++) { - xcb_intern_atom_reply_t *reply; - xcb_generic_error_t *error; - - reply = xcb_intern_atom_reply(xwm->xcb_conn, cookies[i], &error); - - if (reply && !error) { - xwm->atoms[i] = reply->atom; - } - if (reply) { - free(reply); - } - if (error) { - wlr_log(L_ERROR, "could not resolve atom %s, x11 error code %d", - atom_map[i], error->error_code); - free(error); - return; - } - } -} - -static void xcb_init_wm(struct wlr_xwm *xwm) { - xcb_screen_iterator_t screen_iterator = - xcb_setup_roots_iterator(xcb_get_setup(xwm->xcb_conn)); - xwm->screen = screen_iterator.data; - - xwm->window = xcb_generate_id(xwm->xcb_conn); - - uint32_t values[] = { - XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY | - XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT | - XCB_EVENT_MASK_PROPERTY_CHANGE, - /* xwm->cursor, */ - }; - XCB_CALL(xwm, xcb_change_window_attributes_checked(xwm->xcb_conn, - xwm->screen->root, XCB_CW_EVENT_MASK /* | XCB_CW_CURSOR */, values)); - XCB_CALL(xwm, xcb_composite_redirect_subwindows_checked(xwm->xcb_conn, - xwm->screen->root, XCB_COMPOSITE_REDIRECT_MANUAL)); - - XCB_CALL(xwm, xcb_create_window_checked(xwm->xcb_conn, XCB_COPY_FROM_PARENT, - xwm->window, xwm->screen->root, 0, 0, 1, 1, 0, - XCB_WINDOW_CLASS_INPUT_OUTPUT, xwm->screen->root_visual, - XCB_CW_EVENT_MASK, (uint32_t[]){XCB_EVENT_MASK_PROPERTY_CHANGE})); - xcb_atom_t supported[] = { - xwm->atoms[NET_WM_STATE], - }; - XCB_CALL(xwm, xcb_change_property_checked(xwm->xcb_conn, - XCB_PROP_MODE_REPLACE, xwm->screen->root, xwm->atoms[NET_SUPPORTED], - XCB_ATOM_ATOM, 32, sizeof(supported)/sizeof(*supported), supported)); - - XCB_CALL(xwm, xcb_set_selection_owner_checked(xwm->xcb_conn, xwm->window, - xwm->atoms[WM_S0], XCB_CURRENT_TIME)); - XCB_CALL(xwm, xcb_set_selection_owner_checked(xwm->xcb_conn, xwm->window, - xwm->atoms[NET_WM_S0], XCB_CURRENT_TIME)); - xcb_flush(xwm->xcb_conn); -} - void wlr_xwayland_surface_activate(struct wlr_xwayland *wlr_xwayland, struct wlr_xwayland_surface *surface) { struct wlr_xwm *xwm = wlr_xwayland->xwm; @@ -797,6 +733,35 @@ void xwm_destroy(struct wlr_xwm *xwm) { free(xwm); } +static void xwm_get_resources(struct wlr_xwm *xwm) { + size_t i; + xcb_intern_atom_cookie_t cookies[ATOM_LAST]; + + for (i = 0; i < ATOM_LAST; i++) { + cookies[i] = xcb_intern_atom(xwm->xcb_conn, 0, strlen(atom_map[i]), atom_map[i]); + } + for (i = 0; i < ATOM_LAST; i++) { + xcb_intern_atom_reply_t *reply; + xcb_generic_error_t *error; + + reply = xcb_intern_atom_reply(xwm->xcb_conn, cookies[i], &error); + + if (reply && !error) { + xwm->atoms[i] = reply->atom; + } + if (reply) { + free(reply); + } + if (error) { + wlr_log(L_ERROR, "could not resolve atom %s, x11 error code %d", + atom_map[i], error->error_code); + free(error); + return; + } + } +} + + struct wlr_xwm *xwm_create(struct wlr_xwayland *wlr_xwayland) { struct wlr_xwm *xwm = calloc(1, sizeof(struct wlr_xwm)); if (xwm == NULL) { @@ -820,13 +785,44 @@ struct wlr_xwm *xwm_create(struct wlr_xwayland *wlr_xwayland) { wlr_xwayland->wl_display); xwm->event_source = wl_event_loop_add_fd(event_loop, wlr_xwayland->wm_fd[0], WL_EVENT_READABLE, x11_event_handler, xwm); - // probably not needed - // wl_event_source_check(xwm->event_source); + wl_event_source_check(xwm->event_source); - // TODO more xcb init - // xcb_prefetch_extension_data(xwm->xcb_conn, &xcb_composite_id); - xcb_get_resources(xwm); - xcb_init_wm(xwm); + xwm_get_resources(xwm); + + xcb_screen_iterator_t screen_iterator = + xcb_setup_roots_iterator(xcb_get_setup(xwm->xcb_conn)); + xwm->screen = screen_iterator.data; + + xwm->window = xcb_generate_id(xwm->xcb_conn); + + uint32_t values[] = { + XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY | + XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT | + XCB_EVENT_MASK_PROPERTY_CHANGE, + /* xwm->cursor, */ + }; + XCB_CALL(xwm, xcb_change_window_attributes_checked(xwm->xcb_conn, + xwm->screen->root, XCB_CW_EVENT_MASK /* | XCB_CW_CURSOR */, values)); + XCB_CALL(xwm, xcb_composite_redirect_subwindows_checked(xwm->xcb_conn, + xwm->screen->root, XCB_COMPOSITE_REDIRECT_MANUAL)); + + XCB_CALL(xwm, xcb_create_window_checked(xwm->xcb_conn, XCB_COPY_FROM_PARENT, + xwm->window, xwm->screen->root, 0, 0, 1, 1, 0, + XCB_WINDOW_CLASS_INPUT_OUTPUT, xwm->screen->root_visual, + XCB_CW_EVENT_MASK, (uint32_t[]){XCB_EVENT_MASK_PROPERTY_CHANGE})); + xcb_atom_t supported[] = { + xwm->atoms[NET_WM_STATE], + }; + + XCB_CALL(xwm, xcb_change_property_checked(xwm->xcb_conn, + XCB_PROP_MODE_REPLACE, xwm->screen->root, xwm->atoms[NET_SUPPORTED], + XCB_ATOM_ATOM, 32, sizeof(supported)/sizeof(*supported), supported)); + + XCB_CALL(xwm, xcb_set_selection_owner_checked(xwm->xcb_conn, xwm->window, + xwm->atoms[WM_S0], XCB_CURRENT_TIME)); + XCB_CALL(xwm, xcb_set_selection_owner_checked(xwm->xcb_conn, xwm->window, + xwm->atoms[NET_WM_S0], XCB_CURRENT_TIME)); + xcb_flush(xwm->xcb_conn); xwm->surface_create_listener.notify = create_surface_handler; wl_signal_add(&wlr_xwayland->compositor->events.create_surface, From 03bd34e826f01e35b4e23d9555d45924f12dadfa Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Tue, 24 Oct 2017 09:21:11 -0400 Subject: [PATCH 02/32] xwm: atom cleanup --- xwayland/xwm.c | 7 ++++--- xwayland/xwm.h | 45 ++------------------------------------------- 2 files changed, 6 insertions(+), 46 deletions(-) diff --git a/xwayland/xwm.c b/xwayland/xwm.c index 90801d99..5d349253 100644 --- a/xwayland/xwm.c +++ b/xwayland/xwm.c @@ -750,9 +750,9 @@ static void xwm_get_resources(struct wlr_xwm *xwm) { if (reply && !error) { xwm->atoms[i] = reply->atom; } - if (reply) { - free(reply); - } + + free(reply); + if (error) { wlr_log(L_ERROR, "could not resolve atom %s, x11 error code %d", atom_map[i], error->error_code); @@ -789,6 +789,7 @@ struct wlr_xwm *xwm_create(struct wlr_xwayland *wlr_xwayland) { wl_event_source_check(xwm->event_source); xcb_prefetch_extension_data(xwm->xcb_conn, &xcb_xfixes_id); + xwm_get_resources(xwm); xcb_screen_iterator_t screen_iterator = diff --git a/xwayland/xwm.h b/xwayland/xwm.h index a04b1065..bc43134e 100644 --- a/xwayland/xwm.h +++ b/xwayland/xwm.h @@ -3,48 +3,6 @@ #include #include -/* wlc's atom list: - WL_SURFACE_ID, - WM_DELETE_WINDOW, - WM_TAKE_FOCUS, - WM_PROTOCOLS, - WM_NORMAL_HINTS, - MOTIF_WM_HINTS, - TEXT, - UTF8_STRING, - CLIPBOARD, - CLIPBOARD_MANAGER, - TARGETS, - PRIMARY, - WM_S0, - STRING, - WLC_SELECTION, - NET_WM_S0, - NET_WM_PID, - NET_WM_NAME, - NET_WM_STATE, - NET_WM_STATE_FULLSCREEN, - NET_WM_STATE_MODAL, - NET_WM_STATE_ABOVE, - NET_SUPPORTED, - NET_SUPPORTING_WM_CHECK, - NET_WM_WINDOW_TYPE, - NET_WM_WINDOW_TYPE_DESKTOP, - NET_WM_WINDOW_TYPE_DOCK, - NET_WM_WINDOW_TYPE_TOOLBAR, - NET_WM_WINDOW_TYPE_MENU, - NET_WM_WINDOW_TYPE_UTILITY, - NET_WM_WINDOW_TYPE_SPLASH, - NET_WM_WINDOW_TYPE_DIALOG, - NET_WM_WINDOW_TYPE_DROPDOWN_MENU, - NET_WM_WINDOW_TYPE_POPUP_MENU, - NET_WM_WINDOW_TYPE_TOOLTIP, - NET_WM_WINDOW_TYPE_NOTIFICATION, - NET_WM_WINDOW_TYPE_COMBO, - NET_WM_WINDOW_TYPE_DND, - NET_WM_WINDOW_TYPE_NORMAL, - */ - enum atom_name { WL_SURFACE_ID, WM_DELETE_WINDOW, @@ -69,7 +27,7 @@ extern const char *atom_map[ATOM_LAST]; enum net_wm_state_action { NET_WM_STATE_REMOVE = 0, - NET_WM_STATE_ADD = 1, + NET_WM_STATE_ADD = 1, NET_WM_STATE_TOGGLE = 2, }; @@ -90,6 +48,7 @@ struct wlr_xwm { }; void xwm_destroy(struct wlr_xwm *xwm); + struct wlr_xwm *xwm_create(struct wlr_xwayland *wlr_xwayland); #endif From 79978383ba8fc894117947c80fc9d8cd78782fee Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Tue, 24 Oct 2017 10:04:33 -0400 Subject: [PATCH 03/32] xwm: net active window --- xwayland/xwm.c | 63 +++++++++++++++++++++++++++++++++++--------------- xwayland/xwm.h | 4 ++++ 2 files changed, 49 insertions(+), 18 deletions(-) diff --git a/xwayland/xwm.c b/xwayland/xwm.c index 5d349253..bd485eb1 100644 --- a/xwayland/xwm.c +++ b/xwayland/xwm.c @@ -620,8 +620,8 @@ static int x11_event_handler(int fd, uint32_t mask, void *data) { static void create_surface_handler(struct wl_listener *listener, void *data) { struct wlr_surface *surface = data; - struct wlr_xwm *xwm = wl_container_of(listener, xwm, - surface_create_listener); + struct wlr_xwm *xwm = + wl_container_of(listener, xwm, surface_create_listener); if (wl_resource_get_client(surface->resource) != xwm->xwayland->client) { return; } @@ -639,28 +639,55 @@ static void create_surface_handler(struct wl_listener *listener, void *data) { } } +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) { - xcb_client_message_event_t m = {0}; - m.response_type = XCB_CLIENT_MESSAGE; - m.format = 32; - m.window = surface->window_id; - m.type = xwm->atoms[WM_PROTOCOLS]; - m.data.data32[0] = xwm->atoms[WM_TAKE_FOCUS]; - m.data.data32[1] = XCB_TIME_CURRENT_TIME; - xcb_send_event_checked(xwm->xcb_conn, 0, surface->window_id, - XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT, (char*)&m); - xcb_set_input_focus_checked(xwm->xcb_conn, XCB_INPUT_FOCUS_POINTER_ROOT, - surface->window_id, XCB_CURRENT_TIME); - xcb_configure_window_checked(xwm->xcb_conn, surface->window_id, - XCB_CONFIG_WINDOW_STACK_MODE, (uint32_t[]){XCB_STACK_MODE_ABOVE}); + xwm_set_net_active_window(xwm, surface->window_id); } else { - wlr_log(L_DEBUG, "Deactivating xwayland"); - xcb_set_input_focus_checked(xwm->xcb_conn, XCB_INPUT_FOCUS_NONE, - -1, XCB_CURRENT_TIME); + xwm_set_net_active_window(xwm, XCB_WINDOW_NONE); } + + xwm_send_focus_window(xwm, surface); + + xwm->focus_surface = surface; + xcb_flush(xwm->xcb_conn); } diff --git a/xwayland/xwm.h b/xwayland/xwm.h index bc43134e..d8857eb8 100644 --- a/xwayland/xwm.h +++ b/xwayland/xwm.h @@ -20,6 +20,8 @@ enum atom_name { NET_WM_STATE, NET_WM_WINDOW_TYPE, WM_TAKE_FOCUS, + WINDOW, + _NET_ACTIVE_WINDOW, ATOM_LAST, }; @@ -41,6 +43,8 @@ struct wlr_xwm { xcb_screen_t *screen; xcb_window_t window; + struct wlr_xwayland_surface *focus_surface; + struct wl_list new_surfaces; struct wl_list unpaired_surfaces; From c666d34d2d09d8a3536901881ef31450fcdf696a Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Tue, 24 Oct 2017 11:00:41 -0400 Subject: [PATCH 04/32] xwm: add missing atoms to list --- xwayland/xwm.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/xwayland/xwm.c b/xwayland/xwm.c index bd485eb1..ee04f734 100644 --- a/xwayland/xwm.c +++ b/xwayland/xwm.c @@ -30,6 +30,8 @@ const char *atom_map[ATOM_LAST] = { "_NET_WM_STATE", "_NET_WM_WINDOW_TYPE", "WM_TAKE_FOCUS", + "WINDOW", + "_NET_ACTIVE_WINDOW", }; /* General helpers */ From a3f27546681a6a92e1e37ed7692428c36b486a8e Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Tue, 24 Oct 2017 12:00:43 -0400 Subject: [PATCH 05/32] xwm: add surface to rootston on surface commit --- include/wlr/xwayland.h | 9 ++++--- rootston/desktop.c | 8 +++--- xwayland/xwm.c | 55 +++++++++++++++++++++++++++++++++--------- xwayland/xwm.h | 3 ++- 4 files changed, 56 insertions(+), 19 deletions(-) diff --git a/include/wlr/xwayland.h b/include/wlr/xwayland.h index c25d0eb0..0398ff28 100644 --- a/include/wlr/xwayland.h +++ b/include/wlr/xwayland.h @@ -66,14 +66,16 @@ struct wlr_xwayland_surface_size_hints { struct wlr_xwayland_surface { xcb_window_t window_id; + struct wlr_xwm *xwm; uint32_t surface_id; struct wl_list link; struct wlr_surface *surface; - struct wl_listener surface_destroy_listener; int16_t x, y; uint16_t width, height; bool override_redirect; + bool mapped; + bool added; char *title; char *class; @@ -95,9 +97,7 @@ struct wlr_xwayland_surface { struct { struct wl_signal destroy; - struct wl_signal request_configure; - struct wl_signal set_title; struct wl_signal set_class; struct wl_signal set_parent; @@ -106,6 +106,9 @@ struct wlr_xwayland_surface { struct wl_signal set_window_type; } events; + struct wl_listener surface_destroy; + struct wl_listener surface_commit; + void *data; }; diff --git a/rootston/desktop.c b/rootston/desktop.c index 40d088b8..30b5a519 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -99,10 +99,10 @@ bool view_center(struct roots_view *view) { int width, height; wlr_output_effective_resolution(output, &width, &height); - view->x = (double)(width - size.width) / 2 - + l_output->x; - view->y = (double)(height - size.height) / 2 - + l_output->y; + double view_x = (double)(width - size.width) / 2 + l_output->x; + double view_y = (double)(height - size.height) / 2 + l_output->y; + + view_set_position(view, view_x, view_y); return true; } diff --git a/xwayland/xwm.c b/xwayland/xwm.c index ee04f734..2d88c2cb 100644 --- a/xwayland/xwm.c +++ b/xwayland/xwm.c @@ -67,6 +67,7 @@ static struct wlr_xwayland_surface *wlr_xwayland_surface_create( wlr_log(L_ERROR, "Could not allocate wlr xwayland surface"); return NULL; } + surface->xwm = xwm; surface->window_id = window_id; surface->x = x; surface->y = y; @@ -92,6 +93,12 @@ static void wlr_xwayland_surface_destroy(struct wlr_xwayland_surface *surface) { for (size_t i = 0; i < surface->state->length; i++) { free(surface->state->items[i]); } + + if (surface->surface) { + wl_list_remove(&surface->surface_destroy.link); + wl_list_remove(&surface->surface_commit.link); + } + free(surface->title); free(surface->class); free(surface->instance); @@ -412,11 +419,30 @@ static void read_surface_property(struct wlr_xwm *xwm, free(reply); } +static void handle_surface_commit(struct wl_listener *listener, void *data) { + struct wlr_xwayland_surface *xsurface = + wl_container_of(listener, xsurface, surface_commit); + + if (!xsurface->added && + wlr_surface_has_buffer(xsurface->surface) && + xsurface->mapped) { + wl_signal_emit(&xsurface->xwm->xwayland->events.new_surface, xsurface); + xsurface->added = true; + } +} + +static void handle_surface_destroy(struct wl_listener *listener, void *data) { + struct wlr_xwayland_surface *xsurface = + wl_container_of(listener, xsurface, surface_destroy); + + // TODO destroy xwayland surface? +} + static void map_shell_surface(struct wlr_xwm *xwm, - struct wlr_xwayland_surface *xwayland_surface, + struct wlr_xwayland_surface *xsurface, struct wlr_surface *surface) { // get xcb geometry for depth = alpha channel - xwayland_surface->surface = surface; + xsurface->surface = surface; // read all surface properties const xcb_atom_t props[] = { @@ -433,13 +459,20 @@ static void map_shell_surface(struct wlr_xwm *xwm, xwm->atoms[NET_WM_PID], }; for (size_t i = 0; i < sizeof(props)/sizeof(xcb_atom_t); i++) { - read_surface_property(xwm, xwayland_surface, props[i]); + read_surface_property(xwm, xsurface, props[i]); } - wl_list_remove(&xwayland_surface->link); + wl_list_remove(&xsurface->link); wl_list_insert(&xwm->xwayland->displayable_surfaces, - &xwayland_surface->link); - wl_signal_emit(&xwm->xwayland->events.new_surface, xwayland_surface); + &xsurface->link); + + xsurface->surface_commit.notify = handle_surface_commit; + wl_signal_add(&surface->events.commit, &xsurface->surface_commit); + + xsurface->surface_destroy.notify = handle_surface_destroy; + wl_signal_add(&surface->events.destroy, &xsurface->surface_destroy); + + xsurface->mapped = true; } /* xcb event handlers */ @@ -620,10 +653,10 @@ static int x11_event_handler(int fd, uint32_t mask, void *data) { return count; } -static void create_surface_handler(struct wl_listener *listener, void *data) { +static void handle_compositor_surface_create(struct wl_listener *listener, void *data) { struct wlr_surface *surface = data; struct wlr_xwm *xwm = - wl_container_of(listener, xwm, surface_create_listener); + wl_container_of(listener, xwm, compositor_surface_create); if (wl_resource_get_client(surface->resource) != xwm->xwayland->client) { return; } @@ -757,7 +790,7 @@ void xwm_destroy(struct wlr_xwm *xwm) { wl_list_for_each_safe(surface, tmp, &xwm->unpaired_surfaces, link) { wlr_xwayland_surface_destroy(surface); } - wl_list_remove(&xwm->surface_create_listener.link); + wl_list_remove(&xwm->compositor_surface_create.link); xcb_disconnect(xwm->xcb_conn); free(xwm); @@ -875,9 +908,9 @@ struct wlr_xwm *xwm_create(struct wlr_xwayland *wlr_xwayland) { free(xfixes_reply); - xwm->surface_create_listener.notify = create_surface_handler; + xwm->compositor_surface_create.notify = handle_compositor_surface_create; wl_signal_add(&wlr_xwayland->compositor->events.create_surface, - &xwm->surface_create_listener); + &xwm->compositor_surface_create); return xwm; } diff --git a/xwayland/xwm.h b/xwayland/xwm.h index d8857eb8..b557a331 100644 --- a/xwayland/xwm.h +++ b/xwayland/xwm.h @@ -36,7 +36,6 @@ enum net_wm_state_action { struct wlr_xwm { struct wlr_xwayland *xwayland; struct wl_event_source *event_source; - struct wl_listener surface_create_listener; xcb_atom_t atoms[ATOM_LAST]; xcb_connection_t *xcb_conn; @@ -49,6 +48,8 @@ struct wlr_xwm { struct wl_list unpaired_surfaces; const xcb_query_extension_reply_t *xfixes; + + struct wl_listener compositor_surface_create; }; void xwm_destroy(struct wlr_xwm *xwm); From a9d70a625697dcbe6017aca104a6b649c7ae0ac0 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Tue, 24 Oct 2017 13:24:26 -0400 Subject: [PATCH 06/32] xwm: set window attributes on create --- xwayland/xwm.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/xwayland/xwm.c b/xwayland/xwm.c index 2d88c2cb..b8168431 100644 --- a/xwayland/xwm.c +++ b/xwayland/xwm.c @@ -67,6 +67,14 @@ static struct wlr_xwayland_surface *wlr_xwayland_surface_create( wlr_log(L_ERROR, "Could not allocate wlr xwayland surface"); return NULL; } + + uint32_t values[1]; + values[0] = + XCB_EVENT_MASK_FOCUS_CHANGE | + XCB_EVENT_MASK_PROPERTY_CHANGE; + xcb_change_window_attributes(xwm->xcb_conn, window_id, + XCB_CW_EVENT_MASK, &values); + surface->xwm = xwm; surface->window_id = window_id; surface->x = x; @@ -530,11 +538,7 @@ static void handle_configure_request(struct wlr_xwm *xwm, static void handle_map_request(struct wlr_xwm *xwm, xcb_map_request_event_t *ev) { wlr_log(L_DEBUG, "XCB_MAP_REQUEST (%u)", ev->window); - const uint32_t value_list = XCB_EVENT_MASK_FOCUS_CHANGE | - XCB_EVENT_MASK_PROPERTY_CHANGE; - XCB_CALL(xwm, xcb_change_window_attributes_checked(xwm->xcb_conn, - ev->window, XCB_CW_EVENT_MASK, &value_list)); - XCB_CALL(xwm, xcb_map_window_checked(xwm->xcb_conn, ev->window)); + xcb_map_window(xwm->xcb_conn, ev->window); } static void handle_map_notify(struct wlr_xwm *xwm, xcb_map_notify_event_t *ev) { From fa94a06fd6141a82697a0ae1ba548686f325da45 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Tue, 24 Oct 2017 13:57:10 -0400 Subject: [PATCH 07/32] xwm: handle configure notify --- xwayland/xwm.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/xwayland/xwm.c b/xwayland/xwm.c index b8168431..f72f58b2 100644 --- a/xwayland/xwm.c +++ b/xwayland/xwm.c @@ -535,6 +535,21 @@ static void handle_configure_request(struct wlr_xwm *xwm, } } +static void handle_configure_notify(struct wlr_xwm *xwm, + xcb_configure_notify_event_t *ev) { + struct wlr_xwayland_surface *xsurface = + lookup_surface_any(xwm, ev->window); + + if (!xsurface) { + return; + } + + xsurface->x = ev->x; + xsurface->y = ev->y; + xsurface->width = ev->width; + xsurface->height = ev->height; +} + static void handle_map_request(struct wlr_xwm *xwm, xcb_map_request_event_t *ev) { wlr_log(L_DEBUG, "XCB_MAP_REQUEST (%u)", ev->window); @@ -630,6 +645,9 @@ static int x11_event_handler(int fd, uint32_t mask, void *data) { case XCB_CONFIGURE_REQUEST: handle_configure_request(xwm, (xcb_configure_request_event_t *)event); break; + case XCB_CONFIGURE_NOTIFY: + handle_configure_notify(xwm, (xcb_configure_notify_event_t *)event); + break; case XCB_MAP_REQUEST: handle_map_request(xwm, (xcb_map_request_event_t *)event); break; From 79e14f65e0a005b1ab47b294dd2368cb3d55cb33 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Tue, 24 Oct 2017 14:37:18 -0400 Subject: [PATCH 08/32] xwm: fix lists --- include/wlr/xwayland.h | 11 +++++-- xwayland/xwm.c | 73 +++++++++++++++++++++++++++++++----------- xwayland/xwm.h | 4 +-- 3 files changed, 66 insertions(+), 22 deletions(-) diff --git a/include/wlr/xwayland.h b/include/wlr/xwayland.h index 0398ff28..2cd1db92 100644 --- a/include/wlr/xwayland.h +++ b/include/wlr/xwayland.h @@ -25,7 +25,7 @@ struct wlr_xwayland { struct wl_event_source *sigusr1_source; struct wl_listener destroy_listener; struct wlr_xwm *xwm; - struct wl_list displayable_surfaces; + struct wl_list displayable_surfaces; // wlr_xwayland_surface::displayable_link struct { struct wl_signal new_surface; @@ -68,7 +68,14 @@ struct wlr_xwayland_surface { xcb_window_t window_id; struct wlr_xwm *xwm; uint32_t surface_id; - struct wl_list link; + + struct wl_list displayable_link; + // XXX: I think this is just a list of all the surfaces + struct wl_list new_link; + struct wl_list unpaired_link; + bool displayable; + bool unpaired; + struct wlr_surface *surface; int16_t x, y; diff --git a/xwayland/xwm.c b/xwayland/xwm.c index f72f58b2..0839ae20 100644 --- a/xwayland/xwm.c +++ b/xwayland/xwm.c @@ -36,10 +36,32 @@ const char *atom_map[ATOM_LAST] = { /* General helpers */ // TODO: replace this with hash table? -static struct wlr_xwayland_surface *lookup_surface(struct wl_list *list, +static struct wlr_xwayland_surface *lookup_surface(struct wlr_xwm *xwm, xcb_window_t window_id) { struct wlr_xwayland_surface *surface; - wl_list_for_each(surface, list, link) { + wl_list_for_each(surface, &xwm->new_surfaces, new_link) { + if (surface->window_id == window_id) { + return surface; + } + } + return NULL; +} + +static struct wlr_xwayland_surface *lookup_displayable_surface(struct wlr_xwm *xwm, + xcb_window_t window_id) { + struct wlr_xwayland_surface *surface; + wl_list_for_each(surface, &xwm->xwayland->displayable_surfaces, displayable_link) { + if (surface->window_id == window_id) { + return surface; + } + } + return NULL; +} + +static struct wlr_xwayland_surface *lookup_unpaired_surface(struct wlr_xwm *xwm, + xcb_window_t window_id) { + struct wlr_xwayland_surface *surface; + wl_list_for_each(surface, &xwm->unpaired_surfaces, unpaired_link) { if (surface->window_id == window_id) { return surface; } @@ -50,9 +72,9 @@ static struct wlr_xwayland_surface *lookup_surface(struct wl_list *list, static struct wlr_xwayland_surface *lookup_surface_any(struct wlr_xwm *xwm, xcb_window_t window_id) { struct wlr_xwayland_surface *surface; - if ((surface = lookup_surface(&xwm->xwayland->displayable_surfaces, window_id)) || - (surface = lookup_surface(&xwm->unpaired_surfaces, window_id)) || - (surface = lookup_surface(&xwm->new_surfaces, window_id))) { + if ((surface = lookup_displayable_surface(xwm, window_id)) || + (surface = lookup_unpaired_surface(xwm, window_id)) || + (surface = lookup_surface(xwm, window_id))) { return surface; } return NULL; @@ -82,7 +104,7 @@ static struct wlr_xwayland_surface *wlr_xwayland_surface_create( surface->width = width; surface->height = height; surface->override_redirect = override_redirect; - wl_list_insert(&xwm->new_surfaces, &surface->link); + wl_list_insert(&xwm->new_surfaces, &surface->new_link); surface->state = wlr_list_create(); wl_signal_init(&surface->events.destroy); wl_signal_init(&surface->events.request_configure); @@ -97,7 +119,19 @@ static struct wlr_xwayland_surface *wlr_xwayland_surface_create( static void wlr_xwayland_surface_destroy(struct wlr_xwayland_surface *surface) { wl_signal_emit(&surface->events.destroy, surface); - wl_list_remove(&surface->link); + + wl_list_remove(&surface->new_link); + + if (surface->unpaired) { + wl_list_remove(&surface->unpaired_link); + surface->unpaired = false; + } + + if (surface->displayable) { + wl_list_remove(&surface->displayable_link); + surface->displayable = false; + } + for (size_t i = 0; i < surface->state->length; i++) { free(surface->state->items[i]); } @@ -470,9 +504,11 @@ static void map_shell_surface(struct wlr_xwm *xwm, read_surface_property(xwm, xsurface, props[i]); } - wl_list_remove(&xsurface->link); - wl_list_insert(&xwm->xwayland->displayable_surfaces, - &xsurface->link); + if (!xsurface->displayable) { + wl_list_insert(&xwm->xwayland->displayable_surfaces, + &xsurface->displayable_link); + xsurface->displayable = true; + } xsurface->surface_commit.notify = handle_surface_commit; wl_signal_add(&surface->events.commit, &xsurface->surface_commit); @@ -594,8 +630,7 @@ static void handle_client_message(struct wlr_xwm *xwm, wlr_log(L_DEBUG, "XCB_CLIENT_MESSAGE (%u)", ev->window); if (ev->type == xwm->atoms[WL_SURFACE_ID]) { - struct wlr_xwayland_surface *surface = lookup_surface( - &xwm->new_surfaces, ev->window); + struct wlr_xwayland_surface *surface = lookup_surface(xwm, ev->window); if (surface == NULL) { wlr_log(L_DEBUG, "client message WL_SURFACE_ID but no new window %u ?", ev->window); @@ -608,8 +643,10 @@ static void handle_client_message(struct wlr_xwm *xwm, if (resource) { map_shell_surface(xwm, surface, wl_resource_get_user_data(resource)); } else { - wl_list_remove(&surface->link); - wl_list_insert(&xwm->unpaired_surfaces, &surface->link); + if (!surface->unpaired) { + wl_list_insert(&xwm->unpaired_surfaces, &surface->unpaired_link); + surface->unpaired = true; + } } } else if (ev->type == xwm->atoms[NET_WM_STATE]) { struct wlr_xwayland_surface *surface = lookup_surface_any(xwm, @@ -687,7 +724,7 @@ static void handle_compositor_surface_create(struct wl_listener *listener, void uint32_t surface_id = wl_resource_get_id(surface->resource); struct wlr_xwayland_surface *xwayland_surface; - wl_list_for_each(xwayland_surface, &xwm->unpaired_surfaces, link) { + wl_list_for_each(xwayland_surface, &xwm->unpaired_surfaces, unpaired_link) { if (xwayland_surface->surface_id == surface_id) { map_shell_surface(xwm, xwayland_surface, surface); xcb_flush(xwm->xcb_conn); @@ -803,13 +840,13 @@ void xwm_destroy(struct wlr_xwm *xwm) { } struct wlr_xwayland_surface *surface, *tmp; wl_list_for_each_safe(surface, tmp, &xwm->xwayland->displayable_surfaces, - link) { + displayable_link) { wlr_xwayland_surface_destroy(surface); } - wl_list_for_each_safe(surface, tmp, &xwm->new_surfaces, link) { + wl_list_for_each_safe(surface, tmp, &xwm->new_surfaces, new_link) { wlr_xwayland_surface_destroy(surface); } - wl_list_for_each_safe(surface, tmp, &xwm->unpaired_surfaces, link) { + wl_list_for_each_safe(surface, tmp, &xwm->unpaired_surfaces, unpaired_link) { wlr_xwayland_surface_destroy(surface); } wl_list_remove(&xwm->compositor_surface_create.link); diff --git a/xwayland/xwm.h b/xwayland/xwm.h index b557a331..9ae084d2 100644 --- a/xwayland/xwm.h +++ b/xwayland/xwm.h @@ -44,8 +44,8 @@ struct wlr_xwm { struct wlr_xwayland_surface *focus_surface; - struct wl_list new_surfaces; - struct wl_list unpaired_surfaces; + struct wl_list new_surfaces; // wlr_xwayland_surface::new_link + struct wl_list unpaired_surfaces; // wlr_xwayland_surface::unpaired_link const xcb_query_extension_reply_t *xfixes; From 2ff94d0036833b85f54c8be0ffb98c49be168be2 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Tue, 24 Oct 2017 18:57:20 -0400 Subject: [PATCH 09/32] xwm: get rid of displayable surfaces list --- include/wlr/xwayland.h | 8 +-- xwayland/xwayland.c | 1 - xwayland/xwm.c | 107 +++++++++++++++-------------------------- xwayland/xwm.h | 2 +- 4 files changed, 42 insertions(+), 76 deletions(-) diff --git a/include/wlr/xwayland.h b/include/wlr/xwayland.h index 2cd1db92..3d5a204c 100644 --- a/include/wlr/xwayland.h +++ b/include/wlr/xwayland.h @@ -25,7 +25,6 @@ struct wlr_xwayland { struct wl_event_source *sigusr1_source; struct wl_listener destroy_listener; struct wlr_xwm *xwm; - struct wl_list displayable_surfaces; // wlr_xwayland_surface::displayable_link struct { struct wl_signal new_surface; @@ -69,13 +68,8 @@ struct wlr_xwayland_surface { struct wlr_xwm *xwm; uint32_t surface_id; - struct wl_list displayable_link; - // XXX: I think this is just a list of all the surfaces - struct wl_list new_link; + struct wl_list link; struct wl_list unpaired_link; - bool displayable; - bool unpaired; - struct wlr_surface *surface; int16_t x, y; diff --git a/xwayland/xwayland.c b/xwayland/xwayland.c index f1599911..81bac2ce 100644 --- a/xwayland/xwayland.c +++ b/xwayland/xwayland.c @@ -205,7 +205,6 @@ static bool wlr_xwayland_init(struct wlr_xwayland *wlr_xwayland, wlr_xwayland->x_fd[0] = wlr_xwayland->x_fd[1] = -1; wlr_xwayland->wl_fd[0] = wlr_xwayland->wl_fd[1] = -1; wlr_xwayland->wm_fd[0] = wlr_xwayland->wm_fd[1] = -1; - wl_list_init(&wlr_xwayland->displayable_surfaces); wl_signal_init(&wlr_xwayland->events.new_surface); wlr_xwayland->display = open_display_sockets(wlr_xwayland->x_fd); diff --git a/xwayland/xwm.c b/xwayland/xwm.c index 0839ae20..87498fe2 100644 --- a/xwayland/xwm.c +++ b/xwayland/xwm.c @@ -39,18 +39,7 @@ const char *atom_map[ATOM_LAST] = { static struct wlr_xwayland_surface *lookup_surface(struct wlr_xwm *xwm, xcb_window_t window_id) { struct wlr_xwayland_surface *surface; - wl_list_for_each(surface, &xwm->new_surfaces, new_link) { - if (surface->window_id == window_id) { - return surface; - } - } - return NULL; -} - -static struct wlr_xwayland_surface *lookup_displayable_surface(struct wlr_xwm *xwm, - xcb_window_t window_id) { - struct wlr_xwayland_surface *surface; - wl_list_for_each(surface, &xwm->xwayland->displayable_surfaces, displayable_link) { + wl_list_for_each(surface, &xwm->surfaces, link) { if (surface->window_id == window_id) { return surface; } @@ -69,17 +58,6 @@ static struct wlr_xwayland_surface *lookup_unpaired_surface(struct wlr_xwm *xwm, return NULL; } -static struct wlr_xwayland_surface *lookup_surface_any(struct wlr_xwm *xwm, - xcb_window_t window_id) { - struct wlr_xwayland_surface *surface; - if ((surface = lookup_displayable_surface(xwm, window_id)) || - (surface = lookup_unpaired_surface(xwm, window_id)) || - (surface = lookup_surface(xwm, window_id))) { - return surface; - } - return NULL; -} - static struct wlr_xwayland_surface *wlr_xwayland_surface_create( struct wlr_xwm *xwm, xcb_window_t window_id, int16_t x, int16_t y, uint16_t width, uint16_t height, bool override_redirect) { @@ -104,7 +82,7 @@ static struct wlr_xwayland_surface *wlr_xwayland_surface_create( surface->width = width; surface->height = height; surface->override_redirect = override_redirect; - wl_list_insert(&xwm->new_surfaces, &surface->new_link); + wl_list_insert(&xwm->surfaces, &surface->link); surface->state = wlr_list_create(); wl_signal_init(&surface->events.destroy); wl_signal_init(&surface->events.request_configure); @@ -120,16 +98,10 @@ static struct wlr_xwayland_surface *wlr_xwayland_surface_create( static void wlr_xwayland_surface_destroy(struct wlr_xwayland_surface *surface) { wl_signal_emit(&surface->events.destroy, surface); - wl_list_remove(&surface->new_link); + wl_list_remove(&surface->link); - if (surface->unpaired) { + if (surface->surface_id) { wl_list_remove(&surface->unpaired_link); - surface->unpaired = false; - } - - if (surface->displayable) { - wl_list_remove(&surface->displayable_link); - surface->displayable = false; } for (size_t i = 0; i < surface->state->length; i++) { @@ -229,7 +201,7 @@ static void read_surface_parent(struct wlr_xwm *xwm, xcb_window_t *xid = xcb_get_property_value(reply); if (xid != NULL) { - surface->parent = lookup_surface_any(xwm, *xid); + surface->parent = lookup_surface(xwm, *xid); } else { surface->parent = NULL; } @@ -477,6 +449,7 @@ static void handle_surface_destroy(struct wl_listener *listener, void *data) { struct wlr_xwayland_surface *xsurface = wl_container_of(listener, xsurface, surface_destroy); + xsurface->surface = NULL; // TODO destroy xwayland surface? } @@ -504,12 +477,6 @@ static void map_shell_surface(struct wlr_xwm *xwm, read_surface_property(xwm, xsurface, props[i]); } - if (!xsurface->displayable) { - wl_list_insert(&xwm->xwayland->displayable_surfaces, - &xsurface->displayable_link); - xsurface->displayable = true; - } - xsurface->surface_commit.notify = handle_surface_commit; wl_signal_add(&surface->events.commit, &xsurface->surface_commit); @@ -530,7 +497,7 @@ static void handle_create_notify(struct wlr_xwm *xwm, static void handle_destroy_notify(struct wlr_xwm *xwm, xcb_destroy_notify_event_t *ev) { wlr_log(L_DEBUG, "XCB_DESTROY_NOTIFY (%u)", ev->window); - struct wlr_xwayland_surface *surface = lookup_surface_any(xwm, ev->window); + struct wlr_xwayland_surface *surface = lookup_surface(xwm, ev->window); if (surface == NULL) { return; } @@ -541,7 +508,7 @@ static void handle_configure_request(struct wlr_xwm *xwm, xcb_configure_request_event_t *ev) { wlr_log(L_DEBUG, "XCB_CONFIGURE_REQUEST (%u) [%ux%u+%d,%d]", ev->window, ev->width, ev->height, ev->x, ev->y); - struct wlr_xwayland_surface *surface = lookup_surface_any(xwm, ev->window); + struct wlr_xwayland_surface *surface = lookup_surface(xwm, ev->window); if (surface == NULL) { return; } @@ -574,7 +541,7 @@ static void handle_configure_request(struct wlr_xwm *xwm, static void handle_configure_notify(struct wlr_xwm *xwm, xcb_configure_notify_event_t *ev) { struct wlr_xwayland_surface *xsurface = - lookup_surface_any(xwm, ev->window); + lookup_surface(xwm, ev->window); if (!xsurface) { return; @@ -594,7 +561,7 @@ static void handle_map_request(struct wlr_xwm *xwm, static void handle_map_notify(struct wlr_xwm *xwm, xcb_map_notify_event_t *ev) { wlr_log(L_DEBUG, "XCB_MAP_NOTIFY (%u)", ev->window); - struct wlr_xwayland_surface *surface = lookup_surface_any(xwm, ev->window); + struct wlr_xwayland_surface *surface = lookup_surface(xwm, ev->window); if (surface != NULL) { surface->override_redirect = ev->override_redirect; } else { @@ -606,18 +573,32 @@ static void handle_map_notify(struct wlr_xwm *xwm, xcb_map_notify_event_t *ev) { static void handle_unmap_notify(struct wlr_xwm *xwm, xcb_unmap_notify_event_t *ev) { wlr_log(L_DEBUG, "XCB_UNMAP_NOTIFY (%u)", ev->window); - struct wlr_xwayland_surface *surface = lookup_surface_any(xwm, ev->window); - if (surface == NULL) { + struct wlr_xwayland_surface *xsurface = lookup_surface(xwm, ev->window); + if (xsurface == NULL) { return; } - // TODO: remove pointer to surface only? - wlr_xwayland_surface_destroy(surface); + + if (xsurface->surface_id) { + // Make sure we're not on the unpaired surface list or we + // could be assigned a surface during surface creation that + // was mapped before this unmap request. + wl_list_remove(&xsurface->unpaired_link); + xsurface->surface_id = 0; + } + + if (xsurface->surface) { + wl_list_remove(&xsurface->surface_commit.link); + wl_list_remove(&xsurface->surface_destroy.link); + xsurface->surface = NULL; + } + + wlr_xwayland_surface_destroy(xsurface); } static void handle_property_notify(struct wlr_xwm *xwm, xcb_property_notify_event_t *ev) { wlr_log(L_DEBUG, "XCB_PROPERTY_NOTIFY (%u)", ev->window); - struct wlr_xwayland_surface *surface = lookup_surface_any(xwm, ev->window); + struct wlr_xwayland_surface *surface = lookup_surface(xwm, ev->window); if (surface == NULL) { return; } @@ -636,21 +617,20 @@ static void handle_client_message(struct wlr_xwm *xwm, ev->window); return; } - surface->surface_id = ev->data.data32[0]; /* Check if we got notified after wayland surface create event */ - struct wl_resource *resource = wl_client_get_object( - xwm->xwayland->client, surface->surface_id); + uint32_t id = ev->data.data32[0]; + struct wl_resource *resource = + wl_client_get_object(xwm->xwayland->client, id); if (resource) { - map_shell_surface(xwm, surface, wl_resource_get_user_data(resource)); + surface->surface_id = 0; + map_shell_surface(xwm, + surface, wl_resource_get_user_data(resource)); } else { - if (!surface->unpaired) { - wl_list_insert(&xwm->unpaired_surfaces, &surface->unpaired_link); - surface->unpaired = true; - } + surface->surface_id = id; + wl_list_insert(&xwm->unpaired_surfaces, &surface->unpaired_link); } } else if (ev->type == xwm->atoms[NET_WM_STATE]) { - struct wlr_xwayland_surface *surface = lookup_surface_any(xwm, - ev->window); + struct wlr_xwayland_surface *surface = lookup_surface(xwm, ev->window); if (surface == NULL) { return; } @@ -839,14 +819,7 @@ void xwm_destroy(struct wlr_xwm *xwm) { wl_event_source_remove(xwm->event_source); } struct wlr_xwayland_surface *surface, *tmp; - wl_list_for_each_safe(surface, tmp, &xwm->xwayland->displayable_surfaces, - displayable_link) { - wlr_xwayland_surface_destroy(surface); - } - wl_list_for_each_safe(surface, tmp, &xwm->new_surfaces, new_link) { - wlr_xwayland_surface_destroy(surface); - } - wl_list_for_each_safe(surface, tmp, &xwm->unpaired_surfaces, unpaired_link) { + wl_list_for_each_safe(surface, tmp, &xwm->surfaces, link) { wlr_xwayland_surface_destroy(surface); } wl_list_remove(&xwm->compositor_surface_create.link); @@ -891,7 +864,7 @@ struct wlr_xwm *xwm_create(struct wlr_xwayland *wlr_xwayland) { } xwm->xwayland = wlr_xwayland; - wl_list_init(&xwm->new_surfaces); + wl_list_init(&xwm->surfaces); wl_list_init(&xwm->unpaired_surfaces); xwm->xcb_conn = xcb_connect_to_fd(wlr_xwayland->wm_fd[0], NULL); diff --git a/xwayland/xwm.h b/xwayland/xwm.h index 9ae084d2..2bb1ff0b 100644 --- a/xwayland/xwm.h +++ b/xwayland/xwm.h @@ -44,7 +44,7 @@ struct wlr_xwm { struct wlr_xwayland_surface *focus_surface; - struct wl_list new_surfaces; // wlr_xwayland_surface::new_link + struct wl_list surfaces; // wlr_xwayland_surface::link struct wl_list unpaired_surfaces; // wlr_xwayland_surface::unpaired_link const xcb_query_extension_reply_t *xfixes; From 87b5b268d1b55644cdcd24e0549776f03423caeb Mon Sep 17 00:00:00 2001 From: emersion Date: Tue, 24 Oct 2017 21:44:30 +0200 Subject: [PATCH 10/32] Remove gamma_control->link from list in destroy --- types/wlr_gamma_control.c | 1 + 1 file changed, 1 insertion(+) diff --git a/types/wlr_gamma_control.c b/types/wlr_gamma_control.c index 9d74e749..e765c2a5 100644 --- a/types/wlr_gamma_control.c +++ b/types/wlr_gamma_control.c @@ -15,6 +15,7 @@ static void gamma_control_destroy(struct wlr_gamma_control *gamma_control) { wl_signal_emit(&gamma_control->events.destroy, gamma_control); wl_list_remove(&gamma_control->output_destroy_listener.link); wl_resource_set_user_data(gamma_control->resource, NULL); + wl_list_remove(&gamma_control->link); free(gamma_control); } From 3277c6d994508aefdfb19a64069cc3be6a92e5b4 Mon Sep 17 00:00:00 2001 From: Alexander Taylor Date: Tue, 24 Oct 2017 23:51:53 +0100 Subject: [PATCH 11/32] Fix order of WM_HINTS and WM_PROTOCOLS in xwm atom_map --- xwayland/xwm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xwayland/xwm.c b/xwayland/xwm.c index 87498fe2..7cdc84c5 100644 --- a/xwayland/xwm.c +++ b/xwayland/xwm.c @@ -16,8 +16,8 @@ const char *atom_map[ATOM_LAST] = { "WL_SURFACE_ID", "WM_DELETE_WINDOW", - "WM_HINTS", "WM_PROTOCOLS", + "WM_HINTS", "WM_NORMAL_HINTS", "WM_SIZE_HINTS", "_MOTIF_WM_HINTS", From 7643765e7b34b719969231a70f7744d2846dfff6 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Tue, 24 Oct 2017 19:16:50 -0400 Subject: [PATCH 12/32] xwm: unpaired surface list cleanup --- xwayland/xwm.c | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/xwayland/xwm.c b/xwayland/xwm.c index 7cdc84c5..160a1927 100644 --- a/xwayland/xwm.c +++ b/xwayland/xwm.c @@ -47,17 +47,6 @@ static struct wlr_xwayland_surface *lookup_surface(struct wlr_xwm *xwm, return NULL; } -static struct wlr_xwayland_surface *lookup_unpaired_surface(struct wlr_xwm *xwm, - xcb_window_t window_id) { - struct wlr_xwayland_surface *surface; - wl_list_for_each(surface, &xwm->unpaired_surfaces, unpaired_link) { - if (surface->window_id == window_id) { - return surface; - } - } - return NULL; -} - static struct wlr_xwayland_surface *wlr_xwayland_surface_create( struct wlr_xwm *xwm, xcb_window_t window_id, int16_t x, int16_t y, uint16_t width, uint16_t height, bool override_redirect) { @@ -707,6 +696,8 @@ static void handle_compositor_surface_create(struct wl_listener *listener, void wl_list_for_each(xwayland_surface, &xwm->unpaired_surfaces, unpaired_link) { if (xwayland_surface->surface_id == surface_id) { map_shell_surface(xwm, xwayland_surface, surface); + xwayland_surface->surface_id = 0; + wl_list_remove(&xwayland_surface->unpaired_link); xcb_flush(xwm->xcb_conn); return; } From 22435e00c5e1507544e27adac4e7ae88d8b49ac2 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Tue, 24 Oct 2017 19:18:31 -0400 Subject: [PATCH 13/32] xwm: 80col cleanup --- xwayland/xwm.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/xwayland/xwm.c b/xwayland/xwm.c index 160a1927..7d676987 100644 --- a/xwayland/xwm.c +++ b/xwayland/xwm.c @@ -154,7 +154,8 @@ static void read_surface_class(struct wlr_xwm *xwm, surface->class = NULL; } - wlr_log(L_DEBUG, "XCB_ATOM_WM_CLASS: %s %s", surface->instance, surface->class); + wlr_log(L_DEBUG, "XCB_ATOM_WM_CLASS: %s %s", surface->instance, + surface->class); wl_signal_emit(&surface->events.set_class, surface); } @@ -602,7 +603,8 @@ static void handle_client_message(struct wlr_xwm *xwm, if (ev->type == xwm->atoms[WL_SURFACE_ID]) { struct wlr_xwayland_surface *surface = lookup_surface(xwm, ev->window); if (surface == NULL) { - wlr_log(L_DEBUG, "client message WL_SURFACE_ID but no new window %u ?", + wlr_log(L_DEBUG, + "client message WL_SURFACE_ID but no new window %u ?", ev->window); return; } @@ -649,7 +651,8 @@ static int x11_event_handler(int fd, uint32_t mask, void *data) { handle_destroy_notify(xwm, (xcb_destroy_notify_event_t *)event); break; case XCB_CONFIGURE_REQUEST: - handle_configure_request(xwm, (xcb_configure_request_event_t *)event); + handle_configure_request(xwm, + (xcb_configure_request_event_t *)event); break; case XCB_CONFIGURE_NOTIFY: handle_configure_notify(xwm, (xcb_configure_notify_event_t *)event); @@ -681,7 +684,8 @@ static int x11_event_handler(int fd, uint32_t mask, void *data) { return count; } -static void handle_compositor_surface_create(struct wl_listener *listener, void *data) { +static void handle_compositor_surface_create(struct wl_listener *listener, + void *data) { struct wlr_surface *surface = data; struct wlr_xwm *xwm = wl_container_of(listener, xwm, compositor_surface_create); @@ -824,7 +828,8 @@ static void xwm_get_resources(struct wlr_xwm *xwm) { xcb_intern_atom_cookie_t cookies[ATOM_LAST]; for (i = 0; i < ATOM_LAST; i++) { - cookies[i] = xcb_intern_atom(xwm->xcb_conn, 0, strlen(atom_map[i]), atom_map[i]); + cookies[i] = + xcb_intern_atom(xwm->xcb_conn, 0, strlen(atom_map[i]), atom_map[i]); } for (i = 0; i < ATOM_LAST; i++) { xcb_intern_atom_reply_t *reply; From e5ee01254b442ae2f742a7044c56753fef13de76 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Tue, 24 Oct 2017 21:07:46 -0400 Subject: [PATCH 14/32] xwm: map and unmap notify --- include/rootston/view.h | 2 ++ include/wlr/xwayland.h | 2 ++ rootston/xwayland.c | 37 +++++++++++++++++++++++++++++++++++++ xwayland/xwm.c | 27 ++++++++++++--------------- 4 files changed, 53 insertions(+), 15 deletions(-) diff --git a/include/rootston/view.h b/include/rootston/view.h index 7d297329..1a0de6de 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 map_notify; + struct wl_listener unmap_notify; }; enum roots_view_type { diff --git a/include/wlr/xwayland.h b/include/wlr/xwayland.h index 3d5a204c..efee3d9f 100644 --- a/include/wlr/xwayland.h +++ b/include/wlr/xwayland.h @@ -99,6 +99,8 @@ struct wlr_xwayland_surface { struct { struct wl_signal destroy; struct wl_signal request_configure; + struct wl_signal map_notify; + struct wl_signal unmap_notify; struct wl_signal set_title; struct wl_signal set_class; struct wl_signal set_parent; 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); diff --git a/xwayland/xwm.c b/xwayland/xwm.c index 7d676987..6850f56b 100644 --- a/xwayland/xwm.c +++ b/xwayland/xwm.c @@ -75,6 +75,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.map_notify); + wl_signal_init(&surface->events.unmap_notify); wl_signal_init(&surface->events.set_class); wl_signal_init(&surface->events.set_title); wl_signal_init(&surface->events.set_parent); @@ -474,6 +476,7 @@ static void map_shell_surface(struct wlr_xwm *xwm, wl_signal_add(&surface->events.destroy, &xsurface->surface_destroy); xsurface->mapped = true; + wl_signal_emit(&xsurface->events.map_notify, xsurface); } /* xcb event handlers */ @@ -551,13 +554,6 @@ static void handle_map_request(struct wlr_xwm *xwm, static void handle_map_notify(struct wlr_xwm *xwm, xcb_map_notify_event_t *ev) { wlr_log(L_DEBUG, "XCB_MAP_NOTIFY (%u)", ev->window); - struct wlr_xwayland_surface *surface = lookup_surface(xwm, ev->window); - if (surface != NULL) { - surface->override_redirect = ev->override_redirect; - } else { - wlr_xwayland_surface_create(xwm, ev->window, 0, 0, 1, 1, - ev->override_redirect); - } } static void handle_unmap_notify(struct wlr_xwm *xwm, @@ -579,10 +575,11 @@ static void handle_unmap_notify(struct wlr_xwm *xwm, if (xsurface->surface) { wl_list_remove(&xsurface->surface_commit.link); wl_list_remove(&xsurface->surface_destroy.link); - xsurface->surface = NULL; } + xsurface->surface = NULL; - wlr_xwayland_surface_destroy(xsurface); + xsurface->mapped = false; + wl_signal_emit(&xsurface->events.unmap_notify, xsurface); } static void handle_property_notify(struct wlr_xwm *xwm, @@ -696,12 +693,12 @@ static void handle_compositor_surface_create(struct wl_listener *listener, wlr_log(L_DEBUG, "New xwayland surface: %p", surface); uint32_t surface_id = wl_resource_get_id(surface->resource); - struct wlr_xwayland_surface *xwayland_surface; - wl_list_for_each(xwayland_surface, &xwm->unpaired_surfaces, unpaired_link) { - if (xwayland_surface->surface_id == surface_id) { - map_shell_surface(xwm, xwayland_surface, surface); - xwayland_surface->surface_id = 0; - wl_list_remove(&xwayland_surface->unpaired_link); + struct wlr_xwayland_surface *xsurface; + wl_list_for_each(xsurface, &xwm->unpaired_surfaces, unpaired_link) { + if (xsurface->surface_id == surface_id) { + map_shell_surface(xwm, xsurface, surface); + xsurface->surface_id = 0; + wl_list_remove(&xsurface->unpaired_link); xcb_flush(xwm->xcb_conn); return; } From 1be650d78a5612164fff9b3b20c5a2a89f13bdf0 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Wed, 25 Oct 2017 07:12:25 -0400 Subject: [PATCH 15/32] xwm: only emit unmap notify once --- xwayland/xwm.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/xwayland/xwm.c b/xwayland/xwm.c index 6850f56b..7827295e 100644 --- a/xwayland/xwm.c +++ b/xwayland/xwm.c @@ -578,8 +578,10 @@ static void handle_unmap_notify(struct wlr_xwm *xwm, } xsurface->surface = NULL; - xsurface->mapped = false; - wl_signal_emit(&xsurface->events.unmap_notify, xsurface); + if (xsurface->mapped) { + xsurface->mapped = false; + wl_signal_emit(&xsurface->events.unmap_notify, xsurface); + } } static void handle_property_notify(struct wlr_xwm *xwm, From 0d1dd84a48cbfec848866cfbe4e62652765d7c98 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Wed, 25 Oct 2017 08:39:28 -0400 Subject: [PATCH 16/32] 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(-) 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, From b443b9a9987d240e7e5f5ecb766f5ccd7987e35f Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Wed, 25 Oct 2017 08:42:42 -0400 Subject: [PATCH 17/32] xwm: set net active window on xwm create --- xwayland/xwm.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/xwayland/xwm.c b/xwayland/xwm.c index f39f8391..213e633a 100644 --- a/xwayland/xwm.c +++ b/xwayland/xwm.c @@ -957,5 +957,7 @@ struct wlr_xwm *xwm_create(struct wlr_xwayland *wlr_xwayland) { wl_signal_add(&wlr_xwayland->compositor->events.create_surface, &xwm->compositor_surface_create); + xwm_set_net_active_window(xwm, XCB_WINDOW_NONE); + return xwm; } From d6a1e6fd79c7fbd961e1eeaa9df63377e519de3e Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Wed, 25 Oct 2017 18:51:15 -0400 Subject: [PATCH 18/32] xwm: dont flush if no events --- xwayland/xwm.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/xwayland/xwm.c b/xwayland/xwm.c index 213e633a..27d8bff9 100644 --- a/xwayland/xwm.c +++ b/xwayland/xwm.c @@ -739,7 +739,10 @@ static int x11_event_handler(int fd, uint32_t mask, void *data) { free(event); } - xcb_flush(xwm->xcb_conn); + if (count) { + xcb_flush(xwm->xcb_conn); + } + return count; } From 7914f4bda9aa2ea9e57ac36ec0d49e8a2c49d182 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Wed, 25 Oct 2017 20:40:55 -0400 Subject: [PATCH 19/32] xwm: dont focus override redirect windows --- rootston/cursor.c | 8 +++++--- rootston/desktop.c | 1 - rootston/keyboard.c | 2 -- xwayland/xwm.c | 7 ++++++- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/rootston/cursor.c b/rootston/cursor.c index b55eab3f..9193f9b7 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -172,6 +172,10 @@ void set_view_focus(struct roots_input *input, struct roots_desktop *desktop, if (!view) { return; } + if (view->type == ROOTS_XWAYLAND_VIEW && + view->xwayland_surface->override_redirect) { + return; + } input->last_active_view = view; size_t index = 0; @@ -187,6 +191,7 @@ void set_view_focus(struct roots_input *input, struct roots_desktop *desktop, // TODO: list_swap wlr_list_del(desktop->views, index); wlr_list_add(desktop->views, view); + wlr_seat_keyboard_notify_enter(input->wl_seat, view->wlr_surface); } static void handle_cursor_motion(struct wl_listener *listener, void *data) { @@ -275,9 +280,6 @@ static void do_cursor_button_press(struct roots_input *input, input->input_events_idx = (i + 1) % (sizeof(input->input_events) / sizeof(input->input_events[0])); set_view_focus(input, desktop, view); - if (view) { - wlr_seat_keyboard_notify_enter(input->wl_seat, surface); - } break; } } diff --git a/rootston/desktop.c b/rootston/desktop.c index 30b5a519..9438ecea 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -112,7 +112,6 @@ void view_initialize(struct roots_view *view) { struct roots_input *input = view->desktop->server->input; set_view_focus(input, view->desktop, view); - wlr_seat_keyboard_notify_enter(input->wl_seat, view->wlr_surface); } struct roots_view *view_at(struct roots_desktop *desktop, double lx, double ly, diff --git a/rootston/keyboard.c b/rootston/keyboard.c index 61604da0..ef0826aa 100644 --- a/rootston/keyboard.c +++ b/rootston/keyboard.c @@ -36,8 +36,6 @@ static void keyboard_binding_execute(struct roots_keyboard *keyboard, if (server->desktop->views->length > 0) { struct roots_view *view = server->desktop->views->items[0]; set_view_focus(keyboard->input, server->desktop, view); - wlr_seat_keyboard_notify_enter(keyboard->input->wl_seat, - view->wlr_surface); } } else if (strncmp(exec_prefix, command, strlen(exec_prefix)) == 0) { const char *shell_cmd = command + strlen(exec_prefix); diff --git a/xwayland/xwm.c b/xwayland/xwm.c index 27d8bff9..90f2f21c 100644 --- a/xwayland/xwm.c +++ b/xwayland/xwm.c @@ -96,6 +96,10 @@ static void xwm_set_net_active_window(struct wlr_xwm *xwm, static void xwm_send_focus_window(struct wlr_xwm *xwm, struct wlr_xwayland_surface *surface) { if (surface) { + if (surface->override_redirect) { + return; + } + xcb_client_message_event_t client_message; client_message.response_type = XCB_CLIENT_MESSAGE; client_message.format = 32; @@ -124,7 +128,8 @@ static void xwm_send_focus_window(struct wlr_xwm *xwm, void xwm_surface_activate(struct wlr_xwm *xwm, struct wlr_xwayland_surface *xsurface) { - if (xwm->focus_surface == xsurface) { + if (xwm->focus_surface == xsurface || + (xsurface && xsurface->override_redirect)) { return; } From a861b380ef09274b6e9295c2a7d7014425e5b6ae Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Wed, 25 Oct 2017 20:41:55 -0400 Subject: [PATCH 20/32] xwm: add net active window to supported --- xwayland/xwm.c | 1 + 1 file changed, 1 insertion(+) diff --git a/xwayland/xwm.c b/xwayland/xwm.c index 90f2f21c..efef1b20 100644 --- a/xwayland/xwm.c +++ b/xwayland/xwm.c @@ -930,6 +930,7 @@ struct wlr_xwm *xwm_create(struct wlr_xwayland *wlr_xwayland) { XCB_CW_EVENT_MASK, (uint32_t[]){XCB_EVENT_MASK_PROPERTY_CHANGE})); xcb_atom_t supported[] = { xwm->atoms[NET_WM_STATE], + xwm->atoms[_NET_ACTIVE_WINDOW], }; XCB_CALL(xwm, xcb_change_property_checked(xwm->xcb_conn, From ff0006d0f03a8793cbd8ca58ae6c376283748d2a Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Thu, 26 Oct 2017 09:01:53 -0400 Subject: [PATCH 21/32] xwm: refactor client message handler --- xwayland/xwm.c | 68 +++++++++++++++++++++++++++++++------------------- xwayland/xwm.h | 1 + 2 files changed, 44 insertions(+), 25 deletions(-) diff --git a/xwayland/xwm.c b/xwayland/xwm.c index efef1b20..98b23065 100644 --- a/xwayland/xwm.c +++ b/xwayland/xwm.c @@ -32,6 +32,7 @@ const char *atom_map[ATOM_LAST] = { "WM_TAKE_FOCUS", "WINDOW", "_NET_ACTIVE_WINDOW", + "_NET_WM_MOVERESIZE", }; /* General helpers */ @@ -660,37 +661,54 @@ static void handle_property_notify(struct wlr_xwm *xwm, read_surface_property(xwm, surface, ev->atom); } +static void handle_surface_id_message(struct wlr_xwm *xwm, + xcb_client_message_event_t *ev) { + struct wlr_xwayland_surface *xsurface = lookup_surface(xwm, ev->window); + if (xsurface == NULL) { + wlr_log(L_DEBUG, + "client message WL_SURFACE_ID but no new window %u ?", + ev->window); + return; + } + /* Check if we got notified after wayland surface create event */ + uint32_t id = ev->data.data32[0]; + struct wl_resource *resource = + wl_client_get_object(xwm->xwayland->client, id); + if (resource) { + struct wlr_surface *surface = wl_resource_get_user_data(resource); + xsurface->surface_id = 0; + map_shell_surface(xwm, xsurface, surface); + } else { + xsurface->surface_id = id; + wl_list_insert(&xwm->unpaired_surfaces, &xsurface->unpaired_link); + } +} + +static void handle_net_wm_state_message(struct wlr_xwm *xwm, + xcb_client_message_event_t *ev) { + struct wlr_xwayland_surface *xsurface = lookup_surface(xwm, ev->window); + if (xsurface == NULL) { + return; + } + handle_surface_state(xwm, xsurface, &ev->data.data32[1], 2, + ev->data.data32[0]); +} + +static void handle_net_wm_moveresize_message(struct wlr_xwm *xwm, + xcb_client_message_event_t *ev) { + wlr_log(L_DEBUG, "TODO: handle moveresize"); +} + static void handle_client_message(struct wlr_xwm *xwm, xcb_client_message_event_t *ev) { wlr_log(L_DEBUG, "XCB_CLIENT_MESSAGE (%u)", ev->window); if (ev->type == xwm->atoms[WL_SURFACE_ID]) { - struct wlr_xwayland_surface *surface = lookup_surface(xwm, ev->window); - if (surface == NULL) { - wlr_log(L_DEBUG, - "client message WL_SURFACE_ID but no new window %u ?", - ev->window); - return; - } - /* Check if we got notified after wayland surface create event */ - uint32_t id = ev->data.data32[0]; - struct wl_resource *resource = - wl_client_get_object(xwm->xwayland->client, id); - if (resource) { - surface->surface_id = 0; - map_shell_surface(xwm, - surface, wl_resource_get_user_data(resource)); - } else { - surface->surface_id = id; - wl_list_insert(&xwm->unpaired_surfaces, &surface->unpaired_link); - } + handle_surface_id_message(xwm, ev); } else if (ev->type == xwm->atoms[NET_WM_STATE]) { - struct wlr_xwayland_surface *surface = lookup_surface(xwm, ev->window); - if (surface == NULL) { - return; - } - handle_surface_state(xwm, surface, &ev->data.data32[1], 2, - ev->data.data32[0]); + handle_net_wm_state_message(xwm, ev); + } else if (ev->type == xwm->atoms[_NET_WM_MOVERESIZE]) { + handle_net_wm_moveresize_message(xwm, ev); } else { wlr_log(L_DEBUG, "unhandled x11 client message %u", ev->type); } diff --git a/xwayland/xwm.h b/xwayland/xwm.h index 2bb1ff0b..30183834 100644 --- a/xwayland/xwm.h +++ b/xwayland/xwm.h @@ -22,6 +22,7 @@ enum atom_name { WM_TAKE_FOCUS, WINDOW, _NET_ACTIVE_WINDOW, + _NET_WM_MOVERESIZE, ATOM_LAST, }; From 263279b7e0f84e9fece884bb3d87d908da8cfb80 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Thu, 26 Oct 2017 10:39:36 -0400 Subject: [PATCH 22/32] xwm: rewrite xwm initialization --- xwayland/xwm.c | 188 +++++++++++++++++++++++++++++++------------------ xwayland/xwm.h | 2 + 2 files changed, 122 insertions(+), 68 deletions(-) diff --git a/xwayland/xwm.c b/xwayland/xwm.c index 98b23065..93dfdbff 100644 --- a/xwayland/xwm.c +++ b/xwayland/xwm.c @@ -2,6 +2,7 @@ #define _POSIX_C_SOURCE 200809L #endif #include +#include #include #include #include "wlr/util/log.h" @@ -33,6 +34,8 @@ const char *atom_map[ATOM_LAST] = { "WINDOW", "_NET_ACTIVE_WINDOW", "_NET_WM_MOVERESIZE", + "_NET_WM_NAME", + "_NET_SUPPORTING_WM_CHECK", }; /* General helpers */ @@ -867,6 +870,9 @@ void xwm_destroy(struct wlr_xwm *xwm) { } static void xwm_get_resources(struct wlr_xwm *xwm) { + xcb_prefetch_extension_data(xwm->xcb_conn, &xcb_xfixes_id); + xcb_prefetch_extension_data(xwm->xcb_conn, &xcb_composite_id); + size_t i; xcb_intern_atom_cookie_t cookies[ATOM_LAST]; @@ -893,73 +899,6 @@ static void xwm_get_resources(struct wlr_xwm *xwm) { return; } } -} - - -struct wlr_xwm *xwm_create(struct wlr_xwayland *wlr_xwayland) { - struct wlr_xwm *xwm = calloc(1, sizeof(struct wlr_xwm)); - if (xwm == NULL) { - return NULL; - } - - xwm->xwayland = wlr_xwayland; - wl_list_init(&xwm->surfaces); - wl_list_init(&xwm->unpaired_surfaces); - - xwm->xcb_conn = xcb_connect_to_fd(wlr_xwayland->wm_fd[0], NULL); - - int rc = xcb_connection_has_error(xwm->xcb_conn); - if (rc) { - wlr_log(L_ERROR, "xcb connect failed: %d", rc); - free(xwm); - return NULL; - } - - struct wl_event_loop *event_loop = wl_display_get_event_loop( - wlr_xwayland->wl_display); - xwm->event_source = wl_event_loop_add_fd(event_loop, wlr_xwayland->wm_fd[0], - WL_EVENT_READABLE, x11_event_handler, xwm); - wl_event_source_check(xwm->event_source); - - xcb_prefetch_extension_data(xwm->xcb_conn, &xcb_xfixes_id); - - xwm_get_resources(xwm); - - xcb_screen_iterator_t screen_iterator = - xcb_setup_roots_iterator(xcb_get_setup(xwm->xcb_conn)); - xwm->screen = screen_iterator.data; - - xwm->window = xcb_generate_id(xwm->xcb_conn); - - uint32_t values[] = { - XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY | - XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT | - XCB_EVENT_MASK_PROPERTY_CHANGE, - /* xwm->cursor, */ - }; - XCB_CALL(xwm, xcb_change_window_attributes_checked(xwm->xcb_conn, - xwm->screen->root, XCB_CW_EVENT_MASK /* | XCB_CW_CURSOR */, values)); - XCB_CALL(xwm, xcb_composite_redirect_subwindows_checked(xwm->xcb_conn, - xwm->screen->root, XCB_COMPOSITE_REDIRECT_MANUAL)); - - XCB_CALL(xwm, xcb_create_window_checked(xwm->xcb_conn, XCB_COPY_FROM_PARENT, - xwm->window, xwm->screen->root, 0, 0, 1, 1, 0, - XCB_WINDOW_CLASS_INPUT_OUTPUT, xwm->screen->root_visual, - XCB_CW_EVENT_MASK, (uint32_t[]){XCB_EVENT_MASK_PROPERTY_CHANGE})); - xcb_atom_t supported[] = { - xwm->atoms[NET_WM_STATE], - xwm->atoms[_NET_ACTIVE_WINDOW], - }; - - XCB_CALL(xwm, xcb_change_property_checked(xwm->xcb_conn, - XCB_PROP_MODE_REPLACE, xwm->screen->root, xwm->atoms[NET_SUPPORTED], - XCB_ATOM_ATOM, 32, sizeof(supported)/sizeof(*supported), supported)); - - XCB_CALL(xwm, xcb_set_selection_owner_checked(xwm->xcb_conn, xwm->window, - xwm->atoms[WM_S0], XCB_CURRENT_TIME)); - XCB_CALL(xwm, xcb_set_selection_owner_checked(xwm->xcb_conn, xwm->window, - xwm->atoms[NET_WM_S0], XCB_CURRENT_TIME)); - xcb_flush(xwm->xcb_conn); xwm->xfixes = xcb_get_extension_data(xwm->xcb_conn, &xcb_xfixes_id); @@ -980,11 +919,124 @@ struct wlr_xwm *xwm_create(struct wlr_xwayland *wlr_xwayland) { free(xfixes_reply); +} + +static void xwm_create_wm_window(struct wlr_xwm *xwm) { + static const char name[] = "wlroots wm"; + + xwm->window = xcb_generate_id(xwm->xcb_conn); + + xcb_create_window(xwm->xcb_conn, + XCB_COPY_FROM_PARENT, + xwm->window, + xwm->screen->root, + 0, 0, + 10, 10, + 0, + XCB_WINDOW_CLASS_INPUT_OUTPUT, + xwm->screen->root_visual, + 0, NULL); + + xcb_change_property(xwm->xcb_conn, + XCB_PROP_MODE_REPLACE, + xwm->window, + xwm->atoms[_NET_WM_NAME], + xwm->atoms[UTF8_STRING], + 8, // format + strlen(name), name); + + xcb_change_property(xwm->xcb_conn, + XCB_PROP_MODE_REPLACE, + xwm->screen->root, + 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], + XCB_CURRENT_TIME); + + xcb_set_selection_owner(xwm->xcb_conn, + xwm->window, + xwm->atoms[NET_WM_S0], + XCB_CURRENT_TIME); +} + +struct wlr_xwm *xwm_create(struct wlr_xwayland *wlr_xwayland) { + struct wlr_xwm *xwm = calloc(1, sizeof(struct wlr_xwm)); + if (xwm == NULL) { + return NULL; + } + + xwm->xwayland = wlr_xwayland; + wl_list_init(&xwm->surfaces); + wl_list_init(&xwm->unpaired_surfaces); + + xwm->xcb_conn = xcb_connect_to_fd(wlr_xwayland->wm_fd[0], NULL); + + int rc = xcb_connection_has_error(xwm->xcb_conn); + if (rc) { + wlr_log(L_ERROR, "xcb connect failed: %d", rc); + close(wlr_xwayland->wm_fd[0]); + free(xwm); + return NULL; + } + + xcb_screen_iterator_t screen_iterator = + xcb_setup_roots_iterator(xcb_get_setup(xwm->xcb_conn)); + xwm->screen = screen_iterator.data; + + struct wl_event_loop *event_loop = wl_display_get_event_loop( + wlr_xwayland->wl_display); + xwm->event_source = + wl_event_loop_add_fd(event_loop, + wlr_xwayland->wm_fd[0], + WL_EVENT_READABLE, + x11_event_handler, + xwm); + wl_event_source_check(xwm->event_source); + + xwm_get_resources(xwm); + + uint32_t values[1]; + values[0] = + XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY | + XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT | + XCB_EVENT_MASK_PROPERTY_CHANGE; + + xcb_change_window_attributes(xwm->xcb_conn, + xwm->screen->root, + XCB_CW_EVENT_MASK /* | XCB_CW_CURSOR */, + values); + + xcb_composite_redirect_subwindows_checked(xwm->xcb_conn, xwm->screen->root, + XCB_COMPOSITE_REDIRECT_MANUAL); + + xcb_atom_t supported[] = { + xwm->atoms[NET_WM_STATE], + xwm->atoms[_NET_ACTIVE_WINDOW], + xwm->atoms[_NET_WM_MOVERESIZE], + }; + xcb_change_property(xwm->xcb_conn, + XCB_PROP_MODE_REPLACE, + xwm->screen->root, + xwm->atoms[NET_SUPPORTED], + XCB_ATOM_ATOM, + 32, + sizeof(supported)/sizeof(*supported), + supported); + + xwm_set_net_active_window(xwm, XCB_WINDOW_NONE); + xwm->compositor_surface_create.notify = handle_compositor_surface_create; wl_signal_add(&wlr_xwayland->compositor->events.create_surface, &xwm->compositor_surface_create); - xwm_set_net_active_window(xwm, XCB_WINDOW_NONE); + xwm_create_wm_window(xwm); + + xcb_flush(xwm->xcb_conn); return xwm; } diff --git a/xwayland/xwm.h b/xwayland/xwm.h index 30183834..05fcfa7e 100644 --- a/xwayland/xwm.h +++ b/xwayland/xwm.h @@ -23,6 +23,8 @@ enum atom_name { WINDOW, _NET_ACTIVE_WINDOW, _NET_WM_MOVERESIZE, + _NET_WM_NAME, + _NET_SUPPORTING_WM_CHECK, ATOM_LAST, }; From 930ab0685738a150c6e23b6030877f479accf50f Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Thu, 26 Oct 2017 11:39:08 -0400 Subject: [PATCH 23/32] xwm: send net_wm_state --- xwayland/xwm.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/xwayland/xwm.c b/xwayland/xwm.c index 93dfdbff..afbc1387 100644 --- a/xwayland/xwm.c +++ b/xwayland/xwm.c @@ -615,9 +615,36 @@ static void handle_configure_notify(struct wlr_xwm *xwm, xsurface->height = ev->height; } +#define ICCCM_WITHDRAWN_STATE 0 +#define ICCCM_NORMAL_STATE 1 +#define ICCCM_ICONIC_STATE 3 + +static void xsurface_set_wm_state(struct wlr_xwayland_surface *xsurface, + int32_t state) { + struct wlr_xwm *xwm = xsurface->xwm; + uint32_t property[2]; + + property[0] = state; + property[1] = XCB_WINDOW_NONE; + + xcb_change_property(xwm->xcb_conn, + XCB_PROP_MODE_REPLACE, + xsurface->window_id, + xwm->atoms[NET_WM_STATE], + xwm->atoms[NET_WM_STATE], + 32, // format + 2, property); +} + static void handle_map_request(struct wlr_xwm *xwm, xcb_map_request_event_t *ev) { wlr_log(L_DEBUG, "XCB_MAP_REQUEST (%u)", ev->window); + struct wlr_xwayland_surface *xsurface = lookup_surface(xwm, ev->window); + if (!xsurface) { + return; + } + + xsurface_set_wm_state(xsurface, ICCCM_NORMAL_STATE); xcb_map_window(xwm->xcb_conn, ev->window); } @@ -651,6 +678,8 @@ static void handle_unmap_notify(struct wlr_xwm *xwm, xsurface->mapped = false; wl_signal_emit(&xsurface->events.unmap_notify, xsurface); } + + xsurface_set_wm_state(xsurface, ICCCM_WITHDRAWN_STATE); } static void handle_property_notify(struct wlr_xwm *xwm, From 32b848bd467537767001f5da28e32f02d4b7c8dc Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Thu, 26 Oct 2017 11:54:39 -0400 Subject: [PATCH 24/32] xwm: handle focus in --- xwayland/xwm.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/xwayland/xwm.c b/xwayland/xwm.c index afbc1387..01d09768 100644 --- a/xwayland/xwm.c +++ b/xwayland/xwm.c @@ -746,6 +746,21 @@ static void handle_client_message(struct wlr_xwm *xwm, } } +static void handle_focus_in(struct wlr_xwm *xwm, + xcb_focus_in_event_t *ev) { + // Do not interfere with grabs + if (ev->mode == XCB_NOTIFY_MODE_GRAB || + ev->mode == XCB_NOTIFY_MODE_UNGRAB) { + return; + } + + // Do not let X clients change the focus behind the compositor's + // back. Reset the focus to the old one if it changed. + if (!xwm->focus_surface || ev->event != xwm->focus_surface->window_id) { + xwm_send_focus_window(xwm, xwm->focus_surface); + } +} + /* This is in xcb/xcb_event.h, but pulling xcb-util just for a constant * others redefine anyway is meh */ @@ -786,6 +801,9 @@ static int x11_event_handler(int fd, uint32_t mask, void *data) { case XCB_CLIENT_MESSAGE: handle_client_message(xwm, (xcb_client_message_event_t *)event); break; + case XCB_FOCUS_IN: + handle_focus_in(xwm, (xcb_focus_in_event_t *)event); + break; default: wlr_log(L_DEBUG, "X11 event: %d", event->response_type & XCB_EVENT_RESPONSE_TYPE_MASK); From 4a106648c4455793560d8ca3e60082a6f1d5f791 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Thu, 26 Oct 2017 15:58:18 -0400 Subject: [PATCH 25/32] xwm: remove incorrect implementation of net wm state --- include/wlr/xwayland.h | 5 +++ xwayland/xwm.c | 82 +++++++++++++++++------------------------- xwayland/xwm.h | 3 ++ 3 files changed, 40 insertions(+), 50 deletions(-) diff --git a/include/wlr/xwayland.h b/include/wlr/xwayland.h index e7598d4c..6198ff22 100644 --- a/include/wlr/xwayland.h +++ b/include/wlr/xwayland.h @@ -96,6 +96,11 @@ struct wlr_xwayland_surface { uint32_t hints_urgency; struct wlr_xwayland_surface_size_hints *size_hints; + // _NET_WM_STATE + bool fullscreen; + bool maximized_vert; + bool maximized_horz; + struct { struct wl_signal destroy; struct wl_signal request_configure; diff --git a/xwayland/xwm.c b/xwayland/xwm.c index 01d09768..b52dfcf7 100644 --- a/xwayland/xwm.c +++ b/xwayland/xwm.c @@ -36,6 +36,9 @@ const char *atom_map[ATOM_LAST] = { "_NET_WM_MOVERESIZE", "_NET_WM_NAME", "_NET_SUPPORTING_WM_CHECK", + "_NET_WM_STATE_FULLSCREEN", + "_NET_WM_STATE_MAXIMIZED_VERT", + "_NET_WM_STATE_MAXIMIZED_HORZ", }; /* General helpers */ @@ -150,6 +153,30 @@ void xwm_surface_activate(struct wlr_xwm *xwm, xcb_flush(xwm->xcb_conn); } +static void xsurface_set_net_wm_state(struct wlr_xwayland_surface *xsurface) { + struct wlr_xwm *xwm = xsurface->xwm; + uint32_t property[3]; + int i; + + i = 0; + if (xsurface->fullscreen) { + property[i++] = xwm->atoms[_NET_WM_STATE_FULLSCREEN]; + } + if (xsurface->maximized_vert) { + property[i++] = xwm->atoms[_NET_WM_STATE_MAXIMIZED_VERT]; + } + if (xsurface->maximized_horz) { + property[i++] = xwm->atoms[_NET_WM_STATE_MAXIMIZED_HORZ]; + } + + xcb_change_property(xwm->xcb_conn, + XCB_PROP_MODE_REPLACE, + xsurface->window_id, + xwm->atoms[NET_WM_STATE], + XCB_ATOM_ATOM, + 32, // format + i, property); +} static void wlr_xwayland_surface_destroy(struct wlr_xwayland_surface *surface) { wl_signal_emit(&surface->events.destroy, surface); @@ -271,44 +298,6 @@ static void read_surface_parent(struct wlr_xwm *xwm, wl_signal_emit(&surface->events.set_parent, surface); } -static void handle_surface_state(struct wlr_xwm *xwm, - struct wlr_xwayland_surface *surface, xcb_atom_t *state, - size_t state_len, enum net_wm_state_action action) { - for (size_t i = 0; i < state_len; i++) { - xcb_atom_t atom = state[i]; - bool found = false; - for (size_t j = 0; j < surface->state->length; j++) { - xcb_atom_t *cur = surface->state->items[j]; - if (atom == *cur) { - found = true; - if (action == NET_WM_STATE_REMOVE || - action == NET_WM_STATE_TOGGLE) { - free(surface->state->items[j]); - wlr_list_del(surface->state, j); - } - break; - } - } - - if (!found && (action == NET_WM_STATE_ADD || - action == NET_WM_STATE_TOGGLE)) { - xcb_atom_t *atom_ptr = malloc(sizeof(xcb_atom_t)); - *atom_ptr = atom; - wlr_list_add(surface->state, atom_ptr); - } - } - - wlr_log(L_DEBUG, "NET_WM_STATE (%zu)", state_len); - wl_signal_emit(&surface->events.set_state, surface); -} - -static void read_surface_state(struct wlr_xwm *xwm, - struct wlr_xwayland_surface *surface, xcb_get_property_reply_t *reply) { - // reply->type == XCB_ATOM_ANY - handle_surface_state(xwm, surface, xcb_get_property_value(reply), - reply->value_len, NET_WM_STATE_ADD); -} - static void read_surface_pid(struct wlr_xwm *xwm, struct wlr_xwayland_surface *surface, xcb_get_property_reply_t *reply) { if (reply->type != XCB_ATOM_CARDINAL) { @@ -480,7 +469,7 @@ static void read_surface_property(struct wlr_xwm *xwm, } else if (property == xwm->atoms[WM_PROTOCOLS]) { read_surface_protocols(xwm, surface, reply); } else if (property == xwm->atoms[NET_WM_STATE]) { - read_surface_state(xwm, surface, reply); + wlr_log(L_DEBUG, "TODO: read _NET_WM_STATE property"); } else if (property == xwm->atoms[WM_HINTS]) { read_surface_hints(xwm, surface, reply); } else if (property == xwm->atoms[WM_NORMAL_HINTS]) { @@ -645,6 +634,7 @@ static void handle_map_request(struct wlr_xwm *xwm, } xsurface_set_wm_state(xsurface, ICCCM_NORMAL_STATE); + xsurface_set_net_wm_state(xsurface); xcb_map_window(xwm->xcb_conn, ev->window); } @@ -716,16 +706,6 @@ static void handle_surface_id_message(struct wlr_xwm *xwm, } } -static void handle_net_wm_state_message(struct wlr_xwm *xwm, - xcb_client_message_event_t *ev) { - struct wlr_xwayland_surface *xsurface = lookup_surface(xwm, ev->window); - if (xsurface == NULL) { - return; - } - handle_surface_state(xwm, xsurface, &ev->data.data32[1], 2, - ev->data.data32[0]); -} - static void handle_net_wm_moveresize_message(struct wlr_xwm *xwm, xcb_client_message_event_t *ev) { wlr_log(L_DEBUG, "TODO: handle moveresize"); @@ -738,7 +718,7 @@ static void handle_client_message(struct wlr_xwm *xwm, if (ev->type == xwm->atoms[WL_SURFACE_ID]) { handle_surface_id_message(xwm, ev); } else if (ev->type == xwm->atoms[NET_WM_STATE]) { - handle_net_wm_state_message(xwm, ev); + wlr_log(L_DEBUG, "TODO: handle _NET_WM_STATE client message"); } else if (ev->type == xwm->atoms[_NET_WM_MOVERESIZE]) { handle_net_wm_moveresize_message(xwm, ev); } else { @@ -1075,6 +1055,8 @@ struct wlr_xwm *xwm_create(struct wlr_xwayland *wlr_xwayland) { sizeof(supported)/sizeof(*supported), supported); + xcb_flush(xwm->xcb_conn); + xwm_set_net_active_window(xwm, XCB_WINDOW_NONE); xwm->compositor_surface_create.notify = handle_compositor_surface_create; diff --git a/xwayland/xwm.h b/xwayland/xwm.h index 05fcfa7e..4f8c20a2 100644 --- a/xwayland/xwm.h +++ b/xwayland/xwm.h @@ -25,6 +25,9 @@ enum atom_name { _NET_WM_MOVERESIZE, _NET_WM_NAME, _NET_SUPPORTING_WM_CHECK, + _NET_WM_STATE_FULLSCREEN, + _NET_WM_STATE_MAXIMIZED_VERT, + _NET_WM_STATE_MAXIMIZED_HORZ, ATOM_LAST, }; From 6a4290b86ac282a899221834465df81bdd9d6bc9 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Fri, 27 Oct 2017 10:48:09 -0400 Subject: [PATCH 26/32] 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(-) 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], From be297d9d144739e39e9264bc91fa95990873ced0 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Fri, 27 Oct 2017 13:05:14 -0400 Subject: [PATCH 27/32] xwm: net wm state --- include/wlr/xwayland.h | 17 +++++- xwayland/xwm.c | 118 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 129 insertions(+), 6 deletions(-) diff --git a/include/wlr/xwayland.h b/include/wlr/xwayland.h index b108028f..cc5d06cb 100644 --- a/include/wlr/xwayland.h +++ b/include/wlr/xwayland.h @@ -74,6 +74,7 @@ struct wlr_xwayland_surface { struct wlr_surface *surface; int16_t x, y; uint16_t width, height; + uint16_t saved_width, saved_height; bool override_redirect; bool mapped; bool added; @@ -106,12 +107,14 @@ struct wlr_xwayland_surface { struct wl_signal request_configure; struct wl_signal request_move; struct wl_signal request_resize; + struct wl_signal request_maximize; + struct wl_signal request_fullscreen; + struct wl_signal map_notify; struct wl_signal unmap_notify; struct wl_signal set_title; struct wl_signal set_class; struct wl_signal set_parent; - struct wl_signal set_state; struct wl_signal set_pid; struct wl_signal set_window_type; } events; @@ -138,15 +141,25 @@ struct wlr_xwayland_resize_event { 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); + +void wlr_xwayland_destroy(struct wlr_xwayland *wlr_xwayland); + void wlr_xwayland_surface_activate(struct wlr_xwayland *wlr_xwayland, 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); + void wlr_xwayland_surface_close(struct wlr_xwayland *wlr_xwayland, struct wlr_xwayland_surface *surface); +void wlr_xwayland_surface_set_maximized(struct wlr_xwayland *wlr_xwayland, + struct wlr_xwayland_surface *surface, bool maximized); + +void wlr_xwayland_surface_set_fullscreen(struct wlr_xwayland *wlr_xwayland, + struct wlr_xwayland_surface *surface, bool fullscreen); + #endif diff --git a/xwayland/xwm.c b/xwayland/xwm.c index 2caae3a7..5ba91370 100644 --- a/xwayland/xwm.c +++ b/xwayland/xwm.c @@ -79,17 +79,17 @@ static struct wlr_xwayland_surface *wlr_xwayland_surface_create( surface->height = height; surface->override_redirect = override_redirect; wl_list_insert(&xwm->surfaces, &surface->link); - 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.request_maximize); + wl_signal_init(&surface->events.request_fullscreen); wl_signal_init(&surface->events.map_notify); wl_signal_init(&surface->events.unmap_notify); wl_signal_init(&surface->events.set_class); wl_signal_init(&surface->events.set_title); wl_signal_init(&surface->events.set_parent); - wl_signal_init(&surface->events.set_state); wl_signal_init(&surface->events.set_pid); wl_signal_init(&surface->events.set_window_type); return surface; @@ -447,6 +447,21 @@ static void read_surface_motif_hints(struct wlr_xwm *xwm, wlr_log(L_DEBUG, "MOTIF_WM_HINTS (%d)", reply->value_len); } +static void read_surface_net_wm_state(struct wlr_xwm *xwm, + struct wlr_xwayland_surface *xsurface, xcb_get_property_reply_t *reply) { + xsurface->fullscreen = 0; + xcb_atom_t *atom = xcb_get_property_value(reply); + atom = xcb_get_property_value(reply); + for (uint32_t i = 0; i < reply->value_len; i++) { + if (atom[i] == xwm->atoms[_NET_WM_STATE_FULLSCREEN]) + xsurface->fullscreen = true; + if (atom[i] == xwm->atoms[_NET_WM_STATE_MAXIMIZED_VERT]) + xsurface->maximized_vert = true; + if (atom[i] == xwm->atoms[_NET_WM_STATE_MAXIMIZED_HORZ]) + xsurface->maximized_horz = true; + } +} + static void read_surface_property(struct wlr_xwm *xwm, struct wlr_xwayland_surface *surface, xcb_atom_t property) { xcb_get_property_cookie_t cookie = xcb_get_property(xwm->xcb_conn, 0, @@ -471,7 +486,7 @@ static void read_surface_property(struct wlr_xwm *xwm, } else if (property == xwm->atoms[WM_PROTOCOLS]) { read_surface_protocols(xwm, surface, reply); } else if (property == xwm->atoms[NET_WM_STATE]) { - wlr_log(L_DEBUG, "TODO: read _NET_WM_STATE property"); + read_surface_net_wm_state(xwm, surface, reply); } else if (property == xwm->atoms[WM_HINTS]) { read_surface_hints(xwm, surface, reply); } else if (property == xwm->atoms[WM_NORMAL_HINTS]) { @@ -762,6 +777,81 @@ static void handle_net_wm_moveresize_message(struct wlr_xwm *xwm, } } +#define _NET_WM_STATE_REMOVE 0 +#define _NET_WM_STATE_ADD 1 +#define _NET_WM_STATE_TOGGLE 2 + +static bool update_state(int action, bool *state) { + int new_state, changed; + + switch (action) { + case _NET_WM_STATE_REMOVE: + new_state = false; + break; + case _NET_WM_STATE_ADD: + new_state = true; + break; + case _NET_WM_STATE_TOGGLE: + new_state = !*state; + break; + default: + return false; + } + + changed = (*state != new_state); + *state = new_state; + + return changed; +} + +static inline bool xsurface_is_maximized(struct wlr_xwayland_surface *xsurface) { + return xsurface->maximized_horz && xsurface->maximized_vert; +} + +static void handle_net_wm_state_message(struct wlr_xwm *xwm, + xcb_client_message_event_t *client_message) { + struct wlr_xwayland_surface *xsurface = lookup_surface(xwm, client_message->window); + if (!xsurface) { + return; + } + + int maximized = xsurface_is_maximized(xsurface); + + uint32_t action = client_message->data.data32[0]; + uint32_t property = client_message->data.data32[1]; + + if (property == xwm->atoms[_NET_WM_STATE_FULLSCREEN] && + update_state(action, &xsurface->fullscreen)) { + xsurface_set_net_wm_state(xsurface); + + if (xsurface->fullscreen) { + xsurface->saved_width = xsurface->width; + xsurface->saved_height = xsurface->height; + } + + wl_signal_emit(&xsurface->events.request_fullscreen, xsurface); + } else { + if (property == xwm->atoms[_NET_WM_STATE_MAXIMIZED_VERT] && + update_state(action, &xsurface->maximized_vert)) { + xsurface_set_net_wm_state(xsurface); + } + + if (property == xwm->atoms[_NET_WM_STATE_MAXIMIZED_HORZ] && + update_state(action, &xsurface->maximized_horz)) { + xsurface_set_net_wm_state(xsurface); + } + + if (maximized != xsurface_is_maximized(xsurface)) { + if (xsurface_is_maximized(xsurface)) { + xsurface->saved_width = xsurface->width; + xsurface->saved_height = xsurface->height; + } + + wl_signal_emit(&xsurface->events.request_maximize, xsurface); + } + } +} + static void handle_client_message(struct wlr_xwm *xwm, xcb_client_message_event_t *ev) { wlr_log(L_DEBUG, "XCB_CLIENT_MESSAGE (%u)", ev->window); @@ -769,7 +859,7 @@ static void handle_client_message(struct wlr_xwm *xwm, if (ev->type == xwm->atoms[WL_SURFACE_ID]) { handle_surface_id_message(xwm, ev); } else if (ev->type == xwm->atoms[NET_WM_STATE]) { - wlr_log(L_DEBUG, "TODO: handle _NET_WM_STATE client message"); + handle_net_wm_state_message(xwm, ev); } else if (ev->type == xwm->atoms[_NET_WM_MOVERESIZE]) { handle_net_wm_moveresize_message(xwm, ev); } else { @@ -1104,6 +1194,9 @@ struct wlr_xwm *xwm_create(struct wlr_xwayland *wlr_xwayland) { xwm->atoms[NET_WM_STATE], xwm->atoms[_NET_ACTIVE_WINDOW], xwm->atoms[_NET_WM_MOVERESIZE], + xwm->atoms[_NET_WM_STATE_FULLSCREEN], + xwm->atoms[_NET_WM_STATE_MAXIMIZED_HORZ], + xwm->atoms[_NET_WM_STATE_MAXIMIZED_VERT], }; xcb_change_property(xwm->xcb_conn, XCB_PROP_MODE_REPLACE, @@ -1128,3 +1221,20 @@ struct wlr_xwm *xwm_create(struct wlr_xwayland *wlr_xwayland) { return xwm; } + +void wlr_xwayland_surface_set_maximized(struct wlr_xwayland *wlr_xwayland, + struct wlr_xwayland_surface *surface, bool maximized) { + if (xsurface_is_maximized(surface) != maximized) { + surface->maximized_horz = maximized; + surface->maximized_vert = maximized; + xsurface_set_net_wm_state(surface); + } +} + +void wlr_xwayland_surface_set_fullscreen(struct wlr_xwayland *wlr_xwayland, + struct wlr_xwayland_surface *surface, bool fullscreen) { + if (surface->fullscreen != fullscreen) { + surface->fullscreen = fullscreen; + xsurface_set_net_wm_state(surface); + } +} From 325def38418f5caefd6dc23749dd2ca6bae0a36c Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Fri, 27 Oct 2017 15:20:50 -0400 Subject: [PATCH 28/32] xwm: create colormap and visual depth detection --- include/wlr/xwayland.h | 2 ++ xwayland/xwm.c | 47 ++++++++++++++++++++++++++++++++++++++---- xwayland/xwm.h | 2 ++ 3 files changed, 47 insertions(+), 4 deletions(-) diff --git a/include/wlr/xwayland.h b/include/wlr/xwayland.h index cc5d06cb..2d968133 100644 --- a/include/wlr/xwayland.h +++ b/include/wlr/xwayland.h @@ -102,6 +102,8 @@ struct wlr_xwayland_surface { bool maximized_vert; bool maximized_horz; + bool has_alpha; + struct { struct wl_signal destroy; struct wl_signal request_configure; diff --git a/xwayland/xwm.c b/xwayland/xwm.c index 5ba91370..9ddf59df 100644 --- a/xwayland/xwm.c +++ b/xwayland/xwm.c @@ -64,6 +64,9 @@ static struct wlr_xwayland_surface *wlr_xwayland_surface_create( return NULL; } + xcb_get_geometry_cookie_t geometry_cookie = + xcb_get_geometry(xwm->xcb_conn, window_id); + uint32_t values[1]; values[0] = XCB_EVENT_MASK_FOCUS_CHANGE | @@ -92,6 +95,16 @@ static struct wlr_xwayland_surface *wlr_xwayland_surface_create( wl_signal_init(&surface->events.set_parent); wl_signal_init(&surface->events.set_pid); wl_signal_init(&surface->events.set_window_type); + + xcb_get_geometry_reply_t *geometry_reply = + xcb_get_geometry_reply(xwm->xcb_conn, geometry_cookie, NULL); + + if (geometry_reply != NULL) { + surface->has_alpha = geometry_reply->depth == 32; + } + + free(geometry_reply); + return surface; } @@ -193,10 +206,6 @@ static void wlr_xwayland_surface_destroy(struct wlr_xwayland_surface *surface) { wl_list_remove(&surface->unpaired_link); } - for (size_t i = 0; i < surface->state->length; i++) { - free(surface->state->items[i]); - } - if (surface->surface) { wl_list_remove(&surface->surface_destroy.link); wl_list_remove(&surface->surface_commit.link); @@ -1140,6 +1149,35 @@ static void xwm_create_wm_window(struct wlr_xwm *xwm) { XCB_CURRENT_TIME); } +// TODO use me to support 32 bit color somehow +static void xwm_get_visual_and_colormap(struct wlr_xwm *xwm) { + xcb_depth_iterator_t d_iter; + xcb_visualtype_iterator_t vt_iter; + xcb_visualtype_t *visualtype; + + d_iter = xcb_screen_allowed_depths_iterator(xwm->screen); + visualtype = NULL; + while (d_iter.rem > 0) { + if (d_iter.data->depth == 32) { + vt_iter = xcb_depth_visuals_iterator(d_iter.data); + visualtype = vt_iter.data; + break; + } + + xcb_depth_next(&d_iter); + } + + if (visualtype == NULL) { + wlr_log(L_DEBUG, "no 32 bit visualtype\n"); + return; + } + + xwm->visual_id = visualtype->visual_id; + xwm->colormap = xcb_generate_id(xwm->xcb_conn); + xcb_create_colormap_checked(xwm->xcb_conn, XCB_COLORMAP_ALLOC_NONE, + xwm->colormap, xwm->screen->root, xwm->visual_id); +} + struct wlr_xwm *xwm_create(struct wlr_xwayland *wlr_xwayland) { struct wlr_xwm *xwm = calloc(1, sizeof(struct wlr_xwm)); if (xwm == NULL) { @@ -1175,6 +1213,7 @@ struct wlr_xwm *xwm_create(struct wlr_xwayland *wlr_xwayland) { wl_event_source_check(xwm->event_source); xwm_get_resources(xwm); + xwm_get_visual_and_colormap(xwm); uint32_t values[1]; values[0] = diff --git a/xwayland/xwm.h b/xwayland/xwm.h index 4f8c20a2..7d30d278 100644 --- a/xwayland/xwm.h +++ b/xwayland/xwm.h @@ -47,6 +47,8 @@ struct wlr_xwm { xcb_connection_t *xcb_conn; xcb_screen_t *screen; xcb_window_t window; + xcb_visualid_t visual_id; + xcb_colormap_t colormap; struct wlr_xwayland_surface *focus_surface; From 680f8a169dde620ec601967764d465bd290dd917 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Fri, 27 Oct 2017 15:32:19 -0400 Subject: [PATCH 29/32] xwm: remove duplicate calls in net wm state read --- xwayland/xwm.c | 1 - 1 file changed, 1 deletion(-) diff --git a/xwayland/xwm.c b/xwayland/xwm.c index 9ddf59df..e3d7867d 100644 --- a/xwayland/xwm.c +++ b/xwayland/xwm.c @@ -460,7 +460,6 @@ static void read_surface_net_wm_state(struct wlr_xwm *xwm, struct wlr_xwayland_surface *xsurface, xcb_get_property_reply_t *reply) { xsurface->fullscreen = 0; xcb_atom_t *atom = xcb_get_property_value(reply); - atom = xcb_get_property_value(reply); for (uint32_t i = 0; i < reply->value_len; i++) { if (atom[i] == xwm->atoms[_NET_WM_STATE_FULLSCREEN]) xsurface->fullscreen = true; From 942a19a0695d1661e60d193b26661dd4aec70454 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Sun, 29 Oct 2017 10:31:01 -0400 Subject: [PATCH 30/32] xwm: cleanup and consistent naming --- xwayland/xwm.c | 308 ++++++++++++++++++++++++++----------------------- 1 file changed, 162 insertions(+), 146 deletions(-) diff --git a/xwayland/xwm.c b/xwayland/xwm.c index e3d7867d..3786b823 100644 --- a/xwayland/xwm.c +++ b/xwayland/xwm.c @@ -116,29 +116,29 @@ static void xwm_set_net_active_window(struct wlr_xwm *xwm, } static void xwm_send_focus_window(struct wlr_xwm *xwm, - struct wlr_xwayland_surface *surface) { - if (surface) { - if (surface->override_redirect) { + struct wlr_xwayland_surface *xsurface) { + if (xsurface) { + if (xsurface->override_redirect) { return; } 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.window = xsurface->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_send_event(xwm->xcb_conn, 0, xsurface->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); + xsurface->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_configure_window_checked(xwm->xcb_conn, xsurface->window_id, XCB_CONFIG_WINDOW_STACK_MODE, values); } else { xcb_set_input_focus_checked(xwm->xcb_conn, @@ -193,33 +193,34 @@ static void xsurface_set_net_wm_state(struct wlr_xwayland_surface *xsurface) { i, property); } -static void wlr_xwayland_surface_destroy(struct wlr_xwayland_surface *surface) { - wl_signal_emit(&surface->events.destroy, surface); +static void wlr_xwayland_surface_destroy( + struct wlr_xwayland_surface *xsurface) { + wl_signal_emit(&xsurface->events.destroy, xsurface); - if (surface == surface->xwm->focus_surface) { - xwm_surface_activate(surface->xwm, NULL); + if (xsurface == xsurface->xwm->focus_surface) { + xwm_surface_activate(xsurface->xwm, NULL); } - wl_list_remove(&surface->link); + wl_list_remove(&xsurface->link); - if (surface->surface_id) { - wl_list_remove(&surface->unpaired_link); + if (xsurface->surface_id) { + wl_list_remove(&xsurface->unpaired_link); } - if (surface->surface) { - wl_list_remove(&surface->surface_destroy.link); - wl_list_remove(&surface->surface_commit.link); + if (xsurface->surface) { + wl_list_remove(&xsurface->surface_destroy.link); + wl_list_remove(&xsurface->surface_commit.link); } - free(surface->title); - free(surface->class); - free(surface->instance); - wlr_list_free(surface->state); - free(surface->window_type); - free(surface->protocols); - free(surface->hints); - free(surface->size_hints); - free(surface); + free(xsurface->title); + free(xsurface->class); + free(xsurface->instance); + wlr_list_free(xsurface->state); + free(xsurface->window_type); + free(xsurface->protocols); + free(xsurface->hints); + free(xsurface->size_hints); + free(xsurface); } /* xcb helpers */ @@ -269,7 +270,8 @@ static void read_surface_class(struct wlr_xwm *xwm, } static void read_surface_title(struct wlr_xwm *xwm, - struct wlr_xwayland_surface *surface, xcb_get_property_reply_t *reply) { + struct wlr_xwayland_surface *xsurface, + xcb_get_property_reply_t *reply) { if (reply->type != XCB_ATOM_STRING && reply->type != xwm->atoms[UTF8_STRING]) { return; @@ -281,48 +283,51 @@ static void read_surface_title(struct wlr_xwm *xwm, size_t len = xcb_get_property_value_length(reply); char *title = xcb_get_property_value(reply); - free(surface->title); + free(xsurface->title); if (len > 0) { - surface->title = strndup(title, len); + xsurface->title = strndup(title, len); } else { - surface->title = NULL; + xsurface->title = NULL; } - wlr_log(L_DEBUG, "XCB_ATOM_WM_NAME: %s", surface->title); - wl_signal_emit(&surface->events.set_title, surface); + wlr_log(L_DEBUG, "XCB_ATOM_WM_NAME: %s", xsurface->title); + wl_signal_emit(&xsurface->events.set_title, xsurface); } static void read_surface_parent(struct wlr_xwm *xwm, - struct wlr_xwayland_surface *surface, xcb_get_property_reply_t *reply) { + struct wlr_xwayland_surface *xsurface, + xcb_get_property_reply_t *reply) { if (reply->type != XCB_ATOM_WINDOW) { return; } xcb_window_t *xid = xcb_get_property_value(reply); if (xid != NULL) { - surface->parent = lookup_surface(xwm, *xid); + xsurface->parent = lookup_surface(xwm, *xid); } else { - surface->parent = NULL; + xsurface->parent = NULL; } wlr_log(L_DEBUG, "XCB_ATOM_WM_TRANSIENT_FOR: %p", xid); - wl_signal_emit(&surface->events.set_parent, surface); + wl_signal_emit(&xsurface->events.set_parent, xsurface); } static void read_surface_pid(struct wlr_xwm *xwm, - struct wlr_xwayland_surface *surface, xcb_get_property_reply_t *reply) { + struct wlr_xwayland_surface *xsurface, + xcb_get_property_reply_t *reply) { if (reply->type != XCB_ATOM_CARDINAL) { return; } pid_t *pid = xcb_get_property_value(reply); - surface->pid = *pid; - wlr_log(L_DEBUG, "NET_WM_PID %d", surface->pid); - wl_signal_emit(&surface->events.set_pid, surface); + xsurface->pid = *pid; + wlr_log(L_DEBUG, "NET_WM_PID %d", xsurface->pid); + wl_signal_emit(&xsurface->events.set_pid, xsurface); } static void read_surface_window_type(struct wlr_xwm *xwm, - struct wlr_xwayland_surface *surface, xcb_get_property_reply_t *reply) { + struct wlr_xwayland_surface *xsurface, + xcb_get_property_reply_t *reply) { if (reply->type != XCB_ATOM_ATOM) { return; } @@ -331,20 +336,21 @@ static void read_surface_window_type(struct wlr_xwm *xwm, size_t atoms_len = reply->value_len; size_t atoms_size = sizeof(xcb_atom_t) * atoms_len; - free(surface->window_type); - surface->window_type = malloc(atoms_size); - if (surface->window_type == NULL) { + free(xsurface->window_type); + xsurface->window_type = malloc(atoms_size); + if (xsurface->window_type == NULL) { return; } - memcpy(surface->window_type, atoms, atoms_size); - surface->window_type_len = atoms_len; + memcpy(xsurface->window_type, atoms, atoms_size); + xsurface->window_type_len = atoms_len; wlr_log(L_DEBUG, "NET_WM_WINDOW_TYPE (%zu)", atoms_len); - wl_signal_emit(&surface->events.set_window_type, surface); + wl_signal_emit(&xsurface->events.set_window_type, xsurface); } static void read_surface_protocols(struct wlr_xwm *xwm, - struct wlr_xwayland_surface *surface, xcb_get_property_reply_t *reply) { + struct wlr_xwayland_surface *xsurface, + xcb_get_property_reply_t *reply) { if (reply->type != XCB_ATOM_ATOM) { return; } @@ -353,20 +359,21 @@ static void read_surface_protocols(struct wlr_xwm *xwm, size_t atoms_len = reply->value_len; size_t atoms_size = sizeof(xcb_atom_t) * atoms_len; - free(surface->protocols); - surface->protocols = malloc(atoms_size); - if (surface->protocols == NULL) { + free(xsurface->protocols); + xsurface->protocols = malloc(atoms_size); + if (xsurface->protocols == NULL) { return; } - memcpy(surface->protocols, atoms, atoms_size); - surface->protocols_len = atoms_len; + memcpy(xsurface->protocols, atoms, atoms_size); + xsurface->protocols_len = atoms_len; wlr_log(L_DEBUG, "WM_PROTOCOLS (%zu)", atoms_len); } #ifdef HAS_XCB_ICCCM static void read_surface_hints(struct wlr_xwm *xwm, - struct wlr_xwayland_surface *surface, xcb_get_property_reply_t *reply) { + struct wlr_xwayland_surface *xsurface, + xcb_get_property_reply_t *reply) { // According to the docs, reply->type == xwm->atoms[WM_HINTS] // In practice, reply->type == XCB_ATOM_ATOM if (reply->value_len == 0) { @@ -376,26 +383,28 @@ static void read_surface_hints(struct wlr_xwm *xwm, xcb_icccm_wm_hints_t hints; xcb_icccm_get_wm_hints_from_reply(&hints, reply); - free(surface->hints); - surface->hints = calloc(1, sizeof(struct wlr_xwayland_surface_hints)); - if (surface->hints == NULL) { + free(xsurface->hints); + xsurface->hints = calloc(1, sizeof(struct wlr_xwayland_surface_hints)); + if (xsurface->hints == NULL) { return; } - memcpy(surface->hints, &hints, sizeof(struct wlr_xwayland_surface_hints)); - surface->hints_urgency = xcb_icccm_wm_hints_get_urgency(&hints); + memcpy(xsurface->hints, &hints, sizeof(struct wlr_xwayland_surface_hints)); + xsurface->hints_urgency = xcb_icccm_wm_hints_get_urgency(&hints); wlr_log(L_DEBUG, "WM_HINTS (%d)", reply->value_len); } #else static void read_surface_hints(struct wlr_xwm *xwm, - struct wlr_xwayland_surface *surface, xcb_get_property_reply_t *reply) { + struct wlr_xwayland_surface *xsurface, + xcb_get_property_reply_t *reply) { // Do nothing } #endif #ifdef HAS_XCB_ICCCM static void read_surface_normal_hints(struct wlr_xwm *xwm, - struct wlr_xwayland_surface *surface, xcb_get_property_reply_t *reply) { + struct wlr_xwayland_surface *xsurface, + xcb_get_property_reply_t *reply) { if (reply->type != xwm->atoms[WM_SIZE_HINTS] || reply->value_len == 0) { return; } @@ -403,20 +412,21 @@ static void read_surface_normal_hints(struct wlr_xwm *xwm, xcb_size_hints_t size_hints; xcb_icccm_get_wm_size_hints_from_reply(&size_hints, reply); - free(surface->size_hints); - surface->size_hints = + free(xsurface->size_hints); + xsurface->size_hints = calloc(1, sizeof(struct wlr_xwayland_surface_size_hints)); - if (surface->size_hints == NULL) { + if (xsurface->size_hints == NULL) { return; } - memcpy(surface->size_hints, &size_hints, + memcpy(xsurface->size_hints, &size_hints, sizeof(struct wlr_xwayland_surface_size_hints)); wlr_log(L_DEBUG, "WM_NORMAL_HINTS (%d)", reply->value_len); } #else static void read_surface_normal_hints(struct wlr_xwm *xwm, - struct wlr_xwayland_surface *surface, xcb_get_property_reply_t *reply) { + struct wlr_xwayland_surface *xsurface, + xcb_get_property_reply_t *reply) { // Do nothing } #endif @@ -432,22 +442,23 @@ static void read_surface_normal_hints(struct wlr_xwm *xwm, #define MWM_DECOR_TITLE (1 << 3) static void read_surface_motif_hints(struct wlr_xwm *xwm, - struct wlr_xwayland_surface *surface, xcb_get_property_reply_t *reply) { + struct wlr_xwayland_surface *xsurface, + xcb_get_property_reply_t *reply) { if (reply->value_len < 5) { return; } uint32_t *motif_hints = xcb_get_property_value(reply); if (motif_hints[MWM_HINTS_FLAGS_FIELD] & MWM_HINTS_DECORATIONS) { - surface->decorations = WLR_XWAYLAND_SURFACE_DECORATIONS_ALL; + xsurface->decorations = WLR_XWAYLAND_SURFACE_DECORATIONS_ALL; uint32_t decorations = motif_hints[MWM_HINTS_DECORATIONS_FIELD]; if ((decorations & MWM_DECOR_ALL) == 0) { if ((decorations & MWM_DECOR_BORDER) == 0) { - surface->decorations |= + xsurface->decorations |= WLR_XWAYLAND_SURFACE_DECORATIONS_NO_BORDER; } if ((decorations & MWM_DECOR_TITLE) == 0) { - surface->decorations |= + xsurface->decorations |= WLR_XWAYLAND_SURFACE_DECORATIONS_NO_TITLE; } } @@ -457,7 +468,8 @@ static void read_surface_motif_hints(struct wlr_xwm *xwm, } static void read_surface_net_wm_state(struct wlr_xwm *xwm, - struct wlr_xwayland_surface *xsurface, xcb_get_property_reply_t *reply) { + struct wlr_xwayland_surface *xsurface, + xcb_get_property_reply_t *reply) { xsurface->fullscreen = 0; xcb_atom_t *atom = xcb_get_property_value(reply); for (uint32_t i = 0; i < reply->value_len; i++) { @@ -471,9 +483,9 @@ static void read_surface_net_wm_state(struct wlr_xwm *xwm, } static void read_surface_property(struct wlr_xwm *xwm, - struct wlr_xwayland_surface *surface, xcb_atom_t property) { + struct wlr_xwayland_surface *xsurface, xcb_atom_t property) { xcb_get_property_cookie_t cookie = xcb_get_property(xwm->xcb_conn, 0, - surface->window_id, property, XCB_ATOM_ANY, 0, 2048); + xsurface->window_id, property, XCB_ATOM_ANY, 0, 2048); xcb_get_property_reply_t *reply = xcb_get_property_reply(xwm->xcb_conn, cookie, NULL); if (reply == NULL) { @@ -481,26 +493,26 @@ static void read_surface_property(struct wlr_xwm *xwm, } if (property == XCB_ATOM_WM_CLASS) { - read_surface_class(xwm, surface, reply); + read_surface_class(xwm, xsurface, reply); } else if (property == XCB_ATOM_WM_NAME || property == xwm->atoms[NET_WM_NAME]) { - read_surface_title(xwm, surface, reply); + read_surface_title(xwm, xsurface, reply); } else if (property == XCB_ATOM_WM_TRANSIENT_FOR) { - read_surface_parent(xwm, surface, reply); + read_surface_parent(xwm, xsurface, reply); } else if (property == xwm->atoms[NET_WM_PID]) { - read_surface_pid(xwm, surface, reply); + read_surface_pid(xwm, xsurface, reply); } else if (property == xwm->atoms[NET_WM_WINDOW_TYPE]) { - read_surface_window_type(xwm, surface, reply); + read_surface_window_type(xwm, xsurface, reply); } else if (property == xwm->atoms[WM_PROTOCOLS]) { - read_surface_protocols(xwm, surface, reply); + read_surface_protocols(xwm, xsurface, reply); } else if (property == xwm->atoms[NET_WM_STATE]) { - read_surface_net_wm_state(xwm, surface, reply); + read_surface_net_wm_state(xwm, xsurface, reply); } else if (property == xwm->atoms[WM_HINTS]) { - read_surface_hints(xwm, surface, reply); + read_surface_hints(xwm, xsurface, reply); } else if (property == xwm->atoms[WM_NORMAL_HINTS]) { - read_surface_normal_hints(xwm, surface, reply); + read_surface_normal_hints(xwm, xsurface, reply); } else if (property == xwm->atoms[MOTIF_WM_HINTS]) { - read_surface_motif_hints(xwm, surface, reply); + read_surface_motif_hints(xwm, xsurface, reply); } else { wlr_log(L_DEBUG, "unhandled x11 property %u", property); } @@ -528,10 +540,9 @@ static void handle_surface_destroy(struct wl_listener *listener, void *data) { // TODO destroy xwayland surface? } -static void map_shell_surface(struct wlr_xwm *xwm, +static void xwm_map_shell_surface(struct wlr_xwm *xwm, struct wlr_xwayland_surface *xsurface, struct wlr_surface *surface) { - // get xcb geometry for depth = alpha channel xsurface->surface = surface; // read all surface properties @@ -562,38 +573,37 @@ static void map_shell_surface(struct wlr_xwm *xwm, wl_signal_emit(&xsurface->events.map_notify, xsurface); } -/* xcb event handlers */ -static void handle_create_notify(struct wlr_xwm *xwm, +static void xwm_handle_create_notify(struct wlr_xwm *xwm, xcb_create_notify_event_t *ev) { wlr_log(L_DEBUG, "XCB_CREATE_NOTIFY (%u)", ev->window); wlr_xwayland_surface_create(xwm, ev->window, ev->x, ev->y, ev->width, ev->height, ev->override_redirect); } -static void handle_destroy_notify(struct wlr_xwm *xwm, +static void xwm_handle_destroy_notify(struct wlr_xwm *xwm, xcb_destroy_notify_event_t *ev) { wlr_log(L_DEBUG, "XCB_DESTROY_NOTIFY (%u)", ev->window); - struct wlr_xwayland_surface *surface = lookup_surface(xwm, ev->window); - if (surface == NULL) { + struct wlr_xwayland_surface *xsurface = lookup_surface(xwm, ev->window); + if (xsurface == NULL) { return; } - wlr_xwayland_surface_destroy(surface); + wlr_xwayland_surface_destroy(xsurface); } -static void handle_configure_request(struct wlr_xwm *xwm, +static void xwm_handle_configure_request(struct wlr_xwm *xwm, xcb_configure_request_event_t *ev) { wlr_log(L_DEBUG, "XCB_CONFIGURE_REQUEST (%u) [%ux%u+%d,%d]", ev->window, ev->width, ev->height, ev->x, ev->y); - struct wlr_xwayland_surface *surface = lookup_surface(xwm, ev->window); - if (surface == NULL) { + struct wlr_xwayland_surface *xsurface = lookup_surface(xwm, ev->window); + if (xsurface == NULL) { return; } // TODO: handle ev->{parent,sibling}? - if (surface->surface == NULL) { + if (xsurface->surface == NULL) { // Surface has not been mapped yet - wlr_xwayland_surface_configure(xwm->xwayland, surface, ev->x, ev->y, + wlr_xwayland_surface_configure(xwm->xwayland, xsurface, ev->x, ev->y, ev->width, ev->height); } else { struct wlr_xwayland_surface_configure_event *wlr_event = @@ -602,19 +612,19 @@ static void handle_configure_request(struct wlr_xwm *xwm, return; } - wlr_event->surface = surface; + wlr_event->surface = xsurface; wlr_event->x = ev->x; wlr_event->y = ev->y; wlr_event->width = ev->width; wlr_event->height = ev->height; - wl_signal_emit(&surface->events.request_configure, wlr_event); + wl_signal_emit(&xsurface->events.request_configure, wlr_event); free(wlr_event); } } -static void handle_configure_notify(struct wlr_xwm *xwm, +static void xwm_handle_configure_notify(struct wlr_xwm *xwm, xcb_configure_notify_event_t *ev) { struct wlr_xwayland_surface *xsurface = lookup_surface(xwm, ev->window); @@ -650,7 +660,7 @@ static void xsurface_set_wm_state(struct wlr_xwayland_surface *xsurface, 2, property); } -static void handle_map_request(struct wlr_xwm *xwm, +static void xwm_handle_map_request(struct wlr_xwm *xwm, xcb_map_request_event_t *ev) { wlr_log(L_DEBUG, "XCB_MAP_REQUEST (%u)", ev->window); struct wlr_xwayland_surface *xsurface = lookup_surface(xwm, ev->window); @@ -663,11 +673,12 @@ static void handle_map_request(struct wlr_xwm *xwm, xcb_map_window(xwm->xcb_conn, ev->window); } -static void handle_map_notify(struct wlr_xwm *xwm, xcb_map_notify_event_t *ev) { +static void xwm_handle_map_notify(struct wlr_xwm *xwm, + xcb_map_notify_event_t *ev) { wlr_log(L_DEBUG, "XCB_MAP_NOTIFY (%u)", ev->window); } -static void handle_unmap_notify(struct wlr_xwm *xwm, +static void xwm_handle_unmap_notify(struct wlr_xwm *xwm, xcb_unmap_notify_event_t *ev) { wlr_log(L_DEBUG, "XCB_UNMAP_NOTIFY (%u)", ev->window); struct wlr_xwayland_surface *xsurface = lookup_surface(xwm, ev->window); @@ -697,18 +708,18 @@ static void handle_unmap_notify(struct wlr_xwm *xwm, xsurface_set_wm_state(xsurface, ICCCM_WITHDRAWN_STATE); } -static void handle_property_notify(struct wlr_xwm *xwm, +static void xwm_handle_property_notify(struct wlr_xwm *xwm, xcb_property_notify_event_t *ev) { wlr_log(L_DEBUG, "XCB_PROPERTY_NOTIFY (%u)", ev->window); - struct wlr_xwayland_surface *surface = lookup_surface(xwm, ev->window); - if (surface == NULL) { + struct wlr_xwayland_surface *xsurface = lookup_surface(xwm, ev->window); + if (xsurface == NULL) { return; } - read_surface_property(xwm, surface, ev->atom); + read_surface_property(xwm, xsurface, ev->atom); } -static void handle_surface_id_message(struct wlr_xwm *xwm, +static void xwm_handle_surface_id_message(struct wlr_xwm *xwm, xcb_client_message_event_t *ev) { struct wlr_xwayland_surface *xsurface = lookup_surface(xwm, ev->window); if (xsurface == NULL) { @@ -724,7 +735,7 @@ static void handle_surface_id_message(struct wlr_xwm *xwm, if (resource) { struct wlr_surface *surface = wl_resource_get_user_data(resource); xsurface->surface_id = 0; - map_shell_surface(xwm, xsurface, surface); + xwm_map_shell_surface(xwm, xsurface, surface); } else { xsurface->surface_id = id; wl_list_insert(&xwm->unpaired_surfaces, &xsurface->unpaired_link); @@ -744,7 +755,7 @@ static void handle_surface_id_message(struct wlr_xwm *xwm, #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 xwm_handle_net_wm_moveresize_message(struct wlr_xwm *xwm, xcb_client_message_event_t *ev) { // same as xdg-toplevel-v6 // TODO need a common enum for this @@ -781,6 +792,7 @@ static void handle_net_wm_moveresize_message(struct wlr_xwm *xwm, wl_signal_emit(&xsurface->events.request_resize, &resize_event); break; case _NET_WM_MOVERESIZE_CANCEL: + // handled by the compositor break; } } @@ -812,13 +824,15 @@ static bool update_state(int action, bool *state) { return changed; } -static inline bool xsurface_is_maximized(struct wlr_xwayland_surface *xsurface) { +static inline bool xsurface_is_maximized( + struct wlr_xwayland_surface *xsurface) { return xsurface->maximized_horz && xsurface->maximized_vert; } -static void handle_net_wm_state_message(struct wlr_xwm *xwm, +static void xwm_handle_net_wm_state_message(struct wlr_xwm *xwm, xcb_client_message_event_t *client_message) { - struct wlr_xwayland_surface *xsurface = lookup_surface(xwm, client_message->window); + struct wlr_xwayland_surface *xsurface = + lookup_surface(xwm, client_message->window); if (!xsurface) { return; } @@ -860,22 +874,22 @@ static void handle_net_wm_state_message(struct wlr_xwm *xwm, } } -static void handle_client_message(struct wlr_xwm *xwm, +static void xwm_handle_client_message(struct wlr_xwm *xwm, xcb_client_message_event_t *ev) { wlr_log(L_DEBUG, "XCB_CLIENT_MESSAGE (%u)", ev->window); if (ev->type == xwm->atoms[WL_SURFACE_ID]) { - handle_surface_id_message(xwm, ev); + xwm_handle_surface_id_message(xwm, ev); } else if (ev->type == xwm->atoms[NET_WM_STATE]) { - handle_net_wm_state_message(xwm, ev); + xwm_handle_net_wm_state_message(xwm, ev); } else if (ev->type == xwm->atoms[_NET_WM_MOVERESIZE]) { - handle_net_wm_moveresize_message(xwm, ev); + xwm_handle_net_wm_moveresize_message(xwm, ev); } else { wlr_log(L_DEBUG, "unhandled x11 client message %u", ev->type); } } -static void handle_focus_in(struct wlr_xwm *xwm, +static void xwm_handle_focus_in(struct wlr_xwm *xwm, xcb_focus_in_event_t *ev) { // Do not interfere with grabs if (ev->mode == XCB_NOTIFY_MODE_GRAB || @@ -903,35 +917,37 @@ static int x11_event_handler(int fd, uint32_t mask, void *data) { count++; switch (event->response_type & XCB_EVENT_RESPONSE_TYPE_MASK) { case XCB_CREATE_NOTIFY: - handle_create_notify(xwm, (xcb_create_notify_event_t *)event); + xwm_handle_create_notify(xwm, (xcb_create_notify_event_t *)event); break; case XCB_DESTROY_NOTIFY: - handle_destroy_notify(xwm, (xcb_destroy_notify_event_t *)event); + xwm_handle_destroy_notify(xwm, (xcb_destroy_notify_event_t *)event); break; case XCB_CONFIGURE_REQUEST: - handle_configure_request(xwm, + xwm_handle_configure_request(xwm, (xcb_configure_request_event_t *)event); break; case XCB_CONFIGURE_NOTIFY: - handle_configure_notify(xwm, (xcb_configure_notify_event_t *)event); + xwm_handle_configure_notify(xwm, + (xcb_configure_notify_event_t *)event); break; case XCB_MAP_REQUEST: - handle_map_request(xwm, (xcb_map_request_event_t *)event); + xwm_handle_map_request(xwm, (xcb_map_request_event_t *)event); break; case XCB_MAP_NOTIFY: - handle_map_notify(xwm, (xcb_map_notify_event_t *)event); + xwm_handle_map_notify(xwm, (xcb_map_notify_event_t *)event); break; case XCB_UNMAP_NOTIFY: - handle_unmap_notify(xwm, (xcb_unmap_notify_event_t *)event); + xwm_handle_unmap_notify(xwm, (xcb_unmap_notify_event_t *)event); break; case XCB_PROPERTY_NOTIFY: - handle_property_notify(xwm, (xcb_property_notify_event_t *)event); + xwm_handle_property_notify(xwm, + (xcb_property_notify_event_t *)event); break; case XCB_CLIENT_MESSAGE: - handle_client_message(xwm, (xcb_client_message_event_t *)event); + xwm_handle_client_message(xwm, (xcb_client_message_event_t *)event); break; case XCB_FOCUS_IN: - handle_focus_in(xwm, (xcb_focus_in_event_t *)event); + xwm_handle_focus_in(xwm, (xcb_focus_in_event_t *)event); break; default: wlr_log(L_DEBUG, "X11 event: %d", @@ -963,7 +979,7 @@ static void handle_compositor_surface_create(struct wl_listener *listener, struct wlr_xwayland_surface *xsurface; wl_list_for_each(xsurface, &xwm->unpaired_surfaces, unpaired_link) { if (xsurface->surface_id == surface_id) { - map_shell_surface(xwm, xsurface, surface); + xwm_map_shell_surface(xwm, xsurface, surface); xsurface->surface_id = 0; wl_list_remove(&xsurface->unpaired_link); xcb_flush(xwm->xcb_conn); @@ -973,39 +989,39 @@ static void handle_compositor_surface_create(struct wl_listener *listener, } void wlr_xwayland_surface_activate(struct wlr_xwayland *wlr_xwayland, - struct wlr_xwayland_surface *surface, bool activated) { + struct wlr_xwayland_surface *xsurface, 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, xsurface); + } else if (focused == xsurface) { xwm_surface_activate(wlr_xwayland->xwm, NULL); } } void wlr_xwayland_surface_configure(struct wlr_xwayland *wlr_xwayland, - struct wlr_xwayland_surface *surface, int16_t x, int16_t y, + struct wlr_xwayland_surface *xsurface, int16_t x, int16_t y, uint16_t width, uint16_t height) { - surface->x = x; - surface->y = y; - surface->width = width; - surface->height = height; + xsurface->x = x; + xsurface->y = y; + xsurface->width = width; + xsurface->height = height; struct wlr_xwm *xwm = wlr_xwayland->xwm; uint32_t mask = XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y | XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT | XCB_CONFIG_WINDOW_BORDER_WIDTH; uint32_t values[] = {x, y, width, height, 0}; - xcb_configure_window(xwm->xcb_conn, surface->window_id, mask, values); + xcb_configure_window(xwm->xcb_conn, xsurface->window_id, mask, values); xcb_flush(xwm->xcb_conn); } void wlr_xwayland_surface_close(struct wlr_xwayland *wlr_xwayland, - struct wlr_xwayland_surface *surface) { + struct wlr_xwayland_surface *xsurface) { struct wlr_xwm *xwm = wlr_xwayland->xwm; bool supports_delete = false; - for (size_t i = 0; i < surface->protocols_len; i++) { - if (surface->protocols[i] == xwm->atoms[WM_DELETE_WINDOW]) { + for (size_t i = 0; i < xsurface->protocols_len; i++) { + if (xsurface->protocols[i] == xwm->atoms[WM_DELETE_WINDOW]) { supports_delete = true; break; } @@ -1014,17 +1030,17 @@ void wlr_xwayland_surface_close(struct wlr_xwayland *wlr_xwayland, if (supports_delete) { xcb_client_message_event_t ev = {0}; ev.response_type = XCB_CLIENT_MESSAGE; - ev.window = surface->window_id; + ev.window = xsurface->window_id; ev.format = 32; ev.sequence = 0; ev.type = xwm->atoms[WM_PROTOCOLS]; ev.data.data32[0] = xwm->atoms[WM_DELETE_WINDOW]; ev.data.data32[1] = XCB_CURRENT_TIME; XCB_CALL(xwm, xcb_send_event_checked(xwm->xcb_conn, 0, - surface->window_id, XCB_EVENT_MASK_NO_EVENT, (char *)&ev)); + xsurface->window_id, XCB_EVENT_MASK_NO_EVENT, (char *)&ev)); } else { XCB_CALL(xwm, xcb_kill_client_checked(xwm->xcb_conn, - surface->window_id)); + xsurface->window_id)); } } @@ -1035,9 +1051,9 @@ void xwm_destroy(struct wlr_xwm *xwm) { if (xwm->event_source) { wl_event_source_remove(xwm->event_source); } - struct wlr_xwayland_surface *surface, *tmp; - wl_list_for_each_safe(surface, tmp, &xwm->surfaces, link) { - wlr_xwayland_surface_destroy(surface); + struct wlr_xwayland_surface *xsurface, *tmp; + wl_list_for_each_safe(xsurface, tmp, &xwm->surfaces, link) { + wlr_xwayland_surface_destroy(xsurface); } wl_list_remove(&xwm->compositor_surface_create.link); xcb_disconnect(xwm->xcb_conn); From 88316e7921942e186df0c6f41fb405fe85bb83f9 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Sun, 29 Oct 2017 10:36:16 -0400 Subject: [PATCH 31/32] xwm: get rid of xcb call macro --- xwayland/xwm.c | 38 ++++++++++++++------------------------ 1 file changed, 14 insertions(+), 24 deletions(-) diff --git a/xwayland/xwm.c b/xwayland/xwm.c index 3786b823..12dd5dd0 100644 --- a/xwayland/xwm.c +++ b/xwayland/xwm.c @@ -138,10 +138,10 @@ static void xwm_send_focus_window(struct wlr_xwm *xwm, uint32_t values[1]; values[0] = XCB_STACK_MODE_ABOVE; - xcb_configure_window_checked(xwm->xcb_conn, xsurface->window_id, + xcb_configure_window(xwm->xcb_conn, xsurface->window_id, XCB_CONFIG_WINDOW_STACK_MODE, values); } else { - xcb_set_input_focus_checked(xwm->xcb_conn, + xcb_set_input_focus(xwm->xcb_conn, XCB_INPUT_FOCUS_POINTER_ROOT, XCB_NONE, XCB_CURRENT_TIME); } @@ -223,21 +223,6 @@ static void wlr_xwayland_surface_destroy( free(xsurface); } -/* xcb helpers */ -#define XCB_CALL(xwm, x) xcb_call(xwm, __func__, __LINE__, x) -static bool xcb_call(struct wlr_xwm *xwm, const char *func, uint32_t line, - xcb_void_cookie_t cookie) { - xcb_generic_error_t *error; - if (!(error = xcb_request_check(xwm->xcb_conn, cookie))) { - return true; - } - - wlr_log(L_ERROR, "xcb call failed in %s:%u, x11 error code %d", - func, line, error->error_code); - free(error); - return false; -} - static void read_surface_class(struct wlr_xwm *xwm, struct wlr_xwayland_surface *surface, xcb_get_property_reply_t *reply) { if (reply->type != XCB_ATOM_STRING && @@ -1036,11 +1021,12 @@ void wlr_xwayland_surface_close(struct wlr_xwayland *wlr_xwayland, ev.type = xwm->atoms[WM_PROTOCOLS]; ev.data.data32[0] = xwm->atoms[WM_DELETE_WINDOW]; ev.data.data32[1] = XCB_CURRENT_TIME; - XCB_CALL(xwm, xcb_send_event_checked(xwm->xcb_conn, 0, - xsurface->window_id, XCB_EVENT_MASK_NO_EVENT, (char *)&ev)); + xcb_send_event(xwm->xcb_conn, 0, + xsurface->window_id, + XCB_EVENT_MASK_NO_EVENT, + (char *)&ev); } else { - XCB_CALL(xwm, xcb_kill_client_checked(xwm->xcb_conn, - xsurface->window_id)); + xcb_kill_client(xwm->xcb_conn, xsurface->window_id); } } @@ -1189,8 +1175,11 @@ static void xwm_get_visual_and_colormap(struct wlr_xwm *xwm) { xwm->visual_id = visualtype->visual_id; xwm->colormap = xcb_generate_id(xwm->xcb_conn); - xcb_create_colormap_checked(xwm->xcb_conn, XCB_COLORMAP_ALLOC_NONE, - xwm->colormap, xwm->screen->root, xwm->visual_id); + xcb_create_colormap(xwm->xcb_conn, + XCB_COLORMAP_ALLOC_NONE, + xwm->colormap, + xwm->screen->root, + xwm->visual_id); } struct wlr_xwm *xwm_create(struct wlr_xwayland *wlr_xwayland) { @@ -1241,7 +1230,8 @@ struct wlr_xwm *xwm_create(struct wlr_xwayland *wlr_xwayland) { XCB_CW_EVENT_MASK /* | XCB_CW_CURSOR */, values); - xcb_composite_redirect_subwindows_checked(xwm->xcb_conn, xwm->screen->root, + xcb_composite_redirect_subwindows(xwm->xcb_conn, + xwm->screen->root, XCB_COMPOSITE_REDIRECT_MANUAL); xcb_atom_t supported[] = { From ce72a687ce3b88b69b0d319800d2f466205a15f7 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Sun, 29 Oct 2017 10:40:16 -0400 Subject: [PATCH 32/32] xwm: cleanup send focus window logic --- xwayland/xwm.c | 49 ++++++++++++++++++++++++------------------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/xwayland/xwm.c b/xwayland/xwm.c index 12dd5dd0..15a23797 100644 --- a/xwayland/xwm.c +++ b/xwayland/xwm.c @@ -117,34 +117,33 @@ static void xwm_set_net_active_window(struct wlr_xwm *xwm, static void xwm_send_focus_window(struct wlr_xwm *xwm, struct wlr_xwayland_surface *xsurface) { - if (xsurface) { - if (xsurface->override_redirect) { - return; - } - - xcb_client_message_event_t client_message; - client_message.response_type = XCB_CLIENT_MESSAGE; - client_message.format = 32; - client_message.window = xsurface->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, xsurface->window_id, - XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT, (char*)&client_message); - - xcb_set_input_focus(xwm->xcb_conn, XCB_INPUT_FOCUS_POINTER_ROOT, - xsurface->window_id, XCB_CURRENT_TIME); - - uint32_t values[1]; - values[0] = XCB_STACK_MODE_ABOVE; - xcb_configure_window(xwm->xcb_conn, xsurface->window_id, - XCB_CONFIG_WINDOW_STACK_MODE, values); - } else { - xcb_set_input_focus(xwm->xcb_conn, + if (!xsurface) { + xcb_set_input_focus_checked(xwm->xcb_conn, XCB_INPUT_FOCUS_POINTER_ROOT, XCB_NONE, XCB_CURRENT_TIME); + return; + } else if (xsurface->override_redirect) { + return; } + + xcb_client_message_event_t client_message; + client_message.response_type = XCB_CLIENT_MESSAGE; + client_message.format = 32; + client_message.window = xsurface->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, xsurface->window_id, + XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT, (char*)&client_message); + + xcb_set_input_focus(xwm->xcb_conn, XCB_INPUT_FOCUS_POINTER_ROOT, + xsurface->window_id, XCB_CURRENT_TIME); + + uint32_t values[1]; + values[0] = XCB_STACK_MODE_ABOVE; + xcb_configure_window(xwm->xcb_conn, xsurface->window_id, + XCB_CONFIG_WINDOW_STACK_MODE, values); }