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 765601 - icons overlapping on desktop's left upper corner
icons overlapping on desktop's left upper corner
Status: RESOLVED FIXED
Product: nautilus
Classification: Core
Component: Desktop
3.18.x
Other All
: Normal major
: ---
Assigned To: Nautilus Maintainers
Nautilus Maintainers
Depends on:
Blocks:
 
 
Reported: 2016-04-26 12:31 UTC by Angelescu Ovidiu
Modified: 2016-10-07 17:52 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
bad placed icons under linux (301.95 KB, image/png)
2016-04-26 12:31 UTC, Angelescu Ovidiu
  Details
Patch for discussion - this seems to sufficiently work around the issue for us (1.19 KB, patch)
2016-08-31 09:25 UTC, Dominique Leuenberger
none Details | Review
nautilus-canvas: Don't lay down desktop icons if we haven't been allocated size yet (5.37 KB, patch)
2016-10-07 13:01 UTC, Iain Lane
needs-work Details | Review
Now with some missing style and code fixes (5.46 KB, patch)
2016-10-07 13:10 UTC, Iain Lane
none Details | Review
Latest version - directly skip code if we haven't been allocated. (3.03 KB, patch)
2016-10-07 17:07 UTC, Iain Lane
none Details | Review
Thanks for the reviews, here's the latest version (3.66 KB, patch)
2016-10-07 17:35 UTC, Iain Lane
reviewed Details | Review
...and the version for gnome-3-20 (3.36 KB, patch)
2016-10-07 17:35 UTC, Iain Lane
none Details | Review
nautilus-canvas: Don't lay down desktop icons if we haven't been allocated size yet (3.67 KB, patch)
2016-10-07 17:43 UTC, Carlos Soriano
none Details | Review
nautilus-canvas: Don't lay down desktop icons if we haven't been allocated size yet (3.36 KB, patch)
2016-10-07 17:50 UTC, Carlos Soriano
committed Details | Review

Description Angelescu Ovidiu 2016-04-26 12:31:09 UTC
Created attachment 326751 [details]
bad placed icons under linux

Dear maintainer
I have installed gnome-3.18.2 under freebsd-10.3 and under debian sid.
In both cases I have noticed that when desktop-icons are showned those are overlapping in desktop's left top screen.
If I have arranged them by name from desktop icons position's are ok.
I have noticed also that under user's home ./config/nautilus/desktop-metadata
has changed between those two cases. 

When icons positions were ok desktop-metadata content was
[directory]
nautilus-icon-view-keep-aligned=true
nautilus-desktop-icon-size=64
nautilus-icon-view-layout-timestamp=1461653360

[trash]
nautilus-icon-position=40,714
icon-scale=1
nautilus-icon-position-timestamp=1461653360

[home]
nautilus-icon-position=40,14
icon-scale=1
nautilus-icon-position-timestamp=1461653360

When icons posistions were not ok all icons-positions were set to 40,0
something like:
[directory]
nautilus-icon-view-keep-aligned=true
nautilus-desktop-icon-size=64
nautilus-icon-view-layout-timestamp=1461653360

[trash]
nautilus-icon-position=40,0
icon-scale=1
nautilus-icon-position-timestamp=1461653360

[home]
nautilus-icon-position=40,0
icon-scale=1
nautilus-icon-position-timestamp=1461653360

Adding a good desktop-metadata file under ./config/nautilus dir leads to correct icons positions.

Bad icons position image under linux is in first attachement.
Same behaviour is under freebsd too for gnome-3.18.
Comment 1 Angelescu Ovidiu 2016-04-26 12:34:03 UTC
In both cases gvfs version implied is 1.26.X
Comment 2 Angelescu Ovidiu 2016-04-26 12:34:38 UTC
Both cases means in freebsd and in linux
Comment 3 Ondrej Holy 2016-04-26 12:53:11 UTC
Thanks for your bugreport though I don't think this is related to GVfs - reassigning to Nautilus.
Comment 4 Angelescu Ovidiu 2016-04-26 18:06:11 UTC
As I searched on internet icons positions are stored as gvfs metadata.
http://askubuntu.com/questions/573348/desktop-icon-position-programmatically-access-and-manipulate
I don't know more but I will try to test if it's really gvfs related.
Thank you.
Comment 5 Ondrej Holy 2016-04-27 06:48:37 UTC
Positions for some special files are obviously stored in some custom nautilus database in ./config/nautilus/desktop-metadata. But you are right that positions for regular files are stored in gvfs metadata databases. However metadata database is only storage, I suppose that wrong positions are written by nautilus, which I suppose is responsible for placing...

