Merge lp:~3v1n0/unity/launcher-dragwindow-ordering-rewrite into lp:unity

Proposed by Marco Trevisan (Treviño)
Status: Merged
Approved by: Brandon Schaefer
Approved revision: no longer in the source branch.
Merged at revision: 2644
Proposed branch: lp:~3v1n0/unity/launcher-dragwindow-ordering-rewrite
Merge into: lp:unity
Prerequisite: lp:~3v1n0/unity/launchers-setup-struts
Diff against target: 185 lines (+61/-59)
2 files modified
launcher/Launcher.cpp (+48/-53)
manual-tests/Launcher.txt (+13/-6)
To merge this branch: bzr merge lp:~3v1n0/unity/launcher-dragwindow-ordering-rewrite
Reviewer Review Type Date Requested Status
Brandon Schaefer (community) Approve
Review via email: mp+122166@code.launchpad.net

Commit message

Launcher: make always possible to drag an icon to the bottom or top of its sublist

It was not possible before to reorder application icons below the BFB or above the workspace switcher

Description of the change

The code to reorder icons when one was dragged was messy and bugged, so I've rewritten it to improve it and to fix some issues that made impossible (for example) to re-order an icon at the end or at the bottom of an icons sublist (i.e. a list of icons of the same type).

Manual tests updated.

To post a comment you must log in.
Revision history for this message
Brandon Schaefer (brandontschaefer) wrote :

