diff --git a/include/sway/input/cursor.h b/include/sway/input/cursor.h index 91421964a..aa873f46b 100644 --- a/include/sway/input/cursor.h +++ b/include/sway/input/cursor.h @@ -5,6 +5,7 @@ struct sway_cursor { struct wlr_cursor *cursor; + struct wlr_xcursor_manager *xcursor_manager; struct wl_listener motion; struct wl_listener motion_absolute; diff --git a/include/sway/input/seat.h b/include/sway/input/seat.h index a84b7efd0..f7f8a1bbf 100644 --- a/include/sway/input/seat.h +++ b/include/sway/input/seat.h @@ -18,4 +18,6 @@ void sway_seat_add_device(struct sway_seat *seat, void sway_seat_remove_device(struct sway_seat *seat, struct wlr_input_device *device); +void sway_seat_configure_xcursor(struct sway_seat *seat); + #endif diff --git a/sway/input/seat.c b/sway/input/seat.c index 1a2b728c7..1fd659800 100644 --- a/sway/input/seat.c +++ b/sway/input/seat.c @@ -1,8 +1,10 @@ #define _XOPEN_SOURCE 700 #include +#include #include "sway/input/seat.h" #include "sway/input/cursor.h" #include "sway/input/input-manager.h" +#include "sway/output.h" #include "log.h" struct sway_seat *sway_seat_create(struct wl_display *display, @@ -29,6 +31,8 @@ struct sway_seat *sway_seat_create(struct wl_display *display, WL_SEAT_CAPABILITY_POINTER | WL_SEAT_CAPABILITY_TOUCH); + sway_seat_configure_xcursor(seat); + return seat; } @@ -74,3 +78,37 @@ void sway_seat_remove_device(struct sway_seat *seat, break; } } + +void sway_seat_configure_xcursor(struct sway_seat *seat) { + // TODO configure theme and size + const char *cursor_theme = "default"; + + if (seat->cursor->xcursor_manager) { + wlr_xcursor_manager_destroy(seat->cursor->xcursor_manager); + } + + seat->cursor->xcursor_manager = + wlr_xcursor_manager_create(NULL, 24); + if (sway_assert(seat->cursor->xcursor_manager, + "Cannot create XCursor manager for theme %s", cursor_theme)) { + return; + } + + for (int i = 0; i < root_container.children->length; ++i) { + swayc_t *output_container = root_container.children->items[i]; + struct wlr_output *output = + output_container->sway_output->wlr_output; + bool result = + wlr_xcursor_manager_load(seat->cursor->xcursor_manager, + output->scale); + + sway_assert(result, + "Cannot load xcursor theme for output '%s' with scale %d", + output->name, output->scale); + } + + wlr_xcursor_manager_set_cursor_image(seat->cursor->xcursor_manager, + "left_ptr", seat->cursor->cursor); + wlr_cursor_warp(seat->cursor->cursor, NULL, seat->cursor->cursor->x, + seat->cursor->cursor->y); +}