made layout setting dynamic
authorJean-Philippe Orsini <jeanfi@gmail.com>
Wed, 19 Nov 2014 09:26:48 +0000 (10:26 +0100)
committerJean-Philippe Orsini <jeanfi@gmail.com>
Wed, 19 Nov 2014 09:26:48 +0000 (10:26 +0100)
src/cfg.c
src/cfg.h
src/glade/psensor-pref.glade
src/main.c
src/ui.c
src/ui.h
src/ui_graph.c
src/ui_pref.c

index 14267dc..6ee3b49 100644 (file)
--- a/src/cfg.c
+++ b/src/cfg.c
@@ -237,12 +237,12 @@ static void set_alpha_channeld_enabled(bool b)
        set_bool(KEY_ALPHA_CHANNEL_ENABLED, b);
 }
 
-static enum sensorlist_position get_sensorlist_position(void)
+enum sensorlist_position config_get_sensorlist_position(void)
 {
        return get_int(KEY_INTERFACE_SENSORLIST_POSITION);
 }
 
-static void set_sensorlist_position(enum sensorlist_position pos)
+void config_set_sensorlist_position(enum sensorlist_position pos)
 {
        set_int(KEY_INTERFACE_SENSORLIST_POSITION, pos);
 }
@@ -418,7 +418,6 @@ struct config *config_load(void)
        c->graph_fgcolor = get_foreground_color();
        c->graph_bg_alpha = get_graph_background_alpha();
        c->alpha_channel_enabled = is_alpha_channel_enabled();
-       c->sensorlist_position = get_sensorlist_position();
        c->slog_enabled = is_slog_enabled();
        c->slog_interval = config_get_slog_interval();
 
@@ -436,11 +435,6 @@ struct config *config_load(void)
        if (c->graph_monitoring_duration < 1)
                c->graph_monitoring_duration = 10;
 
-       c->unity_launcher_count_disabled
-               = get_bool(KEY_INTERFACE_UNITY_LAUNCHER_COUNT_DISABLED);
-
-       c->hide_on_startup = get_bool(KEY_INTERFACE_HIDE_ON_STARTUP);
-
        c->window_restore_enabled
                = get_bool(KEY_INTERFACE_WINDOW_RESTORE_ENABLED);
 
@@ -467,7 +461,6 @@ void config_save(const struct config *c)
        set_background_color(c->graph_bgcolor);
        set_foreground_color(c->graph_fgcolor);
        set_graph_background_alpha(c->graph_bg_alpha);
-       set_sensorlist_position(c->sensorlist_position);
        set_slog_enabled(c->slog_enabled);
        set_slog_interval(c->slog_interval);
 
@@ -477,9 +470,6 @@ void config_save(const struct config *c)
 
        set_int(KEY_SENSOR_UPDATE_INTERVAL, c->sensor_update_interval);
 
