diff --git a/app/streaming/input/input.cpp b/app/streaming/input/input.cpp index 192f721c..aaf58b5b 100644 --- a/app/streaming/input/input.cpp +++ b/app/streaming/input/input.cpp @@ -116,6 +116,11 @@ SdlInputHandler::SdlInputHandler(StreamingPreferences& prefs, int streamWidth, i m_SpecialKeyCombos[KeyComboQuitAndExit].scanCode = SDL_SCANCODE_E; m_SpecialKeyCombos[KeyComboQuitAndExit].enabled = true; + m_SpecialKeyCombos[KeyComboToggleKeyboardGrab].keyCombo = KeyComboToggleKeyboardGrab; + m_SpecialKeyCombos[KeyComboToggleKeyboardGrab].keyCode = SDLK_k; + m_SpecialKeyCombos[KeyComboToggleKeyboardGrab].scanCode = SDL_SCANCODE_K; + m_SpecialKeyCombos[KeyComboToggleKeyboardGrab].enabled = QGuiApplication::platformName() != "eglfs"; + m_OldIgnoreDevices = SDL_GetHint(SDL_HINT_GAMECONTROLLER_IGNORE_DEVICES); m_OldIgnoreDevicesExcept = SDL_GetHint(SDL_HINT_GAMECONTROLLER_IGNORE_DEVICES_EXCEPT); @@ -319,16 +324,14 @@ bool SdlInputHandler::isCaptureActive() void SdlInputHandler::updateKeyboardGrabState() { - if (m_CaptureSystemKeysMode == StreamingPreferences::CSK_OFF) { - return; - } - - bool shouldGrab = isCaptureActive(); - Uint32 windowFlags = SDL_GetWindowFlags(m_Window); - if (m_CaptureSystemKeysMode == StreamingPreferences::CSK_FULLSCREEN && + bool shouldGrab = m_CaptureSystemKeysMode != StreamingPreferences::CSK_OFF && isCaptureActive(); + if (shouldGrab) { + Uint32 windowFlags = SDL_GetWindowFlags(m_Window); + if (m_CaptureSystemKeysMode == StreamingPreferences::CSK_FULLSCREEN && !(windowFlags & SDL_WINDOW_FULLSCREEN)) { - // Ungrab if it's fullscreen only and we left fullscreen - shouldGrab = false; + // Ungrab if it's fullscreen only and we left fullscreen + shouldGrab = false; + } } // Don't close the window on Alt+F4 when keyboard grab is enabled diff --git a/app/streaming/input/input.h b/app/streaming/input/input.h index 20bbbc33..1c5af856 100644 --- a/app/streaming/input/input.h +++ b/app/streaming/input/input.h @@ -167,6 +167,7 @@ private: KeyComboPasteText, KeyComboTogglePointerRegionLock, KeyComboQuitAndExit, + KeyComboToggleKeyboardGrab, KeyComboMax }; diff --git a/app/streaming/input/keyboard.cpp b/app/streaming/input/keyboard.cpp index 273816f4..b195f73b 100644 --- a/app/streaming/input/keyboard.cpp +++ b/app/streaming/input/keyboard.cpp @@ -153,6 +153,21 @@ void SdlInputHandler::performSpecialKeyCombo(KeyCombo combo) SDL_PushEvent(&quitExitEvent); break; + case KeyComboToggleKeyboardGrab: + SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, + "Detected keyboard grab toggle combo"); + + // Toggle the system key capture mode + if (isSystemKeyCaptureActive()) { + m_CaptureSystemKeysMode = StreamingPreferences::CSK_OFF; + } + else { + m_CaptureSystemKeysMode = StreamingPreferences::CSK_ALWAYS; + } + + updateKeyboardGrabState(); + break; + default: Q_UNREACHABLE(); }