Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows: Fix ICC profile detection not working per-monitor #724

Merged
merged 1 commit into from
Oct 19, 2024
Merged
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
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;
}