Add SDL_GetWindowICCProfile(). (#4314)

* Add SDL_GetWindowICCProfile

* Add new SDL display events

* Implement ICC profile change event for macOS

* Implement ICC profile notification for Windows

* Fix SDL_GetWindowICCProfile() for X11

* Fix compile errors
This commit is contained in:
Cacodemon345
2021-10-22 06:37:20 +06:00
committed by GitHub
parent a34fe8161f
commit 19dee1cd16
18 changed files with 261 additions and 1 deletions

View File

@@ -590,6 +590,30 @@ WIN_KeyboardHookProc(int nCode, WPARAM wParam, LPARAM lParam)
return 1;
}
static void WIN_CheckICMProfileChanged(SDL_Window* window)
{
SDL_VideoDisplay* display = SDL_GetDisplayForWindow(window);
SDL_DisplayData* data = (SDL_DisplayData*)display->driverdata;
static WCHAR currentIcmFileName[MAX_PATH] = { '\0' };
WCHAR icmFileName[MAX_PATH];
HDC hdc;
SDL_bool succeeded;
DWORD fileNameSize = MAX_PATH;
hdc = CreateDCW(data->DeviceName, NULL, NULL, NULL);
if (hdc) {
succeeded = GetICMProfileW(hdc, &fileNameSize, icmFileName);
DeleteDC(hdc);
if (succeeded) {
if (SDL_wcsncmp(currentIcmFileName, icmFileName, fileNameSize)) {
SDL_wcslcpy(currentIcmFileName, icmFileName, fileNameSize);
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_ICCPROF_CHANGED, 0, 0);
}
}
}
}
LRESULT CALLBACK
WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
@@ -655,6 +679,7 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
actually being the foreground window, but this appears to get called in all cases where
the global foreground window changes to and from this window. */
WIN_UpdateFocus(data->window);
WIN_CheckICMProfileChanged(data->window);
}
break;
@@ -1108,6 +1133,8 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
/* Forces a WM_PAINT event */
InvalidateRect(hwnd, NULL, FALSE);
WIN_CheckICMProfileChanged(data->window);
}
break;