Add support for CapsLock and NumLock toggles.

This commit is contained in:
gwr 1996-02-29 19:32:14 +00:00
parent f1938eb0d0
commit 99e8401680
3 changed files with 94 additions and 37 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: kbd.c,v 1.3 1996/02/19 04:36:13 gwr Exp $ */
/* $NetBSD: kbd.c,v 1.4 1996/02/29 19:32:14 gwr Exp $ */
/*
* Copyright (c) 1992, 1993
@ -64,7 +64,6 @@
#include <sys/conf.h>
#include <sys/file.h>
#include <sys/ioctl.h>
/* #include <sys/tty.h> */
#include <sys/time.h>
#include <sys/kernel.h>
#include <sys/syslog.h>
@ -168,16 +167,15 @@ struct kbd_softc {
};
/* Prototypes */
void kbd_ascii(struct tty *);
void kbd_serial(struct tty *, void (*)(), void (*)());
int kbd_iopen(int unit);
void kbd_was_reset(struct kbd_softc *);
void kbd_new_layout(struct kbd_softc *);
void kbd_rint(int);
int kbd_docmd(struct kbd_softc *k, int cmd);
int kbd_iopen(int unit);
void kbd_new_layout(struct kbd_softc *k);
void kbd_output(struct kbd_softc *k, int c);
void kbd_start_tx(struct kbd_softc *k);
void kbd_repeat(void *arg);
void kbd_set_leds(struct kbd_softc *k, int leds);
void kbd_start_tx(struct kbd_softc *k);
void kbd_update_leds(struct kbd_softc *k);
void kbd_was_reset(struct kbd_softc *k);
extern void kd_input(int ascii);
@ -455,7 +453,8 @@ kbdioctl(dev, cmd, data, flag, p)
break;
case KIOCSLED:
error = kbd_set_leds(k, data);
error = kbd_drain_tx(k);
kbd_set_leds(k, *(int *)data);
break;
case KIOCGLED:
@ -618,24 +617,40 @@ kbd_code_to_keysym(ks, c)
*/
if (KEY_UP(c))
km = ks->kbd_k.k_release;
else {
if (ks->kbd_modbits & KBMOD_CTRL_MASK)
km = ks->kbd_k.k_control;
else {
if (ks->kbd_modbits & KBMOD_SHIFT_MASK)
km = ks->kbd_k.k_shifted;
else
km = ks->kbd_k.k_normal;
}
}
else if (ks->kbd_modbits & KBMOD_CTRL_MASK)
km = ks->kbd_k.k_control;
else if (ks->kbd_modbits & KBMOD_SHIFT_MASK)
km = ks->kbd_k.k_shifted;
else
km = ks->kbd_k.k_normal;
if (km == NULL) {
/*
* Do not know how to translate yet.
* We will find out when a RESET comes along.
*/
keysym = KEYSYM_NOP;
} else
keysym = km->keymap[KEY_CODE(c)];
return (KEYSYM_NOP);
}
keysym = km->keymap[KEY_CODE(c)];
/*
* Post-processing for Caps-lock
*/
if ((ks->kbd_modbits & (1 << KBMOD_CAPSLOCK)) &&
(KEYSYM_CLASS(keysym) == KEYSYM_ASCII) )
{
if (('a' <= keysym) && (keysym <= 'z'))
keysym -= ('a' - 'A');
}
/*
* Post-processing for Num-lock
*/
if ((ks->kbd_modbits & (1 << KBMOD_NUMLOCK)) &&
(KEYSYM_CLASS(keysym) == KEYSYM_FUNC) )
{
keysym = kbd_numlock_map[keysym & 0x3F];
}
return (keysym);
}
@ -679,10 +694,9 @@ kbd_input_keysym(k, keysym)
register int keysym;
{
struct kbd_state *ks = &k->k_state;
register int class, data;
register int data;
class = KEYSYM_CLASS(keysym);
switch (class) {
switch (KEYSYM_CLASS(keysym)) {
case KEYSYM_ASCII:
data = KEYSYM_DATA(keysym);
@ -713,6 +727,7 @@ kbd_input_keysym(k, keysym)
case KEYSYM_INVMOD:
data = 1 << (keysym & 0x1F);
ks->kbd_modbits ^= data;
kbd_update_leds(k);
break;
case KEYSYM_ALL_UP:
@ -1268,17 +1283,14 @@ out:
}
int
kbd_set_leds(k, data)
void
kbd_set_leds(k, new_leds)
struct kbd_softc *k;
caddr_t data;
int new_leds;
{
struct kbd_state *ks = &k->k_state;
int error, s;
char new_leds;
int s;
error = 0;
new_leds = *(char*)data;
s = spltty();
/* Don't send unless state changes. */
@ -1290,14 +1302,30 @@ kbd_set_leds(k, data)
if (ks->kbd_id < 4)
goto out;
error = kbd_drain_tx(k);
kbd_output(k, KBD_CMD_SETLED);
kbd_output(k, new_leds);
kbd_start_tx(k);
out:
splx(s);
return(error);
}
void
kbd_update_leds(k)
struct kbd_softc *k;
{
struct kbd_state *ks = &k->k_state;
register char leds;
leds = ks->kbd_leds;
leds &= ~(LED_CAPS_LOCK|LED_NUM_LOCK);
if (ks->kbd_modbits & (1 << KBMOD_CAPSLOCK))
leds |= LED_CAPS_LOCK;
if (ks->kbd_modbits & (1 << KBMOD_NUMLOCK))
leds |= LED_NUM_LOCK;
kbd_set_leds(k, leds);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: kbd_tables.c,v 1.1.1.1 1996/01/24 01:15:35 gwr Exp $ */
/* $NetBSD: kbd_tables.c,v 1.2 1996/02/29 19:32:18 gwr Exp $ */
/*
* Copyright (c) 1996 Gordon W. Ross
@ -872,6 +872,33 @@ char kbd_stringtab[16][10] = {
{ 0x1b, '[', 'C', 0 }, /* Right */
};
/*
* The "NumLock" map, which is used to remap
* function keysyms when NumLock is on.
*/
unsigned short kbd_numlock_map[64] = {
/* KEYSYM_FUNC_L: Identity map */
0x600, 0x601, 0x602, 0x603, 0x604, 0x605, 0x606, 0x607,
0x608, 0x609, 0x60a, 0x60b, 0x60c, 0x60d, 0x60e, 0x60f,
/* KEYSYM_FUNC_R: remap to numbers... */
0x610, 0x611, 0x612,
'=', '/', '*',
'7', '8', '9',
'4', '5', '6',
'1', '2', '3',
0x61f,
/* KEYSYM_FUNC_F: Identity map */
0x620, 0x621, 0x622, 0x623, 0x624, 0x625, 0x626, 0x627,
0x628, 0x629, 0x62a, 0x62b, 0x62c, 0x62d, 0x62e, 0x62f,
/* KEYSYM_FUNC_N: remap just a few... */
0x630, 0x631, 0x632, 0x633, 0x634, 0x635, 0x636, '0',
0x638, '.', '\r', 0x63b, 0x63c, '+', '-', 0x63f,
};
/*
* Keyboard descriptions for each type.
*/

View File

@ -1,4 +1,4 @@
/* $NetBSD: kbd_tables.h,v 1.1.1.1 1996/01/24 01:15:35 gwr Exp $ */
/* $NetBSD: kbd_tables.h,v 1.2 1996/02/29 19:32:20 gwr Exp $ */
/*
* Copyright (c) 1996 Gordon W. Ross
@ -142,6 +142,8 @@ struct keyboard {
};
extern char kbd_stringtab[16][10];
extern unsigned short kbd_numlock_map[64];
extern struct keyboard * keyboards[];
extern int kbd_max_type;
#define KBD_MIN_TYPE 2