setcp.c revision 5b944e2a
1/* 2 * Copyright 2007 Peter Hutterer <peter@cs.unisa.edu.au> 3 * 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 8 * documentation. 9 * 10 * The above copyright notice and this permission notice shall be included 11 * in all copies or substantial portions of the Software. 12 * 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. 20 * 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 24 * from the author. 25 * 26 */ 27 28 29#include "xinput.h" 30#include <string.h> 31 32int 33set_clientpointer(Display* dpy, int argc, char** argv, char* name, char *desc) 34{ 35 XDeviceInfo* info; 36 XID window; 37 XDevice* dev = NULL; 38 char* id; 39 char* dummy; 40 41 if (argc <= 1) 42 { 43 fprintf(stderr, "Usage: xinput %s %s\n", name, desc); 44 return EXIT_FAILURE; 45 } 46 47 id = argv[0]; 48 49 while(*id == '0') id++; 50 51 window = strtol(argv[0], &dummy, (*id == 'x') ? 16 : 10); 52 53 info = find_device_info(dpy, argv[1], False); 54 55 if (!info) { 56 fprintf(stderr, "unable to find device %s\n", argv[1]); 57 return EXIT_FAILURE; 58 } 59 60 dev = XOpenDevice(dpy, info->id); 61 62 if (!dev) 63 { 64 fprintf(stderr, "Cannot open device %s.\n", argv[1]); 65 } else 66 XSetClientPointer(dpy, window, dev); 67 return 0; 68} 69