Merge lp:~3v1n0/unity/switcher-dynamic-model into lp:unity

Proposed by Marco Trevisan (Treviño)
Status: Merged
Approved by: Andrea Azzarone
Approved revision: no longer in the source branch.
Merged at revision: 4038
Proposed branch: lp:~3v1n0/unity/switcher-dynamic-model
Merge into: lp:unity
Diff against target: 1419 lines (+398/-225)
23 files modified
launcher/AbstractLauncherIcon.h (+2/-0)
launcher/ApplicationLauncherIcon.cpp (+4/-11)
launcher/LauncherController.cpp (+5/-6)
launcher/LauncherController.h (+3/-0)
launcher/LauncherIcon.cpp (+2/-2)
launcher/LauncherIcon.h (+0/-3)
launcher/LauncherModel.cpp (+7/-5)
launcher/LauncherModel.h (+0/-1)
launcher/SwitcherController.cpp (+33/-43)
launcher/SwitcherController.h (+5/-3)
launcher/SwitcherControllerImpl.h (+4/-2)
launcher/SwitcherModel.cpp (+253/-77)
launcher/SwitcherModel.h (+22/-7)
launcher/SwitcherView.cpp (+2/-1)
plugins/unityshell/src/unity-launcher-icon-accessible.cpp (+2/-2)
plugins/unityshell/src/unityshell.cpp (+23/-19)
plugins/unityshell/src/unityshell.h (+4/-5)
tests/autopilot/unity/emulators/switcher.py (+3/-3)
tests/test_switcher_controller.cpp (+1/-1)
tests/test_switcher_controller.h (+1/-0)
tests/test_switcher_controller_class.cpp (+5/-0)
tests/test_switcher_model.cpp (+15/-32)
tests/test_switcher_view.cpp (+2/-2)
To merge this branch: bzr merge lp:~3v1n0/unity/switcher-dynamic-model
Reviewer Review Type Date Requested Status
Andrea Azzarone (community) Approve
PS Jenkins bot (community) continuous-integration Needs Fixing
Review via email: mp+276391@code.launchpad.net

Commit message

SwitcherModel: allow to add/remove icons dynamically and update them when they require it

We keep hidden applications in a separated vector; when an application becomes
invisible in switcher we need to move it to the hidden_applications_ vector,
if it becomes visible again we put it back on the main model vector.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

FAILED: Continuous integration, rev:4051
http://jenkins.qa.ubuntu.com/job/unity-ci/1332/
Executed test runs:
    FAILURE: http://jenkins.qa.ubuntu.com/job/unity-wily-armhf-ci/108/console

Click here to trigger a rebuild:
http://s-jenkins.ubuntu-ci:8080/job/unity-ci/1332/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
Andrea Azzarone (azzar1) wrote :

