Merge lp:~3v1n0/unity/launcher-controller-ensure-new-5.0 into lp:unity/5.0

Proposed by Marco Trevisan (Treviño) on 2012-07-26
Status: Merged
Approved by: Marco Trevisan (Treviño) on 2012-07-27
Approved revision: 2394
Merged at revision: 2393
Proposed branch: lp:~3v1n0/unity/launcher-controller-ensure-new-5.0
Merge into: lp:unity/5.0
Diff against target: 980 lines (+539/-194)
10 files modified
plugins/unityshell/src/EdgeBarrierController.cpp (+29/-19)
plugins/unityshell/src/EdgeBarrierController.h (+4/-3)
plugins/unityshell/src/LauncherController.cpp (+35/-166)
plugins/unityshell/src/LauncherController.h (+2/-0)
plugins/unityshell/src/LauncherControllerPrivate.h (+157/-0)
plugins/unityshell/src/UScreen.cpp (+4/-3)
plugins/unityshell/src/UScreen.h (+5/-2)
tests/CMakeLists.txt (+16/-1)
tests/test_launcher_controller.cpp (+202/-0)
tests/test_uscreen_mock.h (+85/-0)
To merge this branch: bzr merge lp:~3v1n0/unity/launcher-controller-ensure-new-5.0
Reviewer Review Type Date Requested Status
Andrea Azzarone (community) 2012-07-26 Approve on 2012-07-26
Review via email: mp+116862@code.launchpad.net

Commit message

LauncherController: Rewritten EnsureLaunchers() added tests, fix a crash caused by invalid barrier subscriptions.

Description of the change

To post a comment you must log in.
Andrea Azzarone (azzar1) :
review: Approve
Unity Merger (unity-merger) wrote :

