Merge lp:~3v1n0/unity/switcher-no-detail-animation-init into lp:unity

Proposed by Marco Trevisan (Treviño)
Status: Merged
Approved by: Marco Trevisan (Treviño)
Approved revision: no longer in the source branch.
Merged at revision: 3135
Proposed branch: lp:~3v1n0/unity/switcher-no-detail-animation-init
Merge into: lp:unity
Diff against target: 448 lines (+135/-43)
9 files modified
launcher/SwitcherController.cpp (+39/-23)
launcher/SwitcherController.h (+5/-4)
launcher/SwitcherControllerImpl.h (+2/-1)
launcher/SwitcherView.cpp (+37/-7)
launcher/SwitcherView.h (+6/-0)
plugins/unityshell/src/GesturalWindowSwitcher.cpp (+2/-2)
plugins/unityshell/src/unityshell.cpp (+7/-4)
tests/test_switcher_controller.cpp (+18/-0)
tests/test_switcher_view.cpp (+19/-2)
To merge this branch: bzr merge lp:~3v1n0/unity/switcher-no-detail-animation-init
Reviewer Review Type Date Requested Status
Brandon Schaefer (community) Approve
PS Jenkins bot continuous-integration Pending
Review via email: mp+146771@code.launchpad.net

Commit message

SwitcherController: add InitiateDetail function to initialize the detail mode

It disables the animation at the beginning, then it re-enables it once needed.

Description of the change

When initializing the switcher in detail mode it should not show any spread animation.

To do that I've added an animate property to the SwitcherView that toggle the switcher animations, then this option is set to false when the switcher is initialized in detail mode, and re-enabled as soon as the detail-mode is disabled again.

Unit tests added.

To post a comment you must log in.
Revision history for this message
Brandon Schaefer (brandontschaefer) wrote :

