[gnome-system-monitor] Chart axis labels follow font scaling (fixes #46)



commit c0199b6f367e9eaad53bfde653b3e36d1860242f
Author: Robert Roth <robert roth off gmail com>
Date:   Fri Nov 6 03:19:14 2020 +0200

    Chart axis labels follow font scaling (fixes #46)

 src/load-graph.cpp  | 14 +++++++++++++-
 src/load-graph.h    |  3 +++
 src/settings-keys.h |  3 +++
 3 files changed, 19 insertions(+), 1 deletion(-)
---
diff --git a/src/load-graph.cpp b/src/load-graph.cpp
index b9c939fb..dd6b6a91 100644
--- a/src/load-graph.cpp
+++ b/src/load-graph.cpp
@@ -260,6 +260,15 @@ load_graph_queue_draw (LoadGraph *graph)
 void load_graph_update_data (LoadGraph *graph);
 static int load_graph_update (gpointer user_data); // predeclare load_graph_update so we can compile ;)
 
+static void
+load_graph_rescale (LoadGraph *graph) {
+    ///org/gnome/desktop/interface/text-scaling-factor
+    graph->fontsize = 8 * graph->font_settings->get_double ("text-scaling-factor");
+    graph->clear_background();
+
+    load_graph_queue_draw (graph);
+}
+
 static gboolean
 load_graph_configure (GtkWidget *widget,
                       GdkEventConfigure *event,
@@ -268,6 +277,8 @@ load_graph_configure (GtkWidget *widget,
     GtkAllocation allocation;
     LoadGraph * const graph = static_cast<LoadGraph*>(data_ptr);
 
+    load_graph_rescale (graph);
+
     gtk_widget_get_allocation (widget, &allocation);
     graph->draw_width = allocation.width - 2 * FRAME_WIDTH;
     graph->draw_height = allocation.height - 2 * FRAME_WIDTH;
@@ -827,11 +838,12 @@ LoadGraph::LoadGraph(guint type)
       labels(),
       mem_color_picker(NULL),
       swap_color_picker(NULL),
+      font_settings(Gio::Settings::create (FONT_SETTINGS_SCHEMA)),
       cpu(),
       net()
 {
     LoadGraph * const graph = this;
-
+    font_settings->signal_changed(FONT_SETTING_SCALING).connect([this](const Glib::ustring&) { 
load_graph_rescale (this); } );
     // FIXME:
     // on configure, graph->frames_per_unit = graph->draw_width/(LoadGraph::NUM_POINTS);
     // knock FRAMES down to 5 until cairo gets faster
diff --git a/src/load-graph.h b/src/load-graph.h
index a49736de..01822c8d 100644
--- a/src/load-graph.h
+++ b/src/load-graph.h
@@ -7,6 +7,7 @@
 
 #include "legacy/gsm_color_button.h"
 #include "util.h"
+#include "settings-keys.h"
 
 enum
 {
@@ -80,6 +81,8 @@ struct LoadGraph
     GsmColorButton *mem_color_picker;
     GsmColorButton *swap_color_picker;
 
+    Glib::RefPtr<Gio::Settings> font_settings;
+
     /* union { */
     struct
     {
diff --git a/src/settings-keys.h b/src/settings-keys.h
index 52bdc812..e5cbd8c7 100644
--- a/src/settings-keys.h
+++ b/src/settings-keys.h
@@ -3,6 +3,9 @@
 #define _GSM_SETTINGS_KEYS_H_
 
 #define GSM_GSETTINGS_SCHEMA                "org.gnome.gnome-system-monitor"
+#define FONT_SETTINGS_SCHEMA                "org.gnome.desktop.interface"
+
+#define FONT_SETTING_SCALING                "text-scaling-factor"
 
 #define GSM_SETTINGS_CHILD_OPEN_FILES       "openfilestree"
 #define GSM_SETTINGS_CHILD_DISKS            "disktreenew"


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]