Subject: port-sparc/956: enhancement to make kbd LEDs work with X windows; patch incl.
To: None <gnats-admin@NetBSD.ORG>
From: Lon Willett <willett@math.utah.edu>
List: netbsd-bugs
Date: 04/11/1995 08:05:05
>Number:         956
>Category:       port-sparc
>Synopsis:       enhancement to make kbd LEDs work with X windows; patch incl.
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    gnats-admin (GNATS administrator)
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Tue Apr 11 08:05:03 1995
>Originator:     Lon Willett
>Organization:
none
>Release:        7 Apr 95
>Environment:

System: NetBSD holly 1.0A NetBSD 1.0A (HOLLY) #6: Sun Apr 9 16:20:31 MDT 1995 lon@holly:/usr/src/sys/arch/sparc/compile/HOLLY sparc

>Description:

	I was annoyed at the lack of kbd LED functionality (with X
	windows), so I added it.

>How-To-Repeat:

	Obvious.  Note that X internally sets "Num-Lock", "Caps-Lock",
	etc, and doesn't worry about the fact that you can't see them.
	This can be confusing.

>Fix:

	This little patch makes type 4 keyboard LEDs work (with X windows).
	I didn't bother adding support for type 2 or 3 kbds (and wouldn't
	have any way to try testing it if I had).  I also didn't bother
	trying to enhance the bare console functionality to use caps-lock,
	etc.

--- src/sys/arch/sparc/include/kbd.h.orig	Mon Nov 21 15:42:06 1994
+++ src/sys/arch/sparc/include/kbd.h	Sun Apr  9 05:54:04 1995
@@ -52,3 +52,9 @@
 #define	KBD_CMD_NOBELL	3		/* turn bell off */
 #define	KBD_CMD_CLICK	10		/* turn keyclick on */
 #define	KBD_CMD_NOCLICK	11		/* turn keyclick off */
+#define	KBD_CMD_SETLED	14		/* set LED state (type 4 kbd) */
+
+#define	LED_NUM_LOCK    0x1
+#define	LED_COMPOSE     0x2
+#define	LED_SCROLL_LOCK 0x4
+#define	LED_CAPS_LOCK   0x8
--- src/sys/arch/sparc/include/kbio.h.orig	Mon Nov 21 15:42:07 1994
+++ src/sys/arch/sparc/include/kbio.h	Sun Apr  9 05:55:30 1995
@@ -56,6 +56,8 @@
 #define	KIOCCMD		_IOW('k', 8, int)	/* X uses this to ring bell */
 #define	KIOCTYPE	_IOR('k', 9, int)	/* get keyboard type */
 #define	KIOCSDIRECT	_IOW('k', 10, int)	/* keys to console? */
+#define	KIOCSLED        _IOW('k', 14, char)	/* set LED state */
+#define	KIOCGLED        _IOR('k', 15, char)	/* get LED state */
 #define	KIOCLAYOUT	_IOR('k', 20, int)	/* get keyboard layout */
 
 #define	TR_NONE			0	/* X compat, unsupported */
--- src/sys/arch/sparc/dev/kbd.c.orig	Mon Nov 21 15:41:41 1994
+++ src/sys/arch/sparc/dev/kbd.c	Sun Apr  9 16:19:57 1995
@@ -164,6 +164,7 @@
 	char	kbd_click;	/* true => keyclick enabled */
 	char	kbd_takeid;	/* take next byte as ID */
 	u_char	kbd_id;		/* a place to store the ID */
+	char	kbd_leds;	/* LED state */
 };
 
 /*
@@ -297,6 +298,8 @@
 			(void) kbd_docmd(KBD_CMD_CLICK, 0);
 		break;
 	}
+
+	ks->kbd_leds = 0;
 }
 
 /*
@@ -574,6 +577,32 @@
 
 	case KIOCSDIRECT:
 		k->k_evmode = *(int *)data;
+		return (0);
+
+	case KIOCSLED:
+		if (k->k_state.kbd_id != KB_SUN4) {
+			/* xxx NYI */
+			k->k_state.kbd_leds = *(char*)data;
+		} else {
+			int s;
+			char leds = *(char *)data;
+			struct tty *tp = kbd_softc.k_kbd;
+			s = spltty();
+			if (tp->t_outq.c_cc > 120)
+				(void) tsleep((caddr_t)&lbolt, TTIPRI,
+					      ttyout, 0);
+			splx(s);
+			if (ttyoutput(KBD_CMD_SETLED, tp) >= 0)
+				return (ENOSPC);	/* ERESTART? */
+			k->k_state.kbd_leds = leds;
+			if (ttyoutput(leds, tp) >= 0)
+				return (ENOSPC);	/* ERESTART? */
+			(*tp->t_oproc)(tp);
+		}
+		return (0);
+
+	case KIOCGLED:
+		*(char *)data = k->k_state.kbd_leds;
 		return (0);
 
 	case KIOCLAYOUT:
------------------------------------------------------------------------
>Audit-Trail:
>Unformatted: