Skip to content

Commit ee85474

Browse files
authored
Merge pull request #180 from Video-Nomad/feat/systray-refresh-dropdown-menu
feat(systray): systray expand/collapse right click menu
2 parents 522bfbf + b93214a commit ee85474

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

docs/widgets/(Widget)-Systray.md

+3
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ There are some limitations with the systray widget:
5050
- **show_volume:** Whether to show volume icon (from the original systray).
5151
- **show_network:** Whether to show network icon (from the original systray).
5252
53+
## Debug Options
54+
Show unpinned button has a right click menu that allows you to refresh the systray icons.
55+
5356
## Style
5457
```css
5558
.systray {} /* The base widget style */

src/core/widgets/yasb/systray.py

+31
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from uuid import UUID
99

1010
from PyQt6.QtCore import (
11+
QPoint,
1112
Qt,
1213
QThread,
1314
QTimer,
@@ -18,6 +19,7 @@
1819
QApplication,
1920
QHBoxLayout,
2021
QLayout,
22+
QMenu,
2123
QPushButton,
2224
)
2325

@@ -139,6 +141,8 @@ def __init__(
139141
self.unpinned_vis_btn = QPushButton()
140142
self.unpinned_vis_btn.setCheckable(True)
141143
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
142146

143147
self.unpinned_widget = DropWidget(self)
144148
self.unpinned_layout = self.unpinned_widget.main_layout
@@ -169,6 +173,33 @@ def __init__(
169173

170174
QTimer.singleShot(0, self.setup_client) # pyright: ignore [reportUnknownMemberType]
171175

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+
172203
def setup_client(self):
173204
"""Setup the tray monitor client and connect signals"""
174205
self.load_state()

0 commit comments

Comments
 (0)