I need to be able to manipulate the video card gamma tables in my cross platform application. This code needs to be able to do this for each display on multi-display systems based on the location of the dialog that the user is interacting with. I have this working on X11 and Windows and on OS/X the code is far enough along that it will manipulate the gamma table of CGMainDisplayID but I have been unable to find any documentation or any other source on how to get from something I can get from Qt such as QDesktopWidget::screenNumber() or this -> winID() to a handle that can be used to manipulate the video card gamma for a specific display.

The code in my dialog looks like this:

Qt Code:
  1. #if defined (Q_WS_WIN)
  2. screen = (int) this -> winId ();
  3. #elif defined(Q_WS_MAC) // FIXME
  4. screen = (int) this -> winId ();
  5. #elif defined(Q_WS_X11) // this is an X11 system
  6. screen = desktop -> screenNumber(pixmapColor -> mapToGlobal(pixmapColor -> pos()));
  7. #else
  8. #error "Your system is not supported yet. The video gamma setting code will need to be updated to support your system."
  9. #endif[
  10.  
  11. gamma_ramp gammaRamp = new gamma_ramp(screen);
  12. gammaRamp->setGammaRamp();
  13. ...
To copy to clipboard, switch view to plain text mode 


For X11 this is very simple to use as the above boils down to a call to XF86VidModeGetGammaRamp(...) where the screenNumber value is passed in as the second parameter. On Windows it is a little more involved since winID needs to be translated into a handle and the called code looks looks like this:

Qt Code:
  1. void gamma_ramp::getGammaRamp()
  2. {
  3. HDC hDisplayDC;
  4. HRESULT hr;
  5.  
  6. hDisplayDC = GetDCEx((HWND) screen, 0, DCX_CLIPSIBLINGS|DCX_CACHE);
  7. hr = GetDeviceGammaRamp(hDisplayDC, (LPVOID) ramp_buffer);
  8. ReleaseDC((HWND) screen, hDisplayDC);
  9.  
  10. this -> convertPrivShort2ramp_type();
  11. }
To copy to clipboard, switch view to plain text mode 

This is much closer to what needs to happen on OS/X where the code currently looks like this:

Qt Code:
  1. void gamma_ramp::getGammaRamp()
  2. {
  3. CGTableCount count;
  4. CGDisplayErr error_code;
  5.  
  6. // FIXME only does the main display
  7. CGDirectDisplayID dspID = CGMainDisplayID();
  8.  
  9. error_code = CGGetDisplayTransferByTable (dspID,
  10. (CGTableCount) size,
  11. &ramp_buffer[0],
  12. &ramp_buffer[size],
  13. &ramp_buffer[size*2],
  14. &count);
  15.  
  16. for (int i=0; i < size; ++i)
  17. {
  18. red[i] = interpol(ramp_buffer, i, size, count);
  19. green[i] = interpol(ramp_buffer + size, i, size, count);
  20. blue[i] = interpol(ramp_buffer + size*2, i, size, count);
  21. }
  22. }
To copy to clipboard, switch view to plain text mode 

As you can see currently the OS/X code only uses the main display:

Qt Code:
  1. CGDirectDisplayID dspID = CGMainDisplayID();
To copy to clipboard, switch view to plain text mode 

What I need is a way to get from winID(), screenNumber() or something that is Qt supplied to a CGDirectDisplayID and I have been desperately looking for anything about how to do this. Anything about this would be helpful such as a possible source of documentation or perhaps a link to a forum that specializes in Qt OS/X. Even the programmer who worked on the OS/X code didn't have any idea how to handle this and he works on a large Qt open source project. I should add that he did get this code to the point where it builds and will work on the main display gamma table. So I am very grateful for his efforts.