From 3b11387c543ead4b30224e9cfd658b6d665e8f0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Tue, 17 May 2016 18:18:05 +0200 Subject: [PATCH] UpKbdBacklight: always try to fetch the current brightness value on get When GetBrightness is called it's better to fetch the current value in the sysnode since many devices doesn't support the emission of brightness changes to userland, and this could make settings daemons to handle this value incorrectly https://bugs.freedesktop.org/show_bug.cgi?id=95457 --- src/up-kbd-backlight.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/up-kbd-backlight.c b/src/up-kbd-backlight.c index cfa1dd3..66c30db 100644 --- a/src/up-kbd-backlight.c +++ b/src/up-kbd-backlight.c @@ -103,6 +103,30 @@ up_kbd_backlight_get_brightness (UpExportedKbdBacklight *skeleton, GDBusMethodInvocation *invocation, UpKbdBacklight *kbd_backlight) { + gchar buf[128]; + guint64 brightness; + ssize_t len; + gchar *end = NULL; + + /* Read current backlight level, for devices that doesn't properly notify userland */ + if (kbd_backlight->priv->fd >= 0) { + lseek (kbd_backlight->priv->fd, 0, SEEK_SET); + len = read (kbd_backlight->priv->fd, buf, G_N_ELEMENTS (buf)); + + if (len > 0) { + buf[MIN(len, (int) G_N_ELEMENTS (buf) - 1)] = '\0'; + brightness = g_ascii_strtoull (buf, &end, 10); + + if (brightness == G_MAXUINT64 || (brightness == 0 && end == buf)) { + g_warning ("failed to convert brightness: %s", buf); + } else { + kbd_backlight->priv->brightness = brightness; + } + } + } else { + g_warning ("cannot read kbd_backlight as file not open"); + } + up_exported_kbd_backlight_complete_get_brightness (skeleton, invocation, kbd_backlight->priv->brightness); return TRUE; -- 1.9.1