Skip to content

Commit

Permalink
Windows: Fix ICC profile detection not working per-monitor
Browse files Browse the repository at this point in the history
  • Loading branch information
jdpurcell committed Oct 14, 2024
1 parent 14f4d45 commit fcea73f
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions src/qvwin32functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,22 +165,31 @@ QByteArray QVWin32Functions::getIccProfileForWindow(const QWindow *window)
{
QByteArray result;
const HWND hWnd = reinterpret_cast<HWND>(window->winId());
const HDC hDC = GetDC(hWnd);
if (hDC)
const HMONITOR hMonitor = MonitorFromWindow(hWnd, MONITOR_DEFAULTTONEAREST);
if (hMonitor)
{
WCHAR profilePathBuff[MAX_PATH];
DWORD profilePathSize = MAX_PATH;
if (GetICMProfileW(hDC, &profilePathSize, profilePathBuff))
MONITORINFOEXW monitorInfo;
monitorInfo.cbSize = sizeof(MONITORINFOEXW);
if (GetMonitorInfoW(hMonitor, &monitorInfo))
{
QString profilePath = QString::fromWCharArray(profilePathBuff);
QFile file(profilePath);
if (file.open(QIODevice::ReadOnly))
const HDC hDC = CreateICW(monitorInfo.szDevice, monitorInfo.szDevice, NULL, NULL);
if (hDC)
{
result = file.readAll();
file.close();
WCHAR profilePathBuff[MAX_PATH];
DWORD profilePathSize = MAX_PATH;
if (GetICMProfileW(hDC, &profilePathSize, profilePathBuff))
{
QString profilePath = QString::fromWCharArray(profilePathBuff);
QFile file(profilePath);
if (file.open(QIODevice::ReadOnly))
{
result = file.readAll();
file.close();
}
}
ReleaseDC(hWnd, hDC);
}
}
ReleaseDC(hWnd, hDC);
}
return result;
}

0 comments on commit fcea73f

Please sign in to comment.