diff options
| author | Marco Trevisan (Treviño) <mail@3v1n0.net> | 2015-10-31 21:45:11 +0100 |
|---|---|---|
| committer | Marco Trevisan (Treviño) <mail@3v1n0.net> | 2015-10-31 21:45:11 +0100 |
| commit | e51041478a31890246c7fabc271a7fc7d6e4d524 (patch) | |
| tree | de69220e114c1f4e4cdd88d3c789574aed487556 | |
| parent | 135edd0fe3066376421cd027be6b1cec5efe92fe (diff) | |
SwitcherModel: don't hide the switcher if there are no more detail windows open
Also fix a crash when removing an icon and we're selecting the last element (bzr r4027.5.12)
| -rw-r--r-- | launcher/SwitcherController.cpp | 12 | ||||
| -rw-r--r-- | launcher/SwitcherControllerImpl.h | 1 | ||||
| -rw-r--r-- | launcher/SwitcherModel.cpp | 37 | ||||
| -rw-r--r-- | launcher/SwitcherModel.h | 2 |
4 files changed, 24 insertions, 28 deletions
diff --git a/launcher/SwitcherController.cpp b/launcher/SwitcherController.cpp index 937f7dff7..7688c99fe 100644 --- a/launcher/SwitcherController.cpp +++ b/launcher/SwitcherController.cpp @@ -306,7 +306,6 @@ void Controller::Impl::Show(ShowMode show_mode, SortMode sort_mode, std::vector< model_->only_apps_on_viewport = (show_mode == ShowMode::CURRENT_VIEWPORT); model_->selection_changed.connect(sigc::mem_fun(this, &Controller::Impl::OnModelSelectionChanged)); model_->detail_selection.changed.connect([this] (bool) { sources_.Remove(DETAIL_TIMEOUT); }); - model_->request_detail_hide.connect(sigc::mem_fun(this, &Controller::Impl::DetailHide)); obj_->AddChild(model_.get()); SelectFirstItem(); @@ -428,9 +427,7 @@ void Controller::Impl::ConstructView() view_->SetModel(model_); view_->background_color = WindowManager::Default().average_color(); view_->monitor = obj_->monitor_; - view_->hide_request.connect(sigc::mem_fun(this, &Controller::Impl::Hide)); - view_->switcher_mouse_up.connect([this] (int icon_index, int button) { if (button == 3) InitiateDetail(true); @@ -479,15 +476,6 @@ void Controller::Impl::Hide(bool accept_state) animation::StartOrReverse(fade_animator_, animation::Direction::BACKWARD); } -void Controller::Impl::DetailHide() -{ - // FIXME We need to refactor SwitcherModel so we can add/remove icons without causing - // a crash. If you remove the last application in the list it crashes. - obj_->detail.changed.emit(false); - model_->detail_selection = false; - Hide(false); -} - void Controller::Impl::HideWindow() { if (model_->detail_selection()) diff --git a/launcher/SwitcherControllerImpl.h b/launcher/SwitcherControllerImpl.h index 53df9cf13..6b2c9fd5f 100644 --- a/launcher/SwitcherControllerImpl.h +++ b/launcher/SwitcherControllerImpl.h @@ -48,7 +48,6 @@ struct Controller::Impl : public sigc::trackable void Show(ShowMode show, SortMode sort, std::vector<launcher::AbstractLauncherIcon::Ptr> const& results); void Hide(bool accept_state); - void DetailHide(); void AddIcon(launcher::AbstractLauncherIcon::Ptr const&); void RemoveIcon(launcher::AbstractLauncherIcon::Ptr const&); diff --git a/launcher/SwitcherModel.cpp b/launcher/SwitcherModel.cpp index 206762785..223b68421 100644 --- a/launcher/SwitcherModel.cpp +++ b/launcher/SwitcherModel.cpp @@ -114,7 +114,10 @@ void SwitcherModel::VerifyApplications() it = applications_.erase(it); anything_changed = true; - if (icon_index < index_) + if (detail_selection && icon_index == index_) + UnsetDetailSelection(); + + if (icon_index < index_ || index_ == applications_.size()) PrevIndex(); continue; @@ -193,12 +196,18 @@ void SwitcherModel::RemoveIcon(launcher::AbstractLauncherIcon::Ptr const& icon) auto icon_it = std::find(applications_.begin(), applications_.end(), icon); if (icon_it != applications_.end()) { + auto icon_index = icon_it - applications_.begin(); applications_.erase(icon_it); if (last_active_application_ == icon) UpdateLastActiveApplication(); - NextIndex(); + if (detail_selection && icon_index == index_) + UnsetDetailSelection(); + + if (icon_index < index_ || index_ == applications_.size()) + PrevIndex(); + updated.emit(); } else @@ -326,17 +335,14 @@ std::vector<Window> SwitcherModel::DetailXids() const results.push_back(xid); } - if (results.empty() && detail_selection) - { - request_detail_hide.emit(); + if (results.empty()) return results; - } std::sort(results.begin(), results.end(), [&wm](Window first, Window second) { - return wm.GetWindowActiveNumber(first) > wm.GetWindowActiveNumber(second); + return wm.GetWindowActiveNumber(first) > wm.GetWindowActiveNumber(second); }); - if (Selection() == last_active_application_ && results.size() > 1) + if (Selection() == last_active_application_) { results.push_back(results.front()); results.erase(results.begin()); @@ -357,6 +363,13 @@ Window SwitcherModel::DetailSelectionWindow() const return windows[detail_selection_index]; } +void SwitcherModel::UnsetDetailSelection() +{ + detail_selection = false; + detail_selection_index = 0; + row_index_ = 0; +} + void SwitcherModel::NextIndex() { last_index_ = index_; @@ -366,9 +379,7 @@ void SwitcherModel::NextIndex() void SwitcherModel::Next() { NextIndex(); - detail_selection = false; - detail_selection_index = 0; - row_index_ = 0; + UnsetDetailSelection(); selection_changed.emit(Selection()); } @@ -381,9 +392,7 @@ void SwitcherModel::PrevIndex() void SwitcherModel::Prev() { PrevIndex(); - detail_selection = false; - detail_selection_index = 0; - row_index_ = 0; + UnsetDetailSelection(); selection_changed.emit(Selection()); } diff --git a/launcher/SwitcherModel.h b/launcher/SwitcherModel.h index be04e7cc5..c7382816d 100644 --- a/launcher/SwitcherModel.h +++ b/launcher/SwitcherModel.h @@ -104,7 +104,6 @@ public: void Select(unsigned int index); sigc::signal<void, launcher::AbstractLauncherIcon::Ptr const&> selection_changed; - sigc::signal<void> request_detail_hide; sigc::signal<void> updated; protected: @@ -121,6 +120,7 @@ private: void VerifyApplications(); void UpdateLastActiveApplication(); void OnIconVisibilityChanged(); + void UnsetDetailSelection(); void NextIndex(); void PrevIndex(); |
