[Xfce4-commits] [panel-plugins/xfce4-hardware-monitor-plugin] 44/96: Properly implement use background color and background color settings

noreply at xfce.org noreply at xfce.org
Thu Nov 27 22:20:49 CET 2014


This is an automated email from the git hooks/post-receive script.

nick pushed a commit to branch master
in repository panel-plugins/xfce4-hardware-monitor-plugin.

commit 0c55b181f70133bb2c53e92ef6bb30fd4f15dbdd
Author: Omega Weapon <OmegaPhil at gmail.com>
Date:   Wed Nov 6 22:03:57 2013 +0000

    Properly implement use background color and background color settings
---
 src/applet.cpp             |   34 +++++++++++++++++++++++++++-------
 src/applet.hpp             |    8 ++++----
 src/preferences-window.cpp |   43 ++++++++++++++++++++++++++++++-------------
 src/preferences-window.hpp |    4 ++--
 4 files changed, 63 insertions(+), 26 deletions(-)

diff --git a/src/applet.cpp b/src/applet.cpp
index 7cad597..cf2cb30 100644
--- a/src/applet.cpp
+++ b/src/applet.cpp
@@ -202,7 +202,7 @@ Applet::Applet(XfcePanelPlugin *plugin)
   }
 
   // Configuring viewer type
-  viewer_type_listener(viewer_type, use_background_color, background_color);
+  viewer_type_listener(viewer_type);
 
   /* Actually setting the viewer size has no effect in this function -
    * seems that it needs to be done in or after the mainloop kicks off */
@@ -294,9 +294,7 @@ void Applet::set_view(View *v)
     view->attach(*i);
 }
 
-// Note that the last two parameters have defaults in the declaration
-void Applet::viewer_type_listener(const Glib::ustring viewer_type,
-  bool use_background_color, int background_color)
+void Applet::viewer_type_listener(const Glib::ustring viewer_type)
 {
   if (viewer_type == "curve")
   {
@@ -340,14 +338,36 @@ void Applet::viewer_type_listener(const Glib::ustring viewer_type,
       set_view(new ColumnView);
   }
 
-  // Setting the view background colour if desired
-  if (use_background_color)
-      view->set_background(background_color);
+  // Make sure the view sets the background
+  background_color_listener(background_color);
 
   // Update recorded viewer type
   this->viewer_type = viewer_type;
 }
 
+void Applet::background_color_listener(unsigned int background_color)
+{
+  if (use_background_color && view.get())
+    view->set_background(background_color);
+
+  // Update background_color
+  this->background_color = background_color;
+}
+
+void Applet::use_background_color_listener(gboolean use_background_color)
+{
+  if (view.get())
+  {
+    if (use_background_color)
+      view->set_background(background_color);
+    else
+      view->unset_background();
+  }
+
+  // Update use_background_color
+  this->use_background_color = use_background_color;
+}
+
 bool Applet::main_loop()
 {
   // Update view
diff --git a/src/applet.hpp b/src/applet.hpp
index 7eaa05b..8f8bd2a 100644
--- a/src/applet.hpp
+++ b/src/applet.hpp
@@ -70,10 +70,10 @@ public:
   void set_viewer_size(const int size);
   const Glib::ustring get_viewer_font();
   void set_viewer_font(const Glib::ustring font_name);
-  void viewer_type_listener(const Glib::ustring viewer_type,
-    bool use_background_color = false,
-    int background_color = 0);
-
+  void viewer_type_listener(const Glib::ustring viewer_type);
+  void background_color_listener(unsigned int background_color);
+  void use_background_color_listener(gboolean use_background_color);
+  
   Glib::RefPtr<Gdk::Pixbuf> get_icon();	// get the application icon
 
   void add_monitor(Monitor *monitor); // take over ownership of monitor
diff --git a/src/preferences-window.cpp b/src/preferences-window.cpp
index b1ea7b2..4e9fd4e 100644
--- a/src/preferences-window.cpp
+++ b/src/preferences-window.cpp
@@ -288,6 +288,9 @@ void PreferencesWindow::background_color_listener(unsigned int background_color)
     a = background_color;
 
   update_colorbutton_if_different(background_colorbutton, r, g, b, a);
+
+  // Actually updating the background color
+  applet.background_color_listener(background_color);
 }
 
 void PreferencesWindow::use_background_color_listener(bool use_background_color)
@@ -296,6 +299,9 @@ void PreferencesWindow::use_background_color_listener(bool use_background_color)
     background_color_radiobutton->set_active();
   else
     panel_background_radiobutton->set_active();
+
+  // Actually updating the background color usage state
+  applet.use_background_color_listener(use_background_color);
 }
 
 void PreferencesWindow::size_listener(int viewer_size)
