Use correct color space for current monitor

We won't always be on the primary monitor, so check which color space
we're actually using right now. For offscreen stuff we assume a standard
sRGB color space.
diff --git a/vncviewer/cocoa.mm b/vncviewer/cocoa.mm
index fc3b5bc..85b736b 100644
--- a/vncviewer/cocoa.mm
+++ b/vncviewer/cocoa.mm
@@ -110,6 +110,28 @@
     [nsw setLevel:newlevel];
 }
 
+CGColorSpaceRef cocoa_win_color_space(Fl_Window *win)
+{
+  NSWindow *nsw;
+  NSColorSpace *nscs;
+
+  nsw = (NSWindow*)fl_xid(win);
+
+  nscs = [nsw colorSpace];
+  if (nscs == nil) {
+    // Offscreen, so return standard SRGB color space
+    assert(false);
+    return CGColorSpaceCreateWithName(kCGColorSpaceSRGB);
+  }
+
+  CGColorSpaceRef lut = [nscs CGColorSpace];
+
+  // We want a permanent reference, not an autorelease
+  CGColorSpaceRetain(lut);
+
+  return lut;
+}
+
 int cocoa_is_keyboard_event(const void *event)
 {
   NSEvent *nsevent;