From 4e74d6edef94e4f2f7caae76088f91e9ee993fba Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sun, 6 Dec 2015 05:14:07 +0100 Subject: gui/keys: allow for pausing global keystrokes for options dialog Toggling tracking while prompting for toggle tracking key causes a deadlock somewhere. --- gui/options-dialog.cpp | 10 ++++++++-- gui/options-dialog.hpp | 3 ++- gui/ui.cpp | 12 +++++++----- gui/ui.h | 1 + 4 files changed, 18 insertions(+), 8 deletions(-) (limited to 'gui') diff --git a/gui/options-dialog.cpp b/gui/options-dialog.cpp index 1edf069d..65407184 100644 --- a/gui/options-dialog.cpp +++ b/gui/options-dialog.cpp @@ -29,8 +29,12 @@ static QString kopts_to_string(const key_opts& kopts) return kopts.keycode; } -OptionsDialog::OptionsDialog(main_settings& main, std::function register_global_keys) - : main(main), register_global_keys(register_global_keys) +OptionsDialog::OptionsDialog(main_settings& main, + std::function register_global_keys, + std::function pause_keybindings) : + main(main), + register_global_keys(register_global_keys), + pause_keybindings(pause_keybindings) { ui.setupUi(this); @@ -115,7 +119,9 @@ void OptionsDialog::bind_key(key_opts& kopts, QLabel* label) d.close(); } }); + pause_keybindings(true); d.exec(); + pause_keybindings(false); register_global_keys(); label->setText(kopts_to_string(kopts)); delete k; diff --git a/gui/options-dialog.hpp b/gui/options-dialog.hpp index 72ae3c30..7700162b 100644 --- a/gui/options-dialog.hpp +++ b/gui/options-dialog.hpp @@ -12,10 +12,11 @@ class OptionsDialog: public QWidget signals: void reload(); public: - OptionsDialog(main_settings& main, std::function register_global_keys); + OptionsDialog(main_settings& main, std::function register_global_keys, std::function pause_keybindings); private: main_settings& main; std::function register_global_keys; + std::function pause_keybindings; Ui::UI_Settings ui; void closeEvent(QCloseEvent *) override { doCancel(); } private slots: diff --git a/gui/ui.cpp b/gui/ui.cpp index 26fcd9ed..e59b1c23 100644 --- a/gui/ui.cpp +++ b/gui/ui.cpp @@ -23,7 +23,8 @@ MainWindow::MainWindow() : pose_update_timer(this), kbd_quit(QKeySequence("Ctrl+Q"), this), no_feed_pixmap(":/images/no-feed.png"), - is_refreshing_profiles(false) + is_refreshing_profiles(false), + keys_paused(false) { ui.setupUi(this); @@ -110,15 +111,15 @@ MainWindow::MainWindow() : QMessageBox::Ok, QMessageBox::NoButton); connect(this, &MainWindow::emit_start_tracker, - this, [&]() -> void { qDebug() << "start tracker"; startTracker(); }, + this, [&]() -> void { if (keys_paused) return; qDebug() << "start tracker"; startTracker(); }, Qt::QueuedConnection); connect(this, &MainWindow::emit_stop_tracker, - this, [&]() -> void { qDebug() << "stop tracker"; stopTracker(); }, + this, [&]() -> void { if (keys_paused) return; qDebug() << "stop tracker"; stopTracker(); }, Qt::QueuedConnection); connect(this, &MainWindow::emit_toggle_tracker, - this, [&]() -> void { qDebug() << "toggle tracker"; if (work) stopTracker(); else startTracker(); }, + this, [&]() -> void { if (keys_paused) return; qDebug() << "toggle tracker"; if (work) stopTracker(); else startTracker(); }, Qt::QueuedConnection); register_shortcuts(); @@ -493,7 +494,8 @@ bool mk_window(mem* place, Args&&... params) void MainWindow::show_options_dialog() { if (mk_window(&options_widget, s, - [&]() -> void { register_shortcuts(); })) + [&]() -> void { register_shortcuts(); }, + [&](bool flag) -> void { keys_paused = flag; })) connect(options_widget.get(), SIGNAL(reload()), this, SLOT(reload_options())); } diff --git a/gui/ui.h b/gui/ui.h index 12ef1f24..ee0a3ce7 100644 --- a/gui/ui.h +++ b/gui/ui.h @@ -56,6 +56,7 @@ class MainWindow : public QMainWindow, private State process_detector_worker det; QMenu profile_menu; bool is_refreshing_profiles; + volatile bool keys_paused; QTimer save_timer; mem current_tracker() -- cgit v1.2.3