From 6a50f724d259a8fa585c22351905130528b66622 Mon Sep 17 00:00:00 2001 From: Bumsik Kim Date: Sat, 28 Apr 2018 02:03:47 -0400 Subject: [PATCH] Trayicon: Widget shows on the nearest coner to the tray icon --- virtscreen.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/virtscreen.py b/virtscreen.py index d215dde..4132891 100755 --- a/virtscreen.py +++ b/virtscreen.py @@ -1,7 +1,7 @@ #!/usr/bin/env python import os, re -from PyQt5.QtGui import QIcon +from PyQt5.QtGui import QIcon, QCursor from PyQt5.QtCore import pyqtSlot, Qt from PyQt5.QtWidgets import (QAction, QApplication, QCheckBox, QComboBox, QDialog, QGridLayout, QGroupBox, QHBoxLayout, QLabel, QLineEdit, @@ -320,6 +320,15 @@ class Window(QDialog): if self.isVisible(): self.hide() else: + # move the widget to one of 4 coners of the primary display, + # depending on the current mouse cursor. + screen = QApplication.desktop().screenGeometry() + x_mid = screen.width() / 2 + y_mid = screen.height() / 2 + cursor = QCursor().pos() + x = (screen.width() - self.width()) if (cursor.x() > x_mid) else 0 + y = (screen.height() - self.height()) if (cursor.y() > y_mid) else 0 + self.move(x, y) self.showNormal() elif reason == QSystemTrayIcon.MiddleClick: self.showMessage()