@@ -337,27 +343,34 @@ void PreferencesWindow::monitor_color_listener(unsigned int color)
 
 namespace 
 {
-  // helper for avoiding clipping when shifting values
+  // Helper for avoiding clipping when shifting values
   unsigned int pack_int(unsigned int r, unsigned int g, unsigned int b,
 		      unsigned int a)
   {
     return ((r & 255) << 24) | ((g & 255) << 16) | ((b & 255) << 8) | (a & 255);
   }
 
+  // Return packed int from color button
+  unsigned int get_colorbutton_int(Gtk::ColorButton *button)
+  {
+
+    // Extract info from button
+    unsigned char a, r, g, b;
+
+    a = button->get_alpha() >> 8;
+
+    Gdk::Color c = button->get_color();
+    r = c.get_red() >> 8;
+    g = c.get_green() >> 8;
+    b = c.get_blue() >> 8;
+
+    return int(pack_int(r, g, b, a));
+  }
 }
 
-void PreferencesWindow::sync_conf_with_colorbutton(std::string settings_dir,
-  std::string setting_name, Gtk::ColorButton *button)
+void PreferencesWindow::sync_conf_with_colorbutton(Glib::ustring settings_dir,
+  Glib::ustring setting_name, Gtk::ColorButton *button)
 {
-  // extract info from button
-  unsigned char a, r, g, b;
-    
-  a = button->get_alpha() >> 8;
-  
-  Gdk::Color c = button->get_color();
-  r = c.get_red() >> 8;
-  g = c.get_green() >> 8;
-  b = c.get_blue() >> 8;
 
   // Search for a writeable settings file, create one if it doesnt exist
   gchar* file = xfce_panel_plugin_save_location(applet.panel_applet, true);
@@ -374,7 +387,7 @@ void PreferencesWindow::sync_conf_with_colorbutton(std::string settings_dir,
     
     // Updating configuration
     xfce_rc_write_int_entry(settings, setting_name.c_str(),
-      int(pack_int(r, g, b, a)));
+      get_colorbutton_int(button));
 
     // Close settings file
     xfce_rc_close(settings);
@@ -394,6 +407,10 @@ void PreferencesWindow::on_background_colorbutton_set()
   // Settings dir here is the default XFCE4 settings group
   sync_conf_with_colorbutton("[NULL]", "background_color",
 			     background_colorbutton);
+
+  // Actually apply the color change
+  applet.background_color_listener(
+    get_colorbutton_int(background_colorbutton));
 }
 
 void PreferencesWindow::on_background_color_radiobutton_toggled()
diff --git a/src/preferences-window.hpp b/src/preferences-window.hpp
index dbd1fe3..83dfd96 100644
--- a/src/preferences-window.hpp
+++ b/src/preferences-window.hpp
@@ -148,8 +148,8 @@ private:
   // for converting between size_scale units and pixels
   int size_scale_to_pixels(int size);
   int pixels_to_size_scale(int pixels);
-  void sync_conf_with_colorbutton(std::string settings_dir,
-    std::string setting_name, Gtk::ColorButton *button);
+  void sync_conf_with_colorbutton(Glib::ustring settings_dir,
+    Glib::ustring setting_name, Gtk::ColorButton *button);
   void connect_monitor_colorbutton(Gtk::ColorButton *colorbutton);
 
   void save_font_name(Glib::ustring font_name);

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list