Merge lp:~azzar1/unity/hud-reset-5.0 into lp:unity/5.0

Proposed by Andrea Azzarone
Status: Merged
Approved by: Tim Penhey
Approved revision: no longer in the source branch.
Merged at revision: 2363
Proposed branch: lp:~azzar1/unity/hud-reset-5.0
Merge into: lp:unity/5.0
Diff against target: 607 lines (+255/-49)
11 files modified
plugins/unityshell/src/HudAbstractView.cpp (+33/-0)
plugins/unityshell/src/HudAbstractView.h (+66/-0)
plugins/unityshell/src/HudController.cpp (+12/-8)
plugins/unityshell/src/HudController.h (+13/-8)
plugins/unityshell/src/HudView.cpp (+11/-12)
plugins/unityshell/src/HudView.h (+15/-20)
plugins/unityshell/src/WindowManager.cpp (+10/-0)
plugins/unityshell/src/WindowManager.h (+2/-0)
tests/CMakeLists.txt (+4/-0)
tests/test_hud_controller.cpp (+87/-0)
tests/test_main.cpp (+2/-1)
To merge this branch: bzr merge lp:~azzar1/unity/hud-reset-5.0
Reviewer Review Type Date Requested Status
Tim Penhey (community) Approve
Review via email: mp+110588@code.launchpad.net

Commit message

Description of the change

== Problem ==
Hud flickers when show up. Read the bug description for more info.

== Test ==
Unity test added. I had to add an hud::AbstractView class to do it.

