Re: [PATCH] Don't position volume/drives above other icons



Am Dienstag, den 23.08.2005, 12:49 +0200 schrieb Christian Neumair:
> Am Dienstag, den 23.08.2005, 12:41 +0200 schrieb martin wehner:
> > On 8/23/05, Christian Neumair <chris gnome-de org> wrote:
> > > Am Dienstag, den 23.08.2005, 01:44 +0200 schrieb Martin Wehner:
> > > > On Mon, 2005-08-15 at 00:52 +0200, Christian Neumair wrote:
> > > > > Probably the most obvious/reported icon container glitch [1,2].
> > > > > Proposed patch attached.
> > > >
> > > > While it'd be cool to fix at last, this code doesn't handle multiple
> > > > lazy icons properly. You can make multiple devices appear on top of each
> > > > other, because lazy icons won't be taken into account once they aren't
> > > > new anymore.
> > > 
> > > Of course. We do call placement_grid_mark_icon which will take care that
> > > other semi-positioned icons aren't assigned the same grid position.
> > 
> > Yes, but only for the _new_ icons, the previous lazy icons aren't
> > pre-filled into the grid you use to find a free position. Just put two
> > devices at the same position on your desktop and try it. I did.
> 
> We could also mark icons as not being lazy once they're positioned. This
> would probably be the most straightforward and obvious solution, since
> otherwise we'd have to add a g_list_find foreach 
> 
> if (icon_is_positioned (icon) && !icon->has_lazy_position) {
> 
> which could be quiet expensive.

Even if it is not expensive (which is very often the case, since
semi_position_icons isn't very long typically), it just seems to be
wrong to keep around a special has_lazy_position flag which is
essentially ignored after the first layout.
Therefore, setting it to FALSE after positioning the icon seems to be
way more reasonable.

Proposed patch attached. A quick test with two volumes revealed that it
seems to work correctly.

-- 
Christian Neumair <chris gnome-de org>
Index: libnautilus-private/nautilus-icon-container.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-icon-container.c,v
retrieving revision 1.393
diff -u -p -r1.393 nautilus-icon-container.c
--- libnautilus-private/nautilus-icon-container.c	12 Aug 2005 18:11:29 -0000	1.393
+++ libnautilus-private/nautilus-icon-container.c	23 Aug 2005 11:52:31 -0000
@@ -5152,7 +5152,7 @@ finish_adding_icon (NautilusIconContaine
 static void
 finish_adding_new_icons (NautilusIconContainer *container)
 {
-	GList *p, *new_icons, *no_position_icons;
+	GList *p, *new_icons, *no_position_icons, *semi_position_icons;
 	NautilusIcon *icon;
 	double bottom;
 
@@ -5161,16 +5161,61 @@ finish_adding_new_icons (NautilusIconCon
 
 	/* Position most icons (not unpositioned manual-layout icons). */
 	new_icons = g_list_reverse (new_icons);
-	no_position_icons = NULL;
+	no_position_icons = semi_position_icons = NULL;
 	for (p = new_icons; p != NULL; p = p->next) {
 		icon = p->data;
 		if (!assign_icon_position (container, icon)) {
 			no_position_icons = g_list_prepend (no_position_icons, icon);
+		} else if (!container->details->auto_layout &&
+			   icon->has_lazy_position) {
+			semi_position_icons = g_list_prepend (semi_position_icons, icon);
 		}
 		finish_adding_icon (container, icon);
 	}
 	g_list_free (new_icons);
 
+	if (semi_position_icons != NULL) {
+		PlacementGrid *grid;
+
+		g_assert (!container->details->auto_layout);
+
+		semi_position_icons = g_list_reverse (semi_position_icons);
+
+		grid = placement_grid_new (container, TRUE);
+
+		for (p = container->details->icons; p != NULL; p = p->next) {
+			icon = p->data;
+
+			if (icon_is_positioned (icon) && !icon->has_lazy_position) {
+				placement_grid_mark_icon (grid, icon);
+			}
+		}
+
+		for (p = semi_position_icons; p != NULL; p = p->next) {
+			NautilusIcon *icon;
+			int x, y;
+
+			icon = p->data;
+			x = icon->x;
+			y = icon->y;
+
+			find_empty_location (container, grid, 
+					     icon, x, y, &x, &y);
+
+			icon_set_position (icon, x, y);
+
+			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;
+		}
+
+		placement_grid_free (grid);
+
+		g_list_free (semi_position_icons);
+	}
+
 	/* Position the unpositioned manual layout icons. */
 	if (no_position_icons != NULL) {
 		g_assert (!container->details->auto_layout);
@@ -5186,13 +5231,18 @@ finish_adding_new_icons (NautilusIconCon
  * nautilus_icon_container_add:
  * @container: A NautilusIconContainer
  * @data: Icon data.
+ * @has_lazy_position: Whether the saved icon position should only be used
+ * 		       if the previous icon position is free. If the position
+ * 		       is occupied, another position near the last one will
+ * 		       be used.
  * 
  * Add icon to represent @data to container.
  * Returns FALSE if there was already such an icon.
  **/
 gboolean
 nautilus_icon_container_add (NautilusIconContainer *container,
-			     NautilusIconData *data)
+			     NautilusIconData *data,
+			     gboolean has_lazy_position)
 {
 	NautilusIconContainerDetails *details;
 	NautilusIcon *icon;
@@ -5212,6 +5262,7 @@ nautilus_icon_container_add (NautilusIco
 	icon->data = data;
 	icon->x = ICON_UNPOSITIONED_VALUE;
 	icon->y = ICON_UNPOSITIONED_VALUE;
+	icon->has_lazy_position = has_lazy_position;
 	icon->scale_x = 1.0;
 	icon->scale_y = 1.0;
  	icon->item = NAUTILUS_ICON_CANVAS_ITEM
Index: libnautilus-private/nautilus-icon-container.h
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-icon-container.h,v
retrieving revision 1.87
diff -u -p -r1.87 nautilus-icon-container.h
--- libnautilus-private/nautilus-icon-container.h	5 Jul 2005 12:23:34 -0000	1.87
+++ libnautilus-private/nautilus-icon-container.h	23 Aug 2005 11:52:31 -0000
@@ -204,7 +204,8 @@ GtkWidget *       nautilus_icon_containe
 /* adding, removing, and managing icons */
 void              nautilus_icon_container_clear                         (NautilusIconContainer  *view);
 gboolean          nautilus_icon_container_add                           (NautilusIconContainer  *view,
-									 NautilusIconData       *data);
+									 NautilusIconData       *data,
+									 gboolean                has_lazy_position);
 void              nautilus_icon_container_layout_now                    (NautilusIconContainer *container);
 gboolean          nautilus_icon_container_remove                        (NautilusIconContainer  *view,
 									 NautilusIconData       *data);
Index: libnautilus-private/nautilus-icon-dnd.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-icon-dnd.c,v
retrieving revision 1.148
diff -u -p -r1.148 nautilus-icon-dnd.c
--- libnautilus-private/nautilus-icon-dnd.c	13 Jul 2005 08:17:29 -0000	1.148
+++ libnautilus-private/nautilus-icon-dnd.c	23 Aug 2005 11:52:32 -0000
@@ -844,7 +844,8 @@ handle_local_move (NautilusIconContainer
 			g_free (screen_string);
 
 			nautilus_icon_container_add (container,
-					NAUTILUS_ICON_CONTAINER_ICON_DATA (file));
+					NAUTILUS_ICON_CONTAINER_ICON_DATA (file),
+					FALSE);
 			
 			icon = nautilus_icon_container_get_icon_by_uri
 				(container, item->uri);
Index: libnautilus-private/nautilus-icon-private.h
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-icon-private.h,v
retrieving revision 1.77
diff -u -p -r1.77 nautilus-icon-private.h
--- libnautilus-private/nautilus-icon-private.h	6 Jul 2005 11:45:08 -0000	1.77
+++ libnautilus-private/nautilus-icon-private.h	23 Aug 2005 11:52:32 -0000
@@ -57,6 +57,7 @@ typedef struct {
 	/* Whether a monitor was set on this icon. */
 	eel_boolean_bit is_monitored : 1;
 
+	eel_boolean_bit has_lazy_position : 1;
 } NautilusIcon;
 
 
Index: src/file-manager/fm-icon-view.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/file-manager/fm-icon-view.c,v
retrieving revision 1.313
diff -u -p -r1.313 fm-icon-view.c
--- src/file-manager/fm-icon-view.c	12 Aug 2005 18:11:30 -0000	1.313
+++ src/file-manager/fm-icon-view.c	23 Aug 2005 11:52:33 -0000
@@ -535,7 +535,9 @@ fm_icon_view_add_file (FMDirectoryView *
 	}
 	
 	if (nautilus_icon_container_add (icon_container,
-					 NAUTILUS_ICON_CONTAINER_ICON_DATA (file))) {
+					 NAUTILUS_ICON_CONTAINER_ICON_DATA (file),
+					 nautilus_file_has_volume (file)
+					 || nautilus_file_has_drive (file))) {
 		nautilus_file_ref (file);
 	}
 }
@@ -2018,7 +2020,9 @@ fm_icon_view_screen_changed (GtkWidget *
 				fm_icon_view_remove_file (view, file);
 			} else {
 				if (nautilus_icon_container_add (icon_container,
-								 NAUTILUS_ICON_CONTAINER_ICON_DATA (file))) {
+								 NAUTILUS_ICON_CONTAINER_ICON_DATA (file),
+								 nautilus_file_has_volume (file)
+								 || nautilus_file_has_drive (file))) {
 					nautilus_file_ref (file);
 				}
 			}

Attachment: signature.asc
Description: This is a digitally signed message part



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