From e2200c2456220c4dcc45024050d36fae6213f894 Mon Sep 17 00:00:00 2001 From: Hugo Lundin Date: Wed, 14 Jul 2021 14:55:56 +0200 Subject: [PATCH] Calculate overlay position from window size Previously, it was assumed that all monitors (and especially the primary monitor, index 0) was inside the window when we calculate the position of the overlay. That might not always be the case, for example when using fullscreen mode over a narrower set of monitors. This commit does so the overlay is positioned correctly based on the actual window size, instead of what we expect it to be. --- vncviewer/DesktopWindow.cxx | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/vncviewer/DesktopWindow.cxx b/vncviewer/DesktopWindow.cxx index e7f91f02..8c85c4d9 100644 --- a/vncviewer/DesktopWindow.cxx +++ b/vncviewer/DesktopWindow.cxx @@ -465,9 +465,34 @@ void DesktopWindow::draw() // Make sure it's properly seen by adjusting it relative to the // primary screen rather than the entire window - if (fullscreen_active() && fullScreenAllMonitors) { + if (fullscreen_active()) { assert(Fl::screen_count() >= 1); - Fl::screen_xywh(sx, sy, sw, sh, 0); + + rfb::Rect window_rect, screen_rect; + window_rect.setXYWH(x(), y(), w(), h()); + + bool found_enclosed_screen = false; + for (int i = 0; i < Fl::screen_count(); i++) { + Fl::screen_xywh(sx, sy, sw, sh, i); + + // The screen with the smallest index that are enclosed by + // the viewport will be used for showing the overlay. + screen_rect.setXYWH(sx, sy, sw, sh); + if (screen_rect.enclosed_by(window_rect)) { + found_enclosed_screen = true; + break; + } + } + + // If no monitor inside the viewport was found, + // use the one primary instead. + if (!found_enclosed_screen) + Fl::screen_xywh(sx, sy, sw, sh, 0); + + // Adjust the coordinates so they are relative to the viewport. + sx -= x(); + sy -= y(); + } else { sx = 0; sy = 0; -- 2.39.5