From e3917af69d1801a6deafa580f77b0feb10562992 Mon Sep 17 00:00:00 2001 From: emersion Date: Fri, 29 Sep 2017 15:57:21 +0200 Subject: xwayland: read window title & class --- xwayland/xwm.c | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- xwayland/xwm.h | 1 + 2 files changed, 85 insertions(+), 2 deletions(-) (limited to 'xwayland') diff --git a/xwayland/xwm.c b/xwayland/xwm.c index 862db70b..37f4298d 100644 --- a/xwayland/xwm.c +++ b/xwayland/xwm.c @@ -1,3 +1,6 @@ +#ifndef _POSIX_C_SOURCE +#define _POSIX_C_SOURCE 200809L +#endif #include #include #include "wlr/util/log.h" @@ -11,6 +14,7 @@ const char *atom_map[ATOM_LAST] = { "WM_S0", "_NET_SUPPORTED", "_NET_WM_S0", + "_NET_WM_NAME", "_NET_WM_STATE", "WM_TAKE_FOCUS", }; @@ -80,12 +84,84 @@ static bool xcb_call(struct wlr_xwm *xwm, const char *func, uint32_t line, return false; } +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, + surface->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) { + return; + } + + // TODO: check reply->type + + if (property == XCB_ATOM_WM_CLASS) { + size_t len = xcb_get_property_value_length(reply); + char *class = xcb_get_property_value(reply); + + // Unpack two sequentially stored strings: instance, class + size_t instance_len = strnlen(class, len); + free(surface->instance); + if (len > 0 && instance_len < len) { + surface->instance = strndup(class, instance_len); + class += instance_len + 1; + } else { + surface->instance = NULL; + } + free(surface->class); + if (len > 0) { + surface->class = strndup(class, len); + } else { + surface->class = NULL; + } + + wlr_log(L_DEBUG, "XCB_ATOM_WM_CLASS: %s %s", surface->instance, surface->class); + } else if (property == XCB_ATOM_WM_NAME || + property == xwm->atoms[NET_WM_NAME]) { + // TODO: if reply->type == XCB_ATOM_STRING, uses latin1 encoding + // if reply->type == xwm->atoms[UTF8_STRING], uses utf8 encoding + size_t len = xcb_get_property_value_length(reply); + char *title = xcb_get_property_value(reply); + + free(surface->title); + if (len > 0) { + surface->title = strndup(title, len); + } else { + surface->title = NULL; + } + + wlr_log(L_DEBUG, "XCB_ATOM_WM_NAME: %s", surface->title); + } else { + wlr_log(L_DEBUG, "unhandled x11 property %u", property); + } + + free(reply); +} + static void map_shell_surface(struct wlr_xwm *xwm, struct wlr_xwayland_surface *xwayland_surface, struct wlr_surface *surface) { // get xcb geometry for depth = alpha channel xwayland_surface->surface = surface; + // read all surface properties + const xcb_atom_t props[] = { + XCB_ATOM_WM_CLASS, + XCB_ATOM_WM_NAME, + XCB_ATOM_WM_TRANSIENT_FOR, + //xwm->atoms[WM_PROTOCOLS], + //xwm->atoms[WM_NORMAL_HINTS], + //xwm->atoms[NET_WM_STATE], + //xwm->atoms[NET_WM_WINDOW_TYPE], + //xwm->atoms[NET_WM_NAME], + //xwm->atoms[NET_WM_PID], + //xwm->atoms[MOTIF_WM_HINTS], + }; + for (size_t i = 0; i < sizeof(props)/sizeof(xcb_atom_t); i++) { + read_surface_property(xwm, xwayland_surface, props[i]); + } + wl_list_remove(&xwayland_surface->link); wl_list_insert(&xwm->xwayland->displayable_surfaces, &xwayland_surface->link); @@ -167,7 +243,12 @@ static void handle_unmap_notify(struct wlr_xwm *xwm, 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); - // TODO lookup window & get properties + struct wlr_xwayland_surface *surface = lookup_surface_any(xwm, ev->window); + if (surface == NULL) { + return; + } + + read_surface_property(xwm, surface, ev->atom); } static void handle_client_message(struct wlr_xwm *xwm, @@ -192,8 +273,9 @@ static void handle_client_message(struct wlr_xwm *xwm, wl_list_remove(&surface->link); wl_list_insert(&xwm->unpaired_surfaces, &surface->link); } + } else { + wlr_log(L_DEBUG, "unhandled x11 client message %u", ev->type); } - wlr_log(L_DEBUG, "unhandled client message %u", ev->type); } /* This is in xcb/xcb_event.h, but pulling xcb-util just for a constant diff --git a/xwayland/xwm.h b/xwayland/xwm.h index ecbab535..1572997e 100644 --- a/xwayland/xwm.h +++ b/xwayland/xwm.h @@ -51,6 +51,7 @@ enum atom_name { WM_S0, NET_SUPPORTED, NET_WM_S0, + NET_WM_NAME, NET_WM_STATE, WM_TAKE_FOCUS, ATOM_LAST, -- cgit v1.2.3 From 47d767dbc4fc88e399a7a2ef3edde9d906a7f773 Mon Sep 17 00:00:00 2001 From: emersion Date: Fri, 29 Sep 2017 16:19:06 +0200 Subject: xwayland: expose wlr_xwayland_surface_configure --- include/wlr/xwayland.h | 3 +++ xwayland/xwm.c | 19 +++++++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) (limited to 'xwayland') diff --git a/include/wlr/xwayland.h b/include/wlr/xwayland.h index 23910139..17582e7d 100644 --- a/include/wlr/xwayland.h +++ b/include/wlr/xwayland.h @@ -56,5 +56,8 @@ 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); +void wlr_xwayland_surface_configure(struct wlr_xwm *xwm, + struct wlr_xwayland_surface *surface, uint32_t x, uint32_t y, + uint32_t width, uint32_t height); #endif diff --git a/xwayland/xwm.c b/xwayland/xwm.c index 37f4298d..83b096aa 100644 --- a/xwayland/xwm.c +++ b/xwayland/xwm.c @@ -199,13 +199,10 @@ static void handle_configure_request(struct wlr_xwm *xwm, surface->y = ev->y; surface->width = ev->width; surface->height = ev->height; - // handle parent/sibling? + // TODO: handle parent/sibling? - uint32_t values[] = {ev->x, ev->y, ev->width, ev->height, 0}; - uint32_t mask = XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y | - XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT | - XCB_CONFIG_WINDOW_BORDER_WIDTH; - xcb_configure_window(xwm->xcb_conn, ev->window, mask, values); + wlr_xwayland_surface_configure(xwm, surface, ev->x, ev->y, ev->width, + ev->height); } static void handle_map_request(struct wlr_xwm *xwm, @@ -430,6 +427,16 @@ void wlr_xwayland_surface_activate(struct wlr_xwayland *wlr_xwayland, xcb_flush(xwm->xcb_conn); } +void wlr_xwayland_surface_configure(struct wlr_xwm *xwm, + struct wlr_xwayland_surface *surface, uint32_t x, uint32_t y, + uint32_t width, uint32_t height) { + 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); +} + void xwm_destroy(struct wlr_xwm *xwm) { if (!xwm) { return; -- cgit v1.2.3 From f2b03b2ec13a4b4eb940366852580ff0e6454a40 Mon Sep 17 00:00:00 2001 From: emersion Date: Fri, 29 Sep 2017 16:44:22 +0200 Subject: Add reply->type checks, add XCB_ATOM_WM_TRANSIENT_FOR --- include/wlr/xwayland.h | 1 + xwayland/xwm.c | 108 +++++++++++++++++++++++++++++++++---------------- xwayland/xwm.h | 1 + 3 files changed, 75 insertions(+), 35 deletions(-) (limited to 'xwayland') diff --git a/include/wlr/xwayland.h b/include/wlr/xwayland.h index 17582e7d..ebb6efb7 100644 --- a/include/wlr/xwayland.h +++ b/include/wlr/xwayland.h @@ -43,6 +43,7 @@ struct wlr_xwayland_surface { char *title; char *class; char *instance; + struct wlr_xwayland_surface *parent; struct { struct wl_signal destroy; diff --git a/xwayland/xwm.c b/xwayland/xwm.c index 83b096aa..e316d8fa 100644 --- a/xwayland/xwm.c +++ b/xwayland/xwm.c @@ -11,6 +11,7 @@ const char *atom_map[ATOM_LAST] = { "WL_SURFACE_ID", "WM_PROTOCOLS", + "UTF8_STRING", "WM_S0", "_NET_SUPPORTED", "_NET_WM_S0", @@ -84,6 +85,74 @@ static bool xcb_call(struct wlr_xwm *xwm, const char *func, uint32_t line, 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 && + reply->type != xwm->atoms[UTF8_STRING]) { + return; + } + + size_t len = xcb_get_property_value_length(reply); + char *class = xcb_get_property_value(reply); + + // Unpack two sequentially stored strings: instance, class + size_t instance_len = strnlen(class, len); + free(surface->instance); + if (len > 0 && instance_len < len) { + surface->instance = strndup(class, instance_len); + class += instance_len + 1; + } else { + surface->instance = NULL; + } + free(surface->class); + if (len > 0) { + surface->class = strndup(class, len); + } else { + surface->class = NULL; + } + + wlr_log(L_DEBUG, "XCB_ATOM_WM_CLASS: %s %s", surface->instance, surface->class); +} + +static void read_surface_title(struct wlr_xwm *xwm, + struct wlr_xwayland_surface *surface, xcb_get_property_reply_t *reply) { + if (reply->type != XCB_ATOM_STRING && + reply->type != xwm->atoms[UTF8_STRING]) { + return; + } + + // TODO: if reply->type == XCB_ATOM_STRING, uses latin1 encoding + // if reply->type == xwm->atoms[UTF8_STRING], uses utf8 encoding + + size_t len = xcb_get_property_value_length(reply); + char *title = xcb_get_property_value(reply); + + free(surface->title); + if (len > 0) { + surface->title = strndup(title, len); + } else { + surface->title = NULL; + } + + wlr_log(L_DEBUG, "XCB_ATOM_WM_NAME: %s", surface->title); +} + +static void read_surface_parent(struct wlr_xwm *xwm, + struct wlr_xwayland_surface *surface, 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_any(xwm, *xid); + } else { + surface->parent = NULL; + } + + wlr_log(L_DEBUG, "XCB_ATOM_WM_TRANSIENT_FOR: %p", xid); +} + 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, @@ -94,44 +163,13 @@ static void read_surface_property(struct wlr_xwm *xwm, return; } - // TODO: check reply->type - if (property == XCB_ATOM_WM_CLASS) { - size_t len = xcb_get_property_value_length(reply); - char *class = xcb_get_property_value(reply); - - // Unpack two sequentially stored strings: instance, class - size_t instance_len = strnlen(class, len); - free(surface->instance); - if (len > 0 && instance_len < len) { - surface->instance = strndup(class, instance_len); - class += instance_len + 1; - } else { - surface->instance = NULL; - } - free(surface->class); - if (len > 0) { - surface->class = strndup(class, len); - } else { - surface->class = NULL; - } - - wlr_log(L_DEBUG, "XCB_ATOM_WM_CLASS: %s %s", surface->instance, surface->class); + read_surface_class(xwm, surface, reply); } else if (property == XCB_ATOM_WM_NAME || property == xwm->atoms[NET_WM_NAME]) { - // TODO: if reply->type == XCB_ATOM_STRING, uses latin1 encoding - // if reply->type == xwm->atoms[UTF8_STRING], uses utf8 encoding - size_t len = xcb_get_property_value_length(reply); - char *title = xcb_get_property_value(reply); - - free(surface->title); - if (len > 0) { - surface->title = strndup(title, len); - } else { - surface->title = NULL; - } - - wlr_log(L_DEBUG, "XCB_ATOM_WM_NAME: %s", surface->title); + read_surface_title(xwm, surface, reply); + } else if (property == XCB_ATOM_WM_TRANSIENT_FOR) { + read_surface_parent(xwm, surface, reply); } else { wlr_log(L_DEBUG, "unhandled x11 property %u", property); } diff --git a/xwayland/xwm.h b/xwayland/xwm.h index 1572997e..5820a06d 100644 --- a/xwayland/xwm.h +++ b/xwayland/xwm.h @@ -48,6 +48,7 @@ enum atom_name { WL_SURFACE_ID, WM_PROTOCOLS, + UTF8_STRING, WM_S0, NET_SUPPORTED, NET_WM_S0, -- cgit v1.2.3 From d8c86431e0b6a72f5cccd8f9e09059aa9eff9fd3 Mon Sep 17 00:00:00 2001 From: emersion Date: Fri, 29 Sep 2017 18:28:38 +0200 Subject: xwayland: add signals for configure, set_{class,title} --- include/rootston/view.h | 1 + include/wlr/types/wlr_wl_shell.h | 2 +- include/wlr/xwayland.h | 16 +++++++++++--- rootston/xwayland.c | 29 +++++++++++++++++++++--- xwayland/xwm.c | 48 ++++++++++++++++++++++++++++++---------- 5 files changed, 77 insertions(+), 19 deletions(-) (limited to 'xwayland') diff --git a/include/rootston/view.h b/include/rootston/view.h index da3b189d..2bd71104 100644 --- a/include/rootston/view.h +++ b/include/rootston/view.h @@ -31,6 +31,7 @@ struct roots_xwayland_surface { struct roots_view *view; // TODO: Maybe destroy listener should go in roots_view struct wl_listener destroy; + struct wl_listener request_configure; }; enum roots_view_type { diff --git a/include/wlr/types/wlr_wl_shell.h b/include/wlr/types/wlr_wl_shell.h index 0b18a131..0db99989 100644 --- a/include/wlr/types/wlr_wl_shell.h +++ b/include/wlr/types/wlr_wl_shell.h @@ -106,7 +106,7 @@ void wlr_wl_shell_destroy(struct wlr_wl_shell *wlr_wl_shell); void wlr_wl_shell_surface_ping(struct wlr_wl_shell_surface *surface); void wlr_wl_shell_surface_configure(struct wlr_wl_shell_surface *surface, - uint32_t edges, int32_t width, int32_t height); + enum wl_shell_surface_resize edges, int32_t width, int32_t height); void wlr_wl_shell_surface_popup_done(struct wlr_wl_shell_surface *surface); #endif diff --git a/include/wlr/xwayland.h b/include/wlr/xwayland.h index ebb6efb7..4e59d9c5 100644 --- a/include/wlr/xwayland.h +++ b/include/wlr/xwayland.h @@ -47,18 +47,28 @@ struct wlr_xwayland_surface { struct { struct wl_signal destroy; + + struct wl_signal request_configure; + + struct wl_signal set_title; + struct wl_signal set_class; } events; void *data; }; +struct wlr_xwayland_surface_configure_event { + struct wlr_xwayland_surface *surface; + int16_t x, y; + uint16_t width, height; +}; + 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); -void wlr_xwayland_surface_configure(struct wlr_xwm *xwm, - struct wlr_xwayland_surface *surface, uint32_t x, uint32_t y, - uint32_t width, uint32_t height); +void wlr_xwayland_surface_configure(struct wlr_xwayland *wlr_xwayland, + struct wlr_xwayland_surface *surface); #endif diff --git a/rootston/xwayland.c b/rootston/xwayland.c index aaf55b37..685681d9 100644 --- a/rootston/xwayland.c +++ b/rootston/xwayland.c @@ -17,7 +17,25 @@ static void handle_destroy(struct wl_listener *listener, void *data) { free(roots_surface); } -static void x11_activate(struct roots_view *view, bool active) { +static void handle_configure(struct wl_listener *listener, void *data) { + struct roots_xwayland_surface *roots_surface = + wl_container_of(listener, roots_surface, destroy); + struct wlr_xwayland_surface_configure_event *event = data; + struct wlr_xwayland_surface *xwayland_surface = event->surface; + + xwayland_surface->x = event->x; + xwayland_surface->y = event->y; + xwayland_surface->width = event->width; + xwayland_surface->height = event->height; + + roots_surface->view->x = (double) event->x; + roots_surface->view->y = (double) event->y; + + wlr_xwayland_surface_configure(roots_surface->view->desktop->xwayland, + xwayland_surface); +} + +static void activate(struct roots_view *view, bool active) { wlr_xwayland_surface_activate(view->desktop->xwayland, view->xwayland_surface); } @@ -35,15 +53,20 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) { wl_list_init(&roots_surface->destroy.link); roots_surface->destroy.notify = handle_destroy; wl_signal_add(&surface->events.destroy, &roots_surface->destroy); + wl_list_init(&roots_surface->request_configure.link); + roots_surface->request_configure.notify = handle_configure; + wl_signal_add(&surface->events.request_configure, + &roots_surface->request_configure); struct roots_view *view = calloc(1, sizeof(struct roots_view)); view->type = ROOTS_XWAYLAND_VIEW; - view->x = view->y = 200; + view->x = (double) surface->x; + view->y = (double) surface->y; view->xwayland_surface = surface; view->roots_xwayland_surface = roots_surface; view->wlr_surface = surface->surface; view->desktop = desktop; - view->activate = x11_activate; + view->activate = activate; roots_surface->view = view; list_add(desktop->views, view); } diff --git a/xwayland/xwm.c b/xwayland/xwm.c index e316d8fa..b8eefa4b 100644 --- a/xwayland/xwm.c +++ b/xwayland/xwm.c @@ -61,6 +61,9 @@ static struct wlr_xwayland_surface *wlr_xwayland_surface_create( surface->override_redirect = override_redirect; wl_list_insert(&xwm->new_surfaces, &surface->link); wl_signal_init(&surface->events.destroy); + wl_signal_init(&surface->events.request_configure); + wl_signal_init(&surface->events.set_class); + wl_signal_init(&surface->events.set_title); return surface; } @@ -112,6 +115,7 @@ static void read_surface_class(struct wlr_xwm *xwm, } wlr_log(L_DEBUG, "XCB_ATOM_WM_CLASS: %s %s", surface->instance, surface->class); + wl_signal_emit(&surface->events.set_class, surface); } static void read_surface_title(struct wlr_xwm *xwm, @@ -135,6 +139,7 @@ static void read_surface_title(struct wlr_xwm *xwm, } wlr_log(L_DEBUG, "XCB_ATOM_WM_NAME: %s", surface->title); + wl_signal_emit(&surface->events.set_title, surface); } static void read_surface_parent(struct wlr_xwm *xwm, @@ -233,14 +238,32 @@ static void handle_configure_request(struct wlr_xwm *xwm, return; } - surface->x = ev->x; - surface->y = ev->y; - surface->width = ev->width; - surface->height = ev->height; - // TODO: handle parent/sibling? + // TODO: handle ev->{parent,sibling}? - wlr_xwayland_surface_configure(xwm, surface, ev->x, ev->y, ev->width, - ev->height); + if (surface->surface == NULL) { + // Surface has not been mapped yet + surface->x = ev->x; + surface->y = ev->y; + surface->width = ev->width; + surface->height = ev->height; + wlr_xwayland_surface_configure(xwm->xwayland, surface); + } else { + struct wlr_xwayland_surface_configure_event *wlr_event = + calloc(1, sizeof(struct wlr_xwayland_surface_configure_event)); + if (wlr_event == NULL) { + return; + } + + wlr_event->surface = surface; + 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); + + free(wlr_event); + } } static void handle_map_request(struct wlr_xwm *xwm, @@ -369,7 +392,7 @@ static void create_surface_handler(struct wl_listener *listener, void *data) { return; } - wlr_log(L_DEBUG, "New x11 surface: %p", surface); + 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; @@ -465,13 +488,14 @@ void wlr_xwayland_surface_activate(struct wlr_xwayland *wlr_xwayland, xcb_flush(xwm->xcb_conn); } -void wlr_xwayland_surface_configure(struct wlr_xwm *xwm, - struct wlr_xwayland_surface *surface, uint32_t x, uint32_t y, - uint32_t width, uint32_t height) { +void wlr_xwayland_surface_configure(struct wlr_xwayland *wlr_xwayland, + struct wlr_xwayland_surface *surface) { + 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}; + uint32_t values[] = {surface->x, surface->y, surface->width, + surface->height, 0}; xcb_configure_window(xwm->xcb_conn, surface->window_id, mask, values); } -- cgit v1.2.3 From 7c9f3240f67ebb9e5070ab41b9d8c23951df977e Mon Sep 17 00:00:00 2001 From: emersion Date: Fri, 29 Sep 2017 20:22:35 +0200 Subject: xwayland: add set_parent event --- include/wlr/xwayland.h | 1 + xwayland/xwm.c | 2 ++ 2 files changed, 3 insertions(+) (limited to 'xwayland') diff --git a/include/wlr/xwayland.h b/include/wlr/xwayland.h index 4e59d9c5..f2484889 100644 --- a/include/wlr/xwayland.h +++ b/include/wlr/xwayland.h @@ -52,6 +52,7 @@ struct wlr_xwayland_surface { struct wl_signal set_title; struct wl_signal set_class; + struct wl_signal set_parent; } events; void *data; diff --git a/xwayland/xwm.c b/xwayland/xwm.c index b8eefa4b..d1e41b3c 100644 --- a/xwayland/xwm.c +++ b/xwayland/xwm.c @@ -64,6 +64,7 @@ static struct wlr_xwayland_surface *wlr_xwayland_surface_create( wl_signal_init(&surface->events.request_configure); wl_signal_init(&surface->events.set_class); wl_signal_init(&surface->events.set_title); + wl_signal_init(&surface->events.set_parent); return surface; } @@ -156,6 +157,7 @@ static void read_surface_parent(struct wlr_xwm *xwm, } wlr_log(L_DEBUG, "XCB_ATOM_WM_TRANSIENT_FOR: %p", xid); + wl_signal_emit(&surface->events.set_parent, surface); } static void read_surface_property(struct wlr_xwm *xwm, -- cgit v1.2.3 From 97346e7a1be87f1b98683e6f42f25a91b4813994 Mon Sep 17 00:00:00 2001 From: emersion Date: Fri, 29 Sep 2017 22:26:03 +0200 Subject: xwayland: add state support --- include/wlr/xwayland.h | 2 ++ rootston/xwayland.c | 16 ++++++++++---- xwayland/xwm.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++-- xwayland/xwm.h | 6 +++++ 4 files changed, 78 insertions(+), 6 deletions(-) (limited to 'xwayland') diff --git a/include/wlr/xwayland.h b/include/wlr/xwayland.h index f2484889..2a7e3240 100644 --- a/include/wlr/xwayland.h +++ b/include/wlr/xwayland.h @@ -44,6 +44,7 @@ struct wlr_xwayland_surface { char *class; char *instance; struct wlr_xwayland_surface *parent; + list_t *state; // list of xcb_atom_t struct { struct wl_signal destroy; @@ -53,6 +54,7 @@ struct wlr_xwayland_surface { struct wl_signal set_title; struct wl_signal set_class; struct wl_signal set_parent; + struct wl_signal set_state; } events; void *data; diff --git a/rootston/xwayland.c b/rootston/xwayland.c index 9f2cc849..181b959d 100644 --- a/rootston/xwayland.c +++ b/rootston/xwayland.c @@ -19,9 +19,10 @@ static void handle_destroy(struct wl_listener *listener, void *data) { static void handle_configure(struct wl_listener *listener, void *data) { struct roots_xwayland_surface *roots_surface = - wl_container_of(listener, roots_surface, destroy); + wl_container_of(listener, roots_surface, request_configure); + struct wlr_xwayland_surface *xwayland_surface = + roots_surface->view->xwayland_surface; struct wlr_xwayland_surface_configure_event *event = data; - struct wlr_xwayland_surface *xwayland_surface = event->surface; xwayland_surface->x = event->x; xwayland_surface->y = event->y; @@ -45,11 +46,14 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) { wl_container_of(listener, desktop, xwayland_surface); struct wlr_xwayland_surface *surface = data; - // TODO: get and log title, class, etc - wlr_log(L_DEBUG, "new xwayland surface"); + wlr_log(L_DEBUG, "new xwayland surface: title=%s, class=%s, instance=%s", + surface->title, surface->class, surface->instance); struct roots_xwayland_surface *roots_surface = calloc(1, sizeof(struct roots_xwayland_surface)); + if (roots_surface == NULL) { + return; + } wl_list_init(&roots_surface->destroy.link); roots_surface->destroy.notify = handle_destroy; wl_signal_add(&surface->events.destroy, &roots_surface->destroy); @@ -59,6 +63,10 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) { &roots_surface->request_configure); struct roots_view *view = calloc(1, sizeof(struct roots_view)); + if (view == NULL) { + free(roots_surface); + return; + } view->type = ROOTS_XWAYLAND_VIEW; view->x = (double)surface->x; view->y = (double)surface->y; diff --git a/xwayland/xwm.c b/xwayland/xwm.c index d1e41b3c..478666eb 100644 --- a/xwayland/xwm.c +++ b/xwayland/xwm.c @@ -60,17 +60,23 @@ static struct wlr_xwayland_surface *wlr_xwayland_surface_create( surface->height = height; surface->override_redirect = override_redirect; wl_list_insert(&xwm->new_surfaces, &surface->link); + surface->state = list_create(); wl_signal_init(&surface->events.destroy); wl_signal_init(&surface->events.request_configure); 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); return surface; } static void wlr_xwayland_surface_destroy(struct wlr_xwayland_surface *surface) { wl_signal_emit(&surface->events.destroy, surface); wl_list_remove(&surface->link); + for (size_t i = 0; i < surface->state->length; i++) { + free(surface->state->items[i]); + } + list_free(surface->state); free(surface); } @@ -160,6 +166,46 @@ 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]); + 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; + 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) { + if (reply->type != XCB_ATOM_ATOM) { // TODO: check that + return; + } + handle_surface_state(xwm, surface, xcb_get_property_value(reply), + reply->value_len, NET_WM_STATE_ADD); +} + 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, @@ -177,6 +223,8 @@ static void read_surface_property(struct wlr_xwm *xwm, read_surface_title(xwm, surface, reply); } else if (property == XCB_ATOM_WM_TRANSIENT_FOR) { read_surface_parent(xwm, surface, reply); + } else if (property == xwm->atoms[NET_WM_STATE]) { + read_surface_state(xwm, surface, reply); } else { wlr_log(L_DEBUG, "unhandled x11 property %u", property); } @@ -197,9 +245,9 @@ static void map_shell_surface(struct wlr_xwm *xwm, XCB_ATOM_WM_TRANSIENT_FOR, //xwm->atoms[WM_PROTOCOLS], //xwm->atoms[WM_NORMAL_HINTS], - //xwm->atoms[NET_WM_STATE], + xwm->atoms[NET_WM_STATE], //xwm->atoms[NET_WM_WINDOW_TYPE], - //xwm->atoms[NET_WM_NAME], + xwm->atoms[NET_WM_NAME], //xwm->atoms[NET_WM_PID], //xwm->atoms[MOTIF_WM_HINTS], }; @@ -333,6 +381,14 @@ static void handle_client_message(struct wlr_xwm *xwm, wl_list_remove(&surface->link); wl_list_insert(&xwm->unpaired_surfaces, &surface->link); } + } else if (ev->type == xwm->atoms[NET_WM_STATE]) { + struct wlr_xwayland_surface *surface = lookup_surface_any(xwm, + ev->window); + if (surface == NULL) { + return; + } + handle_surface_state(xwm, surface, &ev->data.data32[1], 2, + ev->data.data32[0]); } else { wlr_log(L_DEBUG, "unhandled x11 client message %u", ev->type); } diff --git a/xwayland/xwm.h b/xwayland/xwm.h index 5820a06d..8d6b6202 100644 --- a/xwayland/xwm.h +++ b/xwayland/xwm.h @@ -60,6 +60,12 @@ enum atom_name { 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_TOGGLE = 2, +}; + struct wlr_xwm { struct wlr_xwayland *xwayland; struct wl_event_source *event_source; -- cgit v1.2.3 From b78ae541583533dbcfbca2035c09dcd1e6c1b1bd Mon Sep 17 00:00:00 2001 From: emersion Date: Fri, 29 Sep 2017 22:43:14 +0200 Subject: xwayland: add pid support --- include/wlr/xwayland.h | 1 + xwayland/xwm.c | 20 ++++++++++++++++---- xwayland/xwm.h | 1 + 3 files changed, 18 insertions(+), 4 deletions(-) (limited to 'xwayland') diff --git a/include/wlr/xwayland.h b/include/wlr/xwayland.h index 2a7e3240..e67caf9f 100644 --- a/include/wlr/xwayland.h +++ b/include/wlr/xwayland.h @@ -45,6 +45,7 @@ struct wlr_xwayland_surface { char *instance; struct wlr_xwayland_surface *parent; list_t *state; // list of xcb_atom_t + pid_t pid; struct { struct wl_signal destroy; diff --git a/xwayland/xwm.c b/xwayland/xwm.c index 478666eb..45c4b095 100644 --- a/xwayland/xwm.c +++ b/xwayland/xwm.c @@ -15,6 +15,7 @@ const char *atom_map[ATOM_LAST] = { "WM_S0", "_NET_SUPPORTED", "_NET_WM_S0", + "_NET_WM_PID", "_NET_WM_NAME", "_NET_WM_STATE", "WM_TAKE_FOCUS", @@ -199,13 +200,22 @@ static void handle_surface_state(struct wlr_xwm *xwm, static void read_surface_state(struct wlr_xwm *xwm, struct wlr_xwayland_surface *surface, xcb_get_property_reply_t *reply) { - if (reply->type != XCB_ATOM_ATOM) { // TODO: check that - return; - } + // 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) { + return; + } + + pid_t *pid = (pid_t *)xcb_get_property_value(reply); + surface->pid = *pid; + wlr_log(L_DEBUG, "NET_WM_PID %d", surface->pid); +} + 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, @@ -223,6 +233,8 @@ static void read_surface_property(struct wlr_xwm *xwm, read_surface_title(xwm, surface, reply); } else if (property == XCB_ATOM_WM_TRANSIENT_FOR) { read_surface_parent(xwm, surface, reply); + } else if (property == xwm->atoms[NET_WM_PID]) { + read_surface_pid(xwm, surface, reply); } else if (property == xwm->atoms[NET_WM_STATE]) { read_surface_state(xwm, surface, reply); } else { @@ -248,7 +260,7 @@ static void map_shell_surface(struct wlr_xwm *xwm, xwm->atoms[NET_WM_STATE], //xwm->atoms[NET_WM_WINDOW_TYPE], xwm->atoms[NET_WM_NAME], - //xwm->atoms[NET_WM_PID], + xwm->atoms[NET_WM_PID], //xwm->atoms[MOTIF_WM_HINTS], }; for (size_t i = 0; i < sizeof(props)/sizeof(xcb_atom_t); i++) { diff --git a/xwayland/xwm.h b/xwayland/xwm.h index 8d6b6202..b7644107 100644 --- a/xwayland/xwm.h +++ b/xwayland/xwm.h @@ -52,6 +52,7 @@ enum atom_name { WM_S0, NET_SUPPORTED, NET_WM_S0, + NET_WM_PID, NET_WM_NAME, NET_WM_STATE, WM_TAKE_FOCUS, -- cgit v1.2.3 From 5002d968f303f6e678cbe87cc034b14d8f8b3ce8 Mon Sep 17 00:00:00 2001 From: emersion Date: Fri, 29 Sep 2017 23:03:01 +0200 Subject: xwayland: add window_type support --- include/wlr/xwayland.h | 5 +++++ xwayland/xwm.c | 35 +++++++++++++++++++++++++++++++---- xwayland/xwm.h | 1 + 3 files changed, 37 insertions(+), 4 deletions(-) (limited to 'xwayland') diff --git a/include/wlr/xwayland.h b/include/wlr/xwayland.h index e67caf9f..bb85017e 100644 --- a/include/wlr/xwayland.h +++ b/include/wlr/xwayland.h @@ -47,6 +47,9 @@ struct wlr_xwayland_surface { list_t *state; // list of xcb_atom_t pid_t pid; + xcb_atom_t *window_type; + size_t window_type_len; + struct { struct wl_signal destroy; @@ -56,6 +59,8 @@ struct wlr_xwayland_surface { 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; void *data; diff --git a/xwayland/xwm.c b/xwayland/xwm.c index 45c4b095..a84b19a5 100644 --- a/xwayland/xwm.c +++ b/xwayland/xwm.c @@ -18,6 +18,7 @@ const char *atom_map[ATOM_LAST] = { "_NET_WM_PID", "_NET_WM_NAME", "_NET_WM_STATE", + "_NET_WM_WINDOW_TYPE", "WM_TAKE_FOCUS", }; @@ -68,6 +69,8 @@ static struct wlr_xwayland_surface *wlr_xwayland_surface_create( 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; } @@ -78,6 +81,7 @@ static void wlr_xwayland_surface_destroy(struct wlr_xwayland_surface *surface) { free(surface->state->items[i]); } list_free(surface->state); + free(surface->window_type); free(surface); } @@ -211,9 +215,32 @@ static void read_surface_pid(struct wlr_xwm *xwm, return; } - pid_t *pid = (pid_t *)xcb_get_property_value(reply); + 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); +} + +static void read_surface_window_type(struct wlr_xwm *xwm, + struct wlr_xwayland_surface *surface, xcb_get_property_reply_t *reply) { + if (reply->type != XCB_ATOM_ATOM) { + return; + } + + xcb_atom_t *atoms = xcb_get_property_value(reply); + 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) { + return; + } + memcpy(surface->window_type, atoms, atoms_size); + surface->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); } static void read_surface_property(struct wlr_xwm *xwm, @@ -235,6 +262,8 @@ static void read_surface_property(struct wlr_xwm *xwm, read_surface_parent(xwm, surface, reply); } else if (property == xwm->atoms[NET_WM_PID]) { read_surface_pid(xwm, surface, reply); + } else if (property == xwm->atoms[NET_WM_WINDOW_TYPE]) { + read_surface_window_type(xwm, surface, reply); } else if (property == xwm->atoms[NET_WM_STATE]) { read_surface_state(xwm, surface, reply); } else { @@ -256,12 +285,10 @@ static void map_shell_surface(struct wlr_xwm *xwm, XCB_ATOM_WM_NAME, XCB_ATOM_WM_TRANSIENT_FOR, //xwm->atoms[WM_PROTOCOLS], - //xwm->atoms[WM_NORMAL_HINTS], xwm->atoms[NET_WM_STATE], - //xwm->atoms[NET_WM_WINDOW_TYPE], + xwm->atoms[NET_WM_WINDOW_TYPE], xwm->atoms[NET_WM_NAME], xwm->atoms[NET_WM_PID], - //xwm->atoms[MOTIF_WM_HINTS], }; for (size_t i = 0; i < sizeof(props)/sizeof(xcb_atom_t); i++) { read_surface_property(xwm, xwayland_surface, props[i]); diff --git a/xwayland/xwm.h b/xwayland/xwm.h index b7644107..0d753832 100644 --- a/xwayland/xwm.h +++ b/xwayland/xwm.h @@ -55,6 +55,7 @@ enum atom_name { NET_WM_PID, NET_WM_NAME, NET_WM_STATE, + NET_WM_WINDOW_TYPE, WM_TAKE_FOCUS, ATOM_LAST, }; -- cgit v1.2.3 From 4ccb83bf33bbf531eef7fbd20e80146562fcae64 Mon Sep 17 00:00:00 2001 From: emersion Date: Fri, 29 Sep 2017 23:18:12 +0200 Subject: xwayland: add wlr_xwayland_surface_close --- include/wlr/xwayland.h | 5 +++++ xwayland/xwm.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++- xwayland/xwm.h | 1 + 3 files changed, 60 insertions(+), 1 deletion(-) (limited to 'xwayland') diff --git a/include/wlr/xwayland.h b/include/wlr/xwayland.h index bb85017e..43133567 100644 --- a/include/wlr/xwayland.h +++ b/include/wlr/xwayland.h @@ -50,6 +50,9 @@ struct wlr_xwayland_surface { xcb_atom_t *window_type; size_t window_type_len; + xcb_atom_t *protocols; + size_t protocols_len; + struct { struct wl_signal destroy; @@ -79,5 +82,7 @@ void wlr_xwayland_surface_activate(struct wlr_xwayland *wlr_xwayland, struct wlr_xwayland_surface *surface); void wlr_xwayland_surface_configure(struct wlr_xwayland *wlr_xwayland, struct wlr_xwayland_surface *surface); +void wlr_xwayland_surface_close(struct wlr_xwayland *wlr_xwayland, + struct wlr_xwayland_surface *surface); #endif diff --git a/xwayland/xwm.c b/xwayland/xwm.c index a84b19a5..d7816bcd 100644 --- a/xwayland/xwm.c +++ b/xwayland/xwm.c @@ -10,6 +10,7 @@ const char *atom_map[ATOM_LAST] = { "WL_SURFACE_ID", + "WM_DELETE_WINDOW", "WM_PROTOCOLS", "UTF8_STRING", "WM_S0", @@ -243,6 +244,27 @@ static void read_surface_window_type(struct wlr_xwm *xwm, wl_signal_emit(&surface->events.set_window_type, surface); } +static void read_surface_protocols(struct wlr_xwm *xwm, + struct wlr_xwayland_surface *surface, xcb_get_property_reply_t *reply) { + if (reply->type != XCB_ATOM_ATOM) { + return; + } + + xcb_atom_t *atoms = xcb_get_property_value(reply); + 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) { + return; + } + memcpy(surface->protocols, atoms, atoms_size); + surface->protocols_len = atoms_len; + + wlr_log(L_DEBUG, "WM_PROTOCOLS (%zu)", atoms_len); +} + 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, @@ -264,6 +286,8 @@ static void read_surface_property(struct wlr_xwm *xwm, read_surface_pid(xwm, surface, reply); } else if (property == xwm->atoms[NET_WM_WINDOW_TYPE]) { read_surface_window_type(xwm, surface, reply); + } 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); } else { @@ -284,7 +308,7 @@ static void map_shell_surface(struct wlr_xwm *xwm, XCB_ATOM_WM_CLASS, XCB_ATOM_WM_NAME, XCB_ATOM_WM_TRANSIENT_FOR, - //xwm->atoms[WM_PROTOCOLS], + xwm->atoms[WM_PROTOCOLS], xwm->atoms[NET_WM_STATE], xwm->atoms[NET_WM_WINDOW_TYPE], xwm->atoms[NET_WM_NAME], @@ -596,6 +620,35 @@ void wlr_xwayland_surface_configure(struct wlr_xwayland *wlr_xwayland, xcb_configure_window(xwm->xcb_conn, surface->window_id, mask, values); } +void wlr_xwayland_surface_close(struct wlr_xwayland *wlr_xwayland, + struct wlr_xwayland_surface *surface) { + 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]) { + supports_delete = true; + break; + } + } + + if (supports_delete) { + xcb_client_message_event_t ev = {0}; + ev.response_type = XCB_CLIENT_MESSAGE; + ev.window = surface->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)); + } else { + XCB_CALL(xwm, xcb_kill_client_checked(xwm->xcb_conn, + surface->window_id)); + } +} + void xwm_destroy(struct wlr_xwm *xwm) { if (!xwm) { return; diff --git a/xwayland/xwm.h b/xwayland/xwm.h index 0d753832..d1998e48 100644 --- a/xwayland/xwm.h +++ b/xwayland/xwm.h @@ -47,6 +47,7 @@ enum atom_name { WL_SURFACE_ID, + WM_DELETE_WINDOW, WM_PROTOCOLS, UTF8_STRING, WM_S0, -- cgit v1.2.3