Subject: XFree keyboard handling
To: None <tech-x11@NetBSD.org>
From: Martin Husemann <martin@duskware.de>
List: tech-x11
Date: 05/17/2005 21:56:55
--HcAYCG3uE/tztfnV
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

I got lost inside the XFree86 server - if anyone can turn on some guiding
lights, that would be great.

The sparc64 XFree86 server works fine, as long as you have something
like

 Option "Protocol" "wskbd"
 Option "Device" "/dev/wskbd0

in your /etc/XF86Config.

For completeness, and since it is the default install resulting from
X -configure, I tried to make raw keyboard mode work.

There is a strange maze of duplicate code in xfree86/os-support/bsd - 
the bsd_kbd.c stuff (modulo a few missing WSKBD_TYPE_SUN5 cases) seems
to have code to deal with raw sun scancodes, but this code is apparently
not used by the XFree86 server.

On the other hand, bsd_io.c is used and originally had no provisions for sun
raw scancodes (via wscons). It delivers the keyboard input via
xf86PostKbdEvent, which does not look like doing something sane in the
"kbdSun = 1" case, and indeed the resulting server does not understand key
presses.

In the current state, I think I'll just remvoe the COMPAT_RAWKBD option
from the default kernels, which causes the X -configure run to print a
proper hint about the keyboard options needed.

Hints apreciated,

Martin

--HcAYCG3uE/tztfnV
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="xfree.patch"

Index: common/xf86Events.c
===================================================================
RCS file: /cvsroot/xsrc/xfree/xc/programs/Xserver/hw/xfree86/common/xf86Events.c,v
retrieving revision 1.5
diff -u -p -r1.5 xf86Events.c
--- common/xf86Events.c	18 Mar 2005 14:55:14 -0000	1.5
+++ common/xf86Events.c	17 May 2005 19:44:46 -0000
@@ -467,7 +467,7 @@ xf86PostKbdEvent(unsigned key)
 #if defined(SYSCONS_SUPPORT) || defined(PCVT_SUPPORT) || defined(WSCONS_SUPPORT)
   static Bool first_time = TRUE;
 #endif
-#if defined(__sparc__) && (defined(__linux__) || defined(__FreeBSD__))
+#if defined(__sparc__) && (defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__))
   static int  kbdSun = -1;
 #endif
   /* Disable any keyboard processing while in suspend */
@@ -483,17 +483,21 @@ xf86PostKbdEvent(unsigned key)
   }
 #endif
 
-#if defined(__sparc__) && (defined(__linux__) || defined(__FreeBSD__))
+#if defined(__sparc__) && (defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__))
   if (kbdSun == -1) {
+#ifdef __NetBSD__
+    if (xf86Info.wsKbdType == WSKBD_TYPE_SUN || xf86Info.wsKbdType == WSKBD_TYPE_SUN5)
+#else
     if ((xf86Info.xkbmodel && !strcmp(xf86Info.xkbmodel, "sun"))
 	|| (xf86Info.xkbrules && !strcmp(xf86Info.xkbrules, "sun")))
+#endif
       kbdSun = 1;
     else
       kbdSun = 0;
   }
   if (kbdSun)
     goto special;
-#endif /* __sparc__ && (__linux__ || __FreeBSD__) */
+#endif /* __sparc__ && (__linux__ || __FreeBSD__ || __NetBSD__) */
 
 #ifdef __linux__
   if (xf86Info.kbdCustomKeycodes) {
@@ -695,7 +699,7 @@ customkeycodes:
     }
   }
 #endif
