Merge lp:~azzar1/unity/fix-838854 into lp:unity

Proposed by Andrea Azzarone
Status: Merged
Approved by: Andrea Azzarone
Approved revision: no longer in the source branch.
Merged at revision: 2952
Proposed branch: lp:~azzar1/unity/fix-838854
Merge into: lp:unity
Diff against target: 386 lines (+178/-17)
11 files modified
launcher/ExpoLauncherIcon.cpp (+43/-5)
launcher/ExpoLauncherIcon.h (+7/-0)
launcher/LauncherController.cpp (+1/-0)
launcher/LauncherIcon.cpp (+1/-1)
plugins/unityshell/src/unityshell.cpp (+4/-1)
tests/test_expo_launcher_icon.cpp (+71/-10)
unity-shared/PluginAdapter.cpp (+16/-0)
unity-shared/PluginAdapter.h (+4/-0)
unity-shared/StandaloneWindowManager.cpp (+19/-0)
unity-shared/StandaloneWindowManager.h (+7/-0)
unity-shared/WindowManager.h (+5/-0)
To merge this branch: bzr merge lp:~azzar1/unity/fix-838854
Reviewer Review Type Date Requested Status
Marco Trevisan (Treviño) Approve
PS Jenkins bot continuous-integration Pending
Review via email: mp+137615@code.launchpad.net

Commit message

Change expo launcher icon depending on which workspace is currently being utilised.

Description of the change

== Problem ==
Bug #838854: Workspaces, Launcher - The workspace Launcher icon should change depending on which workspace is currently being utilised

== Tests ==
Unit tests added.

Requires: https://code.launchpad.net/~andyrock/unity-asset-pool/ws-icons/+merge/137598

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

