We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 245

Summary: Large xrel value when mouse hidden and grabbed.
Product: SDL Reporter: Dijon Page <skrot>
Component: eventsAssignee: Ryan C. Gordon <icculus>
Status: RESOLVED WORKSFORME QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2    
Version: 1.2.9   
Hardware: x86   
OS: Linux   
Attachments: Test case for SDL warping code

Description Dijon Page 2006-05-31 00:17:59 UTC
I believe I have found a bug in the mouse cursor 'wrapping' code in certain situations. By 'wrapping' I mean that when the mouse cursor is hidden and input grabbed, the mouse is silently warped to the middle of the screen. When this warping is done appears to be OS specific, however (from limited testing in Windows and Linux on my machine).

The problem appears to happen when this sequence of things happen (on Linux):

SDL_ShowCursor(0);
SDL_WM_GrabInput(SDL_GRAB_ON);
// move the mouse cursor enough that the cursor wraps to the center of the window
SDL_ShowCursor(1);
SDL_WM_GrabInput(SDL_GRAB_OFF);
// don't move the mouse at all, then
SDL_ShowCursor(0);
SDL_WM_GrabInput(SDL_GRAB_ON);
// move the mouse. A mouse motion event should be sent with what appears to be the xrel/yrel values from the edge to the new position of the mouse

I can reproduce this behavior every time. I will attach a test case which you can test this behavior with.

The test case hides the cursor and grabs input when you click the left mouse button, and shows the cursor and releases input when you release the left mouse button. The easiest way to test this is to move the mouse right next to the edge of the window, click and hold the mouse button, move the mouse so that the cursor would have warped to the center of the window, release the mouse button, click the mouse button again without moving the mouse beforehand, then move the mouse.

From my limited testing of similar mouse handling code to this in Windows, it appears as though the mouse is warped at a different time (and frequency) to when it is Linux. This seems to complicate things a little, and certainly makes the mouse code give frequently move stuff around the game scene.

If this is a bug in my usage of the SDL event system, please let me know.
Comment 1 Dijon Page 2006-05-31 00:19:24 UTC
Created attachment 135 [details]
Test case for SDL warping code

I have been compiling this code with:

g++ `sdl-config --cflags --libs` -o sdltest sdltest.cpp
Comment 2 Ryan C. Gordon 2006-06-25 15:45:11 UTC
I'm not seeing the behaviour here with this test program on Linux/x11 ... it's possible it's an old X server bug, or we fixed it in svn or something.

--ryan.

Comment 3 Dijon Page 2006-06-25 21:25:41 UTC
(In reply to comment #2)
> I'm not seeing the behaviour here with this test program on Linux/x11 ... it's
> possible it's an old X server bug, or we fixed it in svn or something.
> 
> --ryan.
> 

Hm I'm using xorg-x11 7.0-r1 on Gentoo. I just tried the SVN version of SDL, and I  can still reproduce this behaviour every time.

I'll give xorg 7.1 a shot over the next couple of days and see how it goes then.
Comment 4 Dijon Page 2006-06-25 21:34:10 UTC
I'd just like to stress that for this to do what I'm saying, it is absolutely necessary that the mouse not be moved between the time when the cursor is shown/ungrabbed (after it warping silently) and when the cursor is hidden/grabbed. It's pretty hard to explain, but it's very simple for me to do.

Perhaps it is important so I'll include my xorg.conf mouse section. I'll give the evdev driver a go, if one of the gnome programs doesn't still die with it...

Section "InputDevice"
    Identifier     "Mouse1"
    Driver         "mouse"
    Option         "Protocol" "IMPS/2"
    Option         "Device" "/dev/input/mice"
    Option         "ZAxisMapping" "4 5"
EndSection