Make sure the tray icon point is in screen coordinates
authorKevin Ottens <kevin.ottens@nextcloud.com>
Wed, 15 Jul 2020 09:23:11 +0000 (11:23 +0200)
committerKevin Ottens <ervin@ipsquad.net>
Wed, 15 Jul 2020 10:22:54 +0000 (12:22 +0200)
Previously we were using QCursor::pos() in the Linux case, which is a
fair heuristic except it will always be relative to the primary screen
and not the current screen. This explains why we had to adjust with the
virtual geometry.

In the Windows and Mac case we got the position out of QSystemTrayIcon
and that one was already relative to the current screen.

So now we use QCursor::pos(currentScreen()) which ensures we give the
coordinates relatively to the current screen also in the Linux case.

Since all platforms are now having that point in the same coordinate
system we don't need to mess around with the virtual geometry to
compensate.

Signed-off-by: Kevin Ottens <kevin.ottens@nextcloud.com>
src/gui/systray.cpp

index b2462f6c7148eabbcf6504c5c6c673afa77935c8..79105c8ce186519440c137696915a73124efe4d1 100644 (file)
@@ -279,8 +279,8 @@ QRect Systray::taskbarGeometry() const
 QRect Systray::currentScreenRect() const
 {
     const auto screen = currentScreen();
-    const auto rect = screen->geometry();
-    return rect.translated(screen->virtualGeometry().topLeft());
+    Q_ASSERT(screen);
+    return screen->geometry();
 }
 
 QPoint Systray::computeWindowReferencePoint() const
@@ -378,7 +378,7 @@ QPoint Systray::calcTrayIconCenter() const
     return trayIconCenter;
 #else
     // On Linux, fall back to mouse position (assuming tray icon is activated by mouse click)
-    return QCursor::pos();
+    return QCursor::pos(currentScreen());
 #endif
 }