summaryrefslogtreecommitdiff
path: root/shell/cc-window.c
diff options
context:
space:
mode:
author1pav <40791-1pav@users.noreply.gitlab.gnome.org>2021-08-07 12:11:51 +0200
committerGeorges Basile Stavracas Neto <georges.stavracas@gmail.com>2021-09-24 20:42:06 -0300
commitf89a48a980a59dce863647c9adbd780c116a859e (patch)
tree08ad34b49e51d5548bbee40e851871037e771f88 /shell/cc-window.c
parentc1cfe525270872ae2fe15cef834d22eb14e76bc9 (diff)
downloadgnome-control-center-f89a48a980a59dce863647c9adbd780c116a859e.tar.gz
window: Save application window state
Currently the window state (width, height, maximized) is not preserved across application restarts. These changes implement window state saving/restoring by leveraging the GSettings API. Fixes https://gitlab.gnome.org/GNOME/gnome-control-center/-/issues/1293
Diffstat (limited to 'shell/cc-window.c')
-rw-r--r--shell/cc-window.c80
1 files changed, 80 insertions, 0 deletions
diff --git a/shell/cc-window.c b/shell/cc-window.c
index de4eccc04..6e72ef7ca 100644
--- a/shell/cc-window.c
+++ b/shell/cc-window.c
@@ -82,6 +82,10 @@ struct _CcWindow
GSettings *settings;
CcPanelListView previous_list_view;
+
+ gint current_width;
+ gint current_height;
+ gboolean is_maximized;
};
static void cc_shell_iface_init (CcShellInterface *iface);
@@ -97,6 +101,33 @@ enum
};
/* Auxiliary methods */
+static void
+store_window_state (CcWindow *self)
+{
+ g_settings_set (self->settings,
+ "window-state",
+ "(iib)",
+ self->current_width,
+ self->current_height,
+ self->is_maximized);
+}
+
+static void
+load_window_state (CcWindow *self)
+{
+ g_settings_get (self->settings,
+ "window-state",
+ "(iib)",
+ &self->current_width,
+ &self->current_height,
+ &self->is_maximized);
+
+ if (self->current_width != -1 && self->current_height != -1)
+ gtk_window_set_default_size (GTK_WINDOW (self), self->current_width, self->current_height);
+ if (self->is_maximized)
+ gtk_window_maximize (GTK_WINDOW (self));
+}
+
static gboolean
in_flatpak_sandbox (void)
{
@@ -676,6 +707,39 @@ on_development_warning_dialog_responded_cb (CcWindow *self)
gtk_widget_hide (GTK_WIDGET (self->development_warning_dialog));
}
+static void
+on_window_size_allocate (GtkWidget *widget,
+ GtkAllocation *allocation)
+{
+ CcWindow *self = CC_WINDOW (widget);
+
+ GTK_WIDGET_CLASS (cc_window_parent_class)->size_allocate (widget, allocation);
+
+ if (!self->is_maximized)
+ gtk_window_get_size (GTK_WINDOW (widget), &self->current_width, &self->current_height);
+}
+
+static gboolean
+on_window_state_event (GtkWidget *widget,
+ GdkEventWindowState *event)
+{
+ CcWindow *self = CC_WINDOW (widget);
+
+ self->is_maximized = (event->new_window_state & GDK_WINDOW_STATE_MAXIMIZED) != 0;
+
+ return GTK_WIDGET_CLASS (cc_window_parent_class)->window_state_event (widget, event);
+}
+
+static void
+on_window_destroy (GtkWidget *widget)
+{
+ CcWindow *self = CC_WINDOW (widget);
+
+ store_window_state (self);
+
+ GTK_WIDGET_CLASS (cc_window_parent_class)->destroy (widget);
+}
+
/* CcShell implementation */
static gboolean
cc_window_set_active_panel_from_id (CcShell *shell,
@@ -801,6 +865,8 @@ cc_window_constructed (GObject *object)
CcWindow *self = CC_WINDOW (object);
g_autofree char *id = NULL;
+ load_window_state (self);
+
/* Add the panels */
setup_model (self);
@@ -817,6 +883,20 @@ cc_window_constructed (GObject *object)
G_CALLBACK (update_headerbar_buttons),
self);
+ g_signal_connect (self,
+ "size-allocate",
+ G_CALLBACK (on_window_size_allocate),
+ NULL);
+
+ g_signal_connect (self,
+ "window-state-event",
+ G_CALLBACK (on_window_state_event),
+ NULL);
+ g_signal_connect (self,
+ "destroy",
+ G_CALLBACK (on_window_destroy),
+ NULL);
+
update_headerbar_buttons (self);
show_sidebar (self);