diff options
Diffstat (limited to 'gui')
| -rw-r--r-- | gui/init.cpp | 9 | ||||
| -rw-r--r-- | gui/main-window.cpp | 67 | ||||
| -rw-r--r-- | gui/main-window.hpp | 7 | 
3 files changed, 41 insertions, 42 deletions
| diff --git a/gui/init.cpp b/gui/init.cpp index 7ccc67fe..a53df491 100644 --- a/gui/init.cpp +++ b/gui/init.cpp @@ -160,12 +160,11 @@ int run_window(QApplication& app, std::unique_ptr<QWidget> main_window)          return 2;      } -    app.setQuitOnLastWindowClosed(false); +    app.setQuitOnLastWindowClosed(true); +    int status = app.exec(); -    int ret = app.exec(); -    qDebug() << "exit" << ret; - -    return ret; +    qDebug() << "exit status:" << status; +    return status;  }  int otr_main(int argc, char** argv, std::function<QWidget*()> make_main_window) diff --git a/gui/main-window.cpp b/gui/main-window.cpp index bc20cf59..95f1cf46 100644 --- a/gui/main-window.cpp +++ b/gui/main-window.cpp @@ -72,8 +72,6 @@ main_window::main_window() :  {      ui.setupUi(this); -    setAttribute(Qt::WA_QuitOnClose, true); -  #if !defined _WIN32 && !defined __APPLE__      annoy_if_root();  #endif @@ -189,16 +187,7 @@ main_window::main_window() :              this, [&]() { qDebug() << "restart tracker"; stop_tracker_(); start_tracker_(); },              Qt::QueuedConnection); -    // tray -    { -        init_tray_menu(); - -        connect(&s.tray_enabled, -                static_cast<void (base_value::*)(bool) const>(&base_value::valueChanged), -                this, -                [&](bool) { ensure_tray(); }); -        ensure_tray(); -    } +    init_tray();      register_shortcuts();      det_timer.start(1000); @@ -217,7 +206,7 @@ main_window::main_window() :          setVisible(false);  } -void main_window::init_tray_menu() +void main_window::init_tray()  {      tray_menu.clear(); @@ -274,6 +263,11 @@ void main_window::init_tray_menu()      menu_action_exit.setText(tr("Exit"));      QObject::connect(&menu_action_exit, &QAction::triggered, this, &main_window::exit);      tray_menu.addAction(&menu_action_exit); + +    connect(&s.tray_enabled, +            static_cast<void (base_value::*)(bool) const>(&base_value::valueChanged), +            this, +            &main_window::ensure_tray);  }  void main_window::register_shortcuts() @@ -313,15 +307,6 @@ void main_window::die_on_config_not_writable()                            tr("Check permissions for your .ini directory:\n\n\"%1\"%2\n\nExiting now.").arg(group::ini_directory()).arg(pad),                            QMessageBox::Close, QMessageBox::NoButton); -    // signals main() to short-circuit -    //if (!isVisible()) -    //    setEnabled(false); - -    //setVisible(false); - -    // tray related -    //qApp->setQuitOnLastWindowClosed(true); -      exit(EX_DATAERR);  } @@ -361,12 +346,14 @@ main_window::~main_window()  {      if (tray)          tray->hide(); +    tray = nullptr; +      const bool just_stopping = bool(work); -    stop_tracker_();      // stupid ps3 eye has LED issues      if (just_stopping)      { +        stop_tracker_();          close();          QEventLoop ev;          ev.processEvents(); @@ -716,9 +703,11 @@ void main_window::show_mapping_window()  void main_window::exit(int status)  { -    setEnabled(false); +    QApplication::setQuitOnLastWindowClosed(true); +    tray->hide(); +    tray = nullptr;      close(); -    QCoreApplication::exit(status); +    QApplication::exit(status);  }  bool main_window::set_profile(const QString& new_name_) @@ -748,9 +737,12 @@ bool main_window::set_profile(const QString& new_name_)  }  void main_window::ensure_tray() -{ +{          if (!QSystemTrayIcon::isSystemTrayAvailable()) +    { +        QApplication::setQuitOnLastWindowClosed(true);          return; +    }      if (s.tray_enabled)      { @@ -766,6 +758,8 @@ void main_window::ensure_tray()                      this,                      &main_window::toggle_restore_from_tray);          } + +        QApplication::setQuitOnLastWindowClosed(false);      }      else      { @@ -783,6 +777,8 @@ void main_window::ensure_tray()          if (tray)              tray->hide();          tray = nullptr; + +        QApplication::setQuitOnLastWindowClosed(true);      }  } @@ -892,18 +888,21 @@ bool main_window::is_config_listed(const QString& name)  void main_window::changeEvent(QEvent* e)  { -    if (maybe_hide_to_tray(e)) -        e->accept(); -    else -    { -        QMainWindow::changeEvent(e); -    } +    if (!maybe_hide_to_tray(e)) +        e->ignore();  }  void main_window::closeEvent(QCloseEvent* ev)  { -    ev->accept(); -    exit(); +    if (tray && tray->isVisible()) +    { +        ev->ignore(); +        setVisible(false); +    } +    else +    { +        ev->accept(); +    }  }  bool main_window::event(QEvent* event) diff --git a/gui/main-window.hpp b/gui/main-window.hpp index 402202d6..4fb64b70 100644 --- a/gui/main-window.hpp +++ b/gui/main-window.hpp @@ -89,7 +89,6 @@ class OTR_GUI_EXPORT main_window : public QMainWindow, private State      void update_button_state(bool running, bool inertialp);      void display_pose(const double* mapped, const double* raw); -    void ensure_tray();      void set_title(const QString& game_title = QStringLiteral(""));      static bool get_new_config_name_from_dialog(QString &ret);      void set_profile_in_registry(const QString& profile); @@ -97,7 +96,7 @@ class OTR_GUI_EXPORT main_window : public QMainWindow, private State      void set_keys_enabled(bool flag);      bool is_config_listed(const QString& name); -    void init_tray_menu(); +    void init_tray();      void changeEvent(QEvent* e) override;      void closeEvent(QCloseEvent* ev) override; @@ -121,7 +120,7 @@ class OTR_GUI_EXPORT main_window : public QMainWindow, private State  private slots:      void save_modules(); -    void exit(int status = 0); +    void exit(int status = EXIT_SUCCESS);      bool set_profile(const QString& new_name);      void show_tracker_settings(); @@ -141,6 +140,8 @@ private slots:      void start_tracker_();      void stop_tracker_(); +    void ensure_tray(); +      void toggle_restore_from_tray(QSystemTrayIcon::ActivationReason e);  signals: | 