Are the positions wrong after you restart the computer if you arrange them before?
Comment 6 Ondrej Holy 2016-04-27 06:50:11 UTC
(In reply to Ondrej Holy from comment #5)
> Positions for some special files are obviously stored in some custom
> nautilus database in ./config/nautilus/desktop-metadata. But you are right
> that positions for regular files are stored in gvfs metadata databases.
> However metadata database is only storage, I suppose that wrong positions
> are written by nautilus, which I suppose is responsible for placing...
> 
> Are the positions wrong after you restart the computer if you arrange them
> before?

Or it happens only for first time?
Comment 7 Angelescu Ovidiu 2016-04-29 15:24:01 UTC
If I arrange them positions are ok after logout and relogin.
Comment 8 Carlos Soriano 2016-05-02 07:02:43 UTC
Do you have the "keep aligned" option marked in the right click context menu?
Comment 9 Angelescu Ovidiu 2016-05-03 12:33:41 UTC
Yes,
Keep aligned was marked when icons overlapped.
After unmark it and mark again there positioned ok.
Comment 10 Dominique Leuenberger 2016-08-31 09:25:29 UTC
Created attachment 334511 [details] [review]
Patch for discussion - this seems to sufficiently work around the issue for us
Comment 11 Carlos Soriano 2016-09-01 08:13:29 UTC
Review of attachment 334511 [details] [review]:

::: nautilus-3.21.91.orig/src/nautilus-canvas-container.c
@@ +2041,3 @@
                 /* Check and see if we need to move to a new column */
+                if (y != DESKTOP_PAD_VERTICAL && y + icon_height_for_bound_check > height &&
+                    height > 0 && total > 3)

I'm still unsure about the general code here, so forgive my questions. Why this 3?
Comment 12 Dominique Leuenberger 2016-09-01 08:18:16 UTC
@ZhaoQiang: as the patch originated from you ( to my info ), can you please reply to Carlos?
Comment 13 Zhao Qiang 2016-09-01 09:42:24 UTC
(In reply to Carlos Soriano from comment #11)
> Review of attachment 334511 [details] [review] [review]:
> 
> ::: nautilus-3.21.91.orig/src/nautilus-canvas-container.c
> @@ +2041,3 @@
>                  /* Check and see if we need to move to a new column */
> +                if (y != DESKTOP_PAD_VERTICAL && y +
> icon_height_for_bound_check > height &&
> +                    height > 0 && total > 3)
> 
> I'm still unsure about the general code here, so forgive my questions. Why
> this 3?

Hi Carlos:

In fact, I'm working to make the soluiton more generic now.
:)

"Total" ver here is nautilus desktop icon numbers.
I use it to judge if the system is in first time boot to gnome desktop.

This bug is caused of in this moment, current user don't have $HOME/.config/nautilus/desktop-metadata. nautilus have to detact the screen and do a auto arrange for all icons,
but it do a wrong move to new icon arrange column.

Main linux distributions don't have more than 3 icons in desktop, It can cover 90% of the scene. and I test it's really works. So, I set it.
Comment 14 Iain Lane 2016-10-06 17:03:07 UTC
Alright, I've been debugging this, since we see it on Ubuntu.

I figured out that when this happens, 'height' is 1, instead of the actual height of the desktop. That messes up all of the following calculations.

It's because, in the incorrect case, the size hasn't been allocated yet. There's a race condition going on - I don't see the bug every time.

I didn't test this yet, but I wonder if returning from lay_down_icons_vertical_desktop if (!container->details->has_been_allocated) would work?
Comment 15 Carlos Soriano 2016-10-06 18:25:54 UTC
(In reply to Iain Lane from comment #14)
> Alright, I've been debugging this, since we see it on Ubuntu.
> 
> I figured out that when this happens, 'height' is 1, instead of the actual
> height of the desktop. That messes up all of the following calculations.
> 
> It's because, in the incorrect case, the size hasn't been allocated yet.
> There's a race condition going on - I don't see the bug every time.
> 
> I didn't test this yet, but I wonder if returning from
> lay_down_icons_vertical_desktop if (!container->details->has_been_allocated)
> would work?

Do you mean the actual desktop window height is 1? We set the window height in nautilus_desktop_window_new, is that incorrect for you?
Comment 16 Iain Lane 2016-10-07 13:01:22 UTC
Created attachment 337164 [details] [review]
nautilus-canvas: Don't lay down desktop icons if we haven't been allocated size yet

Sometimes we were trying to lay down icons before size_allocate had been
run. When this has happened, gtk_widget_get_allocation returns 1×1 as
our size. This messes up the algorithm and causes icons to be
overlapping on the canvas.

We fix this by noticing if we're called before size_allocate and then
deferring icon layout until later on, after size_allocate has happened.

https://bugs.launchpad.net/ubuntu/+source/nautilus/+bug/1611955
Comment 17 Iain Lane 2016-10-07 13:10:44 UTC
Created attachment 337166 [details] [review]
Now with some missing style and code fixes
Comment 18 Carlos Soriano 2016-10-07 15:07:58 UTC
Review of attachment 337164 [details] [review]:

I believe your code is actually the right solution.
Doing this upper in the stack, in the desktop-canvas-view as I proposed, means the parent needs to know whether the child is allocated or not for "just sorting the icons", which is the responsibility of the canvas-container.
So let's review this code:

::: src/nautilus-canvas-container.c
@@ +141,3 @@
+    GList *icons;
+    double start_y;
+} SizeAllocateUserData;

I'm fine having this in the priv

@@ +1441,3 @@
 
+    /* We can't get the right allocation if the size hasn't been allocated yet */
+    g_assert (container->details->has_been_allocated);

don't crash nautilus because the icons are wrong, instead g_warning.

@@ +1950,3 @@
 
+    /* We can't get the right allocation if the size hasn't been allocated yet */
+    g_assert (container->details->has_been_allocated);

ditto

@@ +2141,3 @@
 
+static void
+canvas_container_size_allocate_callback (GtkWidget     *widget,

we already have a handler for size_allocate, use that one.

@@ +2165,3 @@
                 double                   start_y)
 {
+    if (!container->details->has_been_allocated)

although this is the function that makes nautilus crash, we can go a little upper in the call stack, since this shouldn't have been reached already.
So let's move this check with a comment to nautilus_canvas_container_sort?
The comment can be along the lines of:
"The clients of the container could want to reorganize the icons when the canvas is not allocated yet. This is the case of the desktop canvas view, where it might reorder the icons when it finish loading all the files"

Then instead of connecting to any signal, you actually have a "needs_resort" in the private data. And actually, container_sort just redoes the layout with that set.

So I think it will work just skipping the redo_layout in container_sort if !has_been_allocated because it will be resorted in the redo_layout in the next size_allocate.

This will make the code much simpler and clearer.
Comment 19 Iain Lane 2016-10-07 17:07:28 UTC
Created attachment 337183 [details] [review]
Latest version - directly skip code if we haven't been allocated.

This is all called later on when the icons are laid out.
Comment 20 Carlos Soriano 2016-10-07 17:20:00 UTC
Review of attachment 337183 [details] [review]:

Can you point to e0081be7cd in the commit message?
Can you explain that this mostly happens in sessions that uses the desktop when starting the session, which easily triggers not having allocation but having all the files read already?

::: src/nautilus-canvas-container.c
@@ +7847,3 @@
     NautilusCanvasPosition position;
 
+    if (!container->details->has_been_allocated)

can you add a comment here along the lines of:
"the container will freeze the icons when allocated, since that calls freeze_icon once it does the relayout. This avoids freezing icons that needs re-position when the allocation is still not done, in order to avoid a wrong position for the icons"
Comment 21 Iain Lane 2016-10-07 17:35:02 UTC
Created attachment 337184 [details] [review]
Thanks for the reviews, here's the latest version
Comment 22 Iain Lane 2016-10-07 17:35:28 UTC
Created attachment 337185 [details] [review]
...and the version for gnome-3-20
Comment 23 Carlos Soriano 2016-10-07 17:38:31 UTC
Review of attachment 337184 [details] [review]:

Excellent patch, I think there is a typo, feel free to commit with that fixed:

::: src/nautilus-canvas-container.c
@@ +7849,3 @@
 
+    /* This early-exit avoids freezing the icons before they have been properly
+     * positioned, since we won't re-layout if auto_layout is TRUE.

FALSE you mean?
Comment 24 Iain Lane 2016-10-07 17:40:00 UTC
(In reply to Carlos Soriano from comment #23)
> Review of attachment 337184 [details] [review] [review]:
> 
> Excellent patch, I think there is a typo, feel free to commit with that
> fixed:
> 
> ::: src/nautilus-canvas-container.c
> @@ +7849,3 @@
>  
> +    /* This early-exit avoids freezing the icons before they have been
> properly
> +     * positioned, since we won't re-layout if auto_layout is TRUE.
> 
> FALSE you mean?

Yeah, sorry about that. I'm out the door in 1 minute though, so I'll do it tomorrow or you (or anyone) can fixup + push for me.

Thanks!
Comment 25 Carlos Soriano 2016-10-07 17:43:25 UTC
Created attachment 337186 [details] [review]
nautilus-canvas: Don't lay down desktop icons if we haven't been allocated size yet

Sometimes we were trying to lay down icons before size_allocate had been
run. When this has happened, gtk_widget_get_allocation returns 1×1 as
our size. This messes up the algorithm and causes icons to be
overlapping on the canvas.

This case happens when using Nautilus as the desktop in early-startup
(e.g. from its XDG autostart file). It can happen that we have read the
desktop files before the allocation has happened.

We fix this by noticing if we're called before size_allocate and then
deferring icon layout until later on, after size_allocate has happened.

This behaviour was introduced in commit
e0081be7cd65de6422529d831f7882009ce00a9d, which sorts and freezes the
desktop in early-startup.

https://bugs.launchpad.net/ubuntu/+source/nautilus/+bug/1611955
Comment 26 Carlos Soriano 2016-10-07 17:44:53 UTC
Comment on attachment 337186 [details] [review]
nautilus-canvas: Don't lay down desktop icons if we haven't been allocated size yet

Thansk a lot Ian! Excellent work.

Attachment 337186 [details] pushed as d82b5bb - nautilus-canvas: Don't lay down desktop icons if we haven't been allocated size yet
Comment 27 Carlos Soriano 2016-10-07 17:50:55 UTC
Created attachment 337190 [details] [review]
nautilus-canvas: Don't lay down desktop icons if we haven't been allocated size yet

Sometimes we were trying to lay down icons before size_allocate had been
run. When this has happened, gtk_widget_get_allocation returns 1×1 as
our size. This messes up the algorithm and causes icons to be
overlapping on the canvas.

This case happens when using Nautilus as the desktop in early-startup
(e.g. from its XDG autostart file). It can happen that we have read the
desktop files before the allocation has happened.

We fix this by noticing if we're called before size_allocate and then
deferring icon layout until later on, after size_allocate has happened.

This behaviour was introduced in commit
e0081be7cd65de6422529d831f7882009ce00a9d, which sorts and freezes the
desktop in early-startup.

https://bugs.launchpad.net/ubuntu/+source/nautilus/+bug/1611955
Comment 28 Carlos Soriano 2016-10-07 17:52:19 UTC
and for 3.20

Attachment 337190 [details] pushed as 4bd2be2 - nautilus-canvas: Don't lay down desktop icons if we haven't been allocated size yet