~ubuntu-branches/ubuntu/trusty/xinput/trusty

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/*
 * 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  the authors  not  be  used  in
 * advertising or publicity pertaining to distribution of the software without
 * 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.
 *
 * THE AUTHORS DISCLAIM ALL   WARRANTIES WITH REGARD  TO  THIS SOFTWARE,
 * INCLUDING ALL IMPLIED   WARRANTIES OF MERCHANTABILITY  AND   FITNESS, IN NO
 * 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
 * PERFORMANCE OF THIS SOFTWARE.
 *
 */

#include "xinput.h"

int
set_ptr_feedback(Display	*display,
		 int		argc,
		 char		*argv[],
		 char		*name,
		 char		*desc)
{
    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;
    }

    /* 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.accelDenom  = atoi(argv[3]);

    XChangeFeedbackControl(display, device, DvAccelNum|DvAccelDenom|DvThreshold,
			   (XFeedbackControl*) &feedback);
    return EXIT_SUCCESS;
}


int
get_feedbacks(Display	*display,
	      int	argc,
	      char	*argv[],
	      char	*name,
	      char	*desc)
{
    XDeviceInfo		*info;
    XDevice		*device;
    XFeedbackState	*state;
    int			num_feedbacks;
    int			loop;
    XPtrFeedbackState	*p;
    XKbdFeedbackState	*k;
    XBellFeedbackState	*b;
    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:
	    k = (XKbdFeedbackState*) state;
	    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);
	    printf("\tduration is %d\n", k->duration);
	    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);
	    break;

	case StringFeedbackClass:
	    s = (XStringFeedbackState*) state;
	    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=%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);
	    break;

	case LedFeedbackClass:
	    l = (XLedFeedbackState*) state;
	    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=%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);
	    break;
	}
	state = (XFeedbackState*) ((char*) state + state->length);
    }
    return EXIT_SUCCESS;
}

/* end of ptrfdbk.c */