]> diplodocus.org Git - xorg-xinput/blobdiff - src/test_xi2.c
xinput 1.5.0
[xorg-xinput] / src / test_xi2.c
index 8c6175f7637f6b71caea6ba95b66d422c49ac669..53d984f04b9bd2919226b04e86e8656b7cb6c34a 100644 (file)
@@ -29,9 +29,6 @@
 extern void print_classes_xi2(Display*, XIAnyClassInfo **classes,
                               int num_classes);
 
-#define BitIsOn(ptr, bit) (((unsigned char *) (ptr))[(bit)>>3] & (1 << ((bit) & 7)))
-#define SetBit(ptr, bit)  (((unsigned char *) (ptr))[(bit)>>3] |= (1 << ((bit) & 7)))
-
 static Window create_win(Display *dpy)
 {
     Window win = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 0, 0, 200,
@@ -39,10 +36,8 @@ static Window create_win(Display *dpy)
     Window subwindow = XCreateSimpleWindow(dpy, win, 50, 50, 50, 50, 0, 0,
             BlackPixel(dpy, 0));
 
-    XSelectInput(dpy, win, ExposureMask);
     XMapWindow(dpy, subwindow);
-    XMapWindow(dpy, win);
-    XFlush(dpy);
+    XSelectInput(dpy, win, ExposureMask);
     return win;
 }
 
@@ -53,27 +48,28 @@ 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_x);
+    printf("    event: %.2f/%.2f\n", event->event_x, event->event_y);
 
     printf("    buttons:");
-    for (i = 0; i < event->buttons->mask_len * 8; i++)
-        if (BitIsOn(event->buttons->mask, i))
+    for (i = 0; i < event->buttons.mask_len * 8; i++)
+        if (XIMaskIsSet(event->buttons.mask, i))
             printf(" %d", i);
     printf("\n");
 
-    printf("    modifiers: locked 0x%x latched 0x%x base 0x%x\n",
-            event->mods->locked, event->mods->latched,
-            event->mods->base);
-    printf("    group: locked 0x%x latched 0x%x base 0x%x\n",
-            event->group->locked, event->group->latched,
-            event->group->base);
+    printf("    modifiers: locked %#x latched %#x base %#x effective: %#x\n",
+            event->mods.locked, event->mods.latched,
+            event->mods.base, event->mods.effective);
+    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:");
 
-    val = event->valuators->values;
-    for (i = 0; i < event->valuators->mask_len * 8; i++)
-        if (BitIsOn(event->valuators->mask, i))
+    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");
 
@@ -144,10 +140,10 @@ static void print_rawevent(XIRawEvent *event)
     printf("    detail: %d\n", event->detail);
     printf("    valuators:\n");
 
-    val = event->valuators->values;
+    val = event->valuators.values;
     raw_val = event->raw_values;
-    for (i = 0; i < event->valuators->mask_len * 8; i++)
-        if (BitIsOn(event->valuators->mask, i))
+    for (i = 0; i < event->valuators.mask_len * 8; i++)
+        if (XIMaskIsSet(event->valuators.mask, i))
             printf("         %2d: %.2f (%.2f)\n", i, *val++, *raw_val++);
     printf("\n");
 }
@@ -157,41 +153,44 @@ static void print_enterleave(XILeaveEvent* event)
     char *mode, *detail;
     int i;
 
+    printf("    device: %d\n", event->deviceid);
     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]" : "",
                                  event->same_screen ? "[same screen]" : "");
     printf("    buttons:");
-    for (i = 0; i < event->buttons->mask_len * 8; i++)
-        if (BitIsOn(event->buttons->mask, i))
+    for (i = 0; i < event->buttons.mask_len * 8; i++)
+        if (XIMaskIsSet(event->buttons.mask, i))
             printf(" %d", i);
     printf("\n");
 
-    printf("    modifiers: locked 0x%x latched 0x%x base 0x%x\n",
-            event->mods->locked, event->mods->latched,
-            event->mods->base);
-    printf("    group: locked 0x%x latched 0x%x base 0x%x\n",
-            event->group->locked, event->group->latched,
-            event->group->base);
+    printf("    modifiers: locked %#x latched %#x base %#x effective: %#x\n",
+            event->mods.locked, event->mods.latched,
+            event->mods.base, event->mods.effective);
+    printf("    group: locked %#x latched %#x base %#x effective: %#x\n",
+            event->group.locked, event->group.latched,
+            event->group.base, event->group.effective);
 
     printf("    root x/y:  %.2f / %.2f\n", event->root_x, event->root_y);
     printf("    event x/y: %.2f / %.2f\n", event->event_x, event->event_y);
