Skip to content

Commit

Permalink
vkconfig: Closing main window exit by default
Browse files Browse the repository at this point in the history
  • Loading branch information
christophe-lunarg committed Apr 26, 2024
1 parent 28efb19 commit b824aa6
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 43 deletions.
80 changes: 39 additions & 41 deletions vkconfig/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,6 @@ MainWindow::MainWindow(QWidget *parent)

connect(ui->launcher_loader_debug, SIGNAL(currentIndexChanged(int)), this, SLOT(OnLauncherLoaderMessageChanged(int)));

ui->check_box_persistent->setToolTip("Keep Vulkan Configurator running in system tray when closing the main window");

Configurator &configurator = Configurator::Get();
Environment &environment = configurator.environment;

Expand All @@ -133,6 +131,7 @@ MainWindow::MainWindow(QWidget *parent)
ui->splitter_2->restoreState(environment.Get(VKCONFIG2_LAYOUT_MAIN_SPLITTER2));
ui->splitter_3->restoreState(environment.Get(VKCONFIG2_LAYOUT_MAIN_SPLITTER3));

ui->check_box_persistent->setToolTip("Keep Vulkan Configurator running in system tray when closing the main window");
ui->check_box_persistent->setVisible(QSystemTrayIcon::isSystemTrayAvailable());

LoadConfigurationList();
Expand Down Expand Up @@ -550,10 +549,45 @@ void MainWindow::on_check_box_apply_list_clicked() {
}

void MainWindow::on_check_box_persistent_clicked() {
Configurator &configurator = Configurator::Get();
if (!QSystemTrayIcon::isSystemTrayAvailable()) {
return;
}

configurator.environment.SetUseSystemTray(ui->check_box_persistent->isChecked());
this->UpdateTray();
Environment &environment = Configurator::Get().environment;

// Alert the user to the current state of the vulkan configurator and
// give them the option to not shutdown.
QSettings settings;
if (ui->check_box_persistent->isChecked() && !settings.value("vkconfig_system_tray_stay_on_close", false).toBool()) {
const QPalette saved_palette = ui->check_box_persistent->palette();
QPalette modified_palette = saved_palette;
modified_palette.setColor(QPalette::ColorRole::WindowText, QColor(255, 0, 0, 255));
ui->check_box_persistent->setPalette(modified_palette);

const std::string message = "Vulkan Layers will remain controlled by Vulkan Configurator while active in the system tray.";

QMessageBox alert(this);
alert.setWindowTitle("Vulkan Configurator behavior when closing the main window");
alert.setText(message.c_str());
alert.setIcon(QMessageBox::Warning);
alert.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
alert.setDefaultButton(QMessageBox::No);
alert.setCheckBox(new QCheckBox("Do not show again."));
alert.setInformativeText(
"Do you want to keep Vulkan Configurator running in the system tray when closing the main window?");

int ret_val = alert.exec();
settings.setValue("vkconfig_system_tray_stay_on_close", alert.checkBox()->isChecked());

ui->check_box_persistent->setPalette(saved_palette);

if (ret_val == QMessageBox::No) {
ui->check_box_persistent->setChecked(false);
return;
}
}

environment.SetUseSystemTray(ui->check_box_persistent->isChecked());
}

void MainWindow::on_check_box_clear_on_launch_clicked() {
Expand Down Expand Up @@ -786,42 +820,6 @@ void MainWindow::OnHelpGPUInfo(bool checked) {
void MainWindow::closeEvent(QCloseEvent *event) {
Environment &environment = Configurator::Get().environment;

// Alert the user to the current state of the vulkan configurator and
// give them the option to not shutdown.
if (QSystemTrayIcon::isSystemTrayAvailable()) {
if (environment.GetUseSystemTray() && environment.GetMode() != LAYERS_MODE_BY_APPLICATIONS) {
QSettings settings;
if (!settings.value("vkconfig_system_tray", false).toBool()) {
const QPalette saved_palette = ui->check_box_persistent->palette();
QPalette modified_palette = saved_palette;
modified_palette.setColor(QPalette::ColorRole::WindowText, QColor(255, 0, 0, 255));
ui->check_box_persistent->setPalette(modified_palette);

const std::string message =
"Vulkan Layers remains controlled by Vulkan Configurator while active in the system tray.";

QMessageBox alert(this);
alert.setWindowTitle("Vulkan Configurator will remain active in the system tray");
alert.setText(message.c_str());
alert.setIcon(QMessageBox::Warning);
alert.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
alert.setDefaultButton(QMessageBox::No);
alert.setCheckBox(new QCheckBox("Do not show again."));
alert.setInformativeText("Are you still ready to move Vulkan Configurator in the system tray?");

int ret_val = alert.exec();
settings.setValue("vkconfig_system_tray", alert.checkBox()->isChecked());

ui->check_box_persistent->setPalette(saved_palette);

if (ret_val == QMessageBox::No) {
event->ignore();
return;
}
}
}
}

// If a child process is still running, destroy it
if (_launch_application) {
ResetLaunchApplication();
Expand Down
5 changes: 3 additions & 2 deletions vkconfig_core/environment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ Environment::Environment(PathManager& paths, const Version& api_version)
: api_version(api_version),
loader_message_types(::GetLoaderMessageTypes(qgetenv("VK_LOADER_DEBUG").toStdString())),
paths_manager(paths),
paths(paths_manager) {
paths(paths_manager),
use_system_tray(false) {
const bool result = Load();
assert(result);
}
Expand All @@ -171,7 +172,7 @@ void Environment::Reset(ResetMode mode) {
this->vkconfig3_version = Version::VKCONFIG3;
this->layers_mode = LAYERS_MODE_BY_CONFIGURATOR_RUNNING;
this->use_application_list = false;
this->use_system_tray = true;
this->use_system_tray = false;

for (std::size_t i = 0; i < ACTIVE_COUNT; ++i) {
actives[i] = GetActiveDefault(static_cast<Active>(i));
Expand Down

0 comments on commit b824aa6

Please sign in to comment.