[Xfce4-commits] [panel-plugins/xfce4-hardware-monitor-plugin] 21/29: Make Bar and Flame visualisations share a unified max from their monitors

noreply at xfce.org noreply at xfce.org
Mon Dec 18 12:45:52 CET 2017


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

o   m   e   g   a   p   h   i   l       p   u   s   h   e   d       a       c   o   m   m   i   t       t   o       b   r   a   n   c   h       m   a   s   t   e   r   
   in repository panel-plugins/xfce4-hardware-monitor-plugin.

commit 57a1226e1139887710f813bcccb0d1b676d8249d
Author: OmegaPhil <OmegaPhil at startmail.com>
Date:   Sat Dec 9 20:28:32 2017 +0000

    Make Bar and Flame visualisations share a unified max from their monitors
---
 src/bar-view.cpp      | 35 +++++++++++++++++++++++++++++------
 src/flame-view.cpp    | 32 ++++++++++++++++++++++++--------
 src/monitor-impls.cpp | 19 ++++++++++++++++---
 src/monitor-impls.hpp | 14 ++++++++++++--
 src/plugin.cpp        | 13 +++++++++----
 src/plugin.hpp        |  6 ++++++
 6 files changed, 96 insertions(+), 23 deletions(-)

diff --git a/src/bar-view.cpp b/src/bar-view.cpp
index f24b2e4..78e78e8 100644
--- a/src/bar-view.cpp
+++ b/src/bar-view.cpp
@@ -38,10 +38,11 @@ public:
   Bar(Monitor *monitor, unsigned int fill_color, bool horizontal = false);
   ~Bar();
 
-  void update();
   void draw(Gnome::Canvas::Canvas &canvas,
       Plugin *plugin, int width, int height, int no, int total,
-      double time_offset);
+      double time_offset, double max);
+  double get_max_value();
+  void update();
 
   Monitor *monitor;
   
@@ -98,7 +99,7 @@ unsigned int outlineified(unsigned int color)
 
 void Bar::draw(Gnome::Canvas::Canvas &canvas,
          Plugin *plugin, int width, int height, int no, int total,
-         double time_offset)
+         double time_offset, double max)
 { 
   unsigned int outline_color = outlineified(fill_color);
 
@@ -127,7 +128,6 @@ void Bar::draw(Gnome::Canvas::Canvas &canvas,
   // don't attain new value immediately
   double value = old_value * (1 - time_offset) + new_value * time_offset;
 
-  double max = monitor->max();
   if (max <= 0)
     max = 0.0000001;
 
@@ -190,6 +190,18 @@ void Bar::draw(Gnome::Canvas::Canvas &canvas,
   }
 }
 
+double Bar::get_max_value()
+{
+  /* Used as part of determination of the max value for all bars in
+   * the view
+   * max is not tracked by the visualisation here */
+  double max = monitor->max();
+  if (max <= 0)
+    max = 0.0000001;
+
+  return max;
+}
+
 
 //
 // class BarView
@@ -303,9 +315,20 @@ void BarView::do_draw_loop()
  
   int total = bars.size();
   int no = 0;
-  
+
+  double max = 0;
+
+  /* Obtain maximum value of all columns in the view, ignoring any monitors with
+   * fixed maxes (their visualisations are not supposed to be scaled) */
+  for (bar_iterator i = bars.begin(), end = bars.end(); i != end; ++i)
+  {
+    if (!(*i)->monitor->fixed_max() && (*i)->get_max_value() > max)
+      max = (*i)->get_max_value();
+  }
+
+  // Drawing bars with the unified max value
   for (bar_iterator i = bars.begin(), end = bars.end(); i != end; ++i)
-    (*i)->draw(*canvas, plugin, width(), height(), no++, total, time_offset);
+    (*i)->draw(*canvas, plugin, width(), height(), no++, total, time_offset, max);
 
   ++draws_since_update;
 }
diff --git a/src/flame-view.cpp b/src/flame-view.cpp
index 18d01eb..67d9cab 100644
--- a/src/flame-view.cpp
+++ b/src/flame-view.cpp
@@ -39,10 +39,10 @@ class Flame
 public:
   Flame(Monitor *monitor, unsigned int color);
 
+  void burn(double overall_max);
+  double get_max_value();
   void update(Gnome::Canvas::Canvas &canvas,
         Plugin *plugin, int width, int height, int no, int total);
-
-  void burn();
   
   Monitor *monitor;
   
@@ -55,7 +55,7 @@ private:
   int next_refuel;
   int cooling;      // cooling factor
 
