xwm: net active window

This commit is contained in:
Tony Crisci 2017-10-24 10:04:33 -04:00
parent 03bd34e826
commit 79978383ba
2 changed files with 49 additions and 18 deletions

View file

@ -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);
}

View file

@ -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;