user: Gaetan Nadon (gnadon) Joins Xorg Team
Please welcome Gaetan Nadon to the Xorg development team, mentored initially by Peter Hutterer (whot)
Please welcome Gaetan Nadon to the Xorg development team, mentored initially by Peter Hutterer (whot)
Recently I was tasked with porting GTK+ to support Xinput 2 (XI2), and whilst the port isn’t finished I quickly discovered just how big the conversion was. This page is designed to help someone who is familiar with XInput 1 switch to XInput 2 – it’s certainly is by no means a complete guide and anyone reading this should also take a look at the various Input2 recipies published.
XI2 is the first major rewrite of the XInput specification in years and with it comes a lot of enhanced functionality, but also a new API. The API was deliberately designed not to be backward compatible. Why? To prevent both XI1 and XI2 features to be intermingled. XI2 brings with it a new device model and a new input model. Both of these are incompatible with XI1. The decision to break the API was not a light one by Peter Hutterer, the main XI2 developer. Supporting XI1 would have ment future changes to XI2 would be impossible – there’s only so far you can push an out dated protocol and api. The added complexity of trying to maintain 2 code paths was also determined to be too high. XI2 is more than just a api/abi change. It literally change the entire input subsystem of the Xorg Xserver. XI2 supports:
With that in mind, the new XI2 API often leaves someone who’s been working with the XI1 wondering what the equivilant XI2 API call is. Most functions have an equivilant in XI2 function though the usage has more often than not, changed dramatically. Below is some examples of how to convert XI1 code to XI2 compatible code and a list of some of the changes which have occurred. If you find something missing, please add to the comments.
The biggest change that any XI1 developer will notice is the XDevice * type has vanished. All XI2 devices make use of the XID type instead. Under the hoods, in the Xserver and XDevice really equates back to an XID anyway now. The next biggest change XI1 developers will notice is the entire XInput2 API has had shifted namespaces. All XInput2 functions, types, etc are now prefixed with XI (ie XIEventMask). This was designed to force segregation of XI1 -> XI2 code.
The header file you include has also changed. Instead of:
#include <X11/extensions/XInput.h>
It’s now:
#include <X11/extensions/XInput2.h>
There’s also been a lot of changes to structures, functions, types and how they are used.
| XI1 Event | XI2 Event | Notes |
|---|---|---|
| XDeviceKeyEvent, XDeviceKeyPressedEvent, XDeviceKeyReleasedEvent, XDeviceButtonEvent, XDeviceButtonPressedEvent, XDeviceButtonReleasedEvent ,XDeviceMotionEvent | XIDeviceEvent | The various events are now incorporated into the one event type. XIDeviceEvent->evtype indicates the subtype of event. Ie XIMotion is a motion event for that device. |
| XProximityNotifyEvent, XProximityInEvent, XProximityOutEvent | XIDeviceEvent (See Note) | Proximity Events have been replaced with device events. Proximity is represented as a value in the valuator on one of the axes |
| XI1 Structure/Type | XI2 Structure/Type | Notes |
|---|---|---|
| XDeviceState | XIDeviceInfo | XIDeviceInfo also contains a name and classes |
| XAnyClassPtr | XIAnyClassInfo * | |
| XValuatorInfo | XIValuatorClassInfo | |
| XInputClass | XIAnyClassInfo | |
| XEventClass | XIEventMask | Used for selecting events to be monitored. One mask is used per device. Standard usage is: XIEventMask mask; mask.deviceid=//some device or XIAllDevices for all devices< mask.mask_len=2; mask.mask=calloc(mask.mask_len, sizeof(char)); XISetMask(mask.mask, XI_ButtonPress); .. XISelectEvents(display, win, &mask, 1) |
| XExtensionVersion | Struct Removed | XIQueryVersion should be used instead |
| XDeviceKeyEvent, XDeviceKeyPressedEvent, XDeviceKeyReleasedEvent, XDeviceButtonEvent, XDeviceButtonPressedEvent, XDeviceButtonReleasedEvent, | Structs Removed | XIDeviceEvents are now used instead |
| XDeviceFocusChangeEvnet, XDeviceFocusInEvent, XDeviceFocusOutEvent | Structs Removed | XIDeviceEvents are now used |
| XProximityNotifyEvent, XProximityInEvent, XProximityOutEvent | Structs Removed | XIDeviceEvents are now used |
| XI1 Function | XI2 Function | Notes |
|---|---|---|
| XFreeDeviceList | XIFreeDeviceInfo | |
| XDefineDeviceCursor | XIDefineCursor | |
| DeviceButton1Motion
DeviceButton2Motion … |
(No Equivelant) | |
| XWarpPointer
XWarpDevicePointer |
XIWarpPointer | XIWarpPointer makes use of the device id like XWarpDevicePointer (XI1.5). XWarpPointer is considered obsolete as it has no concept of a device |
| XQueryDeviceState | XIQueryDevice | Return type is XIDeviceInfo *, can be called with deviceid = XIAllDevices to query all devices hence the ndevices return |
| XFreeDeviceState | XIFreeDeviceInfo | |
| DeviceGrabButton | XIGrabButton | |
| XSelectExtensionEvent | XISelectEvents | Instead of a list of classes now a list of XIEventMask is used, one mask per device. XSelectExtensionEvent is still used for other extension events not related to XInput2 |
| XGetExtensionVersion | XIQueryVersion | If only XI1 is present this will be returned vi the major/minor numbers (ie major = 1) |
Below are some examples of how to use some of the new XI2 functions.
A simple indication how to register for events (XI2 greatly simplifies this)
static int motion_type = INVALID_EVENT_TYPE; static int button_press_type = INVALID_EVENT_TYPE; static int button_release_type = INVALID_EVENT_TYPE; static int key_press_type = INVALID_EVENT_TYPE; static int key_release_type = INVALID_EVENT_TYPE; static int proximity_in_type = INVALID_EVENT_TYPE; static int proximity_out_type = INVALID_EVENT_TYPE; static int register_event(Display *dpy, XDeviceInfo *info) { XEventClass event_list[7]; int i; XDevice *device; XInputClassInfo *ip; device = XOpenDevice(dpy, info->id); // Check for open error if (device->num_classes > 0) { for (ip = device->classes, i=0; i<info->num_classes; ip++, i++) { switch (ip->input_class) { case ButtonClass: DeviceButtonPress(device, button_press_type, event_list[number]); number++; DeviceButtonRelease(device, button_release_type, event_list[number]); number++; break; case ValuatorClass: DeviceMotionNotify(device, motion_type, event_list[number]); number++; if (handle_proximity) { ProximityIn(device, proximity_in_type, event_list[number]); number++; ProximityOut(device, proximity_out_type, event_list[number]); number++; } break; default: fprintf(stderr, "unknown class\n"); break; } } if (XSelectExtensionEvent(dpy, root_win, event_list, number)) { fprintf(stderr, "error selecting extended events\n"); return 0; } }
XIEventMask eventmask; unsigned char mask[1] = { 0 }; /* the actual mask */ eventmask.deviceid = 2; eventmask.mask_len = sizeof(mask); /* always in bytes */ eventmask.mask = mask; /* now set the mask */ XISetMask(mask, XI_ButtonPress); XISetMask(mask, XI_Motion); XISetMask(mask, XI_KeyPress); /* select on the window */ XISelectEvents(display, window, &eventmask, 1);
A simple indication how to get events from XI1 and XI2
//setup via other means int motion_type, button_press_type,button_release_type; void doEvents(Display *dpy) { XEvent Event; while(1) { XNextEvent(dpy, &Event); if (Event.type == motion_type) { XDeviceMotionEvent *motion = (XDeviceMotionEvent *) &Event; ... } else if ((Event.type == button_press_type) || (Event.type == button_release_type)) { XDeviceButtonEvent *button = (XDeviceButtonEvent *) &Event; ... }else if ((Event.type= .... )){ ... } }
//Somewhere else... int xi_opcode; if (!XQueryExtension(display, "XInputExtension",&xi_opcode,&event, &error)) { printf("X Input extension not available.\n"); return EXIT_FAILURE; }
void doEvents (Display *dpy ) { while(1) { XEvent ev; XGenericEventCookie *cookie = &ev.xcookie; XNextEvent(dpy, &ev); if (XGetEventData(dpy, cookie) && cookie->type == GenericEvent && cookie->extension==xi_opcode) { XIDeviceEvent *event = cookie->data; printf("EVENT type %d\n", event->evtype); switch (event->evtype) { // // In all below event>deviceid contains the id of the device // case XI_DeviceChanged: XIDeviceChangedEvent *dc = cookie->data; ... break; case XI_HierarchyChanged: XIHierarchyEvent *he = cookie->data; ... break; case XI_RawEvent: XIRawEvent *re = cookie->data; ... break; case XI_FocusIn: case XI_Enter: XIEnterEvent *ee = cookie->data; ... break; case XI_FocusOut: case XI_Leave: XILeaveEvent *le = cookie->data; ... break; case XI_PropertyEvent: XIPropertyEvent *pe = cookie->data; ... break; case XI_Motion: case XI_ButtonPress: case XI_ButtonRelease: case XI_KeyPress: case XI_KeyRelease: // do something with event (XIDeviceEvent contains data) break; } } } }
Please welcome Yang Zhao (yzhao) to the FD.o ranks. Working on Xorg and in particular the xf86-video-radeonhd driver.
Please welcome Alexander Sack (asac) to the Freedesktop team. Alex will be working on ModemManager & NetworkManager
Please welcome Arkadiusz Miskiewicz (arekm) to the open office team.
Please welcome Alex Villacís Lasso to the FreeDesktop ranks. Alex will be working on improving the Savage driver, mentored by Alex Deucher
Please welcome Eitan Isaccson to (eitani) to the ldtp group
Please welcome Fathi Boudra to the Freedesktop ranks. Fabo will be working on portland and xdg utils.
Please welcome Siarhei Siamashka to the Freedesktop world. Siarhei will be working on Xorg and Cairo, mentored by Søren Pedersen
In an effort to cleanup spam telepathy wiki has been shifted to annarchy, upgraded and catchpa’s added. All spam pages have now been removed.