Merge lp:~aacid/unity/launcher_selection_changed_fix_1067358 into lp:unity

Proposed by Albert Astals Cid on 2012-10-16
Status: Merged
Approved by: Marco Trevisan (Treviño) on 2012-10-17
Approved revision: 2848
Merged at revision: 2848
Proposed branch: lp:~aacid/unity/launcher_selection_changed_fix_1067358
Merge into: lp:unity
Diff against target: 209 lines (+69/-9)
9 files modified
launcher/AbstractLauncherIcon.h (+1/-0)
launcher/LauncherController.cpp (+18/-6)
launcher/LauncherControllerPrivate.h (+2/-0)
launcher/LauncherIcon.cpp (+5/-0)
launcher/LauncherIcon.h (+1/-0)
launcher/MockLauncherIcon.h (+4/-0)
launcher/QuicklistView.cpp (+8/-3)
launcher/QuicklistView.h (+1/-0)
tests/test_launcher_controller.cpp (+29/-0)
To merge this branch: bzr merge lp:~aacid/unity/launcher_selection_changed_fix_1067358
Reviewer Review Type Date Requested Status
Marco Trevisan (Treviño) 2012-10-16 Approve on 2012-10-17
PS Jenkins bot continuous-integration Pending
Review via email: mp+129923@code.launchpad.net

Commit Message

Update the UBUS_LAUNCHER_SELECTION_CHANGED on UBUS_QUICKLIST_END_KEY_NAV

Description of the Change

Update the UBUS_LAUNCHER_SELECTION_CHANGED on UBUS_QUICKLIST_END_KEY_NAV

To post a comment you must log in.
Marco Trevisan (Treviño) (3v1n0) wrote :

Hey, to reply to your IRC question, it would be nice to have tests... It should be quite trivial to test this. Just add a test case to test_launcher_controller, where you check that the ubus message has been sent registering for that selection change.

2845. By Albert Astals Cid on 2012-10-17

Add a test for UBUS_LAUNCHER_SELECTION_CHANGED

2846. By Albert Astals Cid on 2012-10-17

Move the function to the impl

2847. By Albert Astals Cid on 2012-10-17

Improve tests a bit

2848. By Albert Astals Cid on 2012-10-17

Don't fake the closing of the quicklist, really close it

Marco Trevisan (Treviño) (3v1n0) wrote :

