SDL 1.2: Restart joysticks on WM_DEVICECHANGE (equivalent)

Hi,

So far I can only get joysticks working if they are plugged in before the application starts.

In native Win32 + DirectInput I would rescan joysticks whenever WM_DEVICECHANGE is received. That way, the joysticks can be plugged in and unplugged at any time during the course of the game.

Is there an equivalent procedure in SDL 1.2?

Hello,

Have you tried quitting the module, and initializing it again?

cheers,On Sat, May 28, 2011 at 8:50 AM, msturner wrote:

Hi,

So far I can only get joysticks working if they are plugged in before the
application starts.

In native Win32 + DirectInput I would rescan joysticks whenever
WM_DEVICECHANGE is received. That way, the joysticks can be plugged in and
unplugged at any time during the course of the game.

Is there an equivalent procedure in SDL 1.2?


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Ren? Dudfield wrote:

Hello,

Have you tried quitting the module, and initializing it again?

cheers,

That makes sense :slight_smile:

But how would I know when to do it? Is there any SDL event that corresponds to WM_DEVICECHANGE?

Or perhaps the solution is to periodically restart the joystick module, say every 1 second interval?

Thanks for your help!

Hi,

Unfortunately SDL doesn’t really have an event for that. It would be a nice
thing to add however.

Perhaps a UI for it would work ok? Do you have a preferences screen? Or a
main menu screen? If so, perhaps try doing the reset then?

cu.On Tue, May 31, 2011 at 12:02 AM, msturner wrote:

Ren? Dudfield wrote:

Hello,

Have you tried quitting the module, and initializing it again?

cheers,

That makes sense [image: Smile]

But how would I know when to do it? Is there any SDL event that
corresponds to WM_DEVICECHANGE?

Or perhaps the solution is to periodically restart the joystick module, say
every 1 second interval?

Thanks for your help!


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Yeah, in a pause menu or options menu, you might put a button to “scan” for
joysticks.

Jonny DOn Tue, May 31, 2011 at 10:28 AM, Ren? Dudfield wrote:

Hi,

Unfortunately SDL doesn’t really have an event for that. It would be a
nice thing to add however.

Perhaps a UI for it would work ok? Do you have a preferences screen? Or a
main menu screen? If so, perhaps try doing the reset then?

cu.

On Tue, May 31, 2011 at 12:02 AM, msturner wrote:

Ren? Dudfield wrote:

Hello,

Have you tried quitting the module, and initializing it again?

cheers,

That makes sense [image: Smile]

But how would I know when to do it? Is there any SDL event that
corresponds to WM_DEVICECHANGE?

Or perhaps the solution is to periodically restart the joystick module,
say every 1 second interval?

Thanks for your help!


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Have you considered listening for SDL_SysWMEvents? As a workaround if
nothing more for the moment.On 31 May 2011 00:02, msturner wrote:

But how would I know when to do it? Is there any SDL event that
corresponds to WM_DEVICECHANGE?

Thanks for your help everyone.

Ren? and Jonny D:
I do have a preference screen, pause, etc. so that’s no problem. Rescanning every time the menu or pause pops up is a good idea.

Brian:
Thanks for the suggestion of using SDL_SysWMEvent. I’ll play around with it and see what comes through on Linux and Mac. Hopefully I can get consistent behavior on all three platforms.

Thanks for the suggestion of using SDL_SysWMEvent. I’ll play around with
it and see what comes through on Linux and Mac. Hopefully I can get
consistent behavior on all three platforms.

These are not window manager events on most platforms (SDL on Linux and
Mac OS X talk to /dev nodes and the HUD framework, respectively. You
won’t get a GUI event from them).

We’re fixing device hotplugging for SDL 1.3, so you can know when a
joystick is plugged in or removed. In the meantime, the easiest approach
is to quit the subsystem and reinit when in a menu, or when the user
pushes a button (or just once at startup, because in practice, most
people don’t join a game in the middle by plugging in a controller).

–ryan.

Ryan C. Gordon wrote:

These are not window manager events on most platforms (SDL on Linux and
Mac OS X talk to /dev nodes and the HUD framework, respectively. You
won’t get a GUI event from them).

Thanks Ryan. Yes, I did some experimentation and figured that out the hard way. I’ve since discovered that the libudev library can be used on Linux to monitor changes to /dev/input, so I’m going to try that for the Linux build. Still learning about Mac OS X…