@@ -201,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";
@@ -208,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)
@@ -224,7 +225,7 @@ test_sync_grab(Display *display, Window win)
     mask.deviceid = XIAllDevices;
     mask.mask_len = 2;
     mask.mask = calloc(2, sizeof(char));
-    SetBit(mask.mask, XI_ButtonPress);
+    XISetMask(mask.mask, XI_ButtonPress);
 
     if ((rc = XIGrabDevice(display, 2,  win, CurrentTime, None, GrabModeSync,
                            GrabModeAsync, False, &mask)) != GrabSuccess)
@@ -245,12 +246,11 @@ test_sync_grab(Display *display, Window win)
         XIEvent ev;
 
         XNextEvent(display, (XEvent*)&ev);
-        if (ev.type == GenericEvent)
+        if (ev.type == GenericEvent && ev.extension == xi_opcode )
         {
             XIDeviceEvent *event = (XIDeviceEvent*)&ev;
             print_deviceevent(event);
             XIAllowEvents(display, 2, SyncPointer, CurrentTime);
-            XIFreeEventData(&ev);
         }
     }
 
@@ -271,25 +271,24 @@ test_xi2(Display  *display,
     list(display, argc, argv, name, desc);
     win = create_win(display);
 
-    XSync(display, False);
-
     /* 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));
-    SetBit(mask.mask, XI_ButtonPress);
-    SetBit(mask.mask, XI_ButtonRelease);
-    SetBit(mask.mask, XI_KeyPress);
-    SetBit(mask.mask, XI_KeyRelease);
-    SetBit(mask.mask, XI_Motion);
-    SetBit(mask.mask, XI_DeviceChanged);
-    SetBit(mask.mask, XI_Enter);
-    SetBit(mask.mask, XI_Leave);
-    SetBit(mask.mask, XI_FocusIn);
-    SetBit(mask.mask, XI_FocusOut);
-    SetBit(mask.mask, XI_HierarchyChanged);
-    SetBit(mask.mask, XI_PropertyEvent);
+    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);
 
     {
@@ -298,21 +297,26 @@ test_xi2(Display  *display,
 
         mask.deviceid = 2;
         memset(mask.mask, 0, 2);
-        SetBit(mask.mask, XI_KeyPress);
-        SetBit(mask.mask, XI_KeyRelease);
-        SetBit(mask.mask, XI_ButtonPress);
-        SetBit(mask.mask, XI_Motion);
+        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);
-    SetBit(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);
@@ -329,41 +333,46 @@ test_xi2(Display  *display,
 
     while(1)
     {
-        XIEvent ev;
+        XEvent ev;
+        XGenericEventCookie *cookie = (XGenericEventCookie*)&ev.xcookie;
         XNextEvent(display, (XEvent*)&ev);
-        if (ev.type == GenericEvent)
-        {
-            XIDeviceEvent *event = (XIDeviceEvent*)&ev;
 
-            printf("EVENT type %d\n", event->evtype);
-            switch (event->evtype)
+        if (XGetEventData(display, cookie) &&
+            cookie->type == GenericEvent &&
+            cookie->extension == xi_opcode)
+        {
+            printf("EVENT type %d\n", cookie->evtype);
+            switch (cookie->evtype)
             {
                 case XI_DeviceChanged:
-                    print_devicechangedevent(display,
-                                             (XIDeviceChangedEvent*)event);
+                    print_devicechangedevent(display, cookie->data);
                     break;
                 case XI_HierarchyChanged:
-                    print_hierarchychangedevent((XIHierarchyEvent*)event);
+                    print_hierarchychangedevent(cookie->data);
                     break;
-                case XI_RawEvent:
-                    print_rawevent((XIRawEvent*)event);
+                case XI_RawKeyPress:
+                case XI_RawKeyRelease:
+                case XI_RawButtonPress:
+                case XI_RawButtonRelease:
+                case XI_RawMotion:
+                    print_rawevent(cookie->data);
                     break;
                 case XI_Enter:
                 case XI_Leave:
                 case XI_FocusIn:
                 case XI_FocusOut:
-                    print_enterleave((XILeaveEvent*)event);
+                    print_enterleave(cookie->data);
                     break;
                 case XI_PropertyEvent:
-                    print_propertyevent(display, (XIPropertyEvent*)event);
+                    print_propertyevent(display, cookie->data);
                     break;
                 default:
-                    print_deviceevent(event);
+                    print_deviceevent(cookie->data);
                     break;
             }
         }
 
-        XIFreeEventData(&ev);
+        XFreeEventData(display, cookie);
     }
 
     XDestroyWindow(display, win);