]> source.dussan.org Git - tigervnc.git/commitdiff
The OS X keyboard grabbing code needs to be multi-head aware to function
authorPierre Ossman <ossman@cendio.se>
Mon, 27 Aug 2012 14:40:51 +0000 (14:40 +0000)
committerPierre Ossman <ossman@cendio.se>
Mon, 27 Aug 2012 14:40:51 +0000 (14:40 +0000)
properly.

git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@4977 3789f03b-4d11-0410-bbf8-ca57d06f2519

vncviewer/DesktopWindow.cxx
vncviewer/cocoa.h
vncviewer/cocoa.mm

index 6fc2b9230d21e15c7083c21c176e8932880c1ed2..ca33ebeb845ad44b5f1a1870091096eaf48ebbd6 100644 (file)
@@ -439,7 +439,13 @@ void DesktopWindow::grabKeyboard()
 #elif defined(__APPLE__)
   int ret;
   
-  ret = cocoa_capture_display(this);
+  ret = cocoa_capture_display(this,
+#ifdef HAVE_FLTK_FULLSCREEN_SCREENS
+                              fullScreenAllMonitors
+#else
+                              false
+#endif
+                              );
   if (ret != 0)
     vlog.error(_("Failure grabbing keyboard"));
 #else
index 3bbe6fa0f955471a9b92bb451bd3f7f20c8663bc..8798082339011e585b5da46b348e23c7ac522f5c 100644 (file)
@@ -19,7 +19,7 @@
 #ifndef __VNCVIEWER_COCOA_H__
 #define __VNCVIEWER_COCOA_H__
 
-int cocoa_capture_display(Fl_Window *win);
+int cocoa_capture_display(Fl_Window *win, bool all_displays);
 void cocoa_release_display(Fl_Window *win);
 
 #endif
index 6300d3c0988155ef477f206b72f82f3781c91f96..6872b23074fdeb346f6bf1cd4e9fce7bb104d72c 100644 (file)
 
 static bool captured = false;
 
-int cocoa_capture_display(Fl_Window *win)
+int cocoa_capture_display(Fl_Window *win, bool all_displays)
 {
   NSWindow *nsw;
 
   nsw = (NSWindow*)fl_xid(win);
 
   if (!captured) {
-    if (CGDisplayCapture(kCGDirectMainDisplay) != kCGErrorSuccess)
-      return 1;
+    if (all_displays) {
+      if (CGCaptureAllDisplays() != kCGErrorSuccess)
+        return 1;
+    } else {
+      CGDirectDisplayID displays[16];
+      CGDisplayCount count;
+      int index;
+
+      if (CGGetActiveDisplayList(16, displays, &count) != kCGErrorSuccess)
+        return 1;
+
+      if (count != Fl::screen_count())
+        return 1;
+
+#ifdef HAVE_FLTK_FULLSCREEN_SCREENS
+      index = Fl::screen_num(win->x(), win->y(), win->w(), win->h());
+#else
+      index = 0;
+#endif
+
+      if (CGDisplayCapture(displays[index]) != kCGErrorSuccess)
+        return 1;
+    }
 
     captured = true;
   }
@@ -51,7 +72,7 @@ void cocoa_release_display(Fl_Window *win)
   int newlevel;
 
   if (captured)
-    CGDisplayRelease(kCGDirectMainDisplay);
+    CGReleaseAllDisplays();
 
   captured = false;