[client,sdl] fix high dpi detection
* convert dpi value to percentage used by RDP * fix detection of current monitor resolution for SDL windows
This commit is contained in:
parent
1d64c8d93c
commit
aa2c48840a
@ -323,8 +323,6 @@ BOOL sdlDispContext::handle_window_event(const SDL_WindowEvent* ev)
|
||||
case SDL_WINDOWEVENT_ENTER:
|
||||
WINPR_ASSERT(_sdl);
|
||||
_sdl->input.keyboard_grab(ev->windowID, SDL_TRUE);
|
||||
|
||||
|
||||
return _sdl->input.keyboard_focus_in();
|
||||
case SDL_WINDOWEVENT_FOCUS_GAINED:
|
||||
case SDL_WINDOWEVENT_TAKE_FOCUS:
|
||||
|
@ -357,8 +357,6 @@ static BOOL sdl_end_paint_process(rdpContext* context)
|
||||
int w, h;
|
||||
SDL_GetWindowSize(window.window, &w, &h);
|
||||
|
||||
//window.offset_x = 0;
|
||||
//window.offset_y = 0;
|
||||
if (!freerdp_settings_get_bool(context->settings, FreeRDP_SmartSizing))
|
||||
{
|
||||
if (gdi->width < w)
|
||||
@ -505,7 +503,6 @@ static BOOL sdl_pre_connect(freerdp* instance)
|
||||
WINPR_ASSERT(instance->context);
|
||||
|
||||
auto sdl = get_context(instance->context);
|
||||
//sdl->highDpi = TRUE; // If High DPI is available, we want unscaled data, RDP can scale itself.
|
||||
|
||||
auto settings = instance->context->settings;
|
||||
WINPR_ASSERT(settings);
|
||||
@ -605,8 +602,6 @@ static void sdl_cleanup_sdl(SdlContext* sdl)
|
||||
SDL_Quit();
|
||||
}
|
||||
|
||||
|
||||
|
||||
static BOOL sdl_create_windows(SdlContext* sdl)
|
||||
{
|
||||
WINPR_ASSERT(sdl);
|
||||
@ -614,30 +609,28 @@ static BOOL sdl_create_windows(SdlContext* sdl)
|
||||
auto title = sdl_window_get_title(sdl->context()->settings);
|
||||
BOOL rc = FALSE;
|
||||
|
||||
// TODO: Multimonitor setup
|
||||
|
||||
|
||||
UINT32 windowCount = freerdp_settings_get_uint32(sdl->context()->settings, FreeRDP_MonitorCount);
|
||||
UINT32 windowCount =
|
||||
freerdp_settings_get_uint32(sdl->context()->settings, FreeRDP_MonitorCount);
|
||||
|
||||
for (UINT32 x = 0; x < windowCount; x++)
|
||||
{
|
||||
auto monitor = static_cast<rdpMonitor*>(
|
||||
freerdp_settings_get_pointer_array_writable(sdl->context()->settings, FreeRDP_MonitorDefArray, x));
|
||||
auto monitor = static_cast<rdpMonitor*>(freerdp_settings_get_pointer_array_writable(
|
||||
sdl->context()->settings, FreeRDP_MonitorDefArray, x));
|
||||
|
||||
Uint32 w = monitor->width;
|
||||
Uint32 h = monitor->height;
|
||||
if (!(sdl->context()->settings->UseMultimon || sdl->context()->settings->Fullscreen) ){
|
||||
if (!(sdl->context()->settings->UseMultimon || sdl->context()->settings->Fullscreen))
|
||||
{
|
||||
w = sdl->context()->settings->DesktopWidth;
|
||||
h = sdl->context()->settings->DesktopHeight;
|
||||
}
|
||||
|
||||
|
||||
sdl_window_t window = {};
|
||||
Uint32 flags = SDL_WINDOW_SHOWN;
|
||||
Uint32 startupX = SDL_WINDOWPOS_UNDEFINED;
|
||||
Uint32 startupY = SDL_WINDOWPOS_UNDEFINED;
|
||||
|
||||
if (monitor->highDpi)
|
||||
if (monitor->attributes.desktopScaleFactor > 100)
|
||||
{
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 1)
|
||||
flags |= SDL_WINDOW_ALLOW_HIGHDPI;
|
||||
@ -649,24 +642,22 @@ static BOOL sdl_create_windows(SdlContext* sdl)
|
||||
flags |= SDL_WINDOW_FULLSCREEN;
|
||||
}
|
||||
|
||||
|
||||
if (sdl->context()->settings->UseMultimon)
|
||||
{
|
||||
flags |= SDL_WINDOW_BORDERLESS;
|
||||
startupX = monitor->x;
|
||||
startupY = monitor->y;
|
||||
window.offset_x = 0-startupX;
|
||||
window.offset_y = 0-startupY;
|
||||
}else{
|
||||
window.offset_x = 0 - startupX;
|
||||
window.offset_y = 0 - startupY;
|
||||
}
|
||||
else
|
||||
{
|
||||
window.offset_x = 0;
|
||||
window.offset_y = 0;
|
||||
}
|
||||
|
||||
|
||||
window.window = SDL_CreateWindow(title, startupX, startupY,
|
||||
static_cast<int>(w), static_cast<int>(h), flags);
|
||||
|
||||
|
||||
window.window = SDL_CreateWindow(title, startupX, startupY, static_cast<int>(w),
|
||||
static_cast<int>(h), flags);
|
||||
if (!window.window)
|
||||
goto fail;
|
||||
sdl->windows.push_back(window);
|
||||
@ -700,7 +691,6 @@ static BOOL sdl_wait_create_windows(SdlContext* sdl)
|
||||
|
||||
static int sdl_run(SdlContext* sdl)
|
||||
{
|
||||
|
||||
int rc = -1;
|
||||
WINPR_ASSERT(sdl);
|
||||
|
||||
@ -738,11 +728,6 @@ static int sdl_run(SdlContext* sdl)
|
||||
windowEvent.type);
|
||||
#endif
|
||||
std::lock_guard<CriticalSection> lock(sdl->critical);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
switch (windowEvent.type)
|
||||
{
|
||||
case SDL_QUIT:
|
||||
@ -875,48 +860,37 @@ static int sdl_run(SdlContext* sdl)
|
||||
{
|
||||
if (!(curFlags & SDL_WINDOW_BORDERLESS))
|
||||
{
|
||||
//need to do some resizing
|
||||
UINT32 w = GetSystemMetrics(SM_CXSCREEN);
|
||||
UINT32 h = GetSystemMetrics(SM_CYSCREEN);
|
||||
if (sdl->context()->settings->UseMultimon)
|
||||
{
|
||||
w = GetSystemMetrics(SM_CXVIRTUALSCREEN);
|
||||
h = GetSystemMetrics(SM_CYVIRTUALSCREEN);
|
||||
}
|
||||
auto idx = SDL_GetWindowDisplayIndex(window);
|
||||
SDL_DisplayMode mode = {};
|
||||
SDL_GetCurrentDisplayMode(idx, &mode);
|
||||
|
||||
|
||||
SDL_RestoreWindow(window); //Maximize so we can see the caption and bits
|
||||
SDL_SetWindowBordered(window, SDL_FALSE );
|
||||
SDL_SetWindowPosition(window,0,0);
|
||||
SDL_SetWindowAlwaysOnTop(window,SDL_TRUE);
|
||||
SDL_RestoreWindow(window); // Maximize so we can see the caption and
|
||||
// bits
|
||||
SDL_SetWindowBordered(window, SDL_FALSE);
|
||||
SDL_SetWindowPosition(window, 0, 0);
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 16)
|
||||
SDL_SetWindowAlwaysOnTop(window, SDL_TRUE);
|
||||
#endif
|
||||
SDL_RaiseWindow(window);
|
||||
SDL_SetWindowSize(window,static_cast<int>(w), static_cast<int>(h));
|
||||
|
||||
SDL_SetWindowSize(window, mode.w, mode.h);
|
||||
}
|
||||
}else
|
||||
}
|
||||
else
|
||||
{
|
||||
if (curFlags & SDL_WINDOW_BORDERLESS)
|
||||
{
|
||||
|
||||
SDL_SetWindowBordered(window, SDL_TRUE);
|
||||
SDL_SetWindowAlwaysOnTop(window,SDL_FALSE);
|
||||
SDL_SetWindowBordered(window, SDL_TRUE);
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 16)
|
||||
SDL_SetWindowAlwaysOnTop(window, SDL_FALSE);
|
||||
#endif
|
||||
SDL_RaiseWindow(window);
|
||||
SDL_MinimizeWindow(window); //Maximize so we can see the caption and bits
|
||||
SDL_MaximizeWindow(window); //Maximize so we can see the caption and bits
|
||||
|
||||
SDL_MinimizeWindow(
|
||||
window); // Maximize so we can see the caption and bits
|
||||
SDL_MaximizeWindow(
|
||||
window); // Maximize so we can see the caption and bits
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
const BOOL isSet = (curFlags & SDL_WINDOW_FULLSCREEN) ? TRUE : FALSE;
|
||||
if (enter)
|
||||
curFlags |= SDL_WINDOW_FULLSCREEN;
|
||||
else
|
||||
curFlags &= ~SDL_WINDOW_FULLSCREEN;
|
||||
|
||||
if ((enter && !isSet) || (!enter && isSet))
|
||||
SDL_SetWindowFullscreen(window, curFlags);
|
||||
*/
|
||||
}
|
||||
break;
|
||||
case SDL_USEREVENT_POINTER_NULL:
|
||||
|
@ -63,7 +63,6 @@ class SdlContext
|
||||
bool resizeable = false;
|
||||
bool grab_mouse = false;
|
||||
bool grab_kbd = false;
|
||||
//bool highDpi = false;
|
||||
|
||||
std::vector<sdl_window_t> windows;
|
||||
|
||||
|
@ -483,7 +483,9 @@ BOOL sdlInput::mouse_focus(Uint32 windowID)
|
||||
|
||||
SDL_RaiseWindow(window);
|
||||
return TRUE;
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
return TRUE;
|
||||
};
|
||||
}
|
||||
|
@ -187,12 +187,13 @@ static BOOL sdl_apply_display_properties(SdlContext* sdl)
|
||||
freerdp_settings_get_pointer_array(settings, FreeRDP_MonitorIds, x));
|
||||
WINPR_ASSERT(id);
|
||||
|
||||
float hdpi;
|
||||
float vdpi;
|
||||
float ddpi = 1.0f;
|
||||
float hdpi = 1.0f;
|
||||
float vdpi = 1.0f;
|
||||
SDL_Rect rect = {};
|
||||
|
||||
SDL_GetDisplayBounds(*id, &rect);
|
||||
SDL_GetDisplayDPI(*id, nullptr, &hdpi, &vdpi);
|
||||
SDL_GetDisplayDPI(*id, &ddpi, &hdpi, &vdpi);
|
||||
|
||||
bool highDpi = hdpi > 100;
|
||||
|
||||
@ -239,14 +240,15 @@ static BOOL sdl_apply_display_properties(SdlContext* sdl)
|
||||
freerdp_settings_get_pointer_array_writable(settings, FreeRDP_MonitorDefArray, x));
|
||||
WINPR_ASSERT(monitor);
|
||||
|
||||
/* windows uses 96 dpi as 'default' and the scale factors are in percent. */
|
||||
const auto factor = ddpi / 96.0f * 100.0f;
|
||||
monitor->orig_screen = x;
|
||||
monitor->x = rect.x;
|
||||
monitor->y = rect.y;
|
||||
monitor->width = rect.w;
|
||||
monitor->height = rect.h;
|
||||
monitor->highDpi = highDpi;
|
||||
monitor->is_primary = (rect.x == 0) && (rect.y == 0);
|
||||
monitor->attributes.desktopScaleFactor = 100;
|
||||
monitor->attributes.desktopScaleFactor = factor;
|
||||
monitor->attributes.deviceScaleFactor = 100;
|
||||
monitor->attributes.orientation = rdp_orientation;
|
||||
monitor->attributes.physicalWidth = rect.w / hdpi;
|
||||
|
@ -200,12 +200,12 @@ BOOL sdl_handle_mouse_motion(SdlContext* sdl, const SDL_MouseMotionEvent* ev)
|
||||
{
|
||||
WINPR_ASSERT(sdl);
|
||||
WINPR_ASSERT(ev);
|
||||
|
||||
sdl->input.mouse_focus(ev->windowID);
|
||||
const BOOL relative =
|
||||
freerdp_settings_get_bool(sdl->context()->settings, FreeRDP_MouseUseRelativeMove);
|
||||
INT32 x = relative ? ev->xrel : ev->x;
|
||||
INT32 y = relative ? ev->yrel : ev->y;
|
||||
|
||||
sdl_scale_coordinates(sdl, ev->windowID, &x, &y, TRUE, TRUE);
|
||||
return freerdp_client_send_button_event(sdl->common(), relative, PTR_FLAGS_MOVE, x, y);
|
||||
}
|
||||
|
@ -427,7 +427,6 @@ extern "C"
|
||||
INT32 height;
|
||||
UINT32 is_primary;
|
||||
UINT32 orig_screen;
|
||||
BOOL highDpi;
|
||||
MONITOR_ATTRIBUTES attributes;
|
||||
} rdpMonitor;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user