window decoration changes applied immediately
authorJean-Philippe Orsini <jeanfi@gmail.com>
Tue, 11 Nov 2014 09:45:38 +0000 (10:45 +0100)
committerJean-Philippe Orsini <jeanfi@gmail.com>
Tue, 11 Nov 2014 09:45:38 +0000 (10:45 +0100)
src/cfg.c
src/cfg.h
src/glade/psensor-pref.glade
src/ui.c
src/ui_pref.c
src/ui_pref.h

index 37048c9..13ea515 100644 (file)
--- a/src/cfg.c
+++ b/src/cfg.c
@@ -328,7 +328,7 @@ static void set_slog_interval(int interval)
        set_int(KEY_SLOG_INTERVAL, interval);
 }
 
-static bool is_window_decoration_enabled(void)
+bool config_is_window_decoration_enabled(void)
 {
        return !get_bool(KEY_INTERFACE_WINDOW_DECORATION_DISABLED);
 }
@@ -338,7 +338,7 @@ static bool is_window_keep_below_enabled(void)
        return get_bool(KEY_INTERFACE_WINDOW_KEEP_BELOW_ENABLED);
 }
 
-static void set_window_decoration_enabled(bool enabled)
+void config_set_window_decoration_enabled(bool enabled)
 {
        set_bool(KEY_INTERFACE_WINDOW_DECORATION_DISABLED, !enabled);
 }
@@ -419,7 +419,6 @@ struct config *config_load(void)
        c->graph_bg_alpha = get_graph_background_alpha();
        c->alpha_channel_enabled = is_alpha_channel_enabled();
        c->sensorlist_position = get_sensorlist_position();
-       c->window_decoration_enabled = is_window_decoration_enabled();
        c->window_keep_below_enabled = is_window_keep_below_enabled();
        c->slog_enabled = is_slog_enabled();
        c->slog_interval = config_get_slog_interval();
@@ -474,7 +473,6 @@ void config_save(const struct config *c)
        set_foreground_color(c->graph_fgcolor);
        set_graph_background_alpha(c->graph_bg_alpha);
        set_sensorlist_position(c->sensorlist_position);
-       set_window_decoration_enabled(c->window_decoration_enabled);
        set_window_keep_below_enabled(c->window_keep_below_enabled);
        set_slog_enabled(c->slog_enabled);
        set_slog_interval(c->slog_interval);
