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  the authors  not  be  used  in
9  * advertising or publicity pertaining to distribution of the software without
10  * specific,  written      prior  permission.     The authors  make  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  * THE AUTHORS DISCLAIM ALL   WARRANTIES WITH REGARD  TO  THIS SOFTWARE,
15  * INCLUDING ALL IMPLIED   WARRANTIES OF MERCHANTABILITY  AND   FITNESS, IN NO
16  * EVENT  SHALL THE AUTHORS  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
set_ptr_feedback(Display * display,int argc,char * argv[],char * name,char * desc)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     XFeedbackState	*state;
37     int			num_feedbacks;
38     int			loop;
39     int			id;
40 
41     if (argc != 4) {
42 	fprintf(stderr, "usage: xinput %s %s\n", name, desc);
43 	return 1;
44     }
45 
46     info = find_device_info(display, argv[0], True);
47 
48     if (!info) {
49 	fprintf(stderr, "unable to find device '%s'\n", argv[0]);
50 	return 1;
51     }
52 
53     device = XOpenDevice(display, info->id);
54 
55     if (!device) {
56 	fprintf(stderr, "unable to open device '%s'\n", argv[0]);
57 	return 1;
58     }
59 
60     /* We will match the first Ptr Feedback class. Can there be more? */
61     id = -1;
62     state = XGetFeedbackControl(display, device, &num_feedbacks);
63     for(loop=0; loop<num_feedbacks; loop++) {
64 	if (state->class == PtrFeedbackClass) {
65 	   id = state->id;
66 	}
67 	state = (XFeedbackState*) ((char*) state + state->length);
68     }
69 
70     if (id == -1) {
71        fprintf(stderr, "unable to find PtrFeedbackClass for '%s'\n", argv[0]);
72        return 1;
73     }
74 
75     feedback.class       = PtrFeedbackClass;
76     feedback.length      = sizeof(XPtrFeedbackControl);
77     feedback.id	         = id;
78     feedback.threshold	 = atoi(argv[1]);
79     feedback.accelNum	 = atoi(argv[2]);
80     feedback.accelDenom  = atoi(argv[3]);
81 
82     XChangeFeedbackControl(display, device, DvAccelNum|DvAccelDenom|DvThreshold,
83 			   (XFeedbackControl*) &feedback);
84     return EXIT_SUCCESS;
85 }
86 
87 
88 int
get_feedbacks(Display * display,int argc,char * argv[],char * name,char * desc)89 get_feedbacks(Display	*display,
90 	      int	argc,
91 	      char	*argv[],
92 	      char	*name,
93 	      char	*desc)
94 {
95     XDeviceInfo		*info;
96     XDevice		*device;
97     XFeedbackState	*state;
98     int			num_feedbacks;
99     int			loop;
100     XPtrFeedbackState	*p;
101     XKbdFeedbackState	*k;
102     XBellFeedbackState	*b;
103     XLedFeedbackState	*l;
104     XIntegerFeedbackState *i;
105     XStringFeedbackState *s;
106 
107     if (argc != 1) {
108 	fprintf(stderr, "usage: xinput %s %s\n", name, desc);
109 	return 1;
110     }
111 
112     info = find_device_info(display, argv[0], True);
113 
114     if (!info) {
115 	fprintf(stderr, "unable to find device '%s'\n", argv[0]);
116 	return 1;
117     }
118 
119     device = XOpenDevice(display, info->id);
120 
121     if (!device) {
122 	fprintf(stderr, "unable to open device '%s'\n", argv[0]);
123 	return 1;
124     }
125 
126     state = XGetFeedbackControl(display, device, &num_feedbacks);
127 
128     printf("%d feedback class%s\n", num_feedbacks,
129 	   (num_feedbacks > 1) ? "es" : "");
130 
131     for(loop=0; loop<num_feedbacks; loop++) {
132 	switch (state->class) {
133 	case KbdFeedbackClass:
134 	    k = (XKbdFeedbackState*) state;
135 	    printf("KbdFeedbackClass id=%ld\n", state->id);
136 	    printf("\tclick is %d\n", k->click);
137 	    printf("\tpercent is %d\n", k->percent);
138 	    printf("\tpitch is %d\n", k->pitch);
139 	    printf("\tduration is %d\n", k->duration);
140 	    printf("\tled_mask is %d\n", k->led_mask);
141 	    printf("\tglobal_auto_repeat is %d\n", k->global_auto_repeat);
142 	    break;
143 
144 	case PtrFeedbackClass:
145 	    p = (XPtrFeedbackState*) state;
146 	    printf("PtrFeedbackClass id=%ld\n", state->id);
147 	    printf("\taccelNum is %d\n", p->accelNum);
148 	    printf("\taccelDenom is %d\n", p->accelDenom);
149 	    printf("\tthreshold is %d\n", p->threshold);
150 	    break;
151 
152 	case StringFeedbackClass:
153 	    s = (XStringFeedbackState*) state;
154 	    printf("XStringFeedbackControl id=%ld\n", state->id);
155 	    printf("\tmax_symbols is %d\n", s->max_symbols);
156 	    printf("\tnum_syms_supported is %d\n", s->num_syms_supported);
157 	    break;
158 
159 	case IntegerFeedbackClass:
160 	    i = (XIntegerFeedbackState*) state;
161 	    printf("XIntegerFeedbackControl id=%ld\n", state->id);
162 	    printf("\tresolution is %d\n", i->resolution);
163 	    printf("\tminVal is %d\n", i->minVal);
164 	    printf("\tmaxVal is %d\n", i->maxVal);
165 	    break;
166 
167 	case LedFeedbackClass:
168 	    l = (XLedFeedbackState*) state;
169 	    printf("XLedFeedbackState id=%ld\n", state->id);
170 	    printf("\tled_values is %d\n", l->led_values);
171 	    break;
172 
173 	case BellFeedbackClass:
174 	    b = (XBellFeedbackState*) state;
175 	    printf("XBellFeedbackControl id=%ld\n", state->id);
176 	    printf("\tpercent is %d\n", b->percent);
177 	    printf("\tpitch is %d\n", b->pitch);
178 	    printf("\tduration is %d\n", b->duration);
179 	    break;
180 	}
181 	state = (XFeedbackState*) ((char*) state + state->length);
182     }
183     return EXIT_SUCCESS;
184 }
185 
186 /* end of ptrfdbk.c */
187