summaryrefslogtreecommitdiff
diff options
authorMarco Trevisan (Treviño) <mail@3v1n0.net>2015-10-30 18:16:12 +0100
committerMarco Trevisan (Treviño) <mail@3v1n0.net>2015-10-30 18:16:12 +0100
commit7e5bab76646682d8d138c9df181e34facd993cbb (patch)
treefba5dcb144ba69ee94e82b61b2059abc9ee8e48e
parentc36926e3f4dae18a277fc19e25b9a5094ce543a8 (diff)
SwitcherController: add ability to add/remove icons, move more logic to the model
(bzr r4027.5.6)
-rw-r--r--launcher/SwitcherController.cpp61
-rw-r--r--launcher/SwitcherController.h8
-rw-r--r--launcher/SwitcherControllerImpl.h5
-rw-r--r--launcher/SwitcherModel.cpp2
4 files changed, 41 insertions, 35 deletions
diff --git a/launcher/SwitcherController.cpp b/launcher/SwitcherController.cpp
index 3d5796aa8..937f7dff7 100644
--- a/launcher/SwitcherController.cpp
+++ b/launcher/SwitcherController.cpp
@@ -45,25 +45,6 @@ const std::string DETAIL_TIMEOUT = "detail-timeout";
const std::string VIEW_CONSTRUCT_IDLE = "view-construct-idle";
const unsigned FADE_DURATION = 80;
const int XY_OFFSET = 100;
-
-/**
- * Helper comparison functor for sorting application icons.
- */
-bool CompareSwitcherItemsPriority(AbstractLauncherIcon::Ptr const& first,
- AbstractLauncherIcon::Ptr const& second)
-{
- if (first->GetIconType() == second->GetIconType())
- return first->SwitcherPriority() > second->SwitcherPriority();
-
- if (first->GetIconType() == AbstractLauncherIcon::IconType::DESKTOP)
- return true;
-
- if (second->GetIconType() == AbstractLauncherIcon::IconType::DESKTOP)
- return false;
-
- return first->GetIconType() < second->GetIconType();
-}
-
}
namespace switcher
@@ -98,7 +79,7 @@ bool Controller::CanShowSwitcher(const std::vector<AbstractLauncherIcon::Ptr>& r
void Controller::Show(ShowMode show,
SortMode sort,
- std::vector<AbstractLauncherIcon::Ptr> results)
+ std::vector<AbstractLauncherIcon::Ptr> const& results)
{
auto uscreen = UScreen::GetDefault();
monitor_ = uscreen->GetMonitorWithMouse();
@@ -106,6 +87,16 @@ void Controller::Show(ShowMode show,
impl_->Show(show, sort, results);
}
+void Controller::AddIcon(AbstractLauncherIcon::Ptr const& icon)
+{
+ impl_->AddIcon(icon);
+}
+
+void Controller::RemoveIcon(AbstractLauncherIcon::Ptr const& icon)
+{
+ impl_->RemoveIcon(icon);
+}
+
void Controller::Select(int index)
{
if (Visible())
@@ -290,23 +281,33 @@ void Controller::Impl::OnBackgroundUpdate(nux::Color const& new_color)
view_->background_color = new_color;
}
+void Controller::Impl::AddIcon(AbstractLauncherIcon::Ptr const& icon)
+{
+ if (!obj_->visible_ || !model_)
+ return;
+
+ model_->AddIcon(icon);
+}
-void Controller::Impl::Show(ShowMode show, SortMode sort, std::vector<AbstractLauncherIcon::Ptr> results)
+void Controller::Impl::RemoveIcon(AbstractLauncherIcon::Ptr const& icon)
{
- if (results.empty() || obj_->visible_)
+ if (!obj_->visible_ || !model_)
return;
- if (sort == SortMode::FOCUS_ORDER)
- {
- std::sort(results.begin(), results.end(), CompareSwitcherItemsPriority);
- }
+ model_->RemoveIcon(icon);
+}
- model_ = std::make_shared<SwitcherModel>(results);
- obj_->AddChild(model_.get());
+void Controller::Impl::Show(ShowMode show_mode, SortMode sort_mode, std::vector<AbstractLauncherIcon::Ptr> const& results)
+{
+ if (results.empty() || obj_->visible_)
+ return;
+
+ model_ = std::make_shared<SwitcherModel>(results, (sort_mode == SortMode::FOCUS_ORDER));
+ 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));
- model_->only_detail_on_viewport = (show == ShowMode::CURRENT_VIEWPORT);
+ obj_->AddChild(model_.get());
SelectFirstItem();
@@ -715,7 +716,7 @@ void Controller::Impl::SelectFirstItem()
{
Window xid = window->window_id();
- if (model_->only_detail_on_viewport && !wm.IsWindowOnCurrentDesktop(xid))
+ if (model_->only_apps_on_viewport && !wm.IsWindowOnCurrentDesktop(xid))
continue;
uint64_t num = wm.GetWindowActiveNumber(xid);
diff --git a/launcher/SwitcherController.h b/launcher/SwitcherController.h
index 9045fa984..f012912b0 100644
--- a/launcher/SwitcherController.h
+++ b/launcher/SwitcherController.h
@@ -72,7 +72,7 @@ struct Selection
};
-class Controller : public debug::Introspectable
+class Controller : public debug::Introspectable, public sigc::trackable
{
public:
class Impl;
@@ -87,10 +87,12 @@ public:
void Show(ShowMode show,
SortMode sort,
- std::vector<launcher::AbstractLauncherIcon::Ptr> results);
+ std::vector<launcher::AbstractLauncherIcon::Ptr> const& results);
void Hide(bool accept_state=true);
- bool CanShowSwitcher(const std::vector<launcher::AbstractLauncherIcon::Ptr>& resutls) const;
+ bool CanShowSwitcher(std::vector<launcher::AbstractLauncherIcon::Ptr> const& resutls) const;
+ void AddIcon(launcher::AbstractLauncherIcon::Ptr const&);
+ void RemoveIcon(launcher::AbstractLauncherIcon::Ptr const&);
bool Visible();
nux::Geometry GetInputWindowGeometry() const;
diff --git a/launcher/SwitcherControllerImpl.h b/launcher/SwitcherControllerImpl.h
index e3fae2681..53df9cf13 100644
--- a/launcher/SwitcherControllerImpl.h
+++ b/launcher/SwitcherControllerImpl.h
@@ -46,10 +46,13 @@ struct Controller::Impl : public sigc::trackable
Controller::WindowCreator const& create_window);
virtual ~Impl() {}
- void Show(ShowMode show, SortMode sort, std::vector<launcher::AbstractLauncherIcon::Ptr> results);
+ 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&);
+
void StartDetailMode();
void StopDetailMode();
diff --git a/launcher/SwitcherModel.cpp b/launcher/SwitcherModel.cpp
index 1c33a0b71..b2c485d6d 100644
--- a/launcher/SwitcherModel.cpp
+++ b/launcher/SwitcherModel.cpp
@@ -83,7 +83,7 @@ SwitcherModel::SwitcherModel(std::vector<AbstractLauncherIcon::Ptr> const& icons
void SwitcherModel::AddIcon(launcher::AbstractLauncherIcon::Ptr const& icon)
{
- if (!icon)
+ if (!icon || !icon->ShowInSwitcher(only_apps_on_viewport))
return;
if (icon->GetQuirk(AbstractLauncherIcon::Quirk::ACTIVE))