|
|
4d7151 |
From 8517b0284bfed75f82e9692b8543edaf42ba8a92 Mon Sep 17 00:00:00 2001
|
|
|
4d7151 |
From: David King <dking@redhat.com>
|
|
|
4d7151 |
Date: Wed, 18 Dec 2013 14:51:51 +0000
|
|
|
4d7151 |
Subject: [PATCH] Display more than 64 CPUs correctly
|
|
|
4d7151 |
|
|
|
4d7151 |
Add a scrolled window for the GtkGrid containing the CPU color
|
|
|
4d7151 |
selectors, and randomize the color for each CPU, if it is not set in the
|
|
|
4d7151 |
configuration.
|
|
|
4d7151 |
|
|
|
4d7151 |
Adapted from an earlier patch by Cosimo Cecchi in commit
|
|
|
4d7151 |
d5e323b5e2cfd47b47809f09d7dfee307f2eb378.
|
|
|
4d7151 |
|
|
|
4d7151 |
https://bugzilla.redhat.com/show_bug.cgi?id=1040501
|
|
|
4d7151 |
---
|
|
|
4d7151 |
src/interface.cpp | 12 +++++--
|
|
|
4d7151 |
src/procman-app.cpp | 2 +-
|
|
|
4d7151 |
src/util.cpp | 102 +++++++++++++++++++++++++++++++++++++++++++++++++++-
|
|
|
4d7151 |
src/util.h | 2 ++
|
|
|
4d7151 |
4 files changed, 114 insertions(+), 4 deletions(-)
|
|
|
4d7151 |
|
|
|
4d7151 |
diff --git a/src/interface.cpp b/src/interface.cpp
|
|
|
4d7151 |
index c116cf5..720bcb2 100644
|
|
|
4d7151 |
--- a/src/interface.cpp
|
|
|
4d7151 |
+++ b/src/interface.cpp
|
|
|
4d7151 |
@@ -169,7 +169,7 @@ create_sys_view (ProcmanApp *app, GtkBuilder * builder)
|
|
|
4d7151 |
GtkWidget *picker_alignment;
|
|
|
4d7151 |
LoadGraph *cpu_graph, *mem_graph, *net_graph;
|
|
|
4d7151 |
|
|
|
4d7151 |
- gint i;
|
|
|
4d7151 |
+ gint i, rows_n;
|
|
|
4d7151 |
gchar *title_text;
|
|
|
4d7151 |
gchar *label_text;
|
|
|
4d7151 |
gchar *title_template;
|
|
|
4d7151 |
@@ -188,8 +188,16 @@ create_sys_view (ProcmanApp *app, GtkBuilder * builder)
|
|
|
4d7151 |
TRUE,
|
|
|
4d7151 |
0);
|
|
|
4d7151 |
|
|
|
4d7151 |
- GtkWidget* cpu_table = GTK_WIDGET (gtk_builder_get_object (builder, "cpu_table"));
|
|
|
4d7151 |
gint cols = 4;
|
|
|
4d7151 |
+ rows_n = std::max(app->config.num_cpus / cols, 1);
|
|
|
4d7151 |
+
|
|
|
4d7151 |
+ GtkWidget* cpu_table = GTK_WIDGET (gtk_builder_get_object (builder, "cpu_table"));
|
|
|
4d7151 |
+ if (rows_n > 2) {
|
|
|
4d7151 |
+ GtkWidget *scrolled_window = gtk_scrolled_window_new(NULL, NULL);
|
|
|
4d7151 |
+ gtk_widget_reparent(cpu_table, scrolled_window);
|
|
|
4d7151 |
+ gtk_box_pack_end (GTK_BOX (cpu_graph_box), scrolled_window, TRUE, TRUE, 0);
|
|
|
4d7151 |
+ }
|
|
|
4d7151 |
+
|
|
|
4d7151 |
for (i=0;i<app->config.num_cpus; i++) {
|
|
|
4d7151 |
GtkWidget *temp_hbox;
|
|
|
4d7151 |
|
|
|
4d7151 |
diff --git a/src/procman-app.cpp b/src/procman-app.cpp
|
|
|
4d7151 |
index 6ce08b9..83f6975 100644
|
|
|
4d7151 |
--- a/src/procman-app.cpp
|
|
|
4d7151 |
+++ b/src/procman-app.cpp
|
|
|
4d7151 |
@@ -174,7 +174,7 @@ apply_cpu_color_settings(GSettings *settings, gpointer data)
|
|
|
4d7151 |
g_variant_builder_add_value ( &builder, child);
|
|
|
4d7151 |
g_variant_unref (child);
|
|
|
4d7151 |
} else {
|
|
|
4d7151 |
- color = g_strdup ("#f25915e815e8");
|
|
|
4d7151 |
+ color = procman::generate_random_color();
|
|
|
4d7151 |
g_variant_builder_add(&builder, "(us)", i, color);
|
|
|
4d7151 |
}
|
|
|
4d7151 |
gdk_rgba_parse(&app->config.cpu_color[i], color);
|
|
|
4d7151 |
diff --git a/src/util.cpp b/src/util.cpp
|
|
|
4d7151 |
index f06745b..2af00db 100644
|
|
|
4d7151 |
--- a/src/util.cpp
|
|
|
4d7151 |
+++ b/src/util.cpp
|
|
|
4d7151 |
@@ -365,7 +365,85 @@ procman_debug_real(const char *file, int line, const char *func,
|
|
|
4d7151 |
g_free(msg);
|
|
|
4d7151 |
}
|
|
|
4d7151 |
|
|
|
4d7151 |
-
|
|
|
4d7151 |
+/* taken from gtk+/gtk/gtkstyle.c */
|
|
|
4d7151 |
+static void
|
|
|
4d7151 |
+hls_to_rgb (gdouble *h,
|
|
|
4d7151 |
+ gdouble *l,
|
|
|
4d7151 |
+ gdouble *s)
|
|
|
4d7151 |
+{
|
|
|
4d7151 |
+ gdouble hue;
|
|
|
4d7151 |
+ gdouble lightness;
|
|
|
4d7151 |
+ gdouble saturation;
|
|
|
4d7151 |
+ gdouble m1, m2;
|
|
|
4d7151 |
+ gdouble r, g, b;
|
|
|
4d7151 |
+
|
|
|
4d7151 |
+ lightness = *l;
|
|
|
4d7151 |
+ saturation = *s;
|
|
|
4d7151 |
+
|
|
|
4d7151 |
+ if (lightness <= 0.5)
|
|
|
4d7151 |
+ m2 = lightness * (1 + saturation);
|
|
|
4d7151 |
+ else
|
|
|
4d7151 |
+ m2 = lightness + saturation - lightness * saturation;
|
|
|
4d7151 |
+ m1 = 2 * lightness - m2;
|
|
|
4d7151 |
+
|
|
|
4d7151 |
+ if (saturation == 0)
|
|
|
4d7151 |
+ {
|
|
|
4d7151 |
+ *h = lightness;
|
|
|
4d7151 |
+ *l = lightness;
|
|
|
4d7151 |
+ *s = lightness;
|
|
|
4d7151 |
+ }
|
|
|
4d7151 |
+ else
|
|
|
4d7151 |
+ {
|
|
|
4d7151 |
+ hue = *h + 120;
|
|
|
4d7151 |
+ while (hue > 360)
|
|
|
4d7151 |
+ hue -= 360;
|
|
|
4d7151 |
+ while (hue < 0)
|
|
|
4d7151 |
+ hue += 360;
|
|
|
4d7151 |
+
|
|
|
4d7151 |
+ if (hue < 60)
|
|
|
4d7151 |
+ r = m1 + (m2 - m1) * hue / 60;
|
|
|
4d7151 |
+ else if (hue < 180)
|
|
|
4d7151 |
+ r = m2;
|
|
|
4d7151 |
+ else if (hue < 240)
|
|
|
4d7151 |
+ r = m1 + (m2 - m1) * (240 - hue) / 60;
|
|
|
4d7151 |
+ else
|
|
|
4d7151 |
+ r = m1;
|
|
|
4d7151 |
+
|
|
|
4d7151 |
+ hue = *h;
|
|
|
4d7151 |
+ while (hue > 360)
|
|
|
4d7151 |
+ hue -= 360;
|
|
|
4d7151 |
+ while (hue < 0)
|
|
|
4d7151 |
+ hue += 360;
|
|
|
4d7151 |
+
|
|
|
4d7151 |
+ if (hue < 60)
|
|
|
4d7151 |
+ g = m1 + (m2 - m1) * hue / 60;
|
|
|
4d7151 |
+ else if (hue < 180)
|
|
|
4d7151 |
+ g = m2;
|
|
|
4d7151 |
+ else if (hue < 240)
|
|
|
4d7151 |
+ g = m1 + (m2 - m1) * (240 - hue) / 60;
|
|
|
4d7151 |
+ else
|
|
|
4d7151 |
+ g = m1;
|
|
|
4d7151 |
+
|
|
|
4d7151 |
+ hue = *h - 120;
|
|
|
4d7151 |
+ while (hue > 360)
|
|
|
4d7151 |
+ hue -= 360;
|
|
|
4d7151 |
+ while (hue < 0)
|
|
|
4d7151 |
+ hue += 360;
|
|
|
4d7151 |
+
|
|
|
4d7151 |
+ if (hue < 60)
|
|
|
4d7151 |
+ b = m1 + (m2 - m1) * hue / 60;
|
|
|
4d7151 |
+ else if (hue < 180)
|
|
|
4d7151 |
+ b = m2;
|
|
|
4d7151 |
+ else if (hue < 240)
|
|
|
4d7151 |
+ b = m1 + (m2 - m1) * (240 - hue) / 60;
|
|
|
4d7151 |
+ else
|
|
|
4d7151 |
+ b = m1;
|
|
|
4d7151 |
+
|
|
|
4d7151 |
+ *h = r;
|
|
|
4d7151 |
+ *l = g;
|
|
|
4d7151 |
+ *s = b;
|
|
|
4d7151 |
+ }
|
|
|
4d7151 |
+}
|
|
|
4d7151 |
|
|
|
4d7151 |
namespace procman
|
|
|
4d7151 |
{
|
|
|
4d7151 |
@@ -649,6 +727,28 @@ namespace procman
|
|
|
4d7151 |
return procman::format_rate(rate, max_rate, ProcmanApp::get()->config.network_in_bits);
|
|
|
4d7151 |
}
|
|
|
4d7151 |
|
|
|
4d7151 |
+
|
|
|
4d7151 |
+ gchar *generate_random_color (void)
|
|
|
4d7151 |
+ {
|
|
|
4d7151 |
+ GdkColor color;
|
|
|
4d7151 |
+ gdouble h, l, s;
|
|
|
4d7151 |
+
|
|
|
4d7151 |
+ h = g_random_int_range(0, 255);
|
|
|
4d7151 |
+ /* Clip luma, as we don't want colors too light (unreadable on a white
|
|
|
4d7151 |
+ * bg. */
|
|
|
4d7151 |
+ l = g_random_int_range(0, 224);
|
|
|
4d7151 |
+ s = g_random_int_range(0, 255);
|
|
|
4d7151 |
+
|
|
|
4d7151 |
+ hls_to_rgb(&h, &l, &s);
|
|
|
4d7151 |
+
|
|
|
4d7151 |
+ color.red = h * 255;
|
|
|
4d7151 |
+ color.green = l * 255;
|
|
|
4d7151 |
+ color.blue = s * 255;
|
|
|
4d7151 |
+
|
|
|
4d7151 |
+ return gdk_color_to_string(&color;;
|
|
|
4d7151 |
+ }
|
|
|
4d7151 |
+
|
|
|
4d7151 |
+
|
|
|
4d7151 |
}
|
|
|
4d7151 |
|
|
|
4d7151 |
|
|
|
4d7151 |
diff --git a/src/util.h b/src/util.h
|
|
|
4d7151 |
index f55f821..43d0001 100644
|
|
|
4d7151 |
--- a/src/util.h
|
|
|
4d7151 |
+++ b/src/util.h
|
|
|
4d7151 |
@@ -165,6 +165,8 @@ namespace procman
|
|
|
4d7151 |
|
|
|
4d7151 |
std::string format_network(guint64 rate, guint64 max_rate = 0);
|
|
|
4d7151 |
std::string format_network_rate(guint64 rate, guint64 max_rate = 0);
|
|
|
4d7151 |
+
|
|
|
4d7151 |
+ gchar *generate_random_color (void);
|
|
|
4d7151 |
}
|
|
|
4d7151 |
|
|
|
4d7151 |
|
|
|
4d7151 |
--
|
|
|
4d7151 |
1.8.3.1
|
|
|
4d7151 |
|