Merge lp:~3v1n0/unity/launcher-primary-monitor 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: 2154
Proposed branch: lp:~3v1n0/unity/launcher-primary-monitor
Merge into: lp:unity
Diff against target: 144 lines (+62/-22)
2 files modified
manual-tests/Launcher.txt (+19/-0)
plugins/unityshell/src/LauncherController.cpp (+43/-22)
To merge this branch: bzr merge lp:~3v1n0/unity/launcher-primary-monitor
Reviewer Review Type Date Requested Status
Andrea Azzarone (community) Approve
Review via email: mp+98681@code.launchpad.net

Commit message

LauncherController: show a launcher in the primary monitor if set

This ensures that the launcher is shown only on the primary one, not on the one at the left.

Description of the change

Make the Launcher controller be aware of the primary monitor.
This ensures that the launcher is shown only on the primary one.

Added a manual test for now, AP tests are already done, but needs to be polished.
I'll merge them soon.

18:03:18 <didrocks> just propose the branch with a manual test :)
18:03:30 <didrocks> for now
18:03:34 <didrocks> and automate later
18:06:15 <didrocks> tell in the MR that you discussed it with me
18:06:20 <didrocks> and UNBLOCK

;)

To post a comment you must log in.
Revision history for this message
Andrea Azzarone (azzar1) wrote :

Looks good to me!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'manual-tests/Launcher.txt'
2--- manual-tests/Launcher.txt 2012-03-21 12:31:11 +0000
3+++ manual-tests/Launcher.txt 2012-03-21 19:52:23 +0000
4@@ -169,3 +169,22 @@
5
6 Outcome:
7 * The icon should go back to its correct position in the launcher.
8+
9+
10+Test launchers with multiple monitors
11+-------------------------------------
12+This test checks if the launchers are shown in the correct monitor when
13+using a multimonitor setup.
14+
15+#. Open CCSM and and set the Experimental -> "Launcher Monitors" unity setting
16+ to "All Desktops"
17+
18+Outcome:
19+ * A launcher should be shown in each monitor.
20+
21+#. Open CCSM and and set the Experimental -> "Launcher Monitors" unity setting
22+ to "Primary Desktop"
23+
24+Outcome:
25+ * Only the primary monitor should show a launcher. Changing the primary monitor
26+ from gnome-control-center -> Monitor should update the launcher position.
27
28=== modified file 'plugins/unityshell/src/LauncherController.cpp'
29--- plugins/unityshell/src/LauncherController.cpp 2012-03-21 14:44:41 +0000
30+++ plugins/unityshell/src/LauncherController.cpp 2012-03-21 19:52:23 +0000
31@@ -118,7 +118,7 @@
32
33 void SetupBamf();
34
35- void EnsureLaunchers(std::vector<nux::Geometry> const& monitors);
36+ void EnsureLaunchers(int primary, std::vector<nux::Geometry> const& monitors);
37
38 void OnExpoActivated();
39
40@@ -188,6 +188,7 @@
41 {
42 UScreen* uscreen = UScreen::GetDefault();
43 auto monitors = uscreen->GetMonitors();
44+ int primary = uscreen->GetPrimaryMonitor();
45
46 launcher_open = false;
47 launcher_keynav = false;
48@@ -195,7 +196,7 @@
49 reactivate_keynav = false;
50 keynav_restore_window_ = true;
51
52- EnsureLaunchers(monitors);
53+ EnsureLaunchers(primary, monitors);
54
55 launcher_ = launchers[0];
56
57@@ -279,39 +280,58 @@
58 delete device_section_;
59 }
60
61-void Controller::Impl::EnsureLaunchers(std::vector<nux::Geometry> const& monitors)
62+void Controller::Impl::EnsureLaunchers(int primary, std::vector<nux::Geometry> const& monitors)
63 {
64- unsigned int num_monitors;
65- if (parent_->multiple_launchers)
66+ unsigned int num_monitors = monitors.size();
67+ unsigned int num_launchers = parent_->multiple_launchers ? num_monitors : 1;
68+ unsigned int launchers_size = launchers.size();
69+ unsigned int last_monitor = 0;
70+
71+ if (num_launchers == 1)
72 {
73- num_monitors = monitors.size();
74+ if (launchers_size == 0)
75+ {
76+ launchers.push_back(nux::ObjectPtr<Launcher>(CreateLauncher(primary)));
77+ }
78+ else if (!launchers[0].IsValid())
79+ {
80+ launchers[0] = nux::ObjectPtr<Launcher>(CreateLauncher(primary));
81+ }
82+
83+ launchers[0]->monitor(primary);
84+ launchers[0]->Resize();
85+ last_monitor = 1;
86 }
87 else
88 {
89- num_monitors = 1;
90- }
91-
92- unsigned int i;
93- for (i = 0; i < num_monitors; i++)
94- {
95- if (i >= launchers.size())
96- launchers.push_back(nux::ObjectPtr<Launcher> (CreateLauncher(i)));
97-
98- launchers[i]->Resize();
99- }
100-
101- for (; i < launchers.size(); ++i)
102+ for (unsigned int i = 0; i < num_monitors; i++, last_monitor++)
103+ {
104+ if (i >= launchers_size)
105+ {
106+ launchers.push_back(nux::ObjectPtr<Launcher>(CreateLauncher(i)));
107+ }
108+
109+ launchers[i]->monitor(i);
110+ launchers[i]->Resize();
111+ }
112+ }
113+
114+ for (unsigned int i = last_monitor; i < launchers_size; ++i)
115 {
116 auto launcher = launchers[i];
117 if (launcher.IsValid())
118+ {
119+ parent_->RemoveChild(launcher.GetPointer());
120 launcher->GetParent()->UnReference();
121+ }
122 }
123- launchers.resize(num_monitors);
124+
125+ launchers.resize(num_launchers);
126 }
127
128 void Controller::Impl::OnScreenChanged(int primary_monitor, std::vector<nux::Geometry>& monitors)
129 {
130- EnsureLaunchers(monitors);
131+ EnsureLaunchers(primary_monitor, monitors);
132 }
133
134 void Controller::Impl::OnWindowFocusChanged (guint32 xid)
135@@ -803,7 +823,8 @@
136 multiple_launchers.changed.connect([&](bool value) -> void {
137 UScreen* uscreen = UScreen::GetDefault();
138 auto monitors = uscreen->GetMonitors();
139- pimpl->EnsureLaunchers(monitors);
140+ int primary = uscreen->GetPrimaryMonitor();
141+ pimpl->EnsureLaunchers(primary, monitors);
142 options()->show_for_all = !value;
143 });
144 }