Merge lp:~sil2100/unity/fix_draging_last_position_out_of_launcher_5.0 into lp:unity/5.0

Proposed by Łukasz Zemczak
Status: Merged
Approved by: Marco Trevisan (Treviño)
Approved revision: no longer in the source branch.
Merged at revision: 2365
Proposed branch: lp:~sil2100/unity/fix_draging_last_position_out_of_launcher_5.0
Merge into: lp:unity/5.0
Diff against target: 227 lines (+164/-2)
3 files modified
plugins/unityshell/src/Launcher.cpp (+30/-2)
tests/autopilot/autopilot/emulators/unity/launcher.py (+78/-0)
tests/autopilot/autopilot/tests/test_launcher.py (+56/-0)
To merge this branch: bzr merge lp:~sil2100/unity/fix_draging_last_position_out_of_launcher_5.0
Reviewer Review Type Date Requested Status
Marco Trevisan (Treviño) Approve
Review via email: mp+110855@code.launchpad.net

Commit message

Cherry-picked from unity trunk (rev2407):
Launcher: Fix dragging to the last position when out of the launcher

Description of the change

Cherry-picked from upstream. Original description:

Launcher: Fix dragging to the last position when out of the launcher

Without this patch there is the following bug:
 * Have a launcher with free space under the workspace switcher
 * Start dragging a tile from the launcher
 * Move it outside (to the right) of the launcher
 * See how a horizontal bar shows where the icon will land once you release the mouse button
 * Move the mouse down so the horizontal bar should go just before the worspace switcher
 * See that it doesn't go there, it keeps itself one icon before that

