From e2dd2eedab581f688f555a1078bb30278487dc26 Mon Sep 17 00:00:00 2001 From: akallabeth Date: Fri, 30 Jan 2026 11:02:07 +0100 Subject: [PATCH] [client,sdl] implement display detection handling * SdlContext::detectDisplays to create a initial list of displays and their rdpMonitor configuration * SdlContext::getDisplays to query a SDL_DisplayID at runtime * SdlContext::getDisplayIds to query available SDL_DisplayID at runtime --- client/SDL/SDL3/sdl_context.cpp | 41 +++++++++++++++++++++++++++++++++ client/SDL/SDL3/sdl_context.hpp | 7 ++++++ 2 files changed, 48 insertions(+) diff --git a/client/SDL/SDL3/sdl_context.cpp b/client/SDL/SDL3/sdl_context.cpp index 56240c8ac..0a9d65921 100644 --- a/client/SDL/SDL3/sdl_context.cpp +++ b/client/SDL/SDL3/sdl_context.cpp @@ -888,6 +888,37 @@ bool SdlContext::removeDisplayWindow(SDL_DisplayID id) return true; } +bool SdlContext::detectDisplays() +{ + int count = 0; + auto display = SDL_GetDisplays(&count); + if (!display) + return false; + for (int x = 0; x < count; x++) + { + const auto id = display[x]; + auto monitor = SdlWindow::query(id, false); + addOrUpdateDisplay(id, monitor); + } + + return true; +} + +rdpMonitor SdlContext::getDisplay(SDL_DisplayID id) const +{ + return _displays.at(id); +} + +std::vector SdlContext::getDisplayIds() const +{ + std::vector keys; + for (const auto& entry : _displays) + { + keys.push_back(entry.first); + } + return keys; +} + const SdlWindow* SdlContext::getWindowForId(SDL_WindowID id) const { auto it = _windows.find(id); @@ -1091,6 +1122,16 @@ bool SdlContext::handleEvent(const SDL_TouchFingerEvent& ev) return SdlTouch::handleEvent(this, copy.tfinger); } +void SdlContext::addOrUpdateDisplay(SDL_DisplayID id, const rdpMonitor& monitor) +{ + _displays.emplace(id, monitor); +} + +void SdlContext::deleteDisplay(SDL_DisplayID id) +{ + _displays.erase(id); +} + bool SdlContext::eventToPixelCoordinates(SDL_WindowID id, SDL_Event& ev) { auto w = getWindowForId(id); diff --git a/client/SDL/SDL3/sdl_context.hpp b/client/SDL/SDL3/sdl_context.hpp index 393feee2c..b225f19ef 100644 --- a/client/SDL/SDL3/sdl_context.hpp +++ b/client/SDL/SDL3/sdl_context.hpp @@ -121,6 +121,9 @@ class SdlContext [[nodiscard]] bool addDisplayWindow(SDL_DisplayID id); [[nodiscard]] bool removeDisplayWindow(SDL_DisplayID id); + [[nodiscard]] bool detectDisplays(); + [[nodiscard]] rdpMonitor getDisplay(SDL_DisplayID id) const; + [[nodiscard]] std::vector getDisplayIds() const; [[nodiscard]] sdlDispContext& getDisplayChannelContext(); [[nodiscard]] sdlInput& getInputChannelContext(); @@ -162,6 +165,9 @@ class SdlContext [[nodiscard]] bool handleEvent(const SDL_MouseWheelEvent& ev); [[nodiscard]] bool handleEvent(const SDL_TouchFingerEvent& ev); + void addOrUpdateDisplay(SDL_DisplayID id, const rdpMonitor& monitor); + void deleteDisplay(SDL_DisplayID id); + [[nodiscard]] bool createPrimary(); [[nodiscard]] std::string windowTitle() const; [[nodiscard]] bool waitForWindowsCreated(); @@ -206,6 +212,7 @@ class SdlContext SdlConnectionDialogWrapper _dialog; + std::map _displays; std::map _windows; uint32_t _windowWidth = 0;