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

@ -1,6 +1,6 @@
LIBS=opengl wayland-client egl wayland-egl
CFLAGS+=-g -Wall -Wextra $(shell pkg-config --cflags $(LIBS))
LDLIBS+=$(shell pkg-config --libs $(LIBS))
LDLIBS+=$(shell pkg-config --libs $(LIBS)) -lwayland-cursor
WAYLAND_PROTOCOLS=$(shell pkg-config --variable=pkgdatadir wayland-protocols)
WAYLAND_SCANNER=$(shell pkg-config --variable=wayland_scanner wayland-scanner)

View file

@ -86,6 +86,7 @@ void main() {
vec2 uv = vec2(screen_uv.x, screen_uv.y);
uv.y += sin(uv.x * 2.0 + time * 0.2) * 0.47;
uv.y += sin(uv.x * 4.3 + time * 1.34) * 0.09;
uv += 100.0;
float out_val = perlin_noise(uv, vec2(0.0, 0.0), time / 1.0);
float min = 0.42 + sin(time)/8.0;

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);

View file

@ -1,5 +1,6 @@
#include <EGL/egl.h>
#include <wayland-egl.h>
#include <wayland-cursor.h>
#include "xdg-shell-protocol.h"
#include "wlr-layer-shell-unstable-v1-protocol.h"
@ -45,8 +46,15 @@ struct client_state {
struct wl_display *wl_display;
struct wl_registry *wl_registry;
struct wl_compositor *wl_compositor;
struct wl_shm *wl_shm;
struct xdg_wm_base *xdg_wm_base;
struct zwlr_layer_shell_v1 *zwlr_layer_shell_v1;
struct wl_seat *wl_seat;
struct wl_pointer *wl_pointer;
// Cursor
struct wl_surface *cursor_surface;
struct wl_cursor_image *wl_cursor_image;
struct surface_list *surface_list;
/// Next in queue to check if it wants to be rendered.