The Jenkins job https://jenkins.qa.ubuntu.com/job/automerge-unity/969/console reported an error when processing this lp:~3v1n0/unity/launcher-controller-ensure-new-5.0 branch.
Not merging it.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plugins/unityshell/src/EdgeBarrierController.cpp'
2--- plugins/unityshell/src/EdgeBarrierController.cpp 2012-07-03 18:33:18 +0000
3+++ plugins/unityshell/src/EdgeBarrierController.cpp 2012-07-26 13:25:21 +0000
4@@ -15,6 +15,7 @@
5 * along with this program. If not, see <http://www.gnu.org/licenses/>.
6 *
7 * Authored by: Jason Smith <jason.smith@canonical.com>
8+ * Marco Trevisan <marco.trevisan@canonical.com>
9 */
10
11 #include "EdgeBarrierController.h"
12@@ -48,7 +49,7 @@
13 {
14 UScreen *uscreen = UScreen::GetDefault();
15
16- auto monitors = uscreen->GetMonitors();
17+ auto const& monitors = uscreen->GetMonitors();
18 ResizeBarrierList(monitors);
19
20 uscreen->changed.connect([&](int primary, std::vector<nux::Geometry>& layout) {
21@@ -123,17 +124,17 @@
22
23 float decay_responsiveness_mult = ((parent_->options()->edge_responsiveness() - 1) * .3f) + 1;
24 decaymulator_->rate_of_decay = parent_->options()->edge_decay_rate() * decay_responsiveness_mult;
25-
26+
27 float overcome_responsiveness_mult = ((parent_->options()->edge_responsiveness() - 1) * 1.0f) + 1;
28 edge_overcome_pressure_ = parent_->options()->edge_overcome_pressure() * overcome_responsiveness_mult;
29 }
30
31 void EdgeBarrierController::Impl::OnPointerBarrierEvent(ui::PointerBarrierWrapper* owner, ui::BarrierEvent::Ptr event)
32 {
33- int monitor = owner->index;
34+ unsigned monitor = owner->index;
35 bool process = true;
36
37- if ((size_t)monitor <= subscribers_.size())
38+ if (monitor < subscribers_.size())
39 {
40 auto subscriber = subscribers_[monitor];
41 if (subscriber && subscriber->HandleBarrierEvent(owner, event))
42@@ -158,30 +159,39 @@
43 EdgeBarrierController::EdgeBarrierController()
44 : sticky_edges(false)
45 , pimpl(new Impl(this))
46-{
47-}
48+{}
49
50 EdgeBarrierController::~EdgeBarrierController()
51-{
52-
53-}
54-
55-void EdgeBarrierController::Subscribe(EdgeBarrierSubscriber* subscriber, int monitor)
56-{
57- if (pimpl->subscribers_.size() <= (size_t)monitor)
58+{}
59+
60+void EdgeBarrierController::Subscribe(EdgeBarrierSubscriber* subscriber, unsigned int monitor)
61+{
62+ if (monitor >= pimpl->subscribers_.size())
63 pimpl->subscribers_.resize(monitor + 1);
64+
65+ auto const& monitors = UScreen::GetDefault()->GetMonitors();
66 pimpl->subscribers_[monitor] = subscriber;
67-
68- pimpl->SetupBarriers(UScreen::GetDefault()->GetMonitors());
69+ pimpl->ResizeBarrierList(monitors);
70+ pimpl->SetupBarriers(monitors);
71 }
72
73-void EdgeBarrierController::Unsubscribe(EdgeBarrierSubscriber* subscriber, int monitor)
74+void EdgeBarrierController::Unsubscribe(EdgeBarrierSubscriber* subscriber, unsigned int monitor)
75 {
76- if (pimpl->subscribers_.size() < (size_t)monitor || pimpl->subscribers_[monitor] != subscriber)
77+ if (monitor >= pimpl->subscribers_.size() || pimpl->subscribers_[monitor] != subscriber)
78 return;
79+
80+ auto const& monitors = UScreen::GetDefault()->GetMonitors();
81 pimpl->subscribers_[monitor] = nullptr;
82-
83- pimpl->SetupBarriers(UScreen::GetDefault()->GetMonitors());
84+ pimpl->ResizeBarrierList(monitors);
85+ pimpl->SetupBarriers(monitors);
86+}
87+
88+EdgeBarrierSubscriber* EdgeBarrierController::GetSubscriber(unsigned int monitor)
89+{
90+ if (monitor >= pimpl->subscribers_.size())
91+ return nullptr;
92+
93+ return pimpl->subscribers_[monitor];
94 }
95
96
97
98=== modified file 'plugins/unityshell/src/EdgeBarrierController.h'
99--- plugins/unityshell/src/EdgeBarrierController.h 2012-04-04 23:34:52 +0000
100+++ plugins/unityshell/src/EdgeBarrierController.h 2012-07-26 13:25:21 +0000
101@@ -43,12 +43,13 @@
102 nux::Property<bool> sticky_edges;
103 nux::Property<launcher::Options::Ptr> options;
104
105- void Subscribe(EdgeBarrierSubscriber* subscriber, int monitor);
106- void Unsubscribe(EdgeBarrierSubscriber* subscriber, int monitor);
107+ void Subscribe(EdgeBarrierSubscriber* subscriber, unsigned int monitor);
108+ void Unsubscribe(EdgeBarrierSubscriber* subscriber, unsigned int monitor);
109+ EdgeBarrierSubscriber* GetSubscriber(unsigned int monitor);
110
111 private:
112 struct Impl;
113- Impl* pimpl;
114+ std::unique_ptr<Impl> pimpl;
115 };
116
117 }
118
119=== modified file 'plugins/unityshell/src/LauncherController.cpp'
120--- plugins/unityshell/src/LauncherController.cpp 2012-06-28 02:06:44 +0000
121+++ plugins/unityshell/src/LauncherController.cpp 2012-07-26 13:25:21 +0000
122@@ -18,7 +18,6 @@
123 * Tim Penhey <tim.penhey@canonical.com>
124 */
125
126-#include <gio/gio.h>
127 #include <glib/gi18n-lib.h>
128 #include <libbamf/libbamf.h>
129
130@@ -27,28 +26,21 @@
131 #include <Nux/BaseWindow.h>
132 #include <NuxCore/Logger.h>
133
134-#include "LauncherOptions.h"
135 #include "BamfLauncherIcon.h"
136+#include "BFBLauncherIcon.h"
137 #include "DesktopLauncherIcon.h"
138 #include "DeviceLauncherIcon.h"
139-#include "DeviceLauncherSection.h"
140-#include "EdgeBarrierController.h"
141 #include "FavoriteStore.h"
142 #include "HudLauncherIcon.h"
143-#include "Launcher.h"
144 #include "LauncherController.h"
145-#include "LauncherEntryRemote.h"
146-#include "LauncherEntryRemoteModel.h"
147-#include "AbstractLauncherIcon.h"
148+#include "LauncherControllerPrivate.h"
149+#include "LauncherOptions.h"
150 #include "SoftwareCenterLauncherIcon.h"
151-#include "LauncherModel.h"
152-#include "WindowManager.h"
153+#include "TimeUtil.h"
154 #include "TrashLauncherIcon.h"
155-#include "BFBLauncherIcon.h"
156+#include "UBusMessages.h"
157 #include "UScreen.h"
158-#include "UBusWrapper.h"
159-#include "UBusMessages.h"
160-#include "TimeUtil.h"
161+#include "WindowManager.h"
162
163 namespace unity
164 {
165@@ -70,117 +62,6 @@
166 }
167 }
168
169-class Controller::Impl
170-{
171-public:
172- Impl(Display* display, Controller* parent);
173- ~Impl();
174-
175- void UpdateNumWorkspaces(int workspaces);
176-
177- Launcher* CreateLauncher(int monitor);
178-
179- void Save();
180- void SortAndUpdate();
181-
182- nux::ObjectPtr<Launcher> CurrentLauncher();
183-
184- void OnIconAdded(AbstractLauncherIcon::Ptr icon);
185- void OnIconRemoved(AbstractLauncherIcon::Ptr icon);
186-
187- void OnLauncherAddRequest(char* path, AbstractLauncherIcon::Ptr before);
188- void OnLauncherAddRequestSpecial(std::string const& path, AbstractLauncherIcon::Ptr before, std::string const& aptdaemon_trans_id, std::string const& icon_path,
189- int icon_x, int icon_y, int icon_size);
190- void OnLauncherRemoveRequest(AbstractLauncherIcon::Ptr icon);
191- void OnSCIconAnimationComplete(AbstractLauncherIcon::Ptr icon);
192-
193- void OnLauncherEntryRemoteAdded(LauncherEntryRemote::Ptr const& entry);
194- void OnLauncherEntryRemoteRemoved(LauncherEntryRemote::Ptr const& entry);
195-
196- void OnFavoriteStoreFavoriteAdded(std::string const& entry, std::string const& pos, bool before);
197- void OnFavoriteStoreFavoriteRemoved(std::string const& entry);
198- void OnFavoriteStoreReordered();
199-
200-
201- void InsertExpoAction();
202- void RemoveExpoAction();
203-
204- void InsertDesktopIcon();
205- void RemoveDesktopIcon();
206-
207- void SendHomeActivationRequest();
208-
209- int MonitorWithMouse();
210-
211- void InsertTrash();
212-
213- void RegisterIcon(AbstractLauncherIcon::Ptr icon);
214-
215- AbstractLauncherIcon::Ptr CreateFavorite(const char* file_path);
216-
217- SoftwareCenterLauncherIcon::Ptr CreateSCLauncherIcon(std::string const& file_path, std::string const& aptdaemon_trans_id, std::string const& icon_path);
218-
219- void SetupBamf();
220-
221- void EnsureLaunchers(int primary, std::vector<nux::Geometry> const& monitors);
222-
223- void OnExpoActivated();
224-
225- void OnScreenChanged(int primary_monitor, std::vector<nux::Geometry>& monitors);
226-
227- void OnWindowFocusChanged (guint32 xid);
228-
229- void OnViewOpened(BamfMatcher* matcher, BamfView* view);
230-
231- void ReceiveMouseDownOutsideArea(int x, int y, unsigned long button_flags, unsigned long key_flags);
232-
233- void ReceiveLauncherKeyPress(unsigned long eventType,
234- unsigned long keysym,
235- unsigned long state,
236- const char* character,
237- unsigned short keyCount);
238-
239- Controller* parent_;
240- glib::Object<BamfMatcher> matcher_;
241- glib::Signal<void, BamfMatcher*, BamfView*> view_opened_signal_;
242- LauncherModel::Ptr model_;
243- nux::ObjectPtr<Launcher> launcher_;
244- nux::ObjectPtr<Launcher> keyboard_launcher_;
245- int sort_priority_;
246- DeviceLauncherSection device_section_;
247- LauncherEntryRemoteModel remote_model_;
248- AbstractLauncherIcon::Ptr expo_icon_;
249- AbstractLauncherIcon::Ptr desktop_icon_;
250- int num_workspaces_;
251- bool show_desktop_icon_;
252- Display* display_;
253-
254- guint bamf_timer_handler_id_;
255- guint launcher_key_press_handler_id_;
256- guint launcher_label_show_handler_id_;
257- guint launcher_hide_handler_id_;
258-
259- bool launcher_open;
260- bool launcher_keynav;
261- bool launcher_grabbed;
262- bool reactivate_keynav;
263- int reactivate_index;
264- bool keynav_restore_window_;
265-
266- UBusManager ubus;
267-
268- int launcher_key_press_time_;
269-
270- ui::EdgeBarrierController::Ptr edge_barriers_;
271-
272- LauncherList launchers;
273-
274- sigc::connection on_expoicon_activate_connection_;
275- sigc::connection launcher_key_press_connection_;
276- sigc::connection launcher_event_outside_connection_;
277-};
278-
279-
280 Controller::Impl::Impl(Display* display, Controller* parent)
281 : parent_(parent)
282 , matcher_(nullptr)
283@@ -191,9 +72,8 @@
284 , launcher_key_press_handler_id_(0)
285 , launcher_label_show_handler_id_(0)
286 , launcher_hide_handler_id_(0)
287- , edge_barriers_(new ui::EdgeBarrierController())
288 {
289- edge_barriers_->options = parent_->options();
290+ edge_barriers_.options = parent_->options();
291
292 UScreen* uscreen = UScreen::GetDefault();
293 auto monitors = uscreen->GetMonitors();
294@@ -292,54 +172,43 @@
295 unsigned int num_monitors = monitors.size();
296 unsigned int num_launchers = parent_->multiple_launchers ? num_monitors : 1;
297 unsigned int launchers_size = launchers.size();
298- unsigned int last_monitor = 0;
299-
300- if (num_launchers == 1)
301- {
302- if (launchers_size == 0)
303- {
304- launchers.push_back(nux::ObjectPtr<Launcher>(CreateLauncher(primary)));
305- }
306- else if (!launchers[0].IsValid())
307- {
308- launchers[0] = nux::ObjectPtr<Launcher>(CreateLauncher(primary));
309- }
310-
311- launchers[0]->monitor(primary);
312- launchers[0]->Resize();
313- last_monitor = 1;
314- }
315- else
316- {
317- for (unsigned int i = 0; i < num_monitors; i++, last_monitor++)
318- {
319- if (i >= launchers_size)
320- {
321- launchers.push_back(nux::ObjectPtr<Launcher>(CreateLauncher(i)));
322- }
323-
324- launchers[i]->monitor(i);
325- launchers[i]->Resize();
326- }
327- }
328-
329- for (unsigned int i = last_monitor; i < launchers_size; ++i)
330+ unsigned int last_launcher = 0;
331+
332+ for (unsigned int i = 0; i < num_launchers; i++, last_launcher++)
333+ {
334+ if (i >= launchers_size)
335+ {
336+ launchers.push_back(nux::ObjectPtr<Launcher>(CreateLauncher(i)));
337+ }
338+ else if (!launchers[i])
339+ {
340+ launchers[i] = nux::ObjectPtr<Launcher>(CreateLauncher(i));
341+ }
342+
343+ int monitor = (num_launchers == 1) ? primary : i;
344+
345+ if (launchers[i]->monitor() != monitor)
346+ {
347+ edge_barriers_.Unsubscribe(launchers[i].GetPointer(), launchers[i]->monitor);
348+ }
349+
350+ launchers[i]->monitor(monitor);
351+ launchers[i]->Resize();
352+ edge_barriers_.Subscribe(launchers[i].GetPointer(), launchers[i]->monitor);
353+ }
354+
355+ for (unsigned int i = last_launcher; i < launchers_size; ++i)
356 {
357 auto launcher = launchers[i];
358- if (launcher.IsValid())
359+ if (launcher)
360 {
361 parent_->RemoveChild(launcher.GetPointer());
362 launcher->GetParent()->UnReference();
363- edge_barriers_->Unsubscribe(launcher.GetPointer(), launcher->monitor);
364+ edge_barriers_.Unsubscribe(launcher.GetPointer(), launcher->monitor);
365 }
366 }
367
368 launchers.resize(num_launchers);
369-
370- for (size_t i = 0; i < launchers.size(); ++i)
371- {
372- edge_barriers_->Subscribe(launchers[i].GetPointer(), launchers[i]->monitor);
373- }
374 }
375
376 void Controller::Impl::OnScreenChanged(int primary_monitor, std::vector<nux::Geometry>& monitors)
377
378=== modified file 'plugins/unityshell/src/LauncherController.h'
379--- plugins/unityshell/src/LauncherController.h 2012-04-24 16:59:34 +0000
380+++ plugins/unityshell/src/LauncherController.h 2012-07-26 13:25:21 +0000
381@@ -35,6 +35,7 @@
382 class AbstractLauncherIcon;
383 class Launcher;
384 class LauncherModel;
385+class TestLauncherController;
386
387 class Controller : public unity::debug::Introspectable, public sigc::trackable
388 {
389@@ -86,6 +87,7 @@
390 void AddProperties(GVariantBuilder* builder);
391
392 private:
393+ friend class TestLauncherController;
394 class Impl;
395 Impl* pimpl;
396 };
397
398=== added file 'plugins/unityshell/src/LauncherControllerPrivate.h'
399--- plugins/unityshell/src/LauncherControllerPrivate.h 1970-01-01 00:00:00 +0000
400+++ plugins/unityshell/src/LauncherControllerPrivate.h 2012-07-26 13:25:21 +0000
401@@ -0,0 +1,157 @@
402+/*
403+ * Copyright 2012 Canonical Ltd.
404+ *
405+ * This program is free software: you can redistribute it and/or modify it
406+ * under the terms of the GNU General Public License version 3, as published
407+ * by the Free Software Foundation.
408+ *
409+ * This program is distributed in the hope that it will be useful, but
410+ * WITHOUT ANY WARRANTY; without even the implied warranties of
411+ * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
412+ * PURPOSE. See the GNU General Public License for more details.
413+ *
414+ * You should have received a copy of the GNU General Public License
415+ * version 3 along with this program. If not, see
416+ * <http://www.gnu.org/licenses/>
417+ *
418+ * Authored by: Jason Smith <jason.smith@canonical.com>
419+ * Tim Penhey <tim.penhey@canonical.com>
420+ * Marco Trevisan (Treviño) <marco.trevisan@canonical.com>
421+ *
422+ */
423+
424+#ifndef LAUNCHER_CONTROLLER_PRIVATE_H
425+#define LAUNCHER_CONTROLLER_PRIVATE_H
426+
427+#include <Nux/Nux.h>
428+
429+#include "AbstractLauncherIcon.h"
430+#include "DeviceLauncherSection.h"
431+#include "EdgeBarrierController.h"
432+#include "LauncherController.h"
433+#include "Launcher.h"
434+#include "LauncherEntryRemote.h"
435+#include "LauncherEntryRemoteModel.h"
436+#include "LauncherModel.h"
437+#include "SoftwareCenterLauncherIcon.h"
438+#include "UBusWrapper.h"
439+
440+namespace unity
441+{
442+namespace launcher
443+{
444+
445+class Controller::Impl
446+{
447+public:
448+ Impl(Display* display, Controller* parent);
449+ ~Impl();
450+
451+ void UpdateNumWorkspaces(int workspaces);
452+
453+ Launcher* CreateLauncher(int monitor);
454+
455+ void Save();
456+ void SortAndUpdate();
457+
458+ nux::ObjectPtr<Launcher> CurrentLauncher();
459+
460+ void OnIconAdded(AbstractLauncherIcon::Ptr icon);
461+ void OnIconRemoved(AbstractLauncherIcon::Ptr icon);
462+
463+ void OnLauncherAddRequest(char* path, AbstractLauncherIcon::Ptr before);
464+ void OnLauncherAddRequestSpecial(std::string const& path, AbstractLauncherIcon::Ptr before, std::string const& aptdaemon_trans_id, std::string const& icon_path,
465+ int icon_x, int icon_y, int icon_size);
466+ void OnLauncherRemoveRequest(AbstractLauncherIcon::Ptr icon);
467+ void OnSCIconAnimationComplete(AbstractLauncherIcon::Ptr icon);
468+
469+ void OnLauncherEntryRemoteAdded(LauncherEntryRemote::Ptr const& entry);
470+ void OnLauncherEntryRemoteRemoved(LauncherEntryRemote::Ptr const& entry);
471+
472+ void OnFavoriteStoreFavoriteAdded(std::string const& entry, std::string const& pos, bool before);
473+ void OnFavoriteStoreFavoriteRemoved(std::string const& entry);
474+ void OnFavoriteStoreReordered();
475+
476+
477+ void InsertExpoAction();
478+ void RemoveExpoAction();
479+
480+ void InsertDesktopIcon();
481+ void RemoveDesktopIcon();
482+
483+ void SendHomeActivationRequest();
484+
485+ int MonitorWithMouse();
486+
487+ void InsertTrash();
488+
489+ void RegisterIcon(AbstractLauncherIcon::Ptr icon);
490+
491+ AbstractLauncherIcon::Ptr CreateFavorite(const char* file_path);
492+
493+ SoftwareCenterLauncherIcon::Ptr CreateSCLauncherIcon(std::string const& file_path, std::string const& aptdaemon_trans_id, std::string const& icon_path);
494+
495+ void SetupBamf();
496+
497+ void EnsureLaunchers(int primary, std::vector<nux::Geometry> const& monitors);
498+
499+ void OnExpoActivated();
500+
501+ void OnScreenChanged(int primary_monitor, std::vector<nux::Geometry>& monitors);
502+
503+ void OnWindowFocusChanged (guint32 xid);
504+
505+ void OnViewOpened(BamfMatcher* matcher, BamfView* view);
506+
507+ void ReceiveMouseDownOutsideArea(int x, int y, unsigned long button_flags, unsigned long key_flags);
508+
509+ void ReceiveLauncherKeyPress(unsigned long eventType,
510+ unsigned long keysym,
511+ unsigned long state,
512+ const char* character,
513+ unsigned short keyCount);
514+
515+ Controller* parent_;
516+ glib::Object<BamfMatcher> matcher_;
517+ glib::Signal<void, BamfMatcher*, BamfView*> view_opened_signal_;
518+ LauncherModel::Ptr model_;
519+ nux::ObjectPtr<Launcher> launcher_;
520+ nux::ObjectPtr<Launcher> keyboard_launcher_;
521+ int sort_priority_;
522+ DeviceLauncherSection device_section_;
523+ LauncherEntryRemoteModel remote_model_;
524+ AbstractLauncherIcon::Ptr expo_icon_;
525+ AbstractLauncherIcon::Ptr desktop_icon_;
526+ int num_workspaces_;
527+ bool show_desktop_icon_;
528+ Display* display_;
529+
530+ guint bamf_timer_handler_id_;
531+ guint launcher_key_press_handler_id_;
532+ guint launcher_label_show_handler_id_;
533+ guint launcher_hide_handler_id_;
534+
535+ bool launcher_open;
536+ bool launcher_keynav;
537+ bool launcher_grabbed;
538+ bool reactivate_keynav;
539+ int reactivate_index;
540+ bool keynav_restore_window_;
541+
542+ UBusManager ubus;
543+
544+ int launcher_key_press_time_;
545+
546+ ui::EdgeBarrierController edge_barriers_;
547+
548+ LauncherList launchers;
549+
550+ sigc::connection on_expoicon_activate_connection_;
551+ sigc::connection launcher_key_press_connection_;
552+ sigc::connection launcher_event_outside_connection_;
553+};
554+
555+} // launcher namespace
556+} // unity namespace
557+
558+#endif
559
560=== modified file 'plugins/unityshell/src/UScreen.cpp'
561--- plugins/unityshell/src/UScreen.cpp 2012-04-18 13:25:19 +0000
562+++ plugins/unityshell/src/UScreen.cpp 2012-07-26 13:25:21 +0000
563@@ -24,18 +24,19 @@
564
565 namespace
566 {
567-static UScreen* default_screen_ = nullptr;
568 nux::logging::Logger logger("unity.screen");
569 }
570
571+UScreen* UScreen::default_screen_ = nullptr;
572+
573 UScreen::UScreen()
574- : screen_(gdk_screen_get_default(), glib::AddRef())
575+ : primary_(0)
576+ , screen_(gdk_screen_get_default(), glib::AddRef())
577 , proxy_("org.freedesktop.UPower",
578 "/org/freedesktop/UPower",
579 "org.freedesktop.UPower",
580 G_BUS_TYPE_SYSTEM)
581 , refresh_id_(0)
582- , primary_(0)
583 {
584 size_changed_signal_.Connect(screen_, "size-changed", sigc::mem_fun(this, &UScreen::Changed));
585 monitors_changed_signal_.Connect(screen_, "monitors-changed", sigc::mem_fun(this, &UScreen::Changed));
586
587=== modified file 'plugins/unityshell/src/UScreen.h'
588--- plugins/unityshell/src/UScreen.h 2012-04-18 13:07:29 +0000
589+++ plugins/unityshell/src/UScreen.h 2012-07-26 13:25:21 +0000
590@@ -54,14 +54,17 @@
591 void Changed(GdkScreen* screen);
592 void Refresh();
593
594-private:
595+protected:
596+ static UScreen* default_screen_;
597 std::vector<nux::Geometry> monitors_;
598+ int primary_;
599+
600+private:
601 glib::Object<GdkScreen> screen_;
602 glib::DBusProxy proxy_;
603 glib::Signal<void, GdkScreen*> size_changed_signal_;
604 glib::Signal<void, GdkScreen*> monitors_changed_signal_;
605 guint refresh_id_;
606- int primary_;
607 };
608
609 } // Namespace
610
611=== modified file 'tests/CMakeLists.txt'
612--- tests/CMakeLists.txt 2012-06-28 08:49:20 +0000
613+++ tests/CMakeLists.txt 2012-07-26 13:25:21 +0000
614@@ -205,6 +205,7 @@
615 test_icon_loader.cpp
616 test_im_text_entry.cpp
617 test_hud_view.cpp
618+ test_launcher_controller.cpp
619 test_keyboard_util.cpp
620 test_resultviewgrid.cpp
621 test_single_monitor_launcher_icon.cpp
622@@ -214,13 +215,21 @@
623 ${UNITY_SRC}/AbstractPlacesGroup.cpp
624 ${UNITY_SRC}/Animator.cpp
625 ${UNITY_SRC}/BackgroundEffectHelper.cpp
626+ ${UNITY_SRC}/BamfLauncherIcon.cpp
627+ ${UNITY_SRC}/BFBLauncherIcon.cpp
628 ${UNITY_SRC}/CairoBaseWindow.cpp
629 ${UNITY_SRC}/DashSettings.cpp
630 ${UNITY_SRC}/DashStyle.cpp
631 ${UNITY_SRC}/DashViewPrivate.cpp
632 ${UNITY_SRC}/Decaymulator.cpp
633+ ${UNITY_SRC}/DesktopLauncherIcon.cpp
634+ ${UNITY_SRC}/DeviceLauncherIcon.cpp
635+ ${UNITY_SRC}/DeviceLauncherSection.cpp
636+ ${UNITY_SRC}/DevicesSettings.cpp
637 ${UNITY_SRC}/DNDCollectionWindow.cpp
638 ${UNITY_SRC}/DndData.cpp
639+ ${UNITY_SRC}/EdgeBarrierController.cpp
640+ ${UNITY_SRC}/FavoriteStore.cpp
641 ${UNITY_SRC}/GeisAdapter.cpp
642 ${UNITY_SRC}/IconLoader.cpp
643 ${UNITY_SRC}/IconRenderer.cpp
644@@ -233,16 +242,21 @@
645 ${UNITY_SRC}/HudController.cpp
646 ${UNITY_SRC}/HudIcon.cpp
647 ${UNITY_SRC}/HudIconTextureSource.cpp
648+ ${UNITY_SRC}/HudLauncherIcon.cpp
649 ${UNITY_SRC}/HudPrivate.cpp
650 ${UNITY_SRC}/HudView.cpp
651+ ${UNITY_SRC}/IntrospectableWrappers.cpp
652 ${UNITY_SRC}/LayoutSystem.cpp
653 ${UNITY_SRC}/Launcher.cpp
654 ${UNITY_SRC}/LauncherDragWindow.cpp
655+ ${UNITY_SRC}/LauncherController.cpp
656 ${UNITY_SRC}/LauncherEntryRemote.cpp
657+ ${UNITY_SRC}/LauncherEntryRemoteModel.cpp
658 ${UNITY_SRC}/LauncherHideMachine.cpp
659 ${UNITY_SRC}/LauncherHoverMachine.cpp
660 ${UNITY_SRC}/LauncherIcon.cpp
661 ${UNITY_SRC}/LauncherModel.cpp
662+ ${UNITY_SRC}/LauncherOptions.cpp
663 ${UNITY_SRC}/KeyboardUtil.cpp
664 ${UNITY_SRC}/OverlayRenderer.cpp
665 ${UNITY_SRC}/JSONParser.cpp
666@@ -266,6 +280,7 @@
667 ${UNITY_SRC}/QuicklistMenuItemLabel.cpp
668 ${UNITY_SRC}/QuicklistMenuItemRadio.cpp
669 ${UNITY_SRC}/QuicklistMenuItemSeparator.cpp
670+ ${UNITY_SRC}/SoftwareCenterLauncherIcon.cpp
671 ${UNITY_SRC}/SpacerLauncherIcon.cpp
672 ${UNITY_SRC}/TextureCache.cpp
673 ${UNITY_SRC}/UBusWrapper.cpp
674@@ -277,7 +292,7 @@
675 ${UNITY_SRC}/ResultView.cpp
676 ${UNITY_SRC}/ResultViewGrid.cpp
677 ${UNITY_SRC}/ResultRenderer.cpp
678- ${UNITY_SRC}/IntrospectableWrappers.cpp
679+ ${UNITY_SRC}/TrashLauncherIcon.cpp
680 )
681 target_link_libraries(test-gtest gtest gmock ${LIBS})
682 add_test(UnityGTest test-gtest)
683
684=== added file 'tests/test_launcher_controller.cpp'
685--- tests/test_launcher_controller.cpp 1970-01-01 00:00:00 +0000
686+++ tests/test_launcher_controller.cpp 2012-07-26 13:25:21 +0000
687@@ -0,0 +1,202 @@
688+/*
689+ * Copyright 2012 Canonical Ltd.
690+ *
691+ * This program is free software: you can redistribute it and/or modify it
692+ * under the terms of the GNU General Public License version 3, as published
693+ * by the Free Software Foundation.
694+ *
695+ * This program is distributed in the hope that it will be useful, but
696+ * WITHOUT ANY WARRANTY; without even the implied warranties of
697+ * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
698+ * PURPOSE. See the GNU General Public License for more details.
699+ *
700+ * You should have received a copy of the GNU General Public License
701+ * version 3 along with this program. If not, see
702+ * <http://www.gnu.org/licenses/>
703+ *
704+ * Authored by: Marco Trevisan (Treviño) <marco.trevisan@canonical.com>
705+ */
706+
707+#include <gmock/gmock.h>
708+#include "test_uscreen_mock.h"
709+
710+#include "FavoriteStore.h"
711+#include "LauncherController.h"
712+#include "LauncherControllerPrivate.h"
713+#include "PanelStyle.h"
714+#include "DashSettings.h"
715+
716+using namespace unity::launcher;
717+using namespace testing;
718+
719+namespace unity
720+{
721+
722+class MockFavoriteStore : public FavoriteStore
723+{
724+public:
725+ FavoriteList const& GetFavorites()
726+ {
727+ return fav_list_;
728+ };
729+
730+ void AddFavorite(std::string const& desktop_path, int position) {};
731+ void RemoveFavorite(std::string const& desktop_path) {};
732+ void MoveFavorite(std::string const& desktop_path, int position) {};
733+ void SetFavorites(FavoriteList const& desktop_paths) {};
734+
735+private:
736+ FavoriteList fav_list_;
737+};
738+
739+namespace launcher
740+{
741+class TestLauncherController : public testing::Test
742+{
743+public:
744+ TestLauncherController()
745+ : lc(nux::GetGraphicsDisplay()->GetX11Display())
746+ {}
747+
748+ virtual void SetUp()
749+ {
750+ lc.options = std::make_shared<Options>();
751+ lc.multiple_launchers = true;
752+ }
753+
754+protected:
755+ ui::EdgeBarrierController &GetBarrierController()
756+ {
757+ return lc.pimpl->edge_barriers_;
758+ }
759+
760+ MockUScreen uscreen;
761+ dash::Settings settings;
762+ panel::Style panel_style;
763+ GeisAdapter geis_adapter;
764+ MockFavoriteStore favorite_store;
765+ Controller lc;
766+};
767+}
768+
769+TEST_F(TestLauncherController, Construction)
770+{
771+ EXPECT_NE(lc.options(), nullptr);
772+ EXPECT_TRUE(lc.multiple_launchers());
773+}
774+
775+TEST_F(TestLauncherController, MultimonitorMultipleLaunchers)
776+{
777+ lc.multiple_launchers = true;
778+ uscreen.SetupFakeMultiMonitor();
779+
780+ ASSERT_EQ(lc.launchers().size(), max_num_monitors);
781+
782+ for (int i = 0; i < max_num_monitors; ++i)
783+ {
784+ EXPECT_EQ(lc.launchers()[i]->monitor(), i);
785+ }
786+}
787+
788+TEST_F(TestLauncherController, MultimonitorSingleLauncher)
789+{
790+ lc.multiple_launchers = false;
791+ uscreen.SetupFakeMultiMonitor(0, false);
792+
793+ for (int i = 0; i < max_num_monitors; ++i)
794+ {
795+ uscreen.SetPrimary(i);
796+ ASSERT_EQ(lc.launchers().size(), 1);
797+ EXPECT_EQ(lc.launcher().monitor(), i);
798+ }
799+}
800+
801+TEST_F(TestLauncherController, MultimonitorSwitchToMultipleLaunchers)
802+{
803+ lc.multiple_launchers = false;
804+ uscreen.SetupFakeMultiMonitor();
805+
806+ ASSERT_EQ(lc.launchers().size(), 1);
807+
808+ lc.multiple_launchers = true;
809+ EXPECT_EQ(lc.launchers().size(), max_num_monitors);
810+}
811+
812+TEST_F(TestLauncherController, MultimonitorSwitchToSingleLauncher)
813+{
814+ lc.multiple_launchers = true;
815+ int primary = 3;
816+ uscreen.SetupFakeMultiMonitor(primary);
817+
818+ ASSERT_EQ(lc.launchers().size(), max_num_monitors);
819+
820+ lc.multiple_launchers = false;
821+ EXPECT_EQ(lc.launchers().size(), 1);
822+ EXPECT_EQ(lc.launcher().monitor(), primary);
823+}
824+
825+TEST_F(TestLauncherController, MultimonitorSwitchToSingleMonitor)
826+{
827+ uscreen.SetupFakeMultiMonitor();
828+ ASSERT_EQ(lc.launchers().size(), max_num_monitors);
829+
830+ uscreen.Reset();
831+ EXPECT_EQ(lc.launchers().size(), 1);
832+ EXPECT_EQ(lc.launcher().monitor(), 0);
833+}
834+
835+TEST_F(TestLauncherController, MultimonitorRemoveMiddleMonitor)
836+{
837+ uscreen.SetupFakeMultiMonitor();
838+ ASSERT_EQ(lc.launchers().size(), max_num_monitors);
839+
840+ std::vector<nux::Geometry> &monitors = uscreen.GetMonitors();
841+ monitors.erase(monitors.begin() + monitors.size()/2);
842+ uscreen.changed.emit(uscreen.GetPrimaryMonitor(), uscreen.GetMonitors());
843+ ASSERT_EQ(lc.launchers().size(), max_num_monitors - 1);
844+
845+ for (int i = 0; i < max_num_monitors - 1; ++i)
846+ EXPECT_EQ(lc.launchers()[i]->monitor(), i);
847+}
848+
849+TEST_F(TestLauncherController, SingleMonitorSwitchToMultimonitor)
850+{
851+ ASSERT_EQ(lc.launchers().size(), 1);
852+
853+ uscreen.SetupFakeMultiMonitor();
854+
855+ EXPECT_EQ(lc.launchers().size(), max_num_monitors);
856+}
857+
858+TEST_F(TestLauncherController, MultiMonitorEdgeBarrierSubscriptions)
859+{
860+ uscreen.SetupFakeMultiMonitor();
861+
862+ for (int i = 0; i < max_num_monitors; ++i)
863+ ASSERT_EQ(GetBarrierController().GetSubscriber(i), lc.launchers()[i].GetPointer());
864+}
865+
866+TEST_F(TestLauncherController, SingleMonitorEdgeBarrierSubscriptionsUpdates)
867+{
868+ lc.multiple_launchers = false;
869+ uscreen.SetupFakeMultiMonitor(0, false);
870+
871+ for (int i = 0; i < max_num_monitors; ++i)
872+ {
873+ uscreen.SetPrimary(i);
874+
875+ for (int j = 0; j < max_num_monitors; ++j)
876+ {
877+ if (j == i)
878+ {
879+ ASSERT_EQ(GetBarrierController().GetSubscriber(j), &lc.launcher());
880+ }
881+ else
882+ {
883+ ASSERT_EQ(GetBarrierController().GetSubscriber(j), nullptr);
884+ }
885+ }
886+ }
887+}
888+
889+}
890
891=== added file 'tests/test_uscreen_mock.h'
892--- tests/test_uscreen_mock.h 1970-01-01 00:00:00 +0000
893+++ tests/test_uscreen_mock.h 2012-07-26 13:25:21 +0000
894@@ -0,0 +1,85 @@
895+/*
896+ * Copyright 2012 Canonical Ltd.
897+ *
898+ * This program is free software: you can redistribute it and/or modify it
899+ * under the terms of the GNU General Public License version 3, as published
900+ * by the Free Software Foundation.
901+ *
902+ * This program is distributed in the hope that it will be useful, but
903+ * WITHOUT ANY WARRANTY; without even the implied warranties of
904+ * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
905+ * PURPOSE. See the GNU General Public License for more details.
906+ *
907+ * You should have received a copy of the GNU General Public License
908+ * version 3 along with this program. If not, see
909+ * <http://www.gnu.org/licenses/>
910+ *
911+ * Authored by: Marco Trevisan (Treviño) <marco.trevisan@canonical.com>
912+
913+ */
914+
915+#ifndef TEST_USCREEN_MOCK_H
916+#define TEST_USCREEN_MOCK_H
917+
918+#include "MultiMonitor.h"
919+#include "UScreen.h"
920+
921+namespace unity
922+{
923+
924+const unsigned MONITOR_WIDTH = 1024;
925+const unsigned MONITOR_HEIGHT = 768;
926+
927+class MockUScreen : public UScreen
928+{
929+public:
930+ MockUScreen()
931+ {
932+ Reset(false);
933+ }
934+
935+ ~MockUScreen()
936+ {
937+ if (default_screen_ == this)
938+ default_screen_ = nullptr;
939+ }
940+
941+ void Reset(bool emit = true)
942+ {
943+ default_screen_ = this;
944+ primary_ = 0;
945+ monitors_ = {nux::Geometry(0, 0, MONITOR_WIDTH, MONITOR_HEIGHT)};
946+
947+ changed.emit(primary_, monitors_);
948+ }
949+
950+ void SetupFakeMultiMonitor(int primary = 0, bool emit_update = true)
951+ {
952+ SetPrimary(primary, false);
953+ monitors_.clear();
954+
955+ for (int i = 0, total_width = 0; i < max_num_monitors; ++i)
956+ {
957+ monitors_.push_back(nux::Geometry(MONITOR_WIDTH, MONITOR_HEIGHT, total_width, 0));
958+ total_width += MONITOR_WIDTH;
959+
960+ if (emit_update)
961+ changed.emit(GetPrimaryMonitor(), GetMonitors());
962+ }
963+ }
964+
965+ void SetPrimary(int primary, bool emit = true)
966+ {
967+ if (primary_ != primary)
968+ {
969+ primary_ = primary;
970+
971+ if (emit)
972+ changed.emit(primary_, monitors_);
973+ }
974+ }
975+};
976+
977+}
978+
979+#endif
980\ No newline at end of file

Subscribers

People subscribed via source and target branches