mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-05-19 11:18:27 +00:00
Always allow controller events for virtual joysticks regardless of focus state
Refrence https://github.com/libsdl-org/SDL/pull/7024
This commit is contained in:
parent
61f76efb85
commit
d94f2a9ee5
1 changed files with 11 additions and 6 deletions
|
@ -1314,13 +1314,18 @@ void SDL_QuitJoysticks(void)
|
||||||
SDL_UnlockJoysticks();
|
SDL_UnlockJoysticks();
|
||||||
}
|
}
|
||||||
|
|
||||||
static SDL_bool SDL_PrivateJoystickShouldIgnoreEvent()
|
static SDL_bool SDL_PrivateJoystickShouldIgnoreEvent(SDL_Joystick *joystick)
|
||||||
{
|
{
|
||||||
if (SDL_joystick_allows_background_events) {
|
if (SDL_joystick_allows_background_events) {
|
||||||
return SDL_FALSE;
|
return SDL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SDL_HasWindows() && SDL_GetKeyboardFocus() == NULL) {
|
if (SDL_HasWindows() && SDL_GetKeyboardFocus() == NULL) {
|
||||||
|
if (SDL_IsJoystickVIRTUAL(joystick->guid)) {
|
||||||
|
/* Always allow events for virtual controllers, they're not affected by focus */
|
||||||
|
return SDL_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
/* We have windows but we don't have focus, ignore the event. */
|
/* We have windows but we don't have focus, ignore the event. */
|
||||||
return SDL_TRUE;
|
return SDL_TRUE;
|
||||||
}
|
}
|
||||||
|
@ -1520,7 +1525,7 @@ int SDL_SendJoystickAxis(Uint64 timestamp, SDL_Joystick *joystick, Uint8 axis, S
|
||||||
/* We ignore events if we don't have keyboard focus, except for centering
|
/* We ignore events if we don't have keyboard focus, except for centering
|
||||||
* events.
|
* events.
|
||||||
*/
|
*/
|
||||||
if (SDL_PrivateJoystickShouldIgnoreEvent()) {
|
if (SDL_PrivateJoystickShouldIgnoreEvent(joystick)) {
|
||||||
if (info->sending_initial_value ||
|
if (info->sending_initial_value ||
|
||||||
(value > info->zero && value >= info->value) ||
|
(value > info->zero && value >= info->value) ||
|
||||||
(value < info->zero && value <= info->value)) {
|
(value < info->zero && value <= info->value)) {
|
||||||
|
@ -1564,7 +1569,7 @@ int SDL_SendJoystickHat(Uint64 timestamp, SDL_Joystick *joystick, Uint8 hat, Uin
|
||||||
/* We ignore events if we don't have keyboard focus, except for centering
|
/* We ignore events if we don't have keyboard focus, except for centering
|
||||||
* events.
|
* events.
|
||||||
*/
|
*/
|
||||||
if (SDL_PrivateJoystickShouldIgnoreEvent()) {
|
if (SDL_PrivateJoystickShouldIgnoreEvent(joystick)) {
|
||||||
if (value != SDL_HAT_CENTERED) {
|
if (value != SDL_HAT_CENTERED) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1622,7 +1627,7 @@ int SDL_SendJoystickButton(Uint64 timestamp, SDL_Joystick *joystick, Uint8 butto
|
||||||
|
|
||||||
/* We ignore events if we don't have keyboard focus, except for button
|
/* We ignore events if we don't have keyboard focus, except for button
|
||||||
* release. */
|
* release. */
|
||||||
if (SDL_PrivateJoystickShouldIgnoreEvent()) {
|
if (SDL_PrivateJoystickShouldIgnoreEvent(joystick)) {
|
||||||
if (state == SDL_PRESSED) {
|
if (state == SDL_PRESSED) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -2922,7 +2927,7 @@ int SDL_SendJoystickTouchpad(Uint64 timestamp, SDL_Joystick *joystick, int touch
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We ignore events if we don't have keyboard focus, except for touch release */
|
/* We ignore events if we don't have keyboard focus, except for touch release */
|
||||||
if (SDL_PrivateJoystickShouldIgnoreEvent()) {
|
if (SDL_PrivateJoystickShouldIgnoreEvent(joystick)) {
|
||||||
if (event_type != SDL_GAMEPADTOUCHPADUP) {
|
if (event_type != SDL_GAMEPADTOUCHPADUP) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -2961,7 +2966,7 @@ int SDL_SendJoystickSensor(Uint64 timestamp, SDL_Joystick *joystick, SDL_SensorT
|
||||||
SDL_AssertJoysticksLocked();
|
SDL_AssertJoysticksLocked();
|
||||||
|
|
||||||
/* We ignore events if we don't have keyboard focus */
|
/* We ignore events if we don't have keyboard focus */
|
||||||
if (SDL_PrivateJoystickShouldIgnoreEvent()) {
|
if (SDL_PrivateJoystickShouldIgnoreEvent(joystick)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue