]> diplodocus.org Git - xorg-xinput/blobdiff - src/feedback.c
Add Peter and Red Hat's copyright notices and licenses to COPYING
[xorg-xinput] / src / feedback.c
index e16b74ebf44ace699da87b9448f52914595ce4ba..3fad9a94bf444cf3e088a4463a79c51754827b4b 100644 (file)
@@ -1,19 +1,19 @@
 /*
  * Copyright 1996 by Frederic Lepied, France. <Frederic.Lepied@sugix.frmug.org>
- *                                                                            
+ *
  * 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
  * copyright  notice   and   this  permission   notice  appear  in  supporting
- * documentation, and that   the  name of  Frederic   Lepied not  be  used  in
+ * documentation, and that   the  name of  the authors  not  be  used  in
  * advertising or publicity pertaining to distribution of the software without
- * specific,  written      prior  permission.     Frederic  Lepied   makes  no
+ * specific,  written      prior  permission.     The authors  make  no
  * representations about the suitability of this software for any purpose.  It
- * is provided "as is" without express or implied warranty.                   
- *                                                                            
- * FREDERIC  LEPIED DISCLAIMS ALL   WARRANTIES WITH REGARD  TO  THIS SOFTWARE,
+ * is provided "as is" without express or implied warranty.
+ *
+ * THE AUTHORS DISCLAIM 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
+ * EVENT  SHALL THE AUTHORS  BE   LIABLE   FOR ANY  SPECIAL, INDIRECT   OR
  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  * DATA  OR PROFITS, WHETHER  IN  AN ACTION OF  CONTRACT,  NEGLIGENCE OR OTHER
  * TORTIOUS  ACTION, ARISING    OUT OF OR   IN  CONNECTION  WITH THE USE    OR
@@ -33,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; loop<num_feedbacks; loop++) {
+       if (state->class == 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,
@@ -84,31 +103,31 @@ 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; loop<num_feedbacks; loop++) {
        switch (state->class) {
        case KbdFeedbackClass:
@@ -121,13 +140,13 @@ 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=%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:
@@ -156,7 +175,7 @@ get_feedbacks(Display       *display,
            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);