aboutsummaryrefslogtreecommitdiffstats
path: root/meta-xfce/recipes-panel-plugins/cpufreq/xfce4-cpufreq-plugin/0001-Fix-memory-leak-and-reduce-cpu-load-slightly.patch
blob: 92a6e8384d5f59acddb7490cded0810d25fe76be (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
From f86486e128f62ed5a531163535d11f0aa0268928 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andreas=20M=C3=BCller?= <schnitzeltony@gmail.com>
Date: Sun, 5 May 2019 20:45:26 +0200
Subject: [PATCH] Fix memory-leak and reduce cpu-load slightly
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* when setting font remove old css provider befor setting new
  -> fix memory leak
* do call cpufreq_label_set_font only on init and when font was changed
  -> reduce cpu-load

Fixes https://bugzilla.xfce.org/show_bug.cgi?id=15218

Upstream-Status: Submitted [1]

[1] https://bugzilla.xfce.org/attachment.cgi?id=8492

Signed-off-by: Andreas Müller <schnitzeltony@gmail.com>
---
 panel-plugin/xfce4-cpufreq-configure.c |  4 ++++
 panel-plugin/xfce4-cpufreq-plugin.c    | 13 +++++++++++--
 panel-plugin/xfce4-cpufreq-plugin.h    |  2 ++
 3 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/panel-plugin/xfce4-cpufreq-configure.c b/panel-plugin/xfce4-cpufreq-configure.c
index 1205fc9..48e72ff 100644
--- a/panel-plugin/xfce4-cpufreq-configure.c
+++ b/panel-plugin/xfce4-cpufreq-configure.c
@@ -85,7 +85,10 @@ button_fontname_update(GtkWidget *button, gboolean update_plugin)
   }
 
   if (update_plugin)
+  {
+    cpufreq_label_set_font ();
     cpufreq_update_plugin (TRUE);
+  }
 }
 
 
@@ -155,6 +158,7 @@ button_fontcolor_clicked (GtkWidget *button, void *data)
   gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER (button), color);
   cpuFreq->options->fontcolor = gdk_rgba_to_string (color);
   g_free (color);
+  cpufreq_label_set_font ();
   cpufreq_update_plugin (TRUE);
 }
 
diff --git a/panel-plugin/xfce4-cpufreq-plugin.c b/panel-plugin/xfce4-cpufreq-plugin.c
index e886121..8d7c9e5 100644
--- a/panel-plugin/xfce4-cpufreq-plugin.c
+++ b/panel-plugin/xfce4-cpufreq-plugin.c
@@ -44,6 +44,7 @@ cpufreq_label_set_font (void)
 {
   gchar *css = NULL, *css_font = NULL, *css_color = NULL;
   GtkCssProvider *provider;
+  GtkStyleContext *context;
   PangoFontDescription *font;
 
   if (G_UNLIKELY (cpuFreq->label == NULL))
@@ -76,11 +77,17 @@ cpufreq_label_set_font (void)
   if (css)
   {
     provider = gtk_css_provider_new ();
+    context = GTK_STYLE_CONTEXT (gtk_widget_get_style_context (GTK_WIDGET (cpuFreq->label)));
+
+    if (currentProvider)
+      gtk_style_context_remove_provider (context, currentProvider);
 
     gtk_css_provider_load_from_data (provider, css, -1, NULL);
     gtk_style_context_add_provider (
-      GTK_STYLE_CONTEXT (gtk_widget_get_style_context (GTK_WIDGET (cpuFreq->label))),
+      context,
       GTK_STYLE_PROVIDER (provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+
+    currentProvider = provider;
   }
 
   g_free (css);
@@ -420,7 +427,6 @@ cpufreq_update_plugin (gboolean reset_label_size)
 
   if (cpuFreq->layout_changed)
   {
-    cpufreq_label_set_font ();
     cpufreq_widgets_layout ();
   }
 
@@ -601,6 +607,7 @@ cpufreq_widgets (void)
 
   gtk_widget_show_all (cpuFreq->button);
 
+  cpufreq_label_set_font ();
   cpufreq_update_plugin (TRUE);
 }
 
@@ -775,6 +782,8 @@ cpufreq_construct (XfcePanelPlugin *plugin)
 {
   xfce_textdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8");
 
+  currentProvider = NULL;
+
   cpuFreq = g_new0 (CpuFreqPlugin, 1);
   cpuFreq->options = g_new0 (CpuFreqPluginOptions, 1);
   cpuFreq->plugin = plugin;
diff --git a/panel-plugin/xfce4-cpufreq-plugin.h b/panel-plugin/xfce4-cpufreq-plugin.h
index a6895e4..6338698 100644
--- a/panel-plugin/xfce4-cpufreq-plugin.h
+++ b/panel-plugin/xfce4-cpufreq-plugin.h
@@ -95,6 +95,8 @@ typedef struct
 
 CpuFreqPlugin *cpuFreq;
 
+GtkCssProvider *currentProvider;
+
 G_BEGIN_DECLS
 
 void
-- 
2.20.1