From a28f81ac5fb8266b13b55a43b8f4778e91658b6f Mon Sep 17 00:00:00 2001 From: Codian <44289933+xxcodianxx@users.noreply.github.com> Date: Sun, 29 Jan 2023 18:38:45 +1030 Subject: [PATCH 1/3] interface: add GSettings for LoadGraph UI colors Makes the background color and grid color for the load graphs configurable instead of being hardcoded to #FFFFFF and #E3E3E3. New GSettings keys added to the schema: * load-graph-background-color (default: #FFFFFF) * load-graph-grid-color (default: #E3E3E3) Fixes: #88 --- src/interface.cpp | 9 +++++++ src/load-graph.cpp | 11 ++++---- src/load-graph.h | 3 +++ src/org.mate.system-monitor.gschema.xml.in | 9 +++++++ src/procman-app.cpp | 29 ++++++++++++++++++++++ src/procman.h | 3 +++ 6 files changed, 59 insertions(+), 5 deletions(-) diff --git a/src/interface.cpp b/src/interface.cpp index 35979674..7ed683ad 100644 --- a/src/interface.cpp +++ b/src/interface.cpp @@ -398,6 +398,14 @@ create_sys_view (ProcData *procdata, GtkBuilder * builder) procdata->net_graph = net_graph; g_free(title_template); + + procdata->cpu_graph->background_color = procdata->config.load_graph_background_color; + procdata->mem_graph->background_color = procdata->config.load_graph_background_color; + procdata->net_graph->background_color = procdata->config.load_graph_background_color; + + procdata->cpu_graph->grid_color = procdata->config.load_graph_grid_color; + procdata->mem_graph->grid_color = procdata->config.load_graph_grid_color; + procdata->net_graph->grid_color = procdata->config.load_graph_grid_color; } static void @@ -679,3 +687,4 @@ cb_proc_goto_tab (gint tab) ProcData *data = ProcData::get_instance (); gtk_notebook_set_current_page (GTK_NOTEBOOK (data->notebook), tab); } + diff --git a/src/load-graph.cpp b/src/load-graph.cpp index f4ba83fa..494a9a04 100644 --- a/src/load-graph.cpp +++ b/src/load-graph.cpp @@ -113,7 +113,7 @@ static void draw_background(LoadGraph *graph) { cairo_translate (cr, FRAME_WIDTH, FRAME_WIDTH); /* Draw background rectangle */ - cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); + gdk_cairo_set_source_rgba (cr, &graph->background_color); cairo_rectangle (cr, graph->rmargin + graph->indent, 0, graph->draw_width - graph->rmargin - graph->indent, graph->real_draw_height); cairo_fill(cr); @@ -151,9 +151,9 @@ static void draw_background(LoadGraph *graph) { } if (i==0 || i==num_bars) - cairo_set_source_rgba (cr, 0.70, 0.71, 0.70, 1.0); + gdk_cairo_set_source_rgba (cr, &graph->grid_color); else - cairo_set_source_rgba (cr, 0.89, 0.89, 0.89, 1.0); + gdk_cairo_set_source_rgba (cr, &graph->grid_color); cairo_move_to (cr, graph->rmargin + graph->indent - 3, i * graph->graph_dely + 0.5); cairo_line_to (cr, graph->draw_width - 0.5, i * graph->graph_dely + 0.5); cairo_stroke (cr); @@ -164,9 +164,9 @@ static void draw_background(LoadGraph *graph) { for (unsigned int i = 0; i < 7; i++) { double x = (i) * (graph->draw_width - graph->rmargin - graph->indent) / 6; if (i==0 || i==6) - cairo_set_source_rgba (cr, 0.70, 0.71, 0.70, 1.0); + gdk_cairo_set_source_rgba (cr, &graph->grid_color); else - cairo_set_source_rgba (cr, 0.89, 0.89, 0.89, 1.0); + gdk_cairo_set_source_rgba (cr, &graph->grid_color); cairo_move_to (cr, (ceil(x) + 0.5) + graph->rmargin + graph->indent, 0.5); cairo_line_to (cr, (ceil(x) + 0.5) + graph->rmargin + graph->indent, graph->real_draw_height + 4.5); cairo_stroke(cr); @@ -849,3 +849,4 @@ load_graph_get_swap_color_picker(LoadGraph *graph) { return graph->swap_color_picker; } + diff --git a/src/load-graph.h b/src/load-graph.h index 60eff23e..b01b487d 100644 --- a/src/load-graph.h +++ b/src/load-graph.h @@ -55,6 +55,8 @@ struct LoadGraph { guint graph_buffer_offset; std::vector colors; + GdkRGBA background_color; + GdkRGBA grid_color; std::vector data_block; gfloat* data[NUM_POINTS]; @@ -124,3 +126,4 @@ GtkWidget* load_graph_get_swap_color_picker(LoadGraph *g) G_GNUC_CONST; #endif /* _PROCMAN_LOAD_GRAPH_H_ */ + diff --git a/src/org.mate.system-monitor.gschema.xml.in b/src/org.mate.system-monitor.gschema.xml.in index 0bac3e81..afcd8b57 100644 --- a/src/org.mate.system-monitor.gschema.xml.in +++ b/src/org.mate.system-monitor.gschema.xml.in @@ -201,6 +201,14 @@ Show network traffic in bits + + '#FFFFFF' + Default graph background color + + + '#E3E3E3' + Default graph grid color + @@ -537,3 +545,4 @@ + diff --git a/src/procman-app.cpp b/src/procman-app.cpp index 7724a4cc..41f805ab 100644 --- a/src/procman-app.cpp +++ b/src/procman-app.cpp @@ -184,6 +184,18 @@ color_changed_cb (GSettings *settings, const gchar *key, gpointer data) gdk_rgba_parse (&procdata->config.net_out_color, color); procdata->net_graph->colors.at(1) = procdata->config.net_out_color; } + else if (g_str_equal (key, "load-graph-background-color")) { + gdk_rgba_parse (&procdata->config.load_graph_background_color, color); + procdata->cpu_graph->background_color = procdata->config.load_graph_background_color; + procdata->mem_graph->background_color = procdata->config.load_graph_background_color; + procdata->net_graph->background_color = procdata->config.load_graph_background_color; + } + else if (g_str_equal (key, "load-graph-grid-color")) { + gdk_rgba_parse (&procdata->config.load_graph_grid_color, color); + procdata->cpu_graph->grid_color = procdata->config.load_graph_grid_color; + procdata->mem_graph->grid_color = procdata->config.load_graph_grid_color; + procdata->net_graph->grid_color = procdata->config.load_graph_grid_color; + } else { g_assert_not_reached(); } @@ -306,6 +318,22 @@ procman_data_new (GSettings *settings) gdk_rgba_parse(&pd->config.net_out_color, color); g_free (color); + color = g_settings_get_string (settings, "load-graph-background-color"); + if (!color) + color = g_strdup ("#ffffff"); + g_signal_connect (G_OBJECT(settings), "changed::load-graph-background-color", + G_CALLBACK(color_changed_cb), pd); + gdk_rgba_parse(&pd->config.load_graph_background_color, color); + g_free (color); + + color = g_settings_get_string (settings, "load-graph-grid-color"); + if (!color) + color = g_strdup ("#e3e3e3"); + g_signal_connect (G_OBJECT(settings), "changed::load-graph-grid-color", + G_CALLBACK(color_changed_cb), pd); + gdk_rgba_parse(&pd->config.load_graph_grid_color, color); + g_free (color); + /* Sanity checks */ GdkDisplay *display; GdkMonitor *monitor; @@ -434,3 +462,4 @@ void ProcmanApp::on_shutdown() glibtop_close(); } + diff --git a/src/procman.h b/src/procman.h index f7217089..d511df8d 100644 --- a/src/procman.h +++ b/src/procman.h @@ -93,6 +93,8 @@ struct ProcConfig GdkRGBA net_out_color; GdkRGBA bg_color; GdkRGBA frame_color; + GdkRGBA load_graph_background_color; + GdkRGBA load_graph_grid_color; gint num_cpus; bool solaris_mode; bool network_in_bits; @@ -261,3 +263,4 @@ struct KillArgs }; #endif /* _PROCMAN_PROCMAN_H_ */ + From 86637bd219765479ac93410b0295b7052480bea0 Mon Sep 17 00:00:00 2001 From: Codian <44289933+xxcodianxx@users.noreply.github.com> Date: Sun, 29 Jan 2023 19:01:33 +1030 Subject: [PATCH 2/3] cleanup: remove redundant if statement --- src/load-graph.cpp | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/load-graph.cpp b/src/load-graph.cpp index 494a9a04..85449b15 100644 --- a/src/load-graph.cpp +++ b/src/load-graph.cpp @@ -150,10 +150,7 @@ static void draw_background(LoadGraph *graph) { pango_cairo_show_layout (cr, layout); } - if (i==0 || i==num_bars) - gdk_cairo_set_source_rgba (cr, &graph->grid_color); - else - gdk_cairo_set_source_rgba (cr, &graph->grid_color); + gdk_cairo_set_source_rgba (cr, &graph->grid_color); cairo_move_to (cr, graph->rmargin + graph->indent - 3, i * graph->graph_dely + 0.5); cairo_line_to (cr, graph->draw_width - 0.5, i * graph->graph_dely + 0.5); cairo_stroke (cr); @@ -163,10 +160,7 @@ static void draw_background(LoadGraph *graph) { for (unsigned int i = 0; i < 7; i++) { double x = (i) * (graph->draw_width - graph->rmargin - graph->indent) / 6; - if (i==0 || i==6) - gdk_cairo_set_source_rgba (cr, &graph->grid_color); - else - gdk_cairo_set_source_rgba (cr, &graph->grid_color); + gdk_cairo_set_source_rgba (cr, &graph->grid_color); cairo_move_to (cr, (ceil(x) + 0.5) + graph->rmargin + graph->indent, 0.5); cairo_line_to (cr, (ceil(x) + 0.5) + graph->rmargin + graph->indent, graph->real_draw_height + 4.5); cairo_stroke(cr); From 4e336a90373f46c69b2cb5d328ab68f1c25f6c2d Mon Sep 17 00:00:00 2001 From: Codian <44289933+xxcodianxx@users.noreply.github.com> Date: Mon, 30 Jan 2023 17:20:19 +1030 Subject: [PATCH 3/3] cleanup: remove added blank lines on some files Commit a28f81ac5fb8266b13b55a43b8f4778e91658b6f accidentally added an unnecessary blank line to: - src/interface.cpp - src/load-graph.cpp - src/load-graph.h - src/procman-app.cpp - src/procman.h - src/org.mate.system-monitor.gschema.xml.in This commit reverts this by removing the new lines. --- src/interface.cpp | 1 - src/load-graph.cpp | 1 - src/load-graph.h | 1 - src/org.mate.system-monitor.gschema.xml.in | 1 - src/procman-app.cpp | 1 - src/procman.h | 1 - 6 files changed, 6 deletions(-) diff --git a/src/interface.cpp b/src/interface.cpp index 7ed683ad..d1335523 100644 --- a/src/interface.cpp +++ b/src/interface.cpp @@ -687,4 +687,3 @@ cb_proc_goto_tab (gint tab) ProcData *data = ProcData::get_instance (); gtk_notebook_set_current_page (GTK_NOTEBOOK (data->notebook), tab); } - diff --git a/src/load-graph.cpp b/src/load-graph.cpp index 85449b15..58ec3332 100644 --- a/src/load-graph.cpp +++ b/src/load-graph.cpp @@ -843,4 +843,3 @@ load_graph_get_swap_color_picker(LoadGraph *graph) { return graph->swap_color_picker; } - diff --git a/src/load-graph.h b/src/load-graph.h index b01b487d..139f5a36 100644 --- a/src/load-graph.h +++ b/src/load-graph.h @@ -126,4 +126,3 @@ GtkWidget* load_graph_get_swap_color_picker(LoadGraph *g) G_GNUC_CONST; #endif /* _PROCMAN_LOAD_GRAPH_H_ */ - diff --git a/src/org.mate.system-monitor.gschema.xml.in b/src/org.mate.system-monitor.gschema.xml.in index afcd8b57..a886c9ae 100644 --- a/src/org.mate.system-monitor.gschema.xml.in +++ b/src/org.mate.system-monitor.gschema.xml.in @@ -545,4 +545,3 @@ - diff --git a/src/procman-app.cpp b/src/procman-app.cpp index 41f805ab..597049ed 100644 --- a/src/procman-app.cpp +++ b/src/procman-app.cpp @@ -462,4 +462,3 @@ void ProcmanApp::on_shutdown() glibtop_close(); } - diff --git a/src/procman.h b/src/procman.h index d511df8d..24288e6b 100644 --- a/src/procman.h +++ b/src/procman.h @@ -263,4 +263,3 @@ struct KillArgs }; #endif /* _PROCMAN_PROCMAN_H_ */ -