Commit d4654dd1 authored by Matthias Clasen's avatar Matthias Clasen

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
parent a8a33b71
......@@ -230,6 +230,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,
......@@ -261,6 +263,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);
......@@ -623,6 +626,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));
......@@ -632,8 +636,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
......@@ -646,6 +655,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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment