]> diplodocus.org Git - xorg-xinput/blob - src/feedback.c
e16b74ebf44ace699da87b9448f52914595ce4ba
[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 int
27 set_ptr_feedback(Display *display,
28 int argc,
29 char *argv[],
30 char *name,
31 char *desc)
32 {
33 XDeviceInfo *info;
34 XDevice *device;
35 XPtrFeedbackControl feedback;
36
37 if (argc != 4) {
38 fprintf(stderr, "usage: xinput %s %s\n", name, desc);
39 return 1;
40 }
41
42 info = find_device_info(display, argv[0], True);
43
44 if (!info) {
45 fprintf(stderr, "unable to find device %s\n", argv[0]);
46 return 1;
47 }
48
49 device = XOpenDevice(display, info->id);
50
51 if (!device) {
52 fprintf(stderr, "unable to open device %s\n", argv[0]);
53 return 1;
54 }
55
56 feedback.class = PtrFeedbackClass;
57 feedback.length = sizeof(XPtrFeedbackControl);
58 feedback.id = 0;
59 feedback.threshold = atoi(argv[1]);
60 feedback.accelNum = atoi(argv[2]);
61 feedback.accelDenom = atoi(argv[3]);
62
63 XChangeFeedbackControl(display, device, DvAccelNum|DvAccelDenom|DvThreshold,
64 (XFeedbackControl*) &feedback);
65 return EXIT_SUCCESS;
66 }
67
68
69 int
70 get_feedbacks(Display *display,
71 int argc,
72 char *argv[],
73 char *name,
74 char *desc)
75 {
76 XDeviceInfo *info;
77 XDevice *device;
78 XFeedbackState *state;
79 int num_feedbacks;
80 int loop;
81 XPtrFeedbackState *p;
82 XKbdFeedbackState *k;
83 XBellFeedbackState *b;
84 XLedFeedbackState *l;
85 XIntegerFeedbackState *i;
86 XStringFeedbackState *s;
87
88 if (argc != 1) {
89 fprintf(stderr, "usage: xinput %s %s\n", name, desc);
90 return 1;
91 }
92
93 info = find_device_info(display, argv[0], True);
94
95 if (!info) {
96 fprintf(stderr, "unable to find device %s\n", argv[0]);
97 return 1;
98 }
99
100 device = XOpenDevice(display, info->id);
101
102 if (!device) {
103 fprintf(stderr, "unable to open device %s\n", argv[0]);
104 return 1;
105 }
106
107 state = XGetFeedbackControl(display, device, &num_feedbacks);
108
109 printf("%d feedback class%s\n", num_feedbacks,
110 (num_feedbacks > 1) ? "es" : "");
111
112 for(loop=0; loop<num_feedbacks; loop++) {
113 switch (state->class) {
114 case KbdFeedbackClass:
115 k = (XKbdFeedbackState*) state;
116 printf("KbdFeedbackClass id=%ld\n", state->id);
117 printf("\tclick is %d\n", k->click);
118 printf("\tpercent is %d\n", k->percent);
119 printf("\tpitch is %d\n", k->pitch);
120 printf("\tduration is %d\n", k->duration);
121 printf("\tled_mask is %d\n", k->led_mask);
122 printf("\tglobal_auto_repeat is %d\n", k->global_auto_repeat);
123 break;
124
125 case PtrFeedbackClass:
126 p = (XPtrFeedbackState*) state;
127 printf("PtrFeedbackClass id=%ld\n", state->id);
128 printf("\taccelNum is %d\n", p->accelNum);
129 printf("\taccelDenom is %d\n", p->accelDenom);
130 printf("\tthreshold is %d\n", p->threshold);
131 break;
132
133 case StringFeedbackClass:
134 s = (XStringFeedbackState*) state;
135 printf("XStringFeedbackControl id=%ld\n", state->id);
136 printf("\tmax_symbols is %d\n", s->max_symbols);
137 printf("\tnum_syms_supported is %d\n", s->num_syms_supported);
138 break;
139
140 case IntegerFeedbackClass:
141 i = (XIntegerFeedbackState*) state;
142 printf("XIntegerFeedbackControl id=%ld\n", state->id);
143 printf("\tresolution is %d\n", i->resolution);
144 printf("\tminVal is %d\n", i->minVal);
145 printf("\tmaxVal is %d\n", i->maxVal);
146 break;
147
148 case LedFeedbackClass:
149 l = (XLedFeedbackState*) state;
150 printf("XLedFeedbackState id=%ld\n", state->id);
151 printf("\tled_values is %d\n", l->led_values);
152 break;
153
154 case BellFeedbackClass:
155 b = (XBellFeedbackState*) state;
156 printf("XBellFeedbackControl id=%ld\n", state->id);
157 printf("\tpercent is %d\n", b->percent);
158 printf("\tpitch is %d\n", b->pitch);
159 printf("\tduration is %d\n", b->duration);
160 break;
161 }
162 state = (XFeedbackState*) ((char*) state + state->length);
163 }
164 return EXIT_SUCCESS;
165 }
166
167 /* end of ptrfdbk.c */