Allow querying global cursor position

If a platform implements this, e.g. xeyes can track cursor when the
window is not receiving mouse movement events
This commit is contained in:
2026-06-01 21:32:14 +03:00
parent af2132315d
commit 19f043744a
4 changed files with 32 additions and 4 deletions

View File

@@ -1967,6 +1967,16 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
}
const auto [root_x, root_y] = get_window_position(wid);
int32_t root_cursor_x, root_cursor_y;
if (g_platform_ops.query_pointer)
g_platform_ops.query_pointer(&root_cursor_x, &root_cursor_y);
else
{
root_cursor_x = root_x + window.cursor_x;
root_cursor_y = root_y + window.cursor_y;
}
xQueryPointerReply reply {
.type = X_Reply,
.sameScreen = xTrue,
@@ -1974,10 +1984,10 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
.length = 0,
.root = g_root.windowId,
.child = static_cast<CARD32>(child_wid),
.rootX = static_cast<INT16>(root_x + window.cursor_x),
.rootY = static_cast<INT16>(root_y + window.cursor_y),
.winX = static_cast<INT16>(window.cursor_x),
.winY = static_cast<INT16>(window.cursor_y),
.rootX = static_cast<INT16>(root_cursor_x),
.rootY = static_cast<INT16>(root_cursor_y),
.winX = static_cast<INT16>(root_cursor_x - root_x),
.winY = static_cast<INT16>(root_cursor_y - root_y),
.mask = static_cast<KeyButMask>(g_keymask | g_butmask),
};
TRY(encode(client_info.output_buffer, reply));

View File

@@ -61,6 +61,8 @@ struct PlatformOps
void (*request_fullscreen)(PlatformWindow*, bool fullscreen);
/* Warp pointer */
void (*warp_pointer)(int32_t x, int32_t y, bool relative);
/* Get global position of the pointer */
void (*query_pointer)(int32_t* x, int32_t* y);
/* Create a system cursor */
BAN::ErrorOr<BAN::UniqPtr<PlatformCursor>> (*create_system_cursor)(SystemCursorType);
/* Create cursor from custom bitmap */

View File

@@ -348,6 +348,14 @@ static void sdl3_warp_pointer(int32_t x, int32_t y, bool relative)
SDL_WarpMouseGlobal(x, y);
}
static void sdl3_query_pointer(int32_t* x, int32_t* y)
{
float cx, cy;
SDL_GetGlobalMouseState(&cx, &cy);
*x = cx;
*y = cy;
}
static BAN::ErrorOr<BAN::UniqPtr<PlatformCursor>> sdl3_create_system_cursor(SystemCursorType type)
{
static constexpr SDL_SystemCursor cursor_type_map[] {
@@ -428,6 +436,7 @@ PlatformOps g_platform_ops = {
.request_reposition = sdl3_request_reposition,
.request_fullscreen = sdl3_request_fullscreen,
.warp_pointer = sdl3_warp_pointer,
.query_pointer = sdl3_query_pointer,
.create_system_cursor = sdl3_create_system_cursor,
.create_bitmap_cursor = sdl3_create_bitmap_cursor,
.set_cursor = sdl3_set_cursor,

View File

@@ -154,6 +154,12 @@ static void bananos_warp_pointer(int32_t x, int32_t y, bool relative)
(void)relative;
}
static void bananos_query_pointer(int32_t* x, int32_t* y)
{
(void)x;
(void)y;
}
static BAN::ErrorOr<BAN::UniqPtr<PlatformCursor>> bananos_create_system_cursor(SystemCursorType type)
{
(void)type;
@@ -198,6 +204,7 @@ PlatformOps g_platform_ops = {
.request_reposition = bananos_request_reposition,
.request_fullscreen = bananos_request_fullscreen,
.warp_pointer = bananos_warp_pointer,
.query_pointer = nullptr, /* bananos_query_pointer */
.create_system_cursor = bananos_create_system_cursor,
.create_bitmap_cursor = bananos_create_bitmap_cursor,
.set_cursor = bananos_set_cursor,