-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Document SDL_JOYSTICK_ALLOW_BACKGROUND_EVENTS environment variable. #2962
Comments
@KingOfIce77 This seems like it's an issue with SDL 2.0.16 -> 2.0.18. I've built a wheel of pygame 2.1.2 for Windows and Python 3.10, but using SDL 2.0.16: Unzip that and pip install directly from the file, and then say here whether the problem persists. |
Hello ! Thanks for the quick answer. It seems to be ok with your package 2.1.2.dev1 using SDL 2.0.16 |
@zoldalma999 Do you have the time and stuff to handle this one? It looks like we need to report upstream to SDL, but I feel bad doing it without a C minimum reproducible example, and I don't have the hardware for this on my end. |
Thanks for the bug report. have two more questions to ask you:
|
Isn't joystick events not being passed to an inactive window an improvement? |
@zoldalma999 I'm just pointing out that it works in version 2.1.0 and not in 2.1.2. Personally, I need this. Don't hesitate if you have other questions or if you want I perform specifical tests. |
Yes, it would be new to pygame. That is why I asked if this is the issue - it should not work this way on either versions. However, there is an SDL hint for it, |
It's personal so it's selfish but as long as I still have the functionality, I'm fine with it! |
I think having it on by default is a bit counterintuitive. Users normally expect only the active application to receive input style events like mouse clicks - joystick/controller events would be in that class for me. In practice it doesn't likely come up that much because who plays two games simultaneously on PC without closing one down? Then again with modern consoles having freeze and resume features for games maybe we'll get a new generation who will do this... Anyway, I think exposing the SDL_HINT is a fine solution for those that are using this behaviour, but I think the default should follow SDL's logic. |
import os
# needs to be set before importing pygame, or can also be set from shell
# while calling the script
os.environ["SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS"] = "1"
import pygame
[other code here] You can do something like this to set the SDL hint to get it behave the way you want. zoldalma has confirmed this works for him, so it should work for you as well. Oh well, this looks a bit inelegant from code quality POV, but until pygame exposes more of SDL hint get/set API, this is the only way to set SDL hints from pygame |
Reopening because I just directed someone here from the pygame mailing list. Which means (anecdotally) that people care about this functionality. So we should probably document it somehow, at least. |
Thanks for that! And does it really require a numerical string, or is this more correct?
And unfrotunately I won't be back at that computer to test for probably a week, but will post how it works then. For now I reverted to 1.9.6.
For whatever it's worth joystick input seems to be an exception to that rule. Every other Python library that works with joysticks, such as the inputs library, has the joystick input as global. And on Windows for example the joystick config utility in the control panel doens't need focus to catch joystick events. Same goes for every linux joystick testing utility I've tried. I can't think of any joystick utilities or games that need focus. |
Hi, I currently have the exact same problem - I need to capture joystick events even when the pygame window is not in focus. I tried including I am using Python 3.9 and pygame 2.1.2 on Windows 10. |
I can also confirm that the environment variable doesn't work on it's own on Windows. The SDL hint does work if you add it directly to the pygame code base before SDL_Init and recompile pygame. We could add a patch like:
to |
Are you sure you are setting it before importing pygame and calling |
Yes. This was the test code I used:
Which is the joystick module test code from the docs plus your snippet above. Perhaps the environment variables in os.environ don't get turned into SDL environment variables/Hints quick enough? |
Seems like when using environment variables, SDL hints do not work with the "HINT_" part in the name. I still support the idea of either exposing set/get_hint (maybe the new |
Yes, |
Hello, Is this issue still open ? |
Yes. there are three tasks in the first post in this thread that still need doing to tie it off. |
Hey, it seem like the two first tasks are fixed, but not yet marked as completed:
https://www.pygame.org/docs/ref/pygame.html
|
Hijacking top post for tasks:
SetSDLHint()
&GetSDLHint()
(names not final) to new context module.Windows
Python 3.10
PyGame 2.1.2
I had to go back to version 2.1.0 and it works again : my pygame window that captures all joystick events doesn't capture anything anymore when I switch to another window
Current behavior:
No joystick events catched
Expected behavior:
joystick events catched (wirks on pygame 2.1.0)
code
The text was updated successfully, but these errors were encountered: