[agc@pkgsrc.org: Fix for CapsLock problem under XFree86]

  • From: Alistair Crooks <agc@xxxxxxxxxx>
  • To: wilyfans@xxxxxxxxxxxxx
  • Date: Mon, 16 Jun 2003 17:38:19 +0200

I'm not sure if anyone got these, so I'll resend.

All feedback gratefully received - X11 is not my favourite programming
environment, and I'm not really able to test this myself.

Thanks,
Alistair
--- Begin Message ---
  • From: Alistair Crooks <agc@xxxxxxxxxx>
  • To: wilyfans@xxxxxxxxxxxxx
  • Date: Fri, 6 Jun 2003 17:52:10 +0200
I'll attach two patches to this mail which fixes the CapsLock problem
for me under XFree86 4.3.0.  I'm not proud of these, as there are some
deficiencies to them:

1. they assume the initial state of CapsLock is off

2.  they use toupper(3) to "capitalise" a Rune.  This is almost
definitely wrong.

I have not tested the patches under Openwin (or anything except XF86 4.3)

However, they should provide the inspiration to someone to be able to
fix it properly. I'm afraid I'll never use these patches, since I
have CapsLock mapped to Control_L.

Regards,
Alistair
$NetBSD$

--- libXg/gwin.c        2003/06/06 15:34:26     1.1
+++ libXg/gwin.c        2003/06/06 15:35:25
@@ -267,6 +267,11 @@
                case XK_End:
                        k = 0x87;       /* End */
                        break;
+#ifdef RECOGNISE_CAPS_LOCK
+               case XK_Caps_Lock:      /* CapsLock */
+                       toggle_capslock();
+                       return;
+#endif
                default:
                        return; /* not ISO-1 or tty control */
                }
$NetBSD$

--- wily/keyboard.c     2003/06/06 15:36:43     1.1
+++ wily/keyboard.c     2003/06/06 15:41:04
@@ -13,6 +13,36 @@
 static void            deleteword(View*v);
 static void            esc(View*v);
 
+static int             CapsLockOn;
+
+/*
+ * agc - utility function which will only get called (if compiled in)
+ * whenCapsLock is pressed - see ../libXg/gwin.c
+ */
+#ifdef RECOGNISE_CAPS_LOCK
+#include <ctype.h>
+void
+toggle_capslock(void)
+{
+       CapsLockOn = 1 - CapsLockOn;
+}
+#endif
+
+/*
+ * agc - check to see whether CapsLock is on (if compiled in)
+ * and, if so, "capitalise" the Rune. This is done using toupper(3),
+ * which will probably not DTRT.
+ */
+static Rune
+capslockify(Rune r)
+{
+#ifdef RECOGNISE_CAPS_LOCK
+       return (CapsLockOn) ? (Rune) toupper((unsigned char)r) : r;
+#else
+       return r;
+#endif
+}
+
 void
 dokeyboard(View *v, Rune r) {
        switch(r) {
@@ -33,7 +63,7 @@
        case Esc:                       esc(v); break;
        
        case '\n':                      if(!v->scroll){tag_cr(v); break; }
-       default:                        addrune(v,r);
+       default:                        r = capslockify(r); addrune(v,r);
        }
 }
 

--- End Message ---

Other related posts: