blob: ae8bc5279d1de90f909aa7b1229e790cdec93f5d [file] [log] [blame]
Brad Bishopc342db32019-05-15 21:57:59 -04001From f86486e128f62ed5a531163535d11f0aa0268928 Mon Sep 17 00:00:00 2001
2From: =?UTF-8?q?Andreas=20M=C3=BCller?= <schnitzeltony@gmail.com>
3Date: Sun, 5 May 2019 20:45:26 +0200
4Subject: [PATCH] Fix memory-leak and reduce cpu-load slightly
5MIME-Version: 1.0
6Content-Type: text/plain; charset=UTF-8
7Content-Transfer-Encoding: 8bit
8
9* when setting font remove old css provider befor setting new
10 -> fix memory leak
11* do call cpufreq_label_set_font only on init and when font was changed
12 -> reduce cpu-load
13
14Fixes https://bugzilla.xfce.org/show_bug.cgi?id=15218
15
16Upstream-Status: Submitted [1]
17
18[1] https://bugzilla.xfce.org/attachment.cgi?id=8492
19
20Signed-off-by: Andreas MΓΌller <schnitzeltony@gmail.com>
Andrew Geissler4b7c1152020-11-30 19:55:29 -060021
Brad Bishopc342db32019-05-15 21:57:59 -040022---
23 panel-plugin/xfce4-cpufreq-configure.c | 4 ++++
24 panel-plugin/xfce4-cpufreq-plugin.c | 13 +++++++++++--
25 panel-plugin/xfce4-cpufreq-plugin.h | 2 ++
26 3 files changed, 17 insertions(+), 2 deletions(-)
27
28diff --git a/panel-plugin/xfce4-cpufreq-configure.c b/panel-plugin/xfce4-cpufreq-configure.c
29index 1205fc9..48e72ff 100644
30--- a/panel-plugin/xfce4-cpufreq-configure.c
31+++ b/panel-plugin/xfce4-cpufreq-configure.c
32@@ -85,7 +85,10 @@ button_fontname_update(GtkWidget *button, gboolean update_plugin)
33 }
34
35 if (update_plugin)
36+ {
37+ cpufreq_label_set_font ();
38 cpufreq_update_plugin (TRUE);
39+ }
40 }
41
42
43@@ -155,6 +158,7 @@ button_fontcolor_clicked (GtkWidget *button, void *data)
44 gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER (button), color);
45 cpuFreq->options->fontcolor = gdk_rgba_to_string (color);
46 g_free (color);
47+ cpufreq_label_set_font ();
48 cpufreq_update_plugin (TRUE);
49 }
50
51diff --git a/panel-plugin/xfce4-cpufreq-plugin.c b/panel-plugin/xfce4-cpufreq-plugin.c
52index e886121..8d7c9e5 100644
53--- a/panel-plugin/xfce4-cpufreq-plugin.c
54+++ b/panel-plugin/xfce4-cpufreq-plugin.c
55@@ -44,6 +44,7 @@ cpufreq_label_set_font (void)
56 {
57 gchar *css = NULL, *css_font = NULL, *css_color = NULL;
58 GtkCssProvider *provider;
59+ GtkStyleContext *context;
60 PangoFontDescription *font;
61
62 if (G_UNLIKELY (cpuFreq->label == NULL))
63@@ -76,11 +77,17 @@ cpufreq_label_set_font (void)
64 if (css)
65 {
66 provider = gtk_css_provider_new ();
67+ context = GTK_STYLE_CONTEXT (gtk_widget_get_style_context (GTK_WIDGET (cpuFreq->label)));
68+
69+ if (currentProvider)
70+ gtk_style_context_remove_provider (context, currentProvider);
71
72 gtk_css_provider_load_from_data (provider, css, -1, NULL);
73 gtk_style_context_add_provider (
74- GTK_STYLE_CONTEXT (gtk_widget_get_style_context (GTK_WIDGET (cpuFreq->label))),
75+ context,
76 GTK_STYLE_PROVIDER (provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
77+
78+ currentProvider = provider;
79 }
80
81 g_free (css);
82@@ -420,7 +427,6 @@ cpufreq_update_plugin (gboolean reset_label_size)
83
84 if (cpuFreq->layout_changed)
85 {
86- cpufreq_label_set_font ();
87 cpufreq_widgets_layout ();
88 }
89
90@@ -601,6 +607,7 @@ cpufreq_widgets (void)
91
92 gtk_widget_show_all (cpuFreq->button);
93
94+ cpufreq_label_set_font ();
95 cpufreq_update_plugin (TRUE);
96 }
97
98@@ -775,6 +782,8 @@ cpufreq_construct (XfcePanelPlugin *plugin)
99 {
100 xfce_textdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8");
101
102+ currentProvider = NULL;
103+
104 cpuFreq = g_new0 (CpuFreqPlugin, 1);
105 cpuFreq->options = g_new0 (CpuFreqPluginOptions, 1);
106 cpuFreq->plugin = plugin;
107diff --git a/panel-plugin/xfce4-cpufreq-plugin.h b/panel-plugin/xfce4-cpufreq-plugin.h
108index a6895e4..6338698 100644
109--- a/panel-plugin/xfce4-cpufreq-plugin.h
110+++ b/panel-plugin/xfce4-cpufreq-plugin.h
111@@ -95,6 +95,8 @@ typedef struct
112
Andrew Geissler4b7c1152020-11-30 19:55:29 -0600113 extern CpuFreqPlugin *cpuFreq;
Brad Bishopc342db32019-05-15 21:57:59 -0400114
115+GtkCssProvider *currentProvider;
116+
117 G_BEGIN_DECLS
118
119 void
Andrew Geissler4b7c1152020-11-30 19:55:29 -0600120---
Brad Bishopc342db32019-05-15 21:57:59 -04001212.20.1