Add reply->type checks, add XCB_ATOM_WM_TRANSIENT_FOR

This commit is contained in:
emersion 2017-09-29 16:44:22 +02:00
parent 47d767dbc4
commit f2b03b2ec1
No known key found for this signature in database
GPG key ID: 0FDE7BE0E88F5E48
3 changed files with 75 additions and 35 deletions

View file

@ -43,6 +43,7 @@ struct wlr_xwayland_surface {
char *title; char *title;
char *class; char *class;
char *instance; char *instance;
struct wlr_xwayland_surface *parent;
struct { struct {
struct wl_signal destroy; struct wl_signal destroy;

View file

@ -11,6 +11,7 @@
const char *atom_map[ATOM_LAST] = { const char *atom_map[ATOM_LAST] = {
"WL_SURFACE_ID", "WL_SURFACE_ID",
"WM_PROTOCOLS", "WM_PROTOCOLS",
"UTF8_STRING",
"WM_S0", "WM_S0",
"_NET_SUPPORTED", "_NET_SUPPORTED",
"_NET_WM_S0", "_NET_WM_S0",
@ -84,19 +85,13 @@ static bool xcb_call(struct wlr_xwm *xwm, const char *func, uint32_t line,
return false; return false;
} }
static void read_surface_property(struct wlr_xwm *xwm, static void read_surface_class(struct wlr_xwm *xwm,
struct wlr_xwayland_surface *surface, xcb_atom_t property) { struct wlr_xwayland_surface *surface, xcb_get_property_reply_t *reply) {
xcb_get_property_cookie_t cookie = xcb_get_property(xwm->xcb_conn, 0, if (reply->type != XCB_ATOM_STRING &&
surface->window_id, property, XCB_ATOM_ANY, 0, 2048); reply->type != xwm->atoms[UTF8_STRING]) {
xcb_get_property_reply_t *reply = xcb_get_property_reply(xwm->xcb_conn,
cookie, NULL);
if (reply == NULL) {
return; return;
} }
// TODO: check reply->type
if (property == XCB_ATOM_WM_CLASS) {
size_t len = xcb_get_property_value_length(reply); size_t len = xcb_get_property_value_length(reply);
char *class = xcb_get_property_value(reply); char *class = xcb_get_property_value(reply);
@ -117,10 +112,18 @@ static void read_surface_property(struct wlr_xwm *xwm,
} }
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);
} else if (property == XCB_ATOM_WM_NAME || }
property == xwm->atoms[NET_WM_NAME]) {
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 // TODO: if reply->type == XCB_ATOM_STRING, uses latin1 encoding
// if reply->type == xwm->atoms[UTF8_STRING], uses utf8 encoding // if reply->type == xwm->atoms[UTF8_STRING], uses utf8 encoding
size_t len = xcb_get_property_value_length(reply); size_t len = xcb_get_property_value_length(reply);
char *title = xcb_get_property_value(reply); char *title = xcb_get_property_value(reply);
@ -132,6 +135,41 @@ static void read_surface_property(struct wlr_xwm *xwm,
} }
wlr_log(L_DEBUG, "XCB_ATOM_WM_NAME: %s", surface->title); 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,
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;
}
if (property == XCB_ATOM_WM_CLASS) {
read_surface_class(xwm, surface, reply);
} else if (property == XCB_ATOM_WM_NAME ||
property == xwm->atoms[NET_WM_NAME]) {
read_surface_title(xwm, surface, reply);
} else if (property == XCB_ATOM_WM_TRANSIENT_FOR) {
read_surface_parent(xwm, surface, reply);
} else { } else {
wlr_log(L_DEBUG, "unhandled x11 property %u", property); wlr_log(L_DEBUG, "unhandled x11 property %u", property);
} }

View file

@ -48,6 +48,7 @@
enum atom_name { enum atom_name {
WL_SURFACE_ID, WL_SURFACE_ID,
WM_PROTOCOLS, WM_PROTOCOLS,
UTF8_STRING,
WM_S0, WM_S0,
NET_SUPPORTED, NET_SUPPORTED,
NET_WM_S0, NET_WM_S0,