Use SDL's new support for keyboard grab on macOS

This commit is contained in:
Cameron Gutman 2021-08-15 14:54:26 -05:00
parent 267f9f5759
commit 666dc13c01
3 changed files with 0 additions and 70 deletions

View file

@ -176,10 +176,6 @@ SdlInputHandler::SdlInputHandler(StreamingPreferences& prefs, NvComputer*, int s
}
#endif
#ifdef Q_OS_DARWIN
CGSGetGlobalHotKeyOperatingMode(_CGSDefaultConnection(), &m_OldHotKeyMode);
#endif
// Initialize the gamepad mask with currently attached gamepads to avoid
// causing gamepads to unexpectedly disappear and reappear on the host
// during stream startup as we detect currently attached gamepads one at a time.
@ -249,10 +245,6 @@ SdlInputHandler::~SdlInputHandler()
SDL_DestroyCond(m_ClipboardHasData);
SDL_DestroyMutex(m_ClipboardLock);
#ifdef Q_OS_DARWIN
CGSSetGlobalHotKeyOperatingMode(_CGSDefaultConnection(), m_OldHotKeyMode);
#endif
#if !SDL_VERSION_ATLEAST(2, 0, 9)
SDL_QuitSubSystem(SDL_INIT_HAPTIC);
SDL_assert(!SDL_WasInit(SDL_INIT_HAPTIC));
@ -332,27 +324,11 @@ void SdlInputHandler::notifyFocusLost()
setCaptureActive(false);
}
#ifdef Q_OS_DARWIN
// Ungrab the keyboard
updateKeyboardGrabState();
#endif
// Raise all keys that are currently pressed. If we don't do this, certain keys
// used in shortcuts that cause focus loss (such as Alt+Tab) may get stuck down.
raiseAllKeys();
}
void SdlInputHandler::notifyFocusGained()
{
#ifdef Q_OS_DARWIN
// Re-grab the keyboard if it was grabbed before focus loss
// FIXME: We only do this on macOS because we get a spurious
// focus gain when in SDL_WINDOW_FULLSCREEN_DESKTOP on Windows
// immediately after losing focus by clicking on another window.
updateKeyboardGrabState();
#endif
}
bool SdlInputHandler::isCaptureActive()
{
if (SDL_GetRelativeMouseMode()) {
@ -376,18 +352,6 @@ void SdlInputHandler::updateKeyboardGrabState()
// Ungrab if it's fullscreen only and we left fullscreen
shouldGrab = false;
}
#ifdef Q_OS_DARWIN
else if (!(windowFlags & SDL_WINDOW_INPUT_FOCUS)) {
// Ungrab if we lose input focus on macOS. SDL will handle
// this internally for platforms where we use the SDL
// SDL_SetWindowKeyboardGrab() API exclusively.
//
// NB: On X11, we may not have input focus at the time of
// the initial keyboard grab update, so we must not enable
// this codepath on Linux.
shouldGrab = false;
}
#endif
// Don't close the window on Alt+F4 when keyboard grab is enabled
SDL_SetHint(SDL_HINT_WINDOWS_NO_CLOSE_ON_ALT_F4, shouldGrab ? "1" : "0");
@ -405,20 +369,12 @@ void SdlInputHandler::updateKeyboardGrabState()
if (SDL_GetWindowFlags(m_Window) & SDL_WINDOW_FULLSCREEN) {
SDL_SetWindowGrab(m_Window, SDL_TRUE);
}
#endif
#ifdef Q_OS_DARWIN
// SDL doesn't support this private macOS API
CGSSetGlobalHotKeyOperatingMode(_CGSDefaultConnection(), CGSGlobalHotKeyDisable);
#endif
}
else {
#if SDL_VERSION_ATLEAST(2, 0, 15)
// Allow the keyboard to leave the window
SDL_SetWindowKeyboardGrab(m_Window, SDL_FALSE);
#endif
#ifdef Q_OS_DARWIN
// SDL doesn't support this private macOS API
CGSSetGlobalHotKeyOperatingMode(_CGSDefaultConnection(), m_OldHotKeyMode);
#endif
}
}

View file

@ -29,25 +29,6 @@ struct GamepadState {
unsigned char lt, rt;
};
#ifdef Q_OS_DARWIN
#include <CoreGraphics/CGError.h>
extern "C" {
typedef int CGSConnection;
typedef enum {
CGSGlobalHotKeyEnable = 0,
CGSGlobalHotKeyDisable = 1,
} CGSGlobalHotKeyOperatingMode;
extern CGSConnection _CGSDefaultConnection(void);
extern CGError CGSGetGlobalHotKeyOperatingMode(CGSConnection connection,
CGSGlobalHotKeyOperatingMode* mode);
extern CGError CGSSetGlobalHotKeyOperatingMode(CGSConnection connection,
CGSGlobalHotKeyOperatingMode mode);
}
#endif
#define MAX_GAMEPADS 4
#define MAX_FINGERS 2
@ -98,8 +79,6 @@ public:
void notifyFocusLost();
void notifyFocusGained();
bool isCaptureActive();
bool isSystemKeyCaptureActive();
@ -190,10 +169,6 @@ private:
StreamingPreferences::CaptureSysKeysMode m_CaptureSystemKeysMode;
int m_MouseCursorCapturedVisibilityState;
#ifdef Q_OS_DARWIN
CGSGlobalHotKeyOperatingMode m_OldHotKeyMode;
#endif
struct {
KeyCombo keyCombo;
SDL_Keycode keyCode;

View file

@ -1421,7 +1421,6 @@ void Session::execInternal()
if (m_Preferences->muteOnFocusLoss) {
m_AudioMuted = false;
}
m_InputHandler->notifyFocusGained();
break;
case SDL_WINDOWEVENT_LEAVE:
m_InputHandler->notifyMouseLeave();