From 01238dd8ae60d49ebf23feda4b6e1882ae3dd1ac Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Fri, 11 Dec 2015 12:15:03 -0500 Subject: file chooser: Store size more frequently We were only storing the dialog size on unmap, but resetting to the stored default value more often, e.g. on focus-out. This was causing the dialog to 'jump back' to its remembered size after the user manually resized it, leading to frustration and bug reports. Instead, save the dialog size on every ::size-allocate of the toplevel. To avoid needlessly spamming dconf, only write the new value if it changed. --- gtk/gtkfilechooserdialog.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'gtk') diff --git a/gtk/gtkfilechooserdialog.c b/gtk/gtkfilechooserdialog.c index 3f3cf507f8..fa70b08984 100644 --- a/gtk/gtkfilechooserdialog.c +++ b/gtk/gtkfilechooserdialog.c @@ -225,6 +225,8 @@ static void gtk_file_chooser_dialog_notify (GObject *obj static void gtk_file_chooser_dialog_map (GtkWidget *widget); static void gtk_file_chooser_dialog_unmap (GtkWidget *widget); +static void gtk_file_chooser_dialog_size_allocate (GtkWidget *widget, + GtkAllocation *allocation); static void file_chooser_widget_file_activated (GtkFileChooser *chooser, GtkFileChooserDialog *dialog); static void file_chooser_widget_default_size_changed (GtkWidget *widget, @@ -256,6 +258,7 @@ gtk_file_chooser_dialog_class_init (GtkFileChooserDialogClass *class) widget_class->map = gtk_file_chooser_dialog_map; widget_class->unmap = gtk_file_chooser_dialog_unmap; + widget_class->size_allocate = gtk_file_chooser_dialog_size_allocate; gtk_widget_class_set_accessible_role (widget_class, ATK_ROLE_FILE_CHOOSER); @@ -618,6 +621,7 @@ save_dialog_geometry (GtkFileChooserDialog *dialog) { GtkWindow *window; GSettings *settings; + int old_x, old_y, old_width, old_height; int x, y, width, height; settings = _gtk_file_chooser_get_settings_for_widget (GTK_WIDGET (dialog)); @@ -627,8 +631,13 @@ save_dialog_geometry (GtkFileChooserDialog *dialog) gtk_window_get_position (window, &x, &y); gtk_window_get_size (window, &width, &height); - g_settings_set (settings, SETTINGS_KEY_WINDOW_POSITION, "(ii)", x, y); - g_settings_set (settings, SETTINGS_KEY_WINDOW_SIZE, "(ii)", width, height); + g_settings_get (settings, SETTINGS_KEY_WINDOW_POSITION, "(ii)", &old_x, &old_y); + if (old_x != x || old_y != y) + g_settings_set (settings, SETTINGS_KEY_WINDOW_POSITION, "(ii)", x, y); + + g_settings_get (settings, SETTINGS_KEY_WINDOW_SIZE, "(ii)", &old_width, &old_height); + if (old_width != width || old_height != height) + g_settings_set (settings, SETTINGS_KEY_WINDOW_SIZE, "(ii)", width, height); } static void @@ -641,6 +650,16 @@ gtk_file_chooser_dialog_unmap (GtkWidget *widget) GTK_WIDGET_CLASS (gtk_file_chooser_dialog_parent_class)->unmap (widget); } +static void +gtk_file_chooser_dialog_size_allocate (GtkWidget *widget, + GtkAllocation *allocation) +{ + GTK_WIDGET_CLASS (gtk_file_chooser_dialog_parent_class)->size_allocate (widget, allocation); + + if (gtk_widget_is_drawable (widget)) + save_dialog_geometry (GTK_FILE_CHOOSER_DIALOG (widget)); +} + /* We do a signal connection here rather than overriding the method in * class_init because GtkDialog::response is a RUN_LAST signal. We want *our* * handler to be run *first*, regardless of whether the user installs response -- cgit v1.2.1