[Utopia] simple hal-based input library



I wrote a really simple library for providing discovery and access to
input devices, libinput:

	http://primates.ximian.com/~rml/libinput/libinput-0.0.1.tar.gz

The real purpose is to show an example of how to wrap HAL and write
class-specific libraries.  But the result ends up being moderately
useful, since currently figuring out what mice or joysticks are on the
system is total guesswork.

The library performs two basic features:

	- device discovery: apps can query the system for input devices
	  and receive a list in return.

	- device notification: apps can register for callbacks to learn
	  when an input device is added to or removed from the system.

The idea is to write a library that is a little more device-specific and
a little less HAL-specific to handle these tasks.  The library could do
other input-related functions, too.  Wherever possible, HAL ought to be
used.

It is just an example, but if people start using it I will take patches.
First and foremost, it needs to use autotools. :-)

Best,

	Robert Love


The README:

libinput - simple example of a HAL-based library

libinput is used to enumerate all input devices on the system.  It
currently does not provide a mechanism for parsing by type (e.g.,
keyboard, mouse, joystick, etc.) so it is of limited value.  It is just
an example, although it is a huge improvement over current methods for
finding mice and joysticks on a system.

Usage is pretty easy.  In the simplest form, simply do

	struct input *devices;

	if (input_init ())
		/* error ... */

	devices = input_devices_get ();
	while (devices) {
		/* ... */
		devices = devices->next;
	}
	input_devices_put (devices);

Each input device is stored in a 'struct device', which is defined in
libinput.h.

It is possible to open a given device:

	fd = input_device_open (device, 0);

and to close a given device:

	input_device_close (device);

These functions are trivial wrappers around open(2) and close(2).  The
idea is to hide the concept of device nodes from the application.

It is also possible to register callbacks when input devices are added
and removed from the system.  This is, perhaps, a bit cooler and better
shows off the usefulness of HAL (as if correctly enumerating the devices
were not enough).

	void my_mainloop (DBusConnection *dbus_connection)
	{
		dbus_connection_setup_with_g_main (dbus_connection,
						   NULL);
	}

	void my_added (struct input *device)
	{
		printf ("%s was just hotplugged!\n", device->product);
	}

	void my_removed (struct input *device)
	{
		printf ("%s was just hotunplugged!\n", device->product);
	}

	/* ... */

	input_init_with_callbacks (&my_mainloop, &my_added,
				   &my_removed);

	gtk_main ();

Remember, the goal is that the user should NEVER have to touch the
concept of device nodes -- but neither should the applications, either.





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]