From 4ffd1ac2b9fc8d4a75db5cc2ead1bf5b3afac6c9 Mon Sep 17 00:00:00 2001 From: Hans de Goede Date: Sun, 16 Oct 2016 12:47:08 +0200 Subject: [PATCH 1/2] UpKbdBacklight: Emit BrightnessChanged when brightness is changed on GetBrightness Since commit 793642bfb7 ("UpKbdBacklight: don't cache the brightness level, always read it from sysfs attrib"), upower re-gets the actual brigthness from sysfs, to deal with hardware with "hardwired" keyboard brightness hotkeys. This commit makes upower also signal (other) users that the brightness has changed when the brightness has indeed changed underneath upower. --- src/up-kbd-backlight.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/up-kbd-backlight.c b/src/up-kbd-backlight.c index 925a5ed..4813aca 100644 --- a/src/up-kbd-backlight.c +++ b/src/up-kbd-backlight.c @@ -43,6 +43,7 @@ static void up_kbd_backlight_finalize (GObject *object); struct UpKbdBacklightPrivate { gint fd; + gint brightness; gint max_brightness; }; @@ -114,6 +115,7 @@ up_kbd_backlight_brightness_write (UpKbdBacklight *kbd_backlight, gint value) } /* emit signal */ + kbd_backlight->priv->brightness = value; up_exported_kbd_backlight_emit_brightness_changed (UP_EXPORTED_KBD_BACKLIGHT (kbd_backlight), value); @@ -139,6 +141,10 @@ up_kbd_backlight_get_brightness (UpExportedKbdBacklight *skeleton, if (brightness >= 0) { up_exported_kbd_backlight_complete_get_brightness (skeleton, invocation, brightness); + if (brightness != kbd_backlight->priv->brightness) { + kbd_backlight->priv->brightness = brightness; + up_exported_kbd_backlight_emit_brightness_changed (UP_EXPORTED_KBD_BACKLIGHT (kbd_backlight), brightness); + } } else { g_dbus_method_invocation_return_error (invocation, UP_DAEMON_ERROR, UP_DAEMON_ERROR_GENERAL, @@ -217,6 +223,7 @@ up_kbd_backlight_find (UpKbdBacklight *kbd_backlight) gchar *buf_max = NULL; gchar *buf_now = NULL; GError *error = NULL; + gint brightness; kbd_backlight->priv->fd = -1; @@ -261,8 +268,10 @@ up_kbd_backlight_find (UpKbdBacklight *kbd_backlight) kbd_backlight->priv->fd = open (path_now, O_RDWR); /* read brightness and check if it has an acceptable value */ - if (up_kbd_backlight_brightness_read (kbd_backlight) < 0) + brightness = up_kbd_backlight_brightness_read (kbd_backlight); + if (brightness < 0) goto out; + kbd_backlight->priv->brightness = brightness; /* success */ found = TRUE; -- 2.9.3