snj doesn't like my accent, so use proper English month names.
[netbsd-mini2440.git] / sbin / wsconsctl / mouse.c
blob6085a5fec2a73b386eb6ebd717a2659c3df522c7
1 /* $NetBSD: mouse.c,v 1.7 2006/02/05 18:11:46 jmmv Exp $ */
3 /*-
4 * Copyright (c) 1998, 2006 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Juergen Hannken-Illjes and Julio M. Merino Vidal.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/ioctl.h>
33 #include <sys/time.h>
34 #include <dev/wscons/wsconsio.h>
36 #include <err.h>
37 #include <errno.h>
38 #include <limits.h>
39 #include <stdio.h>
40 #include <stdlib.h>
41 #include <string.h>
43 #include "wsconsctl.h"
45 static int mstype;
46 static int resolution;
47 static int samplerate;
48 static struct wsmouse_repeat repeat;
50 static void mouse_get_repeat(int);
51 static void mouse_put_repeat(int);
53 struct field mouse_field_tab[] = {
54 { "resolution", &resolution, FMT_UINT, FLG_WRONLY },
55 { "samplerate", &samplerate, FMT_UINT, FLG_WRONLY },
56 { "type", &mstype, FMT_MSTYPE, FLG_RDONLY },
57 { "repeat.buttons", &repeat.wr_buttons,
58 FMT_BITFIELD, FLG_MODIFY },
59 { "repeat.delay.first", &repeat.wr_delay_first,
60 FMT_UINT, FLG_MODIFY },
61 { "repeat.delay.decrement", &repeat.wr_delay_decrement,
62 FMT_UINT, FLG_MODIFY },
63 { "repeat.delay.minimum", &repeat.wr_delay_minimum,
64 FMT_UINT, FLG_MODIFY },
67 int mouse_field_tab_len = sizeof(mouse_field_tab)/
68 sizeof(mouse_field_tab[0]);
70 void
71 mouse_get_values(int fd)
74 if (field_by_value(&mstype)->flags & FLG_GET)
75 if (ioctl(fd, WSMOUSEIO_GTYPE, &mstype) < 0)
76 err(EXIT_FAILURE, "WSMOUSEIO_GTYPE");
78 if (field_by_value(&repeat.wr_buttons)->flags & FLG_GET ||
79 field_by_value(&repeat.wr_delay_first)->flags & FLG_GET ||
80 field_by_value(&repeat.wr_delay_decrement)->flags & FLG_GET ||
81 field_by_value(&repeat.wr_delay_minimum)->flags & FLG_GET)
82 mouse_get_repeat(fd);
85 static void
86 mouse_get_repeat(int fd)
88 struct wsmouse_repeat tmp;
90 if (ioctl(fd, WSMOUSEIO_GETREPEAT, &tmp) == -1)
91 err(EXIT_FAILURE, "WSMOUSEIO_GETREPEAT");
93 if (field_by_value(&repeat.wr_buttons)->flags & FLG_GET)
94 repeat.wr_buttons = tmp.wr_buttons;
95 if (field_by_value(&repeat.wr_delay_first)->flags & FLG_GET)
96 repeat.wr_delay_first = tmp.wr_delay_first;
97 if (field_by_value(&repeat.wr_delay_decrement)->flags & FLG_GET)
98 repeat.wr_delay_decrement = tmp.wr_delay_decrement;
99 if (field_by_value(&repeat.wr_delay_minimum)->flags & FLG_GET)
100 repeat.wr_delay_minimum = tmp.wr_delay_minimum;
103 void
104 mouse_put_values(int fd)
106 int tmp;
108 if (field_by_value(&resolution)->flags & FLG_SET) {
109 tmp = resolution;
110 if (ioctl(fd, WSMOUSEIO_SRES, &tmp) < 0)
111 err(EXIT_FAILURE, "WSMOUSEIO_SRES");
112 pr_field(field_by_value(&resolution), " -> ");
115 if (field_by_value(&samplerate)->flags & FLG_SET) {
116 tmp = samplerate;
117 if (ioctl(fd, WSMOUSEIO_SRATE, &tmp) < 0)
118 err(EXIT_FAILURE, "WSMOUSEIO_SRATE");
119 pr_field(field_by_value(&samplerate), " -> ");
122 if (field_by_value(&repeat.wr_buttons)->flags & FLG_SET ||
123 field_by_value(&repeat.wr_delay_first)->flags & FLG_SET ||
124 field_by_value(&repeat.wr_delay_decrement)->flags & FLG_SET ||
125 field_by_value(&repeat.wr_delay_minimum)->flags & FLG_SET)
126 mouse_put_repeat(fd);
129 static void
130 mouse_put_repeat(int fd)
132 struct wsmouse_repeat tmp;
134 /* Fetch current values into the temporary structure. */
135 if (ioctl(fd, WSMOUSEIO_GETREPEAT, &tmp) == -1)
136 err(EXIT_FAILURE, "WSMOUSEIO_GETREPEAT");
138 /* Overwrite the desired values in the temporary structure. */
139 if (field_by_value(&repeat.wr_buttons)->flags & FLG_SET)
140 tmp.wr_buttons = repeat.wr_buttons;
141 if (field_by_value(&repeat.wr_delay_first)->flags & FLG_SET)
142 tmp.wr_delay_first = repeat.wr_delay_first;
143 if (field_by_value(&repeat.wr_delay_decrement)->flags & FLG_SET)
144 tmp.wr_delay_decrement = repeat.wr_delay_decrement;
145 if (field_by_value(&repeat.wr_delay_minimum)->flags & FLG_SET)
146 tmp.wr_delay_minimum = repeat.wr_delay_minimum;
148 /* Set new values for repeating events. */
149 if (ioctl(fd, WSMOUSEIO_SETREPEAT, &tmp) == -1)
150 err(EXIT_FAILURE, "WSMOUSEIO_SETREPEAT");
152 /* Now print what changed. */
153 if (field_by_value(&repeat.wr_buttons)->flags & FLG_SET)
154 pr_field(field_by_value(&repeat.wr_buttons), " -> ");
155 if (field_by_value(&repeat.wr_delay_first)->flags & FLG_SET)
156 pr_field(field_by_value(&repeat.wr_delay_first), " -> ");
157 if (field_by_value(&repeat.wr_delay_decrement)->flags & FLG_SET)
158 pr_field(field_by_value(&repeat.wr_delay_decrement), " -> ");
159 if (field_by_value(&repeat.wr_delay_minimum)->flags & FLG_SET)
160 pr_field(field_by_value(&repeat.wr_delay_minimum), " -> ");