#!/usr/bin/env python import dbus,gobject,time,os from dbus.mainloop.glib import DBusGMainLoop from gnome import gconf def main(): global slidestatus global dpad global zoom xmodmap_conf='/usr/lib/sliderotate/normal.xmodmap' slidestatus = '/sys/devices/platform/gpio-switch/slide/state' global client client = gconf.client_get_default() global locked locked = False client.add_dir('/apps/rotate/',gconf.CLIENT_PRELOAD_NONE) client.set_string('/apps/rotate/orientation',"normal") DBusGMainLoop(set_as_default=True) bus = dbus.SystemBus() tklock = bus.get_object('com.nokia.mce','/com/nokia/mce/request') tklock.req_tklock_mode_change(dbus.String("unlocked")) if not os.path.isfile("/usr/bin/powerlaunch"): if os.path.isfile(slidestatus): #Running on N810 bus.add_signal_receiver(power,dbus_interface="org.freedesktop.Hal.Device",path='/org/freedesktop/Hal/devices/computer_logicaldev_input_0',signal_name="Condition") bus.add_signal_receiver(slide,dbus_interface="org.freedesktop.Hal.Device",signal_name="PropertyModified",path='/org/freedesktop/Hal/devices/platform_slide') else: #Running on N800 bus.add_signal_receiver(power,dbus_interface="org.freedesktop.Hal.Device",path='/org/freedesktop/Hal/devices/computer_logicaldev_input',signal_name="Condition") bus.add_signal_receiver(lock,dbus_interface="com.nokia.mce.signal",path='/com/nokia/mce/signal',signal_name='tklock_mode_ind') bus.add_signal_receiver(home,dbus_interface="com.nokia.mce.signal",path='/com/nokia/mce/signal',signal_name='sig_home_key_pressed_long_ind') loop = gobject.MainLoop() loop.run() def lock(member_keyword): global locked if member_keyword == "locked": locked = True elif member_keyword == "unlocked": locked = False def rotate(new_orientation): orientation = client.get_string('/apps/rotate/orientation') rotatedpad = client.get_bool('/apps/rotate/rotatedpad') zoomtopgx = client.get_bool('/apps/rotate/zoomtopgx') dpadright='keycode 111 = Right\\\\nkeycode 113 = Up\\\\nkeycode 114 = Down\\\\nkeycode 116 = Left' dpadnormal='keycode 111 = Up\\\\nkeycode 113 = Left\\\\nkeycode 114 = Right\\\\nkeycode 116 = Down' zoomright='keycode 74 = Page_Up\\\\nkeycode 73 = Page_Down' zoomnormal='keycode 74 = F8\\\\nkeycode 73 = F7' if new_orientation == "power": if orientation == "right": client.set_string('/apps/rotate/orientation',"normal") rotate='DISPLAY=:0.0 /usr/bin/xrandr -o normal' if rotatedpad: dpad=dpadnormal if zoomtopgx: zoom=zoomnormal elif orientation == "normal": client.set_string('/apps/rotate/orientation',"right") rotate='DISPLAY=:0.0 /usr/bin/xrandr -o right' if rotatedpad: dpad=dpadright if zoomtopgx: zoom=zoomright elif new_orientation == "closed": rotate='DISPLAY=:0.0 /usr/bin/xrandr -o %s' % (orientation) if orientation == "right": if rotatedpad: dpad=dpadright if zoomtopgx: zoom=zoomright elif orientation == "normal": if rotatedpad: dpad=dpadnormal if zoomtopgx: zoom=zoomnormal elif new_orientation == "open": rotate='DISPLAY=:0.0 /usr/bin/xrandr -o normal' dpad=dpadnormal zoom=zoomnormal os.system(rotate) if os.path.isfile("/usr/bin/xmodmap"): moddpad='echo -e %s |DISPLAY=:0.0 /usr/bin/xmodmap -' % (dpad) modzoom='echo -e %s |DISPLAY=:0.0 /usr/bin/xmodmap -' % (zoom) os.system(moddpad) os.system(modzoom) def slide(id,obj): f = open(slidestatus,'r') status = f.read() f.close() useclosed = client.get_bool('/apps/rotate/useclosed') useopen = client.get_bool('/apps/rotate/useopen') if status == "closed\n" and useclosed: new_orientation = "closed" rotate(new_orientation) elif status == "open\n" and useopen: new_orientation = "open" rotate(new_orientation) def home(): usehome = client.get_bool('/apps/rotate/usehome') if not locked and usehome: new_orientation = "power" rotate(new_orientation) def power(id,obj): usepower = client.get_bool('/apps/rotate/usepower') if not locked and usepower: new_orientation = "power" rotate(new_orientation) if __name__ == "__main__": main()