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

Most joystick events not detected until window first loses focus then regains it. #1393

Closed
SDLBugzilla opened this issue Feb 10, 2021 · 0 comments

Comments

@SDLBugzilla
Copy link
Collaborator

This bug report was migrated from our old Bugzilla tracker.

Reported in version: 2.0.1
Reported for operating system, platform: Linux, x86

Comments on the original bug report:

On 2014-03-08 06:45:18 +0000, wrote:

After extensive testing and debugging my own programs, I believe this to be a bug in SDL:

SDL_JOYBUTTONDOWN events -- as well as some other joystick-related events -- are only detected once the focus has left an SDL2 window and subsequently returned to it.

Things I have tried which did NOT resolve my issue:
My own test programs which only print out events or only joystick events.
Other peoples' test programs which print out events.
Setting SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS to 1.
Two types of three joysticks (all with a similar layout):
// 0. A standard Sony PS3 DualShock3 controller
// 1. Another standard Sony PS3 DualShock3 controller
// 2. A "Logitech Logitech Dual Action" controller

Things I have not tried yet (I am unable to try these at this time):
Another OS than Linux (Arch Linux, latest updates).
Another WM than dwm (I compiled dwm from recent source).
Running my SDL2 programs any way other than launching them via command line.
// Possibly related is bug 1930:
// https://bugzilla.libsdl.org/show_bug.cgi?id=1930
Other versions of SDL2 (I am using SDL2 version 2.0.1).
Any version of SDL1.x (Actually I did try this but I forgot the results).


TO REPRODUCE (reproduction rate following these steps = 100%):
0. Write an SDL2 program which polls for events then prints out their types.

  1. Compile and link with SDL2.
  2. Plug in a joystick.
  3. Wait ~20 seconds for the kernel to detect the new hardware.
  4. Run the program.
    // A new SDL2 window is created, and focus is given to it.
    // The mouse pointer is inside the window, but has not moved yet.
    // SDL2 correctly detects the joystick.
  5. Press buttons on the joystick and move the axes.
    // Only SDL_JOYBUTTONUP events are detected.
    // If the program manually checks for the states of axes, then
    // the joystick axes are correctly detected on-demand (but no
    // SDL_JOYAXISMOTION events are ever detected).
  6. Move the mouse outside the SDL2 window.
    // The SDL2 window loses focus.
  7. Press buttons on the joystick and move the axes.
    // Same results as in step 5.
  8. Move the mouse back inside the SDL2 window.
    // The SDL2 window regains focus.
  9. Press buttons on the joystick and move the axes.
    // Now, SDL_JOYBUTTONDOWN events are correctly caught!
    // Also, SDL_JOYAXISMOTION events are correctly caught!

Again, I have tried seting "SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS" to "1" and this did not fix my problem. However, even if it did fix it then I would prefer to not have to use a hint since the docs state:
| "In general these hints are just that - they may or may not be
| supported or applicable on any given platform, ..."

Thank you!

^,^<

On 2014-03-08 07:01:18 +0000, wrote:

Oh, I'm compiling in gcc with:
-std=c89 -pedantic -Wall -Wextra

% gcc --version
gcc (GCC) 4.8.2 20131219 (prerelease)
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

%

On 2015-02-19 05:22:18 +0000, Ryan C. Gordon wrote:

Marking a large number of bugs with the "triage-2.0.4" keyword at once. Sorry if you got a lot of email from this. This is to help me sort through some bugs in regards to a 2.0.4 release. We may or may not fix this bug for 2.0.4, though!

On 2015-04-07 04:57:54 +0000, Ryan C. Gordon wrote:

(sorry if you get a lot of copies of this email, I'm marking several bugs at once)

Marking bugs for the (mostly) final 2.0.4 TODO list. This means we're hoping to resolve this bug before 2.0.4 ships if possible. In a perfect world, the open bug count with the target-2.0.4 keyword is zero when we ship.

(Note that closing a bug report as WONTFIX, INVALID or WORKSFORME might still happen.)

--ryan.

On 2015-04-15 04:17:01 +0000, sergio-br2 wrote:

It seems the program does not have focus when you open it, then you Alt+Tab / back and it gains focus. So windows does not lost focus when you Alt+Tab or click in other program, because it just does not have focus at first.

You can test with this program: https://github.com/sergiobenrocha2/cabrio/tree/test (test branch), I used SDL_GetKeyboardFocus() in sdl_wrapper.c, so in event.c it calls sdl_focus() function after the SDL_PollEvent, and you'll see a lot of "Window NOT focused" until you Alt+Tab out and back to the window.

You can confirm it with SDL_WINDOWEVENT_FOCUS_LOST, this event does not appear in the first time window "lost" focus.

Tested in Xubuntu 14.04, x86_64, libsdl 2.0.2.

Weird thing is that with 2.0.2 I get only SDL_JOYBUTTONUP, but with snapshot (4bab88dd387e) it does not appear too without focus.

On 2015-04-15 04:34:44 +0000, sergio-br2 wrote:

I can get window focused at first if I use primusrun (Optimus nvidia hardware):

primusrun ./cabrio

On 2015-04-15 04:55:01 +0000, sergio-br2 wrote:

Finally found a workaround for this, just use SDL_JOYSTICK_ALLOW_BACKGROUND_EVENTS=1

On 2015-05-28 06:18:07 +0000, Ryan C. Gordon wrote:

*** Bug 2309 has been marked as a duplicate of this bug. ***

On 2015-05-28 17:51:22 +0000, Sam Lantinga wrote:

I believe this is fixed in 2.0.4. If you're still seeing this bug after release, please reopen it and attach a test program and try some of the other things you mentioned that you haven't tried yet (another OS, another WM, etc)

Thanks!

On 2015-05-28 20:14:38 +0000, Ryan C. Gordon wrote:

This seems to trigger on Optimus systems and systems without window managers; we might fix the window manager issue before 2.0.4, but I think that's as far as we'll get. Not to imply these aren't serious concerns, but it's a small subset of current users at the moment.

We should probably reopen this so we don't forget it after 2.0.4 ships, though.

--ryan.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant