GNOME Bugzilla – Bug 750446
Desktop icon alignment `floor()`s instead of `round()` Edit
Last modified: 2016-02-02 09:25:02 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
If you want fine graining positioning you can uncheck the "Keep aligned" option. that allows you to position wherever you want.
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.
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?
Could it be an Ubuntu thing? I'll try to make a video and report back with the link.
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).
(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.
Cool, that saves me the trouble of making the video.
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.
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)
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.
Attachment 320169 [details] pushed as 984438f - canvas-container: fix desktop snapping
Awesome!
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.