From 68e408d22646c4d2a093029a907341d2943c5866 Mon Sep 17 00:00:00 2001 From: Nathan Reiner Date: Thu, 13 Apr 2023 17:03:17 +0200 Subject: set cursor position to "text" --- config.mk | 2 +- swt.c | 23 +++++++++++++++++++++++ wayland.h | 6 ++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/config.mk b/config.mk index f92717c..07f35f0 100644 --- a/config.mk +++ b/config.mk @@ -4,5 +4,5 @@ PREFIX = /usr/local XDG_SHELL_CLIENT_PROTOCOL = /usr/share/wayland-protocols/stable/xdg-shell/xdg-shell.xml CFLAGS = -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/harfbuzz -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/sysprof-4 -pthread -DVERSION=\"${VERSION}\" -D_XOPEN_SOURCE=600 -LIBS = -lfreetype -lwayland-client -lrt -lxkbcommon -lm -lgrapheme +LIBS = -lfreetype -lwayland-client -lwayland-cursor -lrt -lxkbcommon -lm -lgrapheme CC=cc diff --git a/swt.c b/swt.c index c05f997..e50fa04 100644 --- a/swt.c +++ b/swt.c @@ -267,6 +267,19 @@ void wdrawline(Line line, int x1, int y1, int x2) { win.fontcache->box.height, colors[line[x].bg] ); + + if (line[x].mode & ATTR_UNDERLINE) { + fprintf(stderr, "DRAWING %c\n", line[x].u); + draw_rect( + win.canvas, + borderpx + x * win.fontcache->box.width, + borderpx + (y1 + 1) * win.fontcache->box.height - 1, + win.fontcache->box.width - 2, + 1, + colors[line[x].fg] + ); + } + draw_char( win.canvas, win.fontcache, @@ -639,6 +652,7 @@ handle_keyboard_event() void pointer_enter(void *data, struct wl_pointer *pointer, uint32_t serial, struct wl_surface *surface, wl_fixed_t x, wl_fixed_t y) { + wl_pointer_set_cursor(client.pointer.pointer, serial, client.pointer.surface, client.pointer.image->hotspot_x, client.pointer.image->hotspot_y); } @@ -651,6 +665,7 @@ pointer_leave(void *data, struct wl_pointer *pointer, uint32_t serial, struct wl void pointer_motion(void *data, struct wl_pointer *pointer, uint32_t time, wl_fixed_t x, wl_fixed_t y) { + wl_surface_commit(client.pointer.surface); } @@ -692,6 +707,14 @@ setup() xdg_toplevel_add_listener(win.surface.toplevel, &toplevel_listener, &win); xdg_toplevel_set_title(win.surface.toplevel, "swt"); wl_surface_commit(win.surface.wl); + + client.pointer.theme = wl_cursor_theme_load(0, 24, client.shm); + client.pointer.cursor = wl_cursor_theme_get_cursor(client.pointer.theme, "text"); + client.pointer.image = client.pointer.cursor->images[0]; + client.pointer.buffer = wl_cursor_image_get_buffer(client.pointer.image); + client.pointer.surface = wl_compositor_create_surface(client.compositor); + wl_surface_attach(client.pointer.surface, client.pointer.buffer, 0, 0); + wl_surface_commit(client.pointer.surface); } diff --git a/wayland.h b/wayland.h index 7cbbc90..d5557a9 100644 --- a/wayland.h +++ b/wayland.h @@ -4,6 +4,7 @@ #include #include #include +#include #include "xdg-shell-client-protocol.h" typedef enum { @@ -51,6 +52,11 @@ typedef struct { } kb; struct { struct wl_pointer *pointer; + struct wl_cursor *cursor; + struct wl_cursor_theme *theme; + struct wl_buffer *buffer; + struct wl_surface *surface; + struct wl_cursor_image *image; struct { uint32_t x; uint32_t y; -- cgit v1.2.3-70-g09d2