[client,sdl] add new SdlWindow members

* get orientation of window on display
* get window size (in logical size)
This commit is contained in:
akallabeth
2026-01-24 08:08:35 +01:00
parent 2bbe3310ba
commit 743e1a6799
2 changed files with 31 additions and 13 deletions

View File

@@ -49,9 +49,9 @@ SdlWindow::SdlWindow(const std::string& title, Sint32 startupX, Sint32 startupY,
const int iscale = static_cast<int>(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<int>(width), static_cast<int>(height), flags
};
(void)window.window();
if ((flags & (SDL_WINDOW_FULLSCREEN)) != 0)
{

View File

@@ -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);