Re: Geometry issues ...



Hi Michael,

> 	I think we need:
> 
> 	a) Store the last saved ConfigureRequest geometry as 
> 	   x,y,width,height on the NautilusWindow instead of 
> 	   stringifying it [ at which point it's lost to sane 
> 	   manipulation ] Better to use a GdkRectangle here IMHO

Not sure why we would need to manipulate it. Having it in string form
makes it easy to compare.

> 	b) Only kick off the geometry save timeout if the window is 
> 	   visible on screen [ not a viewport  window moving hack ],
> 	   and the geometry is different from the last saved state.

Done.

> 	Here you say 1 second,
<snip>
> 
> 	Here you say 1/2 a second :-) 

Excellent ... just seeing if you're really paying attention! ;)

> 
> 	if (timeout_id)
> 		remove_timeout ();
> 	timeout_id = add_timeout (magic_number, ...);
> 
> 	? simpler flow, more lucid, no cut and paste.

Done.
 
> 	ie. before we call eel_gtk_window_set_initial_geometry in
> nautilus-window-manage-views.c (position_and_show_window_callback): we
> scan the list, and if a duplicate is showing the current window [ surely
> we must have checked for this already in there ], then we either:
> 
> 	* pass a new flag 'ignore_position' to
> 	  eel_gtk_window_set_initial_geometry
> or
> 	* clobber geometry_flags &= ~(EEL_GDK_X_VALUE | 
> 				      EEL_GDK_Y_VALUE)

I've added an ignore flag, although the other would avoid API breakage.
I don't know if that's a big deal.

The latest patch is attached. Using this, the geometry really only is
saved when I resize a window ... not when I open a new one or switch
workspaces.

- Frank
Index: eel/eel-gtk-extensions.c
===================================================================
RCS file: /cvs/gnome/eel/eel/eel-gtk-extensions.c,v
retrieving revision 1.49
diff -u -p -r1.49 eel-gtk-extensions.c
--- eel/eel-gtk-extensions.c	3 Jul 2002 05:18:34 -0000	1.49
+++ eel/eel-gtk-extensions.c	14 Jul 2002 06:17:23 -0000
@@ -384,12 +384,14 @@ eel_gtk_window_set_initial_geometry (Gtk
  * use this for the width.
  * @minimum_height: If the height from the string is smaller than this,
  * use this for the height.
+ * @ignore_position: If true position data from string will be ignored.
  */
 void
 eel_gtk_window_set_initial_geometry_from_string (GtkWindow *window, 
 						 const char *geometry_string,
 						 guint minimum_width,
-						 guint minimum_height)
+						 guint minimum_height,
+						 gboolean ignore_position)
 {
 	int left, top;
 	guint width, height;
@@ -414,6 +416,11 @@ eel_gtk_window_set_initial_geometry_from
 	}
 	if (geometry_flags & EEL_GDK_HEIGHT_VALUE) {
 		height = MAX (height, minimum_height);
+	}
+	
+	/* Ignore saved window position if requested. */
+	if (ignore_position) {
+		geometry_flags &= ~(EEL_GDK_X_VALUE | EEL_GDK_Y_VALUE);
 	}
 
 	eel_gtk_window_set_initial_geometry (window, geometry_flags, left, top, width, height);
Index: eel/eel-gtk-extensions.h
===================================================================
RCS file: /cvs/gnome/eel/eel/eel-gtk-extensions.h,v
retrieving revision 1.25
diff -u -p -r1.25 eel-gtk-extensions.h
--- eel/eel-gtk-extensions.h	21 Apr 2002 16:50:24 -0000	1.25
+++ eel/eel-gtk-extensions.h	14 Jul 2002 06:17:23 -0000
@@ -112,7 +112,8 @@ void                  eel_gtk_window_set
 void                  eel_gtk_window_set_initial_geometry_from_string (GtkWindow            *window,
 								       const char           *geometry_string,
 								       guint                 minimum_width,
-								       guint                 minimum_height);
+								       guint                 minimum_height,
+								       gboolean		     ignore_position);
 void                  eel_gtk_window_set_up_close_accelerator         (GtkWindow            *window);
 gboolean              eel_gtk_window_event_is_close_accelerator       (GtkWindow            *window,
 								       GdkEventKey          *event);
? make-local.sh
Index: src/nautilus-application.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/nautilus-application.c,v
retrieving revision 1.193
diff -u -p -r1.193 nautilus-application.c
--- src/nautilus-application.c	8 Jul 2002 15:32:08 -0000	1.193
+++ src/nautilus-application.c	14 Jul 2002 06:17:15 -0000
@@ -45,6 +45,7 @@
 #include <eel/eel-string-list.h>
 #include <eel/eel-string.h>
 #include <eel/eel-vfs-extensions.h>
