Sophie

Sophie

distrib > Scientific%20Linux > 5x > x86_64 > media > main-src > by-pkgid > 26764e702e441b473525f6a16ac25557 > files > 28

hal-0.5.8.1-59.el5.src.rpm

diff -urNp hal-0.5.8.1/hald/linux/acpi.c hal-0.5.8.1-brightness/hald/linux/acpi.c
--- hal-0.5.8.1/hald/linux/acpi.c	2006-09-19 21:23:25.000000000 +0100
+++ hal-0.5.8.1-brightness/hald/linux/acpi.c	2009-07-15 17:29:34.000000000 +0100
@@ -734,6 +734,56 @@ fan_refresh (HalDevice *d, ACPIDevHandle
 	return TRUE;
 }
 
+/* contents of the file is:
+
+level:          15
+commands:       up, down
+commands:       level <level> (<level> is 0-15)
+
+*/
+static gint
+get_ibm_brightness_levels (const gchar *path)
+{
+	gchar *contents = NULL;
+	GError *error = NULL;
+	gchar **lines = NULL;
+	gboolean ret;
+	gint i;
+	gint levels = 0;
+
+	/* can we open the file */
+	ret = g_file_get_contents (path, &contents, NULL, &error);
+	if (!ret) {
+		HAL_WARNING (("Couldn't open %s: %s", path, error->message));
+		g_error_free (error);
+		goto out;
+	}
+
+	/* split into lines */
+	lines = g_strsplit (contents, "\n", 0);
+	for (i=0; lines[i] != NULL; i++) {
+
+		/* not a line we're interested in */
+		if (strstr (lines[i], "<level>") == NULL)
+			continue;
+
+		/* is this a 16 level machine (newer thinkpads) */
+		if (strstr (lines[i], "0-15") != NULL) {
+			levels = 16;
+			break;
+		}
+
+		/* is this a 8 level machine (older thinkpads) */
+		if (strstr (lines[i], "0-7") != NULL) {
+			levels = 8;
+			break;
+		}
+	}
+out:
+	g_free (contents);
+	g_strfreev (lines);
+	return levels;
+}
 /*
  * The different laptop_panel ACPI handling code is below. When a nice sysfs
  * interface comes along, we'll use that instead of these hacks.
@@ -765,7 +815,14 @@ laptop_panel_refresh (HalDevice *d, ACPI
 	} else if (acpi_type == ACPI_TYPE_IBM_DISPLAY) {
 		type = "ibm";
 		desc = "IBM LCD Panel";
-		br_levels = 8;
+
+		/* some older laptops have 8 states, some newer ones 16, but
+		 * if we can't find the correct value use 8, as this was the
+		 * previous hardcoded default */
+		br_levels = get_ibm_brightness_levels ("/proc/acpi/ibm/brightness");
+		if (br_levels == 0)
+			br_levels = 8;
+
 	} else if (acpi_type == ACPI_TYPE_PANASONIC_DISPLAY) {
 		type = "panasonic";
 		desc = "Panasonic LCD Panel";