Fix for CapsLock problem under XFree86

Alistair Crooks <[email protected]>
Newsgroups gmane.editors.wily
Message-ID <[email protected]>
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
patch-ac (text/plain, 328 B)
$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 */
 		}
patch-ad (text/plain, 1 KB)
$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);
 	}
 }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.