diff options
author | Keith Packard <keithp@keithp.com> | 2012-03-21 12:55:09 -0700 |
---|---|---|
committer | Keith Packard <keithp@keithp.com> | 2012-03-21 13:54:42 -0700 |
commit | 9838b7032ea9792bec21af424c53c07078636d21 (patch) | |
tree | b72d0827dac50f0f3b8eab29b3b7639546d735d7 /hw/dmx/examples/xinput.c | |
parent | 75199129c603fc8567185ac31866c9518193cb78 (diff) |
Introduce a consistent coding style
This is strictly the application of the script 'x-indent-all.sh'
from util/modular. Compared to the patch that Daniel posted in
January, I've added a few indent flags:
-bap
-psl
-T PrivatePtr
-T pmWait
-T _XFUNCPROTOBEGIN
-T _XFUNCPROTOEND
-T _X_EXPORT
The typedefs were needed to make the output of sdksyms.sh match the
previous output, otherwise, the code is formatted badly enough that
sdksyms.sh generates incorrect output.
The generated code was compared with the previous version and found to
be essentially identical -- "assert" line numbers and BUILD_TIME were
the only differences found.
The comparison was done with this script:
dir1=$1
dir2=$2
for dir in $dir1 $dir2; do
(cd $dir && find . -name '*.o' | while read file; do
dir=`dirname $file`
base=`basename $file .o`
dump=$dir/$base.dump
objdump -d $file > $dump
done)
done
find $dir1 -name '*.dump' | while read dump; do
otherdump=`echo $dump | sed "s;$dir1;$dir2;"`
diff -u $dump $otherdump
done
Signed-off-by: Keith Packard <keithp@keithp.com>
Acked-by: Daniel Stone <daniel@fooishbar.org>
Acked-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Diffstat (limited to 'hw/dmx/examples/xinput.c')
-rw-r--r-- | hw/dmx/examples/xinput.c | 215 |
1 files changed, 126 insertions, 89 deletions
diff --git a/hw/dmx/examples/xinput.c b/hw/dmx/examples/xinput.c index b12daf201..db6601030 100644 --- a/hw/dmx/examples/xinput.c +++ b/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 } } |