-  void recompute_fuel();
+  void recompute_fuel(double overall_max);
   unsigned int color;
 };
 
@@ -131,9 +131,9 @@ unsigned int random_between(unsigned int min, unsigned int max)
   return min + std::rand() % (max - min);
 }
 
-void Flame::recompute_fuel()
+void Flame::recompute_fuel(double overall_max)
 {
-  int ratio = int(value / max * 255);
+  int ratio = int(value / overall_max * 255);
 
   if (ratio > 255)
     ratio = 255;
@@ -167,7 +167,7 @@ void Flame::recompute_fuel()
     --next_refuel;
 }
 
-void Flame::burn()
+void Flame::burn(double overall_max)
 {
   if (!flame.get())
     return;
@@ -177,7 +177,7 @@ void Flame::burn()
   int width = pixbuf->get_width();
   int height = pixbuf->get_height();
 
-  recompute_fuel();
+  recompute_fuel(overall_max);
   
   // Process the lowest row
   PixelPosition lowest = get_position(pixbuf, 0, height - 1);
@@ -230,6 +230,11 @@ void Flame::burn()
   flame->property_pixbuf() = pixbuf;
 }
 
+double Flame::get_max_value()
+{
+  return max;
+}
+
 
 //
 // class FlameView
@@ -339,6 +344,17 @@ void FlameView::do_detach(Monitor *monitor)
 
 void FlameView::do_draw_loop()
 {
+  double max = 0;
+
+  /* Obtain maximum value of all flames in the view, ignoring any monitors with
+   * fixed maxes (their visualisations are not supposed to be scaled) */
+  for (flame_iterator i = flames.begin(), end = flames.end(); i != end; ++i)
+  {
+    if (!(*i)->monitor->fixed_max() && (*i)->get_max_value() > max)
+      max = (*i)->get_max_value();
+  }
+
+  // Drawing flames with the unified max value
   for (flame_iterator i = flames.begin(), end = flames.end(); i != end; ++i)
-    (*i)->burn();
+    (*i)->burn(max);
 }
diff --git a/src/monitor-impls.cpp b/src/monitor-impls.cpp
index 7e93345..93b42b4 100644
--- a/src/monitor-impls.cpp
+++ b/src/monitor-impls.cpp
@@ -1798,13 +1798,18 @@ double NetworkLoadMonitor::do_measure()
   if (!fixed_max_priv)
   {
     /* Note - max_value is no longer used to determine the graph max for
-   * Curves - the actual maxima stored in the ValueHistories are used */
+     * Curves and Columns - the actual maxima stored in the ValueHistories are
+     * used */
     if (val != 0)     // Reduce scale gradually
       max_value = guint64(max_value * max_decay);
 
     if (val > max_value)
       max_value = guint64(val * 1.05);
 
+    /*
+    // Shared monitor maxes in a visualisation has now been moved to the
+    // individual view implementations, so its not just for network monitors
+    // anymore
     for (nlm_seq::iterator i = sync_monitors.begin(), end = sync_monitors.end();
          i != end; ++i) {
       NetworkLoadMonitor &other = **i;
@@ -1813,6 +1818,7 @@ double NetworkLoadMonitor::do_measure()
       else if (max_value > other.max_value)
         other.max_value = max_value;
     }
+    */
   }
 
   // Calculate time difference in msecs between last sample and current sample
@@ -2005,12 +2011,16 @@ double NetworkLoadMonitor::max()
   return max_value;
 }
 
-void NetworkLoadMonitor::possibly_add_sync_with(Monitor *other)
+// Shared monitor maxes in a visualisation has now been moved to the
+// individual view implementations, so its not just for network monitors
+// anymore
+/*void NetworkLoadMonitor::possibly_add_sync_with(Monitor *other)
 {
   if (NetworkLoadMonitor *o = dynamic_cast<NetworkLoadMonitor *>(other))
     if (interface_type == o->interface_type && direction != o->direction)
       sync_monitors.push_back(o);
 }
+*/
 
 void NetworkLoadMonitor::restore_default_interface_names(XfceRc *settings_w)
 {
@@ -2018,7 +2028,9 @@ void NetworkLoadMonitor::restore_default_interface_names(XfceRc *settings_w)
   NetworkLoadMonitor::save_interfaces(settings_w);
 }
 