-#if defined(__sparc__) && (defined(__linux__) || defined(__FreeBSD__))
+#if defined(__sparc__) && (defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__))
 special:
   if (kbdSun) {
     switch (scanCode) {
@@ -729,7 +733,7 @@ special:
      */
     scanCode--;
   }
-#endif /* __sparc__ && (__linux__ || __FreeBSD__) */
+#endif /* __sparc__ && (__linux__ || __FreeBSD__ || __NetBSD__) */
 
 #ifdef XKB
   if ((xf86Info.ddxSpecialKeys == SKWhenNeeded &&
Index: os-support/bsd/bsd_KbdMap.c
===================================================================
RCS file: /cvsroot/xsrc/xfree/xc/programs/Xserver/hw/xfree86/os-support/bsd/bsd_KbdMap.c,v
retrieving revision 1.2
diff -u -p -r1.2 bsd_KbdMap.c
--- os-support/bsd/bsd_KbdMap.c	11 Nov 2004 19:16:33 -0000	1.2
+++ os-support/bsd/bsd_KbdMap.c	17 May 2005 19:44:47 -0000
@@ -1065,6 +1065,11 @@ KbdGetMapping (InputInfoPtr pInfo, KeySy
                     pKbd->scancodeMap = &wsSun;
                     break;
 #endif
+#ifdef WSKBD_TYPE_SUN5
+	       case WSKBD_TYPE_SUN5:
+                    pKbd->scancodeMap = &wsSun;
+                    break;
+#endif
 	       default:
                     pKbd->RemapScanCode = ATScancode;
                     break;
Index: os-support/bsd/bsd_io.c
===================================================================
RCS file: /cvsroot/xsrc/xfree/xc/programs/Xserver/hw/xfree86/os-support/bsd/bsd_io.c,v
retrieving revision 1.5
diff -u -p -r1.5 bsd_io.c
--- os-support/bsd/bsd_io.c	28 Feb 2003 21:49:42 -0000	1.5
+++ os-support/bsd/bsd_io.c	17 May 2005 19:44:47 -0000
@@ -170,6 +170,14 @@ xf86KbdInit()
 	}
 }
 
+#ifdef WSCONS_SUPPORT
+static void
+printWsType(char *type)
+{
+    xf86Msg(X_PROBED, "Keyboard type: %s\n", type); 
+}
+#endif
+
 int
 xf86KbdOn()
 {
@@ -223,6 +231,38 @@ xf86KbdOn()
 					"Option \"Protocol\" \"wskbd\"\n"
 					"Option \"Device\" \"/dev/wskbd0\"\n"
 					"\nin your XF86Config(5) file\n");
+			if (ioctl(xf86Info.consoleFd, WSKBDIO_GTYPE,
+					&xf86Info.wsKbdType) == -1)
+				FatalError("can't query keyboard type.\n");
+			switch (xf86Info.wsKbdType) {
+		           case WSKBD_TYPE_PC_XT:
+		               printWsType("XT");
+		               break;
+		           case WSKBD_TYPE_PC_AT:
+		               printWsType("AT");
+		               break;
+		           case WSKBD_TYPE_USB:
+		               printWsType("USB");
+		               break;
+#ifdef WSKBD_TYPE_ADB
+		           case WSKBD_TYPE_ADB:
+		               printWsType("ADB");
+		               break;
+#endif
+#ifdef WSKBD_TYPE_SUN
+		           case WSKBD_TYPE_SUN:
+		               printWsType("Sun");
+		               break;
+#endif
+#ifdef WSKBD_TYPE_SUN5
+		           case WSKBD_TYPE_SUN5:
+		               printWsType("Sun5");
+		               break;
+#endif
+		           default:
+			       printWsType("Unknown");
+			       break;
+		       }
 		} else {
 			return xf86Info.kbdFd;
 		}
Index: os-support/bsd/bsd_kbd.c
===================================================================
RCS file: /cvsroot/xsrc/xfree/xc/programs/Xserver/hw/xfree86/os-support/bsd/bsd_kbd.c,v
retrieving revision 1.2
diff -u -p -r1.2 bsd_kbd.c
--- os-support/bsd/bsd_kbd.c	11 Nov 2004 19:16:33 -0000	1.2
+++ os-support/bsd/bsd_kbd.c	17 May 2005 19:44:47 -0000
@@ -495,6 +495,11 @@ OpenKeyboard(InputInfoPtr pInfo)
                printWsType("Sun", pInfo->name);
                break;
 #endif
+#ifdef WSKBD_TYPE_SUN5
+           case WSKBD_TYPE_SUN5:
+               printWsType("Sun5", pInfo->name);
+               break;
+#endif
            default:
 	       printWsType("Unknown", pInfo->name);
 	       break;

--HcAYCG3uE/tztfnV--