Implement WarpPointer
This allows playing games that capture the cursor
This commit is contained in:
@@ -2013,6 +2013,36 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case X_WarpPointer:
|
||||||
|
{
|
||||||
|
auto request = decode<xWarpPointerReq>(packet).value();
|
||||||
|
|
||||||
|
dprintln("WarpPointer");
|
||||||
|
dprintln(" src_wid: {}", request.srcWid);
|
||||||
|
dprintln(" src_x: {}", request.srcX);
|
||||||
|
dprintln(" src_y: {}", request.srcY);
|
||||||
|
dprintln(" src_w: {}", request.srcWidth);
|
||||||
|
dprintln(" src_h: {}", request.srcHeight);
|
||||||
|
dprintln(" dst_wid: {}", request.dstWid);
|
||||||
|
dprintln(" dst_x: {}", request.dstX);
|
||||||
|
dprintln(" dst_y: {}", request.dstY);
|
||||||
|
|
||||||
|
if (g_platform_ops.warp_pointer == nullptr)
|
||||||
|
break;
|
||||||
|
|
||||||
|
// TODO: source window :)
|
||||||
|
|
||||||
|
if (request.dstWid == None)
|
||||||
|
g_platform_ops.warp_pointer(request.dstX, request.dstY, true);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
(void)TRY_REF(get_window(client_info, request.dstWid, X_WarpPointer));
|
||||||
|
const auto [win_x, win_y] = get_window_position(request.dstWid);
|
||||||
|
g_platform_ops.warp_pointer(win_x + request.dstX, win_y + request.dstY, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
case X_QueryKeymap:
|
case X_QueryKeymap:
|
||||||
{
|
{
|
||||||
dprintln("QueryKeymap");
|
dprintln("QueryKeymap");
|
||||||
|
|||||||
@@ -59,6 +59,8 @@ struct PlatformOps
|
|||||||
void (*request_reposition)(PlatformWindow*, int32_t x, int32_t y);
|
void (*request_reposition)(PlatformWindow*, int32_t x, int32_t y);
|
||||||
/* Request new fullscreen state, can be async */
|
/* Request new fullscreen state, can be async */
|
||||||
void (*request_fullscreen)(PlatformWindow*, bool fullscreen);
|
void (*request_fullscreen)(PlatformWindow*, bool fullscreen);
|
||||||
|
/* Warp pointer */
|
||||||
|
void (*warp_pointer)(int32_t x, int32_t y, bool relative);
|
||||||
/* 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 */
|
||||||
|
|||||||
@@ -335,6 +335,19 @@ static void sdl3_request_fullscreen(PlatformWindow* window, bool fullscreen)
|
|||||||
SDL_SetWindowFullscreen(sdl_window.window, fullscreen);
|
SDL_SetWindowFullscreen(sdl_window.window, fullscreen);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void sdl3_warp_pointer(int32_t x, int32_t y, bool relative)
|
||||||
|
{
|
||||||
|
if (relative)
|
||||||
|
{
|
||||||
|
float cx, cy;
|
||||||
|
SDL_GetGlobalMouseState(&cx, &cy);
|
||||||
|
x += cx;
|
||||||
|
x += cy;
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_WarpMouseGlobal(x, y);
|
||||||
|
}
|
||||||
|
|
||||||
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[] {
|
||||||
@@ -414,6 +427,7 @@ PlatformOps g_platform_ops = {
|
|||||||
.request_resize = sdl3_request_resize,
|
.request_resize = sdl3_request_resize,
|
||||||
.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,
|
||||||
.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,
|
||||||
|
|||||||
@@ -147,6 +147,13 @@ static void bananos_request_fullscreen(PlatformWindow* window, bool fullscreen)
|
|||||||
banan_window.window->set_fullscreen(fullscreen);
|
banan_window.window->set_fullscreen(fullscreen);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void bananos_warp_pointer(int32_t x, int32_t y, bool relative)
|
||||||
|
{
|
||||||
|
(void)x;
|
||||||
|
(void)y;
|
||||||
|
(void)relative;
|
||||||
|
}
|
||||||
|
|
||||||
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;
|
||||||
@@ -190,6 +197,7 @@ PlatformOps g_platform_ops = {
|
|||||||
.request_resize = bananos_request_resize,
|
.request_resize = bananos_request_resize,
|
||||||
.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,
|
||||||
.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