[Xfce4-commits] [panel-plugins/xfce4-hardware-monitor-plugin] 24/96: Viewer size maintained in applet, now set correctly on startup and maintained during runtime

noreply at xfce.org noreply at xfce.org
Thu Nov 27 22:20:29 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 dae540c8c3ee14e8141040424841420b41394c1b
Author: Omega Weapon <OmegaPhil at gmail.com>
Date:   Sun Nov 3 11:06:31 2013 +0000

    Viewer size maintained in applet, now set correctly on startup and maintained during runtime
---
 src/applet.cpp             |   55 +++++++++++++++++++++++++++++++++++++++++---
 src/applet.hpp             |    4 ++--
 src/canvas-view.cpp        |    4 ++++
 src/preferences-window.cpp |    5 ----
 4 files changed, 58 insertions(+), 10 deletions(-)

diff --git a/src/applet.cpp b/src/applet.cpp
index c3f67f2..0fa5988 100644
--- a/src/applet.cpp
+++ b/src/applet.cpp
@@ -24,6 +24,7 @@
 
 #include <algorithm>
 #include <vector>
+#include <iostream>
 
 #include <gtkmm/main.h>
 #include <cassert>
@@ -143,7 +144,7 @@ Applet::Applet(XfcePanelPlugin *plugin)
   icon_path("/usr/share/pixmaps/hardware-monitor-applet.png"),
   viewer_type("curve"),
   viewer_font(""),
-  viewer_size(96),  // Arbitrary default
+  viewer_size(96),  // Arbitrary default, see later in this function for notes
   background_color(0x00000000),  // black as the night
   use_background_color(false),
   next_color(0)
@@ -234,7 +235,10 @@ Applet::Applet(XfcePanelPlugin *plugin)
   // Setting the view background colour if desired
   if (use_background_color)
       view->set_background(background_color);
-  
+
+  /* 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 */
+
   // Loading up monitors
   monitor_seq mon = load_monitors(settings);
   for (monitor_iter i = mon.begin(), end = mon.end(); i != end; ++i)
@@ -437,7 +441,52 @@ int Applet::get_viewer_size() const
 
 void Applet::set_viewer_size(const int size)
 {
-  viewer_size = size;
+  // See header file viewer_size_configured notes
+
+  // Obtaining current widget dimensions
+  GtkRequisition req_size;
+  gtk_widget_size_request(GTK_WIDGET(panel_applet), &req_size);
+
+  /*
+  // Debug code
+  std::cout << "Size information: " << req_size.width << "x"
+    << req_size.height << "\n";
+  */
+
+  // Make sure on every call that the viewer size is being honoured
+  // TODO: This needs to deal with orientations
+  if (req_size.width < size)
+    gtk_widget_set_size_request(GTK_WIDGET(panel_applet), viewer_size, -1);
+
+  // Exiting if the size hasn't changed from this program's perspective
+  if (viewer_size == size)
+    return;
+
+  /* Saving
+   * Search for a writeable settings file, create one if it doesnt exist */
+  gchar* file = xfce_panel_plugin_save_location(panel_applet, true);
+
+  if (file)
+  {
+    // Opening setting file
+    XfceRc* settings = xfce_rc_simple_open(file, false);
+    g_free(file);
+
+    // Updating configuration
+    xfce_rc_write_int_entry(settings, "viewer_size", viewer_size);
+
+    // Close settings file
+    xfce_rc_close(settings);
+  }
+  else
+  {
+    // Unable to obtain writeable config file - informing user and exiting
+    std::cerr << _("Unable to obtain writeable config file path in order to"
+      " save new viewer_size in Applet::set_viewer_size!\n");
+  }
+
+  // Debug code
+  //std::cout << "Viewer size set to " << viewer_size << "\n";
 }
 
 const Glib::ustring Applet::get_viewer_font()
diff --git a/src/applet.hpp b/src/applet.hpp
index 32e3783..df04baf 100644
--- a/src/applet.hpp
+++ b/src/applet.hpp
@@ -54,7 +54,7 @@ public:
   ~Applet();
 
   Gtk::Container &get_container();
-  
+
   unsigned int get_fg_color();	// return varying foreground colours
   int get_size() const;		// in pixels
   bool horizontal() const; 	// whether we're in horizontal mode
@@ -103,7 +103,7 @@ private:
   Glib::ustring icon_path;
   Glib::ustring viewer_type;
   Glib::ustring viewer_font;
-  int viewer_size;  // Pixel size used with the viewer scale - nothing to do with the visible area
+  int viewer_size;
   int background_color;
   gboolean use_background_color;
   int next_color;
diff --git a/src/canvas-view.cpp b/src/canvas-view.cpp
index 3c6f207..33a754b 100644
--- a/src/canvas-view.cpp
+++ b/src/canvas-view.cpp
@@ -60,6 +60,10 @@ void CanvasView::do_update()
   // Size is maintained in applet
   size = applet->get_viewer_size();
 
+  /* Ensure that the widget's requested size is being honoured on every
+   * call */
+  applet->set_viewer_size(size);
+
   // Ensure the canvas is shown
   resize_canvas();
 }
diff --git a/src/preferences-window.cpp b/src/preferences-window.cpp
index b1724c8..d0706a7 100644
--- a/src/preferences-window.cpp
+++ b/src/preferences-window.cpp
@@ -325,11 +325,6 @@ void PreferencesWindow::size_listener(unsigned int,
 
   // Actually change the size...
   applet.set_viewer_size(viewer_size);
-  gtk_widget_set_size_request(GTK_WIDGET(applet.panel_applet),
-    viewer_size, -1);
-
-  // Debug code
-  //std::cout << "Viewer size set to " << viewer_size << "\n";
 }
 
 void PreferencesWindow::font_listener(unsigned int,

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


More information about the Xfce4-commits mailing list