Final patch for #330298 (icons get rearranged and overlap)



Hi,

I finally got off my ass and looked at the problems with icons
overlapping on the desktop in 2.16.  There's an easy way to reproduce
this:

1. Insert a CD.  You'll get a volume icon.

2. On the top-left corner of the desktop, arrange your icons like this:

 [ ]    [ ]
 [ ]    [ ]
  CD    Home

 [ ]
 [ ]
file.txt

3. Eject the CD.  The CD icon will disappear.  Now, move the Home icon to the
left:

 [ ]
 [ ]
 Home

 [ ]
 [ ]
file.txt

4. Insert the same CD again.  You'll get an overlap:

 [[]]
 [[]]
 CDHome

 [ ]
 [ ]
file.txt

The attached patch fixes this very easily.  The problem is that when
filling the PlacementGrid, we were ignoring lazily-positioned icons
which had *already* been well-positioned.  So, icon overlaps would only
happen over the non-file icons:  Home, volumes, network mounts, Trash,
etc.

I've attached this patch to
http://bugzilla.gnome.org/show_bug.cgi?id=330298 as well.

I cannot reproduce any of the various "icons get messed up on the
desktop" bugs with this patch anymore.  Wheee!

OK to commit?

  Federico
2006-10-31  Federico Mena Quintero  <federico novell com>

	http://bugzilla.gnome.org/show_bug.cgi?id=330298

	Fix the use of lazy positioning, and the saving of metadata for
	lazily-positioned icons.  Fixes
	https://bugzilla.novell.com/show_bug.cgi?id=155337 and
	https://bugzilla.novell.com/show_bug.cgi?id=174766.

	* src/file-manager/fm-icon-view.c (file_has_lazy_position): Only
	desktop icon files (not "real" files) have lazy positions.  Don't
	consider whether the directory is loading; this is not the right
	place to check that.
	(fm_icon_view_begin_loading): Tell the icon container that we
	just started reloading.
	(fm_icon_view_end_loading): Tell the icon container that we
	finished loading.

	* libnautilus-private/nautilus-icon-private.h
	(NautilusIconContainerDetails): New flag "is_reloading".

	* libnautilus-private/nautilus-icon-container.h: New prototype for
	nautilus_icon_container_set_is_reloading().

	* libnautilus-private/nautilus-icon-container.c
	(nautilus_icon_container_set_is_reloading): New function; sets an
	is_reloading flag in the icon container.
	(icon_set_position): Clear icon->has_lazy_position, since the icon
	will be well-positioned once this function exits.
	(finish_adding_new_icons): Do not ignore already-placed lazy
	position icons when filling the placement grid!  Save the value of
	icon->has_lazy_position before calling assign_icon_position().
	Since that function may call icon_set_position() (which will clear
	the flag), we need to keep the original value of the flag.
	(finish_adding_new_icons): Don't clear icon->has_lazy_position
	here; let icon_set_position() do it.
	(finish_adding_new_icons): Emit the icon_position_changed signal
	so that the parent knows that we moved an icon under it.  This has
	the effect of updating/preserving the position metadata for
	has_lazy_position icons.

--- nautilus/src/file-manager/fm-icon-view.c~	2006-08-29 03:04:42.000000000 -0500
+++ nautilus/src/file-manager/fm-icon-view.c	2006-10-31 17:46:27.000000000 -0600
@@ -512,22 +512,12 @@ static gboolean
 file_has_lazy_position (FMDirectoryView *view,
 			NautilusFile *file)
 {
-	gboolean lazy_position;
-
 	/* For volumes (i.e. cdrom icon) we use lazy positioning so that when
 	 * an old cdrom gets re-mounted in a place that now has another
-	 * icon we don't overlap that one. We don't do this in general though,
-	 * as it can cause icons moving around.
+	 * icon we don't overlap that one.
 	 */
-	lazy_position = nautilus_file_has_volume (file);
-	if (lazy_position && fm_directory_view_get_loading (view)) {
-		/* if volumes are loaded during directory load, don't mark them
-		 * as lazy. This is wrong for files that were mounted during user
-		 * log-off, but it is right for files that were mounted during login. */
-		lazy_position = FALSE;
-	}
 
-	return lazy_position;
+	return NAUTILUS_IS_DESKTOP_ICON_FILE (file);
 }
 
 static void
