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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549
diff --git a/include/SDL_video.h b/include/SDL_video.h
index 6cc85ad..c65aa25 100644
--- a/include/SDL_video.h
+++ b/include/SDL_video.h
@@ -174,7 +174,9 @@ typedef enum
SDL_WINDOWEVENT_FOCUS_LOST, /**< Window has lost keyboard focus */
SDL_WINDOWEVENT_CLOSE, /**< The window manager requests that the window be closed */
SDL_WINDOWEVENT_TAKE_FOCUS, /**< Window is being offered a focus (should SetWindowInputFocus() on itself or a subwindow, or ignore) */
- SDL_WINDOWEVENT_HIT_TEST /**< Window had a hit test that wasn't SDL_HITTEST_NORMAL. */
+ SDL_WINDOWEVENT_HIT_TEST, /**< Window had a hit test that wasn't SDL_HITTEST_NORMAL. */
+ SDL_WINDOWEVENT_ICCPROF_CHANGED,/**< The ICC profile of the window's display has changed. */
+ SDL_WINDOWEVENT_DISPLAY_CHANGED /**< Window has been moved to display data1. */
} SDL_WindowEventID;
/**
@@ -614,6 +616,17 @@ extern DECLSPEC int SDLCALL SDL_GetWindowDisplayMode(SDL_Window * window,
SDL_DisplayMode * mode);
/**
+ * Get the raw ICC profile data for the screen the window is currently on.
+ * Data returned should be freed with SDL_free.
+ *
+ * \param window the window to query
+ * \param size the size of the ICC profile
+ * \returns the raw ICC profile data on success or NULL on failure;
+ * call SDL_GetError() for more information.
+ */
+extern DECLSPEC void* SDLCALL SDL_GetWindowICCProfile(SDL_Window * window, size_t* size);
+
+/**
* Get the pixel format associated with the window.
*
* \param window the window to query
diff --git a/src/dynapi/SDL_dynapi_overrides.h b/src/dynapi/SDL_dynapi_overrides.h
index 77f4347..005f7a7 100644
--- a/src/dynapi/SDL_dynapi_overrides.h
+++ b/src/dynapi/SDL_dynapi_overrides.h
@@ -822,3 +822,4 @@
#define SDL_RenderSetVSync SDL_RenderSetVSync_REAL
#define SDL_asprintf SDL_asprintf_REAL
#define SDL_vasprintf SDL_vasprintf_REAL
+#define SDL_GetWindowICCProfile SDL_GetWindowICCProfile_REAL
diff --git a/src/dynapi/SDL_dynapi_procs.h b/src/dynapi/SDL_dynapi_procs.h
index c383ea6..f30eb41 100644
--- a/src/dynapi/SDL_dynapi_procs.h
+++ b/src/dynapi/SDL_dynapi_procs.h
@@ -889,3 +889,4 @@ SDL_DYNAPI_PROC(int,SDL_RenderSetVSync,(SDL_Renderer *a, int b),(a,b),return)
SDL_DYNAPI_PROC(int,SDL_asprintf,(char **a, SDL_PRINTF_FORMAT_STRING const char *b, ...),(a,b),return)
#endif
SDL_DYNAPI_PROC(int,SDL_vasprintf,(char **a, const char *b, va_list c),(a,b,c),return)
+SDL_DYNAPI_PROC(void*,SDL_GetWindowICCProfile,(SDL_Window *a, size_t *b),(a,b),return)
diff --git a/src/events/SDL_windowevents.c b/src/events/SDL_windowevents.c
index aa31f1e..d984e2f 100644
--- a/src/events/SDL_windowevents.c
+++ b/src/events/SDL_windowevents.c
@@ -110,6 +110,7 @@ SDL_SendWindowEvent(SDL_Window * window, Uint8 windowevent, int data1,
}
window->x = data1;
window->y = data2;
+ SDL_OnWindowMoved(window);
break;
case SDL_WINDOWEVENT_RESIZED:
if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
diff --git a/src/video/SDL_sysvideo.h b/src/video/SDL_sysvideo.h
index 0be19c1..844a7a6 100644
--- a/src/video/SDL_sysvideo.h
+++ b/src/video/SDL_sysvideo.h
@@ -83,6 +83,7 @@ struct SDL_Window
int max_w, max_h;
Uint32 flags;
Uint32 last_fullscreen_flags;
+ Uint32 display_index;
/* Stored position and size for windowed mode */
SDL_Rect windowed;
@@ -233,6 +234,7 @@ struct SDL_VideoDevice
void (*SetWindowFullscreen) (_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen);
int (*SetWindowGammaRamp) (_THIS, SDL_Window * window, const Uint16 * ramp);
int (*GetWindowGammaRamp) (_THIS, SDL_Window * window, Uint16 * ramp);
+ void* (*GetWindowICCProfile) (_THIS, SDL_Window * window, size_t* size);
void (*SetWindowMouseGrab) (_THIS, SDL_Window * window, SDL_bool grabbed);
void (*SetWindowKeyboardGrab) (_THIS, SDL_Window * window, SDL_bool grabbed);
void (*DestroyWindow) (_THIS, SDL_Window * window);
@@ -466,6 +468,7 @@ extern SDL_bool SDL_HasWindows(void);
extern void SDL_OnWindowShown(SDL_Window * window);
extern void SDL_OnWindowHidden(SDL_Window * window);
+extern void SDL_OnWindowMoved(SDL_Window * window);
extern void SDL_OnWindowResized(SDL_Window * window);
extern void SDL_OnWindowMinimized(SDL_Window * window);
extern void SDL_OnWindowRestored(SDL_Window * window);
diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c
index 371a6e5..18268a9 100644
--- a/src/video/SDL_video.c
+++ b/src/video/SDL_video.c
@@ -1207,6 +1207,16 @@ SDL_GetWindowDisplayMode(SDL_Window * window, SDL_DisplayMode * mode)
return 0;
}
+void*
+SDL_GetWindowICCProfile(SDL_Window * window, size_t* size)
+{
+ if (!_this->GetWindowICCProfile) {
+ SDL_Unsupported();
+ return NULL;
+ }
+ return _this->GetWindowICCProfile(_this, window, size);
+}
+
Uint32
SDL_GetWindowPixelFormat(SDL_Window * window)
{
@@ -1628,6 +1638,7 @@ SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags)
window->brightness = 1.0f;
window->next = _this->windows;
window->is_destroying = SDL_FALSE;
+ window->display_index = SDL_GetWindowDisplayIndex(window);
if (_this->windows) {
_this->windows->prev = window;
@@ -1707,6 +1718,7 @@ SDL_CreateWindowFrom(const void *data)
return NULL;
}
+ window->display_index = SDL_GetWindowDisplayIndex(window);
PrepareDragAndDropSupport(window);
return window;
@@ -2844,10 +2856,27 @@ SDL_OnWindowHidden(SDL_Window * window)
void
SDL_OnWindowResized(SDL_Window * window)
{
+ int display_index = SDL_GetWindowDisplayIndex(window);
window->surface_valid = SDL_FALSE;
if (!window->is_destroying) {
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_SIZE_CHANGED, window->w, window->h);
+
+ if (display_index != window->display_index && display_index != -1) {
+ window->display_index = display_index;
+ SDL_SendWindowEvent(window, SDL_WINDOWEVENT_DISPLAY_CHANGED, window->display_index, 0);
+ }
+ }
+}
+
+void
+SDL_OnWindowMoved(SDL_Window * window)
+{
+ int display_index = SDL_GetWindowDisplayIndex(window);
+
+ if (!window->is_destroying && display_index != window->display_index && display_index != -1) {
+ window->display_index = display_index;
+ SDL_SendWindowEvent(window, SDL_WINDOWEVENT_DISPLAY_CHANGED, window->display_index, 0);
}
}
diff --git a/src/video/cocoa/SDL_cocoavideo.m b/src/video/cocoa/SDL_cocoavideo.m
index f70ab74..8f943b4 100644
--- a/src/video/cocoa/SDL_cocoavideo.m
+++ b/src/video/cocoa/SDL_cocoavideo.m
@@ -102,6 +102,7 @@ Cocoa_CreateDevice(int devindex)
device->SetWindowFullscreen = Cocoa_SetWindowFullscreen;
device->SetWindowGammaRamp = Cocoa_SetWindowGammaRamp;
device->GetWindowGammaRamp = Cocoa_GetWindowGammaRamp;
+ device->GetWindowICCProfile = Cocoa_GetWindowICCProfile;
device->SetWindowMouseGrab = Cocoa_SetWindowMouseGrab;
device->SetWindowKeyboardGrab = Cocoa_SetWindowKeyboardGrab;
device->DestroyWindow = Cocoa_DestroyWindow;
diff --git a/src/video/cocoa/SDL_cocoawindow.h b/src/video/cocoa/SDL_cocoawindow.h
index 37bec66..8dca3c0 100644
--- a/src/video/cocoa/SDL_cocoawindow.h
+++ b/src/video/cocoa/SDL_cocoawindow.h
@@ -80,6 +80,7 @@ typedef enum
-(void) windowDidBecomeKey:(NSNotification *) aNotification;
-(void) windowDidResignKey:(NSNotification *) aNotification;
-(void) windowDidChangeBackingProperties:(NSNotification *) aNotification;
+-(void) windowDidChangeScreenProfile:(NSNotification *) aNotification;
-(void) windowWillEnterFullScreen:(NSNotification *) aNotification;
-(void) windowDidEnterFullScreen:(NSNotification *) aNotification;
-(void) windowWillExitFullScreen:(NSNotification *) aNotification;
@@ -151,6 +152,7 @@ extern void Cocoa_SetWindowResizable(_THIS, SDL_Window * window, SDL_bool resiza
extern void Cocoa_SetWindowAlwaysOnTop(_THIS, SDL_Window * window, SDL_bool on_top);
extern void Cocoa_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen);
extern int Cocoa_SetWindowGammaRamp(_THIS, SDL_Window * window, const Uint16 * ramp);
+extern void* Cocoa_GetWindowICCProfile(_THIS, SDL_Window * window, size_t * size);
extern int Cocoa_GetWindowGammaRamp(_THIS, SDL_Window * window, Uint16 * ramp);
extern void Cocoa_SetWindowMouseGrab(_THIS, SDL_Window * window, SDL_bool grabbed);
extern void Cocoa_DestroyWindow(_THIS, SDL_Window * window);
diff --git a/src/video/cocoa/SDL_cocoawindow.m b/src/video/cocoa/SDL_cocoawindow.m
index 7a1446f..617799d 100644
--- a/src/video/cocoa/SDL_cocoawindow.m
+++ b/src/video/cocoa/SDL_cocoawindow.m
@@ -352,6 +352,7 @@ SetWindowStyle(SDL_Window * window, NSUInteger style)
[center addObserver:self selector:@selector(windowDidBecomeKey:) name:NSWindowDidBecomeKeyNotification object:window];
[center addObserver:self selector:@selector(windowDidResignKey:) name:NSWindowDidResignKeyNotification object:window];
[center addObserver:self selector:@selector(windowDidChangeBackingProperties:) name:NSWindowDidChangeBackingPropertiesNotification object:window];
+ [center addObserver:self selector:@selector(windowDidChangeScreenProfile:) name:NSWindowDidChangeScreenProfileNotification object:window];
[center addObserver:self selector:@selector(windowWillEnterFullScreen:) name:NSWindowWillEnterFullScreenNotification object:window];
[center addObserver:self selector:@selector(windowDidEnterFullScreen:) name:NSWindowDidEnterFullScreenNotification object:window];
[center addObserver:self selector:@selector(windowWillExitFullScreen:) name:NSWindowWillExitFullScreenNotification object:window];
@@ -483,6 +484,7 @@ SetWindowStyle(SDL_Window * window, NSUInteger style)
[center removeObserver:self name:NSWindowDidBecomeKeyNotification object:window];
[center removeObserver:self name:NSWindowDidResignKeyNotification object:window];
[center removeObserver:self name:NSWindowDidChangeBackingPropertiesNotification object:window];
+ [center removeObserver:self name:NSWindowDidChangeScreenProfileNotification object:window];
[center removeObserver:self name:NSWindowWillEnterFullScreenNotification object:window];
[center removeObserver:self name:NSWindowDidEnterFullScreenNotification object:window];
[center removeObserver:self name:NSWindowWillExitFullScreenNotification object:window];
@@ -750,6 +752,11 @@ SetWindowStyle(SDL_Window * window, NSUInteger style)
}
}
+- (void)windowDidChangeScreenProfile:(NSNotification *)aNotification
+{
+ SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_ICCPROF_CHANGED, 0, 0);
+}
+
- (void)windowWillEnterFullScreen:(NSNotification *)aNotification
{
SDL_Window *window = _data->window;
@@ -1981,6 +1988,42 @@ Cocoa_SetWindowGammaRamp(_THIS, SDL_Window * window, const Uint16 * ramp)
return 0;
}
+void*
+Cocoa_GetWindowICCProfile(_THIS, SDL_Window * window, size_t * size)
+{
+ SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
+ NSWindow *nswindow = data->nswindow;
+ NSScreen *screen = [nswindow screen];
+ NSData* iccProfileData = nil;
+ void* retIccProfileData = NULL;
+
+ if (screen == nil) {
+ SDL_SetError("Could not get screen of window.");
+ return NULL;
+ }
+
+ if ([screen colorSpace] == nil) {
+ SDL_SetError("Could not get colorspace information of screen.");
+ return NULL;
+ }
+
+ iccProfileData = [[screen colorSpace] ICCProfileData];
+ if (iccProfileData == nil) {
+ SDL_SetError("Could not get ICC profile data.");
+ return NULL;
+ }
+
+ retIccProfileData = SDL_malloc([iccProfileData length]);
+ if (!retIccProfileData) {
+ SDL_OutOfMemory();
+ return NULL;
+ }
+
+ [iccProfileData getBytes:retIccProfileData length:[iccProfileData length]];
+ *size = [iccProfileData length];
+ return retIccProfileData;
+}
+
int
Cocoa_GetWindowGammaRamp(_THIS, SDL_Window * window, Uint16 * ramp)
{
diff --git a/src/video/windows/SDL_windowsevents.c b/src/video/windows/SDL_windowsevents.c
index a1bdaf9..24765fd 100644
--- a/src/video/windows/SDL_windowsevents.c
+++ b/src/video/windows/SDL_windowsevents.c
@@ -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;
diff --git a/src/video/windows/SDL_windowsvideo.c b/src/video/windows/SDL_windowsvideo.c
index a80c20c..2968e91 100644
--- a/src/video/windows/SDL_windowsvideo.c
+++ b/src/video/windows/SDL_windowsvideo.c
@@ -165,6 +165,7 @@ WIN_CreateDevice(int devindex)
device->SetWindowAlwaysOnTop = WIN_SetWindowAlwaysOnTop;
device->SetWindowFullscreen = WIN_SetWindowFullscreen;
device->SetWindowGammaRamp = WIN_SetWindowGammaRamp;
+ device->GetWindowICCProfile = WIN_GetWindowICCProfile;
device->GetWindowGammaRamp = WIN_GetWindowGammaRamp;
device->SetWindowMouseGrab = WIN_SetWindowMouseGrab;
device->SetWindowKeyboardGrab = WIN_SetWindowKeyboardGrab;
diff --git a/src/video/windows/SDL_windowswindow.c b/src/video/windows/SDL_windowswindow.c
index b6e9dc3..892dde7 100644
--- a/src/video/windows/SDL_windowswindow.c
+++ b/src/video/windows/SDL_windowswindow.c
@@ -725,6 +725,32 @@ WIN_SetWindowGammaRamp(_THIS, SDL_Window * window, const Uint16 * ramp)
return succeeded ? 0 : -1;
}
+void*
+WIN_GetWindowICCProfile(_THIS, SDL_Window * window, size_t * size)
+{
+ SDL_VideoDisplay* display = SDL_GetDisplayForWindow(window);
+ SDL_DisplayData* data = (SDL_DisplayData*)display->driverdata;
+ HDC hdc;
+ BOOL succeeded = FALSE;
+ WCHAR filename[MAX_PATH];
+ DWORD fileNameSize = MAX_PATH;
+ void* iccProfileData = NULL;
+
+ hdc = CreateDCW(data->DeviceName, NULL, NULL, NULL);
+ if (hdc) {
+ succeeded = GetICMProfileW(hdc, &fileNameSize, filename);
+ DeleteDC(hdc);
+ }
+
+ if (succeeded) {
+ iccProfileData = SDL_LoadFile(WIN_StringToUTF8(filename), size);
+ if (!iccProfileData)
+ SDL_SetError("Could not open ICC profile");
+ }
+
+ return iccProfileData;
+}
+
int
WIN_GetWindowGammaRamp(_THIS, SDL_Window * window, Uint16 * ramp)
{
diff --git a/src/video/windows/SDL_windowswindow.h b/src/video/windows/SDL_windowswindow.h
index 015fb0f..66a5754 100644
--- a/src/video/windows/SDL_windowswindow.h
+++ b/src/video/windows/SDL_windowswindow.h
@@ -79,6 +79,7 @@ extern void WIN_SetWindowResizable(_THIS, SDL_Window * window, SDL_bool resizabl
extern void WIN_SetWindowAlwaysOnTop(_THIS, SDL_Window * window, SDL_bool on_top);
extern void WIN_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen);
extern int WIN_SetWindowGammaRamp(_THIS, SDL_Window * window, const Uint16 * ramp);
+extern void* WIN_GetWindowICCProfile(_THIS, SDL_Window * window, size_t * size);
extern int WIN_GetWindowGammaRamp(_THIS, SDL_Window * window, Uint16 * ramp);
extern void WIN_SetWindowMouseGrab(_THIS, SDL_Window * window, SDL_bool grabbed);
extern void WIN_SetWindowKeyboardGrab(_THIS, SDL_Window * window, SDL_bool grabbed);
diff --git a/src/video/x11/SDL_x11events.c b/src/video/x11/SDL_x11events.c
index e14f8d8..f070dcc 100644
--- a/src/video/x11/SDL_x11events.c
+++ b/src/video/x11/SDL_x11events.c
@@ -820,6 +820,31 @@ X11_DispatchEvent(_THIS, XEvent *xevent)
X11_UpdateKeymap(_this);
SDL_SendKeymapChangedEvent();
+ } else if (xevent->type == PropertyNotify && videodata && videodata->windowlist) {
+ char* name_of_atom = X11_XGetAtomName(display, xevent->xproperty.atom);
+
+ if (SDL_strncmp(name_of_atom, "_ICC_PROFILE", sizeof("_ICC_PROFILE") - 1) == 0) {
+ XWindowAttributes attrib;
+ int screennum;
+ for (i = 0; i < videodata->numwindows; ++i) {
+ if (videodata->windowlist[i] != NULL) {
+ data = videodata->windowlist[i];
+ X11_XGetWindowAttributes(display, data->xwindow, &attrib);
+ screennum = X11_XScreenNumberOfScreen(attrib.screen);
+ if (screennum == 0 && SDL_strcmp(name_of_atom, "_ICC_PROFILE") == 0) {
+ SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_ICCPROF_CHANGED, 0, 0);
+ } else if (SDL_strncmp(name_of_atom, "_ICC_PROFILE_", sizeof("_ICC_PROFILE_") - 1) == 0 && SDL_strlen(name_of_atom) > sizeof("_ICC_PROFILE_") - 1) {
+ int iccscreennum = SDL_atoi(&name_of_atom[sizeof("_ICC_PROFILE_") - 1]);
+
+ if (screennum == iccscreennum) {
+ SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_ICCPROF_CHANGED, 0, 0);
+ }
+ }
+ }
+ }
+ }
+
+ if (name_of_atom) X11_XFree(name_of_atom);
}
return;
}
diff --git a/src/video/x11/SDL_x11sym.h b/src/video/x11/SDL_x11sym.h
index c4cb03f..3c273cf 100644
--- a/src/video/x11/SDL_x11sym.h
+++ b/src/video/x11/SDL_x11sym.h
@@ -109,6 +109,7 @@ SDL_X11_SYM(int,XRaiseWindow,(Display* a,Window b),(a,b),return)
SDL_X11_SYM(int,XReparentWindow,(Display* a,Window b,Window c,int d,int e),(a,b,c,d,e),return)
SDL_X11_SYM(int,XResetScreenSaver,(Display* a),(a),return)
SDL_X11_SYM(int,XResizeWindow,(Display* a,Window b,unsigned int c,unsigned int d),(a,b,c,d),return)
+SDL_X11_SYM(int,XScreenNumberOfScreen,(Screen* a),(a),return)
SDL_X11_SYM(int,XSelectInput,(Display* a,Window b,long c),(a,b,c),return)
SDL_X11_SYM(Status,XSendEvent,(Display* a,Window b,Bool c,long d,XEvent* e),(a,b,c,d,e),return)
SDL_X11_SYM(XErrorHandler,XSetErrorHandler,(XErrorHandler a),(a),return)
diff --git a/src/video/x11/SDL_x11video.c b/src/video/x11/SDL_x11video.c
index eb3ecc3..a67bce8 100644
--- a/src/video/x11/SDL_x11video.c
+++ b/src/video/x11/SDL_x11video.c
@@ -215,6 +215,7 @@ X11_CreateDevice(int devindex)
device->GetDisplayBounds = X11_GetDisplayBounds;
device->GetDisplayUsableBounds = X11_GetDisplayUsableBounds;
device->GetDisplayDPI = X11_GetDisplayDPI;
+ device->GetWindowICCProfile = X11_GetWindowICCProfile;
device->SetDisplayMode = X11_SetDisplayMode;
device->SuspendScreenSaver = X11_SuspendScreenSaver;
device->PumpEvents = X11_PumpEvents;
diff --git a/src/video/x11/SDL_x11window.c b/src/video/x11/SDL_x11window.c
index df34096..8d81cb0 100644
--- a/src/video/x11/SDL_x11window.c
+++ b/src/video/x11/SDL_x11window.c
@@ -670,6 +670,9 @@ X11_CreateWindow(_THIS, SDL_Window * window)
PropertyChangeMask | StructureNotifyMask |
KeymapStateMask | fevent));
+ /* For _ICC_PROFILE. */
+ X11_XSelectInput(display, RootWindow(display, screen), PropertyChangeMask);
+
X11_XkbSelectEvents(display, XkbUseCoreKbd, XkbStateNotifyMask, XkbStateNotifyMask);
X11_XFlush(display);
@@ -1581,6 +1584,86 @@ X11_SetWindowGammaRamp(_THIS, SDL_Window * window, const Uint16 * ramp)
return 0;
}
+typedef struct {
+ unsigned char *data;
+ int format, count;
+ Atom type;
+} SDL_x11Prop;
+
+/* Reads property
+ Must call X11_XFree on results
+ */
+static void X11_ReadProperty(SDL_x11Prop *p, Display *disp, Window w, Atom prop)
+{
+ unsigned char *ret=NULL;
+ Atom type;
+ int fmt;
+ unsigned long count;
+ unsigned long bytes_left;
+ int bytes_fetch = 0;
+
+ do {
+ if (ret != 0) X11_XFree(ret);
+ X11_XGetWindowProperty(disp, w, prop, 0, bytes_fetch, False, AnyPropertyType, &type, &fmt, &count, &bytes_left, &ret);
+ bytes_fetch += bytes_left;
+ } while (bytes_left != 0);
+
+ p->data=ret;
+ p->format=fmt;
+ p->count=count;
+ p->type=type;
+}
+
+void*
+X11_GetWindowICCProfile(_THIS, SDL_Window * window, size_t * size)
+{
+ SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
+ Display *display = data->videodata->display;
+ XWindowAttributes attributes;
+ Atom icc_profile_atom;
+ char icc_atom_string[sizeof("_ICC_PROFILE_") + 12];
+ void* ret_icc_profile_data = NULL;
+ CARD8* icc_profile_data;
+ int real_format;
+ unsigned long real_nitems;
+ SDL_x11Prop atomProp;
+
+ X11_XGetWindowAttributes(display, X11_IsWindowLegacyFullscreen(_this, window) ? data->fswindow : data->xwindow, &attributes);
+ if (X11_XScreenNumberOfScreen(attributes.screen) > 0) {
+ SDL_snprintf(icc_atom_string, sizeof("_ICC_PROFILE_") + 12, "%s%d", "_ICC_PROFILE_", X11_XScreenNumberOfScreen(attributes.screen));
+ } else {
+ SDL_strlcpy(icc_atom_string, "_ICC_PROFILE", sizeof("_ICC_PROFILE"));
+ }
+ X11_XGetWindowAttributes(display, RootWindowOfScreen(attributes.screen), &attributes);
+
+ icc_profile_atom = X11_XInternAtom(display, icc_atom_string, True);
+ if (icc_profile_atom == None) {
+ SDL_SetError("Screen is not calibrated.\n");
+ return NULL;
+ }
+
+ X11_ReadProperty(&atomProp, display, RootWindowOfScreen(attributes.screen), icc_profile_atom);
+ real_format = atomProp.format;
+ real_nitems = atomProp.count;
+ icc_profile_data = atomProp.data;
+ if (real_format == None) {
+ SDL_SetError("Screen is not calibrated.\n");
+ return NULL;
+ }
+
+ ret_icc_profile_data = SDL_malloc(real_nitems);
+ if (!ret_icc_profile_data) {
+ SDL_OutOfMemory();
+ return NULL;
+ }
+
+ SDL_memcpy(ret_icc_profile_data, icc_profile_data, real_nitems);
+ *size = real_nitems;
+ X11_XFree(icc_profile_data);
+
+ return ret_icc_profile_data;
+}
+
void
X11_SetWindowMouseGrab(_THIS, SDL_Window * window, SDL_bool grabbed)
{
diff --git a/src/video/x11/SDL_x11window.h b/src/video/x11/SDL_x11window.h
index 3b2da5d..a2fbaac 100644
--- a/src/video/x11/SDL_x11window.h
+++ b/src/video/x11/SDL_x11window.h
@@ -102,6 +102,7 @@ extern void X11_SetWindowResizable(_THIS, SDL_Window * window, SDL_bool resizabl
extern void X11_SetWindowAlwaysOnTop(_THIS, SDL_Window * window, SDL_bool on_top);
extern void X11_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen);
extern int X11_SetWindowGammaRamp(_THIS, SDL_Window * window, const Uint16 * ramp);
+extern void* X11_GetWindowICCProfile(_THIS, SDL_Window * window, size_t * size);
extern void X11_SetWindowMouseGrab(_THIS, SDL_Window * window, SDL_bool grabbed);
extern void X11_SetWindowKeyboardGrab(_THIS, SDL_Window * window, SDL_bool grabbed);
extern void X11_DestroyWindow(_THIS, SDL_Window * window);