summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColomban Wendling <[email protected]>2020-09-23 18:57:59 +0200
committerraveit65 <[email protected]>2020-10-20 10:30:34 +0200
commitecf24bdb7668a01e759050fff9d7ad74810863d5 (patch)
tree286646284e42b52e2f4dd9e09ee43a4fc077a239
parent34f8f2f5a1e21ee90f381fef429091e1af04fc9a (diff)
downloadmate-power-manager-ecf24bdb7668a01e759050fff9d7ad74810863d5.tar.bz2
mate-power-manager-ecf24bdb7668a01e759050fff9d7ad74810863d5.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).
-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 240cff8..bf57320 100644
--- a/applets/brightness/brightness-applet.c
+++ b/applets/brightness/brightness-applet.c
@@ -62,6 +62,8 @@ typedef struct{
guint level;
/* a cache for panel size */
gint size;
+ /* the slider action delaying */
+ guint slider_delay_id;
} GpmBrightnessApplet;
typedef struct{
@@ -109,6 +111,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
@@ -434,6 +441,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
@@ -444,8 +469,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;
}
@@ -847,6 +875,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);
@@ -973,6 +1006,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 (),