2 * Copyright 2007 Peter Hutterer
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
10 * The above copyright notice and this permission notice shall be included
11 * in all copies or substantial portions of the Software.
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
14 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
15 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
16 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR
17 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
18 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
19 * OTHER DEALINGS IN THE SOFTWARE.
21 * Except as contained in this notice, the name of the author shall
22 * not be used in advertising or otherwise to promote the sale, use or
23 * other dealings in this Software without prior written authorization
32 #include <X11/Xatom.h>
33 #include <X11/extensions/XIproto.h>
38 print_property(Display
*dpy
, XDevice
* dev
, Atom property
)
40 XIPropertyInfo
*propinfo
;
44 unsigned long nitems
, bytes_after
;
45 unsigned char *data
, *ptr
;
48 propinfo
= XQueryDeviceProperty(dpy
, dev
, property
);
52 name
= XGetAtomName(dpy
, property
);
53 printf("\t%s (%d):\t", name
, property
);
55 if (XGetDeviceProperty(dpy
, dev
, property
, 0, 1000, False
, False
,
56 AnyPropertyType
, &act_type
, &act_format
,
57 &nitems
, &bytes_after
, &data
) == Success
)
62 for (j
= 0; j
< nitems
; j
++)
70 printf("%d", *((int8_t*)ptr
));
73 printf("%d", *((int16_t*)ptr
));
76 printf("%d", *((int32_t*)ptr
));
81 printf("\t%s\n", ptr
);
84 printf("\t%s\n", XGetAtomName(dpy
, (Atom
)(*ptr
)));
87 printf("\t\t... of unknown type %s\n",
88 XGetAtomName(dpy
, act_type
));
96 if (act_type
== XA_STRING
)
102 printf("\tFetch failure\n");
104 if (propinfo
->pending
|| propinfo
->range
|| propinfo
->immutable
|| propinfo
->fromClient
)
106 printf("\t\t%s%s%s%s", ((propinfo
->pending
) ? "[pending]" : ""),
107 ((propinfo
->range
) ? "[range]" : ""),
108 ((propinfo
->immutable
) ? "[immutable]" : ""),
109 ((propinfo
->fromClient
) ? "[client]" : ""));
113 if (propinfo
->num_values
)
115 long *values
= propinfo
->values
;
116 printf("\t\tvalid values: ");
117 while(values
&& propinfo
->num_values
--)
118 printf("%ld ", *values
++);
126 int list_props(Display
*dpy
, int argc
, char** argv
, char* name
, char *desc
)
136 fprintf(stderr
, "Usage: xinput %s %s\n", name
, desc
);
140 for (i
= 0; i
< argc
; i
++)
142 info
= find_device_info(dpy
, argv
[i
], False
);
145 fprintf(stderr
, "unable to find device %s\n", argv
[i
]);
149 dev
= XOpenDevice(dpy
, info
->id
);
152 fprintf(stderr
, "unable to open device '%s'\n", info
->name
);
156 props
= XListDeviceProperties(dpy
, dev
, &nprops
);
159 printf("Device '%s' does not report any properties.\n", info
->name
);
163 printf("Device '%s':\n", info
->name
);
166 print_property(dpy
, dev
, props
[nprops
]);
170 XCloseDevice(dpy
, dev
);
176 set_int_prop(Display
*dpy
, int argc
, char** argv
, char* n
, char *desc
)
185 int format
, nelements
= 0;
189 fprintf(stderr
, "Usage: xinput %s %s\n", n
, desc
);
193 info
= find_device_info(dpy
, argv
[0], False
);
196 fprintf(stderr
, "unable to find device %s\n", argv
[0]);
200 dev
= XOpenDevice(dpy
, info
->id
);
203 fprintf(stderr
, "unable to open device %s\n", argv
[0]);
209 for(i
= 0; i
< strlen(name
); i
++) {
210 if (!isdigit(name
[i
])) {
217 prop
= XInternAtom(dpy
, name
, False
);
221 nelements
= argc
- 3;
222 format
= atoi(argv
[2]);
223 if (format
!= 8 && format
!= 16 && format
!= 32)
225 fprintf(stderr
, "Invalid format %d\n", format
);
229 data
= calloc(nelements
, format
/8);
230 for (i
= 0; i
< nelements
; i
++)
235 *(((int8_t*)data
) + i
) = atoi(argv
[3 + i
]);
238 *(((int16_t*)data
) + i
) = atoi(argv
[3 + i
]);
241 *(((int32_t*)data
) + i
) = atoi(argv
[3 + i
]);
246 XChangeDeviceProperty(dpy
, dev
, prop
, XA_INTEGER
, format
, PropModeReplace
,
247 (unsigned char*)data
, nelements
);
250 XCloseDevice(dpy
, dev
);
255 int watch_props(Display
*dpy
, int argc
, char** argv
, char* n
, char *desc
)
260 XDevicePropertyNotifyEvent
*dpev
;
263 XEventClass cls_prop
;
265 if (list_props(dpy
, argc
, argv
, n
, desc
) != EXIT_SUCCESS
)
268 info
= find_device_info(dpy
, argv
[0], False
);
271 fprintf(stderr
, "unable to find device %s\n", argv
[0]);
275 dev
= XOpenDevice(dpy
, info
->id
);
278 fprintf(stderr
, "unable to open device '%s'\n", info
->name
);
282 DevicePropertyNotify(dev
, type_prop
, cls_prop
);
283 XSelectExtensionEvent(dpy
, DefaultRootWindow(dpy
), &cls_prop
, 1);
287 XNextEvent(dpy
, &ev
);
289 dpev
= (XDevicePropertyNotifyEvent
*)&ev
;
290 if (dpev
->type
!= type_prop
)
293 name
= XGetAtomName(dpy
, dpev
->atom
);
294 printf("Property '%s' changed.\n", name
);
295 print_property(dpy
, dev
, dpev
->atom
);
298 XCloseDevice(dpy
, dev
);