From f4423b410c4f83b5679b959096f15bd631c2318a Mon Sep 17 00:00:00 2001 From: Hugo Lundin Date: Fri, 16 Jul 2021 13:26:08 +0200 Subject: [PATCH] Release displays not enclosed by the window cocoa_capture_displays it captures all displays enclosed by the window_rect. If a set of displays were captured, but the configuration of what monitors to use changed, a second call would only add to the set of captured displays. Therefore, if the user enabled FullScreenAllMonitors (all displays captured) and then disabled it (only one display captured) they would get into a state were monitors not used for the VNC session still were captured (which on macOS for example, results in displays being unusable for other things). This has now been fixed, resulting in monitors outside the window_rect not being unnecessarily captured. --- vncviewer/DesktopWindow.cxx | 5 +++++ vncviewer/cocoa.mm | 42 ++++++++++++++++++++----------------- 2 files changed, 28 insertions(+), 19 deletions(-) diff --git a/vncviewer/DesktopWindow.cxx b/vncviewer/DesktopWindow.cxx index 1278e16c..e7f91f02 100644 --- a/vncviewer/DesktopWindow.cxx +++ b/vncviewer/DesktopWindow.cxx @@ -608,6 +608,11 @@ void DesktopWindow::resize(int x, int y, int w, int h) repositionWidgets(); } + + // Some systems require a grab after the window size has been changed. + // Otherwise they might hold on to displays, resulting in them being unusable. + if (fullscreen_active() && fullscreenSystemKeys) + grabKeyboard(); } diff --git a/vncviewer/cocoa.mm b/vncviewer/cocoa.mm index d6596d34..dca1afa4 100644 --- a/vncviewer/cocoa.mm +++ b/vncviewer/cocoa.mm @@ -56,34 +56,38 @@ int cocoa_capture_displays(Fl_Window *win) nsw = (NSWindow*)fl_xid(win); - if (!captured) { - CGDisplayCount count; - CGDirectDisplayID displays[16]; + CGDisplayCount count; + CGDirectDisplayID displays[16]; - int sx, sy, sw, sh; - rfb::Rect windows_rect, screen_rect; + int sx, sy, sw, sh; + rfb::Rect windows_rect, screen_rect; - windows_rect.setXYWH(win->x(), win->y(), win->w(), win->h()); + windows_rect.setXYWH(win->x(), win->y(), win->w(), win->h()); - if (CGGetActiveDisplayList(16, displays, &count) != kCGErrorSuccess) - return 1; + if (CGGetActiveDisplayList(16, displays, &count) != kCGErrorSuccess) + return 1; - if (count != (unsigned)Fl::screen_count()) - return 1; + if (count != (unsigned)Fl::screen_count()) + return 1; - for (int i = 0; i < Fl::screen_count(); i++) { - Fl::screen_xywh(sx, sy, sw, sh, i); + for (int i = 0; i < Fl::screen_count(); i++) { + Fl::screen_xywh(sx, sy, sw, sh, i); - screen_rect.setXYWH(sx, sy, sw, sh); - if (screen_rect.enclosed_by(windows_rect)) { - if (CGDisplayCapture(displays[i]) != kCGErrorSuccess) - return 1; - } - } + screen_rect.setXYWH(sx, sy, sw, sh); + if (screen_rect.enclosed_by(windows_rect)) { + if (CGDisplayCapture(displays[i]) != kCGErrorSuccess) + return 1; - captured = true; + } else { + // A display might have been captured with the previous + // monitor selection. In that case we don't want to keep + // it when its no longer inside the window_rect. + CGDisplayRelease(displays[i]); + } } + captured = true; + if ([nsw level] == CGShieldingWindowLevel()) return 0; -- 2.39.5