summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorubkp <[email protected]>2023-10-31 06:16:12 -0300
committerGitHub <[email protected]>2023-10-31 10:16:12 +0100
commitab61bad1687044b9ad1144692e8c6bdf6a129794 (patch)
tree426461bf6ee4bb5a159a78bc5bfee21bba271cb4 /src
parentd8acceca14da2ee5f8e03cd23347b28e438334bd (diff)
downloadraylib-ab61bad1687044b9ad1144692e8c6bdf6a129794.tar.gz
raylib-ab61bad1687044b9ad1144692e8c6bdf6a129794.zip
Fix relative mouse mode for DRM (#3492)
Diffstat (limited to 'src')
-rw-r--r--src/platforms/rcore_drm.c34
1 files changed, 30 insertions, 4 deletions
diff --git a/src/platforms/rcore_drm.c b/src/platforms/rcore_drm.c
index 82701e31..9212d7e0 100644
--- a/src/platforms/rcore_drm.c
+++ b/src/platforms/rcore_drm.c
@@ -121,6 +121,7 @@ typedef struct {
Vector2 eventWheelMove; // Registers the event mouse wheel variation
// NOTE: currentButtonState[] can't be written directly due to multithreading, app could miss the update
char currentButtonStateEvdev[MAX_MOUSE_BUTTONS]; // Holds the new mouse state for the next polling event to grab
+ bool cursorRelative; // Relative cursor mode
// Gamepad data
pthread_t gamepadThreadId; // Gamepad reading thread id
@@ -400,6 +401,7 @@ void EnableCursor(void)
// Set cursor position in the middle
SetMousePosition(CORE.Window.screen.width/2, CORE.Window.screen.height/2);
+ platform.cursorRelative = false;
CORE.Input.Mouse.cursorHidden = false;
}
@@ -409,6 +411,7 @@ void DisableCursor(void)
// Set cursor position in the middle
SetMousePosition(CORE.Window.screen.width/2, CORE.Window.screen.height/2);
+ platform.cursorRelative = true;
CORE.Input.Mouse.cursorHidden = true;
}
@@ -522,6 +525,13 @@ void PollInputEvents(void)
PollKeyboardEvents();
+ // Register previous mouse position
+ if (platform.cursorRelative)
+ {
+ CORE.Input.Mouse.previousPosition = CORE.Input.Mouse.currentPosition;
+ CORE.Input.Mouse.currentPosition = (Vector2){ 0.0f, 0.0f };
+ }
+
// Register previous mouse states
CORE.Input.Mouse.previousWheelMove = CORE.Input.Mouse.currentWheelMove;
CORE.Input.Mouse.currentWheelMove = platform.eventWheelMove;
@@ -1535,8 +1545,16 @@ static void *EventThread(void *arg)
{
if (event.code == REL_X)
{
- CORE.Input.Mouse.currentPosition.x += event.value;
- CORE.Input.Touch.position[0].x = CORE.Input.Mouse.currentPosition.x;
+ if (platform.cursorRelative)
+ {
+ CORE.Input.Mouse.currentPosition.x -= event.value;
+ CORE.Input.Touch.position[0].x = CORE.Input.Mouse.currentPosition.x;
+ }
+ else
+ {
+ CORE.Input.Mouse.currentPosition.x += event.value;
+ CORE.Input.Touch.position[0].x = CORE.Input.Mouse.currentPosition.x;
+ }
touchAction = 2; // TOUCH_ACTION_MOVE
gestureUpdate = true;
@@ -1544,8 +1562,16 @@ static void *EventThread(void *arg)
if (event.code == REL_Y)
{
- CORE.Input.Mouse.currentPosition.y += event.value;
- CORE.Input.Touch.position[0].y = CORE.Input.Mouse.currentPosition.y;
+ if (platform.cursorRelative)
+ {
+ CORE.Input.Mouse.currentPosition.y -= event.value;
+ CORE.Input.Touch.position[0].y = CORE.Input.Mouse.currentPosition.y;
+ }
+ else
+ {
+ CORE.Input.Mouse.currentPosition.y += event.value;
+ CORE.Input.Touch.position[0].y = CORE.Input.Mouse.currentPosition.y;
+ }
touchAction = 2; // TOUCH_ACTION_MOVE
gestureUpdate = true;