[nautilus-actions] Move save and restore window size and position to core/na-gtk-utils.c
- From: Pierre Wieser <pwieser src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus-actions] Move save and restore window size and position to core/na-gtk-utils.c
- Date: Fri, 2 Dec 2011 10:50:42 +0000 (UTC)
commit 3bd141d1666ff78248b7c17fb9e8d941582bc31e
Author: Pierre Wieser <pwieser trychlos org>
Date: Wed Nov 30 23:48:45 2011 +0100
Move save and restore window size and position to core/na-gtk-utils.c
ChangeLog | 11 ++++
src/core/na-gtk-utils.c | 147 +++++++++++++++++++++++++++++++++++++++++++++
src/core/na-gtk-utils.h | 9 +++
src/nact/base-gtk-utils.c | 119 +-----------------------------------
src/nact/base-gtk-utils.h | 2 +
5 files changed, 173 insertions(+), 115 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 71b6bda..dedda7b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,16 @@
2011-11-30 Pierre Wieser <pwieser trychlos org>
+ * src/core/na-gtk-utils.c:
+ * src/core/na-gtk-utils.h
+ (na_gtk_utils_restore_position_window, na_gtk_utils_save_window_position):
+ New functions.
+
+ * src/nact/base-gtk-utils.c
+ (base_gtk_utils_restore_window_position, base_gtk_utils_save_window_position):
+ Updated accordingly.
+
+ * src/nact/base-gtk-utils.h: Fix a comment.
+
* src/core/na-importer-ask.c:
* src/core/na-importer-ask.h: Now derives from GObject.
diff --git a/src/core/na-gtk-utils.c b/src/core/na-gtk-utils.c
index 24bd6df..d2db706 100644
--- a/src/core/na-gtk-utils.c
+++ b/src/core/na-gtk-utils.c
@@ -35,6 +35,11 @@
#include <string.h>
#include "na-gtk-utils.h"
+#include "na-settings.h"
+
+static void int_list_to_position( GList *list, gint *x, gint *y, gint *width, gint *height );
+static GList *position_to_int_list( gint x, gint y, gint width, gint height );
+static void free_int_list( GList *list );
/*
* na_gtk_utils_search_for_child_widget:
@@ -127,3 +132,145 @@ na_gtk_utils_dump_children( GtkContainer *container )
dump_children( thisfn, container, 0 );
}
#endif
+
+/**
+ * na_gtk_utils_restore_position_window:
+ * @toplevel: the #GtkWindow window.
+ * @wsp_name: the string which handles the window size and position in user preferences.
+ *
+ * Position the specified window on the screen.
+ *
+ * A window position is stored as a list of integers "x,y,width,height".
+ */
+void
+na_gtk_utils_restore_window_position( GtkWindow *toplevel, const gchar *wsp_name )
+{
+ static const gchar *thisfn = "na_gtk_utils_restore_window_position";
+ GList *list;
+ gint x=0, y=0, width=0, height=0;
+ GdkDisplay *display;
+ GdkScreen *screen;
+ gint screen_width, screen_height;
+
+ g_return_if_fail( GTK_IS_WINDOW( toplevel ));
+ g_return_if_fail( wsp_name && strlen( wsp_name ));
+
+ g_debug( "%s: toplevel=%p (%s), wsp_name=%s",
+ thisfn, ( void * ) toplevel, G_OBJECT_TYPE_NAME( toplevel ), wsp_name );
+
+ list = na_settings_get_uint_list( wsp_name, NULL, NULL );
+
+ if( list ){
+ int_list_to_position( list, &x, &y, &width, &height );
+ g_debug( "%s: wsp_name=%s, x=%d, y=%d, width=%d, height=%d", thisfn, wsp_name, x, y, width, height );
+ free_int_list( list );
+ }
+
+ x = MAX( 1, x );
+ y = MAX( 1, y );
+ width = MAX( 1, width );
+ height = MAX( 1, height );
+
+ display = gdk_display_get_default();
+ screen = gdk_display_get_screen( display, 0 );
+ screen_width = gdk_screen_get_width( screen );
+ screen_height = gdk_screen_get_height( screen );
+
+ /* very dirty hack based on the assumption that Gnome 2.x has a bottom
+ * and a top panel bars, while Gnome 3.x only has one.
+ * Don't know how to get usable height of screen, and don't bother today.
+ */
+ screen_height -= DEFAULT_HEIGHT;
+#if ! GTK_CHECK_VERSION( 3, 0, 0 )
+ screen_height -= DEFAULT_HEIGHT;
+#endif
+
+ width = MIN( width, screen_width-x );
+ height = MIN( height, screen_height-y );
+
+ g_debug( "%s: wsp_name=%s, screen=(%d,%d), x=%d, y=%d, width=%d, height=%d",
+ thisfn, wsp_name, screen_width, screen_height, x, y, width, height );
+
+ gtk_window_move( toplevel, x, y );
+ gtk_window_resize( toplevel, width, height );
+}
+
+/**
+ * na_gtk_utils_save_window_position:
+ * @toplevel: the #GtkWindow window.
+ * @wsp_name: the string which handles the window size and position in user preferences.
+ *
+ * Save the size and position of the specified window.
+ */
+void
+na_gtk_utils_save_window_position( GtkWindow *toplevel, const gchar *wsp_name )
+{
+ static const gchar *thisfn = "na_gtk_utils_save_window_position";
+ gint x, y, width, height;
+ GList *list;
+
+ g_return_if_fail( GTK_IS_WINDOW( toplevel ));
+ g_return_if_fail( wsp_name && strlen( wsp_name ));
+
+ gtk_window_get_position( toplevel, &x, &y );
+ gtk_window_get_size( toplevel, &width, &height );
+ g_debug( "%s: wsp_name=%s, x=%d, y=%d, width=%d, height=%d", thisfn, wsp_name, x, y, width, height );
+
+ list = position_to_int_list( x, y, width, height );
+ na_settings_set_uint_list( wsp_name, list );
+ free_int_list( list );
+}
+
+/*
+ * extract the position of the window from the list of unsigned integers
+ */
+static void
+int_list_to_position( GList *list, gint *x, gint *y, gint *width, gint *height )
+{
+ GList *it;
+ int i;
+
+ g_assert( x );
+ g_assert( y );
+ g_assert( width );
+ g_assert( height );
+
+ for( it=list, i=0 ; it ; it=it->next, i+=1 ){
+ switch( i ){
+ case 0:
+ *x = GPOINTER_TO_UINT( it->data );
+ break;
+ case 1:
+ *y = GPOINTER_TO_UINT( it->data );
+ break;
+ case 2:
+ *width = GPOINTER_TO_UINT( it->data );
+ break;
+ case 3:
+ *height = GPOINTER_TO_UINT( it->data );
+ break;
+ }
+ }
+}
+
+static GList *
+position_to_int_list( gint x, gint y, gint width, gint height )
+{
+ GList *list = NULL;
+
+ list = g_list_append( list, GUINT_TO_POINTER( x ));
+ list = g_list_append( list, GUINT_TO_POINTER( y ));
+ list = g_list_append( list, GUINT_TO_POINTER( width ));
+ list = g_list_append( list, GUINT_TO_POINTER( height ));
+
+ return( list );
+}
+
+/*
+ * free the list of int
+ */
+static void
+free_int_list( GList *list )
+{
+ g_list_free( list );
+}
diff --git a/src/core/na-gtk-utils.h b/src/core/na-gtk-utils.h
index d279e5d..4f496c3 100644
--- a/src/core/na-gtk-utils.h
+++ b/src/core/na-gtk-utils.h
@@ -46,6 +46,15 @@ GtkWidget *na_gtk_utils_search_for_child_widget( GtkContainer *container, const
void na_gtk_utils_dump_children ( GtkContainer *container );
#endif
+/* window size and position
+ */
+void na_gtk_utils_restore_window_position( GtkWindow *toplevel, const gchar *wsp_name );
+void na_gtk_utils_save_window_position ( GtkWindow *toplevel, const gchar *wsp_name );
+
+/* default height of a panel bar (dirty hack!)
+ */
+#define DEFAULT_HEIGHT 22
+
G_END_DECLS
#endif /* __CORE_API_NA_GTK_UTILS_H__ */
diff --git a/src/nact/base-gtk-utils.c b/src/nact/base-gtk-utils.c
index 67fbb50..531d942 100644
--- a/src/nact/base-gtk-utils.c
+++ b/src/nact/base-gtk-utils.c
@@ -34,7 +34,7 @@
#include <string.h>
-#include <core/na-iprefs.h>
+#include <core/na-gtk-utils.h>
#include <core/na-updater.h>
#include "base-gtk-utils.h"
@@ -44,11 +44,6 @@
#define NACT_PROP_TOGGLE_USER_DATA "nact-prop-toggle-user-data"
#define DEFAULT_WIDTH 22
-#define DEFAULT_HEIGHT 22
-
-static void int_list_to_position( const BaseWindow *window, GList *list, gint *x, gint *y, gint *width, gint *height );
-static GList *position_to_int_list( const BaseWindow *window, gint x, gint y, gint width, gint height );
-static void free_int_list( GList *list );
/**
* base_gtk_utils_position_window:
@@ -62,58 +57,15 @@ static void free_int_list( GList *list );
void
base_gtk_utils_restore_window_position( const BaseWindow *window, const gchar *wsp_name )
{
- static const gchar *thisfn = "base_gtk_utils_restore_window_position";
GtkWindow *toplevel;
- GList *list;
- gint x=0, y=0, width=0, height=0;
- GdkDisplay *display;
- GdkScreen *screen;
- gint screen_width, screen_height;
g_return_if_fail( BASE_IS_WINDOW( window ));
g_return_if_fail( wsp_name && strlen( wsp_name ));
toplevel = base_window_get_gtk_toplevel( window );
+ g_return_if_fail( GTK_IS_WINDOW( toplevel ));
- g_debug( "%s: window=%p (%s), toplevel=%p (%s), wsp_name=%s",
- thisfn, ( void * ) window, G_OBJECT_TYPE_NAME( window ),
- ( void * ) toplevel, G_OBJECT_TYPE_NAME( toplevel ), wsp_name );
-
- list = na_settings_get_uint_list( wsp_name, NULL, NULL );
-
- if( list ){
- int_list_to_position( window, list, &x, &y, &width, &height );
- g_debug( "%s: wsp_name=%s, x=%d, y=%d, width=%d, height=%d", thisfn, wsp_name, x, y, width, height );
- free_int_list( list );
- }
-
- x = MAX( 1, x );
- y = MAX( 1, y );
- width = MAX( 1, width );
- height = MAX( 1, height );
-
- display = gdk_display_get_default();
- screen = gdk_display_get_screen( display, 0 );
- screen_width = gdk_screen_get_width( screen );
- screen_height = gdk_screen_get_height( screen );
-
- /* very dirty hack based on the assumption that Gnome 2.x has a bottom
- * and a top panel bars, while Gnome 3.x only has one.
- * Don't know how to get usable height of screen, and don't bother today.
- */
- screen_height -= DEFAULT_HEIGHT;
-#if ! GTK_CHECK_VERSION( 3, 0, 0 )
- screen_height -= DEFAULT_HEIGHT;
-#endif
-
- width = MIN( width, screen_width-x );
- height = MIN( height, screen_height-y );
-
- g_debug( "%s: wsp_name=%s, screen=(%d,%d), x=%d, y=%d, width=%d, height=%d",
- thisfn, wsp_name, screen_width, screen_height, x, y, width, height );
-
- gtk_window_move( toplevel, x, y );
- gtk_window_resize( toplevel, width, height );
+ na_gtk_utils_restore_window_position( toplevel, wsp_name );
}
/**
@@ -126,10 +78,7 @@ base_gtk_utils_restore_window_position( const BaseWindow *window, const gchar *w
void
base_gtk_utils_save_window_position( const BaseWindow *window, const gchar *wsp_name )
{
- static const gchar *thisfn = "base_gtk_utils_save_window_position";
GtkWindow *toplevel;
- gint x, y, width, height;
- GList *list;
g_return_if_fail( BASE_IS_WINDOW( window ));
g_return_if_fail( wsp_name && strlen( wsp_name ));
@@ -137,67 +86,7 @@ base_gtk_utils_save_window_position( const BaseWindow *window, const gchar *wsp_
toplevel = base_window_get_gtk_toplevel( window );
g_return_if_fail( GTK_IS_WINDOW( toplevel ));
- gtk_window_get_position( toplevel, &x, &y );
- gtk_window_get_size( toplevel, &width, &height );
- g_debug( "%s: wsp_name=%s, x=%d, y=%d, width=%d, height=%d", thisfn, wsp_name, x, y, width, height );
-
- list = position_to_int_list( window, x, y, width, height );
- na_settings_set_uint_list( wsp_name, list );
- free_int_list( list );
-}
-
-/*
- * extract the position of the window from the list of unsigned integers
- */
-static void
-int_list_to_position( const BaseWindow *window, GList *list, gint *x, gint *y, gint *width, gint *height )
-{
- GList *it;
- int i;
-
- g_assert( x );
- g_assert( y );
- g_assert( width );
- g_assert( height );
-
- for( it=list, i=0 ; it ; it=it->next, i+=1 ){
- switch( i ){
- case 0:
- *x = GPOINTER_TO_UINT( it->data );
- break;
- case 1:
- *y = GPOINTER_TO_UINT( it->data );
- break;
- case 2:
- *width = GPOINTER_TO_UINT( it->data );
- break;
- case 3:
- *height = GPOINTER_TO_UINT( it->data );
- break;
- }
- }
-}
-
-static GList *
-position_to_int_list( const BaseWindow *window, gint x, gint y, gint width, gint height )
-{
- GList *list = NULL;
-
- list = g_list_append( list, GUINT_TO_POINTER( x ));
- list = g_list_append( list, GUINT_TO_POINTER( y ));
- list = g_list_append( list, GUINT_TO_POINTER( width ));
- list = g_list_append( list, GUINT_TO_POINTER( height ));
-
- return( list );
-}
-
-/*
- * free the list of int
- */
-static void
-free_int_list( GList *list )
-{
- g_list_free( list );
+ na_gtk_utils_save_window_position( toplevel, wsp_name );
}
/**
diff --git a/src/nact/base-gtk-utils.h b/src/nact/base-gtk-utils.h
index 32e3ec9..0744872 100644
--- a/src/nact/base-gtk-utils.h
+++ b/src/nact/base-gtk-utils.h
@@ -47,6 +47,8 @@ G_BEGIN_DECLS
void base_gtk_utils_restore_window_position( const BaseWindow *window, const gchar *wsp_name );
void base_gtk_utils_save_window_position ( const BaseWindow *window, const gchar *wsp_name );
+/* widget status
+ */
#define NACT_PROP_TOGGLE_EDITABLE "nact-prop-toggle-editable"
void base_gtk_utils_set_editable( GObject *widget, gboolean editable );
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]