summaryrefslogtreecommitdiff
path: root/applets/brightness
diff options
context:
space:
mode:
authorColomban Wendling <[email protected]>2020-09-23 18:57:59 +0200
committerraveit65 <[email protected]>2020-10-16 22:51:49 +0200
commit54ce429fd89c0a7a09481637219945616b255ac1 (patch)
tree2561866a3630dc31597b7858682abb9a61457288 /applets/brightness
parent728d1cbcfae014bfdfc559d2a58f40036a08d0d1 (diff)
downloadmate-power-manager-54ce429fd89c0a7a09481637219945616b255ac1.tar.bz2
mate-power-manager-54ce429fd89c0a7a09481637219945616b255ac1.tar.xz
brightness applet: Prevent sliding from bogging down the UI
Do not perform a synchronous DBus call to update the brightness in real time when the slider move, because at least on some hardware the call is slow, which leads to the UI bogging down and looking frozen. To fix this, cap the update rate in response to slider motion. This makes the brightness apply slightly slower, but prevent most bogging down (if the rate is well chosen, at least).
Diffstat (limited to 'applets/brightness')
-rw-r--r--applets/brightness/brightness-applet.c38
1 files changed, 36 insertions, 2 deletions
diff --git a/applets/brightness/brightness-applet.c b/applets/brightness/brightness-applet.c
index fdb5ba5..2d71bae 100644
--- a/applets/brightness/brightness-applet.c
+++ b/applets/brightness/brightness-applet.c
@@ -61,6 +61,8 @@ typedef struct{
guint level;
/* a cache for panel size */
gint size;
+ /* the slider action delaying */
+ guint slider_delay_id;
} GpmBrightnessApplet;
typedef struct{
@@ -108,6 +110,11 @@ static void gpm_applet_destroy_cb (GtkWidget *widget);
#define MATE_PANEL_APPLET_VERTICAL(p) \
(((p) == MATE_PANEL_APPLET_ORIENT_LEFT) || ((p) == MATE_PANEL_APPLET_ORIENT_RIGHT))
+/* The frequency (in milliseconds) at which update the brightness when the UI
+ * slider is moved. A too short value might lead to freezing the UI, and a
+ * too long one will seem unresponsive. */
+#define GPM_BRIGHTNESS_APPLET_SLIDER_FREQUENCY 100
+
/**
* gpm_applet_get_brightness:
* Return value: Success value, or zero for failure
@@ -433,6 +440,24 @@ gpm_applet_minus_cb (GtkWidget *w, GpmBrightnessApplet *applet)
}
/**
+ * gpm_applet_slide_delayed_cb:
+ * @data: Brightness applet instance
+ *
+ * callback for the delayed slider changes, actually performing the DBus call
+ **/
+static gboolean
+gpm_applet_slide_delayed_cb (gpointer data)
+{
+ GpmBrightnessApplet *applet = data;
+
+ applet->call_worked = gpm_applet_set_brightness (applet);
+ gpm_applet_update_popup_level (applet);
+ applet->slider_delay_id = 0;
+
+ return FALSE;
+}
+
+/**
* gpm_applet_slide_cb:
* @widget: The sending widget (slider)
* @applet: Brightness applet instance
@@ -443,8 +468,11 @@ static gboolean
gpm_applet_slide_cb (GtkWidget *w, GpmBrightnessApplet *applet)
{
applet->level = gtk_range_get_value (GTK_RANGE(applet->slider));
- applet->call_worked = gpm_applet_set_brightness (applet);
- gpm_applet_update_popup_level (applet);
+ /* we delay applying the new value to improve reactivity, because the
+ * DBus call might be slow (and we don't want to spam the bus either) */
+ if (! applet->slider_delay_id)
+ applet->slider_delay_id = g_timeout_add (GPM_BRIGHTNESS_APPLET_SLIDER_FREQUENCY,
+ gpm_applet_slide_delayed_cb, applet);
return TRUE;
}
@@ -846,6 +874,11 @@ gpm_applet_destroy_cb (GtkWidget *widget)
{
GpmBrightnessApplet *applet = GPM_BRIGHTNESS_APPLET(widget);
+ if (applet->slider_delay_id) {
+ g_source_remove (applet->slider_delay_id);
+ applet->slider_delay_id = 0;
+ }
+
g_bus_unwatch_name (applet->bus_watch_id);
if (applet->icon != NULL)
g_object_unref (applet->icon);
@@ -970,6 +1003,7 @@ gpm_brightness_applet_init (GpmBrightnessApplet *applet)
applet->icon = NULL;
applet->connection = NULL;
applet->proxy = NULL;
+ applet->slider_delay_id = 0;
/* Add application specific icons to search path */
gtk_icon_theme_append_search_path (gtk_icon_theme_get_default (),