Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,6 @@ target_link_libraries(gui PUBLIC clipper)
if(MAHI_GUI_NATIVE_DIAGS)
target_link_libraries(gui PUBLIC nfd)
endif()
if (WIN32)
target_link_libraries(gui PUBLIC Shcore)
endif()
if(CMAKE_SYSTEM MATCHES "Linux")
# https://techoverflow.net/2019/04/17/how-to-fix-gcc-undefined-reference-to-std-experimental-filesystem/
target_link_libraries(gui PUBLIC GL stdc++fs)
Expand Down
37 changes: 27 additions & 10 deletions src/Mahi/Gui/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,35 @@ static ImGuiContext* configureImGui(GLFWwindow *window, float dpi_scale);
///////////////////////////////////////////////////////////////////////////////

#ifdef _WIN32
float enable_dpi_aware() {
SetProcessDpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE);
const POINT ptZero = { 0, 0 };
auto monitor = MonitorFromPoint(ptZero, MONITOR_DEFAULTTOPRIMARY);
UINT dpiX, dpiY;
auto result = GetDpiForMonitor(monitor, MDT_EFFECTIVE_DPI, &dpiX, &dpiY);
return (float)dpiX / (float)USER_DEFAULT_SCREEN_DPI;
float enable_dpi_aware() {
auto shcore = LoadLibraryA("Shcore.dll");
auto user32 = LoadLibraryA("User32.dll");
if (shcore && user32) {
auto set_process_dpi_awareness = reinterpret_cast<decltype(SetProcessDpiAwareness) *>(
GetProcAddress(shcore, "SetProcessDpiAwareness"));
auto get_dpi_for_monitor = reinterpret_cast<decltype(GetDpiForMonitor) *>(
GetProcAddress(shcore, "GetDpiForMonitor"));
auto monitor_from_point = reinterpret_cast<decltype(MonitorFromPoint) *>(
GetProcAddress(user32, "MonitorFromPoint"));

if (set_process_dpi_awareness && get_dpi_for_monitor && monitor_from_point) {
set_process_dpi_awareness(PROCESS_PER_MONITOR_DPI_AWARE);
const POINT ptZero = {0, 0};
auto monitor = monitor_from_point(ptZero, MONITOR_DEFAULTTOPRIMARY);
UINT dpiX, dpiY;
auto result = get_dpi_for_monitor(monitor, MDT_EFFECTIVE_DPI, &dpiX, &dpiY);
return (float)dpiX / (float)USER_DEFAULT_SCREEN_DPI;
}
}
if (shcore)
FreeLibrary(shcore);
if (user32)
FreeLibrary(user32);

return 1.0f;
}
#else
float enable_dpi_aware() {
return 1.0f;
}
float enable_dpi_aware() { return 1.0f; }
#endif

///////////////////////////////////////////////////////////////////////////////
Expand Down