From 754433d884569f2c496aef52c93107fc4448fbf5 Mon Sep 17 00:00:00 2001 From: "Gergely POLONKAI (W00d5t0ck)" Date: Sat, 21 Sep 2013 19:27:14 +0200 Subject: [PATCH] Window settings are now saved when a window is repositioned or resized --- src/ag-window.c | 29 +++++++++++++++++++++++++++++ src/ag-window.h | 2 ++ 2 files changed, 31 insertions(+) diff --git a/src/ag-window.c b/src/ag-window.c index c69c985..9123f2f 100644 --- a/src/ag-window.c +++ b/src/ag-window.c @@ -503,6 +503,16 @@ window_populate(AgWindow *window) gtk_widget_show_all(priv->grid); } +static gboolean +ag_window_configure_event_cb(GtkWidget *widget, GdkEventConfigure *event, gpointer user_data) +{ + AgWindow *window = AG_WINDOW(widget); + + ag_window_settings_save(GTK_WINDOW(window), ag_settings_peek_window_settings(window->priv->settings)); + + return FALSE; +} + GtkWidget * ag_window_new(AgApp *app) { @@ -515,6 +525,7 @@ ag_window_new(AgApp *app) window_populate(window); gtk_window_set_icon_name(GTK_WINDOW(window), "astrognome"); + g_signal_connect(window, "configure-event", G_CALLBACK(ag_window_configure_event_cb), NULL); ag_window_settings_restore(GTK_WINDOW(window), ag_settings_peek_window_settings(window->priv->settings)); @@ -587,3 +598,21 @@ ag_window_settings_restore(GtkWindow *window, GSettings *settings) } } +void +ag_window_settings_save(GtkWindow *window, GSettings *settings) +{ + GdkWindowState state; + gint width, + height; + gboolean maximized; + + state = gdk_window_get_state(gtk_widget_get_window(GTK_WIDGET(window))); + maximized = ((state & GDK_WINDOW_STATE_MAXIMIZED) == GDK_WINDOW_STATE_MAXIMIZED); + + g_settings_set_boolean(settings, "maximized", maximized); + + gtk_window_get_size(window, &width, &height); + g_settings_set_int(settings, "width", width); + g_settings_set_int(settings, "height", height); +} + diff --git a/src/ag-window.h b/src/ag-window.h index 647a631..ef33e80 100644 --- a/src/ag-window.h +++ b/src/ag-window.h @@ -43,6 +43,8 @@ void ag_window_set_uri(AgWindow *window, gchar *ag_window_get_uri(AgWindow *window); void ag_window_settings_restore(GtkWindow *window, GSettings *settings); +void ag_window_settings_save(GtkWindow *window, + GSettings *settings); #define AG_WINDOW_ERROR (ag_window_error_quark()) GQuark ag_window_error_quark(void);