Home | History | Annotate | Line # | Download | only in wscons
wskbd.c revision 1.20.4.2
      1  1.20.4.2   thorpej /* $NetBSD: wskbd.c,v 1.20.4.2 1999/07/01 23:41:21 thorpej Exp $ */
      2       1.1  drochner 
      3       1.1  drochner /*
      4       1.1  drochner  * Copyright (c) 1996, 1997 Christopher G. Demetriou.  All rights reserved.
      5       1.1  drochner  *
      6       1.2   hannken  * Keysym translator:
      7       1.2   hannken  * Contributed to The NetBSD Foundation by Juergen Hannken-Illjes.
      8       1.2   hannken  *
      9       1.1  drochner  * Redistribution and use in source and binary forms, with or without
     10       1.1  drochner  * modification, are permitted provided that the following conditions
     11       1.1  drochner  * are met:
     12       1.1  drochner  * 1. Redistributions of source code must retain the above copyright
     13       1.1  drochner  *    notice, this list of conditions and the following disclaimer.
     14       1.1  drochner  * 2. Redistributions in binary form must reproduce the above copyright
     15       1.1  drochner  *    notice, this list of conditions and the following disclaimer in the
     16       1.1  drochner  *    documentation and/or other materials provided with the distribution.
     17       1.1  drochner  * 3. All advertising materials mentioning features or use of this software
     18       1.1  drochner  *    must display the following acknowledgement:
     19       1.1  drochner  *      This product includes software developed by Christopher G. Demetriou
     20       1.1  drochner  *	for the NetBSD Project.
     21       1.1  drochner  * 4. The name of the author may not be used to endorse or promote products
     22       1.1  drochner  *    derived from this software without specific prior written permission
     23       1.1  drochner  *
     24       1.1  drochner  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     25       1.1  drochner  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     26       1.1  drochner  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     27       1.1  drochner  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     28       1.1  drochner  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     29       1.1  drochner  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     30       1.1  drochner  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     31       1.1  drochner  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     32       1.1  drochner  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     33       1.1  drochner  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     34       1.1  drochner  */
     35       1.1  drochner 
     36       1.1  drochner static const char _copyright[] __attribute__ ((unused)) =
     37       1.1  drochner     "Copyright (c) 1996, 1997 Christopher G. Demetriou.  All rights reserved.";
     38       1.1  drochner static const char _rcsid[] __attribute__ ((unused)) =
     39  1.20.4.2   thorpej     "$NetBSD: wskbd.c,v 1.20.4.2 1999/07/01 23:41:21 thorpej Exp $";
     40       1.1  drochner 
     41       1.1  drochner /*
     42       1.1  drochner  * Copyright (c) 1992, 1993
     43       1.1  drochner  *	The Regents of the University of California.  All rights reserved.
     44       1.1  drochner  *
     45       1.1  drochner  * This software was developed by the Computer Systems Engineering group
     46       1.1  drochner  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
     47       1.1  drochner  * contributed to Berkeley.
     48       1.1  drochner  *
     49       1.1  drochner  * All advertising materials mentioning features or use of this software
     50       1.1  drochner  * must display the following acknowledgement:
     51       1.1  drochner  *	This product includes software developed by the University of
     52       1.1  drochner  *	California, Lawrence Berkeley Laboratory.
     53       1.1  drochner  *
     54       1.1  drochner  * Redistribution and use in source and binary forms, with or without
     55       1.1  drochner  * modification, are permitted provided that the following conditions
     56       1.1  drochner  * are met:
     57       1.1  drochner  * 1. Redistributions of source code must retain the above copyright
     58       1.1  drochner  *    notice, this list of conditions and the following disclaimer.
     59       1.1  drochner  * 2. Redistributions in binary form must reproduce the above copyright
     60       1.1  drochner  *    notice, this list of conditions and the following disclaimer in the
     61       1.1  drochner  *    documentation and/or other materials provided with the distribution.
     62       1.1  drochner  * 3. All advertising materials mentioning features or use of this software
     63       1.1  drochner  *    must display the following acknowledgement:
     64       1.1  drochner  *	This product includes software developed by the University of
     65       1.1  drochner  *	California, Berkeley and its contributors.
     66       1.1  drochner  * 4. Neither the name of the University nor the names of its contributors
     67       1.1  drochner  *    may be used to endorse or promote products derived from this software
     68       1.1  drochner  *    without specific prior written permission.
     69       1.1  drochner  *
     70       1.1  drochner  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     71       1.1  drochner  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     72       1.1  drochner  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     73       1.1  drochner  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     74       1.1  drochner  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     75       1.1  drochner  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     76       1.1  drochner  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     77       1.1  drochner  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     78       1.1  drochner  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     79       1.1  drochner  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     80       1.1  drochner  * SUCH DAMAGE.
     81       1.1  drochner  *
     82       1.1  drochner  *	@(#)kbd.c	8.2 (Berkeley) 10/30/93
     83       1.1  drochner  */
     84       1.1  drochner 
     85       1.1  drochner /*
     86       1.1  drochner  * Keyboard driver (/dev/wskbd*).  Translates incoming bytes to ASCII or
     87       1.1  drochner  * to `wscons_events' and passes them up to the appropriate reader.
     88       1.1  drochner  */
     89      1.10  jonathan 
     90      1.10  jonathan #include "opt_ddb.h"
     91       1.1  drochner 
     92       1.1  drochner #include <sys/param.h>
     93       1.1  drochner #include <sys/conf.h>
     94       1.1  drochner #include <sys/device.h>
     95       1.1  drochner #include <sys/ioctl.h>
     96       1.1  drochner #include <sys/kernel.h>
     97       1.1  drochner #include <sys/proc.h>
     98       1.1  drochner #include <sys/syslog.h>
     99       1.1  drochner #include <sys/systm.h>
    100       1.2   hannken #include <sys/malloc.h>
    101       1.1  drochner #include <sys/tty.h>
    102       1.1  drochner #include <sys/signalvar.h>
    103       1.1  drochner #include <sys/errno.h>
    104       1.1  drochner #include <sys/fcntl.h>
    105  1.20.4.2   thorpej #include <sys/vnode.h>
    106       1.1  drochner 
    107       1.1  drochner #include <dev/wscons/wsconsio.h>
    108       1.1  drochner #include <dev/wscons/wskbdvar.h>
    109       1.2   hannken #include <dev/wscons/wsksymdef.h>
    110       1.2   hannken #include <dev/wscons/wsksymvar.h>
    111       1.1  drochner #include <dev/wscons/wseventvar.h>
    112       1.1  drochner #include <dev/wscons/wscons_callbacks.h>
    113       1.1  drochner 
    114       1.7  drochner #include "opt_wsdisplay_compat.h"
    115       1.7  drochner 
    116  1.20.4.1   thorpej #include "wsdisplay.h"
    117       1.5   thorpej 
    118       1.3   hannken struct wskbd_internal {
    119      1.12  drochner 	const struct wskbd_mapdata *t_keymap;
    120      1.12  drochner 
    121      1.12  drochner 	const struct wskbd_consops *t_consops;
    122      1.12  drochner 	void	*t_consaccesscookie;
    123       1.3   hannken 
    124       1.3   hannken 	int	t_modifiers;
    125       1.3   hannken 	int	t_composelen;		/* remaining entries in t_composebuf */
    126       1.3   hannken 	keysym_t t_composebuf[2];
    127       1.3   hannken 
    128       1.3   hannken 	struct wskbd_softc *t_sc;	/* back pointer */
    129       1.3   hannken };
    130       1.3   hannken 
    131       1.1  drochner struct wskbd_softc {
    132       1.1  drochner 	struct device	sc_dv;
    133       1.1  drochner 
    134       1.3   hannken 	struct wskbd_internal *id;
    135       1.3   hannken 
    136      1.12  drochner 	const struct wskbd_accessops *sc_accessops;
    137      1.12  drochner 	void *sc_accesscookie;
    138      1.12  drochner 
    139      1.12  drochner 	int	sc_ledstate;
    140       1.1  drochner 
    141       1.3   hannken 	int	sc_ready;		/* accepting events */
    142       1.1  drochner 	struct wseventvar sc_events;	/* event queue state */
    143       1.1  drochner 
    144       1.1  drochner 	int	sc_isconsole;
    145  1.20.4.1   thorpej #if NWSDISPLAY > 0
    146       1.1  drochner 	struct device	*sc_displaydv;
    147  1.20.4.1   thorpej #endif
    148       1.1  drochner 
    149       1.1  drochner 	struct wskbd_bell_data sc_bell_data;
    150       1.1  drochner 	struct wskbd_keyrepeat_data sc_keyrepeat_data;
    151       1.1  drochner 
    152       1.1  drochner 	int	sc_repeating;		/* we've called timeout() */
    153       1.9  drochner 	keysym_t sc_repeatsym;		/* repeated symbol */
    154       1.1  drochner 
    155       1.1  drochner 	int	sc_translating;		/* xlate to chars for emulation */
    156       1.2   hannken 
    157       1.2   hannken 	int	sc_maplen;		/* number of entries in sc_map */
    158       1.2   hannken 	struct wscons_keymap *sc_map;	/* current translation map */
    159      1.12  drochner 	kbd_t sc_layout; /* current layout */
    160  1.20.4.2   thorpej 
    161  1.20.4.2   thorpej 	int		sc_refcnt;
    162  1.20.4.2   thorpej 	u_char		sc_dying;	/* device is being detached */
    163  1.20.4.2   thorpej 
    164       1.1  drochner };
    165       1.1  drochner 
    166       1.2   hannken #define MOD_SHIFT_L		(1 << 0)
    167       1.2   hannken #define MOD_SHIFT_R		(1 << 1)
    168       1.2   hannken #define MOD_SHIFTLOCK		(1 << 2)
    169       1.2   hannken #define MOD_CAPSLOCK		(1 << 3)
    170       1.2   hannken #define MOD_CONTROL_L		(1 << 4)
    171       1.2   hannken #define MOD_CONTROL_R		(1 << 5)
    172       1.2   hannken #define MOD_META_L		(1 << 6)
    173       1.2   hannken #define MOD_META_R		(1 << 7)
    174       1.2   hannken #define MOD_MODESHIFT		(1 << 8)
    175       1.2   hannken #define MOD_NUMLOCK		(1 << 9)
    176       1.2   hannken #define MOD_COMPOSE		(1 << 10)
    177       1.2   hannken #define MOD_HOLDSCREEN		(1 << 11)
    178       1.2   hannken #define MOD_COMMAND		(1 << 12)
    179       1.2   hannken #define MOD_COMMAND1		(1 << 13)
    180       1.2   hannken #define MOD_COMMAND2		(1 << 14)
    181       1.2   hannken 
    182       1.2   hannken #define MOD_ANYSHIFT		(MOD_SHIFT_L | MOD_SHIFT_R | MOD_SHIFTLOCK)
    183       1.2   hannken #define MOD_ANYCONTROL		(MOD_CONTROL_L | MOD_CONTROL_R)
    184       1.2   hannken #define MOD_ANYMETA		(MOD_META_L | MOD_META_R)
    185       1.2   hannken 
    186       1.3   hannken #define MOD_ONESET(id, mask)	(((id)->t_modifiers & (mask)) != 0)
    187       1.3   hannken #define MOD_ALLSET(id, mask)	(((id)->t_modifiers & (mask)) == (mask))
    188       1.2   hannken 
    189       1.1  drochner int	wskbd_match __P((struct device *, struct cfdata *, void *));
    190       1.1  drochner void	wskbd_attach __P((struct device *, struct device *, void *));
    191  1.20.4.2   thorpej int	wskbd_detach __P((struct device *, int));
    192  1.20.4.2   thorpej int	wskbd_activate __P((struct device *, enum devact));
    193  1.20.4.2   thorpej 
    194       1.3   hannken static inline void update_leds __P((struct wskbd_internal *));
    195       1.3   hannken static inline void update_modifier __P((struct wskbd_internal *, u_int, int, int));
    196       1.7  drochner static int internal_command __P((struct wskbd_softc *, u_int *, keysym_t));
    197       1.9  drochner static keysym_t wskbd_translate __P((struct wskbd_internal *, u_int, int));
    198  1.20.4.1   thorpej static int wskbd_enable __P((struct wskbd_softc *, int));
    199  1.20.4.1   thorpej #if NWSDISPLAY > 0
    200       1.2   hannken static void wskbd_holdscreen __P((struct wskbd_softc *, int));
    201  1.20.4.1   thorpej #endif
    202       1.1  drochner 
    203  1.20.4.2   thorpej int	wskbd_do_ioctl __P((struct wskbd_softc *, u_long, caddr_t,
    204  1.20.4.2   thorpej 			    int, struct proc *));
    205  1.20.4.2   thorpej 
    206       1.1  drochner struct cfattach wskbd_ca = {
    207       1.1  drochner 	sizeof (struct wskbd_softc), wskbd_match, wskbd_attach,
    208       1.1  drochner };
    209       1.1  drochner 
    210       1.1  drochner extern struct cfdriver wskbd_cd;
    211       1.1  drochner 
    212       1.1  drochner #ifndef WSKBD_DEFAULT_BELL_PITCH
    213       1.1  drochner #define	WSKBD_DEFAULT_BELL_PITCH	1500	/* 1500Hz */
    214       1.1  drochner #endif
    215       1.1  drochner #ifndef WSKBD_DEFAULT_BELL_PERIOD
    216       1.1  drochner #define	WSKBD_DEFAULT_BELL_PERIOD	100	/* 100ms */
    217       1.1  drochner #endif
    218       1.1  drochner #ifndef WSKBD_DEFAULT_BELL_VOLUME
    219       1.1  drochner #define	WSKBD_DEFAULT_BELL_VOLUME	50	/* 50% volume */
    220       1.1  drochner #endif
    221       1.1  drochner 
    222       1.1  drochner struct wskbd_bell_data wskbd_default_bell_data = {
    223       1.1  drochner 	WSKBD_BELL_DOALL,
    224       1.1  drochner 	WSKBD_DEFAULT_BELL_PITCH,
    225       1.1  drochner 	WSKBD_DEFAULT_BELL_PERIOD,
    226       1.1  drochner 	WSKBD_DEFAULT_BELL_VOLUME,
    227       1.1  drochner };
    228       1.1  drochner 
    229       1.1  drochner #ifndef WSKBD_DEFAULT_KEYREPEAT_DEL1
    230       1.1  drochner #define	WSKBD_DEFAULT_KEYREPEAT_DEL1	400	/* 400ms to start repeating */
    231       1.1  drochner #endif
    232       1.1  drochner #ifndef WSKBD_DEFAULT_KEYREPEAT_DELN
    233       1.1  drochner #define	WSKBD_DEFAULT_KEYREPEAT_DELN	100	/* 100ms to between repeats */
    234       1.1  drochner #endif
    235       1.1  drochner 
    236       1.1  drochner struct wskbd_keyrepeat_data wskbd_default_keyrepeat_data = {
    237       1.1  drochner 	WSKBD_KEYREPEAT_DOALL,
    238       1.1  drochner 	WSKBD_DEFAULT_KEYREPEAT_DEL1,
    239       1.1  drochner 	WSKBD_DEFAULT_KEYREPEAT_DELN,
    240       1.1  drochner };
    241       1.1  drochner 
    242       1.1  drochner cdev_decl(wskbd);
    243  1.20.4.1   thorpej 
    244  1.20.4.1   thorpej #if NWSDISPLAY > 0
    245       1.1  drochner static void wskbd_repeat __P((void *v));
    246  1.20.4.1   thorpej #endif
    247       1.1  drochner 
    248       1.1  drochner static int wskbd_console_initted;
    249       1.1  drochner static struct wskbd_softc *wskbd_console_device;
    250       1.3   hannken static struct wskbd_internal wskbd_console_data;
    251       1.1  drochner 
    252       1.1  drochner /*
    253       1.1  drochner  * Print function (for parent devices).
    254       1.1  drochner  */
    255       1.1  drochner int
    256       1.1  drochner wskbddevprint(aux, pnp)
    257       1.1  drochner 	void *aux;
    258       1.1  drochner 	const char *pnp;
    259       1.1  drochner {
    260       1.1  drochner #if 0
    261       1.1  drochner 	struct wskbddev_attach_args *ap = aux;
    262       1.1  drochner #endif
    263       1.1  drochner 
    264       1.1  drochner 	if (pnp)
    265       1.1  drochner 		printf("wskbd at %s", pnp);
    266       1.1  drochner #if 0
    267       1.1  drochner 	printf(" console %d", ap->console);
    268       1.1  drochner #endif
    269       1.1  drochner 
    270       1.1  drochner 	return (UNCONF);
    271       1.1  drochner }
    272       1.1  drochner 
    273       1.1  drochner int
    274       1.1  drochner wskbd_match(parent, match, aux)
    275       1.1  drochner 	struct device *parent;
    276       1.1  drochner 	struct cfdata *match;
    277       1.1  drochner 	void *aux;
    278       1.1  drochner {
    279       1.1  drochner 	struct wskbddev_attach_args *ap = aux;
    280       1.1  drochner 
    281       1.1  drochner 	if (match->wskbddevcf_console != WSKBDDEVCF_CONSOLE_UNK) {
    282       1.1  drochner 		/*
    283       1.1  drochner 		 * If console-ness of device specified, either match
    284       1.1  drochner 		 * exactly (at high priority), or fail.
    285       1.1  drochner 		 */
    286       1.1  drochner 		if (match->wskbddevcf_console != 0 && ap->console != 0)
    287       1.1  drochner 			return (10);
    288       1.1  drochner 		else
    289       1.1  drochner 			return (0);
    290       1.1  drochner 	}
    291       1.1  drochner 
    292       1.1  drochner 	/* If console-ness unspecified, it wins. */
    293       1.1  drochner 	return (1);
    294       1.1  drochner }
    295       1.1  drochner 
    296       1.1  drochner void
    297       1.1  drochner wskbd_attach(parent, self, aux)
    298       1.1  drochner 	struct device *parent, *self;
    299       1.1  drochner 	void *aux;
    300       1.1  drochner {
    301       1.1  drochner 	struct wskbd_softc *sc = (struct wskbd_softc *)self;
    302       1.1  drochner 	struct wskbddev_attach_args *ap = aux;
    303       1.1  drochner 
    304  1.20.4.1   thorpej #if NWSDISPLAY > 0
    305  1.20.4.1   thorpej 	sc->sc_displaydv = NULL;
    306  1.20.4.1   thorpej #endif
    307  1.20.4.1   thorpej 	sc->sc_isconsole = ap->console;
    308  1.20.4.1   thorpej 
    309  1.20.4.1   thorpej 	if (ap->console) {
    310  1.20.4.1   thorpej 		KASSERT(wskbd_console_initted);
    311  1.20.4.1   thorpej 		KASSERT(wskbd_console_device == NULL);
    312  1.20.4.1   thorpej 
    313  1.20.4.1   thorpej 		wskbd_console_device = sc;
    314  1.20.4.1   thorpej 
    315       1.1  drochner 		printf(": console keyboard");
    316  1.20.4.1   thorpej 
    317  1.20.4.1   thorpej #if NWSDISPLAY > 0
    318  1.20.4.1   thorpej 		if ((sc->sc_displaydv = wsdisplay_set_console_kbd(self)))
    319  1.20.4.1   thorpej 			printf(", using %s", sc->sc_displaydv->dv_xname);
    320  1.20.4.1   thorpej #endif
    321  1.20.4.1   thorpej 	}
    322       1.1  drochner 	printf("\n");
    323       1.1  drochner 
    324       1.3   hannken 	if (ap->console) {
    325       1.3   hannken 		sc->id = &wskbd_console_data;
    326       1.3   hannken 	} else {
    327       1.3   hannken 		sc->id = malloc(sizeof(struct wskbd_internal),
    328       1.3   hannken 				M_DEVBUF, M_WAITOK);
    329      1.12  drochner 		sc->id->t_keymap = ap->keymap;
    330       1.3   hannken 		sc->id->t_modifiers = 0;
    331       1.3   hannken 	}
    332       1.3   hannken 
    333       1.3   hannken 	sc->id->t_sc = sc;
    334       1.3   hannken 
    335      1.12  drochner 	sc->sc_accessops = ap->accessops;
    336      1.12  drochner 	sc->sc_accesscookie = ap->accesscookie;
    337       1.1  drochner 	sc->sc_ready = 0;				/* sanity */
    338       1.1  drochner 	sc->sc_repeating = 0;
    339       1.1  drochner 	sc->sc_translating = 1;
    340      1.12  drochner 	sc->sc_ledstate = -1; /* force update */
    341       1.1  drochner 
    342      1.12  drochner 	if (wskbd_load_keymap(sc->id->t_keymap,
    343       1.2   hannken 			      &sc->sc_map, &sc->sc_maplen) != 0)
    344       1.2   hannken 		panic("cannot load keymap");
    345       1.2   hannken 
    346      1.12  drochner 	sc->sc_layout = sc->id->t_keymap->layout;
    347      1.12  drochner 
    348       1.1  drochner 	/* set default bell and key repeat data */
    349       1.1  drochner 	sc->sc_bell_data = wskbd_default_bell_data;
    350       1.1  drochner 	sc->sc_keyrepeat_data = wskbd_default_keyrepeat_data;
    351       1.1  drochner }
    352       1.1  drochner 
    353       1.1  drochner void
    354      1.12  drochner wskbd_cnattach(consops, conscookie, mapdata)
    355      1.12  drochner 	const struct wskbd_consops *consops;
    356      1.12  drochner 	void *conscookie;
    357      1.12  drochner 	const struct wskbd_mapdata *mapdata;
    358       1.1  drochner {
    359       1.1  drochner 
    360       1.1  drochner 	KASSERT(!wskbd_console_initted);
    361       1.1  drochner 
    362      1.12  drochner 	wskbd_console_data.t_keymap = mapdata;
    363       1.3   hannken 
    364      1.12  drochner 	wskbd_console_data.t_consops = consops;
    365      1.12  drochner 	wskbd_console_data.t_consaccesscookie = conscookie;
    366       1.1  drochner 
    367  1.20.4.1   thorpej #if NWSDISPLAY > 0
    368       1.1  drochner 	wsdisplay_set_cons_kbd(wskbd_cngetc, wskbd_cnpollc);
    369  1.20.4.1   thorpej #endif
    370       1.1  drochner 
    371       1.1  drochner 	wskbd_console_initted = 1;
    372       1.1  drochner }
    373       1.1  drochner 
    374  1.20.4.1   thorpej #if NWSDISPLAY > 0
    375       1.1  drochner static void
    376       1.1  drochner wskbd_repeat(v)
    377       1.1  drochner 	void *v;
    378       1.1  drochner {
    379       1.1  drochner 	struct wskbd_softc *sc = (struct wskbd_softc *)v;
    380       1.1  drochner 	int s = spltty();
    381       1.1  drochner 
    382      1.20  drochner 	if (!sc->sc_repeating) {
    383      1.20  drochner 		/*
    384      1.20  drochner 		 * race condition: a "key up" event came in when wskbd_repeat()
    385      1.20  drochner 		 * was already called but not yet spltty()'d
    386      1.20  drochner 		 */
    387      1.20  drochner 		splx(s);
    388      1.20  drochner 		return;
    389      1.20  drochner 	}
    390       1.9  drochner 	if (sc->sc_displaydv != NULL)
    391       1.9  drochner 		wsdisplay_kbdinput(sc->sc_displaydv, sc->sc_repeatsym);
    392       1.9  drochner 	timeout(wskbd_repeat, sc,
    393       1.9  drochner 		(hz * sc->sc_keyrepeat_data.delN) / 1000);
    394       1.1  drochner 	splx(s);
    395       1.1  drochner }
    396  1.20.4.1   thorpej #endif
    397       1.1  drochner 
    398  1.20.4.2   thorpej int
    399  1.20.4.2   thorpej wskbd_activate(self, act)
    400  1.20.4.2   thorpej 	struct device *self;
    401  1.20.4.2   thorpej 	enum devact act;
    402  1.20.4.2   thorpej {
    403  1.20.4.2   thorpej 	/* XXX should we do something more? */
    404  1.20.4.2   thorpej 	return (0);
    405  1.20.4.2   thorpej }
    406  1.20.4.2   thorpej 
    407  1.20.4.2   thorpej /*
    408  1.20.4.2   thorpej  * Detach a keyboard.  To keep track of users of the softc we keep
    409  1.20.4.2   thorpej  * a reference count that's incremented while inside, e.g., read.
    410  1.20.4.2   thorpej  * If the mouse is active and the reference count is > 0 (0 is the
    411  1.20.4.2   thorpej  * normal state) we post an event and then wait for the process
    412  1.20.4.2   thorpej  * that had the reference to wake us up again.  Then we blow away the
    413  1.20.4.2   thorpej  * vnode and return (which will deallocate the softc).
    414  1.20.4.2   thorpej  * XXX what should we do if we are connected to a display?
    415  1.20.4.2   thorpej  */
    416  1.20.4.2   thorpej int
    417  1.20.4.2   thorpej wskbd_detach(self, flags)
    418  1.20.4.2   thorpej 	struct device  *self;
    419  1.20.4.2   thorpej 	int flags;
    420  1.20.4.2   thorpej {
    421  1.20.4.2   thorpej 	struct wskbd_softc *sc = (struct wskbd_softc *)self;
    422  1.20.4.2   thorpej 	struct wseventvar *evar;
    423  1.20.4.2   thorpej 	int maj, mn;
    424  1.20.4.2   thorpej 	int s;
    425  1.20.4.2   thorpej 
    426  1.20.4.2   thorpej 	evar = &sc->sc_events;
    427  1.20.4.2   thorpej 	if (evar->io) {
    428  1.20.4.2   thorpej 		s = spltty();
    429  1.20.4.2   thorpej 		if (--sc->sc_refcnt >= 0) {
    430  1.20.4.2   thorpej 			/* Wake everyone by generating a dummy event. */
    431  1.20.4.2   thorpej 			if (++evar->put >= WSEVENT_QSIZE)
    432  1.20.4.2   thorpej 				evar->put = 0;
    433  1.20.4.2   thorpej 			WSEVENT_WAKEUP(evar);
    434  1.20.4.2   thorpej 			/* Wait for processes to go away. */
    435  1.20.4.2   thorpej 			if (tsleep(sc, PZERO, "wskdet", hz * 60))
    436  1.20.4.2   thorpej 				printf("wskbd_detach: %s didn't detach\n",
    437  1.20.4.2   thorpej 				       sc->sc_dv.dv_xname);
    438  1.20.4.2   thorpej 		}
    439  1.20.4.2   thorpej 		splx(s);
    440  1.20.4.2   thorpej 	}
    441  1.20.4.2   thorpej 
    442  1.20.4.2   thorpej 	/* locate the major number */
    443  1.20.4.2   thorpej 	for (maj = 0; maj < nchrdev; maj++)
    444  1.20.4.2   thorpej 		if (cdevsw[maj].d_open == wskbdopen)
    445  1.20.4.2   thorpej 			break;
    446  1.20.4.2   thorpej 
    447  1.20.4.2   thorpej 	/* Nuke the vnodes for any open instances. */
    448  1.20.4.2   thorpej 	mn = self->dv_unit;
    449  1.20.4.2   thorpej 	vdevgone(maj, mn, mn, VCHR);
    450  1.20.4.2   thorpej 
    451  1.20.4.2   thorpej 	return (0);
    452  1.20.4.2   thorpej }
    453  1.20.4.2   thorpej 
    454       1.1  drochner void
    455       1.1  drochner wskbd_input(dev, type, value)
    456       1.1  drochner 	struct device *dev;
    457       1.1  drochner 	u_int type;
    458       1.1  drochner 	int value;
    459       1.1  drochner {
    460       1.1  drochner 	struct wskbd_softc *sc = (struct wskbd_softc *)dev;
    461       1.1  drochner 	struct wscons_event *ev;
    462  1.20.4.2   thorpej 	struct wseventvar *evar;
    463       1.1  drochner 	struct timeval xxxtime;
    464  1.20.4.1   thorpej #if NWSDISPLAY > 0
    465       1.9  drochner 	keysym_t ks;
    466  1.20.4.1   thorpej #endif
    467       1.1  drochner 	int put;
    468       1.1  drochner 
    469  1.20.4.1   thorpej #if NWSDISPLAY > 0
    470       1.1  drochner 	if (sc->sc_repeating) {
    471       1.1  drochner 		sc->sc_repeating = 0;
    472       1.1  drochner 		untimeout(wskbd_repeat, sc);
    473       1.1  drochner 	}
    474       1.1  drochner 
    475       1.1  drochner 	/*
    476  1.20.4.2   thorpej 	 * If /dev/wskbd is not connected in event mode translate and
    477       1.1  drochner 	 * send upstream.
    478       1.1  drochner 	 */
    479       1.1  drochner 	if (sc->sc_translating) {
    480       1.9  drochner 		ks = wskbd_translate(sc->id, type, value);
    481       1.9  drochner 		if (ks != KS_voidSymbol) {
    482       1.9  drochner 			sc->sc_repeatsym = ks;
    483       1.9  drochner 			if (sc->sc_displaydv != NULL)
    484       1.9  drochner 				wsdisplay_kbdinput(sc->sc_displaydv,
    485       1.9  drochner 						   sc->sc_repeatsym);
    486       1.9  drochner 
    487       1.9  drochner 			sc->sc_repeating = 1;
    488       1.9  drochner 			timeout(wskbd_repeat, sc,
    489       1.9  drochner 				(hz * sc->sc_keyrepeat_data.del1) / 1000);
    490       1.1  drochner 		}
    491       1.1  drochner 		return;
    492       1.1  drochner 	}
    493  1.20.4.1   thorpej #endif
    494       1.1  drochner 
    495       1.1  drochner 	/*
    496       1.1  drochner 	 * Keyboard is generating events.  Turn this keystroke into an
    497       1.1  drochner 	 * event and put it in the queue.  If the queue is full, the
    498       1.1  drochner 	 * keystroke is lost (sorry!).
    499       1.1  drochner 	 */
    500       1.1  drochner 
    501       1.1  drochner 	/* no one to receive; punt!*/
    502       1.1  drochner 	if (!sc->sc_ready)
    503       1.1  drochner 		return;
    504       1.1  drochner 
    505  1.20.4.2   thorpej 	evar = &sc->sc_events;
    506  1.20.4.2   thorpej 
    507  1.20.4.2   thorpej 	put = evar->put;
    508  1.20.4.2   thorpej 	ev = &evar->q[put];
    509       1.1  drochner 	put = (put + 1) % WSEVENT_QSIZE;
    510  1.20.4.2   thorpej 	if (put == evar->get) {
    511       1.1  drochner 		log(LOG_WARNING, "%s: event queue overflow\n",
    512       1.1  drochner 		    sc->sc_dv.dv_xname);
    513       1.1  drochner 		return;
    514       1.1  drochner 	}
    515       1.1  drochner 	ev->type = type;
    516       1.1  drochner 	ev->value = value;
    517       1.1  drochner 	microtime(&xxxtime);
    518       1.1  drochner 	TIMEVAL_TO_TIMESPEC(&xxxtime, &ev->time);
    519  1.20.4.2   thorpej 	evar->put = put;
    520  1.20.4.2   thorpej 	WSEVENT_WAKEUP(evar);
    521       1.1  drochner }
    522       1.1  drochner 
    523       1.7  drochner #ifdef WSDISPLAY_COMPAT_RAWKBD
    524       1.7  drochner void
    525       1.7  drochner wskbd_rawinput(dev, buf, len)
    526       1.7  drochner 	struct device *dev;
    527       1.7  drochner 	char *buf;
    528       1.7  drochner 	int len;
    529       1.7  drochner {
    530  1.20.4.1   thorpej #if NWSDISPLAY > 0
    531       1.7  drochner 	struct wskbd_softc *sc = (struct wskbd_softc *)dev;
    532       1.9  drochner 	int i;
    533       1.7  drochner 
    534       1.9  drochner 	for (i = 0; i < len; i++)
    535       1.9  drochner 		wsdisplay_kbdinput(sc->sc_displaydv, buf[i]);
    536       1.9  drochner 	/* this is KS_GROUP_Ascii */
    537       1.7  drochner #endif
    538  1.20.4.1   thorpej }
    539  1.20.4.1   thorpej #endif /* WSDISPLAY_COMPAT_RAWKBD */
    540       1.7  drochner 
    541  1.20.4.1   thorpej #if NWSDISPLAY > 0
    542       1.2   hannken static void
    543       1.2   hannken wskbd_holdscreen(sc, hold)
    544       1.2   hannken 	struct wskbd_softc *sc;
    545       1.1  drochner 	int hold;
    546       1.1  drochner {
    547       1.2   hannken 	int new_state;
    548       1.1  drochner 
    549       1.2   hannken 	if (sc->sc_displaydv != NULL) {
    550       1.1  drochner 		wsdisplay_kbdholdscreen(sc->sc_displaydv, hold);
    551      1.12  drochner 		new_state = sc->sc_ledstate;
    552       1.2   hannken 		if (hold)
    553       1.2   hannken 			new_state |= WSKBD_LED_SCROLL;
    554       1.2   hannken 		else
    555       1.2   hannken 			new_state &= ~WSKBD_LED_SCROLL;
    556      1.12  drochner 		if (new_state != sc->sc_ledstate) {
    557      1.12  drochner 			(*sc->sc_accessops->set_leds)(sc->sc_accesscookie,
    558      1.12  drochner 						      new_state);
    559      1.12  drochner 			sc->sc_ledstate = new_state;
    560       1.2   hannken 		}
    561       1.2   hannken 	}
    562       1.1  drochner }
    563  1.20.4.1   thorpej #endif
    564       1.1  drochner 
    565  1.20.4.1   thorpej static int
    566  1.20.4.1   thorpej wskbd_enable(sc, on)
    567  1.20.4.1   thorpej 	struct wskbd_softc *sc;
    568      1.12  drochner 	int on;
    569      1.12  drochner {
    570      1.12  drochner 	int res;
    571      1.12  drochner 
    572      1.12  drochner 	/* XXX reference count? */
    573  1.20.4.1   thorpej 	if (!on && (!sc->sc_translating
    574  1.20.4.1   thorpej #if NWSDISPLAY > 0
    575  1.20.4.1   thorpej 		    || sc->sc_displaydv
    576  1.20.4.1   thorpej #endif
    577  1.20.4.1   thorpej 		))
    578      1.12  drochner 		return (EBUSY);
    579      1.12  drochner 
    580      1.12  drochner 	res = (*sc->sc_accessops->enable)(sc->sc_accesscookie, on);
    581      1.12  drochner 	return (res);
    582      1.12  drochner }
    583      1.12  drochner 
    584      1.12  drochner int
    585       1.1  drochner wskbdopen(dev, flags, mode, p)
    586       1.1  drochner 	dev_t dev;
    587       1.1  drochner 	int flags, mode;
    588       1.1  drochner 	struct proc *p;
    589       1.1  drochner {
    590       1.1  drochner 	struct wskbd_softc *sc;
    591       1.1  drochner 	int unit;
    592       1.1  drochner 
    593       1.1  drochner 	unit = minor(dev);
    594       1.1  drochner 	if (unit >= wskbd_cd.cd_ndevs ||	/* make sure it was attached */
    595       1.1  drochner 	    (sc = wskbd_cd.cd_devs[unit]) == NULL)
    596       1.1  drochner 		return (ENXIO);
    597       1.1  drochner 
    598  1.20.4.2   thorpej 	if (sc->sc_dying)
    599  1.20.4.2   thorpej 		return (EIO);
    600  1.20.4.2   thorpej 
    601       1.1  drochner 	if (sc->sc_events.io)			/* and that it's not in use */
    602       1.1  drochner 		return (EBUSY);
    603       1.1  drochner 
    604       1.1  drochner 	sc->sc_events.io = p;
    605       1.1  drochner 	wsevent_init(&sc->sc_events);		/* may cause sleep */
    606       1.1  drochner 
    607      1.11  drochner 	sc->sc_translating = 0;
    608       1.1  drochner 	sc->sc_ready = 1;			/* start accepting events */
    609       1.1  drochner 
    610  1.20.4.1   thorpej 	wskbd_enable(sc, 1);
    611       1.1  drochner 	return (0);
    612       1.1  drochner }
    613       1.1  drochner 
    614       1.1  drochner int
    615       1.1  drochner wskbdclose(dev, flags, mode, p)
    616       1.1  drochner 	dev_t dev;
    617       1.1  drochner 	int flags, mode;
    618       1.1  drochner 	struct proc *p;
    619       1.1  drochner {
    620      1.16  augustss 	struct wskbd_softc *sc = wskbd_cd.cd_devs[minor(dev)];
    621       1.1  drochner 
    622       1.1  drochner 	sc->sc_ready = 0;			/* stop accepting events */
    623      1.11  drochner 	sc->sc_translating = 1;
    624      1.12  drochner 
    625       1.1  drochner 	wsevent_fini(&sc->sc_events);
    626       1.1  drochner 	sc->sc_events.io = NULL;
    627      1.12  drochner 
    628  1.20.4.1   thorpej 	wskbd_enable(sc, 0);
    629       1.1  drochner 	return (0);
    630       1.1  drochner }
    631       1.1  drochner 
    632       1.1  drochner int
    633       1.1  drochner wskbdread(dev, uio, flags)
    634       1.1  drochner 	dev_t dev;
    635       1.1  drochner 	struct uio *uio;
    636       1.1  drochner 	int flags;
    637       1.1  drochner {
    638      1.16  augustss 	struct wskbd_softc *sc = wskbd_cd.cd_devs[minor(dev)];
    639  1.20.4.2   thorpej 	int error;
    640       1.1  drochner 
    641  1.20.4.2   thorpej 	if (sc->sc_dying)
    642  1.20.4.2   thorpej 		return (EIO);
    643  1.20.4.2   thorpej 
    644  1.20.4.2   thorpej 	sc->sc_refcnt++;
    645  1.20.4.2   thorpej 	error = wsevent_read(&sc->sc_events, uio, flags);
    646  1.20.4.2   thorpej 	if (--sc->sc_refcnt < 0) {
    647  1.20.4.2   thorpej 		wakeup(sc);
    648  1.20.4.2   thorpej 		error = EIO;
    649  1.20.4.2   thorpej 	}
    650  1.20.4.2   thorpej 	return (error);
    651       1.1  drochner }
    652       1.1  drochner 
    653       1.1  drochner int
    654       1.1  drochner wskbdioctl(dev, cmd, data, flag, p)
    655       1.1  drochner 	dev_t dev;
    656       1.1  drochner 	u_long cmd;
    657       1.1  drochner 	caddr_t data;
    658       1.1  drochner 	int flag;
    659       1.1  drochner 	struct proc *p;
    660       1.1  drochner {
    661      1.16  augustss 	struct wskbd_softc *sc = wskbd_cd.cd_devs[minor(dev)];
    662      1.16  augustss 	int error;
    663       1.1  drochner 
    664  1.20.4.2   thorpej 	sc->sc_refcnt++;
    665  1.20.4.2   thorpej 	error = wskbd_do_ioctl(sc, cmd, data, flag, p);
    666  1.20.4.2   thorpej 	if (--sc->sc_refcnt < 0)
    667  1.20.4.2   thorpej 		wakeup(sc);
    668  1.20.4.2   thorpej 	return (error);
    669  1.20.4.2   thorpej }
    670  1.20.4.2   thorpej 
    671  1.20.4.2   thorpej int
    672  1.20.4.2   thorpej wskbd_do_ioctl(sc, cmd, data, flag, p)
    673  1.20.4.2   thorpej 	struct wskbd_softc *sc;
    674  1.20.4.2   thorpej 	u_long cmd;
    675  1.20.4.2   thorpej 	caddr_t data;
    676  1.20.4.2   thorpej 	int flag;
    677  1.20.4.2   thorpej 	struct proc *p;
    678  1.20.4.2   thorpej {
    679  1.20.4.2   thorpej 	int error;
    680  1.20.4.2   thorpej 
    681       1.1  drochner 	/*
    682       1.1  drochner 	 * Try the generic ioctls that the wskbd interface supports.
    683       1.1  drochner 	 */
    684       1.1  drochner 	switch (cmd) {
    685       1.1  drochner 	case FIONBIO:		/* we will remove this someday (soon???) */
    686       1.1  drochner 		return (0);
    687       1.1  drochner 
    688       1.1  drochner 	case FIOASYNC:
    689       1.1  drochner 		sc->sc_events.async = *(int *)data != 0;
    690       1.1  drochner 		return (0);
    691       1.1  drochner 
    692       1.1  drochner 	case TIOCSPGRP:
    693       1.1  drochner 		if (*(int *)data != sc->sc_events.io->p_pgid)
    694       1.1  drochner 			return (EPERM);
    695       1.1  drochner 		return (0);
    696       1.1  drochner 	}
    697       1.1  drochner 
    698       1.1  drochner 	/*
    699       1.1  drochner 	 * Try the keyboard driver for WSKBDIO ioctls.  It returns -1
    700       1.1  drochner 	 * if it didn't recognize the request.
    701       1.1  drochner 	 */
    702       1.1  drochner 	error = wskbd_displayioctl((struct device *)sc, cmd, data, flag, p);
    703       1.1  drochner 	return (error != -1 ? error : ENOTTY);
    704       1.1  drochner }
    705       1.1  drochner 
    706       1.1  drochner /*
    707       1.1  drochner  * WSKBDIO ioctls, handled in both emulation mode and in ``raw'' mode.
    708       1.1  drochner  * Some of these have no real effect in raw mode, however.
    709       1.1  drochner  */
    710       1.1  drochner int
    711       1.1  drochner wskbd_displayioctl(dev, cmd, data, flag, p)
    712       1.1  drochner 	struct device *dev;
    713       1.1  drochner 	u_long cmd;
    714       1.1  drochner 	caddr_t data;
    715       1.1  drochner 	int flag;
    716       1.1  drochner 	struct proc *p;
    717       1.1  drochner {
    718       1.1  drochner 	struct wskbd_softc *sc = (struct wskbd_softc *)dev;
    719       1.1  drochner 	struct wskbd_bell_data *ubdp, *kbdp;
    720       1.1  drochner 	struct wskbd_keyrepeat_data *ukdp, *kkdp;
    721       1.2   hannken 	struct wskbd_map_data *umdp;
    722      1.12  drochner 	struct wskbd_mapdata md;
    723       1.2   hannken 	void *buf;
    724       1.2   hannken 	int len, error;
    725       1.1  drochner 
    726       1.1  drochner 	switch (cmd) {
    727       1.1  drochner #define	SETBELL(dstp, srcp, dfltp)					\
    728       1.1  drochner     do {								\
    729       1.1  drochner 	(dstp)->pitch = ((srcp)->which & WSKBD_BELL_DOPITCH) ?		\
    730       1.1  drochner 	    (srcp)->pitch : (dfltp)->pitch;				\
    731       1.1  drochner 	(dstp)->period = ((srcp)->which & WSKBD_BELL_DOPERIOD) ?	\
    732       1.1  drochner 	    (srcp)->period : (dfltp)->period;				\
    733       1.1  drochner 	(dstp)->volume = ((srcp)->which & WSKBD_BELL_DOVOLUME) ?	\
    734       1.1  drochner 	    (srcp)->volume : (dfltp)->volume;				\
    735       1.1  drochner 	(dstp)->which = WSKBD_BELL_DOALL;				\
    736       1.1  drochner     } while (0)
    737       1.1  drochner 
    738       1.1  drochner 	case WSKBDIO_BELL:
    739       1.1  drochner 		if ((flag & FWRITE) == 0)
    740       1.1  drochner 			return (EACCES);
    741      1.12  drochner 		return ((*sc->sc_accessops->ioctl)(sc->sc_accesscookie,
    742       1.1  drochner 		    WSKBDIO_COMPLEXBELL, (caddr_t)&sc->sc_bell_data, flag, p));
    743       1.1  drochner 
    744       1.1  drochner 	case WSKBDIO_COMPLEXBELL:
    745       1.1  drochner 		if ((flag & FWRITE) == 0)
    746       1.1  drochner 			return (EACCES);
    747       1.1  drochner 		ubdp = (struct wskbd_bell_data *)data;
    748       1.1  drochner 		SETBELL(ubdp, ubdp, &sc->sc_bell_data);
    749      1.12  drochner 		return ((*sc->sc_accessops->ioctl)(sc->sc_accesscookie,
    750       1.1  drochner 		    WSKBDIO_COMPLEXBELL, (caddr_t)ubdp, flag, p));
    751       1.1  drochner 
    752       1.1  drochner 	case WSKBDIO_SETBELL:
    753       1.1  drochner 		if ((flag & FWRITE) == 0)
    754       1.1  drochner 			return (EACCES);
    755       1.1  drochner 		kbdp = &sc->sc_bell_data;
    756       1.1  drochner setbell:
    757       1.1  drochner 		ubdp = (struct wskbd_bell_data *)data;
    758       1.1  drochner 		SETBELL(kbdp, ubdp, kbdp);
    759       1.1  drochner 		return (0);
    760       1.1  drochner 
    761       1.1  drochner 	case WSKBDIO_GETBELL:
    762       1.1  drochner 		kbdp = &sc->sc_bell_data;
    763       1.1  drochner getbell:
    764       1.1  drochner 		ubdp = (struct wskbd_bell_data *)data;
    765       1.1  drochner 		SETBELL(ubdp, kbdp, kbdp);
    766       1.1  drochner 		return (0);
    767       1.1  drochner 
    768       1.1  drochner 	case WSKBDIO_SETDEFAULTBELL:
    769       1.1  drochner 		if ((error = suser(p->p_ucred, &p->p_acflag)) != 0)
    770       1.1  drochner 			return (error);
    771       1.1  drochner 		kbdp = &wskbd_default_bell_data;
    772       1.1  drochner 		goto setbell;
    773       1.1  drochner 
    774       1.1  drochner 
    775       1.1  drochner 	case WSKBDIO_GETDEFAULTBELL:
    776       1.1  drochner 		kbdp = &wskbd_default_bell_data;
    777       1.1  drochner 		goto getbell;
    778       1.1  drochner 
    779       1.1  drochner #undef SETBELL
    780       1.1  drochner 
    781       1.1  drochner #define	SETKEYREPEAT(dstp, srcp, dfltp)					\
    782       1.1  drochner     do {								\
    783       1.1  drochner 	(dstp)->del1 = ((srcp)->which & WSKBD_KEYREPEAT_DODEL1) ?	\
    784       1.1  drochner 	    (srcp)->del1 : (dfltp)->del1;				\
    785       1.1  drochner 	(dstp)->delN = ((srcp)->which & WSKBD_KEYREPEAT_DODELN) ?	\
    786       1.1  drochner 	    (srcp)->delN : (dfltp)->delN;				\
    787       1.1  drochner 	(dstp)->which = WSKBD_KEYREPEAT_DOALL;				\
    788       1.1  drochner     } while (0)
    789       1.1  drochner 
    790       1.1  drochner 	case WSKBDIO_SETKEYREPEAT:
    791       1.1  drochner 		if ((flag & FWRITE) == 0)
    792       1.1  drochner 			return (EACCES);
    793       1.1  drochner 		kkdp = &sc->sc_keyrepeat_data;
    794       1.1  drochner setkeyrepeat:
    795       1.1  drochner 		ukdp = (struct wskbd_keyrepeat_data *)data;
    796       1.1  drochner 		SETKEYREPEAT(kkdp, ukdp, kkdp);
    797       1.1  drochner 		return (0);
    798       1.1  drochner 
    799       1.1  drochner 	case WSKBDIO_GETKEYREPEAT:
    800       1.1  drochner 		kkdp = &sc->sc_keyrepeat_data;
    801       1.1  drochner getkeyrepeat:
    802       1.1  drochner 		ukdp = (struct wskbd_keyrepeat_data *)data;
    803       1.1  drochner 		SETKEYREPEAT(ukdp, kkdp, kkdp);
    804       1.1  drochner 		return (0);
    805       1.1  drochner 
    806       1.1  drochner 	case WSKBDIO_SETDEFAULTKEYREPEAT:
    807       1.1  drochner 		if ((error = suser(p->p_ucred, &p->p_acflag)) != 0)
    808       1.1  drochner 			return (error);
    809       1.1  drochner 		kkdp = &wskbd_default_keyrepeat_data;
    810       1.1  drochner 		goto setkeyrepeat;
    811       1.1  drochner 
    812       1.1  drochner 
    813       1.1  drochner 	case WSKBDIO_GETDEFAULTKEYREPEAT:
    814       1.1  drochner 		kkdp = &wskbd_default_keyrepeat_data;
    815       1.1  drochner 		goto getkeyrepeat;
    816       1.1  drochner 
    817       1.1  drochner #undef SETKEYREPEAT
    818       1.2   hannken 
    819       1.2   hannken 	case WSKBDIO_SETMAP:
    820       1.2   hannken 		if ((flag & FWRITE) == 0)
    821       1.2   hannken 			return (EACCES);
    822       1.2   hannken 		umdp = (struct wskbd_map_data *)data;
    823       1.2   hannken 		len = umdp->maplen*sizeof(struct wscons_keymap);
    824       1.2   hannken 		buf = malloc(len, M_TEMP, M_WAITOK);
    825       1.2   hannken 		error = copyin(umdp->map, buf, len);
    826       1.2   hannken 		if (error == 0) {
    827       1.2   hannken 			wskbd_init_keymap(umdp->maplen,
    828       1.2   hannken 					  &sc->sc_map, &sc->sc_maplen);
    829      1.15  augustss 			memcpy(sc->sc_map, buf, len);
    830      1.14   hannken 			sc->sc_layout = KB_USER;
    831       1.2   hannken 		}
    832       1.2   hannken 		free(buf, M_TEMP);
    833       1.2   hannken 		return(error);
    834       1.2   hannken 
    835       1.2   hannken 	case WSKBDIO_GETMAP:
    836       1.2   hannken 		umdp = (struct wskbd_map_data *)data;
    837       1.2   hannken 		if (umdp->maplen > sc->sc_maplen)
    838       1.2   hannken 			umdp->maplen = sc->sc_maplen;
    839       1.2   hannken 		error = copyout(sc->sc_map, umdp->map,
    840       1.2   hannken 				umdp->maplen*sizeof(struct wscons_keymap));
    841       1.2   hannken 		return(error);
    842       1.2   hannken 
    843       1.2   hannken 	case WSKBDIO_GETENCODING:
    844      1.12  drochner 		*((kbd_t *) data) = sc->sc_layout;
    845       1.2   hannken 		return(0);
    846       1.2   hannken 
    847       1.2   hannken 	case WSKBDIO_SETENCODING:
    848       1.2   hannken 		if ((flag & FWRITE) == 0)
    849       1.2   hannken 			return (EACCES);
    850      1.12  drochner 		md = *(sc->id->t_keymap); /* structure assignment */
    851      1.12  drochner 		md.layout = *((kbd_t *)data);
    852      1.12  drochner 		error = wskbd_load_keymap(&md, &sc->sc_map, &sc->sc_maplen);
    853       1.2   hannken 		if (error == 0)
    854      1.12  drochner 			sc->sc_layout = *((kbd_t *)data);
    855       1.2   hannken 		return(error);
    856       1.1  drochner 	}
    857       1.1  drochner 
    858       1.1  drochner 	/*
    859       1.1  drochner 	 * Try the keyboard driver for WSKBDIO ioctls.  It returns -1
    860       1.1  drochner 	 * if it didn't recognize the request, and in turn we return
    861       1.1  drochner 	 * -1 if we didn't recognize the request.
    862       1.1  drochner 	 */
    863       1.1  drochner /* printf("kbdaccess\n"); */
    864      1.12  drochner 	error = (*sc->sc_accessops->ioctl)(sc->sc_accesscookie, cmd, data,
    865      1.12  drochner 					   flag, p);
    866       1.7  drochner #ifdef WSDISPLAY_COMPAT_RAWKBD
    867       1.7  drochner 	if (!error && cmd == WSKBDIO_SETMODE && *(int *)data == WSKBD_RAW) {
    868       1.7  drochner 		int s = spltty();
    869       1.7  drochner 		sc->id->t_modifiers &= ~(MOD_SHIFT_L | MOD_SHIFT_R
    870       1.7  drochner 					 | MOD_CONTROL_L | MOD_CONTROL_R
    871       1.7  drochner 					 | MOD_META_L | MOD_META_R
    872       1.7  drochner 					 | MOD_COMMAND
    873       1.7  drochner 					 | MOD_COMMAND1 | MOD_COMMAND2);
    874  1.20.4.2   thorpej #if NWSDISPLAY > 0
    875       1.7  drochner 		if (sc->sc_repeating) {
    876       1.7  drochner 			sc->sc_repeating = 0;
    877       1.7  drochner 			untimeout(wskbd_repeat, sc);
    878       1.7  drochner 		}
    879  1.20.4.2   thorpej #endif
    880       1.7  drochner 		splx(s);
    881       1.7  drochner 	}
    882       1.7  drochner #endif
    883       1.7  drochner 	return (error);
    884       1.1  drochner }
    885       1.1  drochner 
    886       1.1  drochner int
    887       1.1  drochner wskbdpoll(dev, events, p)
    888       1.1  drochner 	dev_t dev;
    889       1.1  drochner 	int events;
    890       1.1  drochner 	struct proc *p;
    891       1.1  drochner {
    892       1.1  drochner 	struct wskbd_softc *sc = wskbd_cd.cd_devs[minor(dev)];
    893       1.1  drochner 
    894       1.1  drochner 	return (wsevent_poll(&sc->sc_events, events, p));
    895       1.1  drochner }
    896       1.1  drochner 
    897  1.20.4.1   thorpej #if NWSDISPLAY > 0
    898  1.20.4.1   thorpej 
    899       1.1  drochner int
    900  1.20.4.1   thorpej wskbd_pickfree()
    901       1.1  drochner {
    902  1.20.4.1   thorpej 	int i;
    903  1.20.4.1   thorpej 	struct wskbd_softc *sc;
    904       1.1  drochner 
    905  1.20.4.1   thorpej 	for (i = 0; i < wskbd_cd.cd_ndevs; i++) {
    906  1.20.4.1   thorpej 		if ((sc = wskbd_cd.cd_devs[i]) == NULL)
    907  1.20.4.1   thorpej 			continue;
    908  1.20.4.1   thorpej 		if (sc->sc_displaydv == NULL)
    909  1.20.4.1   thorpej 			return (i);
    910  1.20.4.1   thorpej 	}
    911  1.20.4.1   thorpej 	return (-1);
    912       1.1  drochner }
    913       1.1  drochner 
    914  1.20.4.1   thorpej int
    915  1.20.4.1   thorpej wskbd_set_display(idx, displaydv, kbddv)
    916  1.20.4.1   thorpej 	int idx;
    917  1.20.4.1   thorpej 	struct device *displaydv, **kbddv;
    918       1.1  drochner {
    919  1.20.4.1   thorpej 	struct wskbd_softc *sc;
    920       1.1  drochner 
    921  1.20.4.1   thorpej 	if (idx >= wskbd_cd.cd_ndevs ||	/* make sure it was attached */
    922  1.20.4.1   thorpej 	    (sc = wskbd_cd.cd_devs[idx]) == NULL)
    923  1.20.4.1   thorpej 		return (ENXIO);
    924       1.1  drochner 
    925  1.20.4.1   thorpej 	if (sc->sc_isconsole)
    926  1.20.4.1   thorpej 		return (EBUSY);
    927  1.20.4.1   thorpej 	if (displaydv) {
    928  1.20.4.1   thorpej 		if (sc->sc_displaydv)
    929  1.20.4.1   thorpej 			return (EBUSY);
    930  1.20.4.1   thorpej 		printf("%s: connecting to %s\n",
    931  1.20.4.1   thorpej 		       sc->sc_dv.dv_xname, displaydv->dv_xname);
    932  1.20.4.1   thorpej 	} else {
    933  1.20.4.1   thorpej 		if (sc->sc_displaydv == NULL)
    934  1.20.4.1   thorpej 			return (ENXIO);
    935  1.20.4.1   thorpej 		printf("%s: disconnecting\n", sc->sc_dv.dv_xname);
    936  1.20.4.1   thorpej 	}
    937       1.1  drochner 
    938       1.1  drochner 	sc->sc_displaydv = displaydv;
    939  1.20.4.1   thorpej 	wskbd_enable(sc, displaydv != NULL);
    940  1.20.4.1   thorpej 	if (kbddv)
    941  1.20.4.1   thorpej 		*kbddv = &sc->sc_dv;
    942  1.20.4.1   thorpej 	return (0);
    943       1.1  drochner }
    944       1.1  drochner 
    945  1.20.4.1   thorpej struct device *
    946  1.20.4.1   thorpej wskbd_set_console_display(displaydv)
    947  1.20.4.1   thorpej 	struct device *displaydv;
    948  1.20.4.1   thorpej {
    949  1.20.4.1   thorpej 	if (!wskbd_console_device)
    950  1.20.4.1   thorpej 		return (0);
    951  1.20.4.1   thorpej 	wskbd_console_device->sc_displaydv = displaydv;
    952  1.20.4.1   thorpej 	return (&wskbd_console_device->sc_dv);
    953  1.20.4.1   thorpej }
    954  1.20.4.1   thorpej 
    955  1.20.4.1   thorpej #endif /* NWSDISPLAY > 0 */
    956  1.20.4.1   thorpej 
    957       1.1  drochner /*
    958       1.1  drochner  * Console interface.
    959       1.1  drochner  */
    960       1.1  drochner int
    961       1.1  drochner wskbd_cngetc(dev)
    962       1.1  drochner 	dev_t dev;
    963       1.1  drochner {
    964       1.2   hannken 	u_int type;
    965       1.2   hannken 	int data;
    966       1.9  drochner 	keysym_t ks;
    967       1.1  drochner 
    968       1.1  drochner 	if (!wskbd_console_initted)
    969       1.1  drochner 		return 0;
    970       1.1  drochner 
    971       1.1  drochner 	if (wskbd_console_device != NULL &&
    972       1.1  drochner 	    !wskbd_console_device->sc_translating)
    973       1.1  drochner 		return 0;
    974       1.1  drochner 
    975       1.9  drochner 	for(;;) {
    976      1.12  drochner 		(*wskbd_console_data.t_consops->getc)
    977      1.12  drochner 		    (wskbd_console_data.t_consaccesscookie, &type, &data);
    978       1.9  drochner 		ks = wskbd_translate(&wskbd_console_data, type, data);
    979       1.9  drochner 
    980       1.9  drochner 		if (KS_GROUP(ks) == KS_GROUP_Ascii)
    981       1.9  drochner 			return (KS_VALUE(ks));
    982       1.9  drochner 	}
    983       1.1  drochner }
    984       1.1  drochner 
    985       1.1  drochner void
    986       1.1  drochner wskbd_cnpollc(dev, poll)
    987       1.1  drochner 	dev_t dev;
    988       1.1  drochner 	int poll;
    989       1.1  drochner {
    990       1.1  drochner 
    991       1.1  drochner 	if (!wskbd_console_initted)
    992       1.1  drochner 		return;
    993       1.1  drochner 
    994       1.1  drochner 	if (wskbd_console_device != NULL &&
    995       1.1  drochner 	    !wskbd_console_device->sc_translating)
    996       1.1  drochner 		return;
    997       1.1  drochner 
    998      1.12  drochner 	(*wskbd_console_data.t_consops->pollc)
    999      1.12  drochner 	    (wskbd_console_data.t_consaccesscookie, poll);
   1000       1.2   hannken }
   1001       1.2   hannken 
   1002       1.2   hannken static inline void
   1003       1.3   hannken update_leds(id)
   1004       1.3   hannken 	struct wskbd_internal *id;
   1005       1.2   hannken {
   1006       1.2   hannken 	int new_state;
   1007       1.2   hannken 
   1008       1.2   hannken 	new_state = 0;
   1009       1.3   hannken 	if (id->t_modifiers & (MOD_SHIFTLOCK | MOD_CAPSLOCK))
   1010       1.2   hannken 		new_state |= WSKBD_LED_CAPS;
   1011       1.3   hannken 	if (id->t_modifiers & MOD_NUMLOCK)
   1012       1.2   hannken 		new_state |= WSKBD_LED_NUM;
   1013       1.3   hannken 	if (id->t_modifiers & MOD_COMPOSE)
   1014       1.2   hannken 		new_state |= WSKBD_LED_COMPOSE;
   1015       1.3   hannken 	if (id->t_modifiers & MOD_HOLDSCREEN)
   1016       1.2   hannken 		new_state |= WSKBD_LED_SCROLL;
   1017       1.2   hannken 
   1018      1.12  drochner 	if (id->t_sc && new_state != id->t_sc->sc_ledstate) {
   1019      1.12  drochner 		(*id->t_sc->sc_accessops->set_leds)
   1020      1.12  drochner 		    (id->t_sc->sc_accesscookie, new_state);
   1021      1.12  drochner 		id->t_sc->sc_ledstate = new_state;
   1022       1.2   hannken 	}
   1023       1.2   hannken }
   1024       1.2   hannken 
   1025       1.2   hannken static inline void
   1026       1.3   hannken update_modifier(id, type, toggle, mask)
   1027       1.3   hannken 	struct wskbd_internal *id;
   1028       1.2   hannken 	u_int type;
   1029       1.2   hannken 	int toggle;
   1030       1.2   hannken 	int mask;
   1031       1.2   hannken {
   1032       1.2   hannken 	if (toggle) {
   1033       1.2   hannken 		if (type == WSCONS_EVENT_KEY_DOWN)
   1034       1.3   hannken 			id->t_modifiers ^= mask;
   1035       1.2   hannken 	} else {
   1036       1.2   hannken 		if (type == WSCONS_EVENT_KEY_DOWN)
   1037       1.3   hannken 			id->t_modifiers |= mask;
   1038       1.2   hannken 		else
   1039       1.3   hannken 			id->t_modifiers &= ~mask;
   1040       1.2   hannken 	}
   1041       1.2   hannken }
   1042       1.2   hannken 
   1043       1.7  drochner static int
   1044       1.2   hannken internal_command(sc, type, ksym)
   1045       1.2   hannken 	struct wskbd_softc *sc;
   1046       1.2   hannken 	u_int *type;
   1047       1.2   hannken 	keysym_t ksym;
   1048       1.2   hannken {
   1049       1.2   hannken 	switch (ksym) {
   1050       1.2   hannken 	case KS_Cmd:
   1051       1.3   hannken 		update_modifier(sc->id, *type, 0, MOD_COMMAND);
   1052       1.2   hannken 		break;
   1053       1.2   hannken 
   1054       1.2   hannken 	case KS_Cmd1:
   1055       1.3   hannken 		update_modifier(sc->id, *type, 0, MOD_COMMAND1);
   1056       1.2   hannken 		break;
   1057       1.2   hannken 
   1058       1.2   hannken 	case KS_Cmd2:
   1059       1.3   hannken 		update_modifier(sc->id, *type, 0, MOD_COMMAND2);
   1060       1.2   hannken 		break;
   1061       1.2   hannken 	}
   1062       1.2   hannken 
   1063       1.2   hannken 	if (*type != WSCONS_EVENT_KEY_DOWN ||
   1064       1.3   hannken 	    (! MOD_ONESET(sc->id, MOD_COMMAND) &&
   1065       1.3   hannken 	     ! MOD_ALLSET(sc->id, MOD_COMMAND1 | MOD_COMMAND2)))
   1066       1.7  drochner 		return (0);
   1067       1.2   hannken 
   1068       1.2   hannken 	switch (ksym) {
   1069       1.2   hannken #ifdef DDB
   1070       1.2   hannken 	case KS_Cmd_Debugger:
   1071       1.2   hannken 		if (sc->sc_isconsole)
   1072      1.19  drochner 			console_debugger();
   1073       1.2   hannken 		/* discard this key (ddb discarded command modifiers) */
   1074       1.2   hannken 		*type = WSCONS_EVENT_KEY_UP;
   1075       1.7  drochner 		return (1);
   1076       1.2   hannken #endif
   1077       1.2   hannken 
   1078  1.20.4.1   thorpej #if NWSDISPLAY > 0
   1079       1.2   hannken 	case KS_Cmd_Screen0:
   1080       1.2   hannken 	case KS_Cmd_Screen1:
   1081       1.2   hannken 	case KS_Cmd_Screen2:
   1082       1.2   hannken 	case KS_Cmd_Screen3:
   1083       1.2   hannken 	case KS_Cmd_Screen4:
   1084       1.2   hannken 	case KS_Cmd_Screen5:
   1085       1.2   hannken 	case KS_Cmd_Screen6:
   1086       1.2   hannken 	case KS_Cmd_Screen7:
   1087       1.2   hannken 	case KS_Cmd_Screen8:
   1088       1.2   hannken 	case KS_Cmd_Screen9:
   1089       1.7  drochner 		wsdisplay_switch(sc->sc_displaydv, ksym - KS_Cmd_Screen0, 0);
   1090      1.17  drochner 		return (1);
   1091      1.17  drochner 	case KS_Cmd_ResetEmul:
   1092      1.18  drochner 		wsdisplay_reset(sc->sc_displaydv, WSDISPLAY_RESETEMUL);
   1093      1.18  drochner 		return (1);
   1094      1.18  drochner 	case KS_Cmd_ResetClose:
   1095      1.18  drochner 		wsdisplay_reset(sc->sc_displaydv, WSDISPLAY_RESETCLOSE);
   1096       1.7  drochner 		return (1);
   1097  1.20.4.1   thorpej #endif
   1098       1.2   hannken 	}
   1099       1.7  drochner 	return (0);
   1100       1.2   hannken }
   1101       1.2   hannken 
   1102       1.9  drochner static keysym_t
   1103       1.3   hannken wskbd_translate(id, type, value)
   1104       1.3   hannken 	struct wskbd_internal *id;
   1105       1.2   hannken 	u_int type;
   1106       1.2   hannken 	int value;
   1107       1.2   hannken {
   1108       1.3   hannken 	struct wskbd_softc *sc = id->t_sc;
   1109       1.2   hannken 	keysym_t ksym, res, *group;
   1110       1.3   hannken 	struct wscons_keymap kpbuf, *kp;
   1111       1.7  drochner 	int iscommand = 0;
   1112      1.13  drochner 
   1113      1.13  drochner 	if (type == WSCONS_EVENT_ALL_KEYS_UP) {
   1114      1.13  drochner 		id->t_modifiers &= ~(MOD_SHIFT_L | MOD_SHIFT_R
   1115      1.13  drochner 				| MOD_CONTROL_L | MOD_CONTROL_R
   1116      1.13  drochner 				| MOD_META_L | MOD_META_R
   1117      1.13  drochner 				| MOD_MODESHIFT
   1118      1.13  drochner 				| MOD_COMMAND | MOD_COMMAND1 | MOD_COMMAND2);
   1119      1.13  drochner 		update_leds(id);
   1120      1.13  drochner 		return (KS_voidSymbol);
   1121      1.13  drochner 	}
   1122       1.2   hannken 
   1123       1.3   hannken 	if (sc != NULL) {
   1124       1.3   hannken 		if (value < 0 || value >= sc->sc_maplen) {
   1125       1.2   hannken #ifdef DEBUG
   1126       1.3   hannken 			printf("wskbd_translate: keycode %d out of range\n",
   1127       1.3   hannken 			       value);
   1128       1.2   hannken #endif
   1129       1.9  drochner 			return (KS_voidSymbol);
   1130       1.3   hannken 		}
   1131       1.3   hannken 		kp = sc->sc_map + value;
   1132       1.3   hannken 	} else {
   1133       1.3   hannken 		kp = &kpbuf;
   1134      1.12  drochner 		wskbd_get_mapentry(id->t_keymap, value, kp);
   1135       1.2   hannken 	}
   1136       1.2   hannken 
   1137       1.2   hannken 	/* if this key has a command, process it first */
   1138       1.3   hannken 	if (sc != NULL && kp->command != KS_voidSymbol)
   1139       1.7  drochner 		iscommand = internal_command(sc, &type, kp->command);
   1140       1.2   hannken 
   1141       1.2   hannken 	/* Now update modifiers */
   1142       1.2   hannken 	switch (kp->group1[0]) {
   1143       1.2   hannken 	case KS_Shift_L:
   1144       1.3   hannken 		update_modifier(id, type, 0, MOD_SHIFT_L);
   1145       1.2   hannken 		break;
   1146       1.2   hannken 
   1147       1.2   hannken 	case KS_Shift_R:
   1148       1.3   hannken 		update_modifier(id, type, 0, MOD_SHIFT_R);
   1149       1.2   hannken 		break;
   1150       1.2   hannken 
   1151       1.2   hannken 	case KS_Shift_Lock:
   1152       1.3   hannken 		update_modifier(id, type, 1, MOD_SHIFTLOCK);
   1153       1.2   hannken 		break;
   1154       1.2   hannken 
   1155       1.2   hannken 	case KS_Caps_Lock:
   1156       1.3   hannken 		update_modifier(id, type, 1, MOD_CAPSLOCK);
   1157       1.2   hannken 		break;
   1158       1.2   hannken 
   1159       1.2   hannken 	case KS_Control_L:
   1160       1.3   hannken 		update_modifier(id, type, 0, MOD_CONTROL_L);
   1161       1.2   hannken 		break;
   1162       1.2   hannken 
   1163       1.2   hannken 	case KS_Control_R:
   1164       1.3   hannken 		update_modifier(id, type, 0, MOD_CONTROL_R);
   1165       1.2   hannken 		break;
   1166       1.2   hannken 
   1167       1.2   hannken 	case KS_Alt_L:
   1168       1.3   hannken 		update_modifier(id, type, 0, MOD_META_L);
   1169       1.2   hannken 		break;
   1170       1.2   hannken 
   1171       1.2   hannken 	case KS_Alt_R:
   1172       1.3   hannken 		update_modifier(id, type, 0, MOD_META_R);
   1173       1.2   hannken 		break;
   1174       1.2   hannken 
   1175       1.2   hannken 	case KS_Mode_switch:
   1176       1.3   hannken 		update_modifier(id, type, 0, MOD_MODESHIFT);
   1177       1.2   hannken 		break;
   1178       1.2   hannken 
   1179       1.2   hannken 	case KS_Num_Lock:
   1180       1.3   hannken 		update_modifier(id, type, 1, MOD_NUMLOCK);
   1181       1.2   hannken 		break;
   1182       1.2   hannken 
   1183  1.20.4.1   thorpej #if NWSDISPLAY > 0
   1184       1.2   hannken 	case KS_Hold_Screen:
   1185       1.3   hannken 		if (sc != NULL) {
   1186       1.3   hannken 			update_modifier(id, type, 1, MOD_HOLDSCREEN);
   1187       1.3   hannken 			wskbd_holdscreen(sc, id->t_modifiers & MOD_HOLDSCREEN);
   1188       1.3   hannken 		}
   1189       1.2   hannken 		break;
   1190  1.20.4.1   thorpej #endif
   1191       1.2   hannken 	}
   1192       1.2   hannken 
   1193       1.2   hannken 	/* If this is a key release or we are in command mode, we are done */
   1194       1.7  drochner 	if (type != WSCONS_EVENT_KEY_DOWN || iscommand) {
   1195       1.3   hannken 		update_leds(id);
   1196       1.9  drochner 		return (KS_voidSymbol);
   1197       1.2   hannken 	}
   1198       1.2   hannken 
   1199       1.2   hannken 	/* Get the keysym */
   1200       1.3   hannken 	if (id->t_modifiers & MOD_MODESHIFT)
   1201       1.2   hannken 		group = & kp->group2[0];
   1202       1.2   hannken 	else
   1203       1.2   hannken 		group = & kp->group1[0];
   1204       1.2   hannken 
   1205       1.3   hannken 	if ((id->t_modifiers & MOD_NUMLOCK) != 0 &&
   1206       1.2   hannken 	    KS_GROUP(group[1]) == KS_GROUP_Keypad) {
   1207       1.3   hannken 		if (MOD_ONESET(id, MOD_ANYSHIFT))
   1208       1.2   hannken 			ksym = group[0];
   1209       1.2   hannken 		else
   1210       1.2   hannken 			ksym = group[1];
   1211       1.3   hannken 	} else if (! MOD_ONESET(id, MOD_ANYSHIFT | MOD_CAPSLOCK)) {
   1212       1.2   hannken 		ksym = group[0];
   1213       1.3   hannken 	} else if (MOD_ONESET(id, MOD_CAPSLOCK)) {
   1214       1.3   hannken 		if (! MOD_ONESET(id, MOD_SHIFT_L | MOD_SHIFT_R))
   1215       1.2   hannken 			ksym = group[0];
   1216       1.2   hannken 		else
   1217       1.2   hannken 			ksym = group[1];
   1218       1.2   hannken 		if (ksym >= KS_a && ksym <= KS_z)
   1219       1.2   hannken 			ksym += KS_A - KS_a;
   1220       1.2   hannken 		else if (ksym >= KS_agrave && ksym <= KS_thorn &&
   1221       1.2   hannken 			 ksym != KS_division)
   1222       1.2   hannken 			ksym += KS_Agrave - KS_agrave;
   1223       1.3   hannken 	} else if (MOD_ONESET(id, MOD_ANYSHIFT)) {
   1224       1.2   hannken 		ksym = group[1];
   1225       1.2   hannken 	} else {
   1226       1.2   hannken 		ksym = group[0];
   1227       1.2   hannken 	}
   1228       1.2   hannken 
   1229       1.2   hannken 	/* Process compose sequence and dead accents */
   1230       1.2   hannken 	res = KS_voidSymbol;
   1231       1.2   hannken 
   1232       1.2   hannken 	switch (KS_GROUP(ksym)) {
   1233       1.2   hannken 	case KS_GROUP_Ascii:
   1234       1.2   hannken 	case KS_GROUP_Keypad:
   1235       1.2   hannken 	case KS_GROUP_Function:
   1236       1.2   hannken 		res = ksym;
   1237       1.2   hannken 		break;
   1238       1.2   hannken 
   1239       1.2   hannken 	case KS_GROUP_Mod:
   1240       1.2   hannken 		if (ksym == KS_Multi_key) {
   1241       1.3   hannken 			update_modifier(id, 1, 0, MOD_COMPOSE);
   1242       1.3   hannken 			id->t_composelen = 2;
   1243       1.2   hannken 		}
   1244       1.2   hannken 		break;
   1245       1.2   hannken 
   1246       1.2   hannken 	case KS_GROUP_Dead:
   1247       1.3   hannken 		if (id->t_composelen == 0) {
   1248       1.3   hannken 			update_modifier(id, 1, 0, MOD_COMPOSE);
   1249       1.3   hannken 			id->t_composelen = 1;
   1250       1.3   hannken 			id->t_composebuf[0] = ksym;
   1251       1.2   hannken 		} else
   1252       1.2   hannken 			res = ksym;
   1253       1.2   hannken 		break;
   1254       1.2   hannken 	}
   1255       1.2   hannken 
   1256       1.2   hannken 	if (res == KS_voidSymbol) {
   1257       1.3   hannken 		update_leds(id);
   1258       1.9  drochner 		return (res);
   1259       1.2   hannken 	}
   1260       1.2   hannken 
   1261       1.3   hannken 	if (id->t_composelen > 0) {
   1262       1.3   hannken 		id->t_composebuf[2 - id->t_composelen] = res;
   1263       1.3   hannken 		if (--id->t_composelen == 0) {
   1264       1.3   hannken 			res = wskbd_compose_value(id->t_composebuf);
   1265       1.3   hannken 			update_modifier(id, 0, 0, MOD_COMPOSE);
   1266       1.2   hannken 		} else {
   1267       1.9  drochner 			return (KS_voidSymbol);
   1268       1.2   hannken 		}
   1269       1.2   hannken 	}
   1270       1.2   hannken 
   1271       1.3   hannken 	update_leds(id);
   1272       1.2   hannken 
   1273       1.9  drochner 	/* We are done, return the symbol */
   1274       1.2   hannken 	if (KS_GROUP(res) == KS_GROUP_Ascii) {
   1275       1.3   hannken 		if (MOD_ONESET(id, MOD_ANYCONTROL)) {
   1276       1.2   hannken 			if ((res >= KS_at && res <= KS_z) || res == KS_space)
   1277       1.2   hannken 				res = res & 0x1f;
   1278       1.2   hannken 			else if (res == KS_2)
   1279       1.2   hannken 				res = 0x00;
   1280       1.2   hannken 			else if (res >= KS_3 && res <= KS_7)
   1281       1.2   hannken 				res = KS_Escape + (res - KS_3);
   1282       1.2   hannken 			else if (res == KS_8)
   1283       1.2   hannken 				res = KS_Delete;
   1284       1.2   hannken 		}
   1285       1.3   hannken 		if (MOD_ONESET(id, MOD_ANYMETA))
   1286       1.2   hannken 			res |= 0x80;
   1287       1.2   hannken 	}
   1288       1.2   hannken 
   1289       1.9  drochner 	return (res);
   1290       1.1  drochner }
   1291