From 743e1a6799cfb71a936f98f7ddafd0b3db0eb353 Mon Sep 17 00:00:00 2001 From: akallabeth Date: Sat, 24 Jan 2026 08:08:35 +0100 Subject: [PATCH] [client,sdl] add new SdlWindow members * get orientation of window on display * get window size (in logical size) --- client/SDL/SDL3/sdl_window.cpp | 40 ++++++++++++++++++++++++---------- client/SDL/SDL3/sdl_window.hpp | 4 +++- 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/client/SDL/SDL3/sdl_window.cpp b/client/SDL/SDL3/sdl_window.cpp index 70a244145..54f95f82b 100644 --- a/client/SDL/SDL3/sdl_window.cpp +++ b/client/SDL/SDL3/sdl_window.cpp @@ -49,9 +49,9 @@ SdlWindow::SdlWindow(const std::string& title, Sint32 startupX, Sint32 startupY, const int iscale = static_cast(sc * 100.0f); auto w = 100 * width / iscale; auto h = 100 * height / iscale; - (void)resize({ w, h }); + std::ignore = resize({ w, h }); SDL_SetHint(SDL_HINT_APP_NAME, ""); - (void)SDL_SyncWindow(_window); + std::ignore = SDL_SyncWindow(_window); } SdlWindow::SdlWindow(SdlWindow&& other) noexcept @@ -65,7 +65,7 @@ SdlWindow::~SdlWindow() SDL_DestroyWindow(_window); } -Uint32 SdlWindow::id() const +SDL_WindowID SdlWindow::id() const { if (!_window) return 0; @@ -90,6 +90,17 @@ SDL_Rect SdlWindow::rect() const return rect; } +SDL_Rect SdlWindow::bounds() const +{ + SDL_Rect rect = {}; + if (_window) + { + SDL_GetWindowPosition(_window, &rect.x, &rect.y); + SDL_GetWindowSize(_window, &rect.w, &rect.h); + } + return rect; +} + SDL_Window* SdlWindow::window() const { return _window; @@ -141,8 +152,8 @@ rdpMonitor SdlWindow::monitor(bool isPrimary) const mon.y = rect.y; } - auto orientation = SDL_GetCurrentDisplayOrientation(did); - mon.attributes.orientation = sdl::utils::orientaion_to_rdp(orientation); + const auto orient = orientation(); + mon.attributes.orientation = sdl::utils::orientaion_to_rdp(orient); auto primary = SDL_GetPrimaryDisplay(); mon.is_primary = isPrimary || (SDL_GetWindowID(_window) == primary); @@ -160,6 +171,12 @@ float SdlWindow::scale() const return SDL_GetWindowDisplayScale(_window); } +SDL_DisplayOrientation SdlWindow::orientation() const +{ + const auto did = displayIndex(); + return SDL_GetCurrentDisplayOrientation(did); +} + bool SdlWindow::grabKeyboard(bool enable) { if (!_window) @@ -180,31 +197,31 @@ void SdlWindow::setBordered(bool bordered) { if (_window) SDL_SetWindowBordered(_window, bordered); - (void)SDL_SyncWindow(_window); + std::ignore = SDL_SyncWindow(_window); } void SdlWindow::raise() { SDL_RaiseWindow(_window); - (void)SDL_SyncWindow(_window); + std::ignore = SDL_SyncWindow(_window); } void SdlWindow::resizeable(bool use) { SDL_SetWindowResizable(_window, use); - (void)SDL_SyncWindow(_window); + std::ignore = SDL_SyncWindow(_window); } void SdlWindow::fullscreen(bool enter) { - (void)SDL_SetWindowFullscreen(_window, enter); - (void)SDL_SyncWindow(_window); + std::ignore = SDL_SetWindowFullscreen(_window, enter); + std::ignore = SDL_SyncWindow(_window); } void SdlWindow::minimize() { SDL_MinimizeWindow(_window); - (void)SDL_SyncWindow(_window); + std::ignore = SDL_SyncWindow(_window); } bool SdlWindow::resize(const SDL_Point& size) @@ -313,7 +330,6 @@ SdlWindow SdlWindow::create(SDL_DisplayID id, const std::string& title, Uint32 f SdlWindow window{ ss.str(), startupX, startupY, static_cast(width), static_cast(height), flags }; - (void)window.window(); if ((flags & (SDL_WINDOW_FULLSCREEN)) != 0) { diff --git a/client/SDL/SDL3/sdl_window.hpp b/client/SDL/SDL3/sdl_window.hpp index 629d1ee01..7d40dafc6 100644 --- a/client/SDL/SDL3/sdl_window.hpp +++ b/client/SDL/SDL3/sdl_window.hpp @@ -39,9 +39,10 @@ class SdlWindow SdlWindow& operator=(const SdlWindow& other) = delete; SdlWindow& operator=(SdlWindow&& other) = delete; - [[nodiscard]] Uint32 id() const; + [[nodiscard]] SDL_WindowID id() const; [[nodiscard]] SDL_DisplayID displayIndex() const; [[nodiscard]] SDL_Rect rect() const; + [[nodiscard]] SDL_Rect bounds() const; [[nodiscard]] SDL_Window* window() const; [[nodiscard]] Sint32 offsetX() const; @@ -53,6 +54,7 @@ class SdlWindow [[nodiscard]] rdpMonitor monitor(bool isPrimary) const; [[nodiscard]] float scale() const; + [[nodiscard]] SDL_DisplayOrientation orientation() const; [[nodiscard]] bool grabKeyboard(bool enable); [[nodiscard]] bool grabMouse(bool enable);