To post a comment you must log in.
Revision history for this message
Tim Penhey (thumper) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'plugins/unityshell/src/HudAbstractView.cpp'
2--- plugins/unityshell/src/HudAbstractView.cpp 1970-01-01 00:00:00 +0000
3+++ plugins/unityshell/src/HudAbstractView.cpp 2012-06-15 18:20:23 +0000
4@@ -0,0 +1,33 @@
5+/*
6+ * Copyright (C) 2012 Canonical Ltd
7+ *
8+ * This program is free software: you can redistribute it and/or modify
9+ * it under the terms of the GNU General Public License version 3 as
10+ * published by the Free Software Foundation.
11+ *
12+ * This program is distributed in the hope that it will be useful,
13+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+ * GNU General Public License for more details.
16+ *
17+ * You should have received a copy of the GNU General Public License
18+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
19+ *
20+ * Authored by: Andrea Azzarone <azzaronea@gmail.com>
21+ */
22+
23+#include "HudAbstractView.h"
24+
25+namespace unity
26+{
27+namespace hud
28+{
29+
30+NUX_IMPLEMENT_OBJECT_TYPE(AbstractView);
31+
32+AbstractView::AbstractView()
33+ : nux::View(NUX_TRACKER_LOCATION)
34+{}
35+
36+} // namespace hud
37+} // namespace unity
38
39=== added file 'plugins/unityshell/src/HudAbstractView.h'
40--- plugins/unityshell/src/HudAbstractView.h 1970-01-01 00:00:00 +0000
41+++ plugins/unityshell/src/HudAbstractView.h 2012-06-15 18:20:23 +0000
42@@ -0,0 +1,66 @@
43+/*
44+ * Copyright (C) 2012 Canonical Ltd
45+ *
46+ * This program is free software: you can redistribute it and/or modify
47+ * it under the terms of the GNU General Public License version 3 as
48+ * published by the Free Software Foundation.
49+ *
50+ * This program is distributed in the hope that it will be useful,
51+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
52+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
53+ * GNU General Public License for more details.
54+ *
55+ * You should have received a copy of the GNU General Public License
56+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
57+ *
58+ * Authored by: Andrea Azzarone <azzaronea@gmail.com>
59+ */
60+
61+#ifndef UNITYSHELL_HUD_ABSTRACT_VIEW_H
62+#define UNITYSHELL_HUD_ABSTRACT_VIEW_H
63+
64+#include <memory>
65+#include <string>
66+
67+#include <Nux/Nux.h>
68+#include <Nux/View.h>
69+#include <UnityCore/Hud.h>
70+
71+#include "Introspectable.h"
72+
73+namespace unity
74+{
75+namespace hud
76+{
77+
78+class AbstractView : public nux::View, public unity::debug::Introspectable
79+{
80+ NUX_DECLARE_OBJECT_TYPE(AbstractView, nux::View);
81+public:
82+ typedef nux::ObjectPtr<AbstractView> Ptr;
83+
84+ AbstractView();
85+
86+ virtual void AboutToShow() = 0;
87+ virtual void AboutToHide() = 0;
88+ virtual void Relayout() = 0;
89+ virtual void ResetToDefault() = 0;
90+ virtual void SearchFinished() = 0;
91+ virtual void SetIcon(std::string const& icon_name, unsigned int tile_size, unsigned int size, unsigned int padding) = 0;
92+ virtual void SetQueries(Hud::Queries queries) = 0;
93+ virtual void SetWindowGeometry(nux::Geometry const& absolute_geo, nux::Geometry const& geo) = 0;
94+ virtual void ShowEmbeddedIcon(bool show) = 0;
95+
96+ virtual nux::View* default_focus() const = 0;
97+
98+ // signals
99+ sigc::signal<void, std::string> search_changed;
100+ sigc::signal<void, std::string> search_activated;
101+ sigc::signal<void, Query::Ptr> query_activated;
102+ sigc::signal<void, Query::Ptr> query_selected;
103+};
104+
105+} // namespace hud
106+} // namespace unity
107+
108+#endif // UNITYSHELL_HUD_ABSTRACT_VIEW_H
109
110=== modified file 'plugins/unityshell/src/HudController.cpp'
111--- plugins/unityshell/src/HudController.cpp 2012-04-24 11:37:05 +0000
112+++ plugins/unityshell/src/HudController.cpp 2012-06-15 18:20:23 +0000
113@@ -16,12 +16,14 @@
114 * Authored by: Gord Allott <gord.allott@canonical.com>
115 */
116
117+#include <config.h>
118+
119 #include "HudController.h"
120
121 #include <NuxCore/Logger.h>
122 #include <Nux/HLayout.h>
123 #include <UnityCore/Variant.h>
124-#include "PluginAdapter.h"
125+#include "WindowManager.h"
126 #include "PanelStyle.h"
127 #include "UBusMessages.h"
128 #include "UScreen.h"
129@@ -38,7 +40,7 @@
130 nux::logging::Logger logger("unity.hud.controller");
131 }
132
133-Controller::Controller()
134+Controller::Controller(std::function<AbstractView*(void)> const& function)
135 : launcher_width(64)
136 , launcher_locked_out(false)
137 , multiple_launchers(true)
138@@ -52,6 +54,7 @@
139 , view_(nullptr)
140 , monitor_index_(0)
141 , type_wait_handle_(0)
142+ , view_function_(function)
143 {
144 LOG_DEBUG(logger) << "hud startup";
145 SetupWindow();
146@@ -76,7 +79,7 @@
147
148 launcher_width.changed.connect([&] (int new_width) { Relayout(); });
149
150- PluginAdapter::Default()->compiz_screen_ungrabbed.connect(sigc::mem_fun(this, &Controller::OnScreenUngrabbed));
151+ WindowManager::Default()->compiz_screen_ungrabbed.connect(sigc::mem_fun(this, &Controller::OnScreenUngrabbed));
152
153 hud_service_.queries_updated.connect(sigc::mem_fun(this, &Controller::OnQueriesFinished));
154 EnsureHud();
155@@ -109,16 +112,16 @@
156 window_->mouse_down_outside_pointer_grab_area.connect(sigc::mem_fun(this, &Controller::OnMouseDownOutsideWindow));
157
158 /* FIXME - first time we load our windows there is a race that causes the input window not to actually get input, this side steps that by causing an input window show and hide before we really need it. */
159- PluginAdapter::Default()->saveInputFocus ();
160+ WindowManager::Default()->saveInputFocus ();
161 window_->EnableInputWindow(true, "Hud", true, false);
162 window_->EnableInputWindow(false, "Hud", true, false);
163- PluginAdapter::Default()->restoreInputFocus ();
164+ WindowManager::Default()->restoreInputFocus ();
165 }
166
167 void Controller::SetupHudView()
168 {
169 LOG_DEBUG(logger) << "SetupHudView called";
170- view_ = new View();
171+ view_ = view_function_();
172
173 layout_ = new nux::VLayout(NUX_TRACKER_LOCATION);
174 layout_->AddView(view_, 1, nux::MINOR_POSITION_TOP);
175@@ -274,7 +277,7 @@
176
177 void Controller::ShowHud()
178 {
179- PluginAdapter* adaptor = PluginAdapter::Default();
180+ WindowManager* adaptor = WindowManager::Default();
181 LOG_DEBUG(logger) << "Showing the hud";
182 EnsureHud();
183
184@@ -397,7 +400,7 @@
185
186 restore = true;
187 if (restore)
188- PluginAdapter::Default ()->restoreInputFocus ();
189+ WindowManager::Default ()->restoreInputFocus ();
190
191 hud_service_.CloseQuery();
192
193@@ -447,6 +450,7 @@
194 if (!self->visible_)
195 {
196 self->window_->ShowWindow(false);
197+ self->view_->ResetToDefault();
198 }
199 else
200 {
201
202=== modified file 'plugins/unityshell/src/HudController.h'
203--- plugins/unityshell/src/HudController.h 2012-04-23 00:24:52 +0000
204+++ plugins/unityshell/src/HudController.h 2012-06-15 18:20:23 +0000
205@@ -16,9 +16,10 @@
206 * Authored by: Neil Jagdish Patel <neil.patel@canonical.com>
207 */
208
209-#ifndef UNITY_HUD_CONTROLLER_H_
210-#define UNITY_HUD_CONTROLLER_H_
211+#ifndef UNITYSHELL_HUD_CONTROLLER_H
212+#define UNITYSHELL_HUD_CONTROLLER_H
213
214+#include <functional>
215 #include <memory>
216
217 #include <gdk/gdk.h>
218@@ -42,7 +43,7 @@
219 public:
220 typedef std::shared_ptr<Controller> Ptr;
221
222- Controller();
223+ Controller(std::function<AbstractView*(void)> const& function = []() { return new View; });
224 ~Controller();
225
226 nux::BaseWindow* window() const;
227@@ -59,6 +60,7 @@
228 bool IsVisible();
229
230 protected:
231+ // Introspectable
232 std::string GetName() const;
233 void AddProperties(GVariantBuilder* builder);
234
235@@ -104,16 +106,19 @@
236 float last_opacity_;
237 gint64 start_time_;
238
239- View* view_;
240+ AbstractView* view_;
241 guint ensure_id_;
242 std::string focused_app_icon_;
243 nux::Layout* layout_;
244 uint monitor_index_;
245 guint type_wait_handle_;
246 std::string last_search_;
247+
248+ std::function<AbstractView*(void)> view_function_;
249 };
250
251-
252-}
253-}
254-#endif
255+} // namespace hud
256+} // namespace unity
257+
258+#endif // UNITYSHELL_HUD_CONTROLLER_H
259+
260
261=== modified file 'plugins/unityshell/src/HudView.cpp'
262--- plugins/unityshell/src/HudView.cpp 2012-06-06 15:37:05 +0000
263+++ plugins/unityshell/src/HudView.cpp 2012-06-15 18:20:23 +0000
264@@ -25,9 +25,8 @@
265 #include <UnityCore/GLibWrapper.h>
266 #include <UnityCore/Variant.h>
267 #include <Nux/HLayout.h>
268+#include <Nux/VLayout.h>
269
270-#include <NuxCore/Logger.h>
271-#include "HudButton.h"
272 #include "UBusMessages.h"
273 #include "DashStyle.h"
274
275@@ -38,7 +37,9 @@
276
277 namespace
278 {
279+
280 nux::logging::Logger logger("unity.hud.view");
281+
282 const int grow_anim_length = 90 * 1000;
283 const int pause_before_grow_length = 32 * 1000;
284
285@@ -50,12 +51,13 @@
286 const int bottom_padding = 10;
287 const int left_padding = 11;
288 const int right_padding = 0;
289+
290 }
291
292 NUX_IMPLEMENT_OBJECT_TYPE(View);
293
294 View::View()
295- : nux::View(NUX_TRACKER_LOCATION)
296+ : AbstractView()
297 , button_views_(NULL)
298 , timeline_id_(0)
299 , start_time_(0)
300@@ -70,11 +72,6 @@
301 QueueDraw();
302 });
303
304- nux::ROPConfig rop;
305- rop.Blend = true;
306- rop.SrcBlend = GL_ONE;
307- rop.DstBlend = GL_ONE_MINUS_SRC_ALPHA;
308-
309 SetupViews();
310 search_bar_->key_down.connect (sigc::mem_fun (this, &View::OnKeyDown));
311
312@@ -171,6 +168,9 @@
313
314 void View::ResetToDefault()
315 {
316+ SetQueries(Hud::Queries());
317+ current_height_ = content_layout_->GetBaseHeight();
318+
319 search_bar_->search_string = "";
320 search_bar_->search_hint = _("Type your command");
321 }
322@@ -277,7 +277,7 @@
323 QueueDraw();
324 }
325
326-void View::SetIcon(std::string icon_name, unsigned int tile_size, unsigned int size, unsigned int padding)
327+void View::SetIcon(std::string const& icon_name, unsigned int tile_size, unsigned int size, unsigned int padding)
328 {
329 if (!icon_)
330 return;
331@@ -401,10 +401,9 @@
332 LOG_DEBUG(logger) << "got search change";
333 search_changed.emit(search_string);
334
335- std::list<HudButton::Ptr>::iterator it;
336- for(it = buttons_.begin(); it != buttons_.end(); ++it)
337+ for (auto button : buttons_)
338 {
339- (*it)->fake_focused = false;
340+ button->fake_focused = false;
341 }
342
343 if (!buttons_.empty())
344
345=== modified file 'plugins/unityshell/src/HudView.h'
346--- plugins/unityshell/src/HudView.h 2012-06-06 15:37:05 +0000
347+++ plugins/unityshell/src/HudView.h 2012-06-15 18:20:23 +0000
348@@ -16,34 +16,32 @@
349 * Authored by: Gordon Allott <gord.allott@canonical.com>
350 */
351
352-#ifndef UNITY_HUD_VIEW_H_
353-#define UNITY_HUD_VIEW_H_
354+#ifndef UNITYSHELL_HUD_VIEW_H
355+#define UNITYSHELL_HUD_VIEW_H
356
357 #include <string>
358
359 #include <Nux/Nux.h>
360-#include <Nux/View.h>
361 #include <Nux/VLayout.h>
362
363-#include <UnityCore/Hud.h>
364-#include "Introspectable.h"
365-
366-#include "UBusWrapper.h"
367+#include "HudAbstractView.h"
368 #include "HudIcon.h"
369 #include "HudButton.h"
370 #include "SearchBar.h"
371 #include "OverlayRenderer.h"
372+#include "UBusWrapper.h"
373
374 namespace unity
375 {
376 namespace hud
377 {
378
379-class View : public nux::View, public unity::debug::Introspectable
380+class View : public AbstractView
381 {
382- NUX_DECLARE_OBJECT_TYPE(HudView, nux::View);
383+ NUX_DECLARE_OBJECT_TYPE(HudView, AbstractView);
384+public:
385 typedef nux::ObjectPtr<View> Ptr;
386-public:
387+
388 View();
389 ~View();
390
391@@ -54,7 +52,7 @@
392 std::list<HudButton::Ptr> const& buttons() const;
393
394 void SetQueries(Hud::Queries queries);
395- void SetIcon(std::string icon_name, unsigned int tile_size, unsigned int size, unsigned int padding);
396+ void SetIcon(std::string const& icon_name, unsigned int tile_size, unsigned int size, unsigned int padding);
397 void ShowEmbeddedIcon(bool show);
398 void SearchFinished();
399
400@@ -62,11 +60,6 @@
401 void AboutToHide();
402
403 void SetWindowGeometry(nux::Geometry const& absolute_geo, nux::Geometry const& geo);
404-
405- sigc::signal<void, std::string> search_changed;
406- sigc::signal<void, std::string> search_activated;
407- sigc::signal<void, Query::Ptr> query_activated;
408- sigc::signal<void, Query::Ptr> query_selected;
409
410 protected:
411 virtual Area* FindKeyFocusArea(unsigned int event_type,
412@@ -76,6 +69,7 @@
413 void SetupViews();
414 void OnSearchChanged(std::string const& search_string);
415 virtual long PostLayoutManagement(long LayoutResult);
416+
417 private:
418 void OnMouseButtonDown(int x, int y, unsigned long button, unsigned long key);
419 void OnKeyDown (unsigned long event_type, unsigned long event_keysym,
420@@ -121,7 +115,8 @@
421 bool activated_signal_sent_;
422 };
423
424-
425-}
426-}
427-#endif
428+} // namespace hud
429+} // namespace unity
430+
431+#endif // UNITYSHELL_HUD_VIEW_H
432+
433
434=== modified file 'plugins/unityshell/src/WindowManager.cpp'
435--- plugins/unityshell/src/WindowManager.cpp 2012-04-26 05:56:55 +0000
436+++ plugins/unityshell/src/WindowManager.cpp 2012-06-15 18:20:23 +0000
437@@ -220,6 +220,16 @@
438 g_debug("%s", G_STRFUNC);
439 }
440
441+ bool saveInputFocus()
442+ {
443+ return false;
444+ }
445+
446+ bool restoreInputFocus()
447+ {
448+ return false;
449+ }
450+
451 void AddProperties(GVariantBuilder* builder)
452 {
453 }
454
455=== modified file 'plugins/unityshell/src/WindowManager.h'
456--- plugins/unityshell/src/WindowManager.h 2012-04-26 05:56:55 +0000
457+++ plugins/unityshell/src/WindowManager.h 2012-06-15 18:20:23 +0000
458@@ -106,6 +106,8 @@
459
460 virtual int WorkspaceCount() = 0;
461
462+ virtual bool saveInputFocus() = 0;
463+ virtual bool restoreInputFocus() = 0;
464
465 // Signals
466 sigc::signal<void, guint32> window_mapped;
467
468=== modified file 'tests/CMakeLists.txt'
469--- tests/CMakeLists.txt 2012-06-06 15:37:05 +0000
470+++ tests/CMakeLists.txt 2012-06-15 18:20:23 +0000
471@@ -197,6 +197,7 @@
472 # Tests that require X
473 add_executable(test-gtest
474 test_hud_button.cpp
475+ test_hud_controller.cpp
476 test_dashview_impl.cpp
477 test_texture_cache.cpp
478 test_main.cpp
479@@ -209,6 +210,7 @@
480 test_switcher_model.cpp
481 ${UNITY_SRC}/AbstractLauncherIcon.cpp
482 ${UNITY_SRC}/AbstractPlacesGroup.cpp
483+ ${UNITY_SRC}/Animator.cpp
484 ${UNITY_SRC}/BackgroundEffectHelper.cpp
485 ${UNITY_SRC}/CairoBaseWindow.cpp
486 ${UNITY_SRC}/DashSettings.cpp
487@@ -224,7 +226,9 @@
488 ${UNITY_SRC}/IconTextureSource.cpp
489 ${UNITY_SRC}/IMTextEntry.cpp
490 ${UNITY_SRC}/Introspectable.cpp
491+ ${UNITY_SRC}/HudAbstractView.cpp
492 ${UNITY_SRC}/HudButton.cpp
493+ ${UNITY_SRC}/HudController.cpp
494 ${UNITY_SRC}/HudIcon.cpp
495 ${UNITY_SRC}/HudIconTextureSource.cpp
496 ${UNITY_SRC}/HudPrivate.cpp
497
498=== added file 'tests/test_hud_controller.cpp'
499--- tests/test_hud_controller.cpp 1970-01-01 00:00:00 +0000
500+++ tests/test_hud_controller.cpp 2012-06-15 18:20:23 +0000
501@@ -0,0 +1,87 @@
502+/*
503+ * Copyright 2012 Canonical Ltd.
504+ *
505+ * This program is free software: you can redistribute it and/or modify it
506+ * under the terms of the GNU Lesser General Public License version 3, as
507+ * published by the Free Software Foundation.
508+ *
509+ * This program is distributed in the hope that it will be useful, but
510+ * WITHOUT ANY WARRANTY; without even the implied warranties of
511+ * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
512+ * PURPOSE. See the applicable version of the GNU Lesser General Public
513+ * License for more details.
514+ *
515+ * You should have received a copy of both the GNU Lesser General Public
516+ * License version 3 along with this program. If not, see
517+ * <http://www.gnu.org/licenses/>
518+ *
519+ * Authored by: Andrea Azzarone <azzaronea@gmail.com>
520+ *
521+ */
522+
523+#include <gmock/gmock.h>
524+using namespace testing;
525+
526+#include "HudController.h"
527+#include "DashStyle.h"
528+#include "PanelStyle.h"
529+#include "DashSettings.h"
530+#include "WindowManager.h"
531+#include "test_utils.h"
532+using namespace unity;
533+
534+namespace
535+{
536+
537+class MockHudView : public hud::AbstractView
538+{
539+public:
540+ typedef nux::ObjectPtr<MockHudView> Ptr;
541+
542+ MOCK_METHOD0(AboutToShow, void());
543+ MOCK_METHOD0(AboutToHide, void());
544+ MOCK_METHOD0(Relayout, void());
545+ MOCK_METHOD0(ResetToDefault, void());
546+ MOCK_METHOD0(SearchFinished, void());
547+ MOCK_METHOD4(SetIcon, void(std::string const&, unsigned int tile_size, unsigned int size, unsigned int padding));
548+ MOCK_METHOD1(SetQueries, void(hud::Hud::Queries queries));
549+ MOCK_METHOD2(SetWindowGeometry, void(nux::Geometry const& absolute_geo, nux::Geometry const& geo));
550+ MOCK_METHOD1(ShowEmbeddedIcon, void(bool show));
551+ MOCK_CONST_METHOD0(default_focus, nux::View*());
552+ MOCK_CONST_METHOD0(GetName, std::string());
553+ MOCK_METHOD1(AddProperties, void(GVariantBuilder*));
554+ MOCK_METHOD2(Draw, void(nux::GraphicsEngine&, bool));
555+
556+};
557+
558+class TestHudController : public Test
559+{
560+public:
561+ virtual void SetUp()
562+ {
563+ WindowManager::SetDefault(WindowManager::Default());
564+ view = new MockHudView;
565+ controller.reset(new hud::Controller([&view]{ return view.GetPointer(); }));
566+ }
567+
568+ dash::Settings unity_settings;
569+ dash::Style dash_style;
570+ panel::Style panel_style;
571+
572+ hud::Controller::Ptr controller;
573+ MockHudView::Ptr view;
574+};
575+
576+TEST_F(TestHudController, TestHideHud)
577+{
578+ controller->ShowHud();
579+
580+ EXPECT_CALL(*view, ResetToDefault())
581+ .Times(1);
582+
583+ controller->HideHud();
584+ // view->ResetToDefault should be called at the end of the fade out effect. So wait for it.
585+ Utils::WaitForTimeout(2);
586+}
587+
588+}
589
590=== modified file 'tests/test_main.cpp'
591--- tests/test_main.cpp 2012-05-23 13:11:59 +0000
592+++ tests/test_main.cpp 2012-06-15 18:20:23 +0000
593@@ -1,12 +1,13 @@
594 #include <gtest/gtest.h>
595 #include <gio/gio.h>
596+#include <gtk/gtk.h>
597 #include <NuxCore/Logger.h>
598 #include <Nux/Nux.h>
599
600 int main(int argc, char** argv)
601 {
602 ::testing::InitGoogleTest(&argc, argv);
603- g_type_init();
604+ gtk_init(&argc, &argv);
605
606 nux::NuxInitialize (0);
607 nux::WindowThread* wnd_thread = nux::CreateNuxWindow("Tests", 300, 200, nux::WINDOWSTYLE_NORMAL, NULL, false, NULL, NULL);

Subscribers

People subscribed via source and target branches

to all changes: