From 085483e88577ea91400a1ee46bc4321340824c51 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Tue, 3 Jul 2018 18:52:23 -0300 Subject: [PATCH] -Fix fullscreen on Windows with a HiDPI monitor but a non-HiDPI project -Replaced some viewport size calls to screen size, since viewport size should be deprecated at this point.. --- platform/windows/os_windows.cpp | 70 +++++++++++++++++++-------------- scene/main/scene_tree.cpp | 7 ++-- scene/main/viewport.cpp | 2 +- 3 files changed, 46 insertions(+), 33 deletions(-) diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp index f52c8881d47..216be1064a7 100644 --- a/platform/windows/os_windows.cpp +++ b/platform/windows/os_windows.cpp @@ -70,6 +70,30 @@ __attribute__((visibility("default"))) DWORD NvOptimusEnablement = 0x00000001; #define WM_TOUCH 576 #endif +typedef struct { + int count; + int screen; + Size2 size; +} EnumSizeData; + +typedef struct { + int count; + int screen; + Point2 pos; +} EnumPosData; + +static BOOL CALLBACK _MonitorEnumProcSize(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData) { + + EnumSizeData *data = (EnumSizeData *)dwData; + if (data->count == data->screen) { + data->size.x = lprcMonitor->right - lprcMonitor->left; + data->size.y = lprcMonitor->bottom - lprcMonitor->top; + } + + data->count++; + return TRUE; +} + static String format_error_message(DWORD id) { LPWSTR messageBuffer = NULL; @@ -980,6 +1004,7 @@ Error OS_Windows::initialize(const VideoMode &p_desired, int p_video_driver, int WNDCLASSEXW wc; if (is_hidpi_allowed()) { + print_line("hidpi aware?"); HMODULE Shcore = LoadLibraryW(L"Shcore.dll"); if (Shcore != NULL) { @@ -1024,6 +1049,7 @@ Error OS_Windows::initialize(const VideoMode &p_desired, int p_video_driver, int pre_fs_valid = true; if (video_mode.fullscreen) { + /* this returns DPI unaware size, commenting DEVMODE current; memset(¤t, 0, sizeof(current)); EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, ¤t); @@ -1031,6 +1057,16 @@ Error OS_Windows::initialize(const VideoMode &p_desired, int p_video_driver, int WindowRect.right = current.dmPelsWidth; WindowRect.bottom = current.dmPelsHeight; + */ + + EnumSizeData data = { 0, 0, Size2() }; + EnumDisplayMonitors(NULL, NULL, _MonitorEnumProcSize, (LPARAM)&data); + + WindowRect.right = data.size.width; + WindowRect.bottom = data.size.height; + + print_line("wr right " + itos(WindowRect.right) + ", " + itos(WindowRect.bottom)); + /* DEVMODE dmScreenSettings; memset(&dmScreenSettings,0,sizeof(dmScreenSettings)); dmScreenSettings.dmSize=sizeof(dmScreenSettings); @@ -1455,12 +1491,6 @@ void OS_Windows::set_current_screen(int p_screen) { set_window_position(ofs + get_screen_position(p_screen)); } -typedef struct { - int count; - int screen; - Point2 pos; -} EnumPosData; - static BOOL CALLBACK _MonitorEnumProcPos(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData) { EnumPosData *data = (EnumPosData *)dwData; @@ -1480,24 +1510,6 @@ Point2 OS_Windows::get_screen_position(int p_screen) const { return data.pos; } -typedef struct { - int count; - int screen; - Size2 size; -} EnumSizeData; - -static BOOL CALLBACK _MonitorEnumProcSize(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData) { - - EnumSizeData *data = (EnumSizeData *)dwData; - if (data->count == data->screen) { - data->size.x = lprcMonitor->right - lprcMonitor->left; - data->size.y = lprcMonitor->bottom - lprcMonitor->top; - } - - data->count++; - return TRUE; -} - Size2 OS_Windows::get_screen_size(int p_screen) const { EnumSizeData data = { 0, p_screen == -1 ? get_current_screen() : p_screen, Size2() }; @@ -1557,16 +1569,16 @@ Size2 OS_Windows::get_real_window_size() const { } void OS_Windows::set_window_size(const Size2 p_size) { - video_mode.width = p_size.width; - video_mode.height = p_size.height; + int w = p_size.width; + int h = p_size.height; + + video_mode.width = w; + video_mode.height = h; if (video_mode.fullscreen) { return; } - int w = p_size.width; - int h = p_size.height; - RECT rect; GetWindowRect(hWnd, &rect); diff --git a/scene/main/scene_tree.cpp b/scene/main/scene_tree.cpp index 5caba8ef204..6438616cf22 100644 --- a/scene/main/scene_tree.cpp +++ b/scene/main/scene_tree.cpp @@ -498,7 +498,8 @@ bool SceneTree::idle(float p_time) { _notify_group_pause("idle_process_internal", Node::NOTIFICATION_INTERNAL_PROCESS); _notify_group_pause("idle_process", Node::NOTIFICATION_PROCESS); - Size2 win_size = Size2(OS::get_singleton()->get_video_mode().width, OS::get_singleton()->get_video_mode().height); + Size2 win_size = Size2(OS::get_singleton()->get_window_size().width, OS::get_singleton()->get_window_size().height); + if (win_size != last_screen_size) { last_screen_size = win_size; @@ -1117,7 +1118,7 @@ void SceneTree::_update_root_rect() { } //actual screen video mode - Size2 video_mode = Size2(OS::get_singleton()->get_video_mode().width, OS::get_singleton()->get_video_mode().height); + Size2 video_mode = Size2(OS::get_singleton()->get_window_size().width, OS::get_singleton()->get_window_size().height); Size2 desired_res = stretch_min; Size2 viewport_size; @@ -2009,7 +2010,7 @@ SceneTree::SceneTree() { stretch_aspect = STRETCH_ASPECT_IGNORE; stretch_shrink = 1; - last_screen_size = Size2(OS::get_singleton()->get_video_mode().width, OS::get_singleton()->get_video_mode().height); + last_screen_size = Size2(OS::get_singleton()->get_window_size().width, OS::get_singleton()->get_window_size().height); _update_root_rect(); if (ScriptDebugger::get_singleton()) { diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index a894b82a944..1c837c0a8f7 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -626,7 +626,7 @@ Rect2 Viewport::get_visible_rect() const { if (size == Size2()) { - r = Rect2(Point2(), Size2(OS::get_singleton()->get_video_mode().width, OS::get_singleton()->get_video_mode().height)); + r = Rect2(Point2(), Size2(OS::get_singleton()->get_window_size().width, OS::get_singleton()->get_window_size().height)); } else { r = Rect2(Point2(), size);