-void NetworkLoadMonitor::remove_sync_with(Monitor *other)
+// Shared monitor maxes in a visualisation has now been moved to the View,
+// so its not just for network monitors anymore
+/*void NetworkLoadMonitor::remove_sync_with(Monitor *other)
 {
   nlm_seq::iterator i
     = std::find(sync_monitors.begin(), sync_monitors.end(), other);
@@ -2026,6 +2038,7 @@ void NetworkLoadMonitor::remove_sync_with(Monitor *other)
   if (i != sync_monitors.end())
     sync_monitors.erase(i);
 }
+*/
 
 void NetworkLoadMonitor::save(XfceRc *settings_w)
 {
diff --git a/src/monitor-impls.hpp b/src/monitor-impls.hpp
index 7a39459..7cec4c9 100644
--- a/src/monitor-impls.hpp
+++ b/src/monitor-impls.hpp
@@ -324,8 +324,15 @@ public:
   virtual Glib::ustring get_name();
   virtual Glib::ustring get_short_name();
   virtual double max();
+
+  /*
+   * Shared monitor maxes in a visualisation has now been moved to the
+   * individual view implementations, so its not just for network monitors
+   * anymore
   virtual void possibly_add_sync_with(Monitor *other);
   virtual void remove_sync_with(Monitor *other);
+  */
+
   virtual void save(XfceRc *settings_w);
   virtual void set_fixed_max(bool fixed_max);
   virtual void set_max(double max);
@@ -379,8 +386,11 @@ private:
                                  // when needed
   Direction direction;
 
-  typedef std::list<NetworkLoadMonitor *> nlm_seq;
-  nlm_seq sync_monitors;
+  // Shared monitor maxes in a visualisation has now been moved to the
+  // individual view implementations, so its not just for network monitors
+  // anymore
+  /*typedef std::list<NetworkLoadMonitor *> nlm_seq;
+  nlm_seq sync_monitors;*/
 
   /* Storage for default or customised interface names for all types - can't
    * initialise vector here?? */
diff --git a/src/plugin.cpp b/src/plugin.cpp
index deebbbf..dfb5af0 100644
--- a/src/plugin.cpp
+++ b/src/plugin.cpp
@@ -640,7 +640,7 @@ void Plugin::set_viewer_text_overlay_position(CurveView::TextOverlayPosition
 
 void Plugin::add_monitor(Monitor *monitor)
 {
-  add_sync_for(monitor);
+  //add_sync_for(monitor);
   monitors.push_back(monitor);
 
   /* Checking if monitor has a defined settings directory and therefore
@@ -711,7 +711,7 @@ void Plugin::remove_monitor(Monitor *monitor)
   // Everyone has been notified, it's now safe to remove and delete
   // the monitor
   monitors.remove(monitor);
-  remove_sync_for(monitor);
+  //remove_sync_for(monitor);
   
   delete monitor;
 }
@@ -723,7 +723,7 @@ void Plugin::replace_monitor(Monitor *prev_mon, Monitor *new_mon)
   assert(i != monitors.end());
 
   // Basic configuration
-  add_sync_for(new_mon);
+  //add_sync_for(new_mon);
   *i = new_mon;
   new_mon->set_settings_dir(prev_mon->get_settings_dir());
 
@@ -756,10 +756,14 @@ void Plugin::replace_monitor(Monitor *prev_mon, Monitor *new_mon)
   }
 
   // Deleting previous monitor
-  remove_sync_for(prev_mon);
+  //remove_sync_for(prev_mon);
   delete prev_mon;
 }
 
+/*
+ * Shared monitor maxes in a visualisation has now been moved to the
+ * individual view implementations, so its not just for network monitors
+ * anymore
 void Plugin::add_sync_for(Monitor *monitor)
 {
   for (monitor_iter i = monitors.begin(), end = monitors.end(); i != end; ++i)
@@ -771,6 +775,7 @@ void Plugin::remove_sync_for(Monitor *monitor)
   for (monitor_iter i = monitors.begin(), end = monitors.end(); i != end; ++i)
     (*i)->remove_sync_with(monitor);
 }
+*/
 
 Glib::ustring Plugin::find_empty_monitor_dir()
 {
diff --git a/src/plugin.hpp b/src/plugin.hpp
index a437f50..63c487c 100644
--- a/src/plugin.hpp
+++ b/src/plugin.hpp
@@ -116,8 +116,14 @@ public:
 private:
   // monitors
   monitor_seq monitors;
+
+  /*
+   * Shared monitor maxes in a visualisation has now been moved to the
+   * individual view implementations, so its not just for network monitors
+   * anymore
   void add_sync_for(Monitor *monitor);
   void remove_sync_for(Monitor *monitor);
+  */
 
   // the context menu
   void on_preferences_activated();

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


More information about the Xfce4-commits mailing list