[Pommed-commits] r289 - in trunk: . pommed pommed/mactel

Julien Blache jblache at alioth.debian.org
Fri Mar 2 20:32:38 CET 2007


Author: jblache
Date: 2007-03-02 19:32:38 +0000 (Fri, 02 Mar 2007)
New Revision: 289

Modified:
   trunk/ChangeLog
   trunk/pommed/evdev.c
   trunk/pommed/kbd_backlight.h
   trunk/pommed/mactel/kbd_backlight.c
   trunk/pommed/pommed.c
Log:
Rework automatic keyboard backlight.


Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2007-03-01 21:38:57 UTC (rev 288)
+++ trunk/ChangeLog	2007-03-02 19:32:38 UTC (rev 289)
@@ -11,7 +11,12 @@
 	- gpomme: adapt to the new DBus notification.
 	- wmpomme: adapt to the new DBus notification.
 	- pommed: added support for nVidia GPUs.
-	- pommed: added support for mouseemu users (mouseemu virtual keyboard)
+	- pommed: added support for mouseemu users (mouseemu virtual
+	keyboard)
+	- pommed: rework keyboard backlight automatic mode, the backlight
+	off key now works as a toggle for the automatic mode, as it does
+	on Mac OS X
+	- pommed: turn off keyboard backlight when lid is closed
 	- pommed: added UNTESTED support for
 		  + PowerBook3,3: PowerBook G4 Titanium 15" October 2001
 		  + PowerBook3,4: PowerBook G4 Titanium 15" April 2002

Modified: trunk/pommed/evdev.c
===================================================================
--- trunk/pommed/evdev.c	2007-03-01 21:38:57 UTC (rev 288)
+++ trunk/pommed/evdev.c	2007-03-02 19:32:38 UTC (rev 289)
@@ -116,7 +116,7 @@
 	    if (!has_kbd_backlight())
 	      break;
 
-	    kbd_backlight_off();
+	    kbd_backlight_inhibit_toggle(KBD_INHIBIT_USER);
 	    break;
 
 	  case K_KBD_BCK_DOWN:
@@ -172,9 +172,17 @@
       if (ev.code == SW_LID)
 	{
 	  if (ev.value)
-	    logdebug("\nLID: closed\n");
+	    {
+	      logdebug("\nLID: closed\n");
+
+	      kbd_backlight_inhibit_set(KBD_INHIBIT_LID);
+	    }
 	  else
-	    logdebug("\nLID: open\n");
+	    {
+	      logdebug("\nLID: open\n");
+
+	      kbd_backlight_inhibit_clear(KBD_INHIBIT_LID);
+	    }
 	}
     }
 }

Modified: trunk/pommed/kbd_backlight.h
===================================================================
--- trunk/pommed/kbd_backlight.h	2007-03-01 21:38:57 UTC (rev 288)
+++ trunk/pommed/kbd_backlight.h	2007-03-02 19:32:38 UTC (rev 289)
@@ -24,6 +24,10 @@
 #define KBD_BACKLIGHT_MAX       255
 
 
+#define KBD_INHIBIT_USER        (1 << 0)
+#define KBD_INHIBIT_LID         (1 << 1)
+
+
 #define KBD_USER     0
 #define KBD_AUTO     1
 
@@ -33,8 +37,10 @@
   int level;
   int max;
 
+  int inhibit;
+  int inhibit_lvl;
+
   int auto_on;  /* automatic */
-  int off;      /* turned off ? */
   int r_sens;   /* right sensor */
   int l_sens;   /* left sensor */
 };
@@ -46,9 +52,15 @@
 has_kbd_backlight(void);
 
 void
-kbd_backlight_off(void);
+kbd_backlight_inhibit_set(int mask);
 
 void
+kbd_backlight_inhibit_clear(int mask);
+
+void
+kbd_backlight_inhibit_toggle(int mask);
+
+void
 kbd_backlight_step(int dir);
 
 void

Modified: trunk/pommed/mactel/kbd_backlight.c
===================================================================
--- trunk/pommed/mactel/kbd_backlight.c	2007-03-01 21:38:57 UTC (rev 288)
+++ trunk/pommed/mactel/kbd_backlight.c	2007-03-02 19:32:38 UTC (rev 289)
@@ -89,28 +89,11 @@
 
   FILE *fp;
 
+  if (kbd_bck_info.inhibit)
+    return;
+
   curval = kbd_backlight_get();
 
-  /* automatic backlight toggle by user */
-  if ((val == KBD_BACKLIGHT_OFF) && (kbd_bck_info.auto_on))
-    {
-      if (!kbd_bck_info.off)
-	{
-	  kbd_bck_info.off = 1;
-	  kbd_bck_info.level = curval;
-	}
-      else
-	{
-	  kbd_bck_info.off = 0;
-	  val = kbd_bck_info.level;
-	}
-    }
-
-  /* backlight turned on again by user */
-  if ((val > KBD_BACKLIGHT_OFF)
-      && (kbd_bck_info.auto_on) && (kbd_bck_info.off))
-    kbd_bck_info.off = 0;
-
   if (val == curval)
     return;
 
@@ -136,17 +119,14 @@
 }
 
 void
