mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-23 09:51:57 -05: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:
parent
aa3a6767f6
commit
33b772a7fa
2 changed files with 22 additions and 5 deletions
|
@ -6,6 +6,7 @@ files=(
|
|||
"https://github.com/libsdl-org/SDL/releases/download/release-${version}/SDL2-${version}.tar.gz#64b1102fa22093515b02ef33dd8739dee1ba57e9dbba6a092942b8bbed1a1c5e"
|
||||
)
|
||||
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"
|
||||
"-DPULSEAUDIO=OFF"
|
||||
"-DJACK=OFF"
|
||||
|
|
|
@ -21,6 +21,7 @@ Co-Authored-By: circl <circl.lastname@gmail.com>
|
|||
Co-Authored-By: kleines Filmröllchen <filmroellchen@serenityos.org>
|
||||
Co-Authored-By: Linus Groh <mail@linusgroh.de>
|
||||
Co-Authored-By: Tim Ledbetter <timledbetter@gmail.com>
|
||||
Co-Authored-By: Refrag <R3FR4GYT@gmail.com>
|
||||
---
|
||||
CMakeLists.txt | 25 +-
|
||||
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_serenitymessagebox.cpp | 47 ++
|
||||
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_serenityvideo.cpp | 655 ++++++++++++++++++
|
||||
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.h
|
||||
create mode 100644 src/video/serenity/SDL_serenityevents.cpp
|
||||
|
@ -703,10 +704,10 @@ index 0000000000000000000000000000000000000000..34e607783310310ac8956bccf584b5ab
|
|||
+/* vi: set ts=4 sw=4 expandtab: */
|
||||
diff --git a/src/video/serenity/SDL_serenitymouse.cpp b/src/video/serenity/SDL_serenitymouse.cpp
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..5d0cb527a03dc0ac775ed68d66451495bf993ec6
|
||||
index 0000000000000000000000000000000000000000..c603fe8cedaae61ab8ae84407734d1c89f99ff06
|
||||
--- /dev/null
|
||||
+++ b/src/video/serenity/SDL_serenitymouse.cpp
|
||||
@@ -0,0 +1,142 @@
|
||||
@@ -0,0 +1,157 @@
|
||||
+/*
|
||||
+ Simple DirectMedia Layer
|
||||
+ Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
|
||||
|
@ -746,6 +747,7 @@ index 0000000000000000000000000000000000000000..5d0cb527a03dc0ac775ed68d66451495
|
|||
+#include "SDL_serenityvideo.h"
|
||||
+
|
||||
+#include <LibGfx/StandardCursor.h>
|
||||
+#include <LibGUI/ConnectionToWindowServer.h>
|
||||
+
|
||||
+struct SerenityCursorData final {
|
||||
+ Gfx::StandardCursor cursor_type;
|
||||
|
@ -821,6 +823,20 @@ index 0000000000000000000000000000000000000000..5d0cb527a03dc0ac775ed68d66451495
|
|||
+ 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
|
||||
+SERENITY_InitMouse(_THIS)
|
||||
+{
|
||||
|
@ -831,10 +847,10 @@ index 0000000000000000000000000000000000000000..5d0cb527a03dc0ac775ed68d66451495
|
|||
+ mouse->CreateSystemCursor = SERENITY_CreateSystemCursor;
|
||||
+ mouse->ShowCursor = SERENITY_ShowCursor;
|
||||
+ mouse->FreeCursor = SERENITY_FreeCursor;
|
||||
+ mouse->WarpMouse = SERENITY_WarpMouse;
|
||||
+
|
||||
+ // FIXME: implement below methods
|
||||
+ //mouse->CreateCursor = ...;
|
||||
+ //mouse->WarpMouse = ...;
|
||||
+ //mouse->SetRelativeMouseMode = ...;
|
||||
+
|
||||
+ SDL_SetDefaultCursor(SERENITY_CreateDefaultCursor());
|
||||
|
|
Loading…
Reference in a new issue