text fields: i-beam cursor via W_SetCursorImageFn hook

Implement wl_set_cursor() to forward cursor name strings to the
compositor via a function pointer. Initialize textCursor/defaultCursor/
invisibleCursor in wl_screen_init with xcursor name strings.
This commit is contained in:
lkn 2026-06-23 23:13:06 +02:00
parent 2581233351
commit 7f5dd5f682
2 changed files with 16 additions and 4 deletions

View File

@ -9,6 +9,7 @@
#include "WINGsP.h"
#include <pixman.h>
#include <string.h>
/* Synthetic window IDs for Wayland views (distinct from frame buffer IDs) */
#define WL_VIEW_ID_BASE 0x20000000
@ -44,6 +45,7 @@ void (*W_DragIconHideFn)(void) = NULL;
/* Drag cursor feedback — called during drag loop when the view under the
* cursor changes. accepted=True means the view accepts the drop. */
void (*W_DragCursorFeedbackFn)(Bool accepted) = NULL;
void (*W_SetCursorImageFn)(const char *name) = NULL;
extern void wl_view_destroy_backing_impl(unsigned long id);
@ -165,8 +167,11 @@ void W_UnregisterBacking(WNativeWindow id)
static void *wl_screen_init(W_Screen *scr)
{
(void)scr;
return scr; /* use scr as token */
/* Store cursor names as WMNativeCursor — cast back in wl_set_cursor */
scr->textCursor = (WMNativeCursor)(uintptr_t)"xterm";
scr->defaultCursor = (WMNativeCursor)(uintptr_t)"left_ptr";
scr->invisibleCursor = (WMNativeCursor)(uintptr_t)"none";
return scr;
}
static void wl_screen_fini(void *vctx)
@ -497,8 +502,11 @@ static void wl_set_cursor(void *vctx, W_View *view, WMNativeCursor cursor)
{
(void)vctx;
(void)view;
(void)cursor;
/* WMNativeCursor is managed by wlroots seat */
if (!cursor) return;
if (!W_SetCursorImageFn) return;
const char *name = (const char *)(uintptr_t)cursor;
if (strcmp(name, "none") == 0) name = "default";
W_SetCursorImageFn(name);
}
static void wl_redisplay(void *vctx, W_View *view)

View File

@ -467,6 +467,10 @@ wl_display_open(const char *name)
extern void *W_GetFrameBufImage(unsigned long id);
W_GetFrameBufImageFn = W_GetFrameBufImage;
extern void (*W_SetCursorImageFn)(const char *name);
extern void wl_set_cursor_image(const char *name);
W_SetCursorImageFn = wl_set_cursor_image;
extern int (*W_WLPointerGrabFn)(WNativeWindow, WNativeWindow,
unsigned int, int, int, unsigned long);
extern void (*W_WLPointerUngrabFn)(unsigned long);