-       set_bool(KEY_INTERFACE_UNITY_LAUNCHER_COUNT_DISABLED,
-                c->unity_launcher_count_disabled);
-
        set_bool(KEY_INTERFACE_HIDE_ON_STARTUP, c->hide_on_startup);
 
        set_bool(KEY_INTERFACE_WINDOW_RESTORE_ENABLED,
index bde8af4..496940f 100644 (file)
--- a/src/cfg.h
+++ b/src/cfg.h
@@ -44,9 +44,6 @@ struct config {
 
        bool alpha_channel_enabled;
 
-       /* Position of the sensors list table */
-       enum sensorlist_position sensorlist_position;
-
        bool window_restore_enabled;
        /* Last saved position of the window. */
        int window_x;
@@ -63,8 +60,6 @@ struct config {
        int sensor_values_max_length;
        int sensor_update_interval;
 
-       bool unity_launcher_count_disabled;
-
        int hide_on_startup;
 
        bool slog_enabled;
@@ -157,6 +152,9 @@ void config_set_menu_bar_enabled(bool);
 bool config_is_count_visible(void);
 void config_set_count_visible(bool);
 
+enum sensorlist_position config_get_sensorlist_position(void);
+void config_set_sensorlist_position(enum sensorlist_position pos);
+
 /*
  * Returns the user directory containing psensor data (configuration
  * and log).
index eb05a71..903776d 100644 (file)
                     <property name="margin_bottom">4</property>
                     <property name="model">position_list_store</property>
                     <property name="active">0</property>
+                    <signal name="changed" handler="ui_pref_sensorlist_position_changed_cbk" swapped="no"/>
                     <child>
                       <object class="GtkCellRendererText" id="cellrenderertext1"/>
                       <attributes>
index defc60d..6037469 100644 (file)
@@ -192,7 +192,7 @@ static gboolean ui_refresh_thread(gpointer data)
 
        pmutex_lock(&ui->sensors_mutex);
 
-       graph_update(ui->sensors, ui->w_graph, ui->config, ui->main_window);
+       graph_update(ui->sensors, ui_get_graph(), ui->config, ui->main_window);
 
        ui_sensorlist_update(ui, 0);
 
index 3a83f9c..61641f8 100644 (file)
--- a/src/ui.c
+++ b/src/ui.c
 #include <ui_sensorpref.h>
 #include <ui_status.h>
 
+static GtkWidget *w_sensors_scrolled_tree;
+static GtkWidget *w_graph;
+static GtkContainer *w_sensor_box;
+static GtkContainer *w_main_box;
+
+static void update_layout(void)
+{
+       enum sensorlist_position sensorlist_pos;
+
+       g_object_ref(w_sensors_scrolled_tree);
+       g_object_ref(w_graph);
+
+       gtk_container_remove(w_sensor_box,
+                            w_sensors_scrolled_tree);
+
+       gtk_container_remove(w_sensor_box, w_graph);
+
+       gtk_container_remove(w_main_box, GTK_WIDGET(w_sensor_box));
+
+       sensorlist_pos = config_get_sensorlist_position();
+       if (sensorlist_pos == SENSORLIST_POSITION_RIGHT
+           || sensorlist_pos == SENSORLIST_POSITION_LEFT)
+               w_sensor_box
+                       = GTK_PANED(gtk_paned_new(GTK_ORIENTATION_HORIZONTAL));
+       else
+               w_sensor_box
+                       = GTK_PANED(gtk_paned_new(GTK_ORIENTATION_VERTICAL));
+
+       gtk_box_pack_end(GTK_BOX(w_main_box),
+                        GTK_WIDGET(w_sensor_box), TRUE, TRUE, 2);
+
+       if (sensorlist_pos == SENSORLIST_POSITION_RIGHT
+           || sensorlist_pos == SENSORLIST_POSITION_BOTTOM) {
+               gtk_paned_pack1(w_sensor_box, w_graph, TRUE, TRUE);
+               gtk_paned_pack2(w_sensor_box,
+                               w_sensors_scrolled_tree,
+                               FALSE,
+                               TRUE);
+       } else {
+               gtk_paned_pack1(w_sensor_box,
+                               w_sensors_scrolled_tree,
+                               FALSE,
+                               TRUE);
+               gtk_paned_pack2(w_sensor_box, w_graph, TRUE, TRUE);
+       }
+
+       g_object_unref(w_sensors_scrolled_tree);
+       g_object_unref(w_graph);
+
+       gtk_widget_show_all(GTK_WIDGET(w_sensor_box));
+}
+
 static void set_decoration(GtkWindow *win)
 {
        gtk_window_set_decorated(win, config_is_window_decoration_enabled());
@@ -64,6 +116,12 @@ menu_bar_changed_cbk(GSettings *settings, gchar *key, gpointer data)
        set_menu_bar_enabled(GTK_WIDGET(data));
 }
 
+static void
+sensorlist_position_changed_cbk(GSettings *settings, gchar *key, gpointer data)
+{
+       update_layout();
+}
+
 static void connect_cbks(GtkWindow *win, GtkWidget *menu_bar)
 {
        log_fct_enter();
@@ -83,6 +141,12 @@ static void connect_cbks(GtkWindow *win, GtkWidget *menu_bar)
                               G_CALLBACK(menu_bar_changed_cbk),
                               menu_bar);
 
+       g_signal_connect_after(config_get_GSettings(),
+                              "changed::interface-sensorlist-position",
+                              G_CALLBACK(sensorlist_position_changed_cbk),
+                              menu_bar);
+
+
        log_fct_exit();
 }
 
@@ -111,7 +175,7 @@ static void save_window_pos(struct ui_psensor *ui)
                log_debug("Window size: %d %d", cfg->window_w, cfg->window_h);
 
                cfg->window_divider_pos
-                       = gtk_paned_get_position(GTK_PANED(ui->sensor_box));
+                       = gtk_paned_get_position(GTK_PANED(w_sensor_box));
 
                config_save(cfg);
        }
@@ -287,21 +351,21 @@ void ui_window_create(struct ui_psensor *ui)
        set_keep_below(GTK_WINDOW(window));
 
        menu_bar = GTK_WIDGET(gtk_builder_get_object(builder, "menu_bar"));
-       ui->main_box = GTK_WIDGET(gtk_builder_get_object(builder, "main_box"));
+       w_main_box = GTK_CONTAINER(gtk_builder_get_object(builder, "main_box"));
        ui->popup_menu = GTK_WIDGET(gtk_builder_get_object(builder,
                                                           "popup_menu"));
        g_object_ref(G_OBJECT(ui->popup_menu));
        ui->main_window = window;
-       ui->w_graph = GTK_WIDGET(gtk_builder_get_object(builder, "graph"));
+       w_graph = GTK_WIDGET(gtk_builder_get_object(builder, "graph"));
        ui_graph_create(ui);
 
-       ui->sensor_box = GTK_PANED(gtk_builder_get_object(builder,
-                                                         "sensor_box"));
+       w_sensor_box = GTK_PANED(gtk_builder_get_object(builder,
+                                                       "sensor_box"));
        ui->sensors_store = GTK_LIST_STORE(gtk_builder_get_object
                                           (builder, "sensors_store"));
        ui->sensors_tree = GTK_TREE_VIEW(gtk_builder_get_object
                                         (builder, "sensors_tree"));
-       ui->sensors_scrolled_tree
+       w_sensors_scrolled_tree
                = GTK_SCROLLED_WINDOW(gtk_builder_get_object
                                      (builder, "sensors_scrolled_tree"));
 
@@ -310,7 +374,8 @@ void ui_window_create(struct ui_psensor *ui)
        connect_cbks(GTK_WINDOW(window), menu_bar);
 
        log_debug("ui_window_create(): show_all");
-       gtk_widget_show_all(ui->main_box);
+       update_layout();
+       gtk_widget_show_all(GTK_WIDGET(w_main_box));
        set_menu_bar_enabled(menu_bar);
 
        g_object_unref(G_OBJECT(builder));
@@ -321,55 +386,15 @@ void ui_window_create(struct ui_psensor *ui)
 void ui_window_update(struct ui_psensor *ui)
 {
        struct config *cfg;
+       enum sensorlist_position sensorlist_pos;
 
        log_debug("ui_window_update()");
 
        cfg = ui->config;
 
-       g_object_ref(GTK_WIDGET(ui->sensors_scrolled_tree));
-       g_object_ref(GTK_WIDGET(ui->w_graph));
-
-       gtk_container_remove(GTK_CONTAINER(ui->sensor_box),
-                            GTK_WIDGET(ui->sensors_scrolled_tree));
-
-       gtk_container_remove(GTK_CONTAINER(ui->sensor_box), ui->w_graph);
-
-       gtk_container_remove(GTK_CONTAINER(ui->main_box),
-                            GTK_WIDGET(ui->sensor_box));
-
-       if (cfg->sensorlist_position == SENSORLIST_POSITION_RIGHT
-           || cfg->sensorlist_position == SENSORLIST_POSITION_LEFT)
-               ui->sensor_box
-                       = GTK_PANED(gtk_paned_new(GTK_ORIENTATION_HORIZONTAL));
-       else
-               ui->sensor_box
-                       = GTK_PANED(gtk_paned_new(GTK_ORIENTATION_VERTICAL));
-
-       gtk_box_pack_end(GTK_BOX(ui->main_box),
-                        GTK_WIDGET(ui->sensor_box), TRUE, TRUE, 2);
-
-       if (cfg->sensorlist_position == SENSORLIST_POSITION_RIGHT
-           || cfg->sensorlist_position == SENSORLIST_POSITION_BOTTOM) {
-               gtk_paned_pack1(ui->sensor_box,
-                               GTK_WIDGET(ui->w_graph), TRUE, TRUE);
-               gtk_paned_pack2(ui->sensor_box,
-                               GTK_WIDGET(ui->sensors_scrolled_tree),
-                               FALSE, TRUE);
-       } else {
-               gtk_paned_pack1(ui->sensor_box,
-                               GTK_WIDGET(ui->sensors_scrolled_tree),
-                               FALSE, TRUE);
-               gtk_paned_pack2(ui->sensor_box,
-                               GTK_WIDGET(ui->w_graph), TRUE, TRUE);
-       }
-
        if (cfg->window_restore_enabled)
-               gtk_paned_set_position(ui->sensor_box, cfg->window_divider_pos);
-
-       g_object_unref(GTK_WIDGET(ui->sensors_scrolled_tree));
-       g_object_unref(GTK_WIDGET(ui->w_graph));
+               gtk_paned_set_position(w_sensor_box, cfg->window_divider_pos);
 
-       gtk_widget_show_all(GTK_WIDGET(ui->sensor_box));
 }
 
 void ui_window_show(struct ui_psensor *ui)
@@ -405,3 +430,8 @@ struct psensor **ui_get_sensors_ordered_by_position(struct psensor **sensors)
 
        return result;
 }
+
+GtkWidget *ui_get_graph(void)
+{
+       return w_graph;
+}
index 26229d3..42f2af7 100644 (file)
--- a/src/ui.h
+++ b/src/ui.h
@@ -39,29 +39,14 @@ struct ui_psensor {
        /* mutex which MUST be used for accessing sensors.*/
        pthread_mutex_t sensors_mutex;
 
-       GtkWidget *w_graph;
-
        struct config *config;
 
        GtkWidget *main_window;
 
        GtkWidget *popup_menu;
 
-       /*
-        * The main vertical box, top contains the menubar, bottom
-        * contains the sensor_box.
-        */
-       GtkWidget *main_box;
-
-       /*
-        * The box which contains the sensors graph and the sensors
-        * information list.
-        */
-       GtkPaned *sensor_box;
-
        GtkListStore *sensors_store;
        GtkTreeView *sensors_tree;
-       GtkScrolledWindow *sensors_scrolled_tree;
 
        int graph_update_interval;
 };
@@ -96,5 +81,7 @@ void ui_cb_about(GtkMenuItem *mi, gpointer data);
 void ui_cb_menu_quit(GtkMenuItem *mi, gpointer data);
 void ui_cb_sensor_preferences(GtkMenuItem *mi, gpointer data);
 
+GtkWidget *ui_get_graph(void);
+
 struct psensor **ui_get_sensors_ordered_by_position(struct psensor **);
 #endif
index 0ea7bfe..31db689 100644 (file)
@@ -38,7 +38,7 @@ on_expose_event(GtkWidget *widget, GdkEventExpose *event, gpointer data)
        struct ui_psensor *ui_psensor = (struct ui_psensor *)data;
 
        graph_update(ui_psensor->sensors,
-                    ui_psensor->w_graph,
+                    ui_get_graph(),
                     ui_psensor->config,
                     ui_psensor->main_window);
 
@@ -56,7 +56,7 @@ void ui_graph_create(struct ui_psensor *ui)
 
        log_debug("ui_graph_create()");
 
-       w_graph = ui->w_graph;
+       w_graph = ui_get_graph();
 
        is_smooth_curves_enabled = config_is_smooth_curves_enabled();
        g_signal_connect_after(config_get_GSettings(),
index 3a181c3..cbb5986 100644 (file)
@@ -60,6 +60,11 @@ void ui_pref_count_visible_toggled_cbk(GtkToggleButton *btn, gpointer data)
        config_set_count_visible(gtk_toggle_button_get_active(btn));
 }
 
+void ui_pref_sensorlist_position_changed_cbk(GtkComboBox *combo, gpointer data)
+{
+       config_set_sensorlist_position(gtk_combo_box_get_active(combo));
+}
+
 GdkRGBA color_to_GdkRGBA(struct color *color)
 {
        GdkRGBA c;
@@ -163,7 +168,8 @@ void ui_pref_dialog_run(struct ui_psensor *ui)
 
        w_sensorlist_pos = GTK_COMBO_BOX
                (gtk_builder_get_object(builder, "sensors_list_position"));
-       gtk_combo_box_set_active(w_sensorlist_pos, cfg->sensorlist_position);
+       gtk_combo_box_set_active(w_sensorlist_pos,
+                                config_get_sensorlist_position());
 
        w_autostart = GTK_TOGGLE_BUTTON
                (gtk_builder_get_object(builder, "autostart"));
@@ -177,7 +183,7 @@ void ui_pref_dialog_run(struct ui_psensor *ui)
        w_enable_launcher_counter = GTK_TOGGLE_BUTTON
                (gtk_builder_get_object(builder, "enable_launcher_counter"));
        gtk_toggle_button_set_active(w_enable_launcher_counter,
-                                    !cfg->unity_launcher_count_disabled);
+                                    !config_is_count_visible());
 
        if (ui_unity_is_supported()) {
                gtk_widget_set_has_tooltip
@@ -337,13 +343,6 @@ void ui_pref_dialog_run(struct ui_psensor *ui)
                else
                        cfg->alpha_channel_enabled = 1;
 
-               cfg->sensorlist_position
-                       = gtk_combo_box_get_active(w_sensorlist_pos);
-
-               cfg->unity_launcher_count_disabled
-                       = !gtk_toggle_button_get_active
-                       (w_enable_launcher_counter);
-
                cfg->sensor_update_interval
                        = gtk_spin_button_get_value_as_int(w_s_update_interval);