SDL_WM_GrabInput on OS X

Hi,

I’m the main developer of Enigma (http://fs.fsf.org/enigma). We are
currently trying to port the game to OS X. It works perfectly so far,
except that SDL_WM_GrabInput does not seem to work the way it does on
Windows and Linux. Problem is: the game becomes almost unplayable if
the mouse cannot be moved “continuously”, without stopping at the border
of the screen.

Did anyone else experience the same problem? Are there any known
workarounds? I know, I could simulate the continous motion using
SDL_WarpMouse, but according to the SDL source code (QZ_PumpEvents),

/* 1/2 second after a warp, the mouse cannot move (don’t ask me why) */

so this seems also to be a bad solution. Any ideas?

  • Daniel

Daniel Heck wrote:

Hi,

I’m the main developer of Enigma (http://fs.fsf.org/enigma). We are
currently trying to port the game to OS X. It works perfectly so far,
except that SDL_WM_GrabInput does not seem to work the way it does on
Windows and Linux. Problem is: the game becomes almost unplayable if
the mouse cannot be moved “continuously”, without stopping at the border
of the screen.

Did anyone else experience the same problem? Are there any known
workarounds? I know, I could simulate the continous motion using
SDL_WarpMouse, but according to the SDL source code (QZ_PumpEvents),

/* 1/2 second after a warp, the mouse cannot move (don’t ask me why) */

so this seems also to be a bad solution. Any ideas?

  • Daniel

If you need to get the mouse’s motion, use the “xrel” and “yrel” fields
of the MouseMotionEvent (relative motion), and not the “x” and “y” ones.

RK.

Hi,

I’m the main developer of Enigma (http://fs.fsf.org/enigma). We are
currently trying to port the game to OS X. It works perfectly so far,
except that SDL_WM_GrabInput does not seem to work the way it does on
Windows and Linux. Problem is: the game becomes almost unplayable if
the mouse cannot be moved “continuously”, without stopping at the border
of the screen.

You should still get continuous mouse events if you grab the input.
Problem is, the cursor doesn’t move, since we lock it in the center of
the window. If you need the SDL/OS cursor to move around with the mouse,
you can’t use the grab input function.

Did anyone else experience the same problem? Are there any known
workarounds? I know, I could simulate the continous motion using
SDL_WarpMouse, but according to the SDL source code (QZ_PumpEvents),

/* 1/2 second after a warp, the mouse cannot move (don’t ask me why) */

so this seems also to be a bad solution. Any ideas?

I hacked around this problem to get reasonably continuous motion for
apps that frequently warp the cursor. Warping when you hit/go over the
edge might actually work in your case.

If that doesn’t work, try writing your own “cursor” code so that the
"cursor" is a SDL surface, the SDL input is grabbed, and the SDL cursor
is hidden.

-DOn Friday, August 16, 2002, at 12:03 PM, Daniel Heck wrote:

You should still get continuous mouse events if you grab the input.
Problem is, the cursor doesn’t move, since we lock it in the center of

the window. If you need the SDL/OS cursor to move around with the
mouse, you can’t use the grab input function.

It seems we’ve been able to track down the problem. According to my
co-developer, grabbing the mouse cursor works just fine when the game
runs in a window, but in fullscreen mode it doesn’t. This solves our
problem for the time being, but it’s still somewhat strange.

Thanks for your help,
Daniel

Daniel Heck wrote:

You should still get continuous mouse events if you grab the input.
Problem is, the cursor doesn’t move, since we lock it in the center of

the window. If you need the SDL/OS cursor to move around with the
mouse, you can’t use the grab input function.

It seems we’ve been able to track down the problem. According to my
co-developer, grabbing the mouse cursor works just fine when the game
runs in a window, but in fullscreen mode it doesn’t. This solves our
problem for the time being, but it’s still somewhat strange.

Thanks for your help,
Daniel

What about continues motion by getting “xrel” and “yrel” fields? They
should tell you how much the mouse have moved, even if the cursor did not.

RK.

You should still get continuous mouse events if you grab the input.
Problem is, the cursor doesn’t move, since we lock it in the center of

the window. If you need the SDL/OS cursor to move around with the
mouse, you can’t use the grab input function.

It seems we’ve been able to track down the problem. According to my
co-developer, grabbing the mouse cursor works just fine when the game
runs in a window, but in fullscreen mode it doesn’t. This solves our
problem for the time being, but it’s still somewhat strange.

When in fullscreen SDL_WM_GrabInput() doesn’t actually grab the cursor
like windowed mode does. The reason is that I figured we wouldn’t have
to grab the cursor/input since the cursor/keyboard input can’t leave the
screen (except on multimonitor systems, which we don’t fully support
yet).

Now that I think about it, since the input isn’t really grabbed (but SDL
says it is), we might be treating it like it is somehow…that could be
the source of the bug. I’ll check this out and let you know what I find.On Sunday, August 18, 2002, at 11:31 AM, Daniel Heck wrote:

What about continues motion by getting “xrel” and “yrel” fields? They
should tell you how much the mouse have moved, even if the cursor did
not.

We never used anything but the xrel,yrel fields. The mouse still stops
at the border of the screen in fullscreen mode.

D.

ive done this kind of code before. When i get a mouse movement event, i
check to see how much the mouse has moved relative to the middle of the
screen in x and y then call the warpmouse function to put it back into the
middle of the screen and then handle the code that is controlled by the
movement of the mouse (camera rotation or whatever).

This works for me except i get another mouse move event from the warpmouse
function (in windows atleast) so i have special code to make it not do the
above when the mouse is in the center of the screen.> ----- Original Message -----

From: dheck@ix.urz.uni-heidelberg.de (Daniel Heck)
To:
Sent: Sunday, August 18, 2002 2:38 PM
Subject: Re: [SDL] SDL_WM_GrabInput on OS X

What about continues motion by getting “xrel” and “yrel” fields? They
should tell you how much the mouse have moved, even if the cursor did
not.

We never used anything but the xrel,yrel fields. The mouse still stops
at the border of the screen in fullscreen mode.

D.


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Hello SDL list…

I’ve been using SDL on my OSX machine now for more then a year and a half,
for my uni assignments and personal coding - and I think it is great!

I haven’t joined the mailing list because in that whole time, this is the
first issue that I have had that I couldn’t solve myself (thanks to the
quality documentation…)

I am using the mouse in my app to move the camera and I have found that on
my OSX box, the relative mouse data stops when the cursor reaches then end
on the screen…

I have tried calling “SDL_WM_GrabInput(SDL_GRAB_ON); SDL_ShowCursor(0);” -
this works in windowed mode, but not when the app is running fullscreen…

I’ve searched the archives, and it seems that this has cropped up before,
but it wasn’t solved… (the original email is at the bottom of this one)

Any ideas?

Also, is there a way of switching between fullscreen and windowed without
shutting down the SDL video subsystem?

Thanks for the help,

Matt Smith

Here is the original email:

Daniel Heck wrote:>Hi,

I’m the main developer of Enigma (http://fs.fsf.org/enigma). We are
currently trying to port the game to OS X. It works perfectly so far,
except that SDL_WM_GrabInput does not seem to work the way it does on
Windows and Linux. Problem is: the game becomes almost unplayable if
the mouse cannot be moved “continuously”, without stopping at the border
of the screen.

Did anyone else experience the same problem? Are there any known
workarounds? I know, I could simulate the continous motion using
SDL_WarpMouse, but according to the SDL source code (QZ_PumpEvents),

/* 1/2 second after a warp, the mouse cannot move (don’t ask me why) */

so this seems also to be a bad solution. Any ideas?

  • Daniel

I am using the mouse in my app to move the camera and I have found
that on
my OSX box, the relative mouse data stops when the cursor reaches then
end
on the screen…

I have tried calling “SDL_WM_GrabInput(SDL_GRAB_ON);
SDL_ShowCursor(0);” -
this works in windowed mode, but not when the app is running
fullscreen…

I’ve searched the archives, and it seems that this has cropped up
before,
but it wasn’t solved… (the original email is at the bottom of this
one)

I believe this has been fixed in the current (CVS) version of SDL. If
not, please let me know.

Also, is there a way of switching between fullscreen and windowed
without
shutting down the SDL video subsystem?

No. Luckily, the alternative isn’t much code at all:

flags ^= SDL_FULLSCREEN;
screen = SDL_SetVideoMode (…, flags);
Draw();On Monday, August 4, 2003, at 03:01 PM, mps at utas.edu.au wrote: