int i;
printf(" device: %d (%d)\n", event->deviceid, event->sourceid);
+ printf(" time: %ld\n", event->time);
printf(" detail: %d\n", event->detail);
+ switch(event->evtype) {
+ case XI_KeyPress:
+ case XI_KeyRelease:
+ printf(" flags: %s\n", (event->flags & XIKeyRepeat) ? "repeat" : "");
+ break;
+#if HAVE_XI21
+ case XI_ButtonPress:
+ case XI_ButtonRelease:
+ case XI_Motion:
+ printf(" flags: %s\n", (event->flags & XIPointerEmulated) ? "emulated" : "");
+ break;
+#endif
+#if HAVE_XI22
+ case XI_TouchBegin:
+ case XI_TouchUpdate:
+ case XI_TouchEnd:
+ printf(" flags:%s%s\n",
+ (event->flags & XITouchPendingEnd) ? " pending_end" : "",
+ (event->flags & XITouchEmulatingPointer) ? " emulating" : "");
+ break;
+#endif
+ }
printf(" root: %.2f/%.2f\n", event->root_x, event->root_y);
printf(" event: %.2f/%.2f\n", event->event_x, event->event_y);
printf(" group: locked %#x latched %#x base %#x effective: %#x\n",
event->group.locked, event->group.latched,
event->group.base, event->group.effective);
- printf(" valuators:");
+ printf(" valuators:\n");
val = event->valuators.values;
for (i = 0; i < event->valuators.mask_len * 8; i++)
if (XIMaskIsSet(event->valuators.mask, i))
- printf(" %.2f", *val++);
- printf("\n");
+ printf(" %i: %.2f\n", i, *val++);
- printf(" windows: root 0x%lx event 0x%lx child 0x%ld\n",
+ printf(" windows: root 0x%lx event 0x%lx child 0x%lx\n",
event->root, event->event, event->child);
}
static void print_devicechangedevent(Display *dpy, XIDeviceChangedEvent *event)
{
printf(" device: %d (%d)\n", event->deviceid, event->sourceid);
+ printf(" time: %ld\n", event->time);
printf(" reason: %s\n", (event->reason == XISlaveSwitch) ? "SlaveSwitch" :
"DeviceChanged");
print_classes_xi2(dpy, event->classes, event->num_classes);
static void print_hierarchychangedevent(XIHierarchyEvent *event)
{
int i;
+ printf(" time: %ld\n", event->time);
printf(" Changes happened: %s %s %s %s %s %s %s %s\n",
(event->flags & XIMasterAdded) ? "[new master]" : "",
(event->flags & XIMasterRemoved) ? "[master removed]" : "",
for (i = 0; i < event->num_info; i++)
{
- char *use;
+ char *use = "<undefined>";
switch(event->info[i].use)
{
case XIMasterPointer: use = "master pointer"; break;
int i;
double *val, *raw_val;
- printf(" device: %d\n", event->deviceid);
+ printf(" device: %d (%d)\n", event->deviceid, event->sourceid);
+ printf(" time: %ld\n", event->time);
printf(" detail: %d\n", event->detail);
- printf(" valuators:\n");
+#if HAVE_XI21
+ switch(event->evtype) {
+ case XI_RawButtonPress:
+ case XI_RawButtonRelease:
+ case XI_RawMotion:
+ printf(" flags: %s\n", (event->flags & XIPointerEmulated) ? "emulated" : "");
+ break;
+ }
+#endif
+ printf(" valuators:\n");
val = event->valuators.values;
raw_val = event->raw_values;
for (i = 0; i < event->valuators.mask_len * 8; i++)
static void print_enterleave(XILeaveEvent* event)
{
- char *mode, *detail;
+ char *mode = "<undefined>",
+ *detail = "<undefined>";
int i;
+ printf(" device: %d (%d)\n", event->deviceid, event->sourceid);
+ printf(" time: %ld\n", event->time);
printf(" windows: root 0x%lx event 0x%lx child 0x%ld\n",
event->root, event->event, event->child);
switch(event->mode)
case XINotifyGrab: mode = "NotifyGrab"; break;
case XINotifyUngrab: mode = "NotifyUngrab"; break;
case XINotifyWhileGrabbed: mode = "NotifyWhileGrabbed"; break;
+ case XINotifyPassiveGrab: mode = "NotifyPassiveGrab"; break;
+ case XINotifyPassiveUngrab:mode = "NotifyPassiveUngrab"; break;
}
switch (event->detail)
{
else
changed = "modified";
name = XGetAtomName(display, event->property);
+ printf(" time: %ld\n", event->time);
printf(" property: %ld '%s'\n", event->property, name);
printf(" changed: %s\n", changed);
printf("Done\n");
}
+static const char* type_to_name(int evtype)
+{
+ const char *name;
+
+ switch(evtype) {
+ case XI_DeviceChanged: name = "DeviceChanged"; break;
+ case XI_KeyPress: name = "KeyPress"; break;
+ case XI_KeyRelease: name = "KeyRelease"; break;
+ case XI_ButtonPress: name = "ButtonPress"; break;
+ case XI_ButtonRelease: name = "ButtonRelease"; break;
+ case XI_Motion: name = "Motion"; break;
+ case XI_Enter: name = "Enter"; break;
+ case XI_Leave: name = "Leave"; break;
+ case XI_FocusIn: name = "FocusIn"; break;
+ case XI_FocusOut: name = "FocusOut"; break;
+ case XI_HierarchyChanged: name = "HierarchyChanged"; break;
+ case XI_PropertyEvent: name = "PropertyEvent"; break;
+ case XI_RawKeyPress: name = "RawKeyPress"; break;
+ case XI_RawKeyRelease: name = "RawKeyRelease"; break;
+ case XI_RawButtonPress: name = "RawButtonPress"; break;
+ case XI_RawButtonRelease: name = "RawButtonRelease"; break;
+ case XI_RawMotion: name = "RawMotion"; break;
+ case XI_TouchBegin: name = "TouchBegin"; break;
+ case XI_TouchUpdate: name = "TouchUpdate"; break;
+ case XI_TouchEnd: name = "TouchEnd"; break;
+ case XI_RawTouchBegin: name = "RawTouchBegin"; break;
+ case XI_RawTouchUpdate: name = "RawTouchUpdate"; break;
+ case XI_RawTouchEnd: name = "RawTouchEnd"; break;
+ default:
+ name = "unknown event type"; break;
+ }
+ return name;
+}
+
+
int
test_xi2(Display *display,
int argc,
char *name,
char *desc)
{
- XIEventMask mask;
+ XIEventMask mask[2];
+ XIEventMask *m;
Window win;
+ int deviceid = -1;
+ int use_root = 0;
+ int rc;
- list(display, argc, argv, name, desc);
- win = create_win(display);
+ setvbuf(stdout, NULL, _IOLBF, 0);
- /* Select for motion events */
- mask.deviceid = XIAllDevices;
- mask.mask_len = XIMaskLen(XI_RawMotion);
- mask.mask = calloc(mask.mask_len, sizeof(char));
- XISetMask(mask.mask, XI_ButtonPress);
- XISetMask(mask.mask, XI_ButtonRelease);
- XISetMask(mask.mask, XI_KeyPress);
- XISetMask(mask.mask, XI_KeyRelease);
- XISetMask(mask.mask, XI_Motion);
- XISetMask(mask.mask, XI_DeviceChanged);
- XISetMask(mask.mask, XI_Enter);
- XISetMask(mask.mask, XI_Leave);
- XISetMask(mask.mask, XI_FocusIn);
- XISetMask(mask.mask, XI_FocusOut);
- XISetMask(mask.mask, XI_HierarchyChanged);
- XISetMask(mask.mask, XI_PropertyEvent);
- XISelectEvents(display, win, &mask, 1);
- XMapWindow(display, win);
- XSync(display, False);
+ if (argc >= 1 && strcmp(argv[0], "--root") == 0) {
+ use_root = 1;
- {
- XIGrabModifiers modifiers[] = {{0, 0}, {0, 0x10}, {0, 0x1}, {0, 0x11}};
- int nmods = sizeof(modifiers)/sizeof(modifiers[0]);
-
- mask.deviceid = 2;
- memset(mask.mask, 0, 2);
- XISetMask(mask.mask, XI_KeyPress);
- XISetMask(mask.mask, XI_KeyRelease);
- XISetMask(mask.mask, XI_ButtonPress);
- XISetMask(mask.mask, XI_ButtonRelease);
- XISetMask(mask.mask, XI_Motion);
- XIGrabButton(display, 2, 1, win, None, GrabModeAsync, GrabModeAsync,
- False, &mask, nmods, modifiers);
- XIGrabKeysym(display, 3, 0x71, win, GrabModeAsync, GrabModeAsync,
- False, &mask, nmods, modifiers);
- XIUngrabButton(display, 3, 1, win, nmods - 2, &modifiers[2]);
- XIUngrabKeysym(display, 3, 0x71, win, nmods - 2, &modifiers[2]);
+ argc--;
+ argv++;
}
- mask.deviceid = XIAllMasterDevices;
- memset(mask.mask, 0, 2);
- XISetMask(mask.mask, XI_RawKeyPress);
- XISetMask(mask.mask, XI_RawKeyRelease);
- XISetMask(mask.mask, XI_RawButtonPress);
- XISetMask(mask.mask, XI_RawButtonRelease);
- XISetMask(mask.mask, XI_RawMotion);
- XISelectEvents(display, DefaultRootWindow(display), &mask, 1);
+ rc = list(display, argc, argv, name, desc);
+ if (rc != EXIT_SUCCESS)
+ return rc;
- free(mask.mask);
+ if (use_root)
+ win = DefaultRootWindow(display);
+ else
+ win = create_win(display);
+
+ if (argc >= 1) {
+ XIDeviceInfo *info;
+ info = xi2_find_device_info(display, argv[0]);
+ /* info is alway valid, the list() call exits if the device
+ cannot be found, but let's shut up coverity */
+ if (!info)
+ return EXIT_FAILURE;
+ deviceid = info->deviceid;
+ }
- {
+ /* Select for motion events */
+ m = &mask[0];
+ m->deviceid = (deviceid == -1) ? XIAllDevices : deviceid;
+ m->mask_len = XIMaskLen(XI_LASTEVENT);
+ m->mask = calloc(m->mask_len, sizeof(char));
+ XISetMask(m->mask, XI_ButtonPress);
+ XISetMask(m->mask, XI_ButtonRelease);
+ XISetMask(m->mask, XI_KeyPress);
+ XISetMask(m->mask, XI_KeyRelease);
+ XISetMask(m->mask, XI_Motion);
+ XISetMask(m->mask, XI_DeviceChanged);
+ XISetMask(m->mask, XI_Enter);
+ XISetMask(m->mask, XI_Leave);
+ XISetMask(m->mask, XI_FocusIn);
+ XISetMask(m->mask, XI_FocusOut);
+#if HAVE_XI22
+ XISetMask(m->mask, XI_TouchBegin);
+ XISetMask(m->mask, XI_TouchUpdate);
+ XISetMask(m->mask, XI_TouchEnd);
+#endif
+ if (m->deviceid == XIAllDevices)
+ XISetMask(m->mask, XI_HierarchyChanged);
+ XISetMask(m->mask, XI_PropertyEvent);
+
+ m = &mask[1];
+ m->deviceid = (deviceid == -1) ? XIAllMasterDevices : deviceid;
+ m->mask_len = XIMaskLen(XI_LASTEVENT);
+ m->mask = calloc(m->mask_len, sizeof(char));
+ XISetMask(m->mask, XI_RawKeyPress);
+ XISetMask(m->mask, XI_RawKeyRelease);
+ XISetMask(m->mask, XI_RawButtonPress);
+ XISetMask(m->mask, XI_RawButtonRelease);
+ XISetMask(m->mask, XI_RawMotion);
+#if HAVE_XI22
+ XISetMask(m->mask, XI_RawTouchBegin);
+ XISetMask(m->mask, XI_RawTouchUpdate);
+ XISetMask(m->mask, XI_RawTouchEnd);
+#endif
+
+ XISelectEvents(display, win, &mask[0], use_root ? 2 : 1);
+ if (!use_root) {
+ XISelectEvents(display, DefaultRootWindow(display), &mask[1], 1);
+ XMapWindow(display, win);
+ }
+ XSync(display, False);
+
+ free(mask[0].mask);
+ free(mask[1].mask);
+
+ if (!use_root) {
XEvent event;
XMaskEvent(display, ExposureMask, &event);
XSelectInput(display, win, 0);
cookie->type == GenericEvent &&
cookie->extension == xi_opcode)
{
- printf("EVENT type %d\n", cookie->evtype);
+ printf("EVENT type %d (%s)\n", cookie->evtype, type_to_name(cookie->evtype));
switch (cookie->evtype)
{
case XI_DeviceChanged:
case XI_RawButtonPress:
case XI_RawButtonRelease:
case XI_RawMotion:
+ case XI_RawTouchBegin:
+ case XI_RawTouchUpdate:
+ case XI_RawTouchEnd:
print_rawevent(cookie->data);
break;
case XI_Enter: