|
8 | 8 | from uuid import UUID
|
9 | 9 |
|
10 | 10 | from PyQt6.QtCore import (
|
| 11 | + QPoint, |
11 | 12 | Qt,
|
12 | 13 | QThread,
|
13 | 14 | QTimer,
|
|
18 | 19 | QApplication,
|
19 | 20 | QHBoxLayout,
|
20 | 21 | QLayout,
|
| 22 | + QMenu, |
21 | 23 | QPushButton,
|
22 | 24 | )
|
23 | 25 |
|
@@ -139,6 +141,8 @@ def __init__(
|
139 | 141 | self.unpinned_vis_btn = QPushButton()
|
140 | 142 | self.unpinned_vis_btn.setCheckable(True)
|
141 | 143 | self.unpinned_vis_btn.clicked.connect(self.toggle_unpinned_widget_visibility) # type: ignore
|
| 144 | + self.unpinned_vis_btn.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu) |
| 145 | + self.unpinned_vis_btn.customContextMenuRequested.connect(self.show_context_menu) # type: ignore |
142 | 146 |
|
143 | 147 | self.unpinned_widget = DropWidget(self)
|
144 | 148 | self.unpinned_layout = self.unpinned_widget.main_layout
|
@@ -169,6 +173,33 @@ def __init__(
|
169 | 173 |
|
170 | 174 | QTimer.singleShot(0, self.setup_client) # pyright: ignore [reportUnknownMemberType]
|
171 | 175 |
|
| 176 | + def show_context_menu(self, pos: QPoint): |
| 177 | + """Show the context menu for the unpinned visibility button""" |
| 178 | + menu = QMenu(self) |
| 179 | + menu.setContentsMargins(0, 0, 0, 0) |
| 180 | + menu.setLayoutDirection(Qt.LayoutDirection.LeftToRight) |
| 181 | + menu.setStyleSheet(""" |
| 182 | + QMenu::item { |
| 183 | + padding: 4px 6px; |
| 184 | + } |
| 185 | + QMenu::item:selected { |
| 186 | + background-color: #444; |
| 187 | + color: white; |
| 188 | + border-radius: 6px; |
| 189 | + } |
| 190 | + """) |
| 191 | + refresh_action = menu.addAction("Refresh Systray") # pyright: ignore [reportUnknownMemberType] |
| 192 | + if not refresh_action: |
| 193 | + return |
| 194 | + refresh_action.triggered.connect(self.refresh_systray) # pyright: ignore [reportUnknownMemberType] |
| 195 | + menu.exec(self.unpinned_vis_btn.mapToGlobal(pos)) |
| 196 | + |
| 197 | + def refresh_systray(self): |
| 198 | + """Refresh the icons by sending a message to the tray monitor""" |
| 199 | + client, _ = SystrayWidget.get_client_instance() |
| 200 | + client.send_taskbar_created() |
| 201 | + logger.debug("Systray icons refreshed") |
| 202 | + |
172 | 203 | def setup_client(self):
|
173 | 204 | """Setup the tray monitor client and connect signals"""
|
174 | 205 | self.load_state()
|
|
0 commit comments