RetroArch icon indicating copy to clipboard operation
RetroArch copied to clipboard

Check for focus before reading joypad input.

Open zoltanvb opened this issue 1 year ago • 4 comments

Description

The udev and sdl joypad drivers were reading input in all cases. Now state is not monitored if window has no focus, connect / disconnect events are still processed.

Related Issues

Fixes #16261

zoltanvb avatar Feb 22 '24 20:02 zoltanvb

Is this how the other input drivers work as well? We wouldn't want to introduce something specific to certain input driver implementations in a non-unified way. Also I think it's the wrong approach to do this 'video_driver_has_focus()' call inside the input driver implementation, should be done higher-level.

Also in addition to it being a generic option that should work across the board for all input drivers, I feel this should remain entirely optional and tied behind a setting instead of forced, there might be usecases where we still want input for a non-focused window, this is in fact a handy feature when you want to still be able to play a game in an unfocused window with your gamepad.

LibretroAdmin avatar Feb 23 '24 19:02 LibretroAdmin

some people specifically request input detection in the background. it's a nasty surprise if you're not wanting, that, though, and end up wreaking havoc.

I'm loathe to add more options unnecessarily, but it might be worthwhile here.

hizzlekizzle avatar Feb 23 '24 20:02 hizzlekizzle

In general I feel that Windows drivers do it correctly, which is: keyboard is ignored when app is not in focus, and controllers never.

sonninnos avatar Feb 23 '24 20:02 sonninnos

Udev keyboard/mouse does something similar already, but not much else. Hm, it may be better to unify it, putting it behind an option may solve my concerns for a general solution - I wonder if video context driver focus (which is understood as keyboard focus on desktop) matches the user's perception of focus on all platforms.

zoltanvb avatar Feb 23 '24 21:02 zoltanvb

Ye I feel this should be behind a setting with the following options (you can decide on the names of each option)

0 - receives both keyboard and controller input when out of focus 1 - keyboard ignored when app is not in focus, but controller input still received 2 - keyboard and controller input ignored when app is not in focus

1 should be the default setting value.

LibretroAdmin avatar Mar 19 '24 12:03 LibretroAdmin

I'm fine with the approach (though option 0 will always be a bit misleading, as the possibility of getting keyboard input when out of focus is very much platform/driver dependent). I'm just wary of doing it centrally in input_driver.c, which is probably the 3rd most complex piece in whole RA I have visited so far, so it may take a while. I can close the PR until that time, if preferred.

zoltanvb avatar Mar 19 '24 18:03 zoltanvb