[gnome-system-monitor] Do away of window state internal variables



commit 676bdb334468e3427cf974deff2c2c1194cddcce
Author: Stefano Facchini <stefano facchini gmail com>
Date:   Thu Aug 1 16:23:31 2013 +0200

    Do away of window state internal variables
    
    Just use gsettings keys.

 src/interface.cpp   |   23 ++++++++++++-----------
 src/procman-app.cpp |   25 +++++++++----------------
 src/procman-app.h   |    5 -----
 3 files changed, 21 insertions(+), 32 deletions(-)
---
diff --git a/src/interface.cpp b/src/interface.cpp
index e073f51..f032845 100644
--- a/src/interface.cpp
+++ b/src/interface.cpp
@@ -574,12 +574,13 @@ cb_main_window_delete (GtkWidget *window, GdkEvent *event, gpointer data)
 void
 create_main_window (ProcmanApp *app)
 {
-    gint width, height, xpos, ypos;
     GtkWidget *main_window;
     GtkWidget *stack;
     GtkWidget *process_menu_button;
     GMenuModel *process_menu_model;
 
+    int width, height, xpos, ypos;
+
     GtkBuilder *builder = gtk_builder_new();
     gtk_builder_add_from_resource (builder, "/org/gnome/gnome-system-monitor/data/interface.ui", NULL);
     gtk_builder_add_from_resource (builder, "/org/gnome/gnome-system-monitor/data/menus.ui", NULL);
@@ -589,6 +590,16 @@ create_main_window (ProcmanApp *app)
     gtk_widget_set_name (main_window, "gnome-system-monitor");
     app->main_window = main_window;
 
+    g_settings_get (app->settings, "window-state", "(iiii)",
+                    &width, &height, &xpos, &ypos);
+    width = CLAMP (width, 50, gdk_screen_width ());
+    height = CLAMP (height, 50, gdk_screen_height ());
+
+    gtk_window_set_default_size (GTK_WINDOW (main_window), width, height);
+    gtk_window_move (GTK_WINDOW (main_window), xpos, ypos);
+    if (g_settings_get_boolean (app->settings, "maximized"))
+        gtk_window_maximize (GTK_WINDOW (main_window));
+
     app->process_menu_button = process_menu_button = GTK_WIDGET (gtk_builder_get_object (builder, 
"process_menu_button"));
     process_menu_model = G_MENU_MODEL (gtk_builder_get_object (builder, "process-window-menu"));
     gtk_menu_button_set_menu_model (GTK_MENU_BUTTON (process_menu_button), process_menu_model);
@@ -623,16 +634,6 @@ create_main_window (ProcmanApp *app)
     if (visual)
         gtk_widget_set_visual(main_window, visual);
 
-    width = app->config.width;
-    height = app->config.height;
-    xpos = app->config.xpos;
-    ypos = app->config.ypos;
-    gtk_window_set_default_size (GTK_WINDOW (main_window), width, height);
-    gtk_window_move(GTK_WINDOW (main_window), xpos, ypos);
-    if (app->config.maximized) {
-        gtk_window_maximize(GTK_WINDOW(main_window));
-    }
-
     /* create the main stack */
     app->stack = stack = GTK_WIDGET (gtk_builder_get_object (builder, "stack"));
 
diff --git a/src/procman-app.cpp b/src/procman-app.cpp
index 561db0e..f27141e 100644
--- a/src/procman-app.cpp
+++ b/src/procman-app.cpp
@@ -203,17 +203,11 @@ void
 ProcmanApp::load_settings()
 {
     gchar *color;
-    gint swidth, sheight;
     gint i;
     glibtop_cpu cpu;
 
     settings = g_settings_new (GSM_GSETTINGS_SCHEMA);
 
-    g_settings_get (settings, "window-state", "(iiii)",
-                    &config.width, &config.height, &config.xpos, &config.ypos);
-
-    config.maximized = g_settings_get_boolean (settings, "maximized");
-
     g_signal_connect (G_OBJECT(settings), "changed::show-dependencies", 
G_CALLBACK(cb_show_dependencies_changed), this);
 
     config.solaris_mode = g_settings_get_boolean(settings, procman::settings::solaris_mode.c_str());
@@ -295,10 +289,6 @@ ProcmanApp::load_settings()
     g_free (color);
 
     /* Sanity checks */
-    swidth = gdk_screen_width ();
-    sheight = gdk_screen_height ();
-    config.width = CLAMP (config.width, 50, swidth);
-    config.height = CLAMP (config.height, 50, sheight);
     config.update_interval = MAX (config.update_interval, 1000);
     config.graph_update_interval = MAX (config.graph_update_interval, 250);
     config.disks_update_interval = MAX (config.disks_update_interval, 1000);
@@ -503,16 +493,19 @@ procman_save_tree_state (GSettings *settings, GtkWidget *tree, const gchar *chil
 void
 ProcmanApp::save_config ()
 {
-    config.width  = gdk_window_get_width (gtk_widget_get_window (main_window));
-    config.height = gdk_window_get_height(gtk_widget_get_window (main_window));
-    gtk_window_get_position(GTK_WINDOW(main_window), &config.xpos, &config.ypos);
+    int width, height, xpos, ypos;
+    gboolean maximized;
+
+    width  = gdk_window_get_width (gtk_widget_get_window (main_window));
+    height = gdk_window_get_height (gtk_widget_get_window (main_window));
+    gtk_window_get_position (GTK_WINDOW (main_window), &xpos, &ypos);
 
-    config.maximized = gdk_window_get_state(gtk_widget_get_window (main_window)) & 
GDK_WINDOW_STATE_MAXIMIZED;
+    maximized = gdk_window_get_state (gtk_widget_get_window (main_window)) & GDK_WINDOW_STATE_MAXIMIZED;
 
     g_settings_set (settings, "window-state", "(iiii)",
-                    config.width, config.height, config.xpos, config.ypos);
+                    width, height, xpos, ypos);
 
-    g_settings_set_boolean (settings, "maximized", config.maximized);
+    g_settings_set_boolean (settings, "maximized", maximized);
 }
 
 int ProcmanApp::on_command_line(const Glib::RefPtr<Gio::ApplicationCommandLine>& command_line)
diff --git a/src/procman-app.h b/src/procman-app.h
index 7315a42..4067adb 100644
--- a/src/procman-app.h
+++ b/src/procman-app.h
@@ -27,11 +27,6 @@ enum ProcmanTab
 
 struct ProcConfig
 {
-    gint            width;
-    gint            height;
-    gint            xpos;
-    gint            ypos;
-    gboolean        maximized;
     gboolean        show_all_fs;
     int             update_interval;
     int             graph_update_interval;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]