Merge pull request #167 from emersion/xwayland

[WIP] Improve xwayland
master
Drew DeVault 7 years ago committed by GitHub
commit e4ad534ab4

@ -97,7 +97,9 @@ struct roots_input *input_create(struct roots_server *server,
void input_destroy(struct roots_input *input); void input_destroy(struct roots_input *input);
void pointer_add(struct wlr_input_device *device, struct roots_input *input); void pointer_add(struct wlr_input_device *device, struct roots_input *input);
void pointer_remove(struct wlr_input_device *device, struct roots_input *input);
void keyboard_add(struct wlr_input_device *device, struct roots_input *input); void keyboard_add(struct wlr_input_device *device, struct roots_input *input);
void keyboard_remove(struct wlr_input_device *device, struct roots_input *input);
void cursor_initialize(struct roots_input *input); void cursor_initialize(struct roots_input *input);
void cursor_load_config(struct roots_config *config, void cursor_load_config(struct roots_config *config,

@ -27,7 +27,7 @@ struct roots_xdg_surface_v6 {
struct wl_listener request_show_window_menu; struct wl_listener request_show_window_menu;
}; };
struct roots_x11_surface { struct roots_xwayland_surface {
struct roots_view *view; struct roots_view *view;
// TODO: Maybe destroy listener should go in roots_view // TODO: Maybe destroy listener should go in roots_view
struct wl_listener destroy; struct wl_listener destroy;
@ -48,12 +48,12 @@ struct roots_view {
union { union {
struct wlr_wl_shell_surface *wl_shell_surface; struct wlr_wl_shell_surface *wl_shell_surface;
struct wlr_xdg_surface_v6 *xdg_surface_v6; struct wlr_xdg_surface_v6 *xdg_surface_v6;
struct wlr_x11_window *x11_window; struct wlr_xwayland_surface *xwayland_surface;
}; };
union { union {
struct roots_wl_shell_surface *roots_wl_shell_surface; struct roots_wl_shell_surface *roots_wl_shell_surface;
struct roots_xdg_surface_v6 *roots_xdg_surface_v6; struct roots_xdg_surface_v6 *roots_xdg_surface_v6;
struct roots_x11_surface *roots_x11_surface; struct roots_xwayland_surface *roots_xwayland_surface;
}; };
struct wlr_surface *wlr_surface; struct wlr_surface *wlr_surface;
struct wl_list link; struct wl_list link;

@ -20,7 +20,7 @@ struct wlr_xwayland {
struct wl_event_source *sigusr1_source; struct wl_event_source *sigusr1_source;
struct wl_listener destroy_listener; struct wl_listener destroy_listener;
struct wlr_xwm *xwm; struct wlr_xwm *xwm;
struct wl_list displayable_windows; struct wl_list displayable_surfaces;
struct { struct {
struct wl_signal new_surface; struct wl_signal new_surface;
@ -29,7 +29,7 @@ struct wlr_xwayland {
void *data; void *data;
}; };
struct wlr_x11_window { struct wlr_xwayland_surface {
xcb_window_t window_id; xcb_window_t window_id;
uint32_t surface_id; uint32_t surface_id;
struct wl_list link; struct wl_list link;
@ -50,7 +50,7 @@ struct wlr_x11_window {
void wlr_xwayland_destroy(struct wlr_xwayland *wlr_xwayland); void wlr_xwayland_destroy(struct wlr_xwayland *wlr_xwayland);
struct wlr_xwayland *wlr_xwayland_create(struct wl_display *wl_display, struct wlr_xwayland *wlr_xwayland_create(struct wl_display *wl_display,
struct wlr_compositor *compositor); struct wlr_compositor *compositor);
void wlr_x11_window_activate(struct wlr_xwayland *wlr_xwayland, void wlr_xwayland_surface_activate(struct wlr_xwayland *wlr_xwayland,
struct wlr_x11_window *window); struct wlr_xwayland_surface *surface);
#endif #endif

@ -52,10 +52,10 @@ static void input_remove_notify(struct wl_listener *listener, void *data) {
struct roots_input *input = wl_container_of(listener, input, input_remove); struct roots_input *input = wl_container_of(listener, input, input_remove);
switch (device->type) { switch (device->type) {
case WLR_INPUT_DEVICE_KEYBOARD: case WLR_INPUT_DEVICE_KEYBOARD:
//keyboard_remove(device, input); keyboard_remove(device, input);
break; break;
case WLR_INPUT_DEVICE_POINTER: case WLR_INPUT_DEVICE_POINTER:
//pointer_remove(device, input); pointer_remove(device, input);
break; break;
case WLR_INPUT_DEVICE_TOUCH: case WLR_INPUT_DEVICE_TOUCH:
//touch_remove(device, input); //touch_remove(device, input);

@ -42,6 +42,7 @@ static void keyboard_key_notify(struct wl_listener *listener, void *data) {
void keyboard_add(struct wlr_input_device *device, struct roots_input *input) { void keyboard_add(struct wlr_input_device *device, struct roots_input *input) {
struct roots_keyboard *keyboard = calloc(sizeof(struct roots_keyboard), 1); struct roots_keyboard *keyboard = calloc(sizeof(struct roots_keyboard), 1);
device->data = keyboard;
keyboard->device = device; keyboard->device = device;
keyboard->input = input; keyboard->input = input;
wl_list_init(&keyboard->key.link); wl_list_init(&keyboard->key.link);
@ -64,3 +65,11 @@ void keyboard_add(struct wlr_input_device *device, struct roots_input *input) {
xkb_context_unref(context); xkb_context_unref(context);
wlr_seat_attach_keyboard(input->wl_seat, device); wlr_seat_attach_keyboard(input->wl_seat, device);
} }
void keyboard_remove(struct wlr_input_device *device, struct roots_input *input) {
struct roots_keyboard *keyboard = device->data;
wlr_seat_detach_keyboard(input->wl_seat, device->keyboard);
wl_list_remove(&keyboard->key.link);
wl_list_remove(&keyboard->link);
free(keyboard);
}

@ -6,6 +6,7 @@
void pointer_add(struct wlr_input_device *device, struct roots_input *input) { void pointer_add(struct wlr_input_device *device, struct roots_input *input) {
struct roots_pointer *pointer = calloc(sizeof(struct roots_pointer), 1); struct roots_pointer *pointer = calloc(sizeof(struct roots_pointer), 1);
device->data = pointer;
pointer->device = device; pointer->device = device;
pointer->input = input; pointer->input = input;
wl_list_insert(&input->pointers, &pointer->link); wl_list_insert(&input->pointers, &pointer->link);
@ -13,3 +14,10 @@ void pointer_add(struct wlr_input_device *device, struct roots_input *input) {
cursor_load_config(input->server->config, input->cursor, cursor_load_config(input->server->config, input->cursor,
input, input->server->desktop); input, input->server->desktop);
} }
void pointer_remove(struct wlr_input_device *device, struct roots_input *input) {
struct roots_pointer *pointer = device->data;
wlr_cursor_detach_input_device(input->cursor, device);
wl_list_remove(&pointer->link);
free(pointer);
}

@ -10,7 +10,7 @@
#include "rootston/server.h" #include "rootston/server.h"
static void handle_destroy(struct wl_listener *listener, void *data) { static void handle_destroy(struct wl_listener *listener, void *data) {
struct roots_wl_shell_surface *roots_surface = struct roots_xwayland_surface *roots_surface =
wl_container_of(listener, roots_surface, destroy); wl_container_of(listener, roots_surface, destroy);
wl_list_remove(&roots_surface->destroy.link); wl_list_remove(&roots_surface->destroy.link);
view_destroy(roots_surface->view); view_destroy(roots_surface->view);
@ -18,19 +18,20 @@ static void handle_destroy(struct wl_listener *listener, void *data) {
} }
static void x11_activate(struct roots_view *view, bool active) { static void x11_activate(struct roots_view *view, bool active) {
wlr_x11_window_activate(view->desktop->xwayland, view->x11_window); wlr_xwayland_surface_activate(view->desktop->xwayland,
view->xwayland_surface);
} }
void handle_xwayland_surface(struct wl_listener *listener, void *data) { void handle_xwayland_surface(struct wl_listener *listener, void *data) {
struct roots_desktop *desktop = struct roots_desktop *desktop =
wl_container_of(listener, desktop, xwayland_surface); wl_container_of(listener, desktop, xwayland_surface);
struct wlr_x11_window *surface = data; struct wlr_xwayland_surface *surface = data;
// TODO: get and log title, class, etc // TODO: get and log title, class, etc
wlr_log(L_DEBUG, "new xwayland surface"); wlr_log(L_DEBUG, "new xwayland surface");
struct roots_x11_surface *roots_surface = struct roots_xwayland_surface *roots_surface =
calloc(1, sizeof(struct roots_wl_shell_surface)); calloc(1, sizeof(struct roots_xwayland_surface));
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);
@ -38,8 +39,8 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) {
struct roots_view *view = calloc(1, sizeof(struct roots_view)); struct roots_view *view = calloc(1, sizeof(struct roots_view));
view->type = ROOTS_XWAYLAND_VIEW; view->type = ROOTS_XWAYLAND_VIEW;
view->x = view->y = 200; view->x = view->y = 200;
view->x11_window = surface; view->xwayland_surface = surface;
view->roots_x11_surface = roots_surface; view->roots_xwayland_surface = roots_surface;
view->wlr_surface = surface->surface; view->wlr_surface = surface->surface;
view->desktop = desktop; view->desktop = desktop;
view->activate = x11_activate; view->activate = x11_activate;

@ -193,7 +193,7 @@ static bool wlr_xwayland_init(struct wlr_xwayland *wlr_xwayland,
wlr_xwayland->x_fd[0] = wlr_xwayland->x_fd[1] = -1; wlr_xwayland->x_fd[0] = wlr_xwayland->x_fd[1] = -1;
wlr_xwayland->wl_fd[0] = wlr_xwayland->wl_fd[1] = -1; wlr_xwayland->wl_fd[0] = wlr_xwayland->wl_fd[1] = -1;
wlr_xwayland->wm_fd[0] = wlr_xwayland->wm_fd[1] = -1; wlr_xwayland->wm_fd[0] = wlr_xwayland->wm_fd[1] = -1;
wl_list_init(&wlr_xwayland->displayable_windows); wl_list_init(&wlr_xwayland->displayable_surfaces);
wl_signal_init(&wlr_xwayland->events.new_surface); wl_signal_init(&wlr_xwayland->events.new_surface);
wlr_xwayland->display = open_display_sockets(wlr_xwayland->x_fd); wlr_xwayland->display = open_display_sockets(wlr_xwayland->x_fd);

@ -5,53 +5,64 @@
#include "wlr/xwayland.h" #include "wlr/xwayland.h"
#include "xwm.h" #include "xwm.h"
const char *atom_map[ATOM_LAST] = {
"WL_SURFACE_ID",
"WM_PROTOCOLS",
"WM_S0",
"_NET_SUPPORTED",
"_NET_WM_S0",
"_NET_WM_STATE",
"WM_TAKE_FOCUS",
};
/* General helpers */ /* General helpers */
// TODO: replace this with hash table? // TODO: replace this with hash table?
static struct wlr_x11_window *lookup_window(struct wl_list *list, xcb_window_t window_id) { static struct wlr_xwayland_surface *lookup_surface(struct wl_list *list,
struct wlr_x11_window *window; xcb_window_t window_id) {
wl_list_for_each(window, list, link) { struct wlr_xwayland_surface *surface;
if (window->window_id == window_id) { wl_list_for_each(surface, list, link) {
return window; if (surface->window_id == window_id) {
return surface;
} }
} }
return NULL; return NULL;
} }
static struct wlr_x11_window *lookup_window_any(struct wlr_xwm *xwm, xcb_window_t window_id) { static struct wlr_xwayland_surface *lookup_surface_any(struct wlr_xwm *xwm,
struct wlr_x11_window *window; xcb_window_t window_id) {
if ((window = lookup_window(&xwm->xwayland->displayable_windows, window_id)) || struct wlr_xwayland_surface *surface;
(window = lookup_window(&xwm->unpaired_windows, window_id)) || if ((surface = lookup_surface(&xwm->xwayland->displayable_surfaces, window_id)) ||
(window = lookup_window(&xwm->new_windows, window_id))) { (surface = lookup_surface(&xwm->unpaired_surfaces, window_id)) ||
return window; (surface = lookup_surface(&xwm->new_surfaces, window_id))) {
return surface;
} }
return NULL; return NULL;
} }
static struct wlr_x11_window *wlr_x11_window_create(struct wlr_xwm *xwm, static struct wlr_xwayland_surface *wlr_xwayland_surface_create(
xcb_window_t window_id, int16_t x, int16_t y, struct wlr_xwm *xwm, xcb_window_t window_id, int16_t x, int16_t y,
uint16_t width, uint16_t height, bool override_redirect) { uint16_t width, uint16_t height, bool override_redirect) {
struct wlr_x11_window *window; struct wlr_xwayland_surface *surface =
calloc(1, sizeof(struct wlr_xwayland_surface));
window = calloc(1, sizeof(struct wlr_x11_window)); if (!surface) {
if (!window) { wlr_log(L_ERROR, "Could not allocate wlr xwayland surface");
wlr_log(L_ERROR, "Could not allocate wlr x11 window");
return NULL; return NULL;
} }
window->window_id = window_id; surface->window_id = window_id;
window->x = x; surface->x = x;
window->y = y; surface->y = y;
window->width = width; surface->width = width;
window->height = height; surface->height = height;
window->override_redirect = override_redirect; surface->override_redirect = override_redirect;
wl_list_insert(&xwm->new_windows, &window->link); wl_list_insert(&xwm->new_surfaces, &surface->link);
wl_signal_init(&window->events.destroy); wl_signal_init(&surface->events.destroy);
return window; return surface;
} }
static void wlr_x11_window_destroy(struct wlr_x11_window *window) { static void wlr_xwayland_surface_destroy(struct wlr_xwayland_surface *surface) {
wl_signal_emit(&window->events.destroy, window); wl_signal_emit(&surface->events.destroy, surface);
wl_list_remove(&window->link); wl_list_remove(&surface->link);
free(window); free(surface);
} }
/* xcb helpers */ /* xcb helpers */
@ -69,106 +80,117 @@ static bool xcb_call(struct wlr_xwm *xwm, const char *func, uint32_t line,
return false; return false;
} }
static void map_shell_surface(struct wlr_xwm *xwm, struct wlr_x11_window *window, static void map_shell_surface(struct wlr_xwm *xwm,
struct wlr_xwayland_surface *xwayland_surface,
struct wlr_surface *surface) { struct wlr_surface *surface) {
// get xcb geometry for depth = alpha channel // get xcb geometry for depth = alpha channel
window->surface = surface; xwayland_surface->surface = surface;
wl_list_remove(&window->link); wl_list_remove(&xwayland_surface->link);
wl_list_insert(&xwm->xwayland->displayable_windows, &window->link); wl_list_insert(&xwm->xwayland->displayable_surfaces,
wl_signal_emit(&xwm->xwayland->events.new_surface, window); &xwayland_surface->link);
wl_signal_emit(&xwm->xwayland->events.new_surface, xwayland_surface);
} }
/* xcb event handlers */ /* xcb event handlers */
static void handle_create_notify(struct wlr_xwm *xwm, xcb_create_notify_event_t *ev) { static void handle_create_notify(struct wlr_xwm *xwm,
xcb_create_notify_event_t *ev) {
wlr_log(L_DEBUG, "XCB_CREATE_NOTIFY (%u)", ev->window); wlr_log(L_DEBUG, "XCB_CREATE_NOTIFY (%u)", ev->window);
wlr_x11_window_create(xwm, ev->window, ev->x, ev->y, wlr_xwayland_surface_create(xwm, ev->window, ev->x, ev->y,
ev->width, ev->height, ev->override_redirect); ev->width, ev->height, ev->override_redirect);
} }
static void handle_destroy_notify(struct wlr_xwm *xwm, xcb_destroy_notify_event_t *ev) { static void handle_destroy_notify(struct wlr_xwm *xwm,
struct wlr_x11_window *window; xcb_destroy_notify_event_t *ev) {
wlr_log(L_DEBUG, "XCB_DESTROY_NOTIFY (%u)", ev->window); wlr_log(L_DEBUG, "XCB_DESTROY_NOTIFY (%u)", ev->window);
if (!(window = lookup_window_any(xwm, ev->window))) { struct wlr_xwayland_surface *surface = lookup_surface_any(xwm, ev->window);
if (surface == NULL) {
return; return;
} }
wlr_x11_window_destroy(window); wlr_xwayland_surface_destroy(surface);
} }
static void handle_configure_request(struct wlr_xwm *xwm, xcb_configure_request_event_t *ev) { static void handle_configure_request(struct wlr_xwm *xwm,
struct wlr_x11_window *window; xcb_configure_request_event_t *ev) {
wlr_log(L_DEBUG, "XCB_CONFIGURE_REQUEST (%u) [%ux%u+%d,%d]", ev->window, wlr_log(L_DEBUG, "XCB_CONFIGURE_REQUEST (%u) [%ux%u+%d,%d]", ev->window,
ev->width, ev->height, ev->x, ev->y); ev->width, ev->height, ev->x, ev->y);
if (!(window = lookup_window_any(xwm, ev->window))) { struct wlr_xwayland_surface *surface = lookup_surface_any(xwm, ev->window);
if (surface == NULL) {
return; return;
} }
window->x = ev->x; surface->x = ev->x;
window->y = ev->y; surface->y = ev->y;
window->width = ev->width; surface->width = ev->width;
window->height = ev->height; surface->height = ev->height;
// handle parent/sibling? // handle parent/sibling?
uint32_t values[] = { ev->x, ev->y, ev->width, ev->height, 0 }; uint32_t values[] = {ev->x, ev->y, ev->width, ev->height, 0};
uint32_t mask = XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y | uint32_t mask = XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y |
XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT | XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT |
XCB_CONFIG_WINDOW_BORDER_WIDTH; XCB_CONFIG_WINDOW_BORDER_WIDTH;
xcb_configure_window(xwm->xcb_conn, ev->window, mask, values); xcb_configure_window(xwm->xcb_conn, ev->window, mask, values);
} }
static void handle_map_request(struct wlr_xwm *xwm, xcb_map_request_event_t *ev) { static void handle_map_request(struct wlr_xwm *xwm,
xcb_map_request_event_t *ev) {
wlr_log(L_DEBUG, "XCB_MAP_REQUEST (%u)", ev->window); wlr_log(L_DEBUG, "XCB_MAP_REQUEST (%u)", ev->window);
const uint32_t value_list = XCB_EVENT_MASK_FOCUS_CHANGE |
XCB_EVENT_MASK_PROPERTY_CHANGE;
XCB_CALL(xwm, xcb_change_window_attributes_checked(xwm->xcb_conn, XCB_CALL(xwm, xcb_change_window_attributes_checked(xwm->xcb_conn,
ev->window, XCB_CW_EVENT_MASK, ev->window, XCB_CW_EVENT_MASK, &value_list));
&(uint32_t){XCB_EVENT_MASK_FOCUS_CHANGE | XCB_EVENT_MASK_PROPERTY_CHANGE}));
XCB_CALL(xwm, xcb_map_window_checked(xwm->xcb_conn, ev->window)); XCB_CALL(xwm, xcb_map_window_checked(xwm->xcb_conn, ev->window));
} }
static void handle_map_notify(struct wlr_xwm *xwm, xcb_map_notify_event_t *ev) { static void handle_map_notify(struct wlr_xwm *xwm, xcb_map_notify_event_t *ev) {
struct wlr_x11_window *window;
wlr_log(L_DEBUG, "XCB_MAP_NOTIFY (%u)", ev->window); wlr_log(L_DEBUG, "XCB_MAP_NOTIFY (%u)", ev->window);
if ((window = lookup_window_any(xwm, ev->window))) { struct wlr_xwayland_surface *surface = lookup_surface_any(xwm, ev->window);
window->override_redirect = ev->override_redirect; if (surface != NULL) {
surface->override_redirect = ev->override_redirect;
} else { } else {
wlr_x11_window_create(xwm, ev->window, 0, 0, 1, 1, ev->override_redirect); wlr_xwayland_surface_create(xwm, ev->window, 0, 0, 1, 1,
ev->override_redirect);
} }
} }
static void handle_unmap_notify(struct wlr_xwm *xwm, xcb_unmap_notify_event_t *ev) { static void handle_unmap_notify(struct wlr_xwm *xwm,
struct wlr_x11_window *window; xcb_unmap_notify_event_t *ev) {
wlr_log(L_DEBUG, "XCB_UNMAP_NOTIFY (%u)", ev->window); wlr_log(L_DEBUG, "XCB_UNMAP_NOTIFY (%u)", ev->window);
if (!(window = lookup_window_any(xwm, ev->window))) { struct wlr_xwayland_surface *surface = lookup_surface_any(xwm, ev->window);
if (surface == NULL) {
return; return;
} }
// remove pointer to surface only? // TODO: remove pointer to surface only?
wlr_x11_window_destroy(window); wlr_xwayland_surface_destroy(surface);
} }
static void handle_property_notify(struct wlr_xwm *xwm, xcb_property_notify_event_t *ev) { 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); wlr_log(L_DEBUG, "XCB_PROPERTY_NOTIFY (%u)", ev->window);
// TODO lookup window & get properties // TODO lookup window & get properties
} }
static void handle_client_message(struct wlr_xwm *xwm, xcb_client_message_event_t *ev) { static void handle_client_message(struct wlr_xwm *xwm,
xcb_client_message_event_t *ev) {
wlr_log(L_DEBUG, "XCB_CLIENT_MESSAGE (%u)", ev->window); wlr_log(L_DEBUG, "XCB_CLIENT_MESSAGE (%u)", ev->window);
if (ev->type == xwm->atoms[WL_SURFACE_ID]) { if (ev->type == xwm->atoms[WL_SURFACE_ID]) {
struct wlr_x11_window *window; struct wlr_xwayland_surface *surface = lookup_surface(
struct wl_resource *resource; &xwm->new_surfaces, ev->window);
window = lookup_window(&xwm->new_windows, ev->window); if (surface == NULL) {
if (!window) {
wlr_log(L_DEBUG, "client message WL_SURFACE_ID but no new window %u ?", wlr_log(L_DEBUG, "client message WL_SURFACE_ID but no new window %u ?",
ev->window); ev->window);
return; return;
} }
window->surface_id = ev->data.data32[0]; surface->surface_id = ev->data.data32[0];
/* Check if we got notified after wayland surface create event */ /* Check if we got notified after wayland surface create event */
resource = wl_client_get_object(xwm->xwayland->client, window->surface_id); struct wl_resource *resource = wl_client_get_object(
xwm->xwayland->client, surface->surface_id);
if (resource) { if (resource) {
map_shell_surface(xwm, window, wl_resource_get_user_data(resource)); map_shell_surface(xwm, surface, wl_resource_get_user_data(resource));
} else { } else {
wl_list_remove(&window->link); wl_list_remove(&surface->link);
wl_list_insert(&xwm->unpaired_windows, &window->link); wl_list_insert(&xwm->unpaired_surfaces, &surface->link);
} }
} }
wlr_log(L_DEBUG, "unhandled client message %u", ev->type); wlr_log(L_DEBUG, "unhandled client message %u", ev->type);
@ -224,20 +246,19 @@ static int x11_event_handler(int fd, uint32_t mask, void *data) {
static void create_surface_handler(struct wl_listener *listener, void *data) { static void create_surface_handler(struct wl_listener *listener, void *data) {
struct wlr_surface *surface = 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,
struct wlr_x11_window *window; surface_create_listener);
uint32_t surface_id;
if (wl_resource_get_client(surface->resource) != xwm->xwayland->client) { if (wl_resource_get_client(surface->resource) != xwm->xwayland->client) {
return; return;
} }
wlr_log(L_DEBUG, "New x11 surface: %p", surface); wlr_log(L_DEBUG, "New x11 surface: %p", surface);
surface_id = wl_resource_get_id(surface->resource); uint32_t surface_id = wl_resource_get_id(surface->resource);
wl_list_for_each(window, &xwm->unpaired_windows, link) { struct wlr_xwayland_surface *xwayland_surface;
if (window->surface_id == surface_id) { wl_list_for_each(xwayland_surface, &xwm->unpaired_surfaces, link) {
map_shell_surface(xwm, window, surface); if (xwayland_surface->surface_id == surface_id) {
map_shell_surface(xwm, xwayland_surface, surface);
xcb_flush(xwm->xcb_conn); xcb_flush(xwm->xcb_conn);
return; return;
} }
@ -273,8 +294,8 @@ static void xcb_get_resources(struct wlr_xwm *xwm) {
} }
static void xcb_init_wm(struct wlr_xwm *xwm) { static void xcb_init_wm(struct wlr_xwm *xwm) {
xcb_screen_iterator_t screen_iterator; xcb_screen_iterator_t screen_iterator =
screen_iterator = xcb_setup_roots_iterator(xcb_get_setup(xwm->xcb_conn)); xcb_setup_roots_iterator(xcb_get_setup(xwm->xcb_conn));
xwm->screen = screen_iterator.data; xwm->screen = screen_iterator.data;
xwm->window = xcb_generate_id(xwm->xcb_conn); xwm->window = xcb_generate_id(xwm->xcb_conn);
@ -285,8 +306,8 @@ static void xcb_init_wm(struct wlr_xwm *xwm) {
XCB_EVENT_MASK_PROPERTY_CHANGE, XCB_EVENT_MASK_PROPERTY_CHANGE,
/* xwm->cursor, */ /* xwm->cursor, */
}; };
XCB_CALL(xwm, xcb_change_window_attributes_checked(xwm->xcb_conn, xwm->screen->root, XCB_CALL(xwm, xcb_change_window_attributes_checked(xwm->xcb_conn,
XCB_CW_EVENT_MASK /* | XCB_CW_CURSOR */, values)); xwm->screen->root, XCB_CW_EVENT_MASK /* | XCB_CW_CURSOR */, values));
XCB_CALL(xwm, xcb_composite_redirect_subwindows_checked(xwm->xcb_conn, XCB_CALL(xwm, xcb_composite_redirect_subwindows_checked(xwm->xcb_conn,
xwm->screen->root, XCB_COMPOSITE_REDIRECT_MANUAL)); xwm->screen->root, XCB_COMPOSITE_REDIRECT_MANUAL));
@ -297,9 +318,9 @@ static void xcb_init_wm(struct wlr_xwm *xwm) {
xcb_atom_t supported[] = { xcb_atom_t supported[] = {
xwm->atoms[NET_WM_STATE], xwm->atoms[NET_WM_STATE],
}; };
XCB_CALL(xwm, xcb_change_property_checked(xwm->xcb_conn, XCB_PROP_MODE_REPLACE, XCB_CALL(xwm, xcb_change_property_checked(xwm->xcb_conn,
xwm->screen->root, xwm->atoms[NET_SUPPORTED], XCB_ATOM_ATOM, XCB_PROP_MODE_REPLACE, xwm->screen->root, xwm->atoms[NET_SUPPORTED],
32, sizeof(supported)/sizeof(*supported), supported)); XCB_ATOM_ATOM, 32, sizeof(supported)/sizeof(*supported), supported));
XCB_CALL(xwm, xcb_set_selection_owner_checked(xwm->xcb_conn, xwm->window, XCB_CALL(xwm, xcb_set_selection_owner_checked(xwm->xcb_conn, xwm->window,
xwm->atoms[WM_S0], XCB_CURRENT_TIME)); xwm->atoms[WM_S0], XCB_CURRENT_TIME));
@ -308,21 +329,21 @@ static void xcb_init_wm(struct wlr_xwm *xwm) {
xcb_flush(xwm->xcb_conn); xcb_flush(xwm->xcb_conn);
} }
void wlr_x11_window_activate(struct wlr_xwayland *wlr_xwayland, void wlr_xwayland_surface_activate(struct wlr_xwayland *wlr_xwayland,
struct wlr_x11_window *window) { struct wlr_xwayland_surface *surface) {
struct wlr_xwm *xwm = wlr_xwayland->xwm; struct wlr_xwm *xwm = wlr_xwayland->xwm;
xcb_client_message_event_t m = {0}; xcb_client_message_event_t m = {0};
m.response_type = XCB_CLIENT_MESSAGE; m.response_type = XCB_CLIENT_MESSAGE;
m.format = 32; m.format = 32;
m.window = window->window_id; m.window = surface->window_id;
m.type = xwm->atoms[WM_PROTOCOLS]; m.type = xwm->atoms[WM_PROTOCOLS];
m.data.data32[0] = xwm->atoms[WM_TAKE_FOCUS]; m.data.data32[0] = xwm->atoms[WM_TAKE_FOCUS];
m.data.data32[1] = XCB_TIME_CURRENT_TIME; m.data.data32[1] = XCB_TIME_CURRENT_TIME;
xcb_send_event_checked(xwm->xcb_conn, 0, window->window_id, xcb_send_event_checked(xwm->xcb_conn, 0, surface->window_id,
XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT, (char*)&m); XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT, (char*)&m);
xcb_set_input_focus_checked(xwm->xcb_conn, XCB_INPUT_FOCUS_POINTER_ROOT, xcb_set_input_focus_checked(xwm->xcb_conn, XCB_INPUT_FOCUS_POINTER_ROOT,
window->window_id, XCB_CURRENT_TIME); surface->window_id, XCB_CURRENT_TIME);
xcb_configure_window_checked(xwm->xcb_conn, window->window_id, xcb_configure_window_checked(xwm->xcb_conn, surface->window_id,
XCB_CONFIG_WINDOW_STACK_MODE, (uint32_t[]){XCB_STACK_MODE_ABOVE}); XCB_CONFIG_WINDOW_STACK_MODE, (uint32_t[]){XCB_STACK_MODE_ABOVE});
xcb_flush(xwm->xcb_conn); xcb_flush(xwm->xcb_conn);
} }
@ -334,15 +355,16 @@ void xwm_destroy(struct wlr_xwm *xwm) {
if (xwm->event_source) { if (xwm->event_source) {
wl_event_source_remove(xwm->event_source); wl_event_source_remove(xwm->event_source);
} }
struct wlr_x11_window *window, *tmp; struct wlr_xwayland_surface *surface, *tmp;
wl_list_for_each_safe(window, tmp, &xwm->xwayland->displayable_windows, link) { wl_list_for_each_safe(surface, tmp, &xwm->xwayland->displayable_surfaces,
wlr_x11_window_destroy(window); link) {
wlr_xwayland_surface_destroy(surface);
} }
wl_list_for_each_safe(window, tmp, &xwm->new_windows, link) { wl_list_for_each_safe(surface, tmp, &xwm->new_surfaces, link) {
wlr_x11_window_destroy(window); wlr_xwayland_surface_destroy(surface);
} }
wl_list_for_each_safe(window, tmp, &xwm->unpaired_windows, link) { wl_list_for_each_safe(surface, tmp, &xwm->unpaired_surfaces, link) {
wlr_x11_window_destroy(window); wlr_xwayland_surface_destroy(surface);
} }
wl_list_remove(&xwm->surface_create_listener.link); wl_list_remove(&xwm->surface_create_listener.link);
xcb_disconnect(xwm->xcb_conn); xcb_disconnect(xwm->xcb_conn);
@ -352,20 +374,25 @@ void xwm_destroy(struct wlr_xwm *xwm) {
struct wlr_xwm *xwm_create(struct wlr_xwayland *wlr_xwayland) { struct wlr_xwm *xwm_create(struct wlr_xwayland *wlr_xwayland) {
struct wlr_xwm *xwm = calloc(1, sizeof(struct wlr_xwm)); struct wlr_xwm *xwm = calloc(1, sizeof(struct wlr_xwm));
int rc; if (xwm == NULL) {
return NULL;
}
xwm->xwayland = wlr_xwayland; xwm->xwayland = wlr_xwayland;
wl_list_init(&xwm->new_windows); wl_list_init(&xwm->new_surfaces);
wl_list_init(&xwm->unpaired_windows); wl_list_init(&xwm->unpaired_surfaces);
xwm->xcb_conn = xcb_connect_to_fd(wlr_xwayland->wm_fd[0], NULL); xwm->xcb_conn = xcb_connect_to_fd(wlr_xwayland->wm_fd[0], NULL);
if ((rc = xcb_connection_has_error(xwm->xcb_conn))) {
int rc = xcb_connection_has_error(xwm->xcb_conn);
if (rc) {
wlr_log(L_ERROR, "xcb connect failed: %d", rc); wlr_log(L_ERROR, "xcb connect failed: %d", rc);
free(xwm); free(xwm);
return NULL; return NULL;
} }
struct wl_event_loop *event_loop = wl_display_get_event_loop(wlr_xwayland->wl_display); struct wl_event_loop *event_loop = wl_display_get_event_loop(
wlr_xwayland->wl_display);
xwm->event_source = wl_event_loop_add_fd(event_loop, wlr_xwayland->wm_fd[0], xwm->event_source = wl_event_loop_add_fd(event_loop, wlr_xwayland->wm_fd[0],
WL_EVENT_READABLE, x11_event_handler, xwm); WL_EVENT_READABLE, x11_event_handler, xwm);
// probably not needed // probably not needed

@ -56,14 +56,7 @@ enum atom_name {
ATOM_LAST, ATOM_LAST,
}; };
static const char * const atom_map[ATOM_LAST] = { extern const char *atom_map[ATOM_LAST];
"WL_SURFACE_ID",
"WM_PROTOCOLS",
"WM_S0",
"_NET_SUPPORTED",
"_NET_WM_S0",
"_NET_WM_STATE",
};
struct wlr_xwm { struct wlr_xwm {
struct wlr_xwayland *xwayland; struct wlr_xwayland *xwayland;
@ -75,8 +68,8 @@ struct wlr_xwm {
xcb_screen_t *screen; xcb_screen_t *screen;
xcb_window_t window; xcb_window_t window;
struct wl_list new_windows; struct wl_list new_surfaces;
struct wl_list unpaired_windows; struct wl_list unpaired_surfaces;
}; };
void xwm_destroy(struct wlr_xwm *xwm); void xwm_destroy(struct wlr_xwm *xwm);

Loading…
Cancel
Save