]> diplodocus.org Git - xorg-xinput/blob - src/feedback.c
554642eef52ac26e687834fec47bb40caaa6562e
[xorg-xinput] / src / feedback.c
1 /*
2 * Copyright 1996 by Frederic Lepied, France. <Frederic.Lepied@sugix.frmug.org>
3 *
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name of Frederic Lepied not be used in
9 * advertising or publicity pertaining to distribution of the software without
10 * specific, written prior permission. Frederic Lepied makes no
11 * representations about the suitability of this software for any purpose. It
12 * is provided "as is" without express or implied warranty.
13 *
14 * FREDERIC LEPIED DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL FREDERIC LEPIED BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20 * PERFORMANCE OF THIS SOFTWARE.
21 *
22 */
23
24 #include "xinput.h"
25
26 static const char rcs_id[] = "$Id: feedback.c,v 1.2 1996/12/19 19:40:41 fred Exp $";
27
28 int
29 set_ptr_feedback(Display *display,
30 int argc,
31 char *argv[],
32 char *name,
33 char *desc)
34 {
35 XDeviceInfo *info;
36 XDevice *device;
37 XPtrFeedbackControl feedback;
38
39 if (argc != 4) {
40 fprintf(stderr, "usage: xinput %s %s\n", name, desc);
41 return 1;
42 }
43
44 info = find_device_info(display, argv[0], True);
45
46 if (!info) {
47 fprintf(stderr, "unable to find device %s\n", argv[0]);
48 return 1;
49 }
50
51 device = XOpenDevice(display, info->id);
52
53 if (!device) {
54 fprintf(stderr, "unable to open device %s\n", argv[0]);
55 return 1;
56 }
57
58 feedback.class = PtrFeedbackClass;
59 feedback.length = sizeof(XPtrFeedbackControl);
60 feedback.id = 0;
61 feedback.threshold = atoi(argv[1]);
62 feedback.accelNum = atoi(argv[2]);
63 feedback.accelDenom = atoi(argv[3]);
64
65 XChangeFeedbackControl(display, device, DvAccelNum|DvAccelDenom|DvThreshold,
66 (XFeedbackControl*) &feedback);
67 return EXIT_SUCCESS;
68 }
69
70
71 int
72 get_feedbacks(Display *display,
73 int argc,
74 char *argv[],
75 char *name,
76 char *desc)
77 {
78 XDeviceInfo *info;
79 XDevice *device;
80 XFeedbackState *state;
81 int num_feedbacks;
82 int loop;
83 XPtrFeedbackState *p;
84 XKbdFeedbackState *k;
85 XBellFeedbackState *b;
86 XLedFeedbackState *l;
87 XIntegerFeedbackState *i;
88 XStringFeedbackState *s;
89
90 if (argc != 1) {
91 fprintf(stderr, "usage: xinput %s %s\n", name, desc);
92 return 1;
93 }
94
95 info = find_device_info(display, argv[0], True);
96
97 if (!info) {
98 fprintf(stderr, "unable to find device %s\n", argv[0]);
99 return 1;
100 }
101
102 device = XOpenDevice(display, info->id);
103
104 if (!device) {
105 fprintf(stderr, "unable to open device %s\n", argv[0]);
106 return 1;
107 }
108
109 state = XGetFeedbackControl(display, device, &num_feedbacks);
110
111 printf("%d feedback class%s\n", num_feedbacks,
112 (num_feedbacks > 1) ? "es" : "");
113
114 for(loop=0; loop<num_feedbacks; loop++) {
115 switch (state->class) {
116 case KbdFeedbackClass:
117 k = (XKbdFeedbackState*) state;
118 printf("KbdFeedbackClass id=%d\n", state->id);
119 printf("\tclick is %d\n", k->click);
120 printf("\tpercent is %d\n", k->percent);
121 printf("\tpitch is %d\n", k->pitch);
122 printf("\tduration is %d\n", k->duration);
123 printf("\tled_mask is %d\n", k->led_mask);
124 printf("\tglobal_auto_repeat is %d\n", k->global_auto_repeat);
125 break;
126
127 case PtrFeedbackClass:
128 p = (XPtrFeedbackState*) state;
129 printf("PtrFeedbackClass id=%d\n", state->id);
130 printf("\taccelNum is %d\n", p->accelNum);
131 printf("\taccelDenom is %d\n", p->accelDenom);
132 printf("\tthreshold is %d\n", p->threshold);
133 break;
134
135 case StringFeedbackClass:
136 s = (XStringFeedbackState*) state;
137 printf("XStringFeedbackControl id=%d\n", state->id);
138 printf("\tmax_symbols is %d\n", s->max_symbols);
139 printf("\tnum_syms_supported is %d\n", s->num_syms_supported);
140 break;
141
142 case IntegerFeedbackClass:
143 i = (XIntegerFeedbackState*) state;
144 printf("XIntegerFeedbackControl id=%d\n", state->id);
145 printf("\tresolution is %d\n", i->resolution);
146 printf("\tminVal is %d\n", i->minVal);
147 printf("\tmaxVal is %d\n", i->maxVal);
148 break;
149
150 case LedFeedbackClass:
151 l = (XLedFeedbackState*) state;
152 printf("XLedFeedbackState id=%d\n", state->id);
153 printf("\tled_values is %d\n", l->led_values);
154 break;
155
156 case BellFeedbackClass:
157 b = (XBellFeedbackState*) state;
158 printf("XBellFeedbackControl id=%d\n", state->id);
159 printf("\tpercent is %d\n", b->percent);
160 printf("\tpitch is %d\n", b->pitch);
161 printf("\tduration is %d\n", b->duration);
162 break;
163 }
164 state = (XFeedbackState*) ((char*) state + state->length);
165 }
166 return EXIT_SUCCESS;
167 }
168
169 /* end of ptrfdbk.c
170 */