Hi,

I attached to patches for powersave. Both are for brightness issues:

1.) powersave-fix_brightness_powersave.diff:
This patch fixes the output of 'powersave -k <x>' if the set value is higher 
than the highest available level. Currently powersave alway print the given 
value as set level. I added a goto to the GET_BRIGHTNESS path to print the 
current level.

2.) powersave-add_pmu_brightness.diff:
This patch adds brightness support for PMU (ppc/mac) to powersave.

Please review!

Cheers,

Danny

powersave-fix_brightness_powersave.diff:
 powersave.cpp |    4 +++-
 1 files changed, 3 insertions(+), 1 deletion(-)
powersave-add_pmu_brightness.diff:
 brightness.cpp |   81 +++++++++++++++++++++++++++++++++++++++++++++++++
 brightness.h   |   14 ++++++++
 2 files changed, 95 insertions(+)
Index: daemon/brightness.h
===================================================================
--- daemon/brightness.h	(revision 2020)
+++ daemon/brightness.h	(working copy)
@@ -33,6 +33,7 @@
 #define ACPI_TOSHIBA   "/proc/acpi/toshiba/lcd"
 #define ACPI_PANASONIC "/proc/acpi/panasonic/"
 #define LCD_OMNIBOOK   "/proc/omnibook/lcd"
+#define DEV_PMU        "/dev/pmu"
 
 /* merge #include "powersaved.h" */
 
@@ -153,3 +154,16 @@
 	int GetLevels();
 };
 
+class BrightnessPMU:public Brightness {
+      public:
+	void Init();
+
+	int Get();
+	void Set(int);
+
+	void Min();
+	void Med();
+
+	int GetLevels();
+};
+
Index: daemon/brightness.cpp
===================================================================
--- daemon/brightness.cpp	(revision 2020)
+++ daemon/brightness.cpp	(working copy)
@@ -35,6 +35,9 @@
 #include <sys/utsname.h>
 #include <sstream>
 
+#include <sys/ioctl.h>
+#include <linux/pmu.h>
+
 #include "powerlib.h"
 /* merge #include "config_pm.h" */
 
@@ -76,6 +79,12 @@
 		return new BrightnessOmnibook();
 	}
 
+	if ((fd = open(DEV_PMU, O_RDONLY)) > 0) {
+		close(fd);
+		return new BrightnessPMU();
+	}
+	
+
 	if (fd) {
 		close(fd);
 	}
@@ -727,3 +736,75 @@
 	return 11;
 }
 
+/* Brightness (PMU object (for ppc/mac/iBook)) */
+
+void BrightnessPMU::Init()
+{
+	last_percent = -1;
+	iface = DEV_PMU;
+	return;
+}
+
+int BrightnessPMU::Get()
+{
+	int level = -1;
+
+	if ((fd = open(iface, O_RDWR)) < 0) {
+		perror(iface);
+		goto out;
+	}
+
+	if (ioctl (fd, PMU_IOC_GET_BACKLIGHT, &level) < 0 ) {
+		pDebug(DBG_WARN, "Failed ioctl on /dev/pmu with PMU_IOC_GET_BACKLIGHT");
+		level = -1;
+		goto out;
+	}
+
+out:
+	if (fd) {
+		close(fd);
+	}
+	return level;
+}
+
+void BrightnessPMU::Set(int level)
+{
+	if ((fd = open(iface, O_RDWR)) < 1) {
+		perror(iface);
+		goto out;
+	}
+
+	if (level > 15)
+		level = 15;
+	else if (level < 1)
+		level = 1;
+	
+	if(ioctl (fd, PMU_IOC_SET_BACKLIGHT, &level) < 0) {
+		pDebug(DBG_WARN, "Failed ioctl on /dev/pmu with PMU_IOC_GET_BACKLIGHT");
+		goto out;
+	}
+
+out:
+	if (fd) {
+		close(fd);
+	}
+	return;
+}
+
+void BrightnessPMU::Min()
+{
+	Set(1); // looks as 0 is display off, use as last 1
+	return;
+}
+
+void BrightnessPMU::Med()
+{
+	Set(8);
+	return;
+}
+
+int BrightnessPMU::GetLevels()
+{
+	return 15;
+}
+
Index: user_binary/powersave.cpp
===================================================================
--- user_binary/powersave.cpp	(revision 2020)
+++ user_binary/powersave.cpp	(working copy)
@@ -937,7 +937,8 @@
 			//noerror
 			break;
 		case REPLY_SUCCESS:
-			fprintf(stderr, "Brightness level set to %d.\n", option);
+			fprintf(stderr, "Brightness level set. ");
+			goto get_brightness;
 			break;
 		case REPLY_NO_RIGHTS:
 			no_connect_no_rights_error();
@@ -949,6 +950,7 @@
 		}
 	}
 	if (GET_BRIGHTNESS) {
+get_brightness:
 		int level = -1;
 		err_code = dbusSendSimpleMessageWithReply(REQUEST_MESSAGE, &reply, "BrightnessGet");
 		switch (err_code) {
_______________________________________________
powersave-devel mailing list
[email protected]
http://forge.novell.com/mailman/listinfo/powersave-devel

Reply via email to