X-Git-Url: https://diplodocus.org/git/xorg-xinput/blobdiff_plain/8806f3db5417f1c5946b6589cf2f043e9e7c68d3..115cbd4025a9eb9531633c3e8481cb1923789f57:/src/feedback.c diff --git a/src/feedback.c b/src/feedback.c index 554642e..7f4da57 100644 --- a/src/feedback.c +++ b/src/feedback.c @@ -1,6 +1,6 @@ /* * Copyright 1996 by Frederic Lepied, France. - * + * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that * the above copyright notice appear in all copies and that both that @@ -9,8 +9,8 @@ * advertising or publicity pertaining to distribution of the software without * specific, written prior permission. Frederic Lepied makes no * representations about the suitability of this software for any purpose. It - * is provided "as is" without express or implied warranty. - * + * is provided "as is" without express or implied warranty. + * * FREDERIC LEPIED DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO * EVENT SHALL FREDERIC LEPIED BE LIABLE FOR ANY SPECIAL, INDIRECT OR @@ -23,8 +23,6 @@ #include "xinput.h" -static const char rcs_id[] = "$Id: feedback.c,v 1.2 1996/12/19 19:40:41 fred Exp $"; - int set_ptr_feedback(Display *display, int argc, @@ -35,31 +33,50 @@ set_ptr_feedback(Display *display, XDeviceInfo *info; XDevice *device; XPtrFeedbackControl feedback; - + XFeedbackState *state; + int num_feedbacks; + int loop; + int id; + if (argc != 4) { fprintf(stderr, "usage: xinput %s %s\n", name, desc); return 1; } - + info = find_device_info(display, argv[0], True); - + if (!info) { fprintf(stderr, "unable to find device %s\n", argv[0]); return 1; } - + device = XOpenDevice(display, info->id); - + if (!device) { fprintf(stderr, "unable to open device %s\n", argv[0]); return 1; } - - feedback.class = PtrFeedbackClass; - feedback.length = sizeof(XPtrFeedbackControl); - feedback.id = 0; + + /* We will match the first Ptr Feedback class. Can there be more? */ + id = -1; + state = XGetFeedbackControl(display, device, &num_feedbacks); + for(loop=0; loopclass == PtrFeedbackClass) { + id = state->id; + } + state = (XFeedbackState*) ((char*) state + state->length); + } + + if (id == -1) { + fprintf(stderr, "unable to find PtrFeedbackClass for %s\n", argv[0]); + return 1; + } + + feedback.class = PtrFeedbackClass; + feedback.length = sizeof(XPtrFeedbackControl); + feedback.id = id; feedback.threshold = atoi(argv[1]); - feedback.accelNum = atoi(argv[2]); + feedback.accelNum = atoi(argv[2]); feedback.accelDenom = atoi(argv[3]); XChangeFeedbackControl(display, device, DvAccelNum|DvAccelDenom|DvThreshold, @@ -86,36 +103,36 @@ get_feedbacks(Display *display, XLedFeedbackState *l; XIntegerFeedbackState *i; XStringFeedbackState *s; - + if (argc != 1) { fprintf(stderr, "usage: xinput %s %s\n", name, desc); return 1; } - + info = find_device_info(display, argv[0], True); - + if (!info) { fprintf(stderr, "unable to find device %s\n", argv[0]); return 1; } - + device = XOpenDevice(display, info->id); - + if (!device) { fprintf(stderr, "unable to open device %s\n", argv[0]); return 1; } - + state = XGetFeedbackControl(display, device, &num_feedbacks); printf("%d feedback class%s\n", num_feedbacks, (num_feedbacks > 1) ? "es" : ""); - + for(loop=0; loopclass) { case KbdFeedbackClass: k = (XKbdFeedbackState*) state; - printf("KbdFeedbackClass id=%d\n", state->id); + printf("KbdFeedbackClass id=%ld\n", state->id); printf("\tclick is %d\n", k->click); printf("\tpercent is %d\n", k->percent); printf("\tpitch is %d\n", k->pitch); @@ -123,25 +140,25 @@ get_feedbacks(Display *display, printf("\tled_mask is %d\n", k->led_mask); printf("\tglobal_auto_repeat is %d\n", k->global_auto_repeat); break; - + case PtrFeedbackClass: p = (XPtrFeedbackState*) state; - printf("PtrFeedbackClass id=%d\n", state->id); + printf("PtrFeedbackClass id=%ld\n", state->id); printf("\taccelNum is %d\n", p->accelNum); printf("\taccelDenom is %d\n", p->accelDenom); - printf("\tthreshold is %d\n", p->threshold); + printf("\tthreshold is %d\n", p->threshold); break; case StringFeedbackClass: s = (XStringFeedbackState*) state; - printf("XStringFeedbackControl id=%d\n", state->id); + printf("XStringFeedbackControl id=%ld\n", state->id); printf("\tmax_symbols is %d\n", s->max_symbols); printf("\tnum_syms_supported is %d\n", s->num_syms_supported); break; case IntegerFeedbackClass: i = (XIntegerFeedbackState*) state; - printf("XIntegerFeedbackControl id=%d\n", state->id); + printf("XIntegerFeedbackControl id=%ld\n", state->id); printf("\tresolution is %d\n", i->resolution); printf("\tminVal is %d\n", i->minVal); printf("\tmaxVal is %d\n", i->maxVal); @@ -149,16 +166,16 @@ get_feedbacks(Display *display, case LedFeedbackClass: l = (XLedFeedbackState*) state; - printf("XLedFeedbackState id=%d\n", state->id); + printf("XLedFeedbackState id=%ld\n", state->id); printf("\tled_values is %d\n", l->led_values); break; case BellFeedbackClass: b = (XBellFeedbackState*) state; - printf("XBellFeedbackControl id=%d\n", state->id); + printf("XBellFeedbackControl id=%ld\n", state->id); printf("\tpercent is %d\n", b->percent); printf("\tpitch is %d\n", b->pitch); - printf("\tduration is %d\n", b->duration); + printf("\tduration is %d\n", b->duration); break; } state = (XFeedbackState*) ((char*) state + state->length); @@ -166,5 +183,4 @@ get_feedbacks(Display *display, return EXIT_SUCCESS; } -/* end of ptrfdbk.c -*/ +/* end of ptrfdbk.c */