+#include <eel/eel-gtk-extensions.h>
 #include <gtk/gtksignal.h>
 #include <libgnome/gnome-config.h>
 #include <libgnome/gnome-i18n.h>
@@ -643,15 +644,17 @@ nautilus_window_delete_event_callback (G
 }				       
 
 static gboolean
-save_window_geometry_idle (gpointer callback_data)
+save_window_geometry_timeout (gpointer callback_data)
 {
 	NautilusWindow *window;
 	
 	window = NAUTILUS_WINDOW (callback_data);
 	
+	g_warning ("FRANKW: saving geometry for window %u", (unsigned int) window);	
+
 	nautilus_window_save_geometry (window);
-	
-	window->save_geometry_idle_id = 0;
+
+	window->save_geometry_timeout_id = 0;
 	return FALSE;
 }
  
@@ -661,17 +664,42 @@ nautilus_window_configure_event_callback
 						gpointer callback_data)
 {
 	NautilusWindow *window;
+	char *geometry_string;
 	
 	window = NAUTILUS_WINDOW (widget);
 	
-	/* Only save the geometry when we are idle, 
-	 * since we receive configure events all the time.
+	/* Only save the geometry if the user hasn't resized the window
+	 * for half a second. Otherwise delay the callback another half second.
 	 */
-	if (window->save_geometry_idle_id == 0) {
-		window->save_geometry_idle_id = 
-				g_idle_add (save_window_geometry_idle, window);
+	if (window->save_geometry_timeout_id != 0) {
+		g_source_remove (window->save_geometry_timeout_id);	
 	}
+	if (GTK_WIDGET_VISIBLE (GTK_WIDGET (window)) && !NAUTILUS_IS_DESKTOP_WINDOW (window))
+	{
+		geometry_string = eel_gtk_window_get_geometry_string (GTK_WINDOW (window));
+	
+		/* If the last geometry is NULL the window must have just
+		 * been shown. No need to save geometry to disk since it
+		 * must be the same.
+		 */
+		if (window->last_geometry == NULL) {
+			window->last_geometry = geometry_string;
+			return FALSE;
+		}
+	
+		/* Don't save geometry if it's the same as before. */
+		if (!strcmp (window->last_geometry, geometry_string)) {
+			g_free (geometry_string);
+			return FALSE;
+		}
+
+		g_free (window->last_geometry);
+		window->last_geometry = geometry_string;
 
+		window->save_geometry_timeout_id = 
+				g_timeout_add (500, save_window_geometry_timeout, window);
+
+	}
 	return FALSE;
 }
 
@@ -684,9 +712,9 @@ nautilus_window_unrealize_event_callback
 	
 	window = NAUTILUS_WINDOW (widget);
 
-	if (window->save_geometry_idle_id != 0) {
-		g_source_remove (window->save_geometry_idle_id);
-		window->save_geometry_idle_id = 0;
+	if (window->save_geometry_timeout_id != 0) {
+		g_source_remove (window->save_geometry_timeout_id);
+		window->save_geometry_timeout_id = 0;
 		nautilus_window_save_geometry (window);
 	}
 
Index: src/nautilus-bookmarks-window.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/nautilus-bookmarks-window.c,v
retrieving revision 1.70
diff -u -p -r1.70 nautilus-bookmarks-window.c
--- src/nautilus-bookmarks-window.c	2 Jul 2002 16:07:26 -0000	1.70
+++ src/nautilus-bookmarks-window.c	14 Jul 2002 06:17:16 -0000
@@ -396,7 +396,7 @@ nautilus_bookmarks_window_restore_geomet
 	if (window_geometry != NULL) {	
 		eel_gtk_window_set_initial_geometry_from_string 
 			(GTK_WINDOW (window), window_geometry, 
-			 BOOKMARKS_WINDOW_MIN_WIDTH, BOOKMARKS_WINDOW_MIN_HEIGHT);
+			 BOOKMARKS_WINDOW_MIN_WIDTH, BOOKMARKS_WINDOW_MIN_HEIGHT, FALSE);
 
 	} else {
 		/* use default since there was no stored geometry */
Index: src/nautilus-shell.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/nautilus-shell.c,v
retrieving revision 1.49
diff -u -p -r1.49 nautilus-shell.c
--- src/nautilus-shell.c	14 Feb 2002 23:21:58 -0000	1.49
+++ src/nautilus-shell.c	14 Jul 2002 06:17:16 -0000
@@ -130,7 +130,8 @@ open_window (NautilusShell *shell, const
 		eel_gtk_window_set_initial_geometry_from_string (GTK_WINDOW (window),
 								      geometry,
 								      APPLICATION_WINDOW_MIN_WIDTH,
-								      APPLICATION_WINDOW_MIN_HEIGHT);
+								      APPLICATION_WINDOW_MIN_HEIGHT,
+								      FALSE);
 	}
 
 	if (uri == NULL) {
Index: src/nautilus-window-manage-views.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/nautilus-window-manage-views.c,v
retrieving revision 1.301
diff -u -p -r1.301 nautilus-window-manage-views.c
--- src/nautilus-window-manage-views.c	5 Jul 2002 10:51:03 -0000	1.301
+++ src/nautilus-window-manage-views.c	14 Jul 2002 06:17:16 -0000
@@ -44,6 +44,7 @@
 #include <eel/eel-vfs-extensions.h>
 #include <gtk/gtkmain.h>
 #include <gtk/gtksignal.h>
+#include <gdk/gdkx.h>
 #include <libgnome/gnome-i18n.h>
 #include <libgnomeui/gnome-dialog-util.h>
 #include <libgnomevfs/gnome-vfs-async-ops.h>
@@ -1108,13 +1109,41 @@ cancel_location_change (NautilusWindow *
         end_location_change (window);
 }
 
+
+static gboolean
+pending_location_already_showing (NautilusWindow *window)
+{
+	char *temp;
+	char *location;
+	GList *list, *item;
+	
+	temp = window->details->pending_location;
+	list = nautilus_application_get_window_list ();
+	for (item = list; item != NULL; item = item->next) {
+		location = nautilus_window_get_location (NAUTILUS_WINDOW (item->data));
+
+		if (!NAUTILUS_IS_DESKTOP_WINDOW (item->data)
+		    && location != NULL
+		    && item->data != window
+		    && !strcmp (temp, location)) {
+		    	g_free (location);
+			return TRUE;
+		}
+		
+		g_free (location);
+	}
+	
+	return FALSE;
+}
+
+
 static void
 position_and_show_window_callback (NautilusFile *file,
                        		   gpointer callback_data)
 {
 	NautilusWindow *window;
 	char *geometry_string;
-        
+   
 	window = NAUTILUS_WINDOW (callback_data);
 
         if (!NAUTILUS_IS_DESKTOP_WINDOW (window)) {
@@ -1122,11 +1151,16 @@ position_and_show_window_callback (Nauti
                 geometry_string = nautilus_file_get_metadata 
 			(file, NAUTILUS_METADATA_KEY_WINDOW_GEOMETRY, NULL);
                 if (geometry_string != NULL) {
+			/* Ignore saved window position if a window with the same
+			 * location is already showing. That way the two windows
+			 * wont appear at the exact same location on the screen.
+			 */
                         eel_gtk_window_set_initial_geometry_from_string 
                                 (GTK_WINDOW (window), 
                                  geometry_string,
                                  NAUTILUS_WINDOW_MIN_WIDTH, 
-                                 NAUTILUS_WINDOW_MIN_HEIGHT);
+                                 NAUTILUS_WINDOW_MIN_HEIGHT,
+				 pending_location_already_showing (window));
                 }
                 g_free (geometry_string);
         }
Index: src/nautilus-window.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/nautilus-window.c,v
retrieving revision 1.389
diff -u -p -r1.389 nautilus-window.c
--- src/nautilus-window.c	11 Jun 2002 03:42:25 -0000	1.389
+++ src/nautilus-window.c	14 Jul 2002 06:17:17 -0000
@@ -180,6 +180,9 @@ nautilus_window_instance_init (NautilusW
 	g_object_ref (G_OBJECT (window->details->tooltips));
 	gtk_object_sink (GTK_OBJECT (window->details->tooltips));
 
+	/* Set last geometry to NULL */
+	window->last_geometry = NULL;
+
 	/* Set initial window title */
 	gtk_window_set_title (GTK_WINDOW (window), _("Nautilus"));
 
@@ -877,6 +880,7 @@ nautilus_window_save_geometry (NautilusW
 				    NAUTILUS_METADATA_KEY_WINDOW_GEOMETRY,
 				    NULL,
 				    geometry_string);
+				    
 	g_free (geometry_string);
 }
 
Index: src/nautilus-window.h
===================================================================
RCS file: /cvs/gnome/nautilus/src/nautilus-window.h,v
retrieving revision 1.102
diff -u -p -r1.102 nautilus-window.h
--- src/nautilus-window.h	11 Jun 2002 08:57:14 -0000	1.102
+++ src/nautilus-window.h	14 Jul 2002 06:17:17 -0000
@@ -81,8 +81,10 @@ struct NautilusWindow {
         GtkWidget *view_as_option_menu;
         GtkWidget *navigation_bar;
         
+	char *last_geometry;
+	
         guint status_bar_clear_id;
-        guint save_geometry_idle_id;
+        guint save_geometry_timeout_id;
 	  
         /** CORBA-related elements **/
         NautilusApplication *application;


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