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