index bbdfd77..1d6e777 100644 (file)
--- a/src/cfg.h
+++ b/src/cfg.h
@@ -47,7 +47,6 @@ struct config {
        /* Position of the sensors list table */
        enum sensorlist_position sensorlist_position;
 
-       bool window_decoration_enabled;
        bool window_keep_below_enabled;
        bool window_restore_enabled;
        /* Last saved position of the window. */
@@ -150,6 +149,9 @@ int config_get_sensor_unit(void);
 
 double config_get_default_high_threshold_temperature(void);
 
+bool config_is_window_decoration_enabled(void);
+void config_set_window_decoration_enabled(bool);
+
 /*
  * Returns the user directory containing psensor data (configuration
  * and log).
index 868c682..4cc27d9 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!-- Generated with glade 3.16.1 -->
+<!-- Generated with glade 3.18.3 -->
 <interface>
   <requires lib="gtk+" version="3.4"/>
   <object class="GtkAdjustment" id="mins">
                     <property name="margin_bottom">4</property>
                     <property name="xalign">0</property>
                     <property name="draw_indicator">True</property>
+                    <signal name="toggled" handler="ui_pref_decoration_toggled_cbk" swapped="no"/>
                   </object>
                   <packing>
                     <property name="left_attach">0</property>
                     <property name="top_attach">0</property>
                     <property name="width">2</property>
-                    <property name="height">1</property>
                   </packing>
                 </child>
                 <child>
                     <property name="left_attach">0</property>
                     <property name="top_attach">1</property>
                     <property name="width">2</property>
-                    <property name="height">1</property>
                   </packing>
                 </child>
                 <child>
                     <property name="left_attach">0</property>
                     <property name="top_attach">2</property>
                     <property name="width">2</property>
-                    <property name="height">1</property>
                   </packing>
                 </child>
                 <child>
                     <property name="left_attach">0</property>
                     <property name="top_attach">3</property>
                     <property name="width">2</property>
-                    <property name="height">1</property>
                   </packing>
                 </child>
                 <child>
                   <packing>
                     <property name="left_attach">1</property>
                     <property name="top_attach">4</property>
-                    <property name="width">1</property>
-                    <property name="height">1</property>
                   </packing>
                 </child>
                 <child>
                   <packing>
                     <property name="left_attach">1</property>
                     <property name="top_attach">5</property>
-                    <property name="width">1</property>
-                    <property name="height">1</property>
                   </packing>
                 </child>
                 <child>
                     <property name="left_attach">0</property>
                     <property name="top_attach">4</property>
                     <property name="width">2</property>
-                    <property name="height">1</property>
                   </packing>
                 </child>
                 <child>
                   <packing>
                     <property name="left_attach">0</property>
                     <property name="top_attach">5</property>
-                    <property name="width">1</property>
-                    <property name="height">1</property>
                   </packing>
                 </child>
               </object>
                   <packing>
                     <property name="left_attach">0</property>
                     <property name="top_attach">0</property>
-                    <property name="width">1</property>
-                    <property name="height">1</property>
                   </packing>
                 </child>
                 <child>
                   <packing>
                     <property name="left_attach">0</property>
                     <property name="top_attach">1</property>
-                    <property name="width">1</property>
-                    <property name="height">1</property>
                   </packing>
                 </child>
                 <child>
                   <packing>
                     <property name="left_attach">0</property>
                     <property name="top_attach">2</property>
-                    <property name="width">1</property>
-                    <property name="height">1</property>
                   </packing>
                 </child>
               </object>
                   <packing>
                     <property name="left_attach">1</property>
                     <property name="top_attach">3</property>
-                    <property name="width">1</property>
-                    <property name="height">1</property>
                   </packing>
                 </child>
                 <child>
                   <packing>
                     <property name="left_attach">0</property>
                     <property name="top_attach">3</property>
-                    <property name="width">1</property>
-                    <property name="height">1</property>
                   </packing>
                 </child>
                 <child>
                   <packing>
                     <property name="left_attach">0</property>
                     <property name="top_attach">4</property>
-                    <property name="width">1</property>
-                    <property name="height">1</property>
                   </packing>
                 </child>
                 <child>
                   <packing>
                     <property name="left_attach">1</property>
                     <property name="top_attach">4</property>
-                    <property name="width">1</property>
-                    <property name="height">1</property>
                   </packing>
                 </child>
                 <child>
                   <packing>
                     <property name="left_attach">0</property>
                     <property name="top_attach">5</property>
-                    <property name="width">1</property>
-                    <property name="height">1</property>
                   </packing>
                 </child>
                 <child>
                     <property name="left_attach">0</property>
                     <property name="top_attach">2</property>
                     <property name="width">2</property>
-                    <property name="height">1</property>
                   </packing>
                 </child>
                 <child>
                   <packing>
                     <property name="left_attach">0</property>
                     <property name="top_attach">7</property>
-                    <property name="width">1</property>
-                    <property name="height">1</property>
                   </packing>
                 </child>
                 <child>
                   <packing>
                     <property name="left_attach">0</property>
                     <property name="top_attach">8</property>
-                    <property name="width">1</property>
-                    <property name="height">1</property>
                   </packing>
                 </child>
                 <child>
                     <property name="left_attach">0</property>
                     <property name="top_attach">6</property>
                     <property name="width">2</property>
-                    <property name="height">1</property>
                   </packing>
                 </child>
                 <child>
                   <packing>
                     <property name="left_attach">1</property>
                     <property name="top_attach">5</property>
-                    <property name="width">1</property>
-                    <property name="height">1</property>
                   </packing>
                 </child>
                 <child>
                   <packing>
                     <property name="left_attach">1</property>
                     <property name="top_attach">8</property>
-                    <property name="width">1</property>
-                    <property name="height">1</property>
                   </packing>
                 </child>
                 <child>
                   <packing>
                     <property name="left_attach">1</property>
                     <property name="top_attach">7</property>
-                    <property name="width">1</property>
-                    <property name="height">1</property>
                   </packing>
                 </child>
                 <child>
                     <property name="left_attach">0</property>
                     <property name="top_attach">1</property>
                     <property name="width">2</property>
-                    <property name="height">1</property>
                   </packing>
                 </child>
                 <child>
                     <property name="left_attach">0</property>
                     <property name="top_attach">0</property>
                     <property name="width">2</property>
-                    <property name="height">1</property>
                   </packing>
                 </child>
               </object>
                   <packing>
                     <property name="left_attach">0</property>
                     <property name="top_attach">0</property>
-                    <property name="width">1</property>
-                    <property name="height">1</property>
                   </packing>
                 </child>
                 <child>
                   <packing>
                     <property name="left_attach">1</property>
                     <property name="top_attach">0</property>
-                    <property name="width">1</property>
-                    <property name="height">1</property>
                   </packing>
                 </child>
                 <child>
                   <packing>
                     <property name="left_attach">2</property>
                     <property name="top_attach">0</property>
-                    <property name="width">1</property>
-                    <property name="height">1</property>
                   </packing>
                 </child>
                 <child>
                     <property name="left_attach">0</property>
                     <property name="top_attach">1</property>
                     <property name="width">3</property>
-                    <property name="height">1</property>
                   </packing>
                 </child>
                 <child>
                   <packing>
                     <property name="left_attach">1</property>
                     <property name="top_attach">2</property>
-                    <property name="width">1</property>
-                    <property name="height">1</property>
                   </packing>
                 </child>
                 <child>
                   <packing>
                     <property name="left_attach">0</property>
                     <property name="top_attach">2</property>
-                    <property name="width">1</property>
-                    <property name="height">1</property>
                   </packing>
                 </child>
                 <child>
                   <packing>
                     <property name="left_attach">2</property>
                     <property name="top_attach">2</property>
-                    <property name="width">1</property>
-                    <property name="height">1</property>
                   </packing>
                 </child>
                 <child>
                   <packing>
                     <property name="left_attach">0</property>
                     <property name="top_attach">3</property>
-                    <property name="width">1</property>
-                    <property name="height">1</property>
                   </packing>
                 </child>
                 <child>
                     <property name="left_attach">1</property>
                     <property name="top_attach">3</property>
                     <property name="width">2</property>
-                    <property name="height">1</property>
                   </packing>
                 </child>
               </object>
                   <packing>
                     <property name="left_attach">0</property>
                     <property name="top_attach">1</property>
-                    <property name="width">1</property>
-                    <property name="height">1</property>
                   </packing>
                 </child>
                 <child>
                   <packing>
                     <property name="left_attach">0</property>
                     <property name="top_attach">3</property>
-                    <property name="width">1</property>
-                    <property name="height">1</property>
                   </packing>
                 </child>
                 <child>
                   <packing>
                     <property name="left_attach">0</property>
                     <property name="top_attach">4</property>
-                    <property name="width">1</property>
-                    <property name="height">1</property>
                   </packing>
                 </child>
                 <child>
                   <packing>
                     <property name="left_attach">0</property>
                     <property name="top_attach">6</property>
-                    <property name="width">1</property>
-                    <property name="height">1</property>
                   </packing>
                 </child>
                 <child>
                   <packing>
                     <property name="left_attach">0</property>
                     <property name="top_attach">8</property>
-                    <property name="width">1</property>
-                    <property name="height">1</property>
                   </packing>
                 </child>
                 <child>
                   <packing>
                     <property name="left_attach">0</property>
                     <property name="top_attach">9</property>
-                    <property name="width">1</property>
-                    <property name="height">1</property>
                   </packing>
                 </child>
                 <child>
                   <packing>
                     <property name="left_attach">0</property>
                     <property name="top_attach">10</property>
-                    <property name="width">1</property>
-                    <property name="height">1</property>
                   </packing>
                 </child>
                 <child>
                   <packing>
                     <property name="left_attach">0</property>
                     <property name="top_attach">11</property>
-                    <property name="width">1</property>
-                    <property name="height">1</property>
                   </packing>
                 </child>
                 <child>
                   <packing>
                     <property name="left_attach">0</property>
                     <property name="top_attach">7</property>
-                    <property name="width">1</property>
-                    <property name="height">1</property>
                   </packing>
                 </child>
                 <child>
                   <packing>
                     <property name="left_attach">0</property>
                     <property name="top_attach">5</property>
-                    <property name="width">1</property>
-                    <property name="height">1</property>
                   </packing>
                 </child>
                 <child>
                   <packing>
                     <property name="left_attach">0</property>
                     <property name="top_attach">2</property>
-                    <property name="width">1</property>
-                    <property name="height">1</property>
                   </packing>
                 </child>
                 <child>
                   <packing>
                     <property name="left_attach">0</property>
                     <property name="top_attach">0</property>
-                    <property name="width">1</property>
-                    <property name="height">1</property>
                   </packing>
                 </child>
               </object>
index fc5f5c3..e81e841 100644 (file)
--- a/src/ui.c
+++ b/src/ui.c
 #include "ui_status.h"
 #include "ui_appindicator.h"
 
+static void set_decoration(GtkWindow *win)
+{
+       gtk_window_set_decorated(win, config_is_window_decoration_enabled());
+}
+
+static void
+decoration_changed_cbk(GSettings *settings, gchar *key, gpointer data)
+{
+       set_decoration((GtkWindow *)data);
+}
+
+static void connect_cbks(GtkWindow *win)
+{
+       log_fct_enter();
+
+       g_signal_connect_after(config_get_GSettings(),
+                              "changed::interface-window-decoration-disabled",
+                              G_CALLBACK(decoration_changed_cbk),
+                              win);
+
+       log_fct_exit();
+}
+
 static void save_window_pos(struct ui_psensor *ui)
 {
        gboolean visible;
@@ -225,8 +248,7 @@ void ui_window_create(struct ui_psensor *ui)
        g_signal_connect(window,
                         "delete_event", G_CALLBACK(on_delete_event_cb), ui);
 
-       gtk_window_set_decorated(GTK_WINDOW(window),
-                                cfg->window_decoration_enabled);
+       set_decoration(GTK_WINDOW(window));
 
        gtk_window_set_keep_below(GTK_WINDOW(window),
                                  cfg->window_keep_below_enabled);
@@ -253,6 +275,8 @@ void ui_window_create(struct ui_psensor *ui)
 
        ui_sensorlist_create(ui);
 
+       connect_cbks(GTK_WINDOW(window));
+
        log_debug("ui_window_create(): show_all");
        gtk_widget_show_all(ui->main_box);
 
index 4594a97..27201ad 100644 (file)
 #include <ui_pref.h>
 #include <ui_unity.h>
 
+void ui_pref_decoration_toggled_cbk(GtkToggleButton *btn, gpointer data)
+{
+       config_set_window_decoration_enabled
+               (!config_is_window_decoration_enabled());
+}
+
 GdkRGBA color_to_GdkRGBA(struct color *color)
 {
        GdkRGBA c;
@@ -131,7 +137,7 @@ void ui_pref_dialog_run(struct ui_psensor *ui)
        w_hide_window_decoration = GTK_TOGGLE_BUTTON
                (gtk_builder_get_object(builder, "hide_window_decoration"));
        gtk_toggle_button_set_active(w_hide_window_decoration,
-                                    !cfg->window_decoration_enabled);
+                                    !config_is_window_decoration_enabled());
 
        w_keep_window_below = GTK_TOGGLE_BUTTON
                (gtk_builder_get_object(builder, "keep_window_below"));
@@ -276,6 +282,8 @@ void ui_pref_dialog_run(struct ui_psensor *ui)
 
        gtk_toggle_button_set_active(w_udisks2, config_is_udisks2_enabled());
 
+       gtk_builder_connect_signals(builder, NULL);
+
        result = gtk_dialog_run(diag);
 
        if (result == GTK_RESPONSE_ACCEPT) {
@@ -310,9 +318,6 @@ void ui_pref_dialog_run(struct ui_psensor *ui)
                cfg->sensorlist_position
                        = gtk_combo_box_get_active(w_sensorlist_pos);
 
-               cfg->window_decoration_enabled =
-                       !gtk_toggle_button_get_active(w_hide_window_decoration);
-
                cfg->window_keep_below_enabled
                        = gtk_toggle_button_get_active(w_keep_window_below);
 
@@ -323,9 +328,6 @@ void ui_pref_dialog_run(struct ui_psensor *ui)
                        = !gtk_toggle_button_get_active
                        (w_enable_launcher_counter);
 
-               gtk_window_set_decorated(GTK_WINDOW(ui->main_window),
-                                        cfg->window_decoration_enabled);
-
                gtk_window_set_keep_below(GTK_WINDOW(ui->main_window),
                                          cfg->window_keep_below_enabled);
 
index 2e669c5..219545a 100644 (file)
@@ -24,4 +24,6 @@
 void ui_pref_dialog_run(struct ui_psensor *);
 GdkRGBA color_to_GdkRGBA(struct color *color);
 
+void ui_pref_decoration_toggled_cbk(GtkToggleButton *, gpointer);
+
 #endif