summaryrefslogtreecommitdiff
path: root/applets/brightness/brightness-applet.c
diff options
context:
space:
mode:
Diffstat (limited to 'applets/brightness/brightness-applet.c')
-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 (),