1b1297603Smrg/*
2b1297603Smrg * Copyright 1996 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#include <string.h>
26b1297603Smrg
27b1297603Smrgint
28b1297603Smrgset_mode(Display	*display,
29b1297603Smrg	 int		argc,
30b1297603Smrg	 char		*argv[],
31b1297603Smrg	 char		*name,
32b1297603Smrg	 char		*desc)
33b1297603Smrg{
34b1297603Smrg    XDeviceInfo		*info;
35b1297603Smrg    XDevice		*device;
36b1297603Smrg    int			mode;
37b1297603Smrg
38b1297603Smrg    if (argc != 2) {
39b1297603Smrg	fprintf(stderr, "usage: xinput %s %s\n", name, desc);
40b1297603Smrg	return EXIT_FAILURE;
41b1297603Smrg    }
42b1297603Smrg
43b1297603Smrg    info = find_device_info(display, argv[0], True);
44b1297603Smrg
45b1297603Smrg    if (!info) {
460309d3b3Smrg	fprintf(stderr, "unable to find device '%s'\n", argv[0]);
47b1297603Smrg	return EXIT_FAILURE;
48b1297603Smrg    }
49b1297603Smrg
50b1297603Smrg    if (strcmp(argv[1], "ABSOLUTE") == 0) {
51b1297603Smrg	mode = Absolute;
5254e0bb33Smrg    } else if (strcmp(argv[1], "RELATIVE") == 0) {
53b1297603Smrg	mode = Relative;
5454e0bb33Smrg    } else {
5554e0bb33Smrg	fprintf(stderr, "Invalid mode, use ABSOLUTE or RELATIVE.\n");
5654e0bb33Smrg	return EXIT_FAILURE;
57b1297603Smrg    }
58b1297603Smrg
59b1297603Smrg    device = XOpenDevice(display, info->id);
60b1297603Smrg
61b1297603Smrg    if (device) {
62b1297603Smrg	XSetDeviceMode(display, device, mode);
63b1297603Smrg
64b1297603Smrg	return EXIT_SUCCESS;
65b1297603Smrg    } else {
66b1297603Smrg	fprintf(stderr, "Unable to open device\n");
67b1297603Smrg	return EXIT_FAILURE;
68b1297603Smrg    }
69b1297603Smrg}
70b1297603Smrg
71b1297603Smrg/* end of setmode.c */
72