From 9023a2ec1823d473f1cfe0b723c8636d8e994e2c Mon Sep 17 00:00:00 2001 From: Samuel Mannehed Date: Wed, 6 Oct 2021 14:06:22 +0200 Subject: [PATCH] Workaround options window appearing behind viewer FLTK's fullscreen_x() function will always put the window on a high level (NSStatusWindowLevel = 25), even if the window doesn't have focus. This causes the OptionsDialog to end up behind the DesktopWindow when the fullscreen function is called. Until we can rest assured that most people building TigerVNC will use a fixed version of FLTK, we will need this workaround. --- vncviewer/DesktopWindow.cxx | 16 ++++++++++++---- vncviewer/cocoa.h | 3 +++ vncviewer/cocoa.mm | 14 ++++++++++++++ 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/vncviewer/DesktopWindow.cxx b/vncviewer/DesktopWindow.cxx index d379a712..f334c614 100644 --- a/vncviewer/DesktopWindow.cxx +++ b/vncviewer/DesktopWindow.cxx @@ -918,12 +918,11 @@ void DesktopWindow::fullscreen_on() { bool allMonitors = !strcasecmp(fullScreenMode, "all"); bool selectedMonitors = !strcasecmp(fullScreenMode, "selected"); + int top, bottom, left, right; if (not selectedMonitors and not allMonitors) { - int n = Fl::screen_num(x(), y(), w(), h()); - fullscreen_screens(n, n, n, n); + top = bottom = left = right = Fl::screen_num(x(), y(), w(), h()); } else { - int top, bottom, left, right; int top_y, bottom_y, left_x, right_x; int sx, sy, sw, sh; @@ -983,8 +982,17 @@ void DesktopWindow::fullscreen_on() } } - fullscreen_screens(top, bottom, left, right); } +#ifdef __APPLE__ + // This is a workaround for a bug in FLTK, see: https://github.com/fltk/fltk/pull/277 + int savedLevel; + savedLevel = cocoa_get_level(this); +#endif + fullscreen_screens(top, bottom, left, right); +#ifdef __APPLE__ + // This is a workaround for a bug in FLTK, see: https://github.com/fltk/fltk/pull/277 + cocoa_set_level(this, savedLevel); +#endif if (!fullscreen_active()) fullscreen(); diff --git a/vncviewer/cocoa.h b/vncviewer/cocoa.h index 08340038..ca17ddf9 100644 --- a/vncviewer/cocoa.h +++ b/vncviewer/cocoa.h @@ -21,6 +21,9 @@ class Fl_Window; +int cocoa_get_level(Fl_Window *win); +void cocoa_set_level(Fl_Window *win, int level); + int cocoa_capture_displays(Fl_Window *win); void cocoa_release_displays(Fl_Window *win); diff --git a/vncviewer/cocoa.mm b/vncviewer/cocoa.mm index dca1afa4..e8764f52 100644 --- a/vncviewer/cocoa.mm +++ b/vncviewer/cocoa.mm @@ -50,6 +50,20 @@ const int kVK_Menu = 0x6E; static bool captured = false; +int cocoa_get_level(Fl_Window *win) +{ + NSWindow *nsw; + nsw = (NSWindow*)fl_xid(win); + return [nsw level]; +} + +void cocoa_set_level(Fl_Window *win, int level) +{ + NSWindow *nsw; + nsw = (NSWindow*)fl_xid(win); + [nsw setLevel:level]; +} + int cocoa_capture_displays(Fl_Window *win) { NSWindow *nsw; -- 2.39.5