1 | /* |
2 | Simple DirectMedia Layer |
3 | Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org> |
4 | |
5 | This software is provided 'as-is', without any express or implied |
6 | warranty. In no event will the authors be held liable for any damages |
7 | arising from the use of this software. |
8 | |
9 | Permission is granted to anyone to use this software for any purpose, |
10 | including commercial applications, and to alter it and redistribute it |
11 | freely, subject to the following restrictions: |
12 | |
13 | 1. The origin of this software must not be misrepresented; you must not |
14 | claim that you wrote the original software. If you use this software |
15 | in a product, an acknowledgment in the product documentation would be |
16 | appreciated but is not required. |
17 | 2. Altered source versions must be plainly marked as such, and must not be |
18 | misrepresented as being the original software. |
19 | 3. This notice may not be removed or altered from any source distribution. |
20 | */ |
21 | |
22 | #include "SDL_internal.h" |
23 | |
24 | #if defined(SDL_VIDEO_DRIVER_X11) |
25 | |
26 | #include "SDL_x11video.h" |
27 | #include "SDL_x11xtest.h" |
28 | |
29 | static bool xtest_initialized = false; |
30 | |
31 | void X11_InitXTest(SDL_VideoDevice *_this) |
32 | { |
33 | // This is currently disabled since it doesn't appear to work on XWayland |
34 | #if 0//def SDL_VIDEO_DRIVER_X11_XTEST |
35 | Display *display = _this->internal->display; |
36 | int event, error; |
37 | int opcode; |
38 | |
39 | if (!SDL_X11_HAVE_XTEST || |
40 | !X11_XQueryExtension(display, "XTEST" , &opcode, &event, &error)) { |
41 | return; |
42 | } |
43 | |
44 | xtest_initialized = true; |
45 | #endif |
46 | } |
47 | |
48 | bool X11_XTestIsInitialized(void) |
49 | { |
50 | return xtest_initialized; |
51 | } |
52 | |
53 | bool X11_WarpMouseXTest(SDL_VideoDevice *_this, SDL_Window *window, float x, float y) |
54 | { |
55 | #ifdef SDL_VIDEO_DRIVER_X11_XTEST |
56 | if (!X11_XTestIsInitialized()) { |
57 | return false; |
58 | } |
59 | |
60 | Display *display = _this->internal->display; |
61 | SDL_DisplayData *displaydata = window ? SDL_GetDisplayDriverDataForWindow(window) : SDL_GetDisplayDriverData(SDL_GetPrimaryDisplay()); |
62 | if (!displaydata) { |
63 | return false; |
64 | } |
65 | |
66 | int motion_x = (int)SDL_roundf(x); |
67 | int motion_y = (int)SDL_roundf(y); |
68 | if (window) { |
69 | motion_x += window->x; |
70 | motion_y += window->y; |
71 | } |
72 | |
73 | if (!X11_XTestFakeMotionEvent(display, displaydata->screen, motion_x, motion_y, CurrentTime)) { |
74 | return false; |
75 | } |
76 | X11_XSync(display, False); |
77 | |
78 | return true; |
79 | #else |
80 | return false; |
81 | #endif |
82 | } |
83 | |
84 | #endif // SDL_VIDEO_DRIVER_X11 |
85 | |