LGTM. Works, and tests pass.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'launcher/SwitcherController.cpp'
2--- launcher/SwitcherController.cpp 2013-02-06 00:37:08 +0000
3+++ launcher/SwitcherController.cpp 2013-02-06 18:38:20 +0000
4@@ -65,7 +65,8 @@
5 {
6
7 Controller::Controller(WindowCreator const& create_window)
8- : detail_on_timeout(true)
9+ : detail_mode([this] { return detail_mode_; })
10+ , detail_on_timeout(true)
11 , detail_timeout_length(500)
12 , initial_detail_timeout_length(1500)
13 , visible_(false)
14@@ -131,7 +132,7 @@
15 impl_->Prev();
16 }
17
18-SwitcherView* Controller::GetView()
19+SwitcherView::Ptr Controller::GetView() const
20 {
21 return impl_->GetView();
22 }
23@@ -141,6 +142,11 @@
24 impl_->SetDetail(value, min_windows);
25 }
26
27+void Controller::InitiateDetail()
28+{
29+ impl_->InitiateDetail();
30+}
31+
32 void Controller::NextDetail()
33 {
34 impl_->NextDetail();
35@@ -474,9 +480,9 @@
36 }
37 }
38
39-SwitcherView* Controller::Impl::GetView()
40+SwitcherView::Ptr Controller::Impl::GetView() const
41 {
42- return view_.GetPointer();
43+ return view_;
44 }
45
46 void Controller::Impl::SetDetail(bool value, unsigned int min_windows)
47@@ -492,20 +498,38 @@
48 }
49 }
50
51+void Controller::Impl::InitiateDetail(bool animate)
52+{
53+ if (!model_)
54+ return;
55+
56+ if (!model_->detail_selection)
57+ {
58+ view_->animate = animate;
59+
60+ SetDetail(true);
61+ obj_->detail_mode_ = DetailMode::TAB_NEXT_TILE;
62+
63+ if (!view_->animate())
64+ {
65+ // As soon as the detail selection is changed we re-enable the animations
66+ auto conn = std::make_shared<sigc::connection>();
67+ *conn = model_->detail_selection.changed.connect([this, conn] (bool) {
68+ if (view_)
69+ view_->animate = true;
70+ conn->disconnect();
71+ });
72+ }
73+ }
74+}
75+
76 void Controller::Impl::NextDetail()
77 {
78 if (!model_)
79 return;
80
81- if (!model_->detail_selection)
82- {
83- SetDetail(true);
84- obj_->detail_mode_ = DetailMode::TAB_NEXT_TILE;
85- }
86- else
87- {
88- model_->NextDetail();
89- }
90+ InitiateDetail(true);
91+ model_->NextDetail();
92 }
93
94 void Controller::Impl::PrevDetail()
95@@ -513,16 +537,8 @@
96 if (!model_)
97 return;
98
99- if (!model_->detail_selection)
100- {
101- SetDetail(true);
102- obj_->detail_mode_ = DetailMode::TAB_NEXT_TILE;
103- model_->PrevDetail();
104- }
105- else
106- {
107- model_->PrevDetail();
108- }
109+ InitiateDetail(true);
110+ model_->PrevDetail();
111 }
112
113 LayoutWindow::Vector Controller::Impl::ExternalRenderTargets()
114
115=== modified file 'launcher/SwitcherController.h'
116--- launcher/SwitcherController.h 2013-01-24 17:57:17 +0000
117+++ launcher/SwitcherController.h 2013-02-06 18:38:20 +0000
118@@ -92,6 +92,7 @@
119 void Next();
120 void Prev();
121
122+ void InitiateDetail();
123 void NextDetail();
124 void PrevDetail();
125
126@@ -102,10 +103,9 @@
127
128 void SelectFirstItem();
129
130- void SetWorkspace(nux::Geometry geo,
131- int monitor);
132+ void SetWorkspace(nux::Geometry geo, int monitor);
133
134- SwitcherView* GetView();
135+ nux::ObjectPtr<SwitcherView> GetView() const;
136
137 ui::LayoutWindow::Vector ExternalRenderTargets();
138
139@@ -124,16 +124,17 @@
140 std::string GetName() const;
141 void AddProperties(GVariantBuilder* builder);
142
143+ nux::ROProperty<DetailMode> detail_mode;
144 nux::Property<bool> detail_on_timeout;
145 nux::Property<int> detail_timeout_length;
146 nux::Property<int> initial_detail_timeout_length;
147
148+private:
149 bool visible_;
150 int monitor_;
151 bool show_desktop_disabled_;
152 DetailMode detail_mode_;
153
154-private:
155 ImplPtr impl_;
156 };
157
158
159=== modified file 'launcher/SwitcherControllerImpl.h'
160--- launcher/SwitcherControllerImpl.h 2013-02-01 02:51:23 +0000
161+++ launcher/SwitcherControllerImpl.h 2013-02-06 18:38:20 +0000
162@@ -52,6 +52,7 @@
163 void Next();
164 void Prev();
165
166+ void InitiateDetail(bool animate=false);
167 void NextDetail();
168 void PrevDetail();
169
170@@ -59,7 +60,7 @@
171
172 void SelectFirstItem();
173
174- virtual SwitcherView* GetView();
175+ virtual SwitcherView::Ptr GetView() const;
176
177 ui::LayoutWindow::Vector ExternalRenderTargets();
178
179
180=== modified file 'launcher/SwitcherView.cpp'
181--- launcher/SwitcherView.cpp 2013-01-19 02:52:02 +0000
182+++ launcher/SwitcherView.cpp 2013-02-06 18:38:20 +0000
183@@ -41,6 +41,7 @@
184
185 SwitcherView::SwitcherView()
186 : render_boxes(false)
187+ , animate(true)
188 , border_size(50)
189 , flat_spacing(20)
190 , icon_size(128)
191@@ -57,8 +58,6 @@
192 , target_sizes_set_(false)
193 {
194 icon_renderer_->pip_style = OVER_TILE;
195- save_time_.tv_sec = 0;
196- save_time_.tv_nsec = 0;
197
198 text_view_->SetMaximumWidth(tile_size * spread_size);
199 text_view_->SetLines(1);
200@@ -69,6 +68,19 @@
201 tile_size.changed.connect (sigc::mem_fun (this, &SwitcherView::OnTileSizeChanged));
202
203 CaptureMouseDownAnyWhereElse(true);
204+ ResetTimer();
205+
206+ animate.changed.connect([this] (bool enabled) {
207+ if (enabled)
208+ {
209+ SaveTime();
210+ QueueDraw();
211+ }
212+ else
213+ {
214+ ResetTimer();
215+ }
216+ });
217 }
218
219 std::string SwitcherView::GetName() const
220@@ -125,11 +137,24 @@
221 vertical_size = tile_size + VERTICAL_PADDING * 2;
222 }
223
224-void SwitcherView::SaveLast ()
225+void SwitcherView::SaveTime()
226+{
227+ clock_gettime(CLOCK_MONOTONIC, &save_time_);
228+}
229+
230+void SwitcherView::ResetTimer()
231+{
232+ save_time_.tv_sec = 0;
233+ save_time_.tv_nsec = 0;
234+}
235+
236+void SwitcherView::SaveLast()
237 {
238 saved_args_ = last_args_;
239 saved_background_ = last_background_;
240- clock_gettime(CLOCK_MONOTONIC, &save_time_);
241+
242+ if (animate())
243+ SaveTime();
244 }
245
246 void SwitcherView::OnDetailSelectionIndexChanged(unsigned int index)
247@@ -511,11 +536,16 @@
248 return results;
249 }
250
251+double SwitcherView::GetCurrentProgress()
252+{
253+ clock_gettime(CLOCK_MONOTONIC, &current_);
254+ DeltaTime ms_since_change = TimeUtil::TimeDelta(&current_, &save_time_);
255+ return std::min<double>(1.0f, ms_since_change / static_cast<double>(animation_length()));
256+}
257+
258 void SwitcherView::PreDraw(nux::GraphicsEngine& GfxContext, bool force_draw)
259 {
260- clock_gettime(CLOCK_MONOTONIC, &current_);
261- DeltaTime ms_since_change = TimeUtil::TimeDelta(&current_, &save_time_);
262- float progress = std::min<float>(1.0f, ms_since_change / static_cast<float>(animation_length()));
263+ double progress = GetCurrentProgress();
264
265 if (!target_sizes_set_)
266 {
267
268=== modified file 'launcher/SwitcherView.h'
269--- launcher/SwitcherView.h 2013-01-17 12:56:02 +0000
270+++ launcher/SwitcherView.h 2013-02-06 18:38:20 +0000
271@@ -56,6 +56,7 @@
272 SwitcherModel::Ptr GetModel();
273
274 nux::Property<bool> render_boxes;
275+ nux::Property<bool> animate;
276 nux::Property<int> border_size;
277 nux::Property<int> flat_spacing;
278 nux::Property<int> icon_size;
279@@ -71,6 +72,7 @@
280 // If there's no icon there, -1 is returned.
281 int IconIndexAt(int x, int y);
282
283+
284 protected:
285 // Introspectable methods
286 std::string GetName() const;
287@@ -100,9 +102,13 @@
288
289 nux::Size SpreadSize();
290
291+ double GetCurrentProgress();
292 void GetFlatIconPositions(int n_flat_icons, int size, int selection,
293 int &first_flat, int &last_flat,
294 int &half_fold_left, int &half_fold_right);
295+
296+ void SaveTime();
297+ void ResetTimer();
298 void SaveLast();
299
300 SwitcherModel::Ptr model_;
301
302=== modified file 'plugins/unityshell/src/GesturalWindowSwitcher.cpp'
303--- plugins/unityshell/src/GesturalWindowSwitcher.cpp 2013-01-24 16:32:35 +0000
304+++ plugins/unityshell/src/GesturalWindowSwitcher.cpp 2013-02-06 18:38:20 +0000
305@@ -338,7 +338,7 @@
306
307 state = State::RecognizingMouseClickOrDrag;
308
309- unity::switcher::SwitcherView *view = switcher_controller->GetView();
310+ auto view = switcher_controller->GetView();
311
312 index_icon_hit = view->IconIndexAt(x, y);
313 accumulated_horizontal_drag = 0.0f;
314@@ -416,7 +416,7 @@
315
316 void GesturalWindowSwitcherPrivate::ConnectToSwitcherViewMouseEvents()
317 {
318- unity::switcher::SwitcherView *switcher_view = switcher_controller->GetView();
319+ auto switcher_view = switcher_controller->GetView();
320 g_assert(switcher_view);
321
322 mouse_down_connection = switcher_view->mouse_down.connect(
323
324=== modified file 'plugins/unityshell/src/unityshell.cpp'
325--- plugins/unityshell/src/unityshell.cpp 2013-02-01 02:54:04 +0000
326+++ plugins/unityshell/src/unityshell.cpp 2013-02-06 18:38:20 +0000
327@@ -1438,7 +1438,7 @@
328
329 if (switcher_controller_ && switcher_controller_->Visible())
330 {
331- unity::switcher::SwitcherView* view = switcher_controller_->GetView();
332+ auto const& view = switcher_controller_->GetView();
333
334 if (G_LIKELY(view))
335 {
336@@ -2056,9 +2056,12 @@
337 {
338 altTabInitiateCommon(action, switcher::ShowMode::CURRENT_VIEWPORT);
339 switcher_controller_->Select((switcher_controller_->StartIndex())); // always select the current application
340- }
341-
342- switcher_controller_->NextDetail();
343+ switcher_controller_->InitiateDetail();
344+ }
345+ else
346+ {
347+ switcher_controller_->NextDetail();
348+ }
349
350 action->setState(action->state() | CompAction::StateTermKey);
351 return true;
352
353=== modified file 'tests/test_switcher_controller.cpp'
354--- tests/test_switcher_controller.cpp 2013-02-06 00:37:37 +0000
355+++ tests/test_switcher_controller.cpp 2013-02-06 18:38:20 +0000
356@@ -25,6 +25,7 @@
357 #include "DesktopLauncherIcon.h"
358 #include "SimpleLauncherIcon.h"
359 #include "SwitcherController.h"
360+#include "SwitcherView.h"
361 #include "TimeUtil.h"
362 #include "unity-shared/UnitySettings.h"
363
364@@ -235,6 +236,23 @@
365 EXPECT_EQ(controller_->GetCurrentSelection().window_, 0);
366 }
367
368+TEST_F(TestSwitcherController, InitiateDetail)
369+{
370+ controller_->Show(ShowMode::ALL, SortMode::LAUNCHER_ORDER, icons_);
371+ controller_->InitiateDetail();
372+
373+ auto const& view = controller_->GetView();
374+ auto const& model = view->GetModel();
375+ EXPECT_EQ(controller_->detail_mode(), DetailMode::TAB_NEXT_TILE);
376+ EXPECT_FALSE(view->animate());
377+ EXPECT_TRUE(model->detail_selection());
378+
379+ auto prev_size = model->detail_selection.changed.size();
380+ model->detail_selection = false;
381+ EXPECT_TRUE(view->animate());
382+ EXPECT_LT(model->detail_selection.changed.size(), prev_size);
383+}
384+
385 TEST_F(TestSwitcherController, ShowSwitcher)
386 {
387 EXPECT_FALSE(controller_->Visible());
388
389=== modified file 'tests/test_switcher_view.cpp'
390--- tests/test_switcher_view.cpp 2013-02-05 04:59:37 +0000
391+++ tests/test_switcher_view.cpp 2013-02-06 18:38:20 +0000
392@@ -18,7 +18,7 @@
393 *
394 */
395
396-#include <gtest/gtest.h>
397+#include <gmock/gmock.h>
398
399 #include "SwitcherModel.h"
400 #include "SwitcherView.h"
401@@ -53,8 +53,11 @@
402
403 struct MockSwitcherView : SwitcherView
404 {
405+ MOCK_METHOD0(QueueDraw, void());
406+
407 using SwitcherView::UpdateRenderTargets;
408 using SwitcherView::ResizeRenderTargets;
409+ using SwitcherView::GetCurrentProgress;
410 using SwitcherView::SpreadSize;
411 using SwitcherView::text_view_;
412 using SwitcherView::icon_renderer_;
413@@ -93,13 +96,14 @@
414
415 StandaloneWindowManager* WM;
416 unity::Settings settings;
417- MockSwitcherView switcher;
418+ testing::NiceMock<MockSwitcherView> switcher;
419 };
420
421 TEST_F(TestSwitcherView, Initiate)
422 {
423 const int VERTICAL_PADDING = 45;
424 EXPECT_FALSE(switcher.render_boxes);
425+ EXPECT_TRUE(switcher.animate);
426 EXPECT_EQ(switcher.border_size, 50);
427 EXPECT_EQ(switcher.flat_spacing, 20);
428 EXPECT_EQ(switcher.icon_size, 128);
429@@ -131,6 +135,19 @@
430 EXPECT_FALSE(switcher.model_->detail_selection_index.changed.empty());
431 }
432
433+TEST_F(TestSwitcherView, Animate)
434+{
435+ switcher.animate = false;
436+ EXPECT_EQ(switcher.GetCurrentProgress(), 1.0f);
437+
438+ EXPECT_CALL(switcher, QueueDraw());
439+ switcher.animate = true;
440+ EXPECT_EQ(switcher.GetCurrentProgress(), 0.0f);
441+
442+ switcher.animate = false;
443+ EXPECT_EQ(switcher.GetCurrentProgress(), 1.0f);
444+}
445+
446
447 struct AnimationProgress : TestSwitcherView, testing::WithParamInterface<double> {};
448 INSTANTIATE_TEST_CASE_P(TestSwitcherView, AnimationProgress, testing::Range(0.0, 1.0, 0.1));