setcp.c revision 53719b08
15b944e2aSmrg/*
25b944e2aSmrg * Copyright 2007 Peter Hutterer <peter@cs.unisa.edu.au>
35b944e2aSmrg *
45b944e2aSmrg * Permission to use, copy, modify, distribute, and sell this software and its
55b944e2aSmrg * documentation for any purpose is hereby granted without fee, provided that
65b944e2aSmrg * the above copyright notice appear in all copies and that both that
75b944e2aSmrg * copyright notice and this permission notice appear in supporting
85b944e2aSmrg * documentation.
95b944e2aSmrg *
105b944e2aSmrg * The above copyright notice and this permission notice shall be included
115b944e2aSmrg * in all copies or substantial portions of the Software.
125b944e2aSmrg *
135b944e2aSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
145b944e2aSmrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
155b944e2aSmrg * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
165b944e2aSmrg * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR
175b944e2aSmrg * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
185b944e2aSmrg * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
195b944e2aSmrg * OTHER DEALINGS IN THE SOFTWARE.
205b944e2aSmrg *
215b944e2aSmrg * Except as contained in this notice, the name of the author shall
225b944e2aSmrg * not be used in advertising or otherwise to promote the sale, use or
235b944e2aSmrg * other dealings in this Software without prior written authorization
245b944e2aSmrg * from the author.
255b944e2aSmrg *
265b944e2aSmrg */
275b944e2aSmrg
285b944e2aSmrg
295b944e2aSmrg#include "xinput.h"
305b944e2aSmrg#include <string.h>
315b944e2aSmrg
325b944e2aSmrgint
335b944e2aSmrgset_clientpointer(Display* dpy, int argc, char** argv, char* name, char *desc)
345b944e2aSmrg{
3553719b08Smrg    XIDeviceInfo *info;
365b944e2aSmrg    XID window;
375b944e2aSmrg    char* id;
385b944e2aSmrg    char* dummy;
395b944e2aSmrg
405b944e2aSmrg    if (argc <= 1)
415b944e2aSmrg    {
425b944e2aSmrg        fprintf(stderr, "Usage: xinput %s %s\n", name, desc);
435b944e2aSmrg        return EXIT_FAILURE;
445b944e2aSmrg    }
455b944e2aSmrg
465b944e2aSmrg    id = argv[0];
475b944e2aSmrg
485b944e2aSmrg    while(*id == '0') id++;
495b944e2aSmrg
505b944e2aSmrg    window = strtol(argv[0], &dummy, (*id == 'x') ? 16 : 10);
515b944e2aSmrg
5253719b08Smrg    info = xi2_find_device_info(dpy, argv[1]);
535b944e2aSmrg
545b944e2aSmrg    if (!info) {
555b944e2aSmrg	fprintf(stderr, "unable to find device %s\n", argv[1]);
565b944e2aSmrg	return EXIT_FAILURE;
575b944e2aSmrg    }
585b944e2aSmrg
5953719b08Smrg    XISetClientPointer(dpy, window, info->deviceid);
605b944e2aSmrg    return 0;
615b944e2aSmrg}
62