HPlogo HP Xlib Extensions: > Chapter 5 X Input Device Extension Functions

Listing Available Input Devices

» 

Technical documentation

Complete book in PDF

 » Table of Contents

 » Index

Clients that wish to access input devices through the input extension typically perform the following steps:

  • Determine which input devices are available via XListInputDevices.

  • Open the desired devices via XOpenDevice, specifying device ids obtained via XListInputDevices.

  • Determine the eventclass to be used in selecting each desired input extension event, and the event type that the event will have. This is done using macros provided by the input extension and the XDevice structure returned by XOpenDevice.

  • Select the desired events via the XSelectExtension request, passing the eventclasses obtained above.

  • Receive the desired events via XNextEvent.

Listing Input Devices

To obtain a list of available input devices, use XListInputDevices.

XDeviceInfo *XListInputDevices(display, ndevices_return)
Display *display;
int *ndevices_return;

Title not available (Listing Input Devices )

display

Specifies the connection to the X server.

ndevices_return

Specifies a pointer to a variable where the number of available devices can be returned.

The XListInputDevices function lists the available input devices. This list includes the X pointer, the X keyboard, and any other input devices that are currently accessible through the X server.

Input devices are not opened until requested by some client. After an input device has been listed, it is possible for some non-X process to open that device. In this case, an X request to open a device can fail because the device is no longer available, even though it was available when listed.

For each input device available to the server, the XListInputDevices request returns an XDeviceInfo structure. The inputclassinfo field of that structure contains a pointer to a list of variable-length structures, each of which contains information about one class of input supported by the device.

The XDeviceInfo structure is defined as follows:

typedef struct _XDeviceInfo {
XID id;
Atom type;
char *name;
int num_classes;
int use;
XAnyClassPtr inputclassinfo;
} XDeviceInfo;

The id is a number in the range 0-128 that uniquely identifies the device. It is assigned to the device when it is initialized by the server.

The type field is of type Atom and indicates the nature of the device.

The name field contains a pointer to a null-terminated string that corresponds to one of the defined device types. The following constants identify standard device names: XI_MOUSE, XI_TABLET, XI_KEYBOARD, XI_TOUCHSCREEN, XI_TOUCHPAD, XI_BUTTONBOX, XI_BARCODE, XI_TRACKBALL, XI_QUADRATURE, XI_ID_MODULE, XI_ONE_KNOB, and XI_NINE_KNOB.

Additional input devices may be supported in future releases.

These names may be directly compared with the name field of the XDeviceInfo structure, or used in an XInternAtom request to return an atom that can be compared with the type field of the XDeviceInfo structure.

The num_classes field is a number in the range 0-255 that specifies the number of input classes supported by the device for which information is returned by ListInputDevices. Some input classes, such as class Focus and class Proximity, do not have any information to be returned by ListInputDevices.

The use field specifies how the device is currently being used. If the value is IsXKeyboard, the device is currently being used as the X keyboard. If the value is IsXPointer, the device is currently being used as the X pointer. If the value is IsXExtensionDevice, the device is available for use as an extension device.

Any client may change the use of an input device via the XChangeKeyboardDevice or XChangePointerDevice requests.

The inputclassinfo field contains a pointer to the first input-class specific data. The first two fields are common to all classes. The list of classes supported by each device is a linked list. Refer to the sample program at the end of this chapter for information about traversing that list.

The class field is a number in the range 0-255. It uniquely identifies the class of input for which information is returned. Currently defined classes are KeyClass, ButtonClass, and ValuatorClass.

The length field is a number in the range 0-255. It specifies the number of bytes of data that are contained in this input class. The length includes the class and length fields.

The XKeyInfo structure describes the characteristics of the keys on the device. It is defined as follows:

typedef struct _XKeyInfo {
XID class;
int length;
unsigned short min_keycode;
unsigned short max_keycode;
unsigned short num_keys;
} XKeyInfo;

The min_keycode field specifies the minimum keycode that the device will report. The minimum keycode will not be smaller than 8.

The max_keycode field specifies the maximum keycode that the device will report. The maximum keycode will not be larger than 255.

The num_keys field specifies the number of keys that the device has.

The XButtonInfo structure describes the characteristics of the buttons on the device. It is defined as follows:

typedef struct _XButtonInfo {
XID class;
int length;
short num_buttons;
} XButtonInfo

The num_buttons field specifies the number of buttons that the device has.

The XValuatorInfo structure describes the characteristics of the valuators on the device. It is defined as follows:

typedef struct _XValuatorInfo {
XID class;
int length;
unsigned char num_axes;
unsigned char mode;
unsigned long motion_buffer;
XAxisInfoPtr axes;
} XValuatorInfo;

The num_axes field contains the number of axes the device supports.

The mode field is a constant that has one of the following values: Absolute or Relative. Some devices allow the mode to be changed dynamically via the SetDeviceMode request.

The motion_buffer_size field specifies the number of elements that can be contained in the motion history buffer for the device.

The axes field contains a pointer to an XAxisInfo structure.

The XAxisInfo structure describes the characteristics of a single valuator on the device. It is defined as follows:

typedef struct _XAxisInfo {
int resolution;
int min_value;
int max_value;
} XAxisInfo;

The resolution field contains a number in counts/meter.

The min_value field contains a number that specifies the minimum value the device reports for this axis. For devices whose mode is Relative, the min_val field will contain 0.

The max_value field contains a number that specifies the maximum value the device reports for this axis. For devices whose mode is Relative, the max_val field will contain 0.

Freeing the List of Input Devices

To free the XDeviceInfo array created by XListInputDevices, use XFreeDeviceList.

XFreeDeviceList(list)
XDeviceInfo *list;

Title not available (Freeing the List of Input Devices )

list

Specifies a pointer to the list of XDeviceInfo structures to be freed.

The XFreeDeviceList function frees the list of available extension input devices.

© 1995 Hewlett-Packard Development Company, L.P.