6eddc6a677dca6a0d205aee1db4ffab31c7158a3
2 * Copyright 2001,2002 Red Hat Inc., Durham, North Carolina.
6 * Permission is hereby granted, free of charge, to any person obtaining
7 * a copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation on the rights to use, copy, modify, merge,
10 * publish, distribute, sublicense, and/or sell copies of the Software,
11 * and to permit persons to whom the Software is furnished to do so,
12 * subject to the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial
16 * portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 * NON-INFRINGEMENT. IN NO EVENT SHALL RED HAT AND/OR THEIR SUPPLIERS
22 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
23 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * Rickard E. (Rik) Faith <faith@redhat.com>
38 #include <X11/XKBlib.h>
39 #include <X11/extensions/XInput.h>
40 #include <X11/extensions/XKB.h>
41 #include <X11/extensions/XKBstr.h>
42 #include <X11/extensions/dmxext.h>
46 core(DMXInputAttributes
* iinf
)
50 else if (iinf
->sendsCore
)
51 return "extension (sends core events)";
57 printdmxinfo(Display
* display
, int id
)
61 int major_version
, minor_version
, patch_version
;
62 DMXInputAttributes iinf
;
64 char *backendname
= NULL
;
66 if (!DMXQueryExtension(display
, &event_base
, &error_base
))
68 if (!DMXQueryVersion(display
, &major_version
, &minor_version
,
71 if (major_version
== 1 && minor_version
== 0)
73 if (!DMXGetInputAttributes(display
, id
, &iinf
))
76 printf(" DMX Information: ");
81 switch (iinf
.inputType
) {
82 case DMXLocalInputType
:
83 printf("local, %s", core(&iinf
));
85 case DMXConsoleInputType
:
86 printf("console %s, %s", iinf
.name
, core(&iinf
));
88 case DMXBackendInputType
:
89 if (iinf
.physicalId
>= 0) {
90 if ((backend
= XOpenDisplay(iinf
.name
))) {
91 XExtensionVersion
*ext
= XGetExtensionVersion(backend
, INAME
);
93 if (ext
&& ext
!= (XExtensionVersion
*) NoSuchExtension
) {
95 XDeviceInfo
*devInfo
= XListInputDevices(backend
, &count
);
98 for (i
= 0; i
< count
; i
++) {
99 if ((unsigned) iinf
.physicalId
== devInfo
[i
].id
100 && devInfo
[i
].name
) {
101 backendname
= strdup(devInfo
[i
].name
);
105 XFreeDeviceList(devInfo
);
108 XCloseDisplay(backend
);
111 printf("backend o%d/%s", iinf
.physicalScreen
, iinf
.name
);
112 if (iinf
.physicalId
>= 0)
113 printf("/id%d", iinf
.physicalId
);
115 printf("=%s", backendname
);
118 printf(" %s", core(&iinf
));
125 main(int argc
, char **argv
)
127 Display
*display
= NULL
;
133 XDeviceInfo
*devInfo
;
134 XExtensionVersion
*ext
;
136 if (argc
== 2 || argc
== 3 || argc
== 4 || argc
== 5) {
137 if (!(display
= XOpenDisplay(argv
[1]))) {
138 printf("Cannot open display %s\n", argv
[1]);
142 device
= strtol(argv
[2], NULL
, 0);
144 newmouse
= strtol(argv
[3], NULL
, 0);
146 newkbd
= strtol(argv
[4], NULL
, 0);
149 printf("Usage: %s display [device] [newmouse] [newkbd]\n", argv
[0]);
153 if (!display
&& !(display
= XOpenDisplay(NULL
))) {
154 printf("Cannot open default display\n");
158 ext
= XGetExtensionVersion(display
, INAME
);
159 if (!ext
|| ext
== (XExtensionVersion
*) NoSuchExtension
) {
160 printf("No XInputExtension\n");
163 printf("%s version %d.%d\n", INAME
, ext
->major_version
, ext
->minor_version
);
165 if (!(devInfo
= XListInputDevices(display
, &count
)) || !count
) {
166 printf("Cannot list devices\n");
170 for (i
= 0; i
< count
; i
++) {
172 const char *kind
= "Unknown";
175 switch (devInfo
[i
].use
) {
182 case IsXExtensionDevice
:
183 kind
= "XExtensionDevice";
186 printf("%2lu %-20.20s %-16.16s",
187 (long unsigned) devInfo
[i
].id
,
188 devInfo
[i
].name
? devInfo
[i
].name
: "", kind
);
190 for (j
= 0, any
= devInfo
[i
].inputclassinfo
;
191 j
< devInfo
[i
].num_classes
;
192 any
= (XAnyClassPtr
) ((char *) any
+ any
->length
), j
++) {
193 const char *class = "unk";
195 switch (any
->class) {
219 printf(" %s", class);
222 printdmxinfo(display
, i
);
227 if ((xkb
= XkbGetKeyboard(display
,
228 XkbAllComponentsMask
, devInfo
[i
].id
))) {
229 printf(" Xkb Information:\n");
230 printf(" Device id = %d\n", xkb
->device_spec
);
231 printf(" Min keycode = 0x%02x\n", xkb
->min_key_code
);
232 printf(" Max keycode = 0x%02x\n", xkb
->max_key_code
);
233 #define PRINTNAME(x) \
234 printf(" %s = %s\n", \
235 #x, xkb->names->x ? XGetAtomName(display, xkb->names->x) : "")
248 printf("Trying to make device %d core mouse\n", newmouse
);
249 dev
= XOpenDevice(display
, devInfo
[newmouse
].id
);
250 printf("Status = %d\n", XChangePointerDevice(display
, dev
, 0, 1));
257 printf("Trying to make device %d core keyboard\n", newkbd
);
258 dev
= XOpenDevice(display
, devInfo
[newkbd
].id
);
259 printf("Status = %d\n", XChangeKeyboardDevice(display
, dev
));
264 #define MAX_EVENTS 100
267 XEventClass event_list
[MAX_EVENTS
];
268 int event_type
[MAX_EVENTS
];
269 const char *names
[MAX_EVENTS
];
273 if (cnt >= MAX_EVENTS) abort(); \
274 names[cnt] = #type; \
275 type(dev, event_type[cnt], event_list[cnt]); \
276 if (event_type[cnt]) ++cnt
278 dev
= XOpenDevice(display
, devInfo
[device
].id
);
280 ADD(DeviceKeyRelease
);
281 ADD(DeviceButtonPress
);
282 ADD(DeviceButtonRelease
);
283 ADD(DeviceMotionNotify
);
288 ADD(DeviceStateNotify
);
289 ADD(DeviceMappingNotify
);
290 ADD(ChangeDeviceNotify
);
292 for (i
= 0; i
< cnt
; i
++) {
293 printf("Waiting for %s events of type %d (%lu) on 0x%08lx\n",
295 event_type
[i
], (unsigned long) event_list
[i
],
296 (long unsigned) DefaultRootWindow(display
));
298 XSelectExtensionEvent(display
, DefaultRootWindow(display
),
304 XNextEvent(display
, &event
);
305 for (i
= 0; i
< cnt
; i
++) {
306 XDeviceMotionEvent
*e
= (XDeviceMotionEvent
*) &event
;
307 XDeviceButtonEvent
*b
= (XDeviceButtonEvent
*) &event
;
309 if (event
.type
== event_type
[i
]) {
310 printf("%s id=%lu (%d @ %d,%d; s=0x%04x, d=%d, t=%lu)"
311 " axes_count=%d first=%d %d %d %d %d %d %d\n",
313 (long unsigned) e
->deviceid
,
318 (long unsigned) b
->time
,
324 e
->axis_data
[3], e
->axis_data
[4], e
->axis_data
[5]);
329 /* Used to check motion history for
330 * extension devices. */
332 XDeviceTimeCoord
*tc
;
337 gettimeofday(&tv
, NULL
);
338 ms
= tv
.tv_sec
* 1000 + tv
.tv_usec
/ 1000;
339 tc
= XGetDeviceMotionEvents(display
, dev
, ms
- 1000, ms
,
341 printf("Got %d events of mode %s with %d axes\n",
342 n
, m
== Absolute
? "Absolute" : "Relative", a
);
343 for (i
= 0; i
< n
&& i
< 10; i
++) {
344 printf(" %d: %lu %d %d\n",
345 i
, tc
[i
].time
, tc
[i
].data
[0], tc
[i
].data
[1]);
347 XFreeDeviceMotionEvents(tc
);
353 XCloseDisplay(display
);