Ubuntu Pastebin

Paste from Marco Trevisan (3v1n0) at Tue, 17 May 2016 15:10:30 +0000

Download as text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
diff --git a/src/up-kbd-backlight.c b/src/up-kbd-backlight.c
index cfa1dd3..8eed463 100644
--- a/src/up-kbd-backlight.c
+++ b/src/up-kbd-backlight.c
@@ -103,6 +103,28 @@ up_kbd_backlight_get_brightness (UpExportedKbdBacklight *skeleton,
         GDBusMethodInvocation *invocation,
         UpKbdBacklight *kbd_backlight)
 {
+ gchar buf[128];
+ guint64 brightness;
+ 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);
+
+   if (read (kbd_backlight->priv->fd, buf, G_N_ELEMENTS (buf)) > 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;
Download as text