From a078ca3f5fb2a43191dd2d4de22aefc493edf1ba Mon Sep 17 00:00:00 2001 From: Michael Natterer Date: Mon, 13 May 2013 00:00:57 +0200 Subject: [PATCH] app: change serialization of the right docks width in SWM (again) Use "right-docks-width" and always a positive value instead of "right-docks-position" (as opponsed to "left-docks-width", that distinction is a GtkPaned implementation detail and does not belong into a config file). Parse all old values too. Also fix a glitch in the deserialization code which might fix bug #700147. --- app/display/gimpimagewindow.c | 78 +++++++++++-------- app/tests/gimpdir/sessionrc-2-8-single-window | 2 +- .../gimpdir/sessionrc-expected-single-window | 2 +- 3 files changed, 47 insertions(+), 35 deletions(-) diff --git a/app/display/gimpimagewindow.c b/app/display/gimpimagewindow.c index 8868b3c6da..df0914b8d9 100644 --- a/app/display/gimpimagewindow.c +++ b/app/display/gimpimagewindow.c @@ -66,12 +66,11 @@ #define GIMP_EMPTY_IMAGE_WINDOW_ENTRY_ID "gimp-empty-image-window" #define GIMP_SINGLE_IMAGE_WINDOW_ENTRY_ID "gimp-single-image-window" -/* GtkPaned position of the image area, i.e. the width of the left - * docks area - */ -#define GIMP_IMAGE_WINDOW_LEFT_DOCKS_WIDTH "left-docks-width" +/* The width of the left and right dock areas */ +#define GIMP_IMAGE_WINDOW_LEFT_DOCKS_WIDTH "left-docks-width" +#define GIMP_IMAGE_WINDOW_RIGHT_DOCKS_WIDTH "right-docks-width" -/* GtkPaned position of the right docks area */ +/* deprecated property: GtkPaned position of the right docks area */ #define GIMP_IMAGE_WINDOW_RIGHT_DOCKS_POS "right-docks-position" /* Whether the window's maximized or not */ @@ -827,18 +826,17 @@ gimp_image_window_get_aux_info (GimpSessionManaged *session_managed) g_snprintf (widthbuf, sizeof (widthbuf), "%d", gtk_paned_get_position (GTK_PANED (private->left_hpane))); - aux = gimp_session_info_aux_new (GIMP_IMAGE_WINDOW_LEFT_DOCKS_WIDTH, widthbuf); + aux = gimp_session_info_aux_new (GIMP_IMAGE_WINDOW_LEFT_DOCKS_WIDTH, + widthbuf); aux_info = g_list_append (aux_info, aux); gtk_widget_get_allocation (private->right_hpane, &allocation); - /* a negative number will be interpreted as the width of the second - * child of the pane - */ g_snprintf (widthbuf, sizeof (widthbuf), "%d", - gtk_paned_get_position (GTK_PANED (private->right_hpane)) - - allocation.width); - aux = gimp_session_info_aux_new (GIMP_IMAGE_WINDOW_RIGHT_DOCKS_POS, widthbuf); + allocation.width - + gtk_paned_get_position (GTK_PANED (private->right_hpane))); + aux = gimp_session_info_aux_new (GIMP_IMAGE_WINDOW_RIGHT_DOCKS_WIDTH, + widthbuf); aux_info = g_list_append (aux_info, aux); aux = gimp_session_info_aux_new (GIMP_IMAGE_WINDOW_MAXIMIZED, @@ -851,21 +849,21 @@ gimp_image_window_get_aux_info (GimpSessionManaged *session_managed) } static void -gimp_image_window_set_right_hpane_position (GtkPaned *paned, - GtkAllocation *allocation, - void *data) +gimp_image_window_set_right_docks_width (GtkPaned *paned, + GtkAllocation *allocation, + void *data) { - gint position = GPOINTER_TO_INT (data); + gint width = GPOINTER_TO_INT (data); g_return_if_fail (GTK_IS_PANED (paned)); - if (position > 0) - gtk_paned_set_position (paned, position); + if (width > 0) + gtk_paned_set_position (paned, allocation->width - width); else - gtk_paned_set_position (paned, position + allocation->width); + gtk_paned_set_position (paned, - width); g_signal_handlers_disconnect_by_func (paned, - gimp_image_window_set_right_hpane_position, + gimp_image_window_set_right_docks_width, data); } @@ -875,8 +873,8 @@ gimp_image_window_set_aux_info (GimpSessionManaged *session_managed, { GimpImageWindowPrivate *private; GList *iter; - gint left_docks_width = -1; - gint right_docks_pos = -1; + gint left_docks_width = G_MININT; + gint right_docks_width = G_MININT; gboolean wait_with_right_docks = FALSE; gboolean maximized = FALSE; @@ -891,18 +889,30 @@ gimp_image_window_set_aux_info (GimpSessionManaged *session_managed, if (! strcmp (aux->name, GIMP_IMAGE_WINDOW_LEFT_DOCKS_WIDTH)) width = &left_docks_width; + else if (! strcmp (aux->name, GIMP_IMAGE_WINDOW_RIGHT_DOCKS_WIDTH)) + width = &right_docks_width; else if (! strcmp (aux->name, GIMP_IMAGE_WINDOW_RIGHT_DOCKS_POS)) - width = &right_docks_pos; + width = &right_docks_width; else if (! strcmp (aux->name, GIMP_IMAGE_WINDOW_MAXIMIZED)) if (! g_ascii_strcasecmp (aux->value, "yes")) maximized = TRUE; if (width) sscanf (aux->value, "%d", width); + + /* compat handling for right docks */ + if (! strcmp (aux->name, GIMP_IMAGE_WINDOW_RIGHT_DOCKS_POS)) + { + /* negate the value because negative docks pos means docks width, + * also use the negativenes of a real docks pos as condition below. + */ + *width = - *width; + } } - if (left_docks_width > 0 && - gtk_paned_get_position (GTK_PANED (private->left_hpane)) != left_docks_width) + if (left_docks_width != G_MININT && + gtk_paned_get_position (GTK_PANED (private->left_hpane)) != + left_docks_width) { gtk_paned_set_position (GTK_PANED (private->left_hpane), left_docks_width); @@ -913,26 +923,28 @@ gimp_image_window_set_aux_info (GimpSessionManaged *session_managed, wait_with_right_docks = TRUE; } - if (right_docks_pos > 0 && - gtk_paned_get_position (GTK_PANED (private->right_hpane)) != right_docks_pos) + if (right_docks_width != G_MININT && + gtk_paned_get_position (GTK_PANED (private->right_hpane)) != + right_docks_width) { - if (wait_with_right_docks || right_docks_pos < 0) + if (wait_with_right_docks || right_docks_width > 0) { - /* We must wait on a size allocation before we can set the + /* We must wait for a size allocation before we can set the * position */ g_signal_connect_data (private->right_hpane, "size-allocate", - G_CALLBACK (gimp_image_window_set_right_hpane_position), - GINT_TO_POINTER (right_docks_pos), NULL, + G_CALLBACK (gimp_image_window_set_right_docks_width), + GINT_TO_POINTER (right_docks_width), NULL, G_CONNECT_AFTER); } else { /* We can set the position directly, because we didn't - * change the left hpane position + * change the left hpane position, and we got the old compat + * dock pos property. */ gtk_paned_set_position (GTK_PANED (private->right_hpane), - right_docks_pos); + - right_docks_width); } } diff --git a/app/tests/gimpdir/sessionrc-2-8-single-window b/app/tests/gimpdir/sessionrc-2-8-single-window index a9b618e155..8c603abfaa 100644 --- a/app/tests/gimpdir/sessionrc-2-8-single-window +++ b/app/tests/gimpdir/sessionrc-2-8-single-window @@ -23,7 +23,7 @@ (open-on-exit) (aux-info (left-docks-width "80") - (right-docks-position "200") + (right-docks-width "400") (maximized "no")) (gimp-toolbox (side left)) diff --git a/app/tests/gimpdir/sessionrc-expected-single-window b/app/tests/gimpdir/sessionrc-expected-single-window index e6974e2f0c..c203a1f07e 100644 --- a/app/tests/gimpdir/sessionrc-expected-single-window +++ b/app/tests/gimpdir/sessionrc-expected-single-window @@ -23,7 +23,7 @@ (open-on-exit) (aux-info (left-docks-width "80") - (right-docks-position "-764") + (right-docks-width "400") (maximized "no")) (gimp-toolbox (side left))