Input system for GLFW 3
From GLFW
The aim of this document is to collect information about the input subsystem. It is meant to be a collection of notes that are put here to highlight the issues, solutions and present idea to implement GLFW 3 input rework.
Contents |
Input system internal
The main difference with the existing GLFW is that all the function that are waiting for events now needs to listen to multiple event source at the same time. The notion of event source is implemented in many different way on the different platform. However, it is always based on the principal that instead of waiting for events on the windowing event queue. However, this prevent us from listening to event on multiple queue. We thus need to introduce an intermediate object that only act as a collector of events.
The solution identified for each platfrom is described below:
- Linux/X11 and Cocoa: select or file descriptor base mechanism.
- Win32: CreateEvent mechanism also it might require the introduction of threads internally.
Devices
Currently GLFW support properly keyboard and mouse. Joystick are supported but you don't have Mac OS X support in the main line and the API is based on polling. The rest of GLFW is event driven we want to move to that model as well. Tablet are not supported just yet unless they emulate a mouse.
Keyboard
- Better unicode support
- Alternate input method relying on mechanism such as XIM (X11)
Mouse
- Bidirectional mouse wheel scrolling (implemented)
Joystick
- Event driven
- Device enumeration
- Force feedback support
- Support for Mac OS X (branch available in SF.net Subversion repository)
Tablet
Patch exists but needs work.
Platform-specific information
Linux/X11
Event source
The concept of event source is implemented using the select system call. Support is already implemented and sort of work. It still needs investigation as it has a remaining problem when the application is killed or aborted. There seems to be an issue in the use of select that's causing a segmentation fault. The current trace point out some glibc internal function. This needs to be fixed before we are able to deliver this change to the master branch.
Device enumeration
Device enumeration is a two stage process the first stage consists in registering device already available in the system. This stage includes extracting device information and building a list of available input devices. The second stage consists in monitoring changes to the list of devices connected to the system and notifying the application about changes.
Joystick
Implementation of an event driven API to joystick is not a technical issue. It is relatively straight forward and does not need any special support as it is what is implemented as part of the input system driver. All USB joystick are supported as is. It is possible to extract the name of the joystick, the number of axis and the number of button from the driver.
| TODO: | Check with game port joystick whether they are reported as part of the input system or through a different device. |
The enumeration of device is simple:
- Register a monitor on the directory /dev/input
- Go through the list of device connected at the current time using directory listing on /dev/input looking for generic event source devices (eventXXX)
- Extract device capabilities in order to define whether it is a joystick, a mouse, a keyboard or a tablet, or something completely different (like power button and so on).
- For all joystick add it to the list of supported device.
- poll for changes on the device list as part of the event loop.
- Changes are device addition/removal.
If the inotify API is not available, update to the device list is not supported.
*BSD/X11
No progress.
Solaris/X11
No progress.
Win32
Event source
In order to be able to implement the event driven interface and to be able to wait for change on multiple event source the link below describes how it can be implemented using CreateEvent. The mechanism is very similar to select.
Joystick
Win32 support for joystick is implemented using one of the two alternative:
- WinMM which is the multimedia extension (legacy API)
- DirectInput8 which provides us with all the functionality we want on all type of joystick but the controller for XBOX360
- XInput which provides exclusive access to the XBOX360 controller device.
The later is not that interesting for us now and will only be used in later version.
The DirectInput8 API provides at least the following features:
- API to poll joystick for changes.
- API to implement an EVENT driven API for joystick.
- API to enumerate device and capabilities.
Cocoa
Joystick support on Mac OS X relies on HID and the HID manager API. As a consequence most of the work is very similar to Linux/X11.
![[Main Page]](http://wiki.glfw.org/wiki/images/logo.png)