cursor shape set correctly

This commit is contained in:
Rakarake 2026-02-07 15:30:56 +01:00
parent 6fe9b8bb2a
commit 57e78e8bde
4 changed files with 88 additions and 1 deletions

View file

@ -117,6 +117,60 @@ static const struct wl_callback_listener wl_surface_frame_listener = {
.done = wl_surface_frame_done,
};
void pointer_enter_handler (
void *data,
struct wl_pointer *pointer,
uint32_t serial,
struct wl_surface *surface,
wl_fixed_t x, wl_fixed_t y )
{
struct client_state *state = data;
wl_pointer_set_cursor(pointer, serial, state->cursor_surface,
state->wl_cursor_image->hotspot_x, state->wl_cursor_image->hotspot_y);
}
void pointer_leave_handler (
void *data,
struct wl_pointer *pointer,
uint32_t serial,
struct wl_surface *surface
) { }
void pointer_motion_handler (
void *data,
struct wl_pointer *pointer,
uint32_t time,
wl_fixed_t x,
wl_fixed_t y
) { }
void pointer_button_handler
(
void *data,
struct wl_pointer *pointer,
uint32_t serial,
uint32_t time,
uint32_t button,
uint32_t state
) { }
void pointer_axis_handler
(
void *data,
struct wl_pointer *pointer,
uint32_t time,
uint32_t axis,
wl_fixed_t value
) { }
const struct wl_pointer_listener wl_pointer_listener = {
.enter = pointer_enter_handler,
.leave = pointer_leave_handler,
.motion = pointer_motion_handler,
.button = pointer_button_handler,
.axis = pointer_axis_handler
};
static void registry_handle_global(
void *data,
struct wl_registry *registry,
@ -135,6 +189,28 @@ static void registry_handle_global(
// Set up wl_surface
//state->wl_surface = wl_compositor_create_surface(state->wl_compositor);
}
if (strcmp(interface, wl_shm_interface.name) == 0) {
state->wl_shm = wl_registry_bind(registry, name,
&wl_shm_interface, 1);
}
if (strcmp(interface, wl_seat_interface.name) == 0) {
state->wl_seat = wl_registry_bind(registry, name,
&wl_seat_interface, 1);
state->wl_pointer = wl_seat_get_pointer(state->wl_seat);
wl_pointer_add_listener(state->wl_pointer, &wl_pointer_listener, state);
struct wl_cursor_theme *cursor_theme =
wl_cursor_theme_load(NULL, 24, state->wl_shm);
struct wl_cursor *cursor =
wl_cursor_theme_get_cursor(cursor_theme, "left_ptr");
state->wl_cursor_image = cursor->images[0];
struct wl_buffer *cursor_buffer =
wl_cursor_image_get_buffer(state->wl_cursor_image);
state->cursor_surface = wl_compositor_create_surface(state->wl_compositor);
wl_surface_attach(state->cursor_surface, cursor_buffer, 0, 0);
wl_surface_commit(state->cursor_surface);
}
if ((strcmp(interface, xdg_wm_base_interface.name) == 0) && (state->output_type == OUTPUT_WINDOW)) {
state->xdg_wm_base = wl_registry_bind(
registry, name, &xdg_wm_base_interface, 1);
@ -339,6 +415,8 @@ void wayland_init(struct client_state *state, int output_type) {
wl_registry_add_listener(state->wl_registry, &wl_registry_listener, state);
wl_display_roundtrip(state->wl_display);
wl_seat_get_pointer(state->wl_seat);
struct surface_list *next = state->surface_list;
while (next != NULL) {
wl_surface_commit(next->data.wl_surface);