With this patch this behaviour is fixed

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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'plugins/unityshell/src/Launcher.cpp'
--- plugins/unityshell/src/Launcher.cpp 2012-06-06 09:25:29 +0000
+++ plugins/unityshell/src/Launcher.cpp 2012-06-18 16:32:24 +0000
@@ -2272,8 +2272,36 @@
22722272
2273 if (progress >= 1.0f)2273 if (progress >= 1.0f)
2274 _model->ReorderSmart(_drag_icon, hovered_icon, true);2274 _model->ReorderSmart(_drag_icon, hovered_icon, true);
2275 else if (progress == 0.0f)2275 else if (progress == 0.0f) {
2276 _model->ReorderBefore(_drag_icon, hovered_icon, false);2276 if (_drag_icon->GetIconType() == hovered_icon->GetIconType()) {
2277 _model->ReorderBefore(_drag_icon, hovered_icon, false);
2278 } else {
2279 // LauncherModel::ReorderBefore does not work on different icon types
2280 // so if hovered_icon is of a different type than _drag_icon
2281 // try to use LauncherModel::ReorderAfter with the icon that is before hovered_icon
2282 AbstractLauncherIcon::Ptr iconBeforeHover;
2283 LauncherModel::iterator it;
2284 LauncherModel::iterator prevIt = _model->end();
2285 for (it = _model->begin(); it != _model->end(); it++)
2286 {
2287 if (!(*it)->GetQuirk(AbstractLauncherIcon::QUIRK_VISIBLE) || !(*it)->IsVisibleOnMonitor(monitor))
2288 continue;
2289
2290 if ((*it) == hovered_icon) {
2291 if (prevIt != _model->end()) {
2292 iconBeforeHover = *prevIt;
2293 }
2294 break;
2295 }
2296
2297 prevIt = it;
2298 }
2299
2300 if (iconBeforeHover && _drag_icon != iconBeforeHover) {
2301 _model->ReorderAfter(_drag_icon, iconBeforeHover);
2302 }
2303 }
2304 }
2277 }2305 }
2278 }2306 }
2279}2307}
22802308
=== modified file 'tests/autopilot/autopilot/emulators/unity/launcher.py'
--- tests/autopilot/autopilot/emulators/unity/launcher.py 2012-05-21 15:29:34 +0000
+++ tests/autopilot/autopilot/emulators/unity/launcher.py 2012-06-18 16:32:24 +0000
@@ -7,8 +7,10 @@
7# by the Free Software Foundation.7# by the Free Software Foundation.
8#8#
99
10from autopilot.utilities import get_compiz_option
10import dbus11import dbus
11import logging12import logging
13from math import floor
12from testtools.matchers import NotEquals14from testtools.matchers import NotEquals
13from time import sleep15from time import sleep
1416
@@ -22,6 +24,12 @@
22logger = logging.getLogger(__name__)24logger = logging.getLogger(__name__)
2325
2426
27class IconDragType:
28 """Define possible positions to drag an icon onto another"""
29 INSIDE = 0
30 OUTSIDE = 1
31
32
25class LauncherController(UnityIntrospectionObject):33class LauncherController(UnityIntrospectionObject):
26 """The LauncherController class."""34 """The LauncherController class."""
2735
@@ -116,6 +124,16 @@
116 logger.debug("Moving mouse to center of launcher.")124 logger.debug("Moving mouse to center of launcher.")
117 self._mouse.move(target_x, target_y)125 self._mouse.move(target_x, target_y)
118126
127 def move_mouse_to_icon(self, icon):
128 # The icon may be off the bottom of screen, so we do this in a loop:
129 while 1:
130 target_x = icon.center_x + self.x
131 target_y = icon.center_y
132 if self._mouse.x == target_x and self._mouse.y == target_y:
133 break
134 self._mouse.move(target_x, target_y)
135 sleep(0.5)
136
119 def mouse_reveal_launcher(self):137 def mouse_reveal_launcher(self):
120 """Reveal this launcher with the mouse."""138 """Reveal this launcher with the mouse."""
121 self._screen.move_mouse_to_monitor(self.monitor)139 self._screen.move_mouse_to_monitor(self.monitor)
@@ -246,6 +264,66 @@
246 self._mouse.click(button)264 self._mouse.click(button)
247 self.move_mouse_to_right_of_launcher()265 self.move_mouse_to_right_of_launcher()
248266
267 def drag_icon_to_position(self, icon, pos, drag_type=IconDragType.INSIDE):
268 """Place the supplied icon above the icon in the position pos.
269
270 The icon is dragged inside or outside the launcher.
271
272 >>> drag_icon_to_position(calc_icon, 0, IconDragType.INSIDE)
273
274 This will drag the calculator icon above the bfb (but as you can't go
275 above the bfb it will move below it (to position 1))
276
277 """
278 if not isinstance(icon, BamfLauncherIcon):
279 raise TypeError("icon must be a LauncherIcon")
280
281 [launcher_model] = LauncherModel.get_all_instances()
282 all_icons = launcher_model.get_launcher_icons()
283 all_icon_len = len(all_icons)
284 if pos >= all_icon_len:
285 raise ValueError("pos is outside valid range (0-%d)" % all_icon_len)
286
287 logger.debug("Dragging launcher icon %r on monitor %d to position %s"
288 % (icon, self.monitor, pos))
289 self.mouse_reveal_launcher()
290
291 icon_height = get_compiz_option("unityshell", "icon_size")
292
293 target_icon = all_icons[pos]
294 if target_icon.id == icon.id:
295 logger.warning("%s is already the icon in position %d. Nothing to do." % (icon, pos))
296 return
297
298 self.move_mouse_to_icon(icon)
299 self._mouse.press()
300 sleep(2)
301
302 if drag_type == IconDragType.OUTSIDE:
303 shift_over = self._mouse.x + (icon_height * 2)
304 self._mouse.move(shift_over, self._mouse.y)
305 sleep(0.5)
306
307 # find the target drop position, between the center & top of the target icon
308 target_y = target_icon.center_y - floor(icon_height / 4)
309
310 # Need to move the icons top (if moving up) or bottom (if moving
311 # downward) to the target position
312 moving_up = True if icon.center_y > target_icon.center_y else False
313 icon_half_height = floor(icon_height / 2)
314 fudge_factor = 5
315 if moving_up or drag_type == IconDragType.OUTSIDE:
316 target_y += icon_half_height + fudge_factor
317 else:
318 target_y -= icon_half_height - fudge_factor
319
320 self._mouse.move(self._mouse.x, target_y, rate=20,
321 time_between_events=0.05)
322 sleep(1)
323
324 self._mouse.release()
325 self.move_mouse_to_right_of_launcher()
326
249 def lock_to_launcher(self, icon):327 def lock_to_launcher(self, icon):
250 """lock 'icon' to the launcher, if it's not already.328 """lock 'icon' to the launcher, if it's not already.
251 `icon` must be an instance of BamfLauncherIcon.329 `icon` must be an instance of BamfLauncherIcon.
252330
=== modified file 'tests/autopilot/autopilot/tests/test_launcher.py'
--- tests/autopilot/autopilot/tests/test_launcher.py 2012-05-23 12:13:10 +0000
+++ tests/autopilot/autopilot/tests/test_launcher.py 2012-06-18 16:32:24 +0000
@@ -18,6 +18,7 @@
18from autopilot.emulators.X11 import ScreenGeometry18from autopilot.emulators.X11 import ScreenGeometry
19from autopilot.matchers import Eventually19from autopilot.matchers import Eventually
20from autopilot.tests import AutopilotTestCase, multiply_scenarios20from autopilot.tests import AutopilotTestCase, multiply_scenarios
21from unity.emulators.launcher import IconDragType
2122
22logger = logging.getLogger(__name__)23logger = logging.getLogger(__name__)
2324
@@ -460,6 +461,61 @@
460 self.assertThat(calc_icon, NotEquals(None))461 self.assertThat(calc_icon, NotEquals(None))
461 self.assertThat(calc_icon.visible, Eventually(Equals(True)))462 self.assertThat(calc_icon.visible, Eventually(Equals(True)))
462463
464class LauncherDragIconsBehavior(LauncherTestCase):
465 """Tests interation with dragging icons with the Launcher"""
466
467 scenarios = multiply_scenarios(_make_scenarios(),
468 [
469 ('inside', {'drag_type': IconDragType.INSIDE}),
470 ('outside', {'drag_type': IconDragType.OUTSIDE}),
471 ])
472
473 def ensure_calc_icon_not_in_launcher(self):
474 while 1:
475 icon = self.launcher.model.get_icon_by_desktop_id("gcalctool.desktop")
476 if not icon:
477 break
478 sleep(1)
479
480 def test_can_drag_icon_below_bfb(self):
481 """Application icons must be draggable to below the BFB."""
482
483 self.ensure_calc_icon_not_in_launcher()
484 calc = self.start_app("Calculator")
485 calc_icon = self.launcher.model.get_icon_by_desktop_id(calc.desktop_file)
486
487 bfb_icon_position = 0
488 self.launcher_instance.drag_icon_to_position(calc_icon,
489 bfb_icon_position,
490 self.drag_type)
491 moved_icon = self.launcher.model.\
492 get_launcher_icons_for_monitor(self.launcher_monitor)[1]
493 self.assertThat(moved_icon.id, Equals(calc_icon.id))
494
495 def test_can_drag_icon_above_window_switcher(self):
496 """Launcher icons must be dragable to above the workspace switcher icon."""
497
498 self.ensure_calc_icon_not_in_launcher()
499 calc = self.start_app("Calculator")
500 calc_icon = self.launcher.model.get_icon_by_desktop_id(calc.desktop_file)
501
502 # Move a known icon to the top as it needs to be more than 2 icon
503 # spaces away for this test to actually do anything
504 bfb_icon_position = 0
505 self.launcher_instance.drag_icon_to_position(calc_icon,
506 bfb_icon_position,
507 self.drag_type)
508 sleep(1)
509 switcher_pos = -2
510 self.launcher_instance.drag_icon_to_position(calc_icon,
511 switcher_pos,
512 self.drag_type)
513
514 moved_icon = self.launcher.model.\
515 get_launcher_icons_for_monitor(self.launcher_monitor)[-3]
516 self.assertThat(moved_icon.id, Equals(calc_icon.id))
517
518
463class LauncherRevealTests(LauncherTestCase):519class LauncherRevealTests(LauncherTestCase):
464 """Test the launcher reveal behavior when in autohide mode."""520 """Test the launcher reveal behavior when in autohide mode."""
465521

Subscribers

People subscribed via source and target branches

to all changes: