[client,SDL] Handle window sizing on scaled displays

This commit is contained in:
2026-03-04 17:45:19 +09:00
parent 0a7fd3811c
commit efea17a5fe
3 changed files with 26 additions and 6 deletions

View File

@@ -1084,6 +1084,7 @@ bool SdlContext::handleEvent(const SDL_WindowEvent& ev)
case SDL_EVENT_WINDOW_MOUSE_ENTER:
return restoreCursor();
case SDL_EVENT_WINDOW_DISPLAY_SCALE_CHANGED:
window->resizeToScale();
if (isConnected())
{
if (!window->fill())

View File

@@ -49,20 +49,20 @@ SdlWindow::SdlWindow(SDL_DisplayID id, const std::string& title, const SDL_Rect&
_window = SDL_CreateWindowWithProperties(props);
SDL_DestroyProperties(props);
auto sc = scale();
const int iscale = static_cast<int>(sc * 100.0f);
auto w = 100 * rect.w / iscale;
auto h = 100 * rect.h / iscale;
std::ignore = resize({ w, h });
SDL_SetHint(SDL_HINT_APP_NAME, "");
std::ignore = SDL_SyncWindow(_window);
_monitor = query(_window, id, true);
_intended_w = rect.w;
_intended_h = rect.h;
resizeToScale();
}
SdlWindow::SdlWindow(SdlWindow&& other) noexcept
: _window(other._window), _displayID(other._displayID), _offset_x(other._offset_x),
_offset_y(other._offset_y), _monitor(other._monitor)
_offset_y(other._offset_y), _monitor(other._monitor), _intended_w(other._intended_w),
_intended_h(other._intended_h)
{
other._window = nullptr;
}
@@ -218,6 +218,22 @@ bool SdlWindow::resize(const SDL_Point& size)
return SDL_SetWindowSize(_window, size.x, size.y);
}
void SdlWindow::resizeToScale()
{
if (!_window)
return;
if (_intended_w <= 0 || _intended_h <= 0)
return;
if (SDL_GetWindowFlags(_window) & SDL_WINDOW_FULLSCREEN)
return;
auto sc = scale();
const int iscale = static_cast<int>(sc * 100.0f);
auto w = 100 * _intended_w / iscale;
auto h = 100 * _intended_h / iscale;
std::ignore = resize({ w, h });
}
bool SdlWindow::drawRect(SDL_Surface* surface, SDL_Point offset, const SDL_Rect& srcRect)
{
WINPR_ASSERT(surface);

View File

@@ -67,6 +67,7 @@ class SdlWindow
void minimize();
[[nodiscard]] bool resize(const SDL_Point& size);
void resizeToScale();
[[nodiscard]] bool drawRect(SDL_Surface* surface, SDL_Point offset, const SDL_Rect& srcRect);
[[nodiscard]] bool drawRects(SDL_Surface* surface, SDL_Point offset,
@@ -107,4 +108,6 @@ class SdlWindow
Sint32 _offset_x = 0;
Sint32 _offset_y = 0;
rdpMonitor _monitor{};
Sint32 _intended_w = 0;
Sint32 _intended_h = 0;
};