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:
@@ -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);
|
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 {
|
xQueryPointerReply reply {
|
||||||
.type = X_Reply,
|
.type = X_Reply,
|
||||||
.sameScreen = xTrue,
|
.sameScreen = xTrue,
|
||||||
@@ -1974,10 +1984,10 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
|
|||||||
.length = 0,
|
.length = 0,
|
||||||
.root = g_root.windowId,
|
.root = g_root.windowId,
|
||||||
.child = static_cast<CARD32>(child_wid),
|
.child = static_cast<CARD32>(child_wid),
|
||||||
.rootX = static_cast<INT16>(root_x + window.cursor_x),
|
.rootX = static_cast<INT16>(root_cursor_x),
|
||||||
.rootY = static_cast<INT16>(root_y + window.cursor_y),
|
.rootY = static_cast<INT16>(root_cursor_y),
|
||||||
.winX = static_cast<INT16>(window.cursor_x),
|
.winX = static_cast<INT16>(root_cursor_x - root_x),
|
||||||
.winY = static_cast<INT16>(window.cursor_y),
|
.winY = static_cast<INT16>(root_cursor_y - root_y),
|
||||||
.mask = static_cast<KeyButMask>(g_keymask | g_butmask),
|
.mask = static_cast<KeyButMask>(g_keymask | g_butmask),
|
||||||
};
|
};
|
||||||
TRY(encode(client_info.output_buffer, reply));
|
TRY(encode(client_info.output_buffer, reply));
|
||||||
|
|||||||
@@ -61,6 +61,8 @@ struct PlatformOps
|
|||||||
void (*request_fullscreen)(PlatformWindow*, bool fullscreen);
|
void (*request_fullscreen)(PlatformWindow*, bool fullscreen);
|
||||||
/* Warp pointer */
|
/* Warp pointer */
|
||||||
void (*warp_pointer)(int32_t x, int32_t y, bool relative);
|
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 */
|
/* Create a system cursor */
|
||||||
BAN::ErrorOr<BAN::UniqPtr<PlatformCursor>> (*create_system_cursor)(SystemCursorType);
|
BAN::ErrorOr<BAN::UniqPtr<PlatformCursor>> (*create_system_cursor)(SystemCursorType);
|
||||||
/* Create cursor from custom bitmap */
|
/* Create cursor from custom bitmap */
|
||||||
|
|||||||
@@ -348,6 +348,14 @@ static void sdl3_warp_pointer(int32_t x, int32_t y, bool relative)
|
|||||||
SDL_WarpMouseGlobal(x, y);
|
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 BAN::ErrorOr<BAN::UniqPtr<PlatformCursor>> sdl3_create_system_cursor(SystemCursorType type)
|
||||||
{
|
{
|
||||||
static constexpr SDL_SystemCursor cursor_type_map[] {
|
static constexpr SDL_SystemCursor cursor_type_map[] {
|
||||||
@@ -428,6 +436,7 @@ PlatformOps g_platform_ops = {
|
|||||||
.request_reposition = sdl3_request_reposition,
|
.request_reposition = sdl3_request_reposition,
|
||||||
.request_fullscreen = sdl3_request_fullscreen,
|
.request_fullscreen = sdl3_request_fullscreen,
|
||||||
.warp_pointer = sdl3_warp_pointer,
|
.warp_pointer = sdl3_warp_pointer,
|
||||||
|
.query_pointer = sdl3_query_pointer,
|
||||||
.create_system_cursor = sdl3_create_system_cursor,
|
.create_system_cursor = sdl3_create_system_cursor,
|
||||||
.create_bitmap_cursor = sdl3_create_bitmap_cursor,
|
.create_bitmap_cursor = sdl3_create_bitmap_cursor,
|
||||||
.set_cursor = sdl3_set_cursor,
|
.set_cursor = sdl3_set_cursor,
|
||||||
|
|||||||
@@ -154,6 +154,12 @@ static void bananos_warp_pointer(int32_t x, int32_t y, bool relative)
|
|||||||
(void)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)
|
static BAN::ErrorOr<BAN::UniqPtr<PlatformCursor>> bananos_create_system_cursor(SystemCursorType type)
|
||||||
{
|
{
|
||||||
(void)type;
|
(void)type;
|
||||||
@@ -198,6 +204,7 @@ PlatformOps g_platform_ops = {
|
|||||||
.request_reposition = bananos_request_reposition,
|
.request_reposition = bananos_request_reposition,
|
||||||
.request_fullscreen = bananos_request_fullscreen,
|
.request_fullscreen = bananos_request_fullscreen,
|
||||||
.warp_pointer = bananos_warp_pointer,
|
.warp_pointer = bananos_warp_pointer,
|
||||||
|
.query_pointer = nullptr, /* bananos_query_pointer */
|
||||||
.create_system_cursor = bananos_create_system_cursor,
|
.create_system_cursor = bananos_create_system_cursor,
|
||||||
.create_bitmap_cursor = bananos_create_bitmap_cursor,
|
.create_bitmap_cursor = bananos_create_bitmap_cursor,
|
||||||
.set_cursor = bananos_set_cursor,
|
.set_cursor = bananos_set_cursor,
|
||||||
|
|||||||
Reference in New Issue
Block a user