From 5334c76b834cf7effa21849fff1b0c57cdedb62a Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Fri, 16 Sep 2016 22:29:33 +0200 Subject: gui, logic: add separate option for starting in tray vs tray enabled Suggested-by: @MathijsG, #454 --- gui/main-window.cpp | 16 ++++++++++++---- gui/main-window.hpp | 1 + gui/main.cpp | 2 +- gui/options-dialog.cpp | 1 + gui/options-dialog.ui | 28 +++++++++++++++++++++++----- logic/main-settings.hpp | 3 ++- 6 files changed, 40 insertions(+), 11 deletions(-) diff --git a/gui/main-window.cpp b/gui/main-window.cpp index 89235720..0f070cc4 100644 --- a/gui/main-window.cpp +++ b/gui/main-window.cpp @@ -687,13 +687,16 @@ void MainWindow::ensure_tray() } else { - if (isHidden()) + const bool is_hidden = isHidden() || !isVisible(); + + if (is_hidden) + { show(); - if (!isVisible()) setVisible(true); - raise(); // for OSX - activateWindow(); // for Windows + raise(); // for OSX + activateWindow(); // for Windows + } if (tray) tray->hide(); @@ -824,6 +827,11 @@ bool MainWindow::is_tray_enabled() return s.tray_enabled && QSystemTrayIcon::isSystemTrayAvailable(); } +bool MainWindow::start_in_tray() +{ + return s.tray_enabled && s.tray_start && QSystemTrayIcon::isSystemTrayAvailable(); +} + void MainWindow::set_profile_in_registry(const QString &profile) { QSettings settings(OPENTRACK_ORG); diff --git a/gui/main-window.hpp b/gui/main-window.hpp index b33b22fe..0dfc0259 100644 --- a/gui/main-window.hpp +++ b/gui/main-window.hpp @@ -132,4 +132,5 @@ public: bool maybe_die_on_config_not_writable(const QString& current, QStringList* ini_list); void die_on_config_not_writable(); bool is_tray_enabled(); + bool start_in_tray(); }; diff --git a/gui/main.cpp b/gui/main.cpp index 47999212..763f1cb5 100644 --- a/gui/main.cpp +++ b/gui/main.cpp @@ -144,7 +144,7 @@ main(int argc, char** argv) if (!w->isEnabled()) break; - if (!w->is_tray_enabled()) + if (!w->start_in_tray()) { w->setVisible(true); w->show(); diff --git a/gui/options-dialog.cpp b/gui/options-dialog.cpp index c7ecfe08..be846b35 100644 --- a/gui/options-dialog.cpp +++ b/gui/options-dialog.cpp @@ -40,6 +40,7 @@ OptionsDialog::OptionsDialog(std::function pause_keybindings) : connect(ui.buttonBox, SIGNAL(rejected()), this, SLOT(doCancel())); tie_setting(main.tray_enabled, ui.trayp); + tie_setting(main.tray_start, ui.tray_start); tie_setting(main.center_at_startup, ui.center_at_startup); diff --git a/gui/options-dialog.ui b/gui/options-dialog.ui index 74b448c7..35d6e7e0 100644 --- a/gui/options-dialog.ui +++ b/gui/options-dialog.ui @@ -7,7 +7,7 @@ 0 0 546 - 622 + 594 @@ -316,10 +316,29 @@ - - + + Minimize to tray + + + 3 + + + + + Enable + + + + + + + Start in tray when enabled + + + + @@ -332,7 +351,7 @@ - 20 + 0 0 @@ -1355,7 +1374,6 @@ It won't work properly with translation compensation enabled. bind_restart_tracking bind_tcomp_off_held center_at_startup - trayp camera_yaw camera_pitch camera_roll diff --git a/logic/main-settings.hpp b/logic/main-settings.hpp index 7c02b262..346c3fb2 100644 --- a/logic/main-settings.hpp +++ b/logic/main-settings.hpp @@ -68,7 +68,7 @@ struct main_settings bundle b, b_map; axis_opts a_x, a_y, a_z, a_yaw, a_pitch, a_roll; value tcomp_p, tcomp_tz; - value tray_enabled; + value tray_enabled, tray_start; value camera_yaw, camera_pitch, camera_roll; value use_camera_offset_from_centering; value center_at_startup; @@ -91,6 +91,7 @@ struct main_settings tcomp_p(b, "compensate-translation", true), tcomp_tz(b, "compensate-translation-disable-z-axis", false), tray_enabled(b, "use-system-tray", false), + tray_start(b, "start-in-tray", false), camera_yaw(b, "camera-yaw", 0), camera_pitch(b, "camera-pitch", 0), camera_roll(b, "camera-roll", 0), -- cgit v1.2.3