Getting involved in XInput hotplug development?

Enleth enleth at enleth.com
Sun Feb 4 13:28:07 PST 2007


As someone might be interested in that, there are two little pieces of code I 
wrote, primarily for my personal use (yes, I do really need this hotplug that 
much), and some thoughts:

1. A patch for xserver, hw/xfree86/common/xf86Xinput.c, that prevents crashes 
caused by DBUS messages without an identifier or a driver specified, both 
cases result in a SIGSEV (no driver - crash a few lines down, no identifier - 
one function call further from there, I can't recall the backtrace now).

2. A simple Python script that relays HAL DeviceAdded events to Xserver, 
currently supporting mice and Wacom tablets (I had to adapt the 
linuxwacom.sf.net driver to the new XInput code, the patch will be on its way 
to their mailing list shortly). I know it's ugly because it uses evdev's 
Device option, but works. It takes the display number as an argument, e.g. 
python inputadd.py 0. The identifier string should probably be generated in a 
smarter way to avoid messing things up when two identical devices get plugged 
in at the same time, but that's something to do later.

Still, there is one thing that concerned me while writing the script, namely 
removing the devices. The server expects numerical device identifier, the 
script as it is now has no way of knowing it. There could be a few different 
ways to get around this, but I didn't try to implement any of them, as I'd 
like, even in something I write for myself, to do that the way X.org 
developers see it, so it's either useful for everyone, or just easy for me to 
switch to something more "official" later on.

Regards,
-- 
Remigiusz "Enleth" Marcinkiewicz, enleth at enleth.com
WWW http://enleth.com http://jaskiniabehemota.net
JID enleth at chrome.pl
-------------- next part --------------
A non-text attachment was scrubbed...
Name: xserver-dbus-crash.patch
Type: text/x-diff
Size: 778 bytes
Desc: not available
URL: <http://lists.x.org/archives/xorg/attachments/20070204/8e83a7cd/attachment.patch>
-------------- next part --------------
import sys
import dbus
import gobject
if getattr(dbus, 'version', (0,0,0)) >= (0,41,0):
    import dbus.glib

display = sys.argv[1]
dbus_x_name = 'org.x.config.display' + display
dbus_x_object = '/org/x/config/' + display
dbus_x_intf_input = 'org.x.config.input'

dbus_hal_name = 'org.freedesktop.Hal'
dbus_hal_object = '/org/freedesktop/Hal/Manager'
dbus_hal_intf_manager = 'org.freedesktop.Hal.Manager'
dbus_hal_intf_device = 'org.freedesktop.Hal.Device'

bus = dbus.SystemBus()

xorg_obj = bus.get_object(dbus_x_name,dbus_x_object)
xorg = dbus.Interface(xorg_obj,dbus_x_intf_input)

hal_obj = bus.get_object(dbus_hal_name,dbus_hal_object)
hal = dbus.Interface(hal_obj,dbus_hal_intf_manager)

def SendAddRequest(identifier, device, driver = 'evdev', isCore = 'true', options = []):
	print "Sending device add message."
	xorg.add(['identifier',identifier],['device',device],['driver',driver],['SendCoreEvents',isCore],*options)


def AddMouse(dev):
	print "Adding a mouse."
	name = dev.GetProperty('input.product',  dbus_interface=dbus_hal_intf_device)
	device = dev.GetProperty('input.device',  dbus_interface=dbus_hal_intf_device)
	SendAddRequest(name,device)
	print "Added a mouse."

def AddTablet(dev):
	print "Adding a tablet."
	name = dev.GetProperty('input.product', dbus_interface=dbus_hal_intf_device)
	device = dev.GetProperty('input.device', dbus_interface=dbus_hal_intf_device)
	SendAddRequest(name,device,driver='wacom',options=[['USB','true'],['type','stylus']])
	print "Added a tablet."

def dev_add_callback(udi):
	print "HAL: a device was added."
	dev = bus.get_object('org.freedesktop.Hal',udi)
	if not dev.PropertyExists('info.category',  dbus_interface=dbus_hal_intf_device):
		print "No info.category, ignoring."
		return
	print dev.GetProperty('info.category', dbus_interface=dbus_hal_intf_device)
	if dev.GetProperty('info.category', dbus_interface=dbus_hal_intf_device) == 'input':
		print "Input device detected."
		if not dev.PropertyExists('info.capabilities', dbus_interface=dbus_hal_intf_device):
			return
		capabilities = set(dev.GetProperty('info.capabilities', dbus_interface=dbus_hal_intf_device))
		if 'input.mouse' in capabilities:
			AddMouse(dev)
		if 'input.tablet' in capabilities:
			AddTablet(dev)
	else:
		print "Nothing interesting, ignoring."

hal.connect_to_signal('DeviceAdded',dev_add_callback)

mainloop = gobject.MainLoop()
mainloop.run()


More information about the xorg mailing list