From 206c67e77c5f91bb69715b24bd4874af314068be Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Mon, 4 Feb 2019 18:20:51 +0100 Subject: [PATCH] move Set_mouse_position() to sdlscreen.c / win32screen.c / etc. --- src/input.c | 9 --------- src/input.h | 2 -- src/screen.h | 3 +++ src/sdlscreen.c | 9 +++++++++ src/win32screen.c | 14 ++++++++++++++ src/x11screen.c | 5 +++++ 6 files changed, 31 insertions(+), 11 deletions(-) diff --git a/src/input.c b/src/input.c index 0a901403..1a56e69b 100644 --- a/src/input.c +++ b/src/input.c @@ -1855,15 +1855,6 @@ void Adjust_mouse_sensitivity(word fullscreen) (void)fullscreen; } -void Set_mouse_position(void) -{ -#if defined(USE_SDL) - SDL_WarpMouse(Mouse_X*Pixel_width, Mouse_Y*Pixel_height); -#elif defined(USE_SDL2) - //SDL_WarpMouseInWindow(Window_SDL, Mouse_X*Pixel_width, Mouse_Y*Pixel_height); -#endif -} - static int Color_cycling(void) { static byte offset[16]; diff --git a/src/input.h b/src/input.h index 39ea807c..fbaa9cb6 100644 --- a/src/input.h +++ b/src/input.h @@ -49,8 +49,6 @@ int Has_shortcut(word function); /// Adjust mouse sensitivity (and actual mouse input mode) void Adjust_mouse_sensitivity(word fullscreen); -void Set_mouse_position(void); - int Move_cursor_with_constraints(void); /// diff --git a/src/screen.h b/src/screen.h index 785d70b6..344d3c08 100644 --- a/src/screen.h +++ b/src/screen.h @@ -83,4 +83,7 @@ int GFX2_Get_X11_Display_Window(Display * * display, Window * window); /// Set application icon(s) void Define_icon(void); +/// set (system) mouse cursor position +void Set_mouse_position(void); + #endif // SCREEN_H_INCLUDED diff --git a/src/sdlscreen.c b/src/sdlscreen.c index 7d36d106..539086ee 100644 --- a/src/sdlscreen.c +++ b/src/sdlscreen.c @@ -778,3 +778,12 @@ void Define_icon(void) } } } + +void Set_mouse_position(void) +{ +#if defined(USE_SDL) + SDL_WarpMouse(Mouse_X*Pixel_width, Mouse_Y*Pixel_height); +#elif defined(USE_SDL2) + SDL_WarpMouseInWindow(NULL, Mouse_X*Pixel_width, Mouse_Y*Pixel_height); +#endif +} \ No newline at end of file diff --git a/src/win32screen.c b/src/win32screen.c index cba7c576..f9d15b33 100644 --- a/src/win32screen.c +++ b/src/win32screen.c @@ -609,3 +609,17 @@ void Define_icon(void) // Do nothing because the icon is set in the window class // see Init_Win32() } + +void Set_mouse_position(void) +{ + POINT pt; + pt.x = Mouse_X * Pixel_width; + pt.y = Mouse_Y * Pixel_height; + if (!ClientToScreen(Win32_hwnd, &pt)) + GFX2_Log(GFX2_WARNING, "ClientToScreen(%08x, %p) failed\n", Win32_hwnd, &pt); + else + { + if (!SetCursorPos(pt.x, pt.y)) + GFX2_Log(GFX2_WARNING, "SetCursorPos(%ld, %ld) failed\n", pt.x, pt.y); + } +} \ No newline at end of file diff --git a/src/x11screen.c b/src/x11screen.c index 3e62c2fd..3bab4b3a 100644 --- a/src/x11screen.c +++ b/src/x11screen.c @@ -330,3 +330,8 @@ void Define_icon(void) snprintf(icon_path, sizeof(icon_path), "%s%s", Data_directory, "gfx2.png"); // 48x48 icon = Load_surface(icon_path, NULL); } + +void Set_mouse_position(void) +{ + /// @todo implement screen capture and set position for x11. +}