Reorganize a couple mouse and keyboard functions

This commit is contained in:
Cameron Gutman
2026-09-26 15:01:07 -05:00
parent 8ec572517b
commit b75fe0d932
3 changed files with 39 additions and 39 deletions
-39
View File
@@ -270,45 +270,6 @@ void SdlInputHandler::setWindow(SDL_Window *window)
m_Window = window; m_Window = window;
} }
void SdlInputHandler::raiseAllKeys()
{
if (m_KeysDown.isEmpty()) {
return;
}
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
"Raising %d keys",
(int)m_KeysDown.count());
for (auto keyDown : std::as_const(m_KeysDown)) {
LiSendKeyboardEvent(keyDown, KEY_ACTION_UP, 0);
}
m_KeysDown.clear();
}
void SdlInputHandler::notifyMouseLeave()
{
if (m_NeedsManualCaptureOnLeave) {
// SDL on Windows doesn't send the mouse button up until the mouse re-enters the window
// after leaving it. This breaks some of the Aero snap gestures, so we'll capture it to
// allow us to receive the mouse button up events later.
//
// On macOS and X11, capturing the mouse allows us to receive mouse motion outside the
// window (button up already worked without capture).
if (m_AbsoluteMouseMode && isCaptureActive()) {
// NB: Not using SDL_GetGlobalMouseState() because we want our state not the system's
Uint32 mouseState = SDL_GetMouseState(nullptr, nullptr);
for (Uint32 button = SDL_BUTTON_LEFT; button <= SDL_BUTTON_X2; button++) {
if (mouseState & SDL_BUTTON(button)) {
SDL_CaptureMouse(SDL_TRUE);
break;
}
}
}
}
}
void SdlInputHandler::notifyFocusLost() void SdlInputHandler::notifyFocusLost()
{ {
// Release mouse cursor when another window is activated (e.g. by using ALT+TAB). // Release mouse cursor when another window is activated (e.g. by using ALT+TAB).
+17
View File
@@ -478,3 +478,20 @@ void SdlInputHandler::handleKeyEvent(SDL_KeyboardEvent* event)
modifiers, modifiers,
shouldNotConvertToScanCodeOnServer ? SS_KBE_FLAG_NON_NORMALIZED : 0); shouldNotConvertToScanCodeOnServer ? SS_KBE_FLAG_NON_NORMALIZED : 0);
} }
void SdlInputHandler::raiseAllKeys()
{
if (m_KeysDown.isEmpty()) {
return;
}
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
"Raising %d keys",
(int)m_KeysDown.count());
for (auto keyDown : std::as_const(m_KeysDown)) {
LiSendKeyboardEvent(keyDown, KEY_ACTION_UP, 0);
}
m_KeysDown.clear();
}
+22
View File
@@ -4,6 +4,28 @@
#include "SDL_compat.h" #include "SDL_compat.h"
#include "streaming/streamutils.h" #include "streaming/streamutils.h"
void SdlInputHandler::notifyMouseLeave()
{
if (m_NeedsManualCaptureOnLeave) {
// SDL on Windows doesn't send the mouse button up until the mouse re-enters the window
// after leaving it. This breaks some of the Aero snap gestures, so we'll capture it to
// allow us to receive the mouse button up events later.
//
// On macOS and X11, capturing the mouse allows us to receive mouse motion outside the
// window (button up already worked without capture).
if (m_AbsoluteMouseMode && isCaptureActive()) {
// NB: Not using SDL_GetGlobalMouseState() because we want our state not the system's
Uint32 mouseState = SDL_GetMouseState(nullptr, nullptr);
for (Uint32 button = SDL_BUTTON_LEFT; button <= SDL_BUTTON_X2; button++) {
if (mouseState & SDL_BUTTON(button)) {
SDL_CaptureMouse(SDL_TRUE);
break;
}
}
}
}
}
void SdlInputHandler::handleMouseButtonEvent(SDL_MouseButtonEvent* event) void SdlInputHandler::handleMouseButtonEvent(SDL_MouseButtonEvent* event)
{ {
int button; int button;