aboutsummaryrefslogtreecommitdiff
path: root/xorg-server/hw/dmx/examples/xinput.c
diff options
context:
space:
mode:
Diffstat (limited to 'xorg-server/hw/dmx/examples/xinput.c')
-rw-r--r--xorg-server/hw/dmx/examples/xinput.c215
1 files changed, 126 insertions, 89 deletions
diff --git a/xorg-server/hw/dmx/examples/xinput.c b/xorg-server/hw/dmx/examples/xinput.c
index b12daf201..db6601030 100644
--- a/xorg-server/hw/dmx/examples/xinput.c
+++ b/xorg-server/hw/dmx/examples/xinput.c
@@ -42,31 +42,42 @@
#include <X11/extensions/dmxext.h>
#include <sys/time.h>
-static const char *core(DMXInputAttributes *iinf)
+static const char *
+core(DMXInputAttributes * iinf)
{
- if (iinf->isCore) return "core";
- else if (iinf->sendsCore) return "extension (sends core events)";
- else return "extension";
+ if (iinf->isCore)
+ return "core";
+ else if (iinf->sendsCore)
+ return "extension (sends core events)";
+ else
+ return "extension";
}
-static void printdmxinfo(Display *display, int id)
+static void
+printdmxinfo(Display * display, int id)
{
- int event_base;
- int error_base;
- int major_version, minor_version, patch_version;
- DMXInputAttributes iinf;
- Display *backend;
- char *backendname = NULL;
-
- if (!DMXQueryExtension(display, &event_base, &error_base)) return;
+ int event_base;
+ int error_base;
+ int major_version, minor_version, patch_version;
+ DMXInputAttributes iinf;
+ Display *backend;
+ char *backendname = NULL;
+
+ if (!DMXQueryExtension(display, &event_base, &error_base))
+ return;
if (!DMXQueryVersion(display, &major_version, &minor_version,
- &patch_version)) return;
- if (major_version == 1 && minor_version == 0) return; /* too old */
- if (!DMXGetInputAttributes(display, id, &iinf)) return;
+ &patch_version))
+ return;
+ if (major_version == 1 && minor_version == 0)
+ return; /* too old */
+ if (!DMXGetInputAttributes(display, id, &iinf))
+ return;
printf(" DMX Information: ");
- if (iinf.detached) printf("detached ");
- else printf("active ");
+ if (iinf.detached)
+ printf("detached ");
+ else
+ printf("active ");
switch (iinf.inputType) {
case DMXLocalInputType:
printf("local, %s", core(&iinf));
@@ -78,12 +89,14 @@ static void printdmxinfo(Display *display, int id)
if (iinf.physicalId >= 0) {
if ((backend = XOpenDisplay(iinf.name))) {
XExtensionVersion *ext = XGetExtensionVersion(backend, INAME);
- if (ext && ext != (XExtensionVersion *)NoSuchExtension) {
+
+ if (ext && ext != (XExtensionVersion *) NoSuchExtension) {
int count, i;
XDeviceInfo *devInfo = XListInputDevices(backend, &count);
+
if (devInfo) {
for (i = 0; i < count; i++) {
- if ((unsigned)iinf.physicalId == devInfo[i].id
+ if ((unsigned) iinf.physicalId == devInfo[i].id
&& devInfo[i].name) {
backendname = strdup(devInfo[i].name);
break;
@@ -95,8 +108,9 @@ static void printdmxinfo(Display *display, int id)
XCloseDisplay(backend);
}
}
- printf("backend o%d/%s",iinf.physicalScreen, iinf.name);
- if (iinf.physicalId >= 0) printf("/id%d", iinf.physicalId);
+ printf("backend o%d/%s", iinf.physicalScreen, iinf.name);
+ if (iinf.physicalId >= 0)
+ printf("/id%d", iinf.physicalId);
if (backendname) {
printf("=%s", backendname);
free(backendname);
@@ -107,26 +121,31 @@ static void printdmxinfo(Display *display, int id)
printf("\n");
}
-int main(int argc, char **argv)
+int
+main(int argc, char **argv)
{
- Display *display = NULL;
- int device = -1;
- int newmouse = -1;
- int newkbd = -1;
- int count;
- int i, j;
- XDeviceInfo *devInfo;
- XExtensionVersion *ext;
+ Display *display = NULL;
+ int device = -1;
+ int newmouse = -1;
+ int newkbd = -1;
+ int count;
+ int i, j;
+ XDeviceInfo *devInfo;
+ XExtensionVersion *ext;
if (argc == 2 || argc == 3 || argc == 4 || argc == 5) {
if (!(display = XOpenDisplay(argv[1]))) {
printf("Cannot open display %s\n", argv[1]);
return -1;
}
- if (argc >= 3) device = strtol(argv[2], NULL, 0);
- if (argc >= 4) newmouse = strtol(argv[3], NULL, 0);
- if (argc >= 5) newkbd = strtol(argv[4], NULL, 0);
- } else {
+ if (argc >= 3)
+ device = strtol(argv[2], NULL, 0);
+ if (argc >= 4)
+ newmouse = strtol(argv[3], NULL, 0);
+ if (argc >= 5)
+ newkbd = strtol(argv[4], NULL, 0);
+ }
+ else {
printf("Usage: %s display [device] [newmouse] [newkbd]\n", argv[0]);
return -1;
}
@@ -137,12 +156,11 @@ int main(int argc, char **argv)
}
ext = XGetExtensionVersion(display, INAME);
- if (!ext || ext == (XExtensionVersion *)NoSuchExtension) {
+ if (!ext || ext == (XExtensionVersion *) NoSuchExtension) {
printf("No XInputExtension\n");
return -1;
}
- printf("%s version %d.%d\n",
- INAME, ext->major_version, ext->minor_version);
+ printf("%s version %d.%d\n", INAME, ext->major_version, ext->minor_version);
if (!(devInfo = XListInputDevices(display, &count)) || !count) {
printf("Cannot list devices\n");
@@ -151,30 +169,52 @@ int main(int argc, char **argv)
for (i = 0; i < count; i++) {
XAnyClassPtr any;
- const char *kind = "Unknown";
- int has_key = 0;
-
+ const char *kind = "Unknown";
+ int has_key = 0;
+
switch (devInfo[i].use) {
- case IsXPointer: kind = "XPointer"; break;
- case IsXKeyboard: kind = "XKeyboard"; break;
- case IsXExtensionDevice: kind = "XExtensionDevice"; break;
+ case IsXPointer:
+ kind = "XPointer";
+ break;
+ case IsXKeyboard:
+ kind = "XKeyboard";
+ break;
+ case IsXExtensionDevice:
+ kind = "XExtensionDevice";
+ break;
}
printf("%2lu %-20.20s %-16.16s",
- (long unsigned)devInfo[i].id,
+ (long unsigned) devInfo[i].id,
devInfo[i].name ? devInfo[i].name : "", kind);
for (j = 0, any = devInfo[i].inputclassinfo;
j < devInfo[i].num_classes;
- any = (XAnyClassPtr)((char *)any + any->length), j++) {
- const char *class = "unk";
+ any = (XAnyClassPtr) ((char *) any + any->length), j++) {
+ const char *class = "unk";
+
switch (any->class) {
- case KeyClass: class = "key"; ++has_key; break;
- case ButtonClass: class = "btn"; break;
- case ValuatorClass: class = "val"; break;
- case FeedbackClass: class = "fdb"; break;
- case ProximityClass: class = "prx"; break;
- case FocusClass: class = "foc"; break;
- case OtherClass: class = "oth"; break;
+ case KeyClass:
+ class = "key";
+ ++has_key;
+ break;
+ case ButtonClass:
+ class = "btn";
+ break;
+ case ValuatorClass:
+ class = "val";
+ break;
+ case FeedbackClass:
+ class = "fdb";
+ break;
+ case ProximityClass:
+ class = "prx";
+ break;
+ case FocusClass:
+ class = "foc";
+ break;
+ case OtherClass:
+ class = "oth";
+ break;
}
printf(" %s", class);
}
@@ -182,10 +222,10 @@ int main(int argc, char **argv)
printdmxinfo(display, i);
if (has_key) {
- XkbDescPtr xkb;
+ XkbDescPtr xkb;
+
if ((xkb = XkbGetKeyboard(display,
- XkbAllComponentsMask,
- devInfo[i].id))) {
+ XkbAllComponentsMask, devInfo[i].id))) {
printf(" Xkb Information:\n");
printf(" Device id = %d\n", xkb->device_spec);
printf(" Min keycode = 0x%02x\n", xkb->min_key_code);
@@ -203,41 +243,37 @@ int main(int argc, char **argv)
}
if (newmouse >= 0) {
- XDevice *dev;
+ XDevice *dev;
printf("Trying to make device %d core mouse\n", newmouse);
dev = XOpenDevice(display, devInfo[newmouse].id);
- printf("Status = %d\n",
- XChangePointerDevice(display, dev, 0, 1));
+ printf("Status = %d\n", XChangePointerDevice(display, dev, 0, 1));
return 0;
}
if (newkbd >= 0) {
- XDevice *dev;
+ XDevice *dev;
printf("Trying to make device %d core keyboard\n", newkbd);
dev = XOpenDevice(display, devInfo[newkbd].id);
- printf("Status = %d\n",
- XChangeKeyboardDevice(display, dev));
+ printf("Status = %d\n", XChangeKeyboardDevice(display, dev));
return 0;
}
-
- if (device >=0){
+ if (device >= 0) {
#define MAX_EVENTS 100
- int cnt = 0;
- XDevice *dev;
+ int cnt = 0;
+ XDevice *dev;
XEventClass event_list[MAX_EVENTS];
- int event_type[MAX_EVENTS];
- const char *names[MAX_EVENTS];
- int total = 0;
+ int event_type[MAX_EVENTS];
+ const char *names[MAX_EVENTS];
+ int total = 0;
#define ADD(type) \
if (cnt >= MAX_EVENTS) abort(); \
names[cnt] = #type; \
type(dev, event_type[cnt], event_list[cnt]); \
if (event_type[cnt]) ++cnt
-
dev = XOpenDevice(display, devInfo[device].id);
ADD(DeviceKeyPress);
@@ -252,54 +288,55 @@ int main(int argc, char **argv)
ADD(DeviceStateNotify);
ADD(DeviceMappingNotify);
ADD(ChangeDeviceNotify);
-
+
for (i = 0; i < cnt; i++) {
printf("Waiting for %s events of type %d (%lu) on 0x%08lx\n",
names[i],
- event_type[i], (unsigned long)event_list[i],
- (long unsigned)DefaultRootWindow(display));
+ event_type[i], (unsigned long) event_list[i],
+ (long unsigned) DefaultRootWindow(display));
}
XSelectExtensionEvent(display, DefaultRootWindow(display),
event_list, cnt);
-
+
for (;;) {
XEvent event;
+
XNextEvent(display, &event);
for (i = 0; i < cnt; i++) {
- XDeviceMotionEvent *e = (XDeviceMotionEvent *)&event;
- XDeviceButtonEvent *b = (XDeviceButtonEvent *)&event;
+ XDeviceMotionEvent *e = (XDeviceMotionEvent *) & event;
+ XDeviceButtonEvent *b = (XDeviceButtonEvent *) & event;
+
if (event.type == event_type[i]) {
printf("%s id=%lu (%d @ %d,%d; s=0x%04x, d=%d, t=%lu)"
" axes_count=%d first=%d %d %d %d %d %d %d\n",
names[i],
- (long unsigned)e->deviceid,
+ (long unsigned) e->deviceid,
e->type,
e->x, e->y,
e->device_state,
b->button,
- (long unsigned)b->time,
+ (long unsigned) b->time,
e->axes_count,
e->first_axis,
e->axis_data[0],
e->axis_data[1],
e->axis_data[2],
- e->axis_data[3],
- e->axis_data[4],
- e->axis_data[5]);
+ e->axis_data[3], e->axis_data[4], e->axis_data[5]);
}
}
++total;
#if 0
- /* Used to check motion history for
- * extension devices. */
+ /* Used to check motion history for
+ * extension devices. */
if (!(total % 10)) {
XDeviceTimeCoord *tc;
- int n, m, a;
- struct timeval tv;
- unsigned long ms;
+ int n, m, a;
+ struct timeval tv;
+ unsigned long ms;
+
gettimeofday(&tv, NULL);
ms = tv.tv_sec * 1000 + tv.tv_usec / 1000;
- tc = XGetDeviceMotionEvents(display, dev, ms-1000, ms,
+ tc = XGetDeviceMotionEvents(display, dev, ms - 1000, ms,
&n, &m, &a);
printf("Got %d events of mode %s with %d axes\n",
n, m == Absolute ? "Absolute" : "Relative", a);
@@ -309,7 +346,7 @@ int main(int argc, char **argv)
}
XFreeDeviceMotionEvents(tc);
}
-#endif
+#endif
}
}