LGTM. I have been running it for few days and I could not spot any regression.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'launcher/AbstractLauncherIcon.h'
2--- launcher/AbstractLauncherIcon.h 2015-03-20 16:23:04 +0000
3+++ launcher/AbstractLauncherIcon.h 2015-12-04 17:15:35 +0000
4@@ -253,6 +253,8 @@
5 sigc::signal<void, AbstractLauncherIcon::Ptr const&> remove;
6 sigc::signal<void, nux::ObjectPtr<nux::View>> tooltip_visible;
7 sigc::signal<void, int> visibility_changed;
8+ sigc::signal<void, int> windows_changed;
9+ sigc::signal<void, Quirk, int> quirks_changed;
10 sigc::signal<void> position_saved;
11 sigc::signal<void> position_forgot;
12 sigc::signal<void, std::string const&> uri_changed;
13
14=== modified file 'launcher/ApplicationLauncherIcon.cpp'
15--- launcher/ApplicationLauncherIcon.cpp 2015-10-27 19:21:27 +0000
16+++ launcher/ApplicationLauncherIcon.cpp 2015-12-04 17:15:35 +0000
17@@ -736,8 +736,6 @@
18
19 for (unsigned i = 0; i < monitors::MAX; ++i)
20 SetNumberOfWindowsVisibleOnMonitor(number_of_windows_on_monitor[i], i);
21-
22- WindowsChanged.emit();
23 }
24
25 void ApplicationLauncherIcon::EnsureWindowsLocation()
26@@ -1245,29 +1243,24 @@
27
28 bool ApplicationLauncherIcon::ShowInSwitcher(bool current)
29 {
30- bool result = false;
31-
32- if (IsRunning() && IsVisible())
33+ if (!removed() && IsRunning() && IsVisible())
34 {
35 // If current is true, we only want to show the current workspace.
36 if (!current)
37 {
38- result = true;
39+ return true;
40 }
41 else
42 {
43 for (unsigned i = 0; i < monitors::MAX; ++i)
44 {
45 if (WindowVisibleOnMonitor(i))
46- {
47- result = true;
48- break;
49- }
50+ return true;
51 }
52 }
53 }
54
55- return result;
56+ return false;
57 }
58
59 bool ApplicationLauncherIcon::AllowDetailViewInSwitcher() const
60
61=== modified file 'launcher/LauncherController.cpp'
62--- launcher/LauncherController.cpp 2015-10-27 19:04:37 +0000
63+++ launcher/LauncherController.cpp 2015-12-04 17:15:35 +0000
64@@ -1049,6 +1049,8 @@
65 favorite_store.favorite_removed.connect(sigc::mem_fun(this, &Impl::OnFavoriteStoreFavoriteRemoved));
66 favorite_store.reordered.connect(sigc::mem_fun(this, &Impl::ResetIconPriorities));
67
68+ model_->icon_added.connect(sigc::mem_fun(&parent_->icon_added, &decltype(parent_->icon_added)::emit));
69+ model_->icon_removed.connect(sigc::mem_fun(&parent_->icon_removed, &decltype(parent_->icon_removed)::emit));
70 model_->order_changed.connect(sigc::mem_fun(this, &Impl::SortAndUpdate));
71 model_->icon_removed.connect(sigc::mem_fun(this, &Impl::OnIconRemoved));
72 model_->saved.connect(sigc::mem_fun(this, &Impl::SaveIconsOrder));
73@@ -1115,13 +1117,10 @@
74
75 for (auto icon : *(pimpl->model_))
76 {
77- if (icon->ShowInSwitcher(current))
78+ //otherwise we get two desktop icons in the switcher.
79+ if (icon->GetIconType() != AbstractLauncherIcon::IconType::DESKTOP)
80 {
81- //otherwise we get two desktop icons in the switcher.
82- if (icon->GetIconType() != AbstractLauncherIcon::IconType::DESKTOP)
83- {
84- results.push_back(icon);
85- }
86+ results.push_back(icon);
87 }
88 }
89 return results;
90
91=== modified file 'launcher/LauncherController.h'
92--- launcher/LauncherController.h 2014-03-20 00:04:14 +0000
93+++ launcher/LauncherController.h 2015-12-04 17:15:35 +0000
94@@ -80,6 +80,9 @@
95
96 void ClearTooltips();
97
98+ sigc::signal<void, AbstractLauncherIcon::Ptr const&> icon_added;
99+ sigc::signal<void, AbstractLauncherIcon::Ptr const&> icon_removed;
100+
101 protected:
102 // Introspectable methods
103 std::string GetName() const;
104
105=== modified file 'launcher/LauncherIcon.cpp'
106--- launcher/LauncherIcon.cpp 2015-10-05 16:52:24 +0000
107+++ launcher/LauncherIcon.cpp 2015-12-04 17:15:35 +0000
108@@ -750,9 +750,9 @@
109 return;
110
111 _has_visible_window[monitor] = (number_of_windows > 0);
112-
113 _number_of_visible_windows[monitor] = number_of_windows;
114
115+ windows_changed.emit(monitor);
116 EmitNeedsRedraw(monitor);
117 }
118
119@@ -895,7 +895,7 @@
120 if (quirk == Quirk::VISIBLE)
121 visibility_changed.emit(monitor);
122
123- QuirksChanged.emit();
124+ quirks_changed.emit(quirk, monitor);
125 }
126
127 void LauncherIcon::FullyAnimateQuirkDelayed(guint ms, LauncherIcon::Quirk quirk, int monitor)
128
129=== modified file 'launcher/LauncherIcon.h'
130--- launcher/LauncherIcon.h 2015-03-20 16:23:04 +0000
131+++ launcher/LauncherIcon.h 2015-12-04 17:15:35 +0000
132@@ -139,9 +139,6 @@
133
134 void SkipQuirkAnimation(Quirk quirk, int monitor = -1);
135
136- sigc::signal<void> QuirksChanged;
137- sigc::signal<void> WindowsChanged;
138-
139 IconType GetIconType() const;
140
141 virtual nux::Color BackgroundColor() const;
142
143=== modified file 'launcher/LauncherModel.cpp'
144--- launcher/LauncherModel.cpp 2014-01-13 21:03:53 +0000
145+++ launcher/LauncherModel.cpp 2015-12-04 17:15:35 +0000
146@@ -43,19 +43,21 @@
147 .add("selection", selection_);
148 }
149
150-unity::debug::Introspectable::IntrospectableList LauncherModel::GetIntrospectableChildren()
151+debug::Introspectable::IntrospectableList LauncherModel::GetIntrospectableChildren()
152 {
153 int order = 0;
154- introspection_results_.clear();
155+ std::list<unity::debug::Introspectable*> children;
156
157- for (auto icon : _inner)
158+ for (auto const& icon : _inner)
159+ {
160 if (!icon->removed)
161 {
162 icon->SetOrder(++order);
163- introspection_results_.push_back(icon.GetPointer());
164+ children.push_back(icon.GetPointer());
165 }
166+ }
167
168- return introspection_results_;
169+ return children;
170 }
171
172 bool LauncherModel::IconShouldShelf(AbstractLauncherIcon::Ptr const& icon) const
173
174=== modified file 'launcher/LauncherModel.h'
175--- launcher/LauncherModel.h 2013-09-19 16:44:03 +0000
176+++ launcher/LauncherModel.h 2015-12-04 17:15:35 +0000
177@@ -96,7 +96,6 @@
178 Base _inner_shelf;
179 Base _inner_main;
180 int selection_;
181- std::list<unity::debug::Introspectable*> introspection_results_;
182 glib::SourceManager timeouts_;
183
184 bool Populate();
185
186=== modified file 'launcher/SwitcherController.cpp'
187--- launcher/SwitcherController.cpp 2015-04-03 15:46:16 +0000
188+++ launcher/SwitcherController.cpp 2015-12-04 17:15:35 +0000
189@@ -45,25 +45,6 @@
190 const std::string VIEW_CONSTRUCT_IDLE = "view-construct-idle";
191 const unsigned FADE_DURATION = 80;
192 const int XY_OFFSET = 100;
193-
194-/**
195- * Helper comparison functor for sorting application icons.
196- */
197-bool CompareSwitcherItemsPriority(AbstractLauncherIcon::Ptr const& first,
198- AbstractLauncherIcon::Ptr const& second)
199-{
200- if (first->GetIconType() == second->GetIconType())
201- return first->SwitcherPriority() > second->SwitcherPriority();
202-
203- if (first->GetIconType() == AbstractLauncherIcon::IconType::DESKTOP)
204- return true;
205-
206- if (second->GetIconType() == AbstractLauncherIcon::IconType::DESKTOP)
207- return false;
208-
209- return first->GetIconType() < second->GetIconType();
210-}
211-
212 }
213
214 namespace switcher
215@@ -98,7 +79,7 @@
216
217 void Controller::Show(ShowMode show,
218 SortMode sort,
219- std::vector<AbstractLauncherIcon::Ptr> results)
220+ std::vector<AbstractLauncherIcon::Ptr> const& results)
221 {
222 auto uscreen = UScreen::GetDefault();
223 monitor_ = uscreen->GetMonitorWithMouse();
224@@ -106,6 +87,16 @@
225 impl_->Show(show, sort, results);
226 }
227
228+void Controller::AddIcon(AbstractLauncherIcon::Ptr const& icon)
229+{
230+ impl_->AddIcon(icon);
231+}
232+
233+void Controller::RemoveIcon(AbstractLauncherIcon::Ptr const& icon)
234+{
235+ impl_->RemoveIcon(icon);
236+}
237+
238 void Controller::Select(int index)
239 {
240 if (Visible())
241@@ -290,23 +281,33 @@
242 view_->background_color = new_color;
243 }
244
245-
246-void Controller::Impl::Show(ShowMode show, SortMode sort, std::vector<AbstractLauncherIcon::Ptr> results)
247+void Controller::Impl::AddIcon(AbstractLauncherIcon::Ptr const& icon)
248+{
249+ if (!obj_->visible_ || !model_)
250+ return;
251+
252+ model_->AddIcon(icon);
253+}
254+
255+void Controller::Impl::RemoveIcon(AbstractLauncherIcon::Ptr const& icon)
256+{
257+ if (!obj_->visible_ || !model_)
258+ return;
259+
260+ model_->RemoveIcon(icon);
261+}
262+
263+void Controller::Impl::Show(ShowMode show_mode, SortMode sort_mode, std::vector<AbstractLauncherIcon::Ptr> const& results)
264 {
265 if (results.empty() || obj_->visible_)
266 return;
267
268- if (sort == SortMode::FOCUS_ORDER)
269- {
270- std::sort(results.begin(), results.end(), CompareSwitcherItemsPriority);
271- }
272-
273- model_ = std::make_shared<SwitcherModel>(results);
274- obj_->AddChild(model_.get());
275+ model_ = std::make_shared<SwitcherModel>(results, (sort_mode == SortMode::FOCUS_ORDER));
276+ model_->only_apps_on_viewport = (show_mode == ShowMode::CURRENT_VIEWPORT);
277 model_->selection_changed.connect(sigc::mem_fun(this, &Controller::Impl::OnModelSelectionChanged));
278 model_->detail_selection.changed.connect([this] (bool) { sources_.Remove(DETAIL_TIMEOUT); });
279- model_->request_detail_hide.connect(sigc::mem_fun(this, &Controller::Impl::DetailHide));
280- model_->only_detail_on_viewport = (show == ShowMode::CURRENT_VIEWPORT);
281+ model_->updated.connect([this] { if (!model_->Size()) Hide(false); });
282+ obj_->AddChild(model_.get());
283
284 SelectFirstItem();
285
286@@ -427,9 +428,7 @@
287 view_->SetModel(model_);
288 view_->background_color = WindowManager::Default().average_color();
289 view_->monitor = obj_->monitor_;
290-
291 view_->hide_request.connect(sigc::mem_fun(this, &Controller::Impl::Hide));
292-
293 view_->switcher_mouse_up.connect([this] (int icon_index, int button) {
294 if (button == 3)
295 InitiateDetail(true);
296@@ -478,15 +477,6 @@
297 animation::StartOrReverse(fade_animator_, animation::Direction::BACKWARD);
298 }
299
300-void Controller::Impl::DetailHide()
301-{
302- // FIXME We need to refactor SwitcherModel so we can add/remove icons without causing
303- // a crash. If you remove the last application in the list it crashes.
304- obj_->detail.changed.emit(false);
305- model_->detail_selection = false;
306- Hide(false);
307-}
308-
309 void Controller::Impl::HideWindow()
310 {
311 if (model_->detail_selection())
312@@ -715,7 +705,7 @@
313 {
314 Window xid = window->window_id();
315
316- if (model_->only_detail_on_viewport && !wm.IsWindowOnCurrentDesktop(xid))
317+ if (model_->only_apps_on_viewport && !wm.IsWindowOnCurrentDesktop(xid))
318 continue;
319
320 uint64_t num = wm.GetWindowActiveNumber(xid);
321
322=== modified file 'launcher/SwitcherController.h'
323--- launcher/SwitcherController.h 2015-04-03 15:32:24 +0000
324+++ launcher/SwitcherController.h 2015-12-04 17:15:35 +0000
325@@ -72,7 +72,7 @@
326 };
327
328
329-class Controller : public debug::Introspectable
330+class Controller : public debug::Introspectable, public sigc::trackable
331 {
332 public:
333 class Impl;
334@@ -87,10 +87,12 @@
335
336 void Show(ShowMode show,
337 SortMode sort,
338- std::vector<launcher::AbstractLauncherIcon::Ptr> results);
339+ std::vector<launcher::AbstractLauncherIcon::Ptr> const& results);
340 void Hide(bool accept_state=true);
341
342- bool CanShowSwitcher(const std::vector<launcher::AbstractLauncherIcon::Ptr>& resutls) const;
343+ bool CanShowSwitcher(std::vector<launcher::AbstractLauncherIcon::Ptr> const& resutls) const;
344+ void AddIcon(launcher::AbstractLauncherIcon::Ptr const&);
345+ void RemoveIcon(launcher::AbstractLauncherIcon::Ptr const&);
346
347 bool Visible();
348 nux::Geometry GetInputWindowGeometry() const;
349
350=== modified file 'launcher/SwitcherControllerImpl.h'
351--- launcher/SwitcherControllerImpl.h 2014-03-25 19:07:36 +0000
352+++ launcher/SwitcherControllerImpl.h 2015-12-04 17:15:35 +0000
353@@ -46,9 +46,11 @@
354 Controller::WindowCreator const& create_window);
355 virtual ~Impl() {}
356
357- void Show(ShowMode show, SortMode sort, std::vector<launcher::AbstractLauncherIcon::Ptr> results);
358+ void Show(ShowMode show, SortMode sort, std::vector<launcher::AbstractLauncherIcon::Ptr> const& results);
359 void Hide(bool accept_state);
360- void DetailHide();
361+
362+ void AddIcon(launcher::AbstractLauncherIcon::Ptr const&);
363+ void RemoveIcon(launcher::AbstractLauncherIcon::Ptr const&);
364
365 void StartDetailMode();
366 void StopDetailMode();
367
368=== modified file 'launcher/SwitcherModel.cpp'
369--- launcher/SwitcherModel.cpp 2015-04-03 15:19:31 +0000
370+++ launcher/SwitcherModel.cpp 2015-12-04 17:15:35 +0000
371@@ -1,5 +1,5 @@
372 /*
373- * Copyright (C) 2011-2012 Canonical Ltd
374+ * Copyright (C) 2011-2015 Canonical Ltd
375 *
376 * This program is free software: you can redistribute it and/or modify
377 * it under the terms of the GNU General Public License version 3 as
378@@ -14,6 +14,7 @@
379 * along with this program. If not, see <http://www.gnu.org/licenses/>.
380 *
381 * Authored by: Jason Smith <jason.smith@canonical.com>
382+ * Marco Trevisan <marco.trevisan@canonical.com>
383 */
384
385 #include <math.h>
386@@ -28,41 +29,207 @@
387
388 namespace switcher
389 {
390-
391-
392-SwitcherModel::SwitcherModel(std::vector<AbstractLauncherIcon::Ptr> const& icons)
393+namespace
394+{
395+/**
396+ * Helper comparison functor for sorting application icons.
397+ */
398+bool CompareSwitcherItemsPriority(AbstractLauncherIcon::Ptr const& first,
399+ AbstractLauncherIcon::Ptr const& second)
400+{
401+ if (first->GetIconType() == second->GetIconType())
402+ return first->SwitcherPriority() > second->SwitcherPriority();
403+
404+ if (first->GetIconType() == AbstractLauncherIcon::IconType::DESKTOP)
405+ return true;
406+
407+ if (second->GetIconType() == AbstractLauncherIcon::IconType::DESKTOP)
408+ return false;
409+
410+ return first->GetIconType() < second->GetIconType();
411+}
412+}
413+
414+
415+SwitcherModel::SwitcherModel(std::vector<AbstractLauncherIcon::Ptr> const& icons, bool sort_by_priority)
416 : detail_selection(false)
417 , detail_selection_index(0)
418- , only_detail_on_viewport(false)
419+ , only_apps_on_viewport(true)
420 , applications_(icons)
421+ , sort_by_priority_(sort_by_priority)
422 , index_(0)
423 , last_index_(0)
424 , row_index_(0)
425 {
426- // When using Webapps, there are more than one active icon, so let's just pick
427- // up the first one found which is the web browser.
428- bool found = false;
429- int order = 0;
430-
431+ for (auto it = applications_.begin(); it != applications_.end();)
432+ {
433+ ConnectToIconSignals(*it);
434+
435+ if (!(*it)->ShowInSwitcher(only_apps_on_viewport))
436+ {
437+ hidden_applications_.push_back(*it);
438+ it = applications_.erase(it);
439+ continue;
440+ }
441+
442+ ++it;
443+ }
444+
445+ if (sort_by_priority_)
446+ std::sort(std::begin(applications_), std::end(applications_), CompareSwitcherItemsPriority);
447+
448+ UpdateLastActiveApplication();
449+
450+ only_apps_on_viewport.changed.connect([this] (bool) {
451+ VerifyApplications();
452+ });
453+}
454+
455+void SwitcherModel::UpdateLastActiveApplication()
456+{
457 for (auto const& application : applications_)
458 {
459- application->SetOrder(++order);
460-
461- AddChild(application.GetPointer());
462- if (application->GetQuirk(AbstractLauncherIcon::Quirk::ACTIVE) && !found)
463+ if (application->GetQuirk(AbstractLauncherIcon::Quirk::ACTIVE))
464 {
465 last_active_application_ = application;
466- found = true;
467- }
468- }
469-}
470-
471-SwitcherModel::~SwitcherModel()
472-{
473- for (auto const& application : applications_)
474- {
475- RemoveChild(application.GetPointer());
476- }
477+ break;
478+ }
479+ }
480+}
481+
482+void SwitcherModel::VerifyApplications()
483+{
484+ bool anything_changed = false;
485+
486+ for (auto it = applications_.begin(); it != applications_.end();)
487+ {
488+ if (!(*it)->ShowInSwitcher(only_apps_on_viewport))
489+ {
490+ unsigned icon_index = it - applications_.begin();
491+ hidden_applications_.push_back(*it);
492+ it = applications_.erase(it);
493+ anything_changed = true;
494+ bool was_in_detail = (detail_selection && icon_index == index_);
495+
496+ if (icon_index < index_ || index_ == applications_.size())
497+ PrevIndex();
498+
499+ if (was_in_detail)
500+ UnsetDetailSelection();
501+
502+ continue;
503+ }
504+
505+ ++it;
506+ }
507+
508+ for (auto it = hidden_applications_.begin(); it != hidden_applications_.end();)
509+ {
510+ if ((*it)->ShowInSwitcher(only_apps_on_viewport))
511+ {
512+ InsertIcon(*it);
513+ it = hidden_applications_.erase(it);
514+ anything_changed = true;
515+ continue;
516+ }
517+
518+ ++it;
519+ }
520+
521+ if (anything_changed)
522+ {
523+ if (!last_active_application_ || !last_active_application_->ShowInSwitcher(only_apps_on_viewport))
524+ UpdateLastActiveApplication();
525+
526+ updated.emit();
527+ }
528+}
529+
530+void SwitcherModel::InsertIcon(AbstractLauncherIcon::Ptr const& application)
531+{
532+ if (sort_by_priority_)
533+ {
534+ auto pos = std::upper_bound(applications_.begin(), applications_.end(), application, CompareSwitcherItemsPriority);
535+ unsigned icon_index = pos - applications_.begin();
536+ applications_.insert(pos, application);
537+
538+ if (icon_index <= index_)
539+ NextIndex();
540+ }
541+ else
542+ {
543+ applications_.push_back(application);
544+ }
545+}
546+
547+void SwitcherModel::ConnectToIconSignals(launcher::AbstractLauncherIcon::Ptr const& icon)
548+{
549+ icon->quirks_changed.connect(sigc::hide(sigc::hide(sigc::mem_fun(this, &SwitcherModel::OnIconQuirksChanged))));
550+ icon->windows_changed.connect(sigc::hide(sigc::mem_fun(&updated, &decltype(updated)::emit)));
551+}
552+
553+void SwitcherModel::AddIcon(AbstractLauncherIcon::Ptr const& icon)
554+{
555+ if (!icon || icon->GetIconType() != AbstractLauncherIcon::IconType::APPLICATION)
556+ return;
557+
558+ if (icon->ShowInSwitcher(only_apps_on_viewport))
559+ {
560+ if (icon->GetQuirk(AbstractLauncherIcon::Quirk::ACTIVE))
561+ last_active_application_ = icon;
562+
563+ if (std::find(applications_.begin(), applications_.end(), icon) == applications_.end())
564+ {
565+ InsertIcon(icon);
566+ ConnectToIconSignals(icon);
567+ updated.emit();
568+ }
569+ }
570+ else if (std::find(hidden_applications_.begin(), hidden_applications_.end(), icon) == hidden_applications_.end())
571+ {
572+ hidden_applications_.push_back(icon);
573+ ConnectToIconSignals(icon);
574+ }
575+}
576+
577+void SwitcherModel::RemoveIcon(launcher::AbstractLauncherIcon::Ptr const& icon)
578+{
579+ auto icon_it = std::find(applications_.begin(), applications_.end(), icon);
580+ if (icon_it != applications_.end())
581+ {
582+ unsigned icon_index = icon_it - applications_.begin();
583+ bool was_in_detail = (detail_selection && icon_index == index_);
584+ applications_.erase(icon_it);
585+
586+ if (last_active_application_ == icon)
587+ UpdateLastActiveApplication();
588+
589+ if (icon_index < index_ || index_ == applications_.size())
590+ PrevIndex();
591+
592+ if (was_in_detail)
593+ UnsetDetailSelection();
594+
595+ updated.emit();
596+ }
597+ else
598+ {
599+ hidden_applications_.erase(std::remove(hidden_applications_.begin(), hidden_applications_.end(), icon), hidden_applications_.end());
600+ }
601+}
602+
603+void SwitcherModel::OnIconQuirksChanged()
604+{
605+ auto old_selection = Selection();
606+ VerifyApplications();
607+
608+ if (old_selection == last_active_application_)
609+ UpdateLastActiveApplication();
610+
611+ auto const& new_selection = Selection();
612+
613+ if (old_selection != new_selection)
614+ selection_changed.emit(new_selection);
615 }
616
617 std::string SwitcherModel::GetName() const
618@@ -74,14 +241,31 @@
619 {
620 introspection
621 .add("detail-selection", detail_selection)
622- .add("detail-selection-index", (int)detail_selection_index)
623+ .add("detail-selection-index", detail_selection_index())
624 .add("detail-current-count", DetailXids().size())
625 .add("detail-windows", glib::Variant::FromVector(DetailXids()))
626- .add("only-detail-on-viewport", only_detail_on_viewport)
627+ .add("only-apps-on-viewport", only_apps_on_viewport())
628 .add("selection-index", SelectionIndex())
629 .add("last-selection-index", LastSelectionIndex());
630 }
631
632+debug::Introspectable::IntrospectableList SwitcherModel::GetIntrospectableChildren()
633+{
634+ debug::Introspectable::IntrospectableList children;
635+ unsigned order = 0;
636+
637+ for (auto const& icon : applications_)
638+ {
639+ if (!icon->ShowInSwitcher(only_apps_on_viewport))
640+ {
641+ icon->SetOrder(++order);
642+ children.push_back(icon.GetPointer());
643+ }
644+ }
645+
646+ return children;
647+}
648+
649 SwitcherModel::iterator SwitcherModel::begin()
650 {
651 return applications_.begin();
652@@ -104,12 +288,13 @@
653
654 AbstractLauncherIcon::Ptr SwitcherModel::at(unsigned int index) const
655 {
656- if ((int) index >= Size ())
657+ if (index >= applications_.size())
658 return AbstractLauncherIcon::Ptr();
659+
660 return applications_[index];
661 }
662
663-int SwitcherModel::Size() const
664+size_t SwitcherModel::Size() const
665 {
666 return applications_.size();
667 }
668@@ -148,21 +333,18 @@
669 {
670 Window xid = window->window_id();
671
672- if (!only_detail_on_viewport || wm.IsWindowOnCurrentDesktop(xid))
673+ if (!only_apps_on_viewport || wm.IsWindowOnCurrentDesktop(xid))
674 results.push_back(xid);
675 }
676
677- if (results.empty() && detail_selection)
678- {
679- request_detail_hide.emit();
680+ if (results.empty())
681 return results;
682- }
683
684 std::sort(results.begin(), results.end(), [&wm](Window first, Window second) {
685- return wm.GetWindowActiveNumber(first) > wm.GetWindowActiveNumber(second);
686+ return wm.GetWindowActiveNumber(first) > wm.GetWindowActiveNumber(second);
687 });
688
689- if (Selection() == last_active_application_ && results.size() > 1)
690+ if (Selection() == last_active_application_)
691 {
692 results.push_back(results.front());
693 results.erase(results.begin());
694@@ -183,32 +365,36 @@
695 return windows[detail_selection_index];
696 }
697
698+void SwitcherModel::UnsetDetailSelection()
699+{
700+ detail_selection = false;
701+ detail_selection_index = 0;
702+ row_index_ = 0;
703+}
704+
705+void SwitcherModel::NextIndex()
706+{
707+ last_index_ = index_;
708+ ++index_ %= applications_.size();
709+}
710+
711 void SwitcherModel::Next()
712 {
713+ NextIndex();
714+ UnsetDetailSelection();
715+ selection_changed.emit(Selection());
716+}
717+
718+void SwitcherModel::PrevIndex()
719+{
720 last_index_ = index_;
721-
722- index_++;
723- if (index_ >= applications_.size())
724- index_ = 0;
725-
726- detail_selection = false;
727- detail_selection_index = 0;
728- row_index_ = 0;
729- selection_changed.emit(Selection());
730+ index_ = ((index_ > 0 && index_ < applications_.size()) ? index_ : applications_.size()) - 1;
731 }
732
733 void SwitcherModel::Prev()
734 {
735- last_index_ = index_;
736-
737- if (index_ > 0)
738- index_--;
739- else
740- index_ = applications_.size() - 1;
741-
742- detail_selection = false;
743- detail_selection_index = 0;
744- row_index_ = 0;
745+ PrevIndex();
746+ UnsetDetailSelection();
747 selection_changed.emit(Selection());
748 }
749
750@@ -217,11 +403,7 @@
751 if (!detail_selection())
752 return;
753
754- if (detail_selection_index < DetailXids().size() - 1)
755- detail_selection_index = detail_selection_index + 1;
756- else
757- detail_selection_index = 0;
758-
759+ detail_selection_index = (detail_selection_index + 1) % DetailXids().size();
760 UpdateRowIndex();
761 }
762
763@@ -230,11 +412,7 @@
764 if (!detail_selection())
765 return;
766
767- if (detail_selection_index >= (unsigned int) 1)
768- detail_selection_index = detail_selection_index - 1;
769- else
770- detail_selection_index = DetailXids().size() - 1;
771-
772+ detail_selection_index = ((detail_selection_index() > 0) ? detail_selection_index : DetailXids().size()) - 1;
773 UpdateRowIndex();
774 }
775
776@@ -253,7 +431,7 @@
777 return;
778 }
779
780- current_row++;
781+ ++current_row;
782 }
783 }
784
785@@ -289,11 +467,11 @@
786 increment = next_row;
787
788 detail_selection_index = detail_selection_index + increment;
789- row_index_++;
790+ ++row_index_;
791 }
792 else
793 {
794- detail_selection_index = detail_selection_index + 1;
795+ detail_selection_index = (detail_selection_index + 1) % DetailXids().size();
796 }
797 }
798
799@@ -313,18 +491,18 @@
800 }
801 else
802 {
803- detail_selection_index = detail_selection_index - 1;
804+ detail_selection_index = ((detail_selection_index() > 0) ? detail_selection_index : DetailXids().size()) - 1;
805 }
806 }
807
808 bool SwitcherModel::HasNextDetailRow() const
809 {
810- return (detail_selection_index < DetailXids().size() - 1);
811+ return (detail_selection_index() < DetailXids().size() - 1);
812 }
813
814 bool SwitcherModel::HasPrevDetailRow() const
815 {
816- return (detail_selection_index > (unsigned int) 0);
817+ return (detail_selection_index() > 0);
818 }
819
820 void SwitcherModel::SetRowSizes(std::vector<int> const& row_sizes)
821@@ -334,18 +512,17 @@
822
823 void SwitcherModel::Select(AbstractLauncherIcon::Ptr const& selection)
824 {
825- int i = 0;
826+ unsigned i = 0;
827 for (iterator it = begin(), e = end(); it != e; ++it)
828 {
829 if (*it == selection)
830 {
831- if ((int) index_ != i)
832+ if (index_ != i)
833 {
834 last_index_ = index_;
835 index_ = i;
836
837- detail_selection = false;
838- detail_selection_index = 0;
839+ UnsetDetailSelection();
840 selection_changed.emit(Selection());
841 }
842 break;
843@@ -363,8 +540,7 @@
844 last_index_ = index_;
845 index_ = target;
846
847- detail_selection = false;
848- detail_selection_index = 0;
849+ UnsetDetailSelection();
850 selection_changed.emit(Selection());
851 }
852 }
853
854=== modified file 'launcher/SwitcherModel.h'
855--- launcher/SwitcherModel.h 2015-04-03 15:19:31 +0000
856+++ launcher/SwitcherModel.h 2015-12-04 17:15:35 +0000
857@@ -59,10 +59,10 @@
858
859 nux::Property<bool> detail_selection;
860 nux::Property<unsigned int> detail_selection_index;
861- nux::Property<bool> only_detail_on_viewport;
862+ nux::Property<bool> only_apps_on_viewport;
863
864- SwitcherModel(std::vector<launcher::AbstractLauncherIcon::Ptr> const& icons);
865- virtual ~SwitcherModel();
866+ SwitcherModel(std::vector<launcher::AbstractLauncherIcon::Ptr> const& icons, bool sort_by_priority);
867+ virtual ~SwitcherModel() = default;
868
869 iterator begin();
870 iterator end();
871@@ -72,7 +72,10 @@
872
873 launcher::AbstractLauncherIcon::Ptr at(unsigned int index) const;
874
875- int Size() const;
876+ void AddIcon(launcher::AbstractLauncherIcon::Ptr const&);
877+ void RemoveIcon(launcher::AbstractLauncherIcon::Ptr const&);
878+
879+ size_t Size() const;
880
881 launcher::AbstractLauncherIcon::Ptr Selection() const;
882 int SelectionIndex() const;
883@@ -101,19 +104,31 @@
884 void Select(unsigned int index);
885
886 sigc::signal<void, launcher::AbstractLauncherIcon::Ptr const&> selection_changed;
887- sigc::signal<void> request_detail_hide;
888+ sigc::signal<void> updated;
889
890 protected:
891 // Introspectable methods
892- std::string GetName() const;
893- void AddProperties(debug::IntrospectionData&);
894+ std::string GetName() const override;
895+ void AddProperties(debug::IntrospectionData&) override;
896+ debug::Introspectable::IntrospectableList GetIntrospectableChildren() override;
897
898 private:
899 void UpdateRowIndex();
900 unsigned int SumNRows(unsigned int n) const;
901 bool DetailIndexInLeftHalfOfRow() const;
902+ void InsertIcon(launcher::AbstractLauncherIcon::Ptr const&);
903+ void ConnectToIconSignals(launcher::AbstractLauncherIcon::Ptr const&);
904+ void VerifyApplications();
905+ void UpdateLastActiveApplication();
906+ void OnIconQuirksChanged();
907+ void UnsetDetailSelection();
908+
909+ void NextIndex();
910+ void PrevIndex();
911
912 Applications applications_;
913+ Applications hidden_applications_;
914+ bool sort_by_priority_;
915 unsigned int index_;
916 unsigned int last_index_;
917 unsigned int row_index_;
918
919=== modified file 'launcher/SwitcherView.cpp'
920--- launcher/SwitcherView.cpp 2015-02-13 17:19:08 +0000
921+++ launcher/SwitcherView.cpp 2015-12-04 17:15:35 +0000
922@@ -165,6 +165,7 @@
923 model->selection_changed.connect(sigc::mem_fun(this, &SwitcherView::OnSelectionChanged));
924 model->detail_selection.changed.connect (sigc::mem_fun (this, &SwitcherView::OnDetailSelectionChanged));
925 model->detail_selection_index.changed.connect (sigc::mem_fun (this, &SwitcherView::OnDetailSelectionIndexChanged));
926+ model->updated.connect(sigc::mem_fun(this, &SwitcherView::QueueRelayout));
927
928 last_icon_selected_ = -1;
929
930@@ -648,7 +649,7 @@
931 nux::Geometry const& base = GetGeometry();
932 nux::Size result(base.width - border_size * 2, base.height - border_size * 2);
933
934- int width_padding = std::max(model_->Size() - 1, 0) * minimum_spacing + tile_size;
935+ int width_padding = std::max<int>(model_->Size() - 1, 0) * minimum_spacing + tile_size;
936 result.width -= width_padding;
937
938 return result;
939
940=== modified file 'plugins/unityshell/src/unity-launcher-icon-accessible.cpp'
941--- plugins/unityshell/src/unity-launcher-icon-accessible.cpp 2014-03-11 22:09:15 +0000
942+++ plugins/unityshell/src/unity-launcher-icon-accessible.cpp 2015-12-04 17:15:35 +0000
943@@ -253,8 +253,8 @@
944 g_signal_connect(accessible, "notify::accessible-parent",
945 G_CALLBACK(on_parent_change_cb), self);
946
947- icon->QuirksChanged.connect(sigc::bind(sigc::ptr_fun(on_quirks_change_cb), self));
948- icon->WindowsChanged.connect(sigc::bind(sigc::ptr_fun(on_quirks_change_cb), self));
949+ icon->quirks_changed.connect(sigc::hide(sigc::hide(sigc::bind(sigc::ptr_fun(on_quirks_change_cb), self))));
950+ icon->windows_changed.connect(sigc::hide(sigc::bind(sigc::ptr_fun(on_quirks_change_cb), self)));
951 }
952
953
954
955=== modified file 'plugins/unityshell/src/unityshell.cpp'
956--- plugins/unityshell/src/unityshell.cpp 2015-10-27 17:35:23 +0000
957+++ plugins/unityshell/src/unityshell.cpp 2015-12-04 17:15:35 +0000
958@@ -318,12 +318,12 @@
959 #ifndef USE_GLES
960 wt.reset(nux::CreateFromForeignWindow(cScreen->output(),
961 glXGetCurrentContext(),
962- &UnityScreen::initUnity,
963+ &UnityScreen::InitNuxThread,
964 this));
965 #else
966 wt.reset(nux::CreateFromForeignWindow(cScreen->output(),
967 eglGetCurrentContext(),
968- &UnityScreen::initUnity,
969+ &UnityScreen::InitNuxThread,
970 this));
971 #endif
972
973@@ -431,7 +431,7 @@
974 ubus_manager_.RegisterInterest(UBUS_LAUNCHER_END_KEY_SWITCHER,
975 sigc::mem_fun(this, &UnityScreen::OnLauncherEndKeyNav));
976
977- auto init_plugins_cb = sigc::mem_fun(this, &UnityScreen::initPluginActions);
978+ auto init_plugins_cb = sigc::mem_fun(this, &UnityScreen::InitPluginActions);
979 sources_.Add(std::make_shared<glib::Idle>(init_plugins_cb, glib::Source::Priority::DEFAULT));
980
981 InitGesturesSupport();
982@@ -509,7 +509,7 @@
983 reset_glib_logging();
984 }
985
986-void UnityScreen::initAltTabNextWindow()
987+void UnityScreen::InitAltTabNextWindow()
988 {
989 Display* display = screen->dpy();
990 KeySym tab_keysym = XStringToKeysym("Tab");
991@@ -2766,7 +2766,7 @@
992 WM.activate_indicators_key = std::make_pair(modifiers, keysym);
993 }
994
995-bool UnityScreen::initPluginActions()
996+bool UnityScreen::InitPluginActions()
997 {
998 PluginAdapter& adapter = PluginAdapter::Default();
999
1000@@ -2872,12 +2872,12 @@
1001 if (p->vTable->name() == "expo" ||
1002 p->vTable->name() == "scale")
1003 {
1004- initPluginActions();
1005+ InitPluginActions();
1006 }
1007
1008 bool result = screen->initPluginForScreen(p);
1009 if (p->vTable->name() == "unityshell")
1010- initAltTabNextWindow();
1011+ InitAltTabNextWindow();
1012
1013 return result;
1014 }
1015@@ -3512,17 +3512,14 @@
1016
1017
1018 /* Start up nux after OpenGL is initialized */
1019-void UnityScreen::initUnity(nux::NThread* thread, void* InitData)
1020+void UnityScreen::InitNuxThread(nux::NThread* thread, void* data)
1021 {
1022 Timer timer;
1023- UnityScreen* self = reinterpret_cast<UnityScreen*>(InitData);
1024- self->initLauncher();
1025+ static_cast<UnityScreen*>(data)->InitUnityComponents();
1026
1027 nux::ColorLayer background(nux::color::Transparent);
1028 static_cast<nux::WindowThread*>(thread)->SetWindowBackgroundPaintLayer(&background);
1029- LOG_INFO(logger) << "UnityScreen::initUnity: " << timer.ElapsedSeconds() << "s";
1030-
1031- nux::GetWindowCompositor().sigHiddenViewWindow.connect(sigc::mem_fun(self, &UnityScreen::OnViewHidden));
1032+ LOG_INFO(logger) << "UnityScreen::InitNuxThread: " << timer.ElapsedSeconds() << "s";
1033 }
1034
1035 void UnityScreen::onRedrawRequested()
1036@@ -3987,12 +3984,14 @@
1037 }
1038 }
1039
1040-/* Start up the launcher */
1041-void UnityScreen::initLauncher()
1042+/* Start up the unity components */
1043+void UnityScreen::InitUnityComponents()
1044 {
1045 Timer timer;
1046+ nux::GetWindowCompositor().sigHiddenViewWindow.connect(sigc::mem_fun(this, &UnityScreen::OnViewHidden));
1047
1048 bghash_.reset(new BGHash());
1049+ LOG_INFO(logger) << "InitUnityComponents-BGHash " << timer.ElapsedSeconds() << "s";
1050
1051 auto xdnd_collection_window = std::make_shared<XdndCollectionWindowImp>();
1052 auto xdnd_start_stop_notifier = std::make_shared<XdndStartStopNotifierImp>();
1053@@ -4001,18 +4000,20 @@
1054
1055 launcher_controller_ = std::make_shared<launcher::Controller>(xdnd_manager, edge_barriers_);
1056 Introspectable::AddChild(launcher_controller_.get());
1057+ LOG_INFO(logger) << "InitUnityComponents-Launcher " << timer.ElapsedSeconds() << "s";
1058
1059 switcher_controller_ = std::make_shared<switcher::Controller>();
1060 switcher_controller_->detail.changed.connect(sigc::mem_fun(this, &UnityScreen::OnSwitcherDetailChanged));
1061 Introspectable::AddChild(switcher_controller_.get());
1062-
1063- LOG_INFO(logger) << "initLauncher-Launcher " << timer.ElapsedSeconds() << "s";
1064+ launcher_controller_->icon_added.connect(sigc::mem_fun(switcher_controller_.get(), &switcher::Controller::AddIcon));
1065+ launcher_controller_->icon_removed.connect(sigc::mem_fun(switcher_controller_.get(), &switcher::Controller::RemoveIcon));
1066+ LOG_INFO(logger) << "InitUnityComponents-Switcher " << timer.ElapsedSeconds() << "s";
1067
1068 /* Setup panel */
1069 timer.Reset();
1070 panel_controller_ = std::make_shared<panel::Controller>(menus_, edge_barriers_);
1071 Introspectable::AddChild(panel_controller_.get());
1072- LOG_INFO(logger) << "initLauncher-Panel " << timer.ElapsedSeconds() << "s";
1073+ LOG_INFO(logger) << "InitUnityComponents-Panel " << timer.ElapsedSeconds() << "s";
1074
1075 /* Setup Places */
1076 dash_controller_ = std::make_shared<dash::Controller>();
1077@@ -4027,13 +4028,14 @@
1078 hud_controller_->icon_size = launcher_controller_->options()->icon_size();
1079 hud_controller_->tile_size = launcher_controller_->options()->tile_size();
1080 Introspectable::AddChild(hud_controller_.get());
1081- LOG_INFO(logger) << "initLauncher-hud " << timer.ElapsedSeconds() << "s";
1082+ LOG_INFO(logger) << "InitUnityComponents-Hud " << timer.ElapsedSeconds() << "s";
1083
1084 // Setup Shortcut Hint
1085 auto base_window_raiser = std::make_shared<shortcut::BaseWindowRaiserImp>();
1086 auto shortcuts_modeller = std::make_shared<shortcut::CompizModeller>();
1087 shortcut_controller_ = std::make_shared<shortcut::Controller>(base_window_raiser, shortcuts_modeller);
1088 Introspectable::AddChild(shortcut_controller_.get());
1089+ LOG_INFO(logger) << "InitUnityComponents-ShortcutHints " << timer.ElapsedSeconds() << "s";
1090 ShowFirstRunHints();
1091
1092 // Setup Session Controller
1093@@ -4044,12 +4046,14 @@
1094 manager->unlocked.connect(sigc::mem_fun(this, &UnityScreen::OnScreenUnlocked));
1095 session_dbus_manager_ = std::make_shared<session::DBusManager>(manager);
1096 session_controller_ = std::make_shared<session::Controller>(manager);
1097+ LOG_INFO(logger) << "InitUnityComponents-Session " << timer.ElapsedSeconds() << "s";
1098 Introspectable::AddChild(session_controller_.get());
1099
1100 // Setup Lockscreen Controller
1101 screensaver_dbus_manager_ = std::make_shared<lockscreen::DBusManager>(manager);
1102 lockscreen_controller_ = std::make_shared<lockscreen::Controller>(screensaver_dbus_manager_, manager);
1103 UpdateActivateIndicatorsKey();
1104+ LOG_INFO(logger) << "InitUnityComponents-Lockscreen " << timer.ElapsedSeconds() << "s";
1105
1106 if (g_file_test((DesktopUtilities::GetUserRuntimeDirectory()+local::LOCKED_STAMP).c_str(), G_FILE_TEST_EXISTS))
1107 manager->PromptLockScreen();
1108
1109=== modified file 'plugins/unityshell/src/unityshell.h'
1110--- plugins/unityshell/src/unityshell.h 2015-10-27 17:33:31 +0000
1111+++ plugins/unityshell/src/unityshell.h 2015-12-04 17:15:35 +0000
1112@@ -259,7 +259,10 @@
1113 SHORTCUT_HINT
1114 };
1115
1116- void initAltTabNextWindow ();
1117+ static void InitNuxThread(nux::NThread* thread, void* data);
1118+ void InitUnityComponents();
1119+ bool InitPluginActions();
1120+ void InitAltTabNextWindow();
1121
1122 void SendExecuteCommand();
1123
1124@@ -267,16 +270,12 @@
1125 void CreateSuperNewAction(char shortcut, impl::ActionModifiers flag);
1126 void EnableCancelAction(CancelActionTarget target, bool enabled, int modifiers = 0);
1127
1128- bool initPluginActions();
1129- void initLauncher();
1130-
1131 void compizDamageNux(CompRegion const& region);
1132 void determineNuxDamage(CompRegion &nux_damage);
1133
1134 void onRedrawRequested();
1135 void Relayout();
1136
1137- static void initUnity(nux::NThread* thread, void* InitData);
1138 static void OnStartKeyNav(GVariant* data, void* value);
1139 static void OnExitKeyNav(GVariant* data, void* value);
1140
1141
1142=== modified file 'tests/autopilot/unity/emulators/switcher.py'
1143--- tests/autopilot/unity/emulators/switcher.py 2014-08-05 15:45:44 +0000
1144+++ tests/autopilot/unity/emulators/switcher.py 2015-12-04 17:15:35 +0000
1145@@ -93,11 +93,11 @@
1146 """Returns the SwitcherMode that the switcher is currently in."""
1147 if not self.visible:
1148 return None
1149- if self.model.detail_selection and not self.model.only_detail_on_viewport:
1150+ if self.model.detail_selection and not self.model.only_apps_on_viewport:
1151 return SwitcherMode.DETAIL, SwitcherMode.ALL
1152 elif self.model.detail_selection:
1153 return SwitcherMode.DETAIL
1154- elif not self.model.only_detail_on_viewport:
1155+ elif not self.model.only_apps_on_viewport:
1156 return SwitcherMode.ALL
1157 else:
1158 return SwitcherMode.NORMAL
1159@@ -115,7 +115,7 @@
1160 elif mode == SwitcherMode.ALL:
1161 logger.debug("Initiating switcher in 'all workspaces' mode. Ctrl+Alt+Tab")
1162 self.keybinding_hold_part_then_tap("switcher/reveal_all")
1163- self.model.only_detail_on_viewport.wait_for(False)
1164+ self.model.only_apps_on_viewport.wait_for(False)
1165
1166 def next_icon(self):
1167 """Move to the next icon."""
1168
1169=== modified file 'tests/test_switcher_controller.cpp'
1170--- tests/test_switcher_controller.cpp 2015-04-03 15:32:24 +0000
1171+++ tests/test_switcher_controller.cpp 2015-12-04 17:15:35 +0000
1172@@ -125,7 +125,7 @@
1173 // 0, 1,
1174 // 2, 3
1175 EXPECT_TRUE(model->HasPrevDetailRow());
1176- EXPECT_EQ(static_cast<unsigned int>(model->detail_selection_index), 2);
1177+ EXPECT_EQ(model->detail_selection_index(), 2);
1178 }
1179
1180 TEST_F(TestSwitcherController, StopDetailModeMovesPrevRows)
1181
1182=== modified file 'tests/test_switcher_controller.h'
1183--- tests/test_switcher_controller.h 2015-02-05 14:35:07 +0000
1184+++ tests/test_switcher_controller.h 2015-12-04 17:15:35 +0000
1185@@ -75,6 +75,7 @@
1186
1187 unity::WindowList Windows() override;
1188 bool AllowDetailViewInSwitcher() const override;
1189+ bool ShowInSwitcher(bool) override;
1190 uint64_t SwitcherPriority() override;
1191
1192 bool allow_detail_view_;
1193
1194=== modified file 'tests/test_switcher_controller_class.cpp'
1195--- tests/test_switcher_controller_class.cpp 2015-02-09 16:47:24 +0000
1196+++ tests/test_switcher_controller_class.cpp 2015-12-04 17:15:35 +0000
1197@@ -64,6 +64,11 @@
1198 return window_list;
1199 }
1200
1201+bool FakeLauncherIcon::ShowInSwitcher(bool)
1202+{
1203+ return true;
1204+}
1205+
1206 bool FakeLauncherIcon::AllowDetailViewInSwitcher() const
1207 {
1208 return allow_detail_view_;
1209
1210=== modified file 'tests/test_switcher_model.cpp'
1211--- tests/test_switcher_model.cpp 2013-06-20 20:59:32 +0000
1212+++ tests/test_switcher_model.cpp 2015-12-04 17:15:35 +0000
1213@@ -43,7 +43,7 @@
1214 public:
1215 MockLauncherIcon2(int id)
1216 : id_(id)
1217- { }
1218+ {}
1219
1220 int id_;
1221 };
1222@@ -61,20 +61,19 @@
1223 TestSwitcherModel()
1224 {
1225 for (int i = 0; i < 4; ++i)
1226- {
1227 icons_.push_back(AbstractLauncherIcon::Ptr(new MockLauncherIcon2(i)));
1228- }
1229+
1230+ model = std::make_shared<SwitcherModel>(icons_, false);
1231 }
1232
1233 protected:
1234 std::vector<AbstractLauncherIcon::Ptr> icons_;
1235+ SwitcherModel::Ptr model;
1236 };
1237
1238
1239 TEST_F(TestSwitcherModel, TestConstructor)
1240 {
1241- SwitcherModel::Ptr model(new SwitcherModel(icons_));
1242-
1243 EXPECT_EQ(model->Size(), icons_.size());
1244 EXPECT_EQ(model->Selection(), icons_.front());
1245 EXPECT_EQ(model->LastSelection(), icons_.front());
1246@@ -86,8 +85,6 @@
1247
1248 TEST_F(TestSwitcherModel, TestSelection)
1249 {
1250- SwitcherModel::Ptr model(new SwitcherModel(icons_));
1251-
1252 EXPECT_EQ(IdentityOf(model->Selection()), 0);
1253
1254 model->Next();
1255@@ -126,12 +123,12 @@
1256 TEST_F(TestSwitcherModel, TestActiveDetailWindowSort)
1257 {
1258 // Create a base case for the null hypothesis.
1259- SwitcherModel::Ptr model_detail(new SwitcherModel(icons_));
1260+ auto model_detail = std::make_shared<SwitcherModel>(icons_, false);
1261 model_detail->detail_selection = true;
1262
1263 // Create a test case with an active detail window.
1264 icons_.front()->SetQuirk(AbstractLauncherIcon::Quirk::ACTIVE, true);
1265- SwitcherModel::Ptr model_detail_active(new SwitcherModel(icons_));
1266+ auto model_detail_active = std::make_shared<SwitcherModel>(icons_, false);
1267 model_detail_active->detail_selection = true;
1268
1269 EXPECT_TRUE(model_detail_active->DetailXids().size() > 2);
1270@@ -150,19 +147,17 @@
1271
1272 TEST_F(TestSwitcherModel, SelectionIsActive)
1273 {
1274- SwitcherModel model(icons_);
1275-
1276- model.Selection()->SetQuirk(AbstractLauncherIcon::Quirk::ACTIVE, false);
1277- EXPECT_FALSE(model.SelectionIsActive());
1278-
1279- model.Selection()->SetQuirk(AbstractLauncherIcon::Quirk::ACTIVE, true);
1280- EXPECT_TRUE(model.SelectionIsActive());
1281+ model->Selection()->SetQuirk(AbstractLauncherIcon::Quirk::ACTIVE, false);
1282+ EXPECT_FALSE(model->SelectionIsActive());
1283+
1284+ model->Selection()->SetQuirk(AbstractLauncherIcon::Quirk::ACTIVE, true);
1285+ EXPECT_TRUE(model->SelectionIsActive());
1286 }
1287
1288 TEST_F(TestSwitcherModel, TestWebAppActive)
1289 {
1290 // Create a base case
1291- SwitcherModel::Ptr base_model(new SwitcherModel(icons_));
1292+ auto base_model = std::make_shared<SwitcherModel>(icons_, false);
1293
1294 // Set the first icon as Active to simulate Firefox being active
1295 icons_.front()->SetQuirk(AbstractLauncherIcon::Quirk::ACTIVE, true);
1296@@ -170,18 +165,16 @@
1297 // Set the last icon as Active to simulate that it is a WebApp
1298 icons_.back()->SetQuirk(AbstractLauncherIcon::Quirk::ACTIVE, true);
1299
1300- SwitcherModel::Ptr model(new SwitcherModel(icons_));
1301-
1302- model->DetailXids();
1303+ auto new_model = std::make_shared<SwitcherModel>(icons_, false);
1304+ new_model->DetailXids();
1305
1306 // model's front Window should be different than the base case due to the
1307 // re-sorting in DetailXids().
1308- EXPECT_NE(model->DetailXids().front(), base_model->DetailXids().front());
1309+ EXPECT_NE(new_model->DetailXids().front(), base_model->DetailXids().front());
1310 }
1311
1312 TEST_F(TestSwitcherModel, TestHasNextDetailRow)
1313 {
1314- SwitcherModel::Ptr model(new SwitcherModel(icons_));
1315 model->detail_selection = true;
1316 model->SetRowSizes({2,2});
1317
1318@@ -190,7 +183,6 @@
1319
1320 TEST_F(TestSwitcherModel, TestHasNextDetailRowStopsAtTheEnd)
1321 {
1322- SwitcherModel::Ptr model(new SwitcherModel(icons_));
1323 model->detail_selection = true;
1324 for (unsigned int i = 0; i < model->DetailXids().size() - 1 &&
1325 model->HasNextDetailRow(); i++)
1326@@ -203,7 +195,6 @@
1327
1328 TEST_F(TestSwitcherModel, TestHasPrevDetailRow)
1329 {
1330- SwitcherModel::Ptr model(new SwitcherModel(icons_));
1331 model->detail_selection = true;
1332 model->SetRowSizes({2,2});
1333
1334@@ -216,7 +207,6 @@
1335
1336 TEST_F(TestSwitcherModel, TestHasNextThenPrevDetailRow)
1337 {
1338- SwitcherModel::Ptr model(new SwitcherModel(icons_));
1339 model->detail_selection = true;
1340 model->SetRowSizes({2,2});
1341
1342@@ -231,7 +221,6 @@
1343
1344 TEST_F(TestSwitcherModel, TestNextDetailRow)
1345 {
1346- SwitcherModel::Ptr model(new SwitcherModel(icons_));
1347 model->detail_selection = true;
1348 model->SetRowSizes({2,2});
1349
1350@@ -245,7 +234,6 @@
1351
1352 TEST_F(TestSwitcherModel, TestNextDetailThenNextDetailRow)
1353 {
1354- SwitcherModel::Ptr model(new SwitcherModel(icons_));
1355 model->detail_selection = true;
1356 model->SetRowSizes({2,2});
1357
1358@@ -260,7 +248,6 @@
1359
1360 TEST_F(TestSwitcherModel, TestPrevDetailRow)
1361 {
1362- SwitcherModel::Ptr model(new SwitcherModel(icons_));
1363 model->detail_selection = true;
1364 model->SetRowSizes({2,2});
1365
1366@@ -275,7 +262,6 @@
1367
1368 TEST_F(TestSwitcherModel, TestNextDetailThenPrevDetailRow)
1369 {
1370- SwitcherModel::Ptr model(new SwitcherModel(icons_));
1371 model->detail_selection = true;
1372 model->SetRowSizes({2,2});
1373
1374@@ -292,7 +278,6 @@
1375
1376 TEST_F(TestSwitcherModel, TestUnEvenNextDetailRow)
1377 {
1378- SwitcherModel::Ptr model(new SwitcherModel(icons_));
1379 model->detail_selection = true;
1380 model->SetRowSizes({3,2});
1381
1382@@ -306,7 +291,6 @@
1383
1384 TEST_F(TestSwitcherModel, TestUnEvenPrevDetailRow)
1385 {
1386- SwitcherModel::Ptr model(new SwitcherModel(icons_));
1387 model->detail_selection = true;
1388 model->SetRowSizes({3,2});
1389
1390@@ -321,7 +305,6 @@
1391
1392 TEST_F(TestSwitcherModel, TestNextPrevDetailRowMovesLeftInTopRow)
1393 {
1394- SwitcherModel::Ptr model(new SwitcherModel(icons_));
1395 model->detail_selection = true;
1396 model->SetRowSizes({3,2});
1397
1398
1399=== modified file 'tests/test_switcher_view.cpp'
1400--- tests/test_switcher_view.cpp 2015-03-13 13:49:16 +0000
1401+++ tests/test_switcher_view.cpp 2015-12-04 17:15:35 +0000
1402@@ -96,7 +96,7 @@
1403
1404 SwitcherModel::Applications apps;
1405 apps.push_back(AbstractLauncherIcon::Ptr(app));
1406- switcher.SetModel(std::make_shared<SwitcherModel>(apps));
1407+ switcher.SetModel(std::make_shared<SwitcherModel>(apps, true));
1408
1409 return apps[0];
1410 }
1411@@ -130,7 +130,7 @@
1412 apps.push_back(AbstractLauncherIcon::Ptr(new MockLauncherIcon()));
1413 apps.push_back(AbstractLauncherIcon::Ptr(new MockLauncherIcon()));
1414 apps.push_back(AbstractLauncherIcon::Ptr(new MockLauncherIcon()));
1415- auto model = std::make_shared<SwitcherModel>(apps);
1416+ auto model = std::make_shared<SwitcherModel>(apps, false);
1417
1418 switcher.SetModel(model);
1419 ASSERT_EQ(switcher.model_, model);