From 79a028768f2e6ac28bf425e6597ff8aa61741456 Mon Sep 17 00:00:00 2001
From: songchuanfei <songchuanfei@kylinos.com.cn>
Date: Wed, 13 Jul 2022 05:56:39 -0400
Subject: [PATCH] fix[resource]: Fix resource page too large when system has
 too many cpus
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

- 修复系统CPU数很多时资源页面太长，无法看到全部的问题
  Fixes #23294

Signed-off-by: songchuanfei <songchuanfei@kylinos.com.cn>
---
 src/gsm_color_button.c |  8 +++-----
 src/interface.cpp      |  7 ++++++-
 src/load-graph.cpp     | 11 +----------
 3 files changed, 10 insertions(+), 16 deletions(-)

diff --git a/src/gsm_color_button.c b/src/gsm_color_button.c
index 3148c34..35d2710 100644
--- a/src/gsm_color_button.c
+++ b/src/gsm_color_button.c
@@ -227,7 +227,7 @@ fill_image_buffer_from_file (cairo_t *cr, const char *filePath)
 
 
 static void
-render (GtkWidget * widget)
+render (GtkWidget * widget, cairo_t *cr)
 {
     GSMColorButtonPrivate *priv;
     GSMColorButton *color_button = GSM_COLOR_BUTTON (widget);
@@ -236,7 +236,6 @@ render (GtkWidget * widget)
     GdkRGBA *color;
     GdkRGBA tmp_color = priv->color;
     color = &tmp_color;
-    cairo_t *cr = gdk_cairo_create (gtk_widget_get_window (widget));
     cairo_path_t *path = NULL;
     gint width, height;
     gdouble radius, arc_start, arc_end;
@@ -405,13 +404,12 @@ render (GtkWidget * widget)
 
             break;
         }
-    cairo_destroy (cr);
 }
 
 /* Handle exposure events for the color picker's drawing area */
 static gboolean draw (GtkWidget * widget, cairo_t * cr, gpointer data)
 {
-    render (GTK_WIDGET (data));
+    render (GTK_WIDGET (data), cr);
 
     return FALSE;
 }
@@ -420,7 +418,7 @@ static void
 gsm_color_button_realize (GtkWidget * widget)
 {
     GTK_WIDGET_CLASS (gsm_color_button_parent_class)->realize (widget);
-    render (widget);
+    gtk_widget_queue_draw(widget);
 }
 
 static void gsm_color_button_get_preferred_width (GtkWidget * widget, gint * minimum_width, gint * natural_width)
diff --git a/src/interface.cpp b/src/interface.cpp
index 2a5cbbf..e38915a 100644
--- a/src/interface.cpp
+++ b/src/interface.cpp
@@ -261,6 +261,7 @@ make_title_label (const char *text)
 static GtkWidget *
 create_sys_view (ProcData *procdata)
 {
+    GtkWidget *scrolled;
     GtkWidget *vbox, *hbox;
     GtkWidget *cpu_box, *mem_box, *net_box;
     GtkWidget *cpu_graph_box, *mem_graph_box, *net_graph_box;
@@ -277,6 +278,8 @@ create_sys_view (ProcData *procdata)
     gchar *label_text;
     gchar *title_template;
 
+    scrolled = gtk_scrolled_window_new(NULL, NULL);
+
     // Translators: color picker title, %s is CPU, Memory, Swap, Receiving, Sending
     title_template = g_strdup(_("Pick a Color for '%s'"));
 
@@ -558,7 +561,9 @@ create_sys_view (ProcData *procdata)
     procdata->net_graph = net_graph;
     g_free(title_template);
 
-    return vbox_top;
+    gtk_container_add(GTK_CONTAINER(scrolled), vbox);
+
+    return scrolled;
 }
 
 static void
diff --git a/src/load-graph.cpp b/src/load-graph.cpp
index b24f977..2e294b9 100644
--- a/src/load-graph.cpp
+++ b/src/load-graph.cpp
@@ -220,7 +220,7 @@ load_graph_configure (GtkWidget *widget,
     return TRUE;
 }
 
-static gboolean load_graph_draw (GtkWidget *widget, cairo_t *context, gpointer data_ptr)
+static gboolean load_graph_draw (GtkWidget *widget, cairo_t *cr, gpointer data_ptr)
 {
     LoadGraph * const graph = static_cast<LoadGraph*>(data_ptr);
     GdkWindow *window;
@@ -239,10 +239,6 @@ static gboolean load_graph_draw (GtkWidget *widget, cairo_t *context, gpointer d
     x_offset += graph->rmargin - ((sample_width / graph->frames_per_unit) * graph->render_counter);
 
     /* draw the graph */
-    cairo_t* cr;
-
-    cr = gdk_cairo_create (window);
-
     if (graph->background == NULL) {
         draw_background(graph);
     }
@@ -252,9 +248,6 @@ static gboolean load_graph_draw (GtkWidget *widget, cairo_t *context, gpointer d
     cairo_set_line_width (cr, 1);
     cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
     cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND);
-    cairo_rectangle (cr, graph->rmargin + graph->indent + FRAME_WIDTH + 1, FRAME_WIDTH - 1,
-             graph->draw_width - graph->rmargin - graph->indent - 1, graph->real_draw_height + FRAME_WIDTH - 1);
-    cairo_clip(cr);
 
     for (j = 0; j < graph->n; ++j) {
         cairo_move_to (cr, x_offset, (1.0f - graph->data[0][j]) * graph->real_draw_height);
@@ -275,8 +268,6 @@ static gboolean load_graph_draw (GtkWidget *widget, cairo_t *context, gpointer d
 
     }
 
-    cairo_destroy (cr);
-
     return TRUE;
 }
 
-- 
2.33.0

