Tuesday, May 19, 2009

Fix Thinkpad Function Keys/Hot Keys in kde 4.2 (Jaunty) - patch to display brightness levels.

A small patch for the script to display the brightness level of your Thinkpad display with the brightness Increase/Decrease keys.


--- softkeys.py 2009-05-08 11:51:28.000000000 +0530                       
+++ softkeys-0.1.py     2009-05-19 12:43:58.000000000 +0530               
@@ -1,6 +1,7 @@                                                           
 #!/usr/bin/env python                                                    
 # -*- coding: utf-8 -*-                                                  
 # Copyright: 2009 by Tillmann Falck <tillmann _at_ falcken _dot_ de>     
+# Uttaran Dutta added the funtion for the display for the brightness for T60p <linux-hacks.blogspot.com>
 # License: GPL v2 or later                                                                             
                                                                                                        
 from Xlib.display import Display                                                                       
@@ -16,8 +17,11 @@                                                                                      
 XF86Battery = 244                                                                                      
 XF86Display = 235                                                                                      
 KeyUndock = 202                                                                                        
+XF86MonBrightnessDown = 232                                                                            
+XF86MonBrightnessUp = 233                                                                              
                                                                                                        
-keys = [XF86Sleep, XF86Standby, XF86Screensaver, XF86Battery, XF86Display, KeyUndock]                  
+                                                                                                       
+keys = [XF86Sleep, XF86Standby, XF86Screensaver, XF86Battery, XF86Display, KeyUndock, XF86MonBrightnessDown, XF86MonBrightnessUp]
                                                                                                                                 
 def callDisplay():                                                                                                              
   try:                                                                                                                          
@@ -63,6 +67,14 @@                                                                                                               
     print >>sys.stderr, 'Error while trying to change output, try full auto'                                                    
     os.system('xrandr --auto')                                                                                                  
                                                                                                                                 
+def briStats(bus):                                                                                                              
+  bri = bus.get_object( \                                                                                                       
+    'org.freedesktop.Hal', \                                                                                                    
+    '/org/freedesktop/Hal/devices/computer_backlight')                                                                          
+  briLevel = (bri.GetBrightness(dbus_interface='org.freedesktop.Hal.Device.LaptopPanel')*100)/(bri.GetProperty('laptop_panel.num_levels', dbus_interface='org.freedesktop.Hal.Device')-1)                                                                                         
+  s = 'Brightness level is %d%% <br />' % (briLevel)                                                                                    
+  return s                                                                                                                              
+                                                                                                                                        
 def acStats(bus):                                                                                                                       
   ac = bus.get_object( \                                                                                                                
     'org.freedesktop.Hal', \
@@ -91,6 +103,26 @@
     s = 'Battery %d level %d%%<br />' % (n+1, batLevel)
   return s

+def callBrightness():
+  try:
+    sessBus = dbus.SessionBus()
+    sysBus = dbus.SystemBus()
+
+    hal = dbus.Interface( \
+      sysBus.get_object('org.freedesktop.Hal', \
+        '/org/freedesktop/Hal/Manager'), \
+      dbus_interface='org.freedesktop.Hal.Manager')
+
+    s = briStats(sysBus)
+    ea = dbus.Array([], 's')
+    notify = sessBus.get_object('org.kde.VisualNotifications', '/VisualNotifications')
+    notify.Notify('brightness information',0,'brightness information','','Brightness Information', \
+      s,ea,ea,5000, \
+      dbus_interface='org.kde.VisualNotifications')
+  except:
+    print >>sys.stderr, 'No notifications or no information'
+
+
 def callBattery():
   try:
     sessBus = dbus.SessionBus()
@@ -101,6 +133,7 @@
         '/org/freedesktop/Hal/Manager'), \
       dbus_interface='org.freedesktop.Hal.Manager')

+    briStats(sysBus)
     if hal.DeviceExists('/org/freedesktop/Hal/devices/computer_power_supply_ac_adapter_AC'):
       ac = acStats(sysBus)
     else:
@@ -197,6 +230,8 @@
     callSuspend()
   elif event.detail == KeyUndock:
     callUndock()
+  elif event.detail == XF86MonBrightnessUp or event.detail == XF86MonBrightnessDown:
+    callBrightness()
   else:
     print >>sys.stderr, "Key %d not handeled" % event.detail


Note- The patch just enables the display changing for display brightness should be already working through acpi.

4 comments:

Sudarshan said...

I chanced upon your blog and found it very informative. The event blogs are striking enough to have a feel of the event, so, I would like to have a little chit-chat on your blogging interests. And even we are coming up with an event on startups on June 6th in Bangalore. So, can I have your contact details? Looking forward to hear from you.

varun said...

Thank you. We would not like to put up personal information in blogs, in such events please contact us on email. We would surely respond

Frost Icewind said...

How can i get this working in Lucid?

Thank you.

varun said...

@Frost Icewind: Must work as it is.....