setcp.c revision 53719b08
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 XIDeviceInfo *info; 36 XID window; 37 char* id; 38 char* dummy; 39 40 if (argc <= 1) 41 { 42 fprintf(stderr, "Usage: xinput %s %s\n", name, desc); 43 return EXIT_FAILURE; 44 } 45 46 id = argv[0]; 47 48 while(*id == '0') id++; 49 50 window = strtol(argv[0], &dummy, (*id == 'x') ? 16 : 10); 51 52 info = xi2_find_device_info(dpy, argv[1]); 53 54 if (!info) { 55 fprintf(stderr, "unable to find device %s\n", argv[1]); 56 return EXIT_FAILURE; 57 } 58 59 XISetClientPointer(dpy, window, info->deviceid); 60 return 0; 61} 62