Skip to content

Commit eab36ef

Browse files
vkconfig: Fix Linux tray icon refresh
Change-Id: Idc1b12d8cf8d9f7f01b4a19d317b23443fe10ec1
1 parent 99977f9 commit eab36ef

2 files changed

Lines changed: 30 additions & 23 deletions

File tree

vkconfig_gui/mainwindow.cpp

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -110,19 +110,23 @@ void MainWindow::UpdateUI_Status() {
110110
if (QSystemTrayIcon::isSystemTrayAvailable()) {
111111
// Device
112112
{
113-
QMenu *menu = new QMenu(this);
114-
QSignalMapper *mapper_device = new QSignalMapper(menu);
115-
QSignalMapper *mapper_layers = new QSignalMapper(menu);
113+
if (this->_tray_icon_menu != nullptr) {
114+
delete this->_tray_icon_menu;
115+
}
116+
this->_tray_icon_menu = new QMenu(this);
117+
118+
QSignalMapper *mapper_device = new QSignalMapper(this);
119+
QSignalMapper *mapper_layers = new QSignalMapper(this);
116120

117121
QAction *tray_restore_action = new QAction("&Show Vulkan Configurator UI", this);
118122
tray_restore_action->setIcon(QIcon(":/resourcefiles/vkconfig-on.png"));
119123
QFont font = tray_restore_action->font();
120124
font.setBold(true);
121125
tray_restore_action->setFont(font);
122126
this->connect(tray_restore_action, &QAction::triggered, this, &MainWindow::OnTrayActionShow);
123-
menu->addAction(tray_restore_action);
127+
this->_tray_icon_menu->addAction(tray_restore_action);
124128

125-
menu->addSeparator();
129+
this->_tray_icon_menu->addSeparator();
126130
const bool enabled_device = configurator.driver_override_enabled;
127131

128132
QAction *tray_override = new QAction("Override System Vulkan &Device with:", this);
@@ -131,7 +135,7 @@ void MainWindow::UpdateUI_Status() {
131135
tray_override->setChecked(enabled_device);
132136

133137
this->connect(tray_override, &QAction::toggled, this, &MainWindow::OnTrayActionOverrideDevice);
134-
menu->addAction(tray_override);
138+
this->_tray_icon_menu->addAction(tray_override);
135139

136140
for (std::size_t i = 0, n = configurator.vulkan_system_info.physicalDevices.size(); i < n; ++i) {
137141
const VulkanPhysicalDeviceInfo &info = configurator.vulkan_system_info.physicalDevices[i];
@@ -142,15 +146,15 @@ void MainWindow::UpdateUI_Status() {
142146
action->setChecked(device_info == configurator.driver_override_info);
143147
action->setEnabled(enabled_device);
144148

145-
menu->addAction(action);
149+
this->_tray_icon_menu->addAction(action);
146150

147151
this->connect(action, SIGNAL(triggered()), mapper_device, SLOT(map()));
148152
mapper_device->setMapping(action, i);
149153
}
150154

151155
this->connect(mapper_device, &QSignalMapper::mappedInt, this, &MainWindow::OnDeviceChanged);
152156

153-
menu->addSeparator();
157+
this->_tray_icon_menu->addSeparator();
154158
const bool enabled_layers = configurator.layers_override_enabled && configurator.GetExecutableScope() != EXECUTABLE_PER;
155159

156160
QAction *tray_override_layers = new QAction("Override System Vulkan &Layers Configuration with:", this);
@@ -159,7 +163,7 @@ void MainWindow::UpdateUI_Status() {
159163
tray_override_layers->setChecked(enabled_layers);
160164

161165
this->connect(tray_override_layers, &QAction::toggled, this, &MainWindow::OnTrayActionOverrideLayers);
162-
menu->addAction(tray_override_layers);
166+
this->_tray_icon_menu->addAction(tray_override_layers);
163167

164168
for (std::size_t i = 0, n = configurator.configurations.available_configurations.size(); i < n; ++i) {
165169
const Configuration &configuration = configurator.configurations.available_configurations[i];
@@ -169,39 +173,41 @@ void MainWindow::UpdateUI_Status() {
169173
action->setChecked(configuration.key == configurator.GetSelectedGlobalConfiguration());
170174
action->setEnabled(enabled_layers);
171175

172-
menu->addAction(action);
176+
this->_tray_icon_menu->addAction(action);
173177

174178
this->connect(action, SIGNAL(triggered()), mapper_layers, SLOT(map()));
175179
mapper_layers->setMapping(action, i);
176180
}
177181

178182
this->connect(mapper_layers, &QSignalMapper::mappedInt, this, &MainWindow::OnLayersChanged);
179183

180-
menu->addSeparator();
184+
this->_tray_icon_menu->addSeparator();
181185

182186
QAction *tray_override_loader = new QAction("Override System Vulkan Loader Log", this);
183187
tray_override_loader->setFont(font);
184188
tray_override_loader->setCheckable(true);
185189
tray_override_loader->setChecked(configurator.loader_log_enabled);
186190
this->connect(tray_override_loader, &QAction::toggled, this, &MainWindow::OnTrayActionOverrideLog);
187-
menu->addAction(tray_override_loader);
191+
this->_tray_icon_menu->addAction(tray_override_loader);
188192

189-
menu->addSeparator();
193+
this->_tray_icon_menu->addSeparator();
190194

191195
QAction *tray_quit_action = new QAction("&Quit Vulkan Configurator", this);
192196
tray_quit_action->setIcon(::Get(configurator.current_theme_mode, ::ICON_EXIT));
193197
tray_quit_action->setFont(font);
194198
this->connect(tray_quit_action, &QAction::triggered, qApp, &QCoreApplication::quit);
195-
menu->addAction(tray_quit_action);
196-
197-
if (VKC_ENV != VKC_ENV_WIN32) {
198-
if (this->_tray_icon != nullptr) {
199-
delete this->_tray_icon;
200-
}
201-
this->_tray_icon = new QSystemTrayIcon(this);
202-
}
203-
204-
this->_tray_icon->setContextMenu(menu);
199+
this->_tray_icon_menu->addAction(tray_quit_action);
200+
201+
/*
202+
if (VKC_ENV != VKC_ENV_WIN32) {
203+
if (this->_tray_icon != nullptr) {
204+
delete this->_tray_icon;
205+
}
206+
this->_tray_icon = new QSystemTrayIcon(this);
207+
}
208+
*/
209+
210+
this->_tray_icon->setContextMenu(this->_tray_icon_menu);
205211
this->connect(this->_tray_icon, &QSystemTrayIcon::activated, this, &MainWindow::OnIconActivated);
206212

207213
if (configurator.layers_override_enabled || configurator.driver_override_enabled || configurator.loader_log_enabled) {

vkconfig_gui/mainwindow.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class MainWindow : public QMainWindow {
5757
void changeEvent(QEvent *event) override;
5858

5959
QSystemTrayIcon *_tray_icon = nullptr;
60+
QMenu *_tray_icon_menu = nullptr;
6061

6162
public Q_SLOTS:
6263
void commitDataRequest(QSessionManager &manager);

0 commit comments

Comments
 (0)