Awesome, now works :).

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'launcher/Launcher.cpp'
2--- launcher/Launcher.cpp 2012-08-30 22:29:18 +0000
3+++ launcher/Launcher.cpp 2012-08-30 22:29:18 +0000
4@@ -2088,59 +2088,54 @@
5
6 void Launcher::UpdateDragWindowPosition(int x, int y)
7 {
8- if (_drag_window)
9- {
10- nux::Geometry const& geo = _drag_window->GetGeometry();
11- _drag_window->SetBaseXY(x - geo.width / 2, y - geo.height / 2);
12-
13- AbstractLauncherIcon::Ptr hovered_icon = MouseIconIntersection((int)((GetGeometry().x + GetGeometry().width) / 2.0f), y - GetAbsoluteGeometry().y);
14-
15- struct timespec current;
16- clock_gettime(CLOCK_MONOTONIC, &current);
17- if (_drag_icon && hovered_icon && _drag_icon != hovered_icon)
18- {
19- float progress = DragThresholdProgress(current);
20-
21- if (progress >= 1.0f)
22- _model->ReorderSmart(_drag_icon, hovered_icon, true);
23- else if (progress == 0.0f) {
24- if (_drag_icon->GetIconType() == hovered_icon->GetIconType()) {
25- _model->ReorderBefore(_drag_icon, hovered_icon, false);
26- } else {
27- // LauncherModel::ReorderBefore does not work on different icon types
28- // so if hovered_icon is of a different type than _drag_icon
29- // try to use LauncherModel::ReorderAfter with the icon that is before hovered_icon
30- AbstractLauncherIcon::Ptr iconBeforeHover;
31- LauncherModel::iterator it;
32- LauncherModel::iterator prevIt = _model->end();
33- for (it = _model->begin(); it != _model->end(); ++it)
34- {
35- if (!(*it)->GetQuirk(AbstractLauncherIcon::Quirk::VISIBLE) || !(*it)->IsVisibleOnMonitor(monitor))
36- continue;
37-
38- if ((*it) == hovered_icon) {
39- if (prevIt != _model->end()) {
40- iconBeforeHover = *prevIt;
41- }
42- break;
43- }
44-
45- prevIt = it;
46- }
47-
48- if (iconBeforeHover && _drag_icon != iconBeforeHover) {
49- _model->ReorderAfter(_drag_icon, iconBeforeHover);
50- }
51- }
52- }
53-
54- if (progress >= 1.0f)
55- {
56- _model->ReorderSmart(_drag_icon, hovered_icon, true);
57- }
58- else if (progress == 0.0f)
59- {
60- _model->ReorderBefore(_drag_icon, hovered_icon, false);
61+ if (!_drag_window)
62+ return;
63+
64+ auto const& icon_geo = _drag_window->GetGeometry();
65+ _drag_window->SetBaseXY(x - icon_geo.width / 2, y - icon_geo.height / 2);
66+
67+ if (!_drag_icon)
68+ return;
69+
70+ auto const& launcher_geo = GetGeometry();
71+ auto hovered_icon = MouseIconIntersection((launcher_geo.x + launcher_geo.width) / 2.0, y - GetAbsoluteY());
72+ struct timespec current;
73+ clock_gettime(CLOCK_MONOTONIC, &current);
74+ float progress = DragThresholdProgress(current);
75+
76+ // Icons of different types can't be mixed, so let's avoid this.
77+ if (hovered_icon && hovered_icon->GetIconType() != _drag_icon->GetIconType())
78+ hovered_icon = nullptr;
79+
80+ if (hovered_icon && _drag_icon != hovered_icon)
81+ {
82+ if (progress >= 1.0f)
83+ {
84+ _model->ReorderSmart(_drag_icon, hovered_icon, true);
85+ }
86+ else if (progress == 0.0f)
87+ {
88+ _model->ReorderBefore(_drag_icon, hovered_icon, false);
89+ }
90+ }
91+ else if (!hovered_icon && progress == 0.0f)
92+ {
93+ // If no icon is hovered, then we can add our icon to the bottom
94+ for (auto it = _model->main_rbegin(); it != _model->main_rend(); ++it)
95+ {
96+ auto const& icon = *it;
97+
98+ if (!icon->GetQuirk(AbstractLauncherIcon::Quirk::VISIBLE) ||
99+ !icon->IsVisibleOnMonitor(monitor) ||
100+ icon->GetIconType() != _drag_icon->GetIconType())
101+ {
102+ continue;
103+ }
104+
105+ if (y >= icon->GetCenter(monitor).y)
106+ {
107+ _model->ReorderAfter(_drag_icon, icon);
108+ break;
109 }
110 }
111 }
112
113=== modified file 'manual-tests/Launcher.txt'
114--- manual-tests/Launcher.txt 2012-08-21 17:50:55 +0000
115+++ manual-tests/Launcher.txt 2012-08-30 22:29:18 +0000
116@@ -124,6 +124,7 @@
117 launcher, and that the animation is smooth.
118
119 Setup:
120+#. Ensure that you have multiple applications running or pinned to the launcher
121
122 Actions:
123 #. Move mouse pointer over an application or device icon (not BFB, Workspace switcher or trash)
124@@ -142,6 +143,7 @@
125 This test is all position of the dragged image in relation to the mouse pointer.
126
127 Setup:
128+#. Ensure that you have multiple applications running or pinned to the launcher
129
130 Actions:
131 #. Move the mouse so it is over a launcher icon for an application
132@@ -160,6 +162,7 @@
133 of icons in the launcher.
134
135 Setup:
136+#. Ensure that you have multiple applications running or pinned to the launcher
137
138 Actions:
139 #. Move the mouse so it is over a launcher icon for an application
140@@ -167,13 +170,15 @@
141 #. Drag the icon up and down over the icons in the launcher
142
143 Expected Result:
144- * As the centre of the dragged icon passes the mid-point of the next item
145- above or below it, the icon being dragged over moves and is replaced by the
146- blank "space".
147+ * As the center of the dragged icon passes the mid-point of the next item
148+ above or below it, the icon being dragged over moves and is replaced by the
149+ blank "space".
150 * The animation should be smooth
151 * If the dragged icon is moved rapidly, multiple icons can be moving either
152- upwards or downwards as the space is moved into place under the dragged icon
153- * The BFB and the switcher icons do not move
154+ upwards or downwards as the space is moved into place under the dragged icon
155+ * Dragging the second application icon (the third icon of the launcher) below
156+ the BFB or above the workspace switcher should be possible.
157+ * The BFB and the workspace switcher icons do not move
158
159
160 Dragging icons to reorder - away from launcher
161@@ -181,6 +186,7 @@
162 This test is about reordering the icons without the animation showing.
163
164 Setup:
165+#. Ensure that you have multiple applications running or pinned to the launcher
166
167 Actions:
168 #. Move the mouse so it is over a launcher icon for an application
169@@ -193,7 +199,7 @@
170 * As the icon is dragged away from the launcher, the "space" is closed up
171 and replaced with a grey line.
172 * As the icon is dragged up and down, the line moves between other launcher
173- icons.
174+ icons of the same type.
175 * When released, the icon "flies" back into the launcher, a spaces opens for
176 it, and the any pips for running apps show again.
177
178@@ -203,6 +209,7 @@
179 This test ensures that the launcher icons out of the launcher are properly drawn
180
181 Setup:
182+#. Ensure that you have multiple applications running or pinned to the launcher
183
184 Actions:
185 #. Move the mouse so it is over a launcher icon for an application