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} --- rootston/xwayland.c | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) (limited to 'rootston/xwayland.c') 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); } -- cgit v1.2.3 From 98707c16adc405d6ffaf9fe0a8f466a40f50ef85 Mon Sep 17 00:00:00 2001 From: emersion Date: Fri, 29 Sep 2017 20:44:00 +0200 Subject: Code style --- rootston/xwayland.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'rootston/xwayland.c') diff --git a/rootston/xwayland.c b/rootston/xwayland.c index 685681d9..9f2cc849 100644 --- a/rootston/xwayland.c +++ b/rootston/xwayland.c @@ -28,8 +28,8 @@ static void handle_configure(struct wl_listener *listener, void *data) { xwayland_surface->width = event->width; xwayland_surface->height = event->height; - roots_surface->view->x = (double) event->x; - roots_surface->view->y = (double) event->y; + 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); @@ -60,8 +60,8 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) { struct roots_view *view = calloc(1, sizeof(struct roots_view)); view->type = ROOTS_XWAYLAND_VIEW; - view->x = (double) surface->x; - view->y = (double) surface->y; + 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; -- 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 'rootston/xwayland.c') 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