Skip to content

Commit

Permalink
Check for focus before reading input.
Browse files Browse the repository at this point in the history
The udev and sdl joypad drivers were reading input in all cases.
Now state is not changed if window has no focus, connect / disconnect
events are still processed.
  • Loading branch information
zoltanvb committed Feb 22, 2024
1 parent 70daba6 commit 44b0e6d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 2 additions & 1 deletion input/drivers_joypad/sdl_joypad.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include "../input_driver.h"

#include "../../gfx/video_driver.h"
#include "../../tasks/tasks_internal.h"
#include "../../verbosity.h"

Expand Down Expand Up @@ -422,7 +423,7 @@ static int16_t sdl_joypad_state(
uint16_t port_idx = joypad_info->joy_idx;
sdl_joypad_t *pad = (sdl_joypad_t*)&sdl_pads[port_idx];

if (!pad || !pad->joypad)
if (!pad || !pad->joypad || !video_driver_has_focus())
return 0;
if (port_idx >= MAX_USERS)
return 0;
Expand Down
4 changes: 3 additions & 1 deletion input/drivers_joypad/udev_joypad.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
#include "../../configuration.h"
#include "../../config.def.h"

#include "../../gfx/video_driver.h"

#include "../../tasks/tasks_internal.h"

#include "../../verbosity.h"
Expand Down Expand Up @@ -518,7 +520,7 @@ static void udev_joypad_poll(void)
}
}

for (p = 0; p < MAX_USERS; p++)
for (p = 0; p < MAX_USERS && video_driver_has_focus(); p++)
{
int i, len;
struct input_event events[32];
Expand Down

0 comments on commit 44b0e6d

Please sign in to comment.