xwayland: add state support

This commit is contained in:
emersion 2017-09-29 22:26:03 +02:00
parent 98707c16ad
commit 97346e7a1b
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48
4 changed files with 78 additions and 6 deletions

View File

@ -44,6 +44,7 @@ struct wlr_xwayland_surface {
char *class; char *class;
char *instance; char *instance;
struct wlr_xwayland_surface *parent; struct wlr_xwayland_surface *parent;
list_t *state; // list of xcb_atom_t
struct { struct {
struct wl_signal destroy; struct wl_signal destroy;
@ -53,6 +54,7 @@ struct wlr_xwayland_surface {
struct wl_signal set_title; struct wl_signal set_title;
struct wl_signal set_class; struct wl_signal set_class;
struct wl_signal set_parent; struct wl_signal set_parent;
struct wl_signal set_state;
} events; } events;
void *data; void *data;

View File

@ -19,9 +19,10 @@ static void handle_destroy(struct wl_listener *listener, void *data) {
static void handle_configure(struct wl_listener *listener, void *data) { static void handle_configure(struct wl_listener *listener, void *data) {
struct roots_xwayland_surface *roots_surface = 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_configure_event *event = data;
struct wlr_xwayland_surface *xwayland_surface = event->surface;
xwayland_surface->x = event->x; xwayland_surface->x = event->x;
xwayland_surface->y = event->y; 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); wl_container_of(listener, desktop, xwayland_surface);
struct wlr_xwayland_surface *surface = data; struct wlr_xwayland_surface *surface = data;
// TODO: get and log title, class, etc wlr_log(L_DEBUG, "new xwayland surface: title=%s, class=%s, instance=%s",
wlr_log(L_DEBUG, "new xwayland surface"); surface->title, surface->class, surface->instance);
struct roots_xwayland_surface *roots_surface = struct roots_xwayland_surface *roots_surface =
calloc(1, sizeof(struct roots_xwayland_surface)); calloc(1, sizeof(struct roots_xwayland_surface));
if (roots_surface == NULL) {
return;
}
wl_list_init(&roots_surface->destroy.link); wl_list_init(&roots_surface->destroy.link);
roots_surface->destroy.notify = handle_destroy; roots_surface->destroy.notify = handle_destroy;
wl_signal_add(&surface->events.destroy, &roots_surface->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); &roots_surface->request_configure);
struct roots_view *view = calloc(1, sizeof(struct roots_view)); struct roots_view *view = calloc(1, sizeof(struct roots_view));
if (view == NULL) {
free(roots_surface);
return;
}
view->type = ROOTS_XWAYLAND_VIEW; view->type = ROOTS_XWAYLAND_VIEW;
view->x = (double)surface->x; view->x = (double)surface->x;
view->y = (double)surface->y; view->y = (double)surface->y;

View File

@ -60,17 +60,23 @@ static struct wlr_xwayland_surface *wlr_xwayland_surface_create(
surface->height = height; surface->height = height;
surface->override_redirect = override_redirect; surface->override_redirect = override_redirect;
wl_list_insert(&xwm->new_surfaces, &surface->link); wl_list_insert(&xwm->new_surfaces, &surface->link);
surface->state = list_create();
wl_signal_init(&surface->events.destroy); wl_signal_init(&surface->events.destroy);
wl_signal_init(&surface->events.request_configure); wl_signal_init(&surface->events.request_configure);
wl_signal_init(&surface->events.set_class); wl_signal_init(&surface->events.set_class);
wl_signal_init(&surface->events.set_title); wl_signal_init(&surface->events.set_title);
wl_signal_init(&surface->events.set_parent); wl_signal_init(&surface->events.set_parent);
wl_signal_init(&surface->events.set_state);
return surface; return surface;
} }
static void wlr_xwayland_surface_destroy(struct wlr_xwayland_surface *surface) { static void wlr_xwayland_surface_destroy(struct wlr_xwayland_surface *surface) {
wl_signal_emit(&surface->events.destroy, surface); wl_signal_emit(&surface->events.destroy, surface);
wl_list_remove(&surface->link); 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); free(surface);
} }
@ -160,6 +166,46 @@ static void read_surface_parent(struct wlr_xwm *xwm,
wl_signal_emit(&surface->events.set_parent, surface); 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, static void read_surface_property(struct wlr_xwm *xwm,
struct wlr_xwayland_surface *surface, xcb_atom_t property) { struct wlr_xwayland_surface *surface, xcb_atom_t property) {
xcb_get_property_cookie_t cookie = xcb_get_property(xwm->xcb_conn, 0, 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); read_surface_title(xwm, surface, reply);
} else if (property == XCB_ATOM_WM_TRANSIENT_FOR) { } else if (property == XCB_ATOM_WM_TRANSIENT_FOR) {
read_surface_parent(xwm, surface, reply); read_surface_parent(xwm, surface, reply);
} else if (property == xwm->atoms[NET_WM_STATE]) {
read_surface_state(xwm, surface, reply);
} else { } else {
wlr_log(L_DEBUG, "unhandled x11 property %u", property); 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, XCB_ATOM_WM_TRANSIENT_FOR,
//xwm->atoms[WM_PROTOCOLS], //xwm->atoms[WM_PROTOCOLS],
//xwm->atoms[WM_NORMAL_HINTS], //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_WINDOW_TYPE],
//xwm->atoms[NET_WM_NAME], xwm->atoms[NET_WM_NAME],
//xwm->atoms[NET_WM_PID], //xwm->atoms[NET_WM_PID],
//xwm->atoms[MOTIF_WM_HINTS], //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_remove(&surface->link);
wl_list_insert(&xwm->unpaired_surfaces, &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 { } else {
wlr_log(L_DEBUG, "unhandled x11 client message %u", ev->type); wlr_log(L_DEBUG, "unhandled x11 client message %u", ev->type);
} }

View File

@ -60,6 +60,12 @@ enum atom_name {
extern const char *atom_map[ATOM_LAST]; 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_xwm {
struct wlr_xwayland *xwayland; struct wlr_xwayland *xwayland;
struct wl_event_source *event_source; struct wl_event_source *event_source;