-kbd_backlight_off(void)
-{
-  kbd_backlight_set(KBD_BACKLIGHT_OFF, KBD_USER);
-}
-
-void
 kbd_backlight_step(int dir)
 {
   int val;
   int newval;
 
+  if (kbd_bck_info.inhibit)
+    return;
+
   val = kbd_backlight_get();
 
   if (val < 0)
@@ -176,11 +156,62 @@
   kbd_backlight_set(newval, KBD_USER);
 }
 
+
 void
+kbd_backlight_inhibit_set(int mask)
+{
+  if (!kbd_bck_info.inhibit)
+    kbd_bck_info.inhibit_lvl = kbd_bck_info.level;
+
+  kbd_backlight_set(KBD_BACKLIGHT_OFF,
+		    (mask == KBD_INHIBIT_LID) ? (KBD_AUTO) : (KBD_USER));
+
+  kbd_bck_info.inhibit |= mask;
+
+  logdebug("KBD: inhibit set 0x%02x -> 0x%02x\n", mask, kbd_bck_info.inhibit);
+}
+
+void
+kbd_backlight_inhibit_clear(int mask)
+{
+  kbd_bck_info.inhibit &= ~mask;
+
+  logdebug("KBD: inhibit clear 0x%02x -> 0x%02x\n", mask, kbd_bck_info.inhibit);
+
+  if (kbd_bck_info.inhibit)
+    return;
+
+  if (kbd_bck_info.auto_on)
+    {
+      kbd_bck_info.auto_on = 0;
+      kbd_bck_info.inhibit_lvl = 0;
+    }
+
+  kbd_backlight_set(kbd_bck_info.inhibit_lvl,
+		    (mask == KBD_INHIBIT_LID) ? (KBD_AUTO) : (KBD_USER));
+}
+
+void
+kbd_backlight_inhibit_toggle(int mask)
+{
+  if (kbd_bck_info.inhibit & mask)
+    kbd_backlight_inhibit_clear(mask);
+  else
+    kbd_backlight_inhibit_set(mask);
+}
+
+
+void
 kbd_backlight_init(void)
 {
+  if (kbd_cfg.auto_on)
+    kbd_bck_info.inhibit = 0;
+  else
+    kbd_bck_info.inhibit = KBD_INHIBIT_USER;
+
+  kbd_bck_info.inhibit_lvl = 0;
+
   kbd_bck_info.auto_on = 0;
-  kbd_bck_info.off = 0;
 
   if (!has_kbd_backlight())
     {
@@ -215,21 +246,25 @@
   if ((amb_r < 0) || (amb_l < 0))
     return;
 
+  mbpdbus_send_ambient_light(amb_l, kbd_bck_info.l_sens, amb_r, kbd_bck_info.r_sens);
+
+  kbd_bck_info.r_sens = amb_r;
+  kbd_bck_info.l_sens = amb_l;
+
+  /* Inhibited */
+  if (kbd_bck_info.inhibit)
+    return;
+
   if ((amb_r < kbd_cfg.on_thresh) && (amb_l < kbd_cfg.on_thresh))
     {
       logdebug("Ambient light lower threshold reached\n");
 
-      /* backlight turned on automatically, then disabled by user */
-      if (kbd_bck_info.auto_on && kbd_bck_info.off)
-	return;
-
       /* backlight already on */
       if (kbd_backlight_get() > KBD_BACKLIGHT_OFF)
 	return;
 
       /* turn on backlight */
       kbd_bck_info.auto_on = 1;
-      kbd_bck_info.off = 0;
 
       kbd_backlight_set(kbd_cfg.auto_lvl, KBD_AUTO);
     }
@@ -240,16 +275,10 @@
 	  logdebug("Ambient light upper threshold reached\n");
 
 	  kbd_bck_info.auto_on = 0;
-	  kbd_bck_info.off = 0;
 
 	  kbd_backlight_set(KBD_BACKLIGHT_OFF, KBD_AUTO);
 	}
     }
-
-  mbpdbus_send_ambient_light(amb_l, kbd_bck_info.l_sens, amb_r, kbd_bck_info.r_sens);
-
-  kbd_bck_info.r_sens = amb_r;
-  kbd_bck_info.l_sens = amb_l;
 }
 
 

Modified: trunk/pommed/pommed.c
===================================================================
--- trunk/pommed/pommed.c	2007-03-01 21:38:57 UTC (rev 288)
+++ trunk/pommed/pommed.c	2007-03-02 19:32:38 UTC (rev 289)
@@ -782,7 +782,7 @@
 		evdev_process_events(fds[i].fd);
 	    }
 
-	  if (kbd_cfg.auto_on && has_kbd_backlight())
+	  if (has_kbd_backlight())
 	    {
 	      /* is it time to chek the ambient light sensors ? */
 	      gettimeofday(&tv_now, NULL);
@@ -808,7 +808,7 @@
 		}
 	    }
 	}
-      else if (kbd_cfg.auto_on && has_kbd_backlight())
+      else if (has_kbd_backlight())
 	{
 	  /* poll() timed out, check ambient light sensors */
 	  kbd_backlight_ambient_check();




More information about the Pommed-commits mailing list