diff --git a/include/slurp.h b/include/slurp.h index 4e05b10..92e37a9 100644 --- a/include/slurp.h +++ b/include/slurp.h @@ -52,6 +52,9 @@ struct slurp_output { int32_t width, height; struct pool_buffer buffers[2]; struct pool_buffer *current_buffer; + + struct wl_cursor_theme *cursor_theme; + struct wl_cursor_image *cursor_image; }; struct slurp_pointer { @@ -63,6 +66,8 @@ struct slurp_pointer { int32_t pressed_x, pressed_y; enum wl_pointer_button_state button_state; struct slurp_output *current_output; + + struct wl_surface *cursor_surface; }; void pointer_get_box(struct slurp_pointer *pointer, int *x, int *y, diff --git a/main.c b/main.c index e65f3a6..cebe49c 100644 --- a/main.c +++ b/main.c @@ -1,9 +1,11 @@ #define _POSIX_C_SOURCE 2 +#include #include #include #include #include #include +#include #ifdef __linux__ #include #elif __FreeBSD__ @@ -37,6 +39,14 @@ static void pointer_handle_enter(void *data, struct wl_pointer *wl_pointer, // TODO: handle multiple overlapping outputs pointer->current_output = output; + + wl_surface_set_buffer_scale(pointer->cursor_surface, output->scale); + wl_surface_attach(pointer->cursor_surface, + wl_cursor_image_get_buffer(output->cursor_image), 0, 0); + wl_pointer_set_cursor(wl_pointer, serial, pointer->cursor_surface, + output->cursor_image->hotspot_x / output->scale, + output->cursor_image->hotspot_y / output->scale); + wl_surface_commit(pointer->cursor_surface); } static void pointer_handle_leave(void *data, struct wl_pointer *wl_pointer, @@ -435,6 +445,20 @@ int main(int argc, char *argv[]) { ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM); zwlr_layer_surface_v1_set_exclusive_zone(output->layer_surface, -1); wl_surface_commit(output->surface); + + output->cursor_theme = + wl_cursor_theme_load(NULL, 24 * output->scale, state.shm); + assert(output->cursor_theme); + struct wl_cursor *cursor = + wl_cursor_theme_get_cursor(output->cursor_theme, "crosshair"); + assert(cursor); + output->cursor_image = cursor->images[0]; + } + + struct slurp_pointer *pointer; + wl_list_for_each(pointer, &state.pointers, link) { + pointer->cursor_surface = + wl_compositor_create_surface(state.compositor); } state.running = true; @@ -442,7 +466,7 @@ int main(int argc, char *argv[]) { // This space intentionally left blank } - struct slurp_pointer *pointer, *pointer_tmp; + struct slurp_pointer *pointer_tmp; wl_list_for_each_safe(pointer, pointer_tmp, &state.pointers, link) { destroy_pointer(pointer); } diff --git a/meson.build b/meson.build index 0a0e4af..d76beb2 100644 --- a/meson.build +++ b/meson.build @@ -17,6 +17,7 @@ slurp_inc = include_directories('include') cairo = dependency('cairo') wayland_client = dependency('wayland-client') +wayland_cursor = dependency('wayland-cursor') wayland_protos = dependency('wayland-protocols', version: '>=1.14') subdir('protocol') @@ -32,6 +33,7 @@ executable( cairo, client_protos, wayland_client, + wayland_cursor, ], include_directories: [slurp_inc], install: true,