Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[core] Fix relative mouse mode for PLATFORM_DRM #3492

Merged
merged 1 commit into from Oct 31, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 30 additions & 4 deletions src/platforms/rcore_drm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1535,17 +1545,33 @@ 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;
}

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;
Expand Down