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
)
43 unsigned long nitems
, bytes_after
;
44 unsigned char *data
, *ptr
;
47 name
= XGetAtomName(dpy
, property
);
48 printf("\t%s (%d):\t", name
, property
);
50 if (XGetDeviceProperty(dpy
, dev
, property
, 0, 1000, False
,
51 AnyPropertyType
, &act_type
, &act_format
,
52 &nitems
, &bytes_after
, &data
) == Success
)
57 for (j
= 0; j
< nitems
; j
++)
65 printf("%d", *((int8_t*)ptr
));
68 printf("%d", *((int16_t*)ptr
));
71 printf("%d", *((int32_t*)ptr
));
76 printf("\t%s\n", ptr
);
79 printf("\t%s\n", XGetAtomName(dpy
, (Atom
)(*ptr
)));
82 printf("\t\t... of unknown type %s\n",
83 XGetAtomName(dpy
, act_type
));
91 if (act_type
== XA_STRING
)
97 printf("\tFetch failure\n");
101 int list_props(Display
*dpy
, int argc
, char** argv
, char* name
, char *desc
)
111 fprintf(stderr
, "Usage: xinput %s %s\n", name
, desc
);
115 for (i
= 0; i
< argc
; i
++)
117 info
= find_device_info(dpy
, argv
[i
], False
);
120 fprintf(stderr
, "unable to find device %s\n", argv
[i
]);
124 dev
= XOpenDevice(dpy
, info
->id
);
127 fprintf(stderr
, "unable to open device '%s'\n", info
->name
);
131 props
= XListDeviceProperties(dpy
, dev
, &nprops
);
134 printf("Device '%s' does not report any properties.\n", info
->name
);
138 printf("Device '%s':\n", info
->name
);
141 print_property(dpy
, dev
, props
[nprops
]);
145 XCloseDevice(dpy
, dev
);
151 set_int_prop(Display
*dpy
, int argc
, char** argv
, char* n
, char *desc
)
160 int format
, nelements
= 0;
164 fprintf(stderr
, "Usage: xinput %s %s\n", n
, desc
);
168 info
= find_device_info(dpy
, argv
[0], False
);
171 fprintf(stderr
, "unable to find device %s\n", argv
[0]);
175 dev
= XOpenDevice(dpy
, info
->id
);
178 fprintf(stderr
, "unable to open device %s\n", argv
[0]);
184 for(i
= 0; i
< strlen(name
); i
++) {
185 if (!isdigit(name
[i
])) {
192 prop
= XInternAtom(dpy
, name
, False
);
196 nelements
= argc
- 3;
197 format
= atoi(argv
[2]);
198 if (format
!= 8 && format
!= 16 && format
!= 32)
200 fprintf(stderr
, "Invalid format %d\n", format
);
204 data
= calloc(nelements
, format
/8);
205 for (i
= 0; i
< nelements
; i
++)
210 *(((int8_t*)data
) + i
) = atoi(argv
[3 + i
]);
213 *(((int16_t*)data
) + i
) = atoi(argv
[3 + i
]);
216 *(((int32_t*)data
) + i
) = atoi(argv
[3 + i
]);
221 XChangeDeviceProperty(dpy
, dev
, prop
, XA_INTEGER
, format
, PropModeReplace
,
222 (unsigned char*)data
, nelements
);
225 XCloseDevice(dpy
, dev
);
230 int watch_props(Display
*dpy
, int argc
, char** argv
, char* n
, char *desc
)
235 XDevicePropertyNotifyEvent
*dpev
;
238 XEventClass cls_prop
;
240 if (list_props(dpy
, argc
, argv
, n
, desc
) != EXIT_SUCCESS
)
243 info
= find_device_info(dpy
, argv
[0], False
);
246 fprintf(stderr
, "unable to find device %s\n", argv
[0]);
250 dev
= XOpenDevice(dpy
, info
->id
);
253 fprintf(stderr
, "unable to open device '%s'\n", info
->name
);
257 DevicePropertyNotify(dev
, type_prop
, cls_prop
);
258 XSelectExtensionEvent(dpy
, DefaultRootWindow(dpy
), &cls_prop
, 1);
262 XNextEvent(dpy
, &ev
);
264 dpev
= (XDevicePropertyNotifyEvent
*)&ev
;
265 if (dpev
->type
!= type_prop
)
268 name
= XGetAtomName(dpy
, dpev
->atom
);
269 printf("Property '%s' changed.\n", name
);
270 print_property(dpy
, dev
, dpev
->atom
);
273 XCloseDevice(dpy
, dev
);
276 int delete_prop(Display
*dpy
, int argc
, char** argv
, char* n
, char *desc
)
285 info
= find_device_info(dpy
, argv
[0], False
);
288 fprintf(stderr
, "unable to find device %s\n", argv
[0]);
292 dev
= XOpenDevice(dpy
, info
->id
);
295 fprintf(stderr
, "unable to open device '%s'\n", info
->name
);
301 for(i
= 0; i
< strlen(name
); i
++) {
302 if (!isdigit(name
[i
])) {
309 prop
= XInternAtom(dpy
, name
, False
);
313 XDeleteDeviceProperty(dpy
, dev
, prop
);
315 XCloseDevice(dpy
, dev
);