Home | History | Annotate | Line # | Download | only in wsconsctl
mouse.c revision 1.5
      1  1.5     jmmv /*	$NetBSD: mouse.c,v 1.5 2006/02/05 17:38:33 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.5     jmmv     				FMT_BITFIELD, FLG_MODIFY },
     66  1.5     jmmv     { "repeat.delay.first",	&repeat.wr_delay_first,
     67  1.5     jmmv     				FMT_UINT, FLG_MODIFY },
     68  1.5     jmmv     { "repeat.delay.decrement",	&repeat.wr_delay_decrement,
     69  1.5     jmmv     				FMT_UINT, FLG_MODIFY },
     70  1.5     jmmv     { "repeat.delay.minimum",	&repeat.wr_delay_minimum,
     71  1.5     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.1  hannken 	if (field_by_value(&mstype)->flags & FLG_GET)
     81  1.1  hannken 		if (ioctl(fd, WSMOUSEIO_GTYPE, &mstype) < 0)
     82  1.1  hannken 			err(1, "WSMOUSEIO_GTYPE");
     83  1.5     jmmv 
     84  1.5     jmmv 	if (field_by_value(&repeat.wr_buttons)->flags & FLG_GET ||
     85  1.5     jmmv 	    field_by_value(&repeat.wr_delay_first)->flags & FLG_GET ||
     86  1.5     jmmv 	    field_by_value(&repeat.wr_delay_decrement)->flags & FLG_GET ||
     87  1.5     jmmv 	    field_by_value(&repeat.wr_delay_minimum)->flags & FLG_GET)
     88  1.5     jmmv 		mouse_get_repeat(fd);
     89  1.5     jmmv }
     90  1.5     jmmv 
     91  1.5     jmmv static void
     92  1.5     jmmv mouse_get_repeat(int fd)
     93  1.5     jmmv {
     94  1.5     jmmv 	struct wsmouse_repeat tmp;
     95  1.5     jmmv 
     96  1.5     jmmv 	if (ioctl(fd, WSMOUSEIO_GETREPEAT, &tmp) == -1)
     97  1.5     jmmv 		err(1, "WSMOUSEIO_GETREPEAT");
     98  1.5     jmmv 
     99  1.5     jmmv 	if (field_by_value(&repeat.wr_buttons)->flags & FLG_GET)
    100  1.5     jmmv 		repeat.wr_buttons = tmp.wr_buttons;
    101  1.5     jmmv 	if (field_by_value(&repeat.wr_delay_first)->flags & FLG_GET)
    102  1.5     jmmv 		repeat.wr_delay_first = tmp.wr_delay_first;
    103  1.5     jmmv 	if (field_by_value(&repeat.wr_delay_decrement)->flags & FLG_GET)
    104  1.5     jmmv 		repeat.wr_delay_decrement = tmp.wr_delay_decrement;
    105  1.5     jmmv 	if (field_by_value(&repeat.wr_delay_minimum)->flags & FLG_GET)
    106  1.5     jmmv 		repeat.wr_delay_minimum = tmp.wr_delay_minimum;
    107  1.1  hannken }
    108  1.1  hannken 
    109  1.1  hannken void
    110  1.4  xtraeme mouse_put_values(int fd)
    111  1.1  hannken {
    112  1.3       ad 	int tmp;
    113  1.2       ad 
    114  1.3       ad 	if (field_by_value(&resolution)->flags & FLG_SET) {
    115  1.3       ad 		tmp = resolution;
    116  1.3       ad 		if (ioctl(fd, WSMOUSEIO_SRES, &tmp) < 0)
    117  1.2       ad 			err(1, "WSMOUSEIO_SRES");
    118  1.3       ad 		pr_field(field_by_value(&resolution), " -> ");
    119  1.3       ad 	}
    120  1.5     jmmv 
    121  1.3       ad 	if (field_by_value(&samplerate)->flags & FLG_SET) {
    122  1.3       ad 		tmp = samplerate;
    123  1.3       ad 		if (ioctl(fd, WSMOUSEIO_SRATE, &tmp) < 0)
    124  1.2       ad 			err(1, "WSMOUSEIO_SRES");
    125  1.3       ad 		pr_field(field_by_value(&tmp), " -> ");
    126  1.3       ad 	}
    127  1.5     jmmv 
    128  1.5     jmmv 	if (field_by_value(&repeat.wr_buttons)->flags & FLG_SET ||
    129  1.5     jmmv 	    field_by_value(&repeat.wr_delay_first)->flags & FLG_SET ||
    130  1.5     jmmv 	    field_by_value(&repeat.wr_delay_decrement)->flags & FLG_SET ||
    131  1.5     jmmv 	    field_by_value(&repeat.wr_delay_minimum)->flags & FLG_SET)
    132  1.5     jmmv 		mouse_put_repeat(fd);
    133  1.5     jmmv }
    134  1.5     jmmv 
    135  1.5     jmmv static void
    136  1.5     jmmv mouse_put_repeat(int fd)
    137  1.5     jmmv {
    138  1.5     jmmv 	struct wsmouse_repeat tmp;
    139  1.5     jmmv 
    140  1.5     jmmv 	/* Fetch current values into the temporary structure. */
    141  1.5     jmmv 	if (ioctl(fd, WSMOUSEIO_GETREPEAT, &tmp) == -1)
    142  1.5     jmmv 		err(1, "WSMOUSEIO_GETREPEAT");
    143  1.5     jmmv 
    144  1.5     jmmv 	/* Overwrite the desired values in the temporary structure. */
    145  1.5     jmmv 	if (field_by_value(&repeat.wr_buttons)->flags & FLG_SET)
    146  1.5     jmmv 		tmp.wr_buttons = repeat.wr_buttons;
    147  1.5     jmmv 	if (field_by_value(&repeat.wr_delay_first)->flags & FLG_SET)
    148  1.5     jmmv 		tmp.wr_delay_first = repeat.wr_delay_first;
    149  1.5     jmmv 	if (field_by_value(&repeat.wr_delay_decrement)->flags & FLG_SET)
    150  1.5     jmmv 		tmp.wr_delay_decrement = repeat.wr_delay_decrement;
    151  1.5     jmmv 	if (field_by_value(&repeat.wr_delay_minimum)->flags & FLG_SET)
    152  1.5     jmmv 		tmp.wr_delay_minimum = repeat.wr_delay_minimum;
    153  1.5     jmmv 
    154  1.5     jmmv 	/* Set new values for repeating events. */
    155  1.5     jmmv 	if (ioctl(fd, WSMOUSEIO_SETREPEAT, &tmp) == -1)
    156  1.5     jmmv 		err(1, "WSMOUSEIO_SETREPEAT");
    157  1.5     jmmv 
    158  1.5     jmmv 	/* Now print what changed. */
    159  1.5     jmmv 	if (field_by_value(&repeat.wr_buttons)->flags & FLG_SET)
    160  1.5     jmmv 		pr_field(field_by_value(&repeat.wr_buttons), " -> ");
    161  1.5     jmmv 	if (field_by_value(&repeat.wr_delay_first)->flags & FLG_SET)
    162  1.5     jmmv 		pr_field(field_by_value(&repeat.wr_delay_first), " -> ");
    163  1.5     jmmv 	if (field_by_value(&repeat.wr_delay_decrement)->flags & FLG_SET)
    164  1.5     jmmv 		pr_field(field_by_value(&repeat.wr_delay_decrement), " -> ");
    165  1.5     jmmv 	if (field_by_value(&repeat.wr_delay_minimum)->flags & FLG_SET)
    166  1.5     jmmv 		pr_field(field_by_value(&repeat.wr_delay_minimum), " -> ");
    167  1.1  hannken }
    168