1b1297603Smrg/* 2b1297603Smrg * Copyright 1996-1997 by Frederic Lepied, France. <Frederic.Lepied@sugix.frmug.org> 3b1297603Smrg * 4b1297603Smrg * Permission to use, copy, modify, distribute, and sell this software and its 5b1297603Smrg * documentation for any purpose is hereby granted without fee, provided that 6b1297603Smrg * the above copyright notice appear in all copies and that both that 7b1297603Smrg * copyright notice and this permission notice appear in supporting 85b944e2aSmrg * documentation, and that the name of the authors not be used in 9b1297603Smrg * advertising or publicity pertaining to distribution of the software without 105b944e2aSmrg * specific, written prior permission. The authors make no 11b1297603Smrg * representations about the suitability of this software for any purpose. It 12b1297603Smrg * is provided "as is" without express or implied warranty. 13b1297603Smrg * 145b944e2aSmrg * THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 15b1297603Smrg * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO 165b944e2aSmrg * EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR 17b1297603Smrg * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 18b1297603Smrg * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 19b1297603Smrg * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 20b1297603Smrg * PERFORMANCE OF THIS SOFTWARE. 21b1297603Smrg * 22b1297603Smrg */ 23b1297603Smrg 24b1297603Smrg#include "xinput.h" 25b1297603Smrg 26b1297603Smrgint 27b1297603Smrgquery_state(Display *display, 28b1297603Smrg int argc, 29b1297603Smrg char *argv[], 30b1297603Smrg char *name, 31b1297603Smrg char *desc) 32b1297603Smrg{ 33b1297603Smrg XDeviceInfo *info; 34b1297603Smrg XDevice *device; 35b1297603Smrg XDeviceState *state; 36b1297603Smrg int loop; 37b1297603Smrg int loop2; 38b1297603Smrg XInputClass *cls; 39b1297603Smrg XValuatorState *val_state; 40b1297603Smrg XKeyState *key_state; 41b1297603Smrg XButtonState *but_state; 42b1297603Smrg 43b1297603Smrg if (argc != 1) { 44b1297603Smrg fprintf(stderr, "usage: xinput %s %s\n", name, desc); 45b1297603Smrg return 1; 46b1297603Smrg } 47b1297603Smrg 48b1297603Smrg info = find_device_info(display, argv[0], True); 49b1297603Smrg 50b1297603Smrg if (!info) { 510309d3b3Smrg fprintf(stderr, "unable to find device '%s'\n", argv[0]); 52b1297603Smrg return 1; 53b1297603Smrg } 54b1297603Smrg 55b1297603Smrg device = XOpenDevice(display, info->id); 56b1297603Smrg 57b1297603Smrg if (!device) { 580309d3b3Smrg fprintf(stderr, "unable to open device '%s'\n", argv[0]); 59b1297603Smrg return 1; 60b1297603Smrg } 61b1297603Smrg 62b1297603Smrg state = XQueryDeviceState(display, device); 63b1297603Smrg 64b1297603Smrg if (state) { 65b1297603Smrg cls = state->data; 66b1297603Smrg printf("%d class%s :\n", state->num_classes, 67b1297603Smrg (state->num_classes > 1) ? "es" : ""); 68b1297603Smrg for(loop=0; loop<state->num_classes; loop++) { 69b1297603Smrg switch(cls->class) { 70b1297603Smrg case ValuatorClass: 71b1297603Smrg val_state = (XValuatorState *) cls; 72b1297603Smrg printf("ValuatorClass Mode=%s Proximity=%s\n", 73b1297603Smrg val_state->mode & 1 ? "Absolute" : "Relative", 74b1297603Smrg val_state->mode & 2 ? "Out" : "In"); 75b1297603Smrg for(loop2=0; loop2<val_state->num_valuators; loop2++) { 76b1297603Smrg printf("\tvaluator[%d]=%d\n", loop2, val_state->valuators[loop2]); 77b1297603Smrg } 78b1297603Smrg break; 79b1297603Smrg 80b1297603Smrg case ButtonClass: 81b1297603Smrg but_state = (XButtonState *) cls; 82b1297603Smrg printf("ButtonClass\n"); 83b1297603Smrg for(loop2=1; loop2<=but_state->num_buttons; loop2++) { 84b1297603Smrg printf("\tbutton[%d]=%s\n", loop2, 85b1297603Smrg (but_state->buttons[loop2 / 8] & (1 << (loop2 % 8))) ? "down" : "up" ); 86b1297603Smrg } 87b1297603Smrg break; 88b1297603Smrg 89b1297603Smrg case KeyClass: 90b1297603Smrg key_state = (XKeyState *) cls; 91b1297603Smrg printf("KeyClass\n"); 92b1297603Smrg for(loop2=0; loop2<key_state->num_keys; loop2++) { 93b1297603Smrg printf("\tkey[%d]=%s\n", loop2, 94b1297603Smrg (key_state->keys[loop2 / 8] & (1 << (loop2 % 8))) ? "down" : "up" ); 95b1297603Smrg } 96b1297603Smrg 97b1297603Smrg break; 98b1297603Smrg 99b1297603Smrg } 100b1297603Smrg cls = (XInputClass *) ((char *) cls + cls->length); 101b1297603Smrg } 102b1297603Smrg XFreeDeviceState(state); 103b1297603Smrg } 104b1297603Smrg return EXIT_SUCCESS; 105b1297603Smrg} 106b1297603Smrg 107b1297603Smrg/* end of state.c */ 108