Merge pull request #2079 from pypeclub/feature/tray_menu_click_pos

Tray UI: Show menu where first click happened
This commit is contained in:
Jakub Trllo 2021-09-30 09:55:11 +02:00 committed by GitHub
commit 2093861dd5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -289,6 +289,7 @@ class SystemTrayIcon(QtWidgets.QSystemTrayIcon):
self._click_timer = click_timer
self._doubleclick = False
self._click_pos = None
def _click_timer_timeout(self):
self._click_timer.stop()
@ -301,13 +302,17 @@ class SystemTrayIcon(QtWidgets.QSystemTrayIcon):
self._show_context_menu()
def _show_context_menu(self):
pos = QtGui.QCursor().pos()
pos = self._click_pos
self._click_pos = None
if pos is None:
pos = QtGui.QCursor().pos()
self.contextMenu().popup(pos)
def on_systray_activated(self, reason):
# show contextMenu if left click
if reason == QtWidgets.QSystemTrayIcon.Trigger:
if self.tray_man.doubleclick_callback:
self._click_pos = QtGui.QCursor().pos()
self._click_timer.start()
else:
self._show_context_menu()