[Xfce4-commits] [xfce/xfce4-power-manager] 06/09: Battery plugin: Make display brightness widget snappier
noreply at xfce.org
noreply at xfce.org
Sun Jul 27 13:20:55 CEST 2014
This is an automated email from the git hooks/post-receive script.
eric pushed a commit to branch master
in repository xfce/xfce4-power-manager.
commit cee59a17df71765cde96a26440de4eb639eb21e9
Author: Harald Judt <h.judt at gmx.at>
Date: Sat Jul 26 21:58:53 2014 +0200
Battery plugin: Make display brightness widget snappier
Dragging the slider produces a lot of events, and processing these makes
the UI lag behind because of the many helper calls. Let's update the
brightness level only after a small timeout.
---
panel-plugins/battery/battery-button.c | 37 ++++++++++++++++++++++++++++++--
1 file changed, 35 insertions(+), 2 deletions(-)
diff --git a/panel-plugins/battery/battery-button.c b/panel-plugins/battery/battery-button.c
index b0bace7..027f5d4 100644
--- a/panel-plugins/battery/battery-button.c
+++ b/panel-plugins/battery/battery-button.c
@@ -42,6 +42,8 @@
#include "scalemenuitem.h"
+#define SET_LEVEL_TIMEOUT (25)
+
#define BATTERY_BUTTON_GET_PRIVATE(o) \
(G_TYPE_INSTANCE_GET_PRIVATE ((o), BATTERY_TYPE_BUTTON, BatteryButtonPrivate))
@@ -78,6 +80,9 @@ struct BatteryButtonPrivate
/* display brightness slider widget */
GtkWidget *range;
+
+ /* filter range value changed events for snappier UI feedback */
+ guint set_level_timeout;
};
typedef struct
@@ -470,6 +475,7 @@ battery_button_init (BatteryButton *button)
button->priv->brightness = xfpm_brightness_new ();
xfpm_brightness_setup (button->priv->brightness);
+ button->priv->set_level_timeout = 0;
button->priv->upower = up_client_new ();
if ( !xfconf_init (&error) )
@@ -499,6 +505,12 @@ battery_button_finalize (GObject *object)
g_free(button->priv->panel_icon_name);
+ if (button->priv->set_level_timeout)
+ {
+ g_source_remove(button->priv->set_level_timeout);
+ button->priv->set_level_timeout = 0;
+ }
+
g_signal_handlers_disconnect_by_data (button->priv->upower, button);
#ifdef XFCE_PLUGIN
@@ -788,8 +800,8 @@ increase_brightness (BatteryButton *button)
}
}
-static void
-range_value_changed_cb (GtkWidget *widget, BatteryButton *button)
+static gboolean
+brightness_set_level_with_timeout (BatteryButton *button)
{
gint32 range_level, hw_level;
@@ -803,6 +815,27 @@ range_value_changed_cb (GtkWidget *widget, BatteryButton *button)
{
xfpm_brightness_set_level (button->priv->brightness, range_level);
}
+
+ if (button->priv->set_level_timeout)
+ {
+ g_source_remove(button->priv->set_level_timeout);
+ button->priv->set_level_timeout = 0;
+ }
+
+ return FALSE;
+}
+
+static void
+range_value_changed_cb (GtkWidget *widget, BatteryButton *button)
+{
+ TRACE("entering");
+
+ if (button->priv->set_level_timeout)
+ return;
+
+ button->priv->set_level_timeout =
+ g_timeout_add(SET_LEVEL_TIMEOUT,
+ (GSourceFunc) brightness_set_level_with_timeout, button);
}
static void
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list