X-Git-Url: https://diplodocus.org/git/xorg-xinput/blobdiff_plain/cb93b032989907e5274d9a5d95ae01535001ec19..3778f707cca0b9f023a8a5fc86e26776ef6e1b6c:/src/test_xi2.c diff --git a/src/test_xi2.c b/src/test_xi2.c index 6bad866..9ddb291 100644 --- a/src/test_xi2.c +++ b/src/test_xi2.c @@ -48,6 +48,7 @@ static void print_deviceevent(XIDeviceEvent* event) printf(" device: %d (%d)\n", event->deviceid, event->sourceid); printf(" detail: %d\n", event->detail); + printf(" flags: %s\n", (event->flags & XIKeyRepeat) ? "repeat" : ""); printf(" root: %.2f/%.2f\n", event->root_x, event->root_y); printf(" event: %.2f/%.2f\n", event->event_x, event->event_y); @@ -152,25 +153,28 @@ static void print_enterleave(XILeaveEvent* event) char *mode, *detail; int i; + printf(" device: %d (%d)\n", event->deviceid, event->sourceid); printf(" windows: root 0x%lx event 0x%lx child 0x%ld\n", event->root, event->event, event->child); switch(event->mode) { - case NotifyNormal: mode = "NotifyNormal"; break; - case NotifyGrab: mode = "NotifyGrab"; break; - case NotifyUngrab: mode = "NotifyUngrab"; break; - case NotifyWhileGrabbed: mode = "NotifyWhileGrabbed"; break; + case XINotifyNormal: mode = "NotifyNormal"; break; + 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) { - case NotifyAncestor: detail = "NotifyAncestor"; break; - case NotifyVirtual: detail = "NotifyVirtual"; break; - case NotifyInferior: detail = "NotifyInferior"; break; - case NotifyNonlinear: detail = "NotifyNonlinear"; break; - case NotifyNonlinearVirtual: detail = "NotifyNonlinearVirtual"; break; - case NotifyPointer: detail = "NotifyPointer"; break; - case NotifyPointerRoot: detail = "NotifyPointerRoot"; break; - case NotifyDetailNone: detail = "NotifyDetailNone"; break; + case XINotifyAncestor: detail = "NotifyAncestor"; break; + case XINotifyVirtual: detail = "NotifyVirtual"; break; + case XINotifyInferior: detail = "NotifyInferior"; break; + case XINotifyNonlinear: detail = "NotifyNonlinear"; break; + case XINotifyNonlinearVirtual: detail = "NotifyNonlinearVirtual"; break; + case XINotifyPointer: detail = "NotifyPointer"; break; + case XINotifyPointerRoot: detail = "NotifyPointerRoot"; break; + case XINotifyDetailNone: detail = "NotifyDetailNone"; break; } printf(" mode: %s (detail %s)\n", mode, detail); printf(" flags: %s %s\n", event->focus ? "[focus]" : "", @@ -196,6 +200,7 @@ static void print_enterleave(XILeaveEvent* event) static void print_propertyevent(Display *display, XIPropertyEvent* event) { char *changed; + char *name; if (event->what == XIPropertyDeleted) changed = "deleted"; @@ -203,10 +208,11 @@ static void print_propertyevent(Display *display, XIPropertyEvent* event) changed = "created"; else changed = "modified"; - - printf(" property: %ld '%s'\n", event->property, XGetAtomName(display, event->property)); + name = XGetAtomName(display, event->property); + printf(" property: %ld '%s'\n", event->property, name); printf(" changed: %s\n", changed); + XFree(name); } void test_sync_grab(Display *display, Window win) @@ -252,6 +258,35 @@ test_sync_grab(Display *display, Window win) 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; + default: + name = "unknown event type"; break; + } + return name; +} + + int test_xi2(Display *display, int argc, @@ -267,7 +302,7 @@ test_xi2(Display *display, /* Select for motion events */ mask.deviceid = XIAllDevices; - mask.mask_len = 2; + mask.mask_len = XIMaskLen(XI_RawMotion); mask.mask = calloc(mask.mask_len, sizeof(char)); XISetMask(mask.mask, XI_ButtonPress); XISetMask(mask.mask, XI_ButtonRelease); @@ -294,18 +329,23 @@ test_xi2(Display *display, 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, + XIGrabKeycode(display, 3, 24 /* q */, 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]); + XIUngrabKeycode(display, 3, 24 /* q */, win, nmods - 2, &modifiers[2]); } mask.deviceid = XIAllMasterDevices; memset(mask.mask, 0, 2); - XISetMask(mask.mask, XI_RawEvent); + 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); free(mask.mask); @@ -330,7 +370,7 @@ test_xi2(Display *display, 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: @@ -339,7 +379,11 @@ test_xi2(Display *display, case XI_HierarchyChanged: print_hierarchychangedevent(cookie->data); break; - case XI_RawEvent: + case XI_RawKeyPress: + case XI_RawKeyRelease: + case XI_RawButtonPress: + case XI_RawButtonRelease: + case XI_RawMotion: print_rawevent(cookie->data); break; case XI_Enter: