[client,sdl] handle input events in SdlContext

This commit is contained in:
Armin Novak
2026-01-27 14:03:06 +01:00
committed by akallabeth
parent ba07955689
commit 03c350950a
4 changed files with 21 additions and 23 deletions

View File

@@ -1101,6 +1101,13 @@ bool SdlContext::handleEvent(const SDL_Event& ev)
const auto& cev = ev.clipboard;
return getClipboardChannelContext().handleEvent(cev);
}
case SDL_EVENT_KEY_DOWN:
case SDL_EVENT_KEY_UP:
{
const auto& cev = ev.key;
return getInputChannelContext().handleEvent(cev);
}
break;
default:
return true;
}

View File

@@ -115,14 +115,6 @@ static void sdl_term_handler([[maybe_unused]] int signum, [[maybe_unused]] const
case SDL_EVENT_QUIT:
freerdp_abort_connect_context(sdl->context());
break;
case SDL_EVENT_KEY_DOWN:
case SDL_EVENT_KEY_UP:
{
const SDL_KeyboardEvent* ev = &windowEvent.key;
if (!sdl->getInputChannelContext().keyboard_handle_event(ev))
return -1;
}
break;
case SDL_EVENT_RENDER_TARGETS_RESET:
std::ignore = sdl->redraw();
break;

View File

@@ -558,17 +558,16 @@ bool sdlInput::extract(const std::string& token, uint32_t& key, uint32_t& value)
return freerdp_extract_key_value(token.c_str(), &key, &value);
}
bool sdlInput::keyboard_handle_event(const SDL_KeyboardEvent* ev)
bool sdlInput::handleEvent(const SDL_KeyboardEvent& ev)
{
WINPR_ASSERT(ev);
const UINT32 rdp_scancode = scancode_to_rdp(ev->scancode);
const UINT32 rdp_scancode = scancode_to_rdp(ev.scancode);
const SDL_Keymod mods = SDL_GetModState();
if (_hotkeysEnabled && (mods & _hotkeyModmask) == _hotkeyModmask)
{
if (ev->type == SDL_EVENT_KEY_DOWN)
if (ev.type == SDL_EVENT_KEY_DOWN)
{
if (ev->scancode == _hotkeyFullscreen)
if (ev.scancode == _hotkeyFullscreen)
{
WLog_Print(_sdl->getWLog(), WLOG_INFO, "%s+<%s> pressed, toggling fullscreen state",
masktostr(_hotkeyModmask).c_str(), sdl_scancode_name(_hotkeyFullscreen));
@@ -576,7 +575,7 @@ bool sdlInput::keyboard_handle_event(const SDL_KeyboardEvent* ev)
return false;
return _sdl->toggleFullscreen();
}
if (ev->scancode == _hotkeyResizable)
if (ev.scancode == _hotkeyResizable)
{
WLog_Print(_sdl->getWLog(), WLOG_INFO, "%s+<%s> pressed, toggling resizeable state",
masktostr(_hotkeyModmask).c_str(), sdl_scancode_name(_hotkeyResizable));
@@ -585,15 +584,15 @@ bool sdlInput::keyboard_handle_event(const SDL_KeyboardEvent* ev)
return _sdl->toggleResizeable();
}
if (ev->scancode == _hotkeyGrab)
if (ev.scancode == _hotkeyGrab)
{
WLog_Print(_sdl->getWLog(), WLOG_INFO, "%s+<%s> pressed, toggling grab state",
masktostr(_hotkeyModmask).c_str(), sdl_scancode_name(_hotkeyGrab));
if (!keyboard_sync_state())
return false;
return keyboard_grab(ev->windowID, !_sdl->grabKeyboard());
return keyboard_grab(ev.windowID, !_sdl->grabKeyboard());
}
if (ev->scancode == _hotkeyDisconnect)
if (ev.scancode == _hotkeyDisconnect)
{
WLog_Print(_sdl->getWLog(), WLOG_INFO, "%s+<%s> pressed, disconnecting RDP session",
masktostr(_hotkeyModmask).c_str(), sdl_scancode_name(_hotkeyDisconnect));
@@ -602,7 +601,7 @@ bool sdlInput::keyboard_handle_event(const SDL_KeyboardEvent* ev)
freerdp_abort_connect_context(_sdl->context());
return true;
}
if (ev->scancode == _hotkeyMinimize)
if (ev.scancode == _hotkeyMinimize)
{
WLog_Print(_sdl->getWLog(), WLOG_INFO, "%s+<%s> pressed, minimizing client",
masktostr(_hotkeyModmask).c_str(), sdl_scancode_name(_hotkeyMinimize));
@@ -619,7 +618,7 @@ bool sdlInput::keyboard_handle_event(const SDL_KeyboardEvent* ev)
const DWORD sc = RDP_SCANCODE_CODE(rdp_scancode);
WLog_Print(_sdl->getWLog(), WLOG_DEBUG,
"SDL keycode: %02" PRIX32 " -> rdp code: [%04" PRIx16 "] %02" PRIX8 "%s",
ev->scancode, rdp_scancode, sc, ex ? " extended" : "");
ev.scancode, rdp_scancode, sc, ex ? " extended" : "");
}
#endif
@@ -631,11 +630,11 @@ bool sdlInput::keyboard_handle_event(const SDL_KeyboardEvent* ev)
WLog_Print(_sdl->getWLog(), WLOG_DEBUG,
"SDL keycode: %02" PRIX32 " -> remapped rdp code: [%04" PRIx16 "] %02" PRIX8
"%s",
ev->scancode, scancode, sc, ex ? " extended" : "");
ev.scancode, scancode, sc, ex ? " extended" : "");
}
#endif
return freerdp_input_send_keyboard_event_ex(
_sdl->context()->input, ev->type == SDL_EVENT_KEY_DOWN, ev->repeat, scancode);
return freerdp_input_send_keyboard_event_ex(_sdl->context()->input,
ev.type == SDL_EVENT_KEY_DOWN, ev.repeat, scancode);
}
bool sdlInput::keyboard_grab(Uint32 windowID, bool enable)

View File

@@ -47,7 +47,7 @@ class sdlInput
[[nodiscard]] bool keyboard_sync_state();
[[nodiscard]] bool keyboard_focus_in();
[[nodiscard]] bool keyboard_handle_event(const SDL_KeyboardEvent* ev);
[[nodiscard]] bool handleEvent(const SDL_KeyboardEvent& ev);
[[nodiscard]] bool keyboard_grab(Uint32 windowID, bool enable);
[[nodiscard]] bool mouse_focus(Uint32 windowID);