Looks good, even if I'd prefer a dynamic icon with cairo... But this is fine for now.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'launcher/ExpoLauncherIcon.cpp'
2--- launcher/ExpoLauncherIcon.cpp 2012-11-26 16:09:53 +0000
3+++ launcher/ExpoLauncherIcon.cpp 2012-12-03 16:12:21 +0000
4@@ -15,6 +15,7 @@
5 * along with this program. If not, see <http://www.gnu.org/licenses/>.
6 *
7 * Authored by: Marco Trevisan <marco.trevisan@canonical.com>
8+ * Andrea Azzarone <andrea.azzarone@canonical.com>
9 */
10
11 #include "ExpoLauncherIcon.h"
12@@ -32,10 +33,51 @@
13 : SimpleLauncherIcon(IconType::EXPO)
14 {
15 tooltip_text = _("Workspace Switcher");
16- icon_name = "workspace-switcher";
17+ icon_name = "workspace-switcher-top-left";
18 SetQuirk(Quirk::VISIBLE, false);
19 SetQuirk(Quirk::RUNNING, false);
20 SetShortcut('s');
21+
22+ auto& wm = WindowManager::Default();
23+ OnViewportLayoutChanged(wm.GetViewportHSize(), wm.GetViewportVSize());
24+
25+ wm.viewport_layout_changed.connect(sigc::mem_fun(this, &ExpoLauncherIcon::OnViewportLayoutChanged));
26+}
27+
28+void ExpoLauncherIcon::OnViewportLayoutChanged(int hsize, int vsize)
29+{
30+ if (hsize != 2 || vsize != 2)
31+ {
32+ icon_name = "workspace-switcher-top-left";
33+ screen_viewport_switch_ended_connection_.disconnect();
34+ terminate_expo_connection_.disconnect();
35+ }
36+ else
37+ {
38+ UpdateIcon();
39+
40+ if (!terminate_expo_connection_)
41+ {
42+ auto& wm = WindowManager::Default();
43+ auto cb = sigc::mem_fun(this, &ExpoLauncherIcon::UpdateIcon);
44+ screen_viewport_switch_ended_connection_ = wm.screen_viewport_switch_ended.connect(cb);
45+ terminate_expo_connection_ = wm.terminate_expo.connect(cb);
46+ }
47+ }
48+}
49+
50+void ExpoLauncherIcon::UpdateIcon()
51+{
52+ auto const& vp = WindowManager::Default().GetCurrentViewport();
53+
54+ if (vp.x == 0 and vp.y == 0)
55+ icon_name = "workspace-switcher-top-left";
56+ else if (vp.x == 0)
57+ icon_name = "workspace-switcher-left-bottom";
58+ else if (vp.y == 0)
59+ icon_name = "workspace-switcher-right-top";
60+ else
61+ icon_name = "workspace-switcher-right-bottom";
62 }
63
64 void ExpoLauncherIcon::ActivateLauncherIcon(ActionArg arg)
65@@ -44,13 +86,9 @@
66 WindowManager& wm = WindowManager::Default();
67
68 if (!wm.IsExpoActive())
69- {
70 wm.InitiateExpo();
71- }
72 else
73- {
74 wm.TerminateExpo();
75- }
76 }
77
78 void ExpoLauncherIcon::Stick(bool save)
79
80=== modified file 'launcher/ExpoLauncherIcon.h'
81--- launcher/ExpoLauncherIcon.h 2012-09-07 15:01:14 +0000
82+++ launcher/ExpoLauncherIcon.h 2012-12-03 16:12:21 +0000
83@@ -37,6 +37,13 @@
84 void ActivateLauncherIcon(ActionArg arg);
85 std::string GetName() const;
86 std::string GetRemoteUri();
87+
88+private:
89+ void OnViewportLayoutChanged(int hsize, int vsize);
90+ void UpdateIcon();
91+
92+ sigc::connection screen_viewport_switch_ended_connection_;
93+ sigc::connection terminate_expo_connection_;
94 };
95
96 }
97
98=== modified file 'launcher/LauncherController.cpp'
99--- launcher/LauncherController.cpp 2012-11-28 22:05:07 +0000
100+++ launcher/LauncherController.cpp 2012-12-03 16:12:21 +0000
101@@ -145,6 +145,7 @@
102
103 WindowManager& wm = WindowManager::Default();
104 wm.window_focus_changed.connect(sigc::mem_fun(this, &Controller::Impl::OnWindowFocusChanged));
105+ wm.viewport_layout_changed.connect(sigc::group(sigc::mem_fun(this, &Controller::Impl::UpdateNumWorkspaces), sigc::_1 * sigc::_2));
106
107 ubus.RegisterInterest(UBUS_QUICKLIST_END_KEY_NAV, [&](GVariant * args) {
108 if (reactivate_keynav)
109
110=== modified file 'launcher/LauncherIcon.cpp'
111--- launcher/LauncherIcon.cpp 2012-11-27 01:09:26 +0000
112+++ launcher/LauncherIcon.cpp 2012-12-03 16:12:21 +0000
113@@ -360,7 +360,7 @@
114
115 // FIXME: we need to create some kind of -unity postfix to see if we are looking to the unity-icon-theme
116 // for dedicated unity icons, then remove the postfix and degrade to other icon themes if not found
117- if (icon_name == "workspace-switcher" && IsMonoDefaultTheme())
118+ if (icon_name.find("workspace-switcher") == 0)
119 result = TextureFromSpecificGtkTheme(GetUnityTheme(), icon_name, size, update_glow_colors);
120
121 if (!result)
122
123=== modified file 'plugins/unityshell/src/unityshell.cpp'
124--- plugins/unityshell/src/unityshell.cpp 2012-11-27 00:39:39 +0000
125+++ plugins/unityshell/src/unityshell.cpp 2012-12-03 16:12:21 +0000
126@@ -3071,7 +3071,10 @@
127 if (strcmp(plugin, "core") == 0)
128 {
129 if (strcmp(name, "hsize") == 0 || strcmp(name, "vsize") == 0)
130- launcher_controller_->UpdateNumWorkspaces(screen->vpSize().width() * screen->vpSize().height());
131+ {
132+ WindowManager& wm = WindowManager::Default();
133+ wm.viewport_layout_changed.emit(screen->vpSize().width(), screen->vpSize().height());
134+ }
135 }
136 }
137 return status;
138
139=== modified file 'tests/test_expo_launcher_icon.cpp'
140--- tests/test_expo_launcher_icon.cpp 2012-10-11 01:44:15 +0000
141+++ tests/test_expo_launcher_icon.cpp 2012-12-03 16:12:21 +0000
142@@ -15,34 +15,39 @@
143 * <http://www.gnu.org/licenses/>
144 *
145 * Authored by: Marco Trevisan (Treviño) <marco.trevisan@canonical.com>
146+ * Andrea Azzarone <andrea.azzarone@canonical.com>
147 */
148
149 #include <gmock/gmock.h>
150
151 #include "launcher/ExpoLauncherIcon.h"
152-#include "unity-shared/WindowManager.h"
153+#include "unity-shared/StandaloneWindowManager.h"
154
155 using namespace unity;
156 using namespace unity::launcher;
157
158 namespace
159 {
160+
161 struct TestExpoLauncherIcon : testing::Test
162 {
163+ TestExpoLauncherIcon()
164+ : wm(dynamic_cast<StandaloneWindowManager*>(&WindowManager::Default()))
165+ {}
166+
167 ExpoLauncherIcon icon;
168+ StandaloneWindowManager* wm;
169 };
170
171 TEST_F(TestExpoLauncherIcon, ActivateToggleExpo)
172 {
173- WindowManager& wm = WindowManager::Default();
174-
175- ASSERT_FALSE(wm.IsExpoActive());
176-
177- icon.Activate(ActionArg());
178- ASSERT_TRUE(wm.IsExpoActive());
179-
180- icon.Activate(ActionArg());
181- EXPECT_FALSE(wm.IsExpoActive());
182+ ASSERT_FALSE(wm->IsExpoActive());
183+
184+ icon.Activate(ActionArg());
185+ ASSERT_TRUE(wm->IsExpoActive());
186+
187+ icon.Activate(ActionArg());
188+ EXPECT_FALSE(wm->IsExpoActive());
189 }
190
191 TEST_F(TestExpoLauncherIcon, Position)
192@@ -55,4 +60,60 @@
193 EXPECT_EQ(icon.RemoteUri(), "unity://expo-icon");
194 }
195
196+TEST_F(TestExpoLauncherIcon, Icon2x2Layout)
197+{
198+ EXPECT_EQ(icon.icon_name, "workspace-switcher-top-left");
199+
200+ wm->SetCurrentViewport(nux::Point(1, 0));
201+ wm->screen_viewport_switch_ended.emit();
202+ EXPECT_EQ(icon.icon_name, "workspace-switcher-right-top");
203+
204+ wm->SetCurrentViewport(nux::Point(0, 1));
205+ wm->screen_viewport_switch_ended.emit();
206+ EXPECT_EQ(icon.icon_name, "workspace-switcher-left-bottom");
207+
208+ wm->SetCurrentViewport(nux::Point(1, 1));
209+ wm->screen_viewport_switch_ended.emit();
210+ EXPECT_EQ(icon.icon_name, "workspace-switcher-right-bottom");
211+
212+ wm->SetCurrentViewport(nux::Point(0, 0));
213+ wm->screen_viewport_switch_ended.emit();
214+ EXPECT_EQ(icon.icon_name, "workspace-switcher-top-left");
215+}
216+
217+TEST_F(TestExpoLauncherIcon, Icon2x2Layout_Expo)
218+{
219+ EXPECT_EQ(icon.icon_name, "workspace-switcher-top-left");
220+
221+ wm->SetCurrentViewport(nux::Point(1, 0));
222+ wm->terminate_expo.emit();
223+ EXPECT_EQ(icon.icon_name, "workspace-switcher-right-top");
224+
225+ wm->SetCurrentViewport(nux::Point(0, 1));
226+ wm->terminate_expo.emit();
227+ EXPECT_EQ(icon.icon_name, "workspace-switcher-left-bottom");
228+
229+ wm->SetCurrentViewport(nux::Point(1, 1));
230+ wm->terminate_expo.emit();
231+ EXPECT_EQ(icon.icon_name, "workspace-switcher-right-bottom");
232+
233+ wm->SetCurrentViewport(nux::Point(0, 0));
234+ wm->terminate_expo.emit();
235+ EXPECT_EQ(icon.icon_name, "workspace-switcher-top-left");
236+}
237+
238+TEST_F(TestExpoLauncherIcon, IconNot2x2Layout)
239+{
240+ wm->SetCurrentViewport(nux::Point(1, 0));
241+ wm->screen_viewport_switch_ended.emit();
242+ EXPECT_EQ(icon.icon_name, "workspace-switcher-right-top");
243+
244+ wm->viewport_layout_changed.emit(5, 2);
245+ EXPECT_EQ(icon.icon_name, "workspace-switcher-top-left");
246+
247+ wm->SetCurrentViewport(nux::Point(1, 1));
248+ wm->screen_viewport_switch_ended.emit();
249+ EXPECT_EQ(icon.icon_name, "workspace-switcher-top-left");
250+}
251+
252 }
253
254=== modified file 'unity-shared/PluginAdapter.cpp'
255--- unity-shared/PluginAdapter.cpp 2012-11-27 01:09:26 +0000
256+++ unity-shared/PluginAdapter.cpp 2012-12-03 16:12:21 +0000
257@@ -1084,6 +1084,22 @@
258 return m_Screen->vpSize().width() * m_Screen->vpSize().height();
259 }
260
261+nux::Point PluginAdapter::GetCurrentViewport() const
262+{
263+ CompPoint const& vp = m_Screen->vp();
264+ return nux::Point(vp.x(), vp.y());
265+}
266+
267+int PluginAdapter::GetViewportHSize() const
268+{
269+ return m_Screen->vpSize().width();
270+}
271+
272+int PluginAdapter::GetViewportVSize() const
273+{
274+ return m_Screen->vpSize().height();
275+}
276+
277 void PluginAdapter::SetMwmWindowHints(Window xid, MotifWmHints* new_hints) const
278 {
279 Display* display = m_Screen->dpy();
280
281=== modified file 'unity-shared/PluginAdapter.h'
282--- unity-shared/PluginAdapter.h 2012-11-12 17:27:48 +0000
283+++ unity-shared/PluginAdapter.h 2012-12-03 16:12:21 +0000
284@@ -177,6 +177,10 @@
285
286 int WorkspaceCount() const;
287
288+ nux::Point GetCurrentViewport() const override;
289+ int GetViewportHSize() const override;
290+ int GetViewportVSize() const override;
291+
292 void SetCoverageAreaBeforeAutomaximize(float area);
293
294 bool SaveInputFocus();
295
296=== modified file 'unity-shared/StandaloneWindowManager.cpp'
297--- unity-shared/StandaloneWindowManager.cpp 2012-11-27 01:19:45 +0000
298+++ unity-shared/StandaloneWindowManager.cpp 2012-12-03 16:12:21 +0000
299@@ -438,6 +438,21 @@
300 return 4;
301 }
302
303+nux::Point StandaloneWindowManager::GetCurrentViewport() const
304+{
305+ return current_vp_;
306+}
307+
308+ int StandaloneWindowManager::GetViewportHSize() const
309+{
310+ return 2;
311+}
312+
313+int StandaloneWindowManager::GetViewportVSize() const
314+{
315+ return 2;
316+}
317+
318 bool StandaloneWindowManager::SaveInputFocus()
319 {
320 return false;
321@@ -480,6 +495,10 @@
322 return standalone_windows_;
323 }
324
325+void StandaloneWindowManager::SetCurrentViewport(nux::Point const& vp)
326+{
327+ current_vp_ = vp;
328+}
329
330 void StandaloneWindowManager::AddProperties(GVariantBuilder* builder)
331 {
332
333=== modified file 'unity-shared/StandaloneWindowManager.h'
334--- unity-shared/StandaloneWindowManager.h 2012-10-31 18:20:10 +0000
335+++ unity-shared/StandaloneWindowManager.h 2012-12-03 16:12:21 +0000
336@@ -129,6 +129,10 @@
337
338 virtual int WorkspaceCount() const;
339
340+ nux::Point GetCurrentViewport() const override;
341+ int GetViewportHSize() const override;
342+ int GetViewportVSize() const override;
343+
344 virtual bool SaveInputFocus();
345 virtual bool RestoreInputFocus();
346
347@@ -142,6 +146,8 @@
348 void AddStandaloneWindow(StandaloneWindow::Ptr const& window);
349 std::map<Window, StandaloneWindow::Ptr> GetStandaloneWindows() const;
350
351+ void SetCurrentViewport(nux::Point const& vp);
352+
353 protected:
354 virtual void AddProperties(GVariantBuilder* builder);
355
356@@ -152,6 +158,7 @@
357 bool scale_active_for_group_;
358 unsigned current_desktop_;
359 std::map<Window, StandaloneWindow::Ptr> standalone_windows_;
360+ nux::Point current_vp_;
361 };
362
363 }
364
365=== modified file 'unity-shared/WindowManager.h'
366--- unity-shared/WindowManager.h 2012-11-15 18:44:55 +0000
367+++ unity-shared/WindowManager.h 2012-12-03 16:12:21 +0000
368@@ -141,6 +141,10 @@
369
370 virtual int WorkspaceCount() const = 0;
371
372+ virtual nux::Point GetCurrentViewport() const = 0;
373+ virtual int GetViewportHSize() const = 0;
374+ virtual int GetViewportVSize() const = 0;
375+
376 virtual bool SaveInputFocus() = 0;
377 virtual bool RestoreInputFocus() = 0;
378
379@@ -173,6 +177,7 @@
380 sigc::signal<void> screen_ungrabbed;
381 sigc::signal<void> screen_viewport_switch_started;
382 sigc::signal<void> screen_viewport_switch_ended;
383+ sigc::signal<void, int, int> viewport_layout_changed;
384
385 protected:
386 std::string GetName() const;