1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 07:37:46 +00:00

Ports: Implement SDL2 mouse warping

This patch implements the mouse warping functionality of SDL2.
This adds a WarpMouse function implementation to the SDL2 port.
SDL2 will then be able to use this for it's relative mouse mode
implementation.

With this, multiple ports depending on SDL2 now correctly lock the
mouse inside the window and it improves the experience significantly.

Note that as of now, you may need to pass the kernel argument
'vmmouse=off' in order to test these changes properly.
This commit is contained in:
Refrag 2024-02-18 15:21:12 +01:00 committed by Jelle Raaijmakers
parent aa3a6767f6
commit 33b772a7fa
2 changed files with 22 additions and 5 deletions

View file

@ -6,6 +6,7 @@ files=(
"https://github.com/libsdl-org/SDL/releases/download/release-${version}/SDL2-${version}.tar.gz#64b1102fa22093515b02ef33dd8739dee1ba57e9dbba6a092942b8bbed1a1c5e" "https://github.com/libsdl-org/SDL/releases/download/release-${version}/SDL2-${version}.tar.gz#64b1102fa22093515b02ef33dd8739dee1ba57e9dbba6a092942b8bbed1a1c5e"
) )
configopts=( configopts=(
"-DCMAKE_CXX_FLAGS=-I${SERENITY_BUILD_DIR}/Root/usr/include/Services/ -I${SERENITY_BUILD_DIR}/Root/usr/include/Userland/Services/"
"-DCMAKE_TOOLCHAIN_FILE=${SERENITY_BUILD_DIR}/CMakeToolchain.txt" "-DCMAKE_TOOLCHAIN_FILE=${SERENITY_BUILD_DIR}/CMakeToolchain.txt"
"-DPULSEAUDIO=OFF" "-DPULSEAUDIO=OFF"
"-DJACK=OFF" "-DJACK=OFF"

View file

@ -21,6 +21,7 @@ Co-Authored-By: circl <circl.lastname@gmail.com>
Co-Authored-By: kleines Filmröllchen <filmroellchen@serenityos.org> Co-Authored-By: kleines Filmröllchen <filmroellchen@serenityos.org>
Co-Authored-By: Linus Groh <mail@linusgroh.de> Co-Authored-By: Linus Groh <mail@linusgroh.de>
Co-Authored-By: Tim Ledbetter <timledbetter@gmail.com> Co-Authored-By: Tim Ledbetter <timledbetter@gmail.com>
Co-Authored-By: Refrag <R3FR4GYT@gmail.com>
--- ---
CMakeLists.txt | 25 +- CMakeLists.txt | 25 +-
build-scripts/config.sub | 3 + build-scripts/config.sub | 3 +
@ -39,11 +40,11 @@ Co-Authored-By: Tim Ledbetter <timledbetter@gmail.com>
src/video/serenity/SDL_serenityevents_c.h | 33 + src/video/serenity/SDL_serenityevents_c.h | 33 +
src/video/serenity/SDL_serenitymessagebox.cpp | 47 ++ src/video/serenity/SDL_serenitymessagebox.cpp | 47 ++
src/video/serenity/SDL_serenitymessagebox.h | 38 + src/video/serenity/SDL_serenitymessagebox.h | 38 +
src/video/serenity/SDL_serenitymouse.cpp | 142 ++++ src/video/serenity/SDL_serenitymouse.cpp | 169 +++++
src/video/serenity/SDL_serenitymouse.h | 39 ++ src/video/serenity/SDL_serenitymouse.h | 39 ++
src/video/serenity/SDL_serenityvideo.cpp | 655 ++++++++++++++++++ src/video/serenity/SDL_serenityvideo.cpp | 655 ++++++++++++++++++
src/video/serenity/SDL_serenityvideo.h | 101 +++ src/video/serenity/SDL_serenityvideo.h | 101 +++
21 files changed, 1365 insertions(+), 26 deletions(-) 21 files changed, 1392 insertions(+), 26 deletions(-)
create mode 100644 src/audio/serenity/SDL_serenityaudio.cpp create mode 100644 src/audio/serenity/SDL_serenityaudio.cpp
create mode 100644 src/audio/serenity/SDL_serenityaudio.h create mode 100644 src/audio/serenity/SDL_serenityaudio.h
create mode 100644 src/video/serenity/SDL_serenityevents.cpp create mode 100644 src/video/serenity/SDL_serenityevents.cpp
@ -703,10 +704,10 @@ index 0000000000000000000000000000000000000000..34e607783310310ac8956bccf584b5ab
+/* vi: set ts=4 sw=4 expandtab: */ +/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/video/serenity/SDL_serenitymouse.cpp b/src/video/serenity/SDL_serenitymouse.cpp diff --git a/src/video/serenity/SDL_serenitymouse.cpp b/src/video/serenity/SDL_serenitymouse.cpp
new file mode 100644 new file mode 100644
index 0000000000000000000000000000000000000000..5d0cb527a03dc0ac775ed68d66451495bf993ec6 index 0000000000000000000000000000000000000000..c603fe8cedaae61ab8ae84407734d1c89f99ff06
--- /dev/null --- /dev/null
+++ b/src/video/serenity/SDL_serenitymouse.cpp +++ b/src/video/serenity/SDL_serenitymouse.cpp
@@ -0,0 +1,142 @@ @@ -0,0 +1,157 @@
+/* +/*
+ Simple DirectMedia Layer + Simple DirectMedia Layer
+ Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org> + Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
@ -746,6 +747,7 @@ index 0000000000000000000000000000000000000000..5d0cb527a03dc0ac775ed68d66451495
+#include "SDL_serenityvideo.h" +#include "SDL_serenityvideo.h"
+ +
+#include <LibGfx/StandardCursor.h> +#include <LibGfx/StandardCursor.h>
+#include <LibGUI/ConnectionToWindowServer.h>
+ +
+struct SerenityCursorData final { +struct SerenityCursorData final {
+ Gfx::StandardCursor cursor_type; + Gfx::StandardCursor cursor_type;
@ -821,6 +823,20 @@ index 0000000000000000000000000000000000000000..5d0cb527a03dc0ac775ed68d66451495
+ return 0; + return 0;
+} +}
+ +
+static void
+SERENITY_WarpMouse(SDL_Window *window, int x, int y)
+{
+ auto platform_window = SerenityPlatformWindow::from_sdl_window(window);
+
+ auto window_position = platform_window->window()->position();
+ auto warp_position = Gfx::Point(x, y);
+
+ auto absolute_warp_position = window_position + warp_position;
+
+ GUI::ConnectionToWindowServer::the().async_set_global_cursor_position(absolute_warp_position);
+ SDL_SendMouseMotion(window, 0, 0, warp_position.x(), warp_position.y());
+}
+
+void +void
+SERENITY_InitMouse(_THIS) +SERENITY_InitMouse(_THIS)
+{ +{
@ -831,10 +847,10 @@ index 0000000000000000000000000000000000000000..5d0cb527a03dc0ac775ed68d66451495
+ mouse->CreateSystemCursor = SERENITY_CreateSystemCursor; + mouse->CreateSystemCursor = SERENITY_CreateSystemCursor;
+ mouse->ShowCursor = SERENITY_ShowCursor; + mouse->ShowCursor = SERENITY_ShowCursor;
+ mouse->FreeCursor = SERENITY_FreeCursor; + mouse->FreeCursor = SERENITY_FreeCursor;
+ mouse->WarpMouse = SERENITY_WarpMouse;
+ +
+ // FIXME: implement below methods + // FIXME: implement below methods
+ //mouse->CreateCursor = ...; + //mouse->CreateCursor = ...;
+ //mouse->WarpMouse = ...;
+ //mouse->SetRelativeMouseMode = ...; + //mouse->SetRelativeMouseMode = ...;
+ +
+ SDL_SetDefaultCursor(SERENITY_CreateDefaultCursor()); + SDL_SetDefaultCursor(SERENITY_CreateDefaultCursor());