#!/usr/bin/python # # handle-dock-change.py # Copyright (c) 2007, L. David Baron # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # The GNU General Public License is available at the URL # http://www.gnu.org/licenses/gpl.txt or from the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA import dbus, gobject, os, time # I'll need to change this for the next version of dbus-python # see http://dbus.freedesktop.org/doc/dbus-python/doc/tutorial.html#setting-up-an-event-loop # from dbus.mainloop.glib import DBusGMainLoop # DBusGMainLoop(set_as_default=True) import dbus.glib def device_state_changed(added, sender): # We don't actually get anything about the monitor itself (although # maybe I could if I plugged it into the USB, but that messes up # some other things). # So listen for changes of whether my keyboard (connected to the # same dock) is plugged in. # See dbus-monitor --system and lsusb for more information. if sender == "/org/freedesktop/Hal/devices/usb_device_10d5_5552_noserial_if0": os.system("/usr/bin/aticonfig --enable-monitor=auto --effective=now") time.sleep(1) # don't crash the X server if added: os.system("/usr/bin/xrandr -s 1920x1200") else: os.system("/usr/bin/xrandr -s 1400x1050") def device_removed(sender=None): device_state_changed(False, sender) def device_added(sender=None): device_state_changed(True, sender) bus = dbus.SystemBus() bus.add_signal_receiver(device_removed, "DeviceRemoved", "org.freedesktop.Hal.Manager", "org.freedesktop.Hal", "/org/freedesktop/Hal/Manager") bus.add_signal_receiver(device_added, "DeviceAdded", "org.freedesktop.Hal.Manager", "org.freedesktop.Hal", "/org/freedesktop/Hal/Manager") loop = gobject.MainLoop() loop.run()