2000-03-23 10:01:25 +03:00
|
|
|
/* $NetBSD: wskbd.c,v 1.38 2000/03/23 07:01:47 thorpej Exp $ */
|
1998-03-22 17:24:02 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1996, 1997 Christopher G. Demetriou. All rights reserved.
|
|
|
|
*
|
1998-04-07 17:43:16 +04:00
|
|
|
* Keysym translator:
|
|
|
|
* Contributed to The NetBSD Foundation by Juergen Hannken-Illjes.
|
|
|
|
*
|
1998-03-22 17:24:02 +03:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by Christopher G. Demetriou
|
|
|
|
* for the NetBSD Project.
|
|
|
|
* 4. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2000-01-05 14:19:36 +03:00
|
|
|
#include <sys/cdefs.h>
|
2000-03-23 10:01:25 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: wskbd.c,v 1.38 2000/03/23 07:01:47 thorpej Exp $");
|
1998-03-22 17:24:02 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1992, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* This software was developed by the Computer Systems Engineering group
|
|
|
|
* at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
|
|
|
|
* contributed to Berkeley.
|
|
|
|
*
|
|
|
|
* All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Lawrence Berkeley Laboratory.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* @(#)kbd.c 8.2 (Berkeley) 10/30/93
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Keyboard driver (/dev/wskbd*). Translates incoming bytes to ASCII or
|
|
|
|
* to `wscons_events' and passes them up to the appropriate reader.
|
|
|
|
*/
|
|
|
|
|
1998-07-05 02:18:13 +04:00
|
|
|
#include "opt_ddb.h"
|
|
|
|
|
1998-03-22 17:24:02 +03:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/syslog.h>
|
|
|
|
#include <sys/systm.h>
|
2000-03-23 10:01:25 +03:00
|
|
|
#include <sys/callout.h>
|
1998-04-07 17:43:16 +04:00
|
|
|
#include <sys/malloc.h>
|
1998-03-22 17:24:02 +03:00
|
|
|
#include <sys/tty.h>
|
|
|
|
#include <sys/signalvar.h>
|
|
|
|
#include <sys/errno.h>
|
|
|
|
#include <sys/fcntl.h>
|
1999-06-30 10:21:21 +04:00
|
|
|
#include <sys/vnode.h>
|
1998-03-22 17:24:02 +03:00
|
|
|
|
|
|
|
#include <dev/wscons/wsconsio.h>
|
|
|
|
#include <dev/wscons/wskbdvar.h>
|
1998-04-07 17:43:16 +04:00
|
|
|
#include <dev/wscons/wsksymdef.h>
|
|
|
|
#include <dev/wscons/wsksymvar.h>
|
1998-03-22 17:24:02 +03:00
|
|
|
#include <dev/wscons/wseventvar.h>
|
|
|
|
#include <dev/wscons/wscons_callbacks.h>
|
|
|
|
|
1998-06-12 02:08:57 +04:00
|
|
|
#include "opt_wsdisplay_compat.h"
|
|
|
|
|
1999-05-14 20:01:11 +04:00
|
|
|
#include "wsdisplay.h"
|
1999-07-29 22:20:02 +04:00
|
|
|
#include "wsmux.h"
|
|
|
|
|
|
|
|
#ifdef WSKBD_DEBUG
|
|
|
|
#define DPRINTF(x) if (wskbddebug) printf x
|
|
|
|
int wskbddebug = 0;
|
|
|
|
#else
|
|
|
|
#define DPRINTF(x)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if NWSMUX > 0 || NWSDISPLAY > 0
|
|
|
|
#include <dev/wscons/wsmuxvar.h>
|
|
|
|
#endif
|
1998-05-23 05:06:36 +04:00
|
|
|
|
1998-04-09 17:09:45 +04:00
|
|
|
struct wskbd_internal {
|
1998-08-02 18:18:07 +04:00
|
|
|
const struct wskbd_mapdata *t_keymap;
|
1998-04-09 17:09:45 +04:00
|
|
|
|
1998-08-02 18:18:07 +04:00
|
|
|
const struct wskbd_consops *t_consops;
|
|
|
|
void *t_consaccesscookie;
|
1998-04-09 17:09:45 +04:00
|
|
|
|
|
|
|
int t_modifiers;
|
|
|
|
int t_composelen; /* remaining entries in t_composebuf */
|
|
|
|
keysym_t t_composebuf[2];
|
|
|
|
|
1999-12-21 15:02:04 +03:00
|
|
|
int t_flags;
|
|
|
|
#define WSKFL_METAESC 1
|
|
|
|
|
|
|
|
#define MAXKEYSYMSPERKEY 2 /* ESC <key> at max */
|
|
|
|
keysym_t t_symbols[MAXKEYSYMSPERKEY];
|
|
|
|
|
1998-04-09 17:09:45 +04:00
|
|
|
struct wskbd_softc *t_sc; /* back pointer */
|
|
|
|
};
|
|
|
|
|
1998-03-22 17:24:02 +03:00
|
|
|
struct wskbd_softc {
|
|
|
|
struct device sc_dv;
|
|
|
|
|
1998-04-09 17:09:45 +04:00
|
|
|
struct wskbd_internal *id;
|
1998-03-22 17:24:02 +03:00
|
|
|
|
1998-08-02 18:18:07 +04:00
|
|
|
const struct wskbd_accessops *sc_accessops;
|
|
|
|
void *sc_accesscookie;
|
|
|
|
|
|
|
|
int sc_ledstate;
|
1998-04-09 17:09:45 +04:00
|
|
|
|
|
|
|
int sc_ready; /* accepting events */
|
1998-03-22 17:24:02 +03:00
|
|
|
struct wseventvar sc_events; /* event queue state */
|
|
|
|
|
|
|
|
int sc_isconsole;
|
1999-05-14 20:01:11 +04:00
|
|
|
#if NWSDISPLAY > 0
|
1998-03-22 17:24:02 +03:00
|
|
|
struct device *sc_displaydv;
|
1999-05-14 20:01:11 +04:00
|
|
|
#endif
|
1998-03-22 17:24:02 +03:00
|
|
|
|
|
|
|
struct wskbd_bell_data sc_bell_data;
|
|
|
|
struct wskbd_keyrepeat_data sc_keyrepeat_data;
|
|
|
|
|
|
|
|
int sc_repeating; /* we've called timeout() */
|
2000-03-23 10:01:25 +03:00
|
|
|
struct callout sc_repeat_ch;
|
1998-03-22 17:24:02 +03:00
|
|
|
|
|
|
|
int sc_translating; /* xlate to chars for emulation */
|
1998-04-07 17:43:16 +04:00
|
|
|
|
|
|
|
int sc_maplen; /* number of entries in sc_map */
|
|
|
|
struct wscons_keymap *sc_map; /* current translation map */
|
1998-08-02 18:18:07 +04:00
|
|
|
kbd_t sc_layout; /* current layout */
|
1999-06-30 10:21:21 +04:00
|
|
|
|
|
|
|
int sc_refcnt;
|
|
|
|
u_char sc_dying; /* device is being detached */
|
|
|
|
|
1999-07-29 22:20:02 +04:00
|
|
|
#if NWSMUX > 0 || NWSDISPLAY > 0
|
|
|
|
struct wsmux_softc *sc_mux;
|
|
|
|
#endif
|
1998-03-22 17:24:02 +03:00
|
|
|
};
|
|
|
|
|
1998-04-07 17:43:16 +04:00
|
|
|
#define MOD_SHIFT_L (1 << 0)
|
|
|
|
#define MOD_SHIFT_R (1 << 1)
|
|
|
|
#define MOD_SHIFTLOCK (1 << 2)
|
|
|
|
#define MOD_CAPSLOCK (1 << 3)
|
|
|
|
#define MOD_CONTROL_L (1 << 4)
|
|
|
|
#define MOD_CONTROL_R (1 << 5)
|
|
|
|
#define MOD_META_L (1 << 6)
|
|
|
|
#define MOD_META_R (1 << 7)
|
|
|
|
#define MOD_MODESHIFT (1 << 8)
|
|
|
|
#define MOD_NUMLOCK (1 << 9)
|
|
|
|
#define MOD_COMPOSE (1 << 10)
|
|
|
|
#define MOD_HOLDSCREEN (1 << 11)
|
|
|
|
#define MOD_COMMAND (1 << 12)
|
|
|
|
#define MOD_COMMAND1 (1 << 13)
|
|
|
|
#define MOD_COMMAND2 (1 << 14)
|
|
|
|
|
|
|
|
#define MOD_ANYSHIFT (MOD_SHIFT_L | MOD_SHIFT_R | MOD_SHIFTLOCK)
|
|
|
|
#define MOD_ANYCONTROL (MOD_CONTROL_L | MOD_CONTROL_R)
|
|
|
|
#define MOD_ANYMETA (MOD_META_L | MOD_META_R)
|
|
|
|
|
1998-04-09 17:09:45 +04:00
|
|
|
#define MOD_ONESET(id, mask) (((id)->t_modifiers & (mask)) != 0)
|
|
|
|
#define MOD_ALLSET(id, mask) (((id)->t_modifiers & (mask)) == (mask))
|
1998-04-07 17:43:16 +04:00
|
|
|
|
1998-03-22 17:24:02 +03:00
|
|
|
int wskbd_match __P((struct device *, struct cfdata *, void *));
|
|
|
|
void wskbd_attach __P((struct device *, struct device *, void *));
|
1999-06-30 10:21:21 +04:00
|
|
|
int wskbd_detach __P((struct device *, int));
|
|
|
|
int wskbd_activate __P((struct device *, enum devact));
|
|
|
|
|
1999-07-29 22:20:02 +04:00
|
|
|
static int wskbd_displayioctl
|
|
|
|
__P((struct device *, u_long, caddr_t, int, struct proc *p));
|
|
|
|
int wskbd_set_display __P((struct device *, struct wsmux_softc *));
|
|
|
|
|
1998-04-09 17:09:45 +04:00
|
|
|
static inline void update_leds __P((struct wskbd_internal *));
|
|
|
|
static inline void update_modifier __P((struct wskbd_internal *, u_int, int, int));
|
1998-06-12 02:08:57 +04:00
|
|
|
static int internal_command __P((struct wskbd_softc *, u_int *, keysym_t));
|
1999-12-21 15:02:04 +03:00
|
|
|
static int wskbd_translate __P((struct wskbd_internal *, u_int, int));
|
1999-05-15 18:22:46 +04:00
|
|
|
static int wskbd_enable __P((struct wskbd_softc *, int));
|
1999-05-14 20:01:11 +04:00
|
|
|
#if NWSDISPLAY > 0
|
1998-04-07 17:43:16 +04:00
|
|
|
static void wskbd_holdscreen __P((struct wskbd_softc *, int));
|
1999-05-14 20:01:11 +04:00
|
|
|
#endif
|
1998-03-22 17:24:02 +03:00
|
|
|
|
1999-06-30 10:21:21 +04:00
|
|
|
int wskbd_do_ioctl __P((struct wskbd_softc *, u_long, caddr_t,
|
|
|
|
int, struct proc *));
|
|
|
|
|
1999-07-29 22:20:02 +04:00
|
|
|
int wskbddoclose __P((struct device *, int, int, struct proc *));
|
|
|
|
int wskbddoioctl __P((struct device *, u_long, caddr_t, int,
|
|
|
|
struct proc *));
|
|
|
|
|
1998-03-22 17:24:02 +03:00
|
|
|
struct cfattach wskbd_ca = {
|
|
|
|
sizeof (struct wskbd_softc), wskbd_match, wskbd_attach,
|
1999-07-06 11:42:23 +04:00
|
|
|
wskbd_detach, wskbd_activate
|
1998-03-22 17:24:02 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
extern struct cfdriver wskbd_cd;
|
|
|
|
|
|
|
|
#ifndef WSKBD_DEFAULT_BELL_PITCH
|
|
|
|
#define WSKBD_DEFAULT_BELL_PITCH 1500 /* 1500Hz */
|
|
|
|
#endif
|
|
|
|
#ifndef WSKBD_DEFAULT_BELL_PERIOD
|
|
|
|
#define WSKBD_DEFAULT_BELL_PERIOD 100 /* 100ms */
|
|
|
|
#endif
|
|
|
|
#ifndef WSKBD_DEFAULT_BELL_VOLUME
|
|
|
|
#define WSKBD_DEFAULT_BELL_VOLUME 50 /* 50% volume */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
struct wskbd_bell_data wskbd_default_bell_data = {
|
|
|
|
WSKBD_BELL_DOALL,
|
|
|
|
WSKBD_DEFAULT_BELL_PITCH,
|
|
|
|
WSKBD_DEFAULT_BELL_PERIOD,
|
|
|
|
WSKBD_DEFAULT_BELL_VOLUME,
|
|
|
|
};
|
|
|
|
|
|
|
|
#ifndef WSKBD_DEFAULT_KEYREPEAT_DEL1
|
|
|
|
#define WSKBD_DEFAULT_KEYREPEAT_DEL1 400 /* 400ms to start repeating */
|
|
|
|
#endif
|
|
|
|
#ifndef WSKBD_DEFAULT_KEYREPEAT_DELN
|
|
|
|
#define WSKBD_DEFAULT_KEYREPEAT_DELN 100 /* 100ms to between repeats */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
struct wskbd_keyrepeat_data wskbd_default_keyrepeat_data = {
|
|
|
|
WSKBD_KEYREPEAT_DOALL,
|
|
|
|
WSKBD_DEFAULT_KEYREPEAT_DEL1,
|
|
|
|
WSKBD_DEFAULT_KEYREPEAT_DELN,
|
|
|
|
};
|
|
|
|
|
|
|
|
cdev_decl(wskbd);
|
1999-05-14 20:01:11 +04:00
|
|
|
|
1999-12-01 14:41:46 +03:00
|
|
|
#if NWSMUX > 0 || NWSDISPLAY > 0
|
1999-07-29 22:20:02 +04:00
|
|
|
struct wsmuxops wskbd_muxops = {
|
|
|
|
wskbdopen, wskbddoclose, wskbddoioctl, wskbd_displayioctl,
|
|
|
|
wskbd_set_display
|
|
|
|
};
|
1999-12-01 14:41:46 +03:00
|
|
|
#endif
|
1999-07-29 22:20:02 +04:00
|
|
|
|
1999-05-14 20:01:11 +04:00
|
|
|
#if NWSDISPLAY > 0
|
1998-03-22 17:24:02 +03:00
|
|
|
static void wskbd_repeat __P((void *v));
|
1999-05-14 20:01:11 +04:00
|
|
|
#endif
|
1998-03-22 17:24:02 +03:00
|
|
|
|
|
|
|
static int wskbd_console_initted;
|
|
|
|
static struct wskbd_softc *wskbd_console_device;
|
1998-04-09 17:09:45 +04:00
|
|
|
static struct wskbd_internal wskbd_console_data;
|
1998-03-22 17:24:02 +03:00
|
|
|
|
1999-12-21 15:02:04 +03:00
|
|
|
static void wskbd_update_layout __P((struct wskbd_internal *, kbd_t));
|
|
|
|
|
|
|
|
static void
|
|
|
|
wskbd_update_layout(id, enc)
|
|
|
|
struct wskbd_internal *id;
|
|
|
|
kbd_t enc;
|
|
|
|
{
|
|
|
|
|
|
|
|
if (enc & KB_METAESC)
|
|
|
|
id->t_flags |= WSKFL_METAESC;
|
|
|
|
else
|
|
|
|
id->t_flags &= ~WSKFL_METAESC;
|
|
|
|
}
|
|
|
|
|
1998-03-22 17:24:02 +03:00
|
|
|
/*
|
|
|
|
* Print function (for parent devices).
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
wskbddevprint(aux, pnp)
|
|
|
|
void *aux;
|
|
|
|
const char *pnp;
|
|
|
|
{
|
|
|
|
#if 0
|
|
|
|
struct wskbddev_attach_args *ap = aux;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (pnp)
|
|
|
|
printf("wskbd at %s", pnp);
|
|
|
|
#if 0
|
|
|
|
printf(" console %d", ap->console);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return (UNCONF);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
wskbd_match(parent, match, aux)
|
|
|
|
struct device *parent;
|
|
|
|
struct cfdata *match;
|
|
|
|
void *aux;
|
|
|
|
{
|
|
|
|
struct wskbddev_attach_args *ap = aux;
|
|
|
|
|
|
|
|
if (match->wskbddevcf_console != WSKBDDEVCF_CONSOLE_UNK) {
|
|
|
|
/*
|
|
|
|
* If console-ness of device specified, either match
|
|
|
|
* exactly (at high priority), or fail.
|
|
|
|
*/
|
|
|
|
if (match->wskbddevcf_console != 0 && ap->console != 0)
|
|
|
|
return (10);
|
|
|
|
else
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If console-ness unspecified, it wins. */
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
wskbd_attach(parent, self, aux)
|
|
|
|
struct device *parent, *self;
|
|
|
|
void *aux;
|
|
|
|
{
|
|
|
|
struct wskbd_softc *sc = (struct wskbd_softc *)self;
|
|
|
|
struct wskbddev_attach_args *ap = aux;
|
1999-07-29 22:20:02 +04:00
|
|
|
#if NWSMUX > 0 || NWSDISPLAY > 0
|
|
|
|
int mux;
|
|
|
|
#endif
|
1998-03-22 17:24:02 +03:00
|
|
|
|
1999-05-15 18:22:46 +04:00
|
|
|
#if NWSDISPLAY > 0
|
|
|
|
sc->sc_displaydv = NULL;
|
|
|
|
#endif
|
|
|
|
sc->sc_isconsole = ap->console;
|
|
|
|
|
1999-07-29 22:20:02 +04:00
|
|
|
#if NWSMUX > 0 || NWSDISPLAY > 0
|
|
|
|
mux = sc->sc_dv.dv_cfdata->wskbddevcf_mux;
|
|
|
|
if (sc->sc_isconsole && mux != WSKBDDEVCF_MUX_DEFAULT) {
|
1999-08-17 03:22:22 +04:00
|
|
|
printf(" (mux %d ignored for console)", mux);
|
1999-07-29 22:20:02 +04:00
|
|
|
mux = WSKBDDEVCF_MUX_DEFAULT;
|
1999-05-15 18:22:46 +04:00
|
|
|
}
|
1999-07-29 22:20:02 +04:00
|
|
|
if (mux != WSKBDDEVCF_MUX_DEFAULT)
|
|
|
|
printf(" mux %d", mux);
|
|
|
|
#endif
|
1998-03-22 17:24:02 +03:00
|
|
|
|
1998-04-09 17:09:45 +04:00
|
|
|
if (ap->console) {
|
|
|
|
sc->id = &wskbd_console_data;
|
|
|
|
} else {
|
|
|
|
sc->id = malloc(sizeof(struct wskbd_internal),
|
|
|
|
M_DEVBUF, M_WAITOK);
|
1999-12-21 15:02:04 +03:00
|
|
|
bzero(sc->id, sizeof(struct wskbd_internal));
|
1998-08-02 18:18:07 +04:00
|
|
|
sc->id->t_keymap = ap->keymap;
|
1999-12-21 15:02:04 +03:00
|
|
|
wskbd_update_layout(sc->id, ap->keymap->layout);
|
1998-04-09 17:09:45 +04:00
|
|
|
}
|
|
|
|
|
2000-03-23 10:01:25 +03:00
|
|
|
callout_init(&sc->sc_repeat_ch);
|
|
|
|
|
1998-04-09 17:09:45 +04:00
|
|
|
sc->id->t_sc = sc;
|
|
|
|
|
1998-08-02 18:18:07 +04:00
|
|
|
sc->sc_accessops = ap->accessops;
|
|
|
|
sc->sc_accesscookie = ap->accesscookie;
|
1998-03-22 17:24:02 +03:00
|
|
|
sc->sc_ready = 0; /* sanity */
|
|
|
|
sc->sc_repeating = 0;
|
|
|
|
sc->sc_translating = 1;
|
1998-08-02 18:18:07 +04:00
|
|
|
sc->sc_ledstate = -1; /* force update */
|
1998-03-22 17:24:02 +03:00
|
|
|
|
1998-08-02 18:18:07 +04:00
|
|
|
if (wskbd_load_keymap(sc->id->t_keymap,
|
1998-04-07 17:43:16 +04:00
|
|
|
&sc->sc_map, &sc->sc_maplen) != 0)
|
|
|
|
panic("cannot load keymap");
|
|
|
|
|
1998-08-02 18:18:07 +04:00
|
|
|
sc->sc_layout = sc->id->t_keymap->layout;
|
|
|
|
|
1998-03-22 17:24:02 +03:00
|
|
|
/* set default bell and key repeat data */
|
|
|
|
sc->sc_bell_data = wskbd_default_bell_data;
|
|
|
|
sc->sc_keyrepeat_data = wskbd_default_keyrepeat_data;
|
1999-07-29 22:20:02 +04:00
|
|
|
|
|
|
|
if (ap->console) {
|
|
|
|
KASSERT(wskbd_console_initted);
|
|
|
|
KASSERT(wskbd_console_device == NULL);
|
|
|
|
|
|
|
|
wskbd_console_device = sc;
|
|
|
|
|
|
|
|
printf(": console keyboard");
|
|
|
|
|
|
|
|
#if NWSDISPLAY > 0
|
|
|
|
if ((sc->sc_displaydv = wsdisplay_set_console_kbd(self)))
|
|
|
|
printf(", using %s", sc->sc_displaydv->dv_xname);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
|
1999-07-31 00:52:27 +04:00
|
|
|
#if NWSMUX > 0
|
1999-07-29 22:20:02 +04:00
|
|
|
if (mux != WSKBDDEVCF_MUX_DEFAULT)
|
|
|
|
wsmux_attach(mux, WSMUX_KBD, &sc->sc_dv, &sc->sc_events,
|
|
|
|
&sc->sc_mux, &wskbd_muxops);
|
|
|
|
#endif
|
|
|
|
|
1998-03-22 17:24:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1998-08-02 18:18:07 +04:00
|
|
|
wskbd_cnattach(consops, conscookie, mapdata)
|
|
|
|
const struct wskbd_consops *consops;
|
|
|
|
void *conscookie;
|
|
|
|
const struct wskbd_mapdata *mapdata;
|
1998-03-22 17:24:02 +03:00
|
|
|
{
|
|
|
|
KASSERT(!wskbd_console_initted);
|
|
|
|
|
1998-08-02 18:18:07 +04:00
|
|
|
wskbd_console_data.t_keymap = mapdata;
|
1999-12-21 15:02:04 +03:00
|
|
|
wskbd_update_layout(&wskbd_console_data, mapdata->layout);
|
1998-04-09 17:09:45 +04:00
|
|
|
|
1998-08-02 18:18:07 +04:00
|
|
|
wskbd_console_data.t_consops = consops;
|
|
|
|
wskbd_console_data.t_consaccesscookie = conscookie;
|
1998-03-22 17:24:02 +03:00
|
|
|
|
1999-05-14 20:01:11 +04:00
|
|
|
#if NWSDISPLAY > 0
|
2000-03-07 00:37:16 +03:00
|
|
|
wsdisplay_set_cons_kbd(wskbd_cngetc, wskbd_cnpollc, wskbd_cnbell);
|
1999-05-14 20:01:11 +04:00
|
|
|
#endif
|
1998-03-22 17:24:02 +03:00
|
|
|
|
|
|
|
wskbd_console_initted = 1;
|
|
|
|
}
|
|
|
|
|
1999-12-02 02:22:57 +03:00
|
|
|
void
|
|
|
|
wskbd_cndetach()
|
|
|
|
{
|
|
|
|
KASSERT(wskbd_console_initted);
|
|
|
|
|
|
|
|
wskbd_console_data.t_keymap = 0;
|
|
|
|
|
|
|
|
wskbd_console_data.t_consops = 0;
|
|
|
|
wskbd_console_data.t_consaccesscookie = 0;
|
|
|
|
|
|
|
|
#if NWSDISPLAY > 0
|
|
|
|
wsdisplay_unset_cons_kbd();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
wskbd_console_initted = 0;
|
|
|
|
}
|
|
|
|
|
1999-05-14 20:01:11 +04:00
|
|
|
#if NWSDISPLAY > 0
|
1998-03-22 17:24:02 +03:00
|
|
|
static void
|
|
|
|
wskbd_repeat(v)
|
|
|
|
void *v;
|
|
|
|
{
|
|
|
|
struct wskbd_softc *sc = (struct wskbd_softc *)v;
|
|
|
|
int s = spltty();
|
|
|
|
|
1999-03-27 14:22:23 +03:00
|
|
|
if (!sc->sc_repeating) {
|
|
|
|
/*
|
|
|
|
* race condition: a "key up" event came in when wskbd_repeat()
|
|
|
|
* was already called but not yet spltty()'d
|
|
|
|
*/
|
|
|
|
splx(s);
|
|
|
|
return;
|
|
|
|
}
|
1999-12-21 15:02:04 +03:00
|
|
|
if (sc->sc_displaydv != NULL) {
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < sc->sc_repeating; i++)
|
|
|
|
wsdisplay_kbdinput(sc->sc_displaydv,
|
|
|
|
sc->id->t_symbols[i]);
|
|
|
|
}
|
2000-03-23 10:01:25 +03:00
|
|
|
callout_reset(&sc->sc_repeat_ch,
|
|
|
|
(hz * sc->sc_keyrepeat_data.delN) / 1000, wskbd_repeat, sc);
|
1998-03-22 17:24:02 +03:00
|
|
|
splx(s);
|
|
|
|
}
|
1999-05-14 20:01:11 +04:00
|
|
|
#endif
|
1998-03-22 17:24:02 +03:00
|
|
|
|
1999-06-30 10:21:21 +04:00
|
|
|
int
|
|
|
|
wskbd_activate(self, act)
|
|
|
|
struct device *self;
|
|
|
|
enum devact act;
|
|
|
|
{
|
|
|
|
/* XXX should we do something more? */
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Detach a keyboard. To keep track of users of the softc we keep
|
|
|
|
* a reference count that's incremented while inside, e.g., read.
|
1999-07-29 22:20:02 +04:00
|
|
|
* If the keyboard is active and the reference count is > 0 (0 is the
|
1999-06-30 10:21:21 +04:00
|
|
|
* normal state) we post an event and then wait for the process
|
|
|
|
* that had the reference to wake us up again. Then we blow away the
|
|
|
|
* vnode and return (which will deallocate the softc).
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
wskbd_detach(self, flags)
|
|
|
|
struct device *self;
|
|
|
|
int flags;
|
|
|
|
{
|
|
|
|
struct wskbd_softc *sc = (struct wskbd_softc *)self;
|
|
|
|
struct wseventvar *evar;
|
|
|
|
int maj, mn;
|
|
|
|
int s;
|
1999-07-31 00:52:27 +04:00
|
|
|
#if NWSMUX > 0
|
1999-07-29 22:20:02 +04:00
|
|
|
int mux;
|
|
|
|
|
|
|
|
mux = sc->sc_dv.dv_cfdata->wskbddevcf_mux;
|
|
|
|
if (mux != WSMOUSEDEVCF_MUX_DEFAULT)
|
|
|
|
wsmux_detach(mux, &sc->sc_dv);
|
|
|
|
#endif
|
1999-06-30 10:21:21 +04:00
|
|
|
|
|
|
|
evar = &sc->sc_events;
|
|
|
|
if (evar->io) {
|
|
|
|
s = spltty();
|
|
|
|
if (--sc->sc_refcnt >= 0) {
|
|
|
|
/* Wake everyone by generating a dummy event. */
|
|
|
|
if (++evar->put >= WSEVENT_QSIZE)
|
|
|
|
evar->put = 0;
|
|
|
|
WSEVENT_WAKEUP(evar);
|
|
|
|
/* Wait for processes to go away. */
|
|
|
|
if (tsleep(sc, PZERO, "wskdet", hz * 60))
|
|
|
|
printf("wskbd_detach: %s didn't detach\n",
|
|
|
|
sc->sc_dv.dv_xname);
|
|
|
|
}
|
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* locate the major number */
|
|
|
|
for (maj = 0; maj < nchrdev; maj++)
|
|
|
|
if (cdevsw[maj].d_open == wskbdopen)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Nuke the vnodes for any open instances. */
|
|
|
|
mn = self->dv_unit;
|
|
|
|
vdevgone(maj, mn, mn, VCHR);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1998-03-22 17:24:02 +03:00
|
|
|
void
|
|
|
|
wskbd_input(dev, type, value)
|
|
|
|
struct device *dev;
|
|
|
|
u_int type;
|
|
|
|
int value;
|
|
|
|
{
|
|
|
|
struct wskbd_softc *sc = (struct wskbd_softc *)dev;
|
|
|
|
struct wscons_event *ev;
|
1999-06-30 10:21:21 +04:00
|
|
|
struct wseventvar *evar;
|
1998-03-22 17:24:02 +03:00
|
|
|
struct timeval xxxtime;
|
1999-05-14 20:01:11 +04:00
|
|
|
#if NWSDISPLAY > 0
|
1999-12-21 15:02:04 +03:00
|
|
|
int num, i;
|
1999-05-14 20:01:11 +04:00
|
|
|
#endif
|
1998-03-22 17:24:02 +03:00
|
|
|
int put;
|
|
|
|
|
1999-05-14 20:01:11 +04:00
|
|
|
#if NWSDISPLAY > 0
|
1998-03-22 17:24:02 +03:00
|
|
|
if (sc->sc_repeating) {
|
|
|
|
sc->sc_repeating = 0;
|
2000-03-23 10:01:25 +03:00
|
|
|
callout_stop(&sc->sc_repeat_ch);
|
1998-03-22 17:24:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1999-06-30 10:21:21 +04:00
|
|
|
* If /dev/wskbd is not connected in event mode translate and
|
1998-03-22 17:24:02 +03:00
|
|
|
* send upstream.
|
|
|
|
*/
|
|
|
|
if (sc->sc_translating) {
|
1999-12-21 15:02:04 +03:00
|
|
|
num = wskbd_translate(sc->id, type, value);
|
|
|
|
if (num > 0) {
|
|
|
|
if (sc->sc_displaydv != NULL) {
|
|
|
|
for (i = 0; i < num; i++)
|
|
|
|
wsdisplay_kbdinput(sc->sc_displaydv,
|
|
|
|
sc->id->t_symbols[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
sc->sc_repeating = num;
|
2000-03-23 10:01:25 +03:00
|
|
|
callout_reset(&sc->sc_repeat_ch,
|
|
|
|
(hz * sc->sc_keyrepeat_data.del1) / 1000,
|
|
|
|
wskbd_repeat, sc);
|
1998-03-22 17:24:02 +03:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
1999-05-14 20:01:11 +04:00
|
|
|
#endif
|
1998-03-22 17:24:02 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Keyboard is generating events. Turn this keystroke into an
|
|
|
|
* event and put it in the queue. If the queue is full, the
|
|
|
|
* keystroke is lost (sorry!).
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* no one to receive; punt!*/
|
|
|
|
if (!sc->sc_ready)
|
|
|
|
return;
|
|
|
|
|
1999-11-08 07:48:18 +03:00
|
|
|
#if NWSMUX > 0
|
1999-07-29 22:20:02 +04:00
|
|
|
if (sc->sc_mux)
|
|
|
|
evar = &sc->sc_mux->sc_events;
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
evar = &sc->sc_events;
|
1999-06-30 10:21:21 +04:00
|
|
|
|
|
|
|
put = evar->put;
|
|
|
|
ev = &evar->q[put];
|
1998-03-22 17:24:02 +03:00
|
|
|
put = (put + 1) % WSEVENT_QSIZE;
|
1999-06-30 10:21:21 +04:00
|
|
|
if (put == evar->get) {
|
1998-03-22 17:24:02 +03:00
|
|
|
log(LOG_WARNING, "%s: event queue overflow\n",
|
|
|
|
sc->sc_dv.dv_xname);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ev->type = type;
|
|
|
|
ev->value = value;
|
|
|
|
microtime(&xxxtime);
|
|
|
|
TIMEVAL_TO_TIMESPEC(&xxxtime, &ev->time);
|
1999-06-30 10:21:21 +04:00
|
|
|
evar->put = put;
|
|
|
|
WSEVENT_WAKEUP(evar);
|
1998-03-22 17:24:02 +03:00
|
|
|
}
|
|
|
|
|
1998-06-12 02:08:57 +04:00
|
|
|
#ifdef WSDISPLAY_COMPAT_RAWKBD
|
|
|
|
void
|
|
|
|
wskbd_rawinput(dev, buf, len)
|
|
|
|
struct device *dev;
|
2000-01-22 18:09:00 +03:00
|
|
|
u_char *buf;
|
1998-06-12 02:08:57 +04:00
|
|
|
int len;
|
|
|
|
{
|
1999-05-14 20:01:11 +04:00
|
|
|
#if NWSDISPLAY > 0
|
1998-06-12 02:08:57 +04:00
|
|
|
struct wskbd_softc *sc = (struct wskbd_softc *)dev;
|
1998-06-15 21:48:32 +04:00
|
|
|
int i;
|
1998-06-12 02:08:57 +04:00
|
|
|
|
1998-06-15 21:48:32 +04:00
|
|
|
for (i = 0; i < len; i++)
|
|
|
|
wsdisplay_kbdinput(sc->sc_displaydv, buf[i]);
|
|
|
|
/* this is KS_GROUP_Ascii */
|
1998-06-12 02:08:57 +04:00
|
|
|
#endif
|
1999-05-14 20:01:11 +04:00
|
|
|
}
|
|
|
|
#endif /* WSDISPLAY_COMPAT_RAWKBD */
|
1998-06-12 02:08:57 +04:00
|
|
|
|
1999-05-14 20:01:11 +04:00
|
|
|
#if NWSDISPLAY > 0
|
1998-04-07 17:43:16 +04:00
|
|
|
static void
|
|
|
|
wskbd_holdscreen(sc, hold)
|
|
|
|
struct wskbd_softc *sc;
|
1998-03-22 17:24:02 +03:00
|
|
|
int hold;
|
|
|
|
{
|
1998-04-07 17:43:16 +04:00
|
|
|
int new_state;
|
1998-03-22 17:24:02 +03:00
|
|
|
|
1998-04-07 17:43:16 +04:00
|
|
|
if (sc->sc_displaydv != NULL) {
|
1998-03-22 17:24:02 +03:00
|
|
|
wsdisplay_kbdholdscreen(sc->sc_displaydv, hold);
|
1998-08-02 18:18:07 +04:00
|
|
|
new_state = sc->sc_ledstate;
|
1998-04-07 17:43:16 +04:00
|
|
|
if (hold)
|
|
|
|
new_state |= WSKBD_LED_SCROLL;
|
|
|
|
else
|
|
|
|
new_state &= ~WSKBD_LED_SCROLL;
|
1998-08-02 18:18:07 +04:00
|
|
|
if (new_state != sc->sc_ledstate) {
|
|
|
|
(*sc->sc_accessops->set_leds)(sc->sc_accesscookie,
|
|
|
|
new_state);
|
|
|
|
sc->sc_ledstate = new_state;
|
1998-04-07 17:43:16 +04:00
|
|
|
}
|
|
|
|
}
|
1998-03-22 17:24:02 +03:00
|
|
|
}
|
1999-05-14 20:01:11 +04:00
|
|
|
#endif
|
1998-03-22 17:24:02 +03:00
|
|
|
|
1999-05-15 18:22:46 +04:00
|
|
|
static int
|
|
|
|
wskbd_enable(sc, on)
|
|
|
|
struct wskbd_softc *sc;
|
1998-08-02 18:18:07 +04:00
|
|
|
int on;
|
|
|
|
{
|
|
|
|
int res;
|
|
|
|
|
|
|
|
/* XXX reference count? */
|
1999-05-14 20:01:11 +04:00
|
|
|
if (!on && (!sc->sc_translating
|
|
|
|
#if NWSDISPLAY > 0
|
|
|
|
|| sc->sc_displaydv
|
|
|
|
#endif
|
|
|
|
))
|
1998-08-02 18:18:07 +04:00
|
|
|
return (EBUSY);
|
|
|
|
|
|
|
|
res = (*sc->sc_accessops->enable)(sc->sc_accesscookie, on);
|
|
|
|
return (res);
|
|
|
|
}
|
|
|
|
|
1998-03-22 17:24:02 +03:00
|
|
|
int
|
|
|
|
wskbdopen(dev, flags, mode, p)
|
|
|
|
dev_t dev;
|
|
|
|
int flags, mode;
|
|
|
|
struct proc *p;
|
|
|
|
{
|
|
|
|
struct wskbd_softc *sc;
|
|
|
|
int unit;
|
|
|
|
|
|
|
|
unit = minor(dev);
|
|
|
|
if (unit >= wskbd_cd.cd_ndevs || /* make sure it was attached */
|
|
|
|
(sc = wskbd_cd.cd_devs[unit]) == NULL)
|
|
|
|
return (ENXIO);
|
|
|
|
|
1999-06-30 10:21:21 +04:00
|
|
|
if (sc->sc_dying)
|
|
|
|
return (EIO);
|
|
|
|
|
1999-08-07 19:04:35 +04:00
|
|
|
if (!(flags & FREAD)) {
|
|
|
|
/* Not opening for read, only ioctl is available. */
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1999-11-08 07:48:18 +03:00
|
|
|
#if NWSMUX > 0
|
1999-07-29 22:20:02 +04:00
|
|
|
if (sc->sc_mux)
|
|
|
|
return (EBUSY);
|
|
|
|
#endif
|
|
|
|
|
1998-03-22 17:24:02 +03:00
|
|
|
if (sc->sc_events.io) /* and that it's not in use */
|
|
|
|
return (EBUSY);
|
|
|
|
|
|
|
|
sc->sc_events.io = p;
|
|
|
|
wsevent_init(&sc->sc_events); /* may cause sleep */
|
|
|
|
|
1998-07-23 18:33:01 +04:00
|
|
|
sc->sc_translating = 0;
|
1998-03-22 17:24:02 +03:00
|
|
|
sc->sc_ready = 1; /* start accepting events */
|
|
|
|
|
1999-05-15 18:22:46 +04:00
|
|
|
wskbd_enable(sc, 1);
|
1998-03-22 17:24:02 +03:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
wskbdclose(dev, flags, mode, p)
|
|
|
|
dev_t dev;
|
|
|
|
int flags, mode;
|
|
|
|
struct proc *p;
|
|
|
|
{
|
1999-07-29 22:20:02 +04:00
|
|
|
return (wskbddoclose(wskbd_cd.cd_devs[minor(dev)], flags, mode, p));
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
wskbddoclose(dv, flags, mode, p)
|
|
|
|
struct device *dv;
|
|
|
|
int flags, mode;
|
|
|
|
struct proc *p;
|
|
|
|
{
|
|
|
|
struct wskbd_softc *sc = (struct wskbd_softc *)dv;
|
1998-03-22 17:24:02 +03:00
|
|
|
|
1999-08-07 19:04:35 +04:00
|
|
|
if (!(flags & FREAD)) {
|
|
|
|
/* Nothing to do, because open didn't do anything. */
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1998-03-22 17:24:02 +03:00
|
|
|
sc->sc_ready = 0; /* stop accepting events */
|
1998-07-23 18:33:01 +04:00
|
|
|
sc->sc_translating = 1;
|
1998-08-02 18:18:07 +04:00
|
|
|
|
1998-03-22 17:24:02 +03:00
|
|
|
wsevent_fini(&sc->sc_events);
|
|
|
|
sc->sc_events.io = NULL;
|
1998-08-02 18:18:07 +04:00
|
|
|
|
1999-05-15 18:22:46 +04:00
|
|
|
wskbd_enable(sc, 0);
|
1998-03-22 17:24:02 +03:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
wskbdread(dev, uio, flags)
|
|
|
|
dev_t dev;
|
|
|
|
struct uio *uio;
|
|
|
|
int flags;
|
|
|
|
{
|
1999-01-10 21:22:14 +03:00
|
|
|
struct wskbd_softc *sc = wskbd_cd.cd_devs[minor(dev)];
|
1999-06-30 10:21:21 +04:00
|
|
|
int error;
|
|
|
|
|
|
|
|
if (sc->sc_dying)
|
|
|
|
return (EIO);
|
1998-03-22 17:24:02 +03:00
|
|
|
|
1999-06-30 10:21:21 +04:00
|
|
|
sc->sc_refcnt++;
|
|
|
|
error = wsevent_read(&sc->sc_events, uio, flags);
|
|
|
|
if (--sc->sc_refcnt < 0) {
|
|
|
|
wakeup(sc);
|
|
|
|
error = EIO;
|
|
|
|
}
|
|
|
|
return (error);
|
1998-03-22 17:24:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
wskbdioctl(dev, cmd, data, flag, p)
|
|
|
|
dev_t dev;
|
|
|
|
u_long cmd;
|
|
|
|
caddr_t data;
|
|
|
|
int flag;
|
|
|
|
struct proc *p;
|
|
|
|
{
|
1999-07-29 22:20:02 +04:00
|
|
|
return (wskbddoioctl(wskbd_cd.cd_devs[minor(dev)], cmd, data, flag,p));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* A wrapper around the ioctl() workhorse to make reference counting easy. */
|
|
|
|
int
|
|
|
|
wskbddoioctl(dv, cmd, data, flag, p)
|
|
|
|
struct device *dv;
|
|
|
|
u_long cmd;
|
|
|
|
caddr_t data;
|
|
|
|
int flag;
|
|
|
|
struct proc *p;
|
|
|
|
{
|
|
|
|
struct wskbd_softc *sc = (struct wskbd_softc *)dv;
|
1999-01-10 21:22:14 +03:00
|
|
|
int error;
|
1998-03-22 17:24:02 +03:00
|
|
|
|
1999-06-30 10:21:21 +04:00
|
|
|
sc->sc_refcnt++;
|
|
|
|
error = wskbd_do_ioctl(sc, cmd, data, flag, p);
|
|
|
|
if (--sc->sc_refcnt < 0)
|
|
|
|
wakeup(sc);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
wskbd_do_ioctl(sc, cmd, data, flag, p)
|
|
|
|
struct wskbd_softc *sc;
|
|
|
|
u_long cmd;
|
|
|
|
caddr_t data;
|
|
|
|
int flag;
|
|
|
|
struct proc *p;
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
1998-03-22 17:24:02 +03:00
|
|
|
/*
|
|
|
|
* Try the generic ioctls that the wskbd interface supports.
|
|
|
|
*/
|
|
|
|
switch (cmd) {
|
|
|
|
case FIONBIO: /* we will remove this someday (soon???) */
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
case FIOASYNC:
|
|
|
|
sc->sc_events.async = *(int *)data != 0;
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
case TIOCSPGRP:
|
|
|
|
if (*(int *)data != sc->sc_events.io->p_pgid)
|
|
|
|
return (EPERM);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Try the keyboard driver for WSKBDIO ioctls. It returns -1
|
|
|
|
* if it didn't recognize the request.
|
|
|
|
*/
|
|
|
|
error = wskbd_displayioctl((struct device *)sc, cmd, data, flag, p);
|
|
|
|
return (error != -1 ? error : ENOTTY);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* WSKBDIO ioctls, handled in both emulation mode and in ``raw'' mode.
|
|
|
|
* Some of these have no real effect in raw mode, however.
|
|
|
|
*/
|
1999-07-29 22:20:02 +04:00
|
|
|
static int
|
1998-03-22 17:24:02 +03:00
|
|
|
wskbd_displayioctl(dev, cmd, data, flag, p)
|
|
|
|
struct device *dev;
|
|
|
|
u_long cmd;
|
|
|
|
caddr_t data;
|
|
|
|
int flag;
|
|
|
|
struct proc *p;
|
|
|
|
{
|
|
|
|
struct wskbd_softc *sc = (struct wskbd_softc *)dev;
|
|
|
|
struct wskbd_bell_data *ubdp, *kbdp;
|
|
|
|
struct wskbd_keyrepeat_data *ukdp, *kkdp;
|
1998-04-07 17:43:16 +04:00
|
|
|
struct wskbd_map_data *umdp;
|
1998-08-02 18:18:07 +04:00
|
|
|
struct wskbd_mapdata md;
|
1999-12-21 15:02:04 +03:00
|
|
|
kbd_t enc;
|
1998-04-07 17:43:16 +04:00
|
|
|
void *buf;
|
|
|
|
int len, error;
|
1998-03-22 17:24:02 +03:00
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
#define SETBELL(dstp, srcp, dfltp) \
|
|
|
|
do { \
|
|
|
|
(dstp)->pitch = ((srcp)->which & WSKBD_BELL_DOPITCH) ? \
|
|
|
|
(srcp)->pitch : (dfltp)->pitch; \
|
|
|
|
(dstp)->period = ((srcp)->which & WSKBD_BELL_DOPERIOD) ? \
|
|
|
|
(srcp)->period : (dfltp)->period; \
|
|
|
|
(dstp)->volume = ((srcp)->which & WSKBD_BELL_DOVOLUME) ? \
|
|
|
|
(srcp)->volume : (dfltp)->volume; \
|
|
|
|
(dstp)->which = WSKBD_BELL_DOALL; \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
case WSKBDIO_BELL:
|
|
|
|
if ((flag & FWRITE) == 0)
|
|
|
|
return (EACCES);
|
1998-08-02 18:18:07 +04:00
|
|
|
return ((*sc->sc_accessops->ioctl)(sc->sc_accesscookie,
|
1998-03-22 17:24:02 +03:00
|
|
|
WSKBDIO_COMPLEXBELL, (caddr_t)&sc->sc_bell_data, flag, p));
|
|
|
|
|
|
|
|
case WSKBDIO_COMPLEXBELL:
|
|
|
|
if ((flag & FWRITE) == 0)
|
|
|
|
return (EACCES);
|
|
|
|
ubdp = (struct wskbd_bell_data *)data;
|
|
|
|
SETBELL(ubdp, ubdp, &sc->sc_bell_data);
|
1998-08-02 18:18:07 +04:00
|
|
|
return ((*sc->sc_accessops->ioctl)(sc->sc_accesscookie,
|
1998-03-22 17:24:02 +03:00
|
|
|
WSKBDIO_COMPLEXBELL, (caddr_t)ubdp, flag, p));
|
|
|
|
|
|
|
|
case WSKBDIO_SETBELL:
|
|
|
|
if ((flag & FWRITE) == 0)
|
|
|
|
return (EACCES);
|
|
|
|
kbdp = &sc->sc_bell_data;
|
|
|
|
setbell:
|
|
|
|
ubdp = (struct wskbd_bell_data *)data;
|
|
|
|
SETBELL(kbdp, ubdp, kbdp);
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
case WSKBDIO_GETBELL:
|
|
|
|
kbdp = &sc->sc_bell_data;
|
|
|
|
getbell:
|
|
|
|
ubdp = (struct wskbd_bell_data *)data;
|
|
|
|
SETBELL(ubdp, kbdp, kbdp);
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
case WSKBDIO_SETDEFAULTBELL:
|
|
|
|
if ((error = suser(p->p_ucred, &p->p_acflag)) != 0)
|
|
|
|
return (error);
|
|
|
|
kbdp = &wskbd_default_bell_data;
|
|
|
|
goto setbell;
|
|
|
|
|
|
|
|
|
|
|
|
case WSKBDIO_GETDEFAULTBELL:
|
|
|
|
kbdp = &wskbd_default_bell_data;
|
|
|
|
goto getbell;
|
|
|
|
|
|
|
|
#undef SETBELL
|
|
|
|
|
|
|
|
#define SETKEYREPEAT(dstp, srcp, dfltp) \
|
|
|
|
do { \
|
|
|
|
(dstp)->del1 = ((srcp)->which & WSKBD_KEYREPEAT_DODEL1) ? \
|
|
|
|
(srcp)->del1 : (dfltp)->del1; \
|
|
|
|
(dstp)->delN = ((srcp)->which & WSKBD_KEYREPEAT_DODELN) ? \
|
|
|
|
(srcp)->delN : (dfltp)->delN; \
|
|
|
|
(dstp)->which = WSKBD_KEYREPEAT_DOALL; \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
case WSKBDIO_SETKEYREPEAT:
|
|
|
|
if ((flag & FWRITE) == 0)
|
|
|
|
return (EACCES);
|
|
|
|
kkdp = &sc->sc_keyrepeat_data;
|
|
|
|
setkeyrepeat:
|
|
|
|
ukdp = (struct wskbd_keyrepeat_data *)data;
|
|
|
|
SETKEYREPEAT(kkdp, ukdp, kkdp);
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
case WSKBDIO_GETKEYREPEAT:
|
|
|
|
kkdp = &sc->sc_keyrepeat_data;
|
|
|
|
getkeyrepeat:
|
|
|
|
ukdp = (struct wskbd_keyrepeat_data *)data;
|
|
|
|
SETKEYREPEAT(ukdp, kkdp, kkdp);
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
case WSKBDIO_SETDEFAULTKEYREPEAT:
|
|
|
|
if ((error = suser(p->p_ucred, &p->p_acflag)) != 0)
|
|
|
|
return (error);
|
|
|
|
kkdp = &wskbd_default_keyrepeat_data;
|
|
|
|
goto setkeyrepeat;
|
|
|
|
|
|
|
|
|
|
|
|
case WSKBDIO_GETDEFAULTKEYREPEAT:
|
|
|
|
kkdp = &wskbd_default_keyrepeat_data;
|
|
|
|
goto getkeyrepeat;
|
|
|
|
|
|
|
|
#undef SETKEYREPEAT
|
1998-04-07 17:43:16 +04:00
|
|
|
|
|
|
|
case WSKBDIO_SETMAP:
|
|
|
|
if ((flag & FWRITE) == 0)
|
|
|
|
return (EACCES);
|
|
|
|
umdp = (struct wskbd_map_data *)data;
|
|
|
|
len = umdp->maplen*sizeof(struct wscons_keymap);
|
|
|
|
buf = malloc(len, M_TEMP, M_WAITOK);
|
|
|
|
error = copyin(umdp->map, buf, len);
|
|
|
|
if (error == 0) {
|
|
|
|
wskbd_init_keymap(umdp->maplen,
|
|
|
|
&sc->sc_map, &sc->sc_maplen);
|
1999-01-10 03:28:21 +03:00
|
|
|
memcpy(sc->sc_map, buf, len);
|
1999-12-21 15:02:04 +03:00
|
|
|
/* drop the variant bits handled by the map */
|
|
|
|
sc->sc_layout = KB_USER |
|
|
|
|
(KB_VARIANT(sc->sc_layout) & KB_HANDLEDBYWSKBD);
|
|
|
|
wskbd_update_layout(sc->id, sc->sc_layout);
|
1998-04-07 17:43:16 +04:00
|
|
|
}
|
|
|
|
free(buf, M_TEMP);
|
|
|
|
return(error);
|
|
|
|
|
|
|
|
case WSKBDIO_GETMAP:
|
|
|
|
umdp = (struct wskbd_map_data *)data;
|
|
|
|
if (umdp->maplen > sc->sc_maplen)
|
|
|
|
umdp->maplen = sc->sc_maplen;
|
|
|
|
error = copyout(sc->sc_map, umdp->map,
|
|
|
|
umdp->maplen*sizeof(struct wscons_keymap));
|
|
|
|
return(error);
|
|
|
|
|
|
|
|
case WSKBDIO_GETENCODING:
|
1998-08-02 18:18:07 +04:00
|
|
|
*((kbd_t *) data) = sc->sc_layout;
|
1998-04-07 17:43:16 +04:00
|
|
|
return(0);
|
|
|
|
|
|
|
|
case WSKBDIO_SETENCODING:
|
|
|
|
if ((flag & FWRITE) == 0)
|
|
|
|
return (EACCES);
|
1999-12-21 15:02:04 +03:00
|
|
|
enc = *((kbd_t *)data);
|
|
|
|
if (KB_ENCODING(enc) == KB_USER) {
|
|
|
|
/* user map must already be loaded */
|
|
|
|
if (KB_ENCODING(sc->sc_layout) != KB_USER)
|
|
|
|
return (EINVAL);
|
|
|
|
/* map variants make no sense */
|
|
|
|
if (KB_VARIANT(enc) & ~KB_HANDLEDBYWSKBD)
|
|
|
|
return (EINVAL);
|
|
|
|
} else {
|
|
|
|
md = *(sc->id->t_keymap); /* structure assignment */
|
|
|
|
md.layout = enc;
|
|
|
|
error = wskbd_load_keymap(&md, &sc->sc_map,
|
|
|
|
&sc->sc_maplen);
|
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
sc->sc_layout = enc;
|
|
|
|
wskbd_update_layout(sc->id, enc);
|
|
|
|
return (0);
|
1998-03-22 17:24:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Try the keyboard driver for WSKBDIO ioctls. It returns -1
|
|
|
|
* if it didn't recognize the request, and in turn we return
|
|
|
|
* -1 if we didn't recognize the request.
|
|
|
|
*/
|
|
|
|
/* printf("kbdaccess\n"); */
|
1998-08-02 18:18:07 +04:00
|
|
|
error = (*sc->sc_accessops->ioctl)(sc->sc_accesscookie, cmd, data,
|
|
|
|
flag, p);
|
1998-06-12 02:08:57 +04:00
|
|
|
#ifdef WSDISPLAY_COMPAT_RAWKBD
|
|
|
|
if (!error && cmd == WSKBDIO_SETMODE && *(int *)data == WSKBD_RAW) {
|
|
|
|
int s = spltty();
|
|
|
|
sc->id->t_modifiers &= ~(MOD_SHIFT_L | MOD_SHIFT_R
|
|
|
|
| MOD_CONTROL_L | MOD_CONTROL_R
|
|
|
|
| MOD_META_L | MOD_META_R
|
|
|
|
| MOD_COMMAND
|
|
|
|
| MOD_COMMAND1 | MOD_COMMAND2);
|
1999-07-01 15:18:20 +04:00
|
|
|
#if NWSDISPLAY > 0
|
1998-06-12 02:08:57 +04:00
|
|
|
if (sc->sc_repeating) {
|
|
|
|
sc->sc_repeating = 0;
|
2000-03-23 10:01:25 +03:00
|
|
|
callout_stop(&sc->sc_repeat_ch);
|
1998-06-12 02:08:57 +04:00
|
|
|
}
|
1999-07-01 15:18:20 +04:00
|
|
|
#endif
|
1998-06-12 02:08:57 +04:00
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return (error);
|
1998-03-22 17:24:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
wskbdpoll(dev, events, p)
|
|
|
|
dev_t dev;
|
|
|
|
int events;
|
|
|
|
struct proc *p;
|
|
|
|
{
|
|
|
|
struct wskbd_softc *sc = wskbd_cd.cd_devs[minor(dev)];
|
|
|
|
|
|
|
|
return (wsevent_poll(&sc->sc_events, events, p));
|
|
|
|
}
|
|
|
|
|
1999-05-15 18:22:46 +04:00
|
|
|
#if NWSDISPLAY > 0
|
|
|
|
|
1998-03-22 17:24:02 +03:00
|
|
|
int
|
1999-05-15 18:22:46 +04:00
|
|
|
wskbd_pickfree()
|
1998-03-22 17:24:02 +03:00
|
|
|
{
|
1999-05-15 18:22:46 +04:00
|
|
|
int i;
|
|
|
|
struct wskbd_softc *sc;
|
1998-03-22 17:24:02 +03:00
|
|
|
|
1999-05-15 18:22:46 +04:00
|
|
|
for (i = 0; i < wskbd_cd.cd_ndevs; i++) {
|
|
|
|
if ((sc = wskbd_cd.cd_devs[i]) == NULL)
|
|
|
|
continue;
|
|
|
|
if (sc->sc_displaydv == NULL)
|
|
|
|
return (i);
|
|
|
|
}
|
|
|
|
return (-1);
|
1998-03-22 17:24:02 +03:00
|
|
|
}
|
|
|
|
|
1999-07-29 22:20:02 +04:00
|
|
|
struct device *
|
|
|
|
wskbd_set_console_display(displaydv, muxsc)
|
|
|
|
struct device *displaydv;
|
|
|
|
struct wsmux_softc *muxsc;
|
|
|
|
{
|
|
|
|
struct wskbd_softc *sc = wskbd_console_device;
|
|
|
|
|
|
|
|
if (!sc)
|
|
|
|
return (0);
|
|
|
|
sc->sc_displaydv = displaydv;
|
|
|
|
(void)wsmux_attach_sc(muxsc, WSMUX_KBD, &sc->sc_dv, &sc->sc_events,
|
|
|
|
&sc->sc_mux, &wskbd_muxops);
|
|
|
|
return (&sc->sc_dv);
|
|
|
|
}
|
|
|
|
|
1999-05-15 18:22:46 +04:00
|
|
|
int
|
1999-07-29 22:20:02 +04:00
|
|
|
wskbd_set_display(dv, muxsc)
|
|
|
|
struct device *dv;
|
|
|
|
struct wsmux_softc *muxsc;
|
1998-03-22 17:24:02 +03:00
|
|
|
{
|
1999-07-29 22:20:02 +04:00
|
|
|
struct wskbd_softc *sc = (struct wskbd_softc *)dv;
|
|
|
|
struct device *displaydv = muxsc ? muxsc->sc_displaydv : 0;
|
|
|
|
struct device *odisplaydv;
|
|
|
|
int error;
|
1998-03-22 17:24:02 +03:00
|
|
|
|
1999-07-29 22:20:02 +04:00
|
|
|
DPRINTF(("wskbd_set_display: %s mux=%p disp=%p odisp=%p cons=%d\n",
|
|
|
|
dv->dv_xname, muxsc, sc->sc_displaydv, displaydv,
|
|
|
|
sc->sc_isconsole));
|
1998-03-22 17:24:02 +03:00
|
|
|
|
1999-05-15 18:22:46 +04:00
|
|
|
if (sc->sc_isconsole)
|
|
|
|
return (EBUSY);
|
1999-07-29 22:20:02 +04:00
|
|
|
|
1999-05-15 18:22:46 +04:00
|
|
|
if (displaydv) {
|
|
|
|
if (sc->sc_displaydv)
|
|
|
|
return (EBUSY);
|
|
|
|
} else {
|
|
|
|
if (sc->sc_displaydv == NULL)
|
|
|
|
return (ENXIO);
|
|
|
|
}
|
1998-03-22 17:24:02 +03:00
|
|
|
|
1999-07-29 22:20:02 +04:00
|
|
|
odisplaydv = sc->sc_displaydv;
|
1998-03-22 17:24:02 +03:00
|
|
|
sc->sc_displaydv = displaydv;
|
1999-07-29 22:20:02 +04:00
|
|
|
|
|
|
|
error = wskbd_enable(sc, displaydv != NULL);
|
|
|
|
if (error) {
|
|
|
|
sc->sc_displaydv = odisplaydv;
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (displaydv)
|
|
|
|
printf("%s: connecting to %s\n",
|
|
|
|
sc->sc_dv.dv_xname, displaydv->dv_xname);
|
|
|
|
else
|
|
|
|
printf("%s: disconnecting from %s\n",
|
|
|
|
sc->sc_dv.dv_xname, odisplaydv->dv_xname);
|
|
|
|
|
1999-05-15 18:22:46 +04:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1999-07-29 22:20:02 +04:00
|
|
|
int
|
|
|
|
wskbd_add_mux(unit, muxsc)
|
|
|
|
int unit;
|
|
|
|
struct wsmux_softc *muxsc;
|
1999-05-15 18:22:46 +04:00
|
|
|
{
|
1999-07-29 22:20:02 +04:00
|
|
|
struct wskbd_softc *sc;
|
|
|
|
|
|
|
|
DPRINTF(("wskbd_add_mux: %d %s %p\n", unit, muxsc->sc_dv.dv_xname,
|
|
|
|
muxsc->sc_displaydv));
|
|
|
|
if (unit < 0 || unit >= wskbd_cd.cd_ndevs ||
|
|
|
|
(sc = wskbd_cd.cd_devs[unit]) == NULL)
|
|
|
|
return (ENXIO);
|
|
|
|
|
|
|
|
if (sc->sc_mux || sc->sc_events.io)
|
|
|
|
return (EBUSY);
|
|
|
|
|
|
|
|
return (wsmux_attach_sc(muxsc, WSMUX_KBD, &sc->sc_dv, &sc->sc_events,
|
|
|
|
&sc->sc_mux, &wskbd_muxops));
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
wskbd_rem_mux(unit, muxsc)
|
|
|
|
int unit;
|
|
|
|
struct wsmux_softc *muxsc;
|
|
|
|
{
|
|
|
|
struct wskbd_softc *sc;
|
|
|
|
|
|
|
|
DPRINTF(("wskbd_rem_mux: %d %s\n", unit, muxsc->sc_dv.dv_xname));
|
|
|
|
if (unit < 0 || unit >= wskbd_cd.cd_ndevs ||
|
|
|
|
(sc = wskbd_cd.cd_devs[unit]) == NULL)
|
|
|
|
return (ENXIO);
|
|
|
|
|
|
|
|
return (wsmux_detach_sc(muxsc, &sc->sc_dv));
|
1998-03-22 17:24:02 +03:00
|
|
|
}
|
|
|
|
|
1999-05-14 20:01:11 +04:00
|
|
|
#endif /* NWSDISPLAY > 0 */
|
|
|
|
|
1998-03-22 17:24:02 +03:00
|
|
|
/*
|
|
|
|
* Console interface.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
wskbd_cngetc(dev)
|
|
|
|
dev_t dev;
|
|
|
|
{
|
1999-12-21 15:02:04 +03:00
|
|
|
static int num = 0;
|
|
|
|
static int pos;
|
1998-04-07 17:43:16 +04:00
|
|
|
u_int type;
|
|
|
|
int data;
|
1998-06-15 21:48:32 +04:00
|
|
|
keysym_t ks;
|
1998-03-22 17:24:02 +03:00
|
|
|
|
|
|
|
if (!wskbd_console_initted)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (wskbd_console_device != NULL &&
|
|
|
|
!wskbd_console_device->sc_translating)
|
|
|
|
return 0;
|
|
|
|
|
1998-06-15 21:48:32 +04:00
|
|
|
for(;;) {
|
1999-12-21 15:02:04 +03:00
|
|
|
if (num-- > 0) {
|
|
|
|
ks = wskbd_console_data.t_symbols[pos++];
|
|
|
|
if (KS_GROUP(ks) == KS_GROUP_Ascii)
|
|
|
|
return (KS_VALUE(ks));
|
|
|
|
} else {
|
|
|
|
(*wskbd_console_data.t_consops->getc)
|
|
|
|
(wskbd_console_data.t_consaccesscookie,
|
|
|
|
&type, &data);
|
|
|
|
num = wskbd_translate(&wskbd_console_data, type, data);
|
|
|
|
pos = 0;
|
|
|
|
}
|
1998-06-15 21:48:32 +04:00
|
|
|
}
|
1998-03-22 17:24:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
wskbd_cnpollc(dev, poll)
|
|
|
|
dev_t dev;
|
|
|
|
int poll;
|
|
|
|
{
|
|
|
|
|
|
|
|
if (!wskbd_console_initted)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (wskbd_console_device != NULL &&
|
|
|
|
!wskbd_console_device->sc_translating)
|
|
|
|
return;
|
|
|
|
|
1998-08-02 18:18:07 +04:00
|
|
|
(*wskbd_console_data.t_consops->pollc)
|
|
|
|
(wskbd_console_data.t_consaccesscookie, poll);
|
1998-03-22 17:24:02 +03:00
|
|
|
}
|
1998-04-07 17:43:16 +04:00
|
|
|
|
2000-03-07 00:37:16 +03:00
|
|
|
void
|
|
|
|
wskbd_cnbell(dev, pitch, period, volume)
|
|
|
|
dev_t dev;
|
|
|
|
u_int pitch, period, volume;
|
|
|
|
{
|
|
|
|
|
|
|
|
if (!wskbd_console_initted)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (wskbd_console_data.t_consops->bell != NULL)
|
|
|
|
(*wskbd_console_data.t_consops->bell)
|
|
|
|
(wskbd_console_data.t_consaccesscookie, pitch, period,
|
|
|
|
volume);
|
|
|
|
}
|
|
|
|
|
1998-04-07 17:43:16 +04:00
|
|
|
static inline void
|
1998-04-09 17:09:45 +04:00
|
|
|
update_leds(id)
|
|
|
|
struct wskbd_internal *id;
|
1998-04-07 17:43:16 +04:00
|
|
|
{
|
|
|
|
int new_state;
|
|
|
|
|
|
|
|
new_state = 0;
|
1998-04-09 17:09:45 +04:00
|
|
|
if (id->t_modifiers & (MOD_SHIFTLOCK | MOD_CAPSLOCK))
|
1998-04-07 17:43:16 +04:00
|
|
|
new_state |= WSKBD_LED_CAPS;
|
1998-04-09 17:09:45 +04:00
|
|
|
if (id->t_modifiers & MOD_NUMLOCK)
|
1998-04-07 17:43:16 +04:00
|
|
|
new_state |= WSKBD_LED_NUM;
|
1998-04-09 17:09:45 +04:00
|
|
|
if (id->t_modifiers & MOD_COMPOSE)
|
1998-04-07 17:43:16 +04:00
|
|
|
new_state |= WSKBD_LED_COMPOSE;
|
1998-04-09 17:09:45 +04:00
|
|
|
if (id->t_modifiers & MOD_HOLDSCREEN)
|
1998-04-07 17:43:16 +04:00
|
|
|
new_state |= WSKBD_LED_SCROLL;
|
|
|
|
|
1998-08-02 18:18:07 +04:00
|
|
|
if (id->t_sc && new_state != id->t_sc->sc_ledstate) {
|
|
|
|
(*id->t_sc->sc_accessops->set_leds)
|
|
|
|
(id->t_sc->sc_accesscookie, new_state);
|
|
|
|
id->t_sc->sc_ledstate = new_state;
|
1998-04-07 17:43:16 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
1998-04-09 17:09:45 +04:00
|
|
|
update_modifier(id, type, toggle, mask)
|
|
|
|
struct wskbd_internal *id;
|
1998-04-07 17:43:16 +04:00
|
|
|
u_int type;
|
|
|
|
int toggle;
|
|
|
|
int mask;
|
|
|
|
{
|
|
|
|
if (toggle) {
|
|
|
|
if (type == WSCONS_EVENT_KEY_DOWN)
|
1998-04-09 17:09:45 +04:00
|
|
|
id->t_modifiers ^= mask;
|
1998-04-07 17:43:16 +04:00
|
|
|
} else {
|
|
|
|
if (type == WSCONS_EVENT_KEY_DOWN)
|
1998-04-09 17:09:45 +04:00
|
|
|
id->t_modifiers |= mask;
|
1998-04-07 17:43:16 +04:00
|
|
|
else
|
1998-04-09 17:09:45 +04:00
|
|
|
id->t_modifiers &= ~mask;
|
1998-04-07 17:43:16 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-06-12 02:08:57 +04:00
|
|
|
static int
|
1998-04-07 17:43:16 +04:00
|
|
|
internal_command(sc, type, ksym)
|
|
|
|
struct wskbd_softc *sc;
|
|
|
|
u_int *type;
|
|
|
|
keysym_t ksym;
|
|
|
|
{
|
|
|
|
switch (ksym) {
|
|
|
|
case KS_Cmd:
|
1998-04-09 17:09:45 +04:00
|
|
|
update_modifier(sc->id, *type, 0, MOD_COMMAND);
|
1998-04-07 17:43:16 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case KS_Cmd1:
|
1998-04-09 17:09:45 +04:00
|
|
|
update_modifier(sc->id, *type, 0, MOD_COMMAND1);
|
1998-04-07 17:43:16 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case KS_Cmd2:
|
1998-04-09 17:09:45 +04:00
|
|
|
update_modifier(sc->id, *type, 0, MOD_COMMAND2);
|
1998-04-07 17:43:16 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*type != WSCONS_EVENT_KEY_DOWN ||
|
1998-04-09 17:09:45 +04:00
|
|
|
(! MOD_ONESET(sc->id, MOD_COMMAND) &&
|
|
|
|
! MOD_ALLSET(sc->id, MOD_COMMAND1 | MOD_COMMAND2)))
|
1998-06-12 02:08:57 +04:00
|
|
|
return (0);
|
1998-04-07 17:43:16 +04:00
|
|
|
|
|
|
|
switch (ksym) {
|
|
|
|
#ifdef DDB
|
|
|
|
case KS_Cmd_Debugger:
|
|
|
|
if (sc->sc_isconsole)
|
1999-01-26 20:08:37 +03:00
|
|
|
console_debugger();
|
1998-04-07 17:43:16 +04:00
|
|
|
/* discard this key (ddb discarded command modifiers) */
|
|
|
|
*type = WSCONS_EVENT_KEY_UP;
|
1998-06-12 02:08:57 +04:00
|
|
|
return (1);
|
1998-04-07 17:43:16 +04:00
|
|
|
#endif
|
|
|
|
|
1999-05-14 20:01:11 +04:00
|
|
|
#if NWSDISPLAY > 0
|
1998-04-07 17:43:16 +04:00
|
|
|
case KS_Cmd_Screen0:
|
|
|
|
case KS_Cmd_Screen1:
|
|
|
|
case KS_Cmd_Screen2:
|
|
|
|
case KS_Cmd_Screen3:
|
|
|
|
case KS_Cmd_Screen4:
|
|
|
|
case KS_Cmd_Screen5:
|
|
|
|
case KS_Cmd_Screen6:
|
|
|
|
case KS_Cmd_Screen7:
|
|
|
|
case KS_Cmd_Screen8:
|
|
|
|
case KS_Cmd_Screen9:
|
1998-06-12 02:08:57 +04:00
|
|
|
wsdisplay_switch(sc->sc_displaydv, ksym - KS_Cmd_Screen0, 0);
|
|
|
|
return (1);
|
1999-01-14 14:44:54 +03:00
|
|
|
case KS_Cmd_ResetEmul:
|
1999-01-17 18:59:17 +03:00
|
|
|
wsdisplay_reset(sc->sc_displaydv, WSDISPLAY_RESETEMUL);
|
|
|
|
return (1);
|
|
|
|
case KS_Cmd_ResetClose:
|
|
|
|
wsdisplay_reset(sc->sc_displaydv, WSDISPLAY_RESETCLOSE);
|
1999-01-14 14:44:54 +03:00
|
|
|
return (1);
|
1999-05-14 20:01:11 +04:00
|
|
|
#endif
|
1998-04-07 17:43:16 +04:00
|
|
|
}
|
1998-06-12 02:08:57 +04:00
|
|
|
return (0);
|
1998-04-07 17:43:16 +04:00
|
|
|
}
|
|
|
|
|
1999-12-21 15:02:04 +03:00
|
|
|
static int
|
1998-04-09 17:09:45 +04:00
|
|
|
wskbd_translate(id, type, value)
|
|
|
|
struct wskbd_internal *id;
|
1998-04-07 17:43:16 +04:00
|
|
|
u_int type;
|
|
|
|
int value;
|
|
|
|
{
|
1998-04-09 17:09:45 +04:00
|
|
|
struct wskbd_softc *sc = id->t_sc;
|
1998-04-07 17:43:16 +04:00
|
|
|
keysym_t ksym, res, *group;
|
1998-04-09 17:09:45 +04:00
|
|
|
struct wscons_keymap kpbuf, *kp;
|
1998-06-12 02:08:57 +04:00
|
|
|
int iscommand = 0;
|
1998-04-07 17:43:16 +04:00
|
|
|
|
1998-09-17 22:05:43 +04:00
|
|
|
if (type == WSCONS_EVENT_ALL_KEYS_UP) {
|
|
|
|
id->t_modifiers &= ~(MOD_SHIFT_L | MOD_SHIFT_R
|
|
|
|
| MOD_CONTROL_L | MOD_CONTROL_R
|
|
|
|
| MOD_META_L | MOD_META_R
|
|
|
|
| MOD_MODESHIFT
|
|
|
|
| MOD_COMMAND | MOD_COMMAND1 | MOD_COMMAND2);
|
|
|
|
update_leds(id);
|
1999-12-21 15:02:04 +03:00
|
|
|
return (0);
|
1998-09-17 22:05:43 +04:00
|
|
|
}
|
|
|
|
|
1998-04-09 17:09:45 +04:00
|
|
|
if (sc != NULL) {
|
|
|
|
if (value < 0 || value >= sc->sc_maplen) {
|
1998-04-07 17:43:16 +04:00
|
|
|
#ifdef DEBUG
|
1998-04-09 17:09:45 +04:00
|
|
|
printf("wskbd_translate: keycode %d out of range\n",
|
|
|
|
value);
|
1998-04-07 17:43:16 +04:00
|
|
|
#endif
|
1999-12-21 15:02:04 +03:00
|
|
|
return (0);
|
1998-04-09 17:09:45 +04:00
|
|
|
}
|
|
|
|
kp = sc->sc_map + value;
|
|
|
|
} else {
|
|
|
|
kp = &kpbuf;
|
1998-08-02 18:18:07 +04:00
|
|
|
wskbd_get_mapentry(id->t_keymap, value, kp);
|
1998-04-07 17:43:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* if this key has a command, process it first */
|
1998-04-09 17:09:45 +04:00
|
|
|
if (sc != NULL && kp->command != KS_voidSymbol)
|
1998-06-12 02:08:57 +04:00
|
|
|
iscommand = internal_command(sc, &type, kp->command);
|
1998-04-07 17:43:16 +04:00
|
|
|
|
|
|
|
/* Now update modifiers */
|
|
|
|
switch (kp->group1[0]) {
|
|
|
|
case KS_Shift_L:
|
1998-04-09 17:09:45 +04:00
|
|
|
update_modifier(id, type, 0, MOD_SHIFT_L);
|
1998-04-07 17:43:16 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case KS_Shift_R:
|
1998-04-09 17:09:45 +04:00
|
|
|
update_modifier(id, type, 0, MOD_SHIFT_R);
|
1998-04-07 17:43:16 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case KS_Shift_Lock:
|
1998-04-09 17:09:45 +04:00
|
|
|
update_modifier(id, type, 1, MOD_SHIFTLOCK);
|
1998-04-07 17:43:16 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case KS_Caps_Lock:
|
1998-04-09 17:09:45 +04:00
|
|
|
update_modifier(id, type, 1, MOD_CAPSLOCK);
|
1998-04-07 17:43:16 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case KS_Control_L:
|
1998-04-09 17:09:45 +04:00
|
|
|
update_modifier(id, type, 0, MOD_CONTROL_L);
|
1998-04-07 17:43:16 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case KS_Control_R:
|
1998-04-09 17:09:45 +04:00
|
|
|
update_modifier(id, type, 0, MOD_CONTROL_R);
|
1998-04-07 17:43:16 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case KS_Alt_L:
|
1998-04-09 17:09:45 +04:00
|
|
|
update_modifier(id, type, 0, MOD_META_L);
|
1998-04-07 17:43:16 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case KS_Alt_R:
|
1998-04-09 17:09:45 +04:00
|
|
|
update_modifier(id, type, 0, MOD_META_R);
|
1998-04-07 17:43:16 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case KS_Mode_switch:
|
1998-04-09 17:09:45 +04:00
|
|
|
update_modifier(id, type, 0, MOD_MODESHIFT);
|
1998-04-07 17:43:16 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case KS_Num_Lock:
|
1998-04-09 17:09:45 +04:00
|
|
|
update_modifier(id, type, 1, MOD_NUMLOCK);
|
1998-04-07 17:43:16 +04:00
|
|
|
break;
|
|
|
|
|
1999-05-14 20:01:11 +04:00
|
|
|
#if NWSDISPLAY > 0
|
1998-04-07 17:43:16 +04:00
|
|
|
case KS_Hold_Screen:
|
1998-04-09 17:09:45 +04:00
|
|
|
if (sc != NULL) {
|
|
|
|
update_modifier(id, type, 1, MOD_HOLDSCREEN);
|
|
|
|
wskbd_holdscreen(sc, id->t_modifiers & MOD_HOLDSCREEN);
|
|
|
|
}
|
1998-04-07 17:43:16 +04:00
|
|
|
break;
|
1999-05-14 20:01:11 +04:00
|
|
|
#endif
|
1998-04-07 17:43:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* If this is a key release or we are in command mode, we are done */
|
1998-06-12 02:08:57 +04:00
|
|
|
if (type != WSCONS_EVENT_KEY_DOWN || iscommand) {
|
1998-04-09 17:09:45 +04:00
|
|
|
update_leds(id);
|
1999-12-21 15:02:04 +03:00
|
|
|
return (0);
|
1998-04-07 17:43:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the keysym */
|
1998-04-09 17:09:45 +04:00
|
|
|
if (id->t_modifiers & MOD_MODESHIFT)
|
1998-04-07 17:43:16 +04:00
|
|
|
group = & kp->group2[0];
|
|
|
|
else
|
|
|
|
group = & kp->group1[0];
|
|
|
|
|
1998-04-09 17:09:45 +04:00
|
|
|
if ((id->t_modifiers & MOD_NUMLOCK) != 0 &&
|
1998-04-07 17:43:16 +04:00
|
|
|
KS_GROUP(group[1]) == KS_GROUP_Keypad) {
|
1998-04-09 17:09:45 +04:00
|
|
|
if (MOD_ONESET(id, MOD_ANYSHIFT))
|
1998-04-07 17:43:16 +04:00
|
|
|
ksym = group[0];
|
|
|
|
else
|
|
|
|
ksym = group[1];
|
1998-04-09 17:09:45 +04:00
|
|
|
} else if (! MOD_ONESET(id, MOD_ANYSHIFT | MOD_CAPSLOCK)) {
|
1998-04-07 17:43:16 +04:00
|
|
|
ksym = group[0];
|
1998-04-09 17:09:45 +04:00
|
|
|
} else if (MOD_ONESET(id, MOD_CAPSLOCK)) {
|
|
|
|
if (! MOD_ONESET(id, MOD_SHIFT_L | MOD_SHIFT_R))
|
1998-04-07 17:43:16 +04:00
|
|
|
ksym = group[0];
|
|
|
|
else
|
|
|
|
ksym = group[1];
|
|
|
|
if (ksym >= KS_a && ksym <= KS_z)
|
|
|
|
ksym += KS_A - KS_a;
|
|
|
|
else if (ksym >= KS_agrave && ksym <= KS_thorn &&
|
|
|
|
ksym != KS_division)
|
|
|
|
ksym += KS_Agrave - KS_agrave;
|
1998-04-09 17:09:45 +04:00
|
|
|
} else if (MOD_ONESET(id, MOD_ANYSHIFT)) {
|
1998-04-07 17:43:16 +04:00
|
|
|
ksym = group[1];
|
|
|
|
} else {
|
|
|
|
ksym = group[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Process compose sequence and dead accents */
|
|
|
|
res = KS_voidSymbol;
|
|
|
|
|
|
|
|
switch (KS_GROUP(ksym)) {
|
|
|
|
case KS_GROUP_Ascii:
|
|
|
|
case KS_GROUP_Keypad:
|
|
|
|
case KS_GROUP_Function:
|
|
|
|
res = ksym;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case KS_GROUP_Mod:
|
|
|
|
if (ksym == KS_Multi_key) {
|
1998-04-09 17:09:45 +04:00
|
|
|
update_modifier(id, 1, 0, MOD_COMPOSE);
|
|
|
|
id->t_composelen = 2;
|
1998-04-07 17:43:16 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case KS_GROUP_Dead:
|
1998-04-09 17:09:45 +04:00
|
|
|
if (id->t_composelen == 0) {
|
|
|
|
update_modifier(id, 1, 0, MOD_COMPOSE);
|
|
|
|
id->t_composelen = 1;
|
|
|
|
id->t_composebuf[0] = ksym;
|
1998-04-07 17:43:16 +04:00
|
|
|
} else
|
|
|
|
res = ksym;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (res == KS_voidSymbol) {
|
1998-04-09 17:09:45 +04:00
|
|
|
update_leds(id);
|
1999-12-21 15:02:04 +03:00
|
|
|
return (0);
|
1998-04-07 17:43:16 +04:00
|
|
|
}
|
|
|
|
|
1998-04-09 17:09:45 +04:00
|
|
|
if (id->t_composelen > 0) {
|
|
|
|
id->t_composebuf[2 - id->t_composelen] = res;
|
|
|
|
if (--id->t_composelen == 0) {
|
|
|
|
res = wskbd_compose_value(id->t_composebuf);
|
|
|
|
update_modifier(id, 0, 0, MOD_COMPOSE);
|
1998-04-07 17:43:16 +04:00
|
|
|
} else {
|
1999-12-21 15:02:04 +03:00
|
|
|
return (0);
|
1998-04-07 17:43:16 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-04-09 17:09:45 +04:00
|
|
|
update_leds(id);
|
1998-04-07 17:43:16 +04:00
|
|
|
|
1998-06-15 21:48:32 +04:00
|
|
|
/* We are done, return the symbol */
|
1998-04-07 17:43:16 +04:00
|
|
|
if (KS_GROUP(res) == KS_GROUP_Ascii) {
|
1998-04-09 17:09:45 +04:00
|
|
|
if (MOD_ONESET(id, MOD_ANYCONTROL)) {
|
1998-04-07 17:43:16 +04:00
|
|
|
if ((res >= KS_at && res <= KS_z) || res == KS_space)
|
|
|
|
res = res & 0x1f;
|
|
|
|
else if (res == KS_2)
|
|
|
|
res = 0x00;
|
|
|
|
else if (res >= KS_3 && res <= KS_7)
|
|
|
|
res = KS_Escape + (res - KS_3);
|
|
|
|
else if (res == KS_8)
|
|
|
|
res = KS_Delete;
|
|
|
|
}
|
1999-12-21 15:02:04 +03:00
|
|
|
if (MOD_ONESET(id, MOD_ANYMETA)) {
|
|
|
|
if (id->t_flags & WSKFL_METAESC) {
|
|
|
|
id->t_symbols[0] = KS_Escape;
|
|
|
|
id->t_symbols[1] = res;
|
|
|
|
return (2);
|
|
|
|
} else
|
|
|
|
res |= 0x80;
|
|
|
|
}
|
1998-04-07 17:43:16 +04:00
|
|
|
}
|
|
|
|
|
1999-12-21 15:02:04 +03:00
|
|
|
id->t_symbols[0] = res;
|
|
|
|
return (1);
|
1998-04-07 17:43:16 +04:00
|
|
|
}
|