Skip to content

Improve -nomousegrab mouse input handling #702

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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: 13 additions & 21 deletions ddio/lnxmouse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ static bool DDIO_mouse_init = false;
static struct mses_state {
int fd; // file descriptor of mouse
int t, l, b, r; // limit rectangle of absolute mouse coords
int x, y, dx, dy, cx, cy; // current x,y,z in absolute mouse coords
int x, y, cx, cy; // current x,y,z in absolute mouse coords
float dx, dy;
int btn_mask;
} DDIO_mouse_state;

Expand Down Expand Up @@ -169,7 +170,7 @@ void ddio_MouseReset() {

DDIO_mouse_state.x = DDIO_mouse_state.cx = Lnx_app_obj->m_W / 2;
DDIO_mouse_state.y = DDIO_mouse_state.cy = Lnx_app_obj->m_H / 2;
DDIO_mouse_state.dy = DDIO_mouse_state.dx = 0;
DDIO_mouse_state.dy = DDIO_mouse_state.dx = 0.0f;
}

// displays the mouse pointer. Each Hide call = Show call.
Expand Down Expand Up @@ -388,25 +389,16 @@ bool sdlMouseWheelFilter(SDL_Event const *event) {

bool sdlMouseMotionFilter(SDL_Event const *event) {
if (event->type == SDL_EVENT_JOYSTICK_BALL_MOTION) {
DDIO_mouse_state.dx = event->jball.xrel / 100;
DDIO_mouse_state.dy = event->jball.yrel / 100;
DDIO_mouse_state.dx = event->jball.xrel / 100.0f;
DDIO_mouse_state.dy = event->jball.yrel / 100.0f;
DDIO_mouse_state.x += DDIO_mouse_state.dx;
DDIO_mouse_state.y += DDIO_mouse_state.dy;
} // if
else {
if (ddio_mouseGrabbed) {
DDIO_mouse_state.dx += event->motion.xrel;
DDIO_mouse_state.dy += event->motion.yrel;
DDIO_mouse_state.x += DDIO_mouse_state.dx;
DDIO_mouse_state.y += DDIO_mouse_state.dy;
} // if
else {
DDIO_mouse_state.dx = event->motion.x - DDIO_mouse_state.x;
DDIO_mouse_state.dy = event->motion.y - DDIO_mouse_state.y;
DDIO_mouse_state.x = event->motion.x;
DDIO_mouse_state.y = event->motion.y;
} // else
} // else
} else {
DDIO_mouse_state.dx += event->motion.xrel;
DDIO_mouse_state.dy += event->motion.yrel;
DDIO_mouse_state.x += DDIO_mouse_state.dx;
DDIO_mouse_state.y += DDIO_mouse_state.dy;
}

if (DDIO_mouse_state.x < DDIO_mouse_state.l)
DDIO_mouse_state.x = DDIO_mouse_state.l;
Expand Down Expand Up @@ -449,8 +441,8 @@ int ddio_MouseGetState(int *x, int *y, int *dx, int *dy, int *z, int *dz) {
if (dz)
*dz = 0;

DDIO_mouse_state.dx = 0;
DDIO_mouse_state.dy = 0;
DDIO_mouse_state.dx = 0.0f;
DDIO_mouse_state.dy = 0.0f;

// unset the mouse wheel "button" once it's been retrieved.
DDIO_mouse_state.btn_mask &= ~(MOUSE_B5|MOUSE_B6);
Expand Down
Loading