From da9a7a32cbce280283883c6332484ec2358346c2 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Wed, 15 May 2019 05:58:47 +0200 Subject: opentrack: try fix main window not showing --- opentrack/main-window.cpp | 54 ++++++++++++++++++++--------------------------- 1 file changed, 23 insertions(+), 31 deletions(-) diff --git a/opentrack/main-window.cpp b/opentrack/main-window.cpp index 139795d5..006d78ed 100644 --- a/opentrack/main-window.cpp +++ b/opentrack/main-window.cpp @@ -38,23 +38,23 @@ main_window::main_window() : State(OPENTRACK_BASE_PATH + OPENTRACK_LIBRARY_PATH) annoy_if_root(); #endif + setWindowFlags(Qt::MSWindowsFixedSizeDialogHint | windowFlags()); + setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + init_profiles(); init_buttons(); - init_tray_menu(); init_dylibs(); init_shortcuts(); - - setWindowFlags(Qt::MSWindowsFixedSizeDialogHint | windowFlags()); - setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - adjustSize(); - - setVisible(!start_in_tray()); + init_tray_menu(); connect(&pose_update_timer, &QTimer::timeout, this, &main_window::show_pose, Qt::DirectConnection); connect(&det_timer, &QTimer::timeout, this, &main_window::maybe_start_profile_from_executable); det_timer.start(1000); + + adjustSize(); + ensure_tray(); // calls QWidget::show() } void main_window::init_shortcuts() @@ -216,8 +216,6 @@ void main_window::init_tray_menu() connect(&s.tray_enabled, value_::value_changed(), this, &main_window::ensure_tray); - - ensure_tray(); } void main_window::init_buttons() @@ -688,13 +686,25 @@ void main_window::set_profile(const QString& new_name_, bool migrate) void main_window::ensure_tray() { - if (!QSystemTrayIcon::isSystemTrayAvailable()) + if (!tray_enabled()) { + if (!isVisible()) + { + show(); + +#ifdef __APPLE__ + raise(); // for OSX +#endif + activateWindow(); // for Windows + } + + if (tray) + tray->hide(); + tray = nullptr; + QApplication::setQuitOnLastWindowClosed(true); - return; } - - if (s.tray_enabled) + else { if (!tray) { @@ -711,24 +721,6 @@ void main_window::ensure_tray() QApplication::setQuitOnLastWindowClosed(false); } - else - { - if (!isVisible()) - { - show(); - -#ifdef __APPLE__ - raise(); // for OSX -#endif - activateWindow(); // for Windows - } - - if (tray) - tray->hide(); - tray = nullptr; - - QApplication::setQuitOnLastWindowClosed(true); - } } void main_window::toggle_restore_from_tray(QSystemTrayIcon::ActivationReason e) -- cgit v1.2.3