Nice, thanks!

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 2012-10-11 20:01:44 +0000
3+++ launcher/AbstractLauncherIcon.h 2012-10-17 09:49:23 +0000
4@@ -138,6 +138,7 @@
5 virtual void SetSortPriority(int priority) = 0;
6
7 virtual bool OpenQuicklist(bool select_first_item = false, int monitor = -1) = 0;
8+ virtual void CloseQuicklist() = 0;
9
10 virtual void SetCenter(nux::Point3 const& center, int monitor, nux::Geometry const& parent_geo) = 0;
11
12
13=== modified file 'launcher/LauncherController.cpp'
14--- launcher/LauncherController.cpp 2012-10-15 18:33:59 +0000
15+++ launcher/LauncherController.cpp 2012-10-17 09:49:23 +0000
16@@ -150,6 +150,13 @@
17 parent_->KeyNavGrab();
18
19 model_->SetSelection(reactivate_index);
20+ AbstractLauncherIcon::Ptr const& selected = model_->Selection();
21+
22+ if (selected)
23+ {
24+ ubus.SendMessage(UBUS_LAUNCHER_SELECTION_CHANGED,
25+ g_variant_new_string(selected->tooltip_text().c_str()));
26+ }
27 });
28
29 parent_->AddChild(model_.get());
30@@ -1381,12 +1388,7 @@
31 case NUX_VK_RIGHT:
32 case NUX_KP_RIGHT:
33 case XK_Menu:
34- if (model_->Selection()->OpenQuicklist(true, keyboard_launcher_->monitor()))
35- {
36- reactivate_keynav = true;
37- reactivate_index = model_->SelectionIndex();
38- parent_->KeyNavTerminate(false);
39- }
40+ OpenQuicklist();
41 break;
42
43 // <SPACE> (open a new instance)
44@@ -1411,6 +1413,16 @@
45 }
46 }
47
48+void Controller::Impl::OpenQuicklist()
49+{
50+ if (model_->Selection()->OpenQuicklist(true, keyboard_launcher_->monitor()))
51+ {
52+ reactivate_keynav = true;
53+ reactivate_index = model_->SelectionIndex();
54+ parent_->KeyNavTerminate(false);
55+ }
56+}
57+
58 void Controller::Impl::OnBusAcquired(GDBusConnection* connection, const gchar* name, gpointer user_data)
59 {
60 GDBusNodeInfo* introspection_data = g_dbus_node_info_new_for_xml(DBUS_INTROSPECTION.c_str(), nullptr);
61
62=== modified file 'launcher/LauncherControllerPrivate.h'
63--- launcher/LauncherControllerPrivate.h 2012-10-12 10:39:33 +0000
64+++ launcher/LauncherControllerPrivate.h 2012-10-17 09:49:23 +0000
65@@ -107,6 +107,8 @@
66 const char* character,
67 unsigned short keyCount);
68
69+ void OpenQuicklist();
70+
71 static void OnBusAcquired(GDBusConnection* connection, const gchar* name, gpointer user_data);
72 static void OnDBusMethodCall(GDBusConnection* connection, const gchar* sender, const gchar* object_path,
73 const gchar* interface_name, const gchar* method_name,
74
75=== modified file 'launcher/LauncherIcon.cpp'
76--- launcher/LauncherIcon.cpp 2012-10-15 12:48:26 +0000
77+++ launcher/LauncherIcon.cpp 2012-10-17 09:49:23 +0000
78@@ -635,6 +635,11 @@
79 return true;
80 }
81
82+void LauncherIcon::CloseQuicklist()
83+{
84+ _quicklist->HideAndEndQuicklistNav();
85+}
86+
87 void LauncherIcon::RecvMouseDown(int button, int monitor, unsigned long key_flags)
88 {
89 if (button == 3)
90
91=== modified file 'launcher/LauncherIcon.h'
92--- launcher/LauncherIcon.h 2012-10-11 20:01:44 +0000
93+++ launcher/LauncherIcon.h 2012-10-17 09:49:23 +0000
94@@ -81,6 +81,7 @@
95 void ShowTooltip();
96
97 bool OpenQuicklist(bool select_first_item = false, int monitor = -1);
98+ void CloseQuicklist();
99
100 void SetCenter(nux::Point3 const& center, int parent_monitor, nux::Geometry const& parent_geo);
101
102
103=== modified file 'launcher/MockLauncherIcon.h'
104--- launcher/MockLauncherIcon.h 2012-10-12 14:34:33 +0000
105+++ launcher/MockLauncherIcon.h 2012-10-17 09:49:23 +0000
106@@ -130,6 +130,10 @@
107 return false;
108 }
109
110+ void CloseQuicklist()
111+ {
112+ }
113+
114 void SetCenter(nux::Point3 const& center, int monitor, nux::Geometry const& geo)
115 {
116 center_[monitor] = center;
117
118=== modified file 'launcher/QuicklistView.cpp'
119--- launcher/QuicklistView.cpp 2012-10-11 11:04:13 +0000
120+++ launcher/QuicklistView.cpp 2012-10-17 09:49:23 +0000
121@@ -279,9 +279,7 @@
122 // left (close quicklist, go back to laucher key-nav)
123 case NUX_VK_LEFT:
124 case NUX_KP_LEFT:
125- Hide();
126- // inform Launcher we switch back to Launcher key-nav
127- UBusManager::SendMessage(UBUS_QUICKLIST_END_KEY_NAV);
128+ HideAndEndQuicklistNav();
129 break;
130
131 // esc (close quicklist, exit key-nav)
132@@ -403,6 +401,13 @@
133 }
134 }
135
136+void QuicklistView::HideAndEndQuicklistNav()
137+{
138+ Hide();
139+ // inform Launcher we switch back to Launcher key-nav
140+ UBusManager::SendMessage(UBUS_QUICKLIST_END_KEY_NAV);
141+}
142+
143 void QuicklistView::Draw(nux::GraphicsEngine& gfxContext, bool forceDraw)
144 {
145 CairoBaseWindow::Draw(gfxContext, forceDraw);
146
147=== modified file 'launcher/QuicklistView.h'
148--- launcher/QuicklistView.h 2012-08-15 02:51:33 +0000
149+++ launcher/QuicklistView.h 2012-10-17 09:49:23 +0000
150@@ -60,6 +60,7 @@
151
152 void Show();
153 void Hide();
154+ void HideAndEndQuicklistNav();
155
156 int GetNumItems();
157 QuicklistMenuItem* GetNthItems(int index);
158
159=== modified file 'tests/test_launcher_controller.cpp'
160--- tests/test_launcher_controller.cpp 2012-10-12 16:02:44 +0000
161+++ tests/test_launcher_controller.cpp 2012-10-17 09:49:23 +0000
162@@ -32,6 +32,7 @@
163 #include "SoftwareCenterLauncherIcon.h"
164 #include "PanelStyle.h"
165 #include "UnitySettings.h"
166+#include "UBusMessages.h"
167 #include "test_utils.h"
168 #include "test_uscreen_mock.h"
169 #include "test_mock_devices.h"
170@@ -204,6 +205,14 @@
171 lc.multiple_launchers = true;
172 }
173
174+ void ProcessUBusMessages()
175+ {
176+ bool expired = false;
177+ glib::Idle idle([&] { expired = true; return false; },
178+ glib::Source::Priority::LOW);
179+ Utils::WaitUntil(expired);
180+ }
181+
182 protected:
183 struct MockLauncherController : Controller
184 {
185@@ -1499,4 +1508,24 @@
186 EXPECT_TRUE(lc.Impl()->expo_icon_->IsVisible());
187 }
188
189+TEST_F(TestLauncherController, UpdateSelectionChanged)
190+{
191+ UBusManager manager;
192+ std::string last_selection_change;
193+ manager.RegisterInterest(UBUS_LAUNCHER_SELECTION_CHANGED, [&] (GVariant *data) { last_selection_change = g_variant_get_string(data, 0); });
194+
195+ lc.KeyNavGrab();
196+ ProcessUBusMessages();
197+ ASSERT_EQ(lc.Impl()->model_->Selection()->tooltip_text(), last_selection_change);
198+
199+ lc.KeyNavNext();
200+ ProcessUBusMessages();
201+ ASSERT_EQ(lc.Impl()->model_->Selection()->tooltip_text(), last_selection_change);
202+
203+ lc.Impl()->OpenQuicklist();
204+ lc.Impl()->model_->Selection()->CloseQuicklist();
205+ ProcessUBusMessages();
206+ ASSERT_EQ(lc.Impl()->model_->Selection()->tooltip_text(), last_selection_change);
207+}
208+
209 }