mambatray.py: wayland: workaround left-click causing menu to appear in screen center by disabling if plasmawayland session

This commit is contained in:
Silvan 2024-02-25 16:39:08 +01:00
parent ee9bf1f12b
commit e0664fa1de

View File

@ -20,8 +20,8 @@ class SystemTrayIcon(QSystemTrayIcon):
menu = None
def __init__(self, icon, parent=None):
QSystemTrayIcon.__init__(self, icon, parent)
def __init__(self, icon):
QSystemTrayIcon.__init__(self, icon)
global w, contatore, srpm, lista, NetsrpmsArg, nOre, desktop_session
nOre = 2
@ -32,8 +32,7 @@ class SystemTrayIcon(QSystemTrayIcon):
NetsrpmsArg = "-c"
lista = []
contatore = 0
w = parent
self.menu = QMenu(parent)
self.menu = QMenu()
try:
desktop_session = os.path.basename(os.getenv('DESKTOP_SESSION'))
@ -65,6 +64,7 @@ class SystemTrayIcon(QSystemTrayIcon):
softwareBaseInstallsProcess = QProcess(self)
softwareMenu = self.menu.addMenu(QIcon.fromTheme("applications-system"),_("Software"))
softwareManageAction = softwareMenu.addAction(QIcon.fromTheme("applications-other"),_("Add/Remove software packages..."))
softwareManageAction.triggered.connect(self.softwareManager)
@ -84,6 +84,7 @@ class SystemTrayIcon(QSystemTrayIcon):
networkMenu = self.menu.addMenu(QIcon.fromTheme("preferences-system-network"),
_("Network"))
networkFirewallMenu = networkMenu.addMenu(QIcon.fromTheme("security-medium"),_("Firewall"))
networkFirewallDisableAction = networkFirewallMenu.addAction(QIcon.fromTheme("security-low"),_("Disable"))
networkFirewallDisableAction.triggered.connect(self.networkFirewallDisable)
@ -105,7 +106,6 @@ class SystemTrayIcon(QSystemTrayIcon):
self.setToolTip(_("{} control center").format(distro.name()))
self.activated.connect(self.iconActivated)
self.setContextMenu(self.menu)
self.show()
# the first time refresh packages cache after 5 minutes
refreshPackagesTimer.start( 5 * 60000 )
@ -114,6 +114,9 @@ class SystemTrayIcon(QSystemTrayIcon):
def iconActivated(self, reason):
if reason in (QSystemTrayIcon.Trigger, QSystemTrayIcon.DoubleClick, QSystemTrayIcon.Context):
# FIXME: on plasma wayland and left click menu will popup in the center of the screen
# disabling and only supporting right click.
if desktop_session != 'plasmawayland':
self.contextMenu().popup(QCursor.pos())
def about(self):
@ -234,17 +237,13 @@ class SystemTrayIcon(QSystemTrayIcon):
return testo[0:len(testo)-2]
def main():
if __name__ == '__main__':
app = QApplication(sys.argv)
if app.isSessionRestored():
app.exit(1)
else:
app.setQuitOnLastWindowClosed(0)
gettext.install('mambatray', '/usr/share/locale')
trayIcon = SystemTrayIcon(QIcon.fromTheme("mambatray")
)
sys.exit(app.exec_())
if __name__ == '__main__':
main()
trayIcon = SystemTrayIcon(QIcon.fromTheme("mambatray"))
trayIcon.show()
sys.exit(app.exec())