17cupsofcoffee / tetra

🎮 A simple 2D game framework written in Rust
MIT License
909 stars 63 forks source link

Input monitoring permissions are requested on MacOS Big Sur #291

Closed 17cupsofcoffee closed 2 years ago

17cupsofcoffee commented 2 years ago

Discussed in https://github.com/17cupsofcoffee/tetra/discussions/289

This appears to be an upstream issue in SDL - raised at https://github.com/libsdl-org/SDL/issues/4887.

17cupsofcoffee commented 2 years ago

@sumibi-yakitori: Migrating to an issue for any further updates, bit easier for me to read :)

If you set the SDL_JOYSTICK_HIDAPI environment variable to 0 and run with 2.0.16, do you still see the issue? People on the SDL2 GitHub are suggesting that the issue may be due to SDL interacting with a HID device that SDL sees as a joystick, but MacOS sees as a keyboard.

sumibi-yakitori commented 2 years ago

@17cupsofcoffee Thanks for taking the time to let me know! However, I'm beginning to think I don't want to waste too much of your time.

sdl2::hint::set("SDL_JOYSTICK_HIDAPI", "0");

For now, I think I'll just embed this code in my applications.

17cupsofcoffee commented 2 years ago

I definitely don't consider it a waste of time - this seems like an issue that might have gone unnoticed if you hadn't reported it, so you've probably helped out a load of other SDL2 Mac devs in the process :)

I'm not 100% sure if that code will work, as SDL_JOYSTICK_HIDAPI is an environment variable rather than an SDL hint (if i'm wrong and it does work for you, ignore me 😅). What may work, though, is adding:

std::env::set_var("SDL_JOYSTICK_HIDAPI", "0");

Which also avoids you needing to keep a sdl2 dependency in sync with mine :)

sumibi-yakitori commented 2 years ago

I was able to confirm that setting the hint flag also circumvents this problem.

But I see, the means you showed is better without the hassle of matching the library version 👍

17cupsofcoffee commented 2 years ago

SDL 2.0.18 is out, so this should be fixed now 🎉