@@ -1073,6 +1063,8 @@ fm_icon_view_begin_loading (FMDirectoryV
 	file = fm_directory_view_get_directory_as_file (view);
 	icon_container = GTK_WIDGET (get_icon_container (icon_view));
 
+	nautilus_icon_container_set_is_reloading (NAUTILUS_ICON_CONTAINER (icon_container), TRUE);
+
 	nautilus_icon_container_set_allow_moves (NAUTILUS_ICON_CONTAINER (icon_container),
 						 fm_directory_view_get_allow_moves (view));
 
@@ -1147,6 +1139,7 @@ fm_icon_view_end_loading (FMDirectoryVie
 	FMIconView *icon_view;
 
 	icon_view = FM_ICON_VIEW (view);
+	nautilus_icon_container_set_is_reloading (get_icon_container (icon_view), FALSE);
 }
 
 static NautilusZoomLevel
--- nautilus-2.15.4/libnautilus-private/nautilus-icon-container.h
+++ nautilus-2.15.4/libnautilus-private/nautilus-icon-container.h
@@ -228,6 +228,8 @@
 									 NautilusIconData       *data);
 
 /* control the layout */
+void              nautilus_icon_container_set_is_reloading              (NautilusIconContainer  *container,
+									 gboolean                is_reloading);
 gboolean          nautilus_icon_container_is_auto_layout                (NautilusIconContainer  *container);
 void              nautilus_icon_container_set_auto_layout               (NautilusIconContainer  *container,
 									 gboolean                auto_layout);
--- nautilus/libnautilus-private/nautilus-icon-container.c.orig	2006-10-31 17:58:43.000000000 -0600
+++ nautilus/libnautilus-private/nautilus-icon-container.c	2006-10-31 18:00:47.000000000 -0600
@@ -288,6 +288,8 @@ icon_set_position (NautilusIcon *icon,
 	int x1, y1, x2, y2;
 	int container_x, container_y, container_width, container_height;
 
+	icon->has_lazy_position = FALSE;
+
 	if (icon->x == x && icon->y == y) {
 		return;
 	}
@@ -348,7 +350,7 @@ icon_set_position (NautilusIcon *icon,
 	if (icon->y == ICON_UNPOSITIONED_VALUE) {
 		icon->y = 0;
 	}
-	
+
 	eel_canvas_item_move (EEL_CANVAS_ITEM (icon->item),
 				x - icon->x,
 				y - icon->y);
@@ -5708,9 +5710,13 @@ finish_adding_new_icons (NautilusIconCon
 	new_icons = g_list_reverse (new_icons);
 	no_position_icons = semi_position_icons = NULL;
 	for (p = new_icons; p != NULL; p = p->next) {
+		gboolean has_lazy_position;
+
 		icon = p->data;
+		has_lazy_position = icon->has_lazy_position;
+
                 if (assign_icon_position (container, icon)) {
-                        if (!container->details->auto_layout && icon->has_lazy_position) {
+			if (!container->details->is_reloading && !container->details->auto_layout && has_lazy_position) {
                                 semi_position_icons = g_list_prepend (semi_position_icons, icon);
                         }
                 } else {
@@ -5743,6 +5749,7 @@ finish_adding_new_icons (NautilusIconCon
 		for (p = semi_position_icons; p != NULL; p = p->next) {
 			NautilusIcon *icon;
 			int x, y;
+			NautilusIconPosition position;
 
 			icon = p->data;
 			x = icon->x;
@@ -5755,9 +5762,10 @@ finish_adding_new_icons (NautilusIconCon
 
 			placement_grid_mark_icon (grid, icon);
 
-			/* ensure that next time we run this code, the formerly semi-positioned
-			 * icons are treated as being positioned. */
-			icon->has_lazy_position = FALSE;
+			position.x = icon->x;
+			position.y = icon->y;
+			g_signal_emit (container, signals[ICON_POSITION_CHANGED], 0,
+				       icon->data, &position);
 		}
 
 		placement_grid_free (grid);
@@ -6657,6 +6665,15 @@ nautilus_icon_container_sort (NautilusIc
 	}
 }
 
+void
+nautilus_icon_container_set_is_reloading (NautilusIconContainer *container,
+					  gboolean               is_reloading)
+{
+	g_return_if_fail (NAUTILUS_IS_ICON_CONTAINER (container));
+
+	container->details->is_reloading = is_reloading;
+}
+
 gboolean
 nautilus_icon_container_is_auto_layout (NautilusIconContainer *container)
 {
--- nautilus-2.15.4/libnautilus-private/nautilus-icon-private.h
+++ nautilus-2.15.4/libnautilus-private/nautilus-icon-private.h
@@ -253,6 +253,8 @@
 	guint a11y_item_action_idle_handler;
 	GQueue* a11y_item_action_queue;
 
+	eel_boolean_bit is_reloading : 1;
+
 	/* interactive search */
 	gboolean disable_popdown;
 	gboolean imcontext_changed;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]