diff --git a/include/wlr/xwayland.h b/include/wlr/xwayland.h index 2d968133..bea97394 100644 --- a/include/wlr/xwayland.h +++ b/include/wlr/xwayland.h @@ -12,6 +12,7 @@ #endif struct wlr_xwm; +struct wlr_xwayland_cursor; struct wlr_xwayland { pid_t pid; @@ -25,6 +26,7 @@ struct wlr_xwayland { struct wl_event_source *sigusr1_source; struct wl_listener destroy_listener; struct wlr_xwm *xwm; + struct wlr_xwayland_cursor *cursor; struct { struct wl_signal new_surface; @@ -148,6 +150,10 @@ struct wlr_xwayland *wlr_xwayland_create(struct wl_display *wl_display, void wlr_xwayland_destroy(struct wlr_xwayland *wlr_xwayland); +void wlr_xwayland_set_cursor(struct wlr_xwayland *wlr_xwayland, + uint8_t *pixels, uint32_t stride, uint32_t width, uint32_t height, + int32_t hotspot_x, int32_t hotspot_y); + void wlr_xwayland_surface_activate(struct wlr_xwayland *wlr_xwayland, struct wlr_xwayland_surface *surface, bool activated); diff --git a/rootston/input.c b/rootston/input.c index 8109d2b6..5d367a5e 100644 --- a/rootston/input.c +++ b/rootston/input.c @@ -4,6 +4,7 @@ #include #include #include +#include #include "rootston/server.h" #include "rootston/config.h" #include "rootston/input.h" @@ -96,6 +97,14 @@ struct roots_input *input_create(struct roots_server *server, return NULL; } + if (server->desktop->xwayland != NULL) { + struct wlr_xcursor_image *xcursor_image = xcursor->images[0]; + wlr_xwayland_set_cursor(server->desktop->xwayland, + xcursor_image->buffer, xcursor_image->width, xcursor_image->width, + xcursor_image->height, xcursor_image->hotspot_x, + xcursor_image->hotspot_y); + } + input->wl_seat = wlr_seat_create(server->wl_display, "seat0"); if (input->wl_seat == NULL) { wlr_log(L_ERROR, "Cannot create seat"); diff --git a/xwayland/xwayland.c b/xwayland/xwayland.c index 81bac2ce..0452f04c 100644 --- a/xwayland/xwayland.c +++ b/xwayland/xwayland.c @@ -29,6 +29,15 @@ static inline int clearenv(void) { } #endif +struct wlr_xwayland_cursor { + uint8_t *pixels; + uint32_t stride; + uint32_t width; + uint32_t height; + int32_t hotspot_x; + int32_t hotspot_y; +}; + static void safe_close(int fd) { if (fd >= 0) { close(fd); @@ -190,6 +199,14 @@ static int xserver_handle_ready(int signal_number, void *data) { wl_event_source_remove(wlr_xwayland->sigusr1_source); wlr_xwayland->sigusr1_source = NULL; + if (wlr_xwayland->cursor != NULL) { + struct wlr_xwayland_cursor *cur = wlr_xwayland->cursor; + xwm_set_cursor(wlr_xwayland->xwm, cur->pixels, cur->stride, cur->width, + cur->height, cur->hotspot_x, cur->hotspot_y); + free(cur); + wlr_xwayland->cursor = NULL; + } + char display_name[16]; snprintf(display_name, sizeof(display_name), ":%d", wlr_xwayland->display); setenv("DISPLAY", display_name, true); @@ -298,3 +315,26 @@ struct wlr_xwayland *wlr_xwayland_create(struct wl_display *wl_display, free(wlr_xwayland); return NULL; } + +void wlr_xwayland_set_cursor(struct wlr_xwayland *wlr_xwayland, + uint8_t *pixels, uint32_t stride, uint32_t width, uint32_t height, + int32_t hotspot_x, int32_t hotspot_y) { + if (wlr_xwayland->xwm != NULL) { + xwm_set_cursor(wlr_xwayland->xwm, pixels, stride, width, height, + hotspot_x, hotspot_y); + return; + } + + free(wlr_xwayland->cursor); + + wlr_xwayland->cursor = calloc(1, sizeof(struct wlr_xwayland_cursor)); + if (wlr_xwayland->cursor == NULL) { + return; + } + wlr_xwayland->cursor->pixels = pixels; + wlr_xwayland->cursor->stride = stride; + wlr_xwayland->cursor->width = width; + wlr_xwayland->cursor->height = height; + wlr_xwayland->cursor->hotspot_x = hotspot_x; + wlr_xwayland->cursor->hotspot_y = hotspot_y; +} diff --git a/xwayland/xwm.c b/xwayland/xwm.c index 8b94a199..9d6bc347 100644 --- a/xwayland/xwm.c +++ b/xwayland/xwm.c @@ -1194,6 +1194,7 @@ void xwm_set_cursor(struct wlr_xwm *xwm, const uint8_t *pixels, uint32_t stride, xcb_free_cursor(xwm->xcb_conn, xwm->cursor); } + stride *= 4; int depth = 32; xcb_pixmap_t pix = xcb_generate_id(xwm->xcb_conn); @@ -1240,6 +1241,7 @@ void xwm_set_cursor(struct wlr_xwm *xwm, const uint8_t *pixels, uint32_t stride, uint32_t values[] = {xwm->cursor}; xcb_change_window_attributes(xwm->xcb_conn, xwm->screen->root, XCB_CW_CURSOR, values); + xcb_flush(xwm->xcb_conn); } struct wlr_xwm *xwm_create(struct wlr_xwayland *wlr_xwayland) { @@ -1279,16 +1281,6 @@ struct wlr_xwm *xwm_create(struct wlr_xwayland *wlr_xwayland) { xwm_get_resources(xwm); xwm_get_visual_and_colormap(xwm); - // TODO - struct wlr_xcursor_theme *xcursor_theme = - wlr_xcursor_theme_load("default", 16); - struct wlr_xcursor *xcursor = - wlr_xcursor_theme_get_cursor(xcursor_theme, "left_ptr"); - struct wlr_xcursor_image *xcursor_image = xcursor->images[0]; - xwm_set_cursor(xwm, xcursor_image->buffer, 4 * xcursor_image->width, - xcursor_image->width, xcursor_image->height, xcursor_image->hotspot_x, - xcursor_image->hotspot_y); - uint32_t values[] = { XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY | XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT | diff --git a/xwayland/xwm.h b/xwayland/xwm.h index ba1ed3c2..d3911ecd 100644 --- a/xwayland/xwm.h +++ b/xwayland/xwm.h @@ -61,8 +61,11 @@ struct wlr_xwm { struct wl_listener compositor_surface_create; }; -void xwm_destroy(struct wlr_xwm *xwm); - struct wlr_xwm *xwm_create(struct wlr_xwayland *wlr_xwayland); +void xwm_destroy(struct wlr_xwm *xwm); + +void xwm_set_cursor(struct wlr_xwm *xwm, const uint8_t *pixels, uint32_t stride, + uint32_t width, uint32_t height, int32_t hotspot_x, int32_t hotspot_y); + #endif