After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 750446 - Desktop icon alignment `floor()`s instead of `round()` Edit
Desktop icon alignment `floor()`s instead of `round()` Edit
Status: RESOLVED FIXED
Product: nautilus
Classification: Core
Component: Desktop
unspecified
Other Linux
: Normal minor
: ---
Assigned To: Nautilus Maintainers
Nautilus Maintainers
Depends on:
Blocks:
 
 
Reported: 2015-06-05 09:28 UTC by Shahbaz
Modified: 2016-02-02 09:25 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
canvas-container: fix desktop snapping (1.71 KB, patch)
2016-02-01 08:47 UTC, Carlos Soriano
committed Details | Review

Description Shahbaz 2015-06-05 09:28:14 UTC
When dragging to arrange icons on the desktop, there is an invisible grid that the icons get snapped to. The x-axis has larger distance between grid lines and this bug is more visible in that direction.

Steps to reproduce:

1. Take an icon
2. Drag a few pixels to left
3. Release icon

Expected behavior:

- You are more or less still in the same position, so the icon should go back to where it was before dragging

Observed behavior:

- The icon jumps a long way to the left

You can recreate this with "one pixel up" as well, where the icon jumps up, although not as dramatically as with the x-axis. The behavior is the same regardless of the icon size.

I am reporting this as a bug, because it is highly annoying to move an icon to more or less where you want, only to find it jumps back. I think the correct behavior would be for the icon to snap to the closest grid lines, rather than the one on its left/up.

---

More information on Launchpad: https://bugs.launchpad.net/ubuntu/+source/nautilus/+bug/1462267

$ apt-cache policy nautilus
nautilus:
  Installed: 1:3.10.1-0ubuntu9.8
  Candidate: 1:3.10.1-0ubuntu9.8
  Version table:
 *** 1:3.10.1-0ubuntu9.8 0
        500 http://us.archive.ubuntu.com/ubuntu/ trusty-updates/main i386 Packages
        100 /var/lib/dpkg/status
     1:3.10.1-0ubuntu8 0
        500 http://us.archive.ubuntu.com/ubuntu/ trusty/main i386 Packages
Comment 1 Carlos Soriano 2015-06-05 09:38:23 UTC
If you want fine graining positioning you can uncheck the "Keep aligned" option. that allows you to position wherever you want.
Comment 2 Shahbaz 2015-06-05 09:41:18 UTC
I do want the alignment. But the alignment should snap to the *closest* corner, not the one that is on its left/up no matter how far it is.
Comment 3 Carlos Soriano 2015-06-05 09:46:37 UTC
Then I'm not sure I can reproduce it. For me it's working as expected I guess, you drag, and it snaps to the closest grid point.
Can you make a video or something?
Comment 4 Shahbaz 2015-06-05 09:52:28 UTC
Could it be an Ubuntu thing? I'll try to make a video and report back with the link.
Comment 5 Shahbaz 2015-06-05 09:53:12 UTC
Just to be sure, drag a bit to the **left** to see if it still snaps to the closest grid point (which is on the right).
Comment 6 Carlos Soriano 2015-06-05 09:56:12 UTC
(In reply to Shahbaz from comment #5)
> Just to be sure, drag a bit to the **left** to see if it still snaps to the
> closest grid point (which is on the right).

Ah! Got it now.
Comment 7 Carlos Soriano 2015-06-05 09:56:20 UTC
(In reply to Shahbaz from comment #5)
> Just to be sure, drag a bit to the **left** to see if it still snaps to the
> closest grid point (which is on the right).

Ah! Got it now.
Comment 8 Shahbaz 2015-06-05 11:10:16 UTC
Cool, that saves me the trouble of making the video.
Comment 9 Shahbaz 2016-02-01 02:24:03 UTC
7 months later, and I still observe this behavior in Ubuntu 15.10. Is this being addressed at all? I imagine the fix should be very simple.
Comment 10 Shahbaz 2016-02-01 03:07:45 UTC
I'm not familiar with the code, but taking a look at (for the first time), I see the following error:

In libnautilus-private/nautilus-canvas-container.c you have:

    #define SNAP_HORIZONTAL(func,x) ((func ((double)((x) - DESKTOP_PAD_HORIZONTAL) / SNAP_SIZE_X) * SNAP_SIZE_X) + DESKTOP_PAD_HORIZONTAL)
    #define SNAP_VERTICAL(func, y) ((func ((double)((y) - DESKTOP_PAD_VERTICAL) / SNAP_SIZE_Y) * SNAP_SIZE_Y) + DESKTOP_PAD_VERTICAL)

    #define SNAP_NEAREST_HORIZONTAL(x) SNAP_HORIZONTAL (floor, x + .5)
    #define SNAP_NEAREST_VERTICAL(y) SNAP_VERTICAL (floor, y + .5)

And it looks like `floor()` with `x + .5` is intended to give a `round()` effect (in `SNAP_NEAREST_HORIZONTAL`). However, `x` is divided by `SNAP_SIZE_X` before getting `floor()`ed, so the `.5` has really little effect on the end result. Same thing with `y`. The correct thing to do would have been:

    #define SNAP_NEAREST_HORIZONTAL(x) SNAP_HORIZONTAL (floor, x + SNAP_SIZE_X / 2)
    #define SNAP_NEAREST_VERTICAL(y) SNAP_VERTICAL (floor, y + SNAP_SIZE_Y / 2)
Comment 11 Carlos Soriano 2016-02-01 08:47:15 UTC
Created attachment 320169 [details] [review]
canvas-container: fix desktop snapping

To snap an icon to the closest grid cell, we were trying to round
the x position with an offset of 0.5. However, cells are not
normalized, so that 0.5 is actually doing little to round the
position.

This is making the icons to snap to the right closest cell once the
user drags more the icon left to the current cell.

The actual size of the cell is SNAP_SIZE_*, so to fix this use half
of the SNAP_SIZE to "round" the number.
Comment 12 Carlos Soriano 2016-02-01 08:51:41 UTC
Attachment 320169 [details] pushed as 984438f - canvas-container: fix desktop snapping
Comment 13 Shahbaz 2016-02-01 16:06:33 UTC
Awesome!
Comment 14 Carlos Soriano 2016-02-02 09:25:02 UTC
thanks for digging into the code.

You will need to update to 3.18 to have it. Probably that means ubuntu 16.10 if I'm not mistaken.