From: khera@cs.duke.edu (Vivek Khera)
Newsgroups: comp.windows.x
Subject: Re: How to enable Num Lock under X ?
Date: 12 Aug 92 15:41:00 GMT
Organization: Duke University CS Dept., Durham, NC
In-reply-to: ravi@wwtc.timeplex.COM's message of 10 Aug 92 04:07:40 GMT
X-Md4-Signature: 88b585227dd2f5a37779748dc79182ed

In article <9208100407.AA01920@wwtc.timeplex.com> ravi@wwtc.timeplex.COM (ravikumar) writes:

   Hi xperts,

	   How do I enable Num Lock( LED and the function) ??
   I am using Sparc 1+ , X and Motif1.1.1

   I am aware that I may have to use 'xmodmap' but how ??

you need to apply the following patch to your X11R5 Xsun server.
works quite well.


(Message patches:3)
From: brendan@cs.widener.edu (Brendan Kehoe)
Newsgroups: comp.windows.x
Subject: Enabling NumLock & the keypad on Suns under R5
Date: 18 Oct 91 02:13:26 GMT
Organization: Widener University Computer Science Dept, Chester PA
NNTP-Posting-Host: wilma.cs.widener.edu


 This patch will make the NumLock key work on Sun4 keyboards under
X11R5 (as of fix #3, but I don't think it'll make a huge difference if
you haven't applied all 3 fixes yet).  It's based on the same kind of
hack for X11R4 by Viktor Dukhovni (slcpi!viktor).

 I applied them to a fresh copy of R5 at fix 3 and have had it running
for over a week now without trouble.  (The only thing it changes is
the server.)

 Any suggestions on how to better implement this facility are
certainly welcome!

 Feed these changes into patch(1) above the mit directory, then do
`make Everything'.

Brendan Kehoe (brendan@cs.widener.edu)

-- cut --
*** mit/server/ddx/sun/sunKbd.c-orig	Wed Oct  9 21:54:57 1991
--- mit/server/ddx/sun/sunKbd.c	Thu Oct 10 16:16:56 1991
***************
*** 92,97 ****
--- 92,109 ----
      0,				/* lock state */
  };
  
+ #ifdef SUN_NUMHACK
+ /*
+  * The following table is the list of scancodes for keys affected by
+  * the numlock switch.  The order MUST match the order of simulated
+  * numlock keys defined at the end of the keymap in sunKeyMap.c
+  */
+ static char		numlock_keys[] = {
+     0x2d, 0x2e, 0x2f, 0x32, 0x44, 0x45, 0x46, 0x47, 0x5a,
+     0x5b, 0x5c, 0x5d, 0x5e, 0x70, 0x71, 0x72, 0x7d, 0x00
+ };
+ #endif
+ 
  /*-
   *-----------------------------------------------------------------------
   * sunKbdProc --
***************
*** 425,431 ****
  {
      KbPrivPtr	  pPriv = (KbPrivPtr) pKeyboard->devicePrivate;
      int	 	  kbdOpenedHere; 
-     char	  led;
      int		  i;
  
      kbdOpenedHere = ( pPriv->fd < 0 );
--- 437,442 ----
***************
*** 465,478 ****
      }
  }
  
  sunKbdLockLight (pKeyboard, on)
      DevicePtr	pKeyboard;
      Bool	on;
  {
      KbPrivPtr	pPriv = (KbPrivPtr) pKeyboard->devicePrivate;
-     KeybdCtrl	ctrl;
  
!     pPriv->lockLight = on;
      sunKbdSetLights (pKeyboard);
  }
  
--- 476,505 ----
      }
  }
  
+ #ifdef SUN_NUMHACK
+ sunKbdLockLight (pKeyboard, on, isnumlock)
+ #else
  sunKbdLockLight (pKeyboard, on)
+ #endif
      DevicePtr	pKeyboard;
      Bool	on;
+ #ifdef SUN_NUMHACK
+     Bool	isnumlock;
+ #endif
  {
      KbPrivPtr	pPriv = (KbPrivPtr) pKeyboard->devicePrivate;
  
! #ifdef SUN_NUMHACK
!     if (isnumlock) {
!       /* There has to be some snazzy way to do this.  */
!       if (on)
! 	pPriv->ctrl->leds |= 0x04;
!       else
! 	pPriv->ctrl->leds &= ~0x04;
!     } else
! #endif
!       pPriv->lockLight = on;
! 
      sunKbdSetLights (pKeyboard);
  }
  
***************
*** 547,557 ****
  {
      xEvent		xE;
      KbPrivPtr		pPriv;
-     int			delta;
      BYTE		key;
      CARD8		keyModifiers;
  
!     key = (fe->id & 0x7F) + sysKbPriv.offset;
      keyModifiers = ((DeviceIntPtr)pKeyboard)->key->modifierMap[key];
      if (autoRepeatKeyDown && (keyModifiers == 0) &&
  	((fe->value == VKEY_DOWN) || (key == autoRepeatEvent.u.u.detail))) {
--- 574,600 ----
  {
      xEvent		xE;
      KbPrivPtr		pPriv;
      BYTE		key;
      CARD8		keyModifiers;
  
! #ifdef SUN_NUMHACK
! #define NUM_LOCK_CODE	(0x61+MIN_KEYCODE)
! 
!     fe->id &= 0x7f;
!     pPriv = (KbPrivPtr) pKeyboard->devicePrivate;
!     if (pPriv->type == KB_SUN4 &&
! 	BitIsOn(((DeviceIntPtr)pKeyboard)->key->down, NUM_LOCK_CODE)) {
! 
!       register char *cp;
!       if ((cp = (char *)index (numlock_keys, fe->id)) != NULL)
! 	fe->id = 0x7f + 1 + (cp - numlock_keys);
!     }
! 
!     key = fe->id + sysKbPriv.offset;
! #else
!     key = (fe->id & 0x7f) + sysKbPriv.offset;
! #endif
! 
      keyModifiers = ((DeviceIntPtr)pKeyboard)->key->modifierMap[key];
      if (autoRepeatKeyDown && (keyModifiers == 0) &&
  	((fe->value == VKEY_DOWN) || (key == autoRepeatEvent.u.u.detail))) {
***************
*** 565,576 ****
--- 608,630 ----
      xE.u.u.type = ((fe->value == VKEY_UP) ? KeyRelease : KeyPress);
      xE.u.u.detail = key;
  
+ #ifndef SUN_NUMHACK
      if (keyModifiers & LockMask) {
+ #else
+     if (keyModifiers & LockMask ||
+ 	(pPriv->type == KB_SUN4 && key == NUM_LOCK_CODE)) {
+ #endif
  	if (xE.u.u.type == KeyRelease)
  	    return; /* this assumes autorepeat is not desired */
  	if (BitIsOn(((DeviceIntPtr)pKeyboard)->key->down, key))
  	    xE.u.u.type = KeyRelease;
+ 
+ #ifdef SUN_NUMHACK
+ 	sunKbdLockLight (pKeyboard, xE.u.u.type == KeyPress,
+ 			 key == NUM_LOCK_CODE);
+ #else
  	sunKbdLockLight (pKeyboard, xE.u.u.type == KeyPress);
+ #endif
      }
  
      if ((xE.u.u.type == KeyPress) && (keyModifiers == 0)) {
*** mit/server/ddx/sun/sunKeyMap.c-orig	Wed Oct  9 21:55:13 1991
--- mit/server/ddx/sun/sunKeyMap.c	Wed Oct  9 21:52:17 1991
***************
*** 116,124 ****
  	XK_quoteleft,	XK_asciitilde,		/* 0x2a */
  	XK_BackSpace,	NoSymbol,		/* 0x2b */
  	NoSymbol,	NoSymbol,		/* 0x2c */
! 	XK_R4,		NoSymbol,		/* 0x2d */
! 	XK_R5,		NoSymbol,		/* 0x2e */
! 	XK_R6,		NoSymbol,		/* 0x2f */
  	NoSymbol,	NoSymbol,		/* 0x30 */
  	XK_L5,		NoSymbol,		/* 0x31 */
  	NoSymbol,	NoSymbol,		/* 0x32 */
--- 116,124 ----
  	XK_quoteleft,	XK_asciitilde,		/* 0x2a */
  	XK_BackSpace,	NoSymbol,		/* 0x2b */
  	NoSymbol,	NoSymbol,		/* 0x2c */
! 	XK_R4,		XK_KP_Equal,		/* 0x2d */
! 	XK_R5,		XK_KP_Divide,		/* 0x2e */
! 	XK_R6,		XK_KP_Multiply,		/* 0x2f */
  	NoSymbol,	NoSymbol,		/* 0x30 */
  	XK_L5,		NoSymbol,		/* 0x31 */
  	NoSymbol,	NoSymbol,		/* 0x32 */
***************
*** 459,464 ****
--- 459,488 ----
          XK_KP_Add,      XK_KP_Add,              /* 0x7d */
          NoSymbol,       NoSymbol,               /* 0x7e */
          NoSymbol,       NoSymbol,               /* 0x7f */
+ 
+ #ifdef SUN_NUMHACK
+         /* these entries are faked scan codes for keys that are affected
+          * by the numlock key.  The order must match the table in sunKbd.c
+          */
+         XK_KP_Equal,    XK_R4,                  /* 0x2d => 0x80 */
+         XK_KP_Divide,   XK_R5,                  /* 0x2e => 0x81 */
+         XK_KP_Multiply, XK_R6,                  /* 0x2f => 0x82 */
+         XK_KP_Decimal,  NoSymbol,               /* 0x32 => 0x83 */
+         XK_KP_7,        XK_R7,                  /* 0x44 => 0x84 */
+         XK_KP_8,        XK_R8,                  /* 0x45 => 0x85 */
+         XK_KP_9,        XK_R9,                  /* 0x46 => 0x86 */
+         XK_KP_Subtract, NoSymbol,               /* 0x47 => 0x87 */
+         XK_KP_Enter,    NoSymbol,               /* 0x5a => 0x88 */
+         XK_KP_4,        XK_R10,                 /* 0x5b => 0x89 */
+         XK_KP_5,        XK_R11,                 /* 0x5c => 0x8a */
+         XK_KP_6,        XK_R12,                 /* 0x5d => 0x8b */
+         XK_KP_0,        NoSymbol,               /* 0x5e => 0x8c */
+         XK_KP_1,        XK_R13,                 /* 0x70 => 0x8d */
+         XK_KP_2,        XK_R14,                 /* 0x71 => 0x8e */
+         XK_KP_3,        XK_R15,                 /* 0x72 => 0x8f */
+         XK_KP_Add,      NoSymbol,               /* 0x7d => 0x90 */
+ #endif
+ 
  };
  
  
***************
*** 473,479 ****
--- 497,507 ----
  #endif
      Sun2Map,		1,	0x7a,	2,
      Sun3Map,		1,	0x7a,	2,
+ #ifdef SUN_NUMHACK
+     Sun4Map,		1,	0x90,	2,
+ #else
      Sun4Map,		1,	0x7d,	2,
+ #endif
  };
  
  #define	cT	(ControlMask)
*** mit/config/sun.cf-orig	Wed Oct  9 21:57:07 1991
--- mit/config/sun.cf	Wed Oct  9 21:52:12 1991
***************
*** 68,71 ****
  #define SunWindowsDefines /* as nothing */
  #endif
  
! #define ServerOSDefines SunWindowsDefines AllocateLocalDefines
--- 68,78 ----
  #define SunWindowsDefines /* as nothing */
  #endif
  
! #define UseSunNumlock		YES	/* enable numlock support on type4 kbds? */
! 
! #if UseSunNumlock
! #define SunNumlockDefines	-DSUN_NUMHACK
! #else
! #define SunNumlockDefines	/* as nothing */
! #endif
! #define ServerOSDefines SunNumlockDefines SunWindowsDefines AllocateLocalDefines
-- cut --
-- 
Brendan Kehoe, Sun Network Manager                      brendan@cs.widener.edu
Widener University                                                 Chester, PA
                "So are you still interested in serving on the Supreme Court?"
                              "I'd rather die than withdraw from the process."
--
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Vivek Khera, Gradual Student/Systems Guy  Department of Computer Science
Internet:   khera@cs.duke.edu             Box 90129
            (MIME mail accepted)          Durham, NC 27708-0129 (919)660-6528
Xref: sparky comp.windows.x:15356 comp.sys.ibm.pc:429 comp.os.os2:239 comp.sys.mac:225 comp.windows.misc:1163