Skip to content

Commit 262b8a6

Browse files
authored
Fix color management issue on windows
Since 2.7 cycle there seems to be bug causing wrong profile used on secondary monitors. The issue is however very trivial, the usage of incorrect GetDC() function is the culprit. Inspired by: https://discuss.pixls.us/t/darktable-windows-insider-program-11-2-25/53891/2
1 parent 610a604 commit 262b8a6

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

src/common/colorspaces.c

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@
3737
#include "colord-gtk.h"
3838
#endif
3939

40+
#ifdef _WIN32
41+
#include <dwmapi.h>
42+
#include <gdk/gdkwin32.h>
43+
#endif
44+
4045
#if 0
4146
#include <ApplicationServices/ApplicationServices.h>
4247
#include <Carbon/Carbon.h>
@@ -2009,7 +2014,19 @@ void dt_colorspaces_set_display_profile
20092014
profile_source = g_strdup("osx color profile api");
20102015
#endif
20112016
#elif defined G_OS_WIN32
2012-
HDC hdc = GetDC(NULL);
2017+
2018+
//HDC hdc = GetDC(NULL);
2019+
GtkWidget *widget = (profile_type == DT_COLORSPACE_DISPLAY2)
2020+
? darktable.develop->second_wnd
2021+
: dt_ui_center(darktable.gui->ui);
2022+
GdkWindow *window = gtk_widget_get_window(widget);
2023+
HWND hwnd = (HWND)gdk_win32_window_get_handle(window); // get window handle
2024+
HMONITOR hMonitor = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST); // get monitor handle
2025+
if(!hMonitor){ return;} //TODO log error
2026+
MONITORINFOEX monitorInfo;
2027+
monitorInfo.cbSize = sizeof(MONITORINFOEX);
2028+
if(!GetMonitorInfoW(hMonitor,(LPMONITORINFO) &monitorInfo)) { return;} //get monitor info , TODO log error
2029+
HDC hdc = CreateIC(L"MONITOR",monitorInfo.szDevice,NULL,NULL); // get device-info context of the monitor
20132030
if(hdc != NULL)
20142031
{
20152032
DWORD len = 0;
@@ -2028,7 +2045,7 @@ void dt_colorspaces_set_display_profile
20282045
}
20292046
}
20302047
g_free(wpath);
2031-
ReleaseDC(NULL, hdc);
2048+
DeleteDC(hdc);
20322049
}
20332050
profile_source = g_strdup("windows color profile api");
20342051
#endif

0 commit comments

Comments
 (0)