[hackers] [st] Add key for toogling numlock handling || "Roberto E. Vargas Caballero"

From: <hg_AT_suckless.org>
Date: Sun, 25 Nov 2012 09:25:26 +0100 (CET)

changeset: 427:1b9f4b63550e
user: "Roberto E. Vargas Caballero" <k0ga_AT_shike2.com>
date: Sun Nov 25 09:23:02 2012 +0100
files: config.def.h st.c
description:
Add key for toogling numlock handling
Keypad will generate keycodes when keypad application mode is enabled. It
can cause problems with some programs like vi, which operates in such
mode.

This patch change by default don't generate the keycodes never, but this
behaviour can be changed using the combination Alt + NumLock.
---
 config.def.h |   34 ++++++++++++++++++----------------
 st.c         |   17 +++++++++++++++--
 2 files changed, 33 insertions(+), 18 deletions(-)
diff -r c96fca73c600 -r 1b9f4b63550e config.def.h
--- a/config.def.h	Wed Nov 21 20:38:15 2012 +0100
+++ b/config.def.h	Sun Nov 25 09:23:02 2012 +0100
_AT_@ -62,6 +62,7 @@
 	{ MODKEY|ShiftMask,	XK_Prior,	xzoom,		{.i = +1} },
 	{ MODKEY|ShiftMask,	XK_Next,	xzoom,		{.i = -1} },
 	{ ShiftMask,		XK_Insert,	selpaste,	{.i =  0} },
+	{ MODKEY,		XK_Num_Lock,	numlock,	{.i =  0} },
 };
 
 /*
_AT_@ -73,6 +74,7 @@
  * keypad value:
  * * 0: no value
  * * > 0: keypad application mode enabled
+ * *   = 2: term.numlock = 1
  * * < 0: keypad application mode disabled
  * cursor value:
  * * 0: no value
_AT_@ -123,24 +125,24 @@
 	{ XK_KP_Insert,     XK_ANY_MOD,     "\033[2~",       0,    0,    0},
 	{ XK_KP_Delete,     ShiftMask,      "\033[3;2~",     0,    0,    0},
 	{ XK_KP_Delete,     XK_ANY_MOD,     "\033[3~",       0,    0,    0},
-	{ XK_KP_Multiply,   XK_ANY_MOD,     "\033Oj",       +1,    0,    0},
-	{ XK_KP_Add,        XK_ANY_MOD,     "\033Ok",       +1,    0,    0},
-	{ XK_KP_Enter,      XK_ANY_MOD,     "\033OM",       +1,    0,    0},
+	{ XK_KP_Multiply,   XK_ANY_MOD,     "\033Oj",       +2,    0,    0},
+	{ XK_KP_Add,        XK_ANY_MOD,     "\033Ok",       +2,    0,    0},
+	{ XK_KP_Enter,      XK_ANY_MOD,     "\033OM",       +2,    0,    0},
 	{ XK_KP_Enter,      XK_ANY_MOD,     "\r",           -1,    0,   -1},
 	{ XK_KP_Enter,      XK_ANY_MOD,     "\r\n",         -1,    0,   +1},
-	{ XK_KP_Subtract,   XK_ANY_MOD,     "\033Om",       +1,    0,    0},
-	{ XK_KP_Decimal,    XK_ANY_MOD,     "\033On",       +1,    0,    0},
-	{ XK_KP_Divide,     XK_ANY_MOD,     "\033Oo",       +1,    0,    0},
-	{ XK_KP_0,          XK_ANY_MOD,     "\033Op",       +1,    0,    0},
-	{ XK_KP_1,          XK_ANY_MOD,     "\033Oq",       +1,    0,    0},
-	{ XK_KP_2,          XK_ANY_MOD,     "\033Or",       +1,    0,    0},
-	{ XK_KP_3,          XK_ANY_MOD,     "\033Os",       +1,    0,    0},
-	{ XK_KP_4,          XK_ANY_MOD,     "\033Ot",       +1,    0,    0},
-	{ XK_KP_5,          XK_ANY_MOD,     "\033Ou",       +1,    0,    0},
-	{ XK_KP_6,          XK_ANY_MOD,     "\033Ov",       +1,    0,    0},
-	{ XK_KP_7,          XK_ANY_MOD,     "\033Ow",       +1,    0,    0},
-	{ XK_KP_8,          XK_ANY_MOD,     "\033Ox",       +1,    0,    0},
-	{ XK_KP_9,          XK_ANY_MOD,     "\033Oy",       +1,    0,    0},
+	{ XK_KP_Subtract,   XK_ANY_MOD,     "\033Om",       +2,    0,    0},
+	{ XK_KP_Decimal,    XK_ANY_MOD,     "\033On",       +2,    0,    0},
+	{ XK_KP_Divide,     XK_ANY_MOD,     "\033Oo",       +2,    0,    0},
+	{ XK_KP_0,          XK_ANY_MOD,     "\033Op",       +2,    0,    0},
+	{ XK_KP_1,          XK_ANY_MOD,     "\033Oq",       +2,    0,    0},
+	{ XK_KP_2,          XK_ANY_MOD,     "\033Or",       +2,    0,    0},
+	{ XK_KP_3,          XK_ANY_MOD,     "\033Os",       +2,    0,    0},
+	{ XK_KP_4,          XK_ANY_MOD,     "\033Ot",       +2,    0,    0},
+	{ XK_KP_5,          XK_ANY_MOD,     "\033Ou",       +2,    0,    0},
+	{ XK_KP_6,          XK_ANY_MOD,     "\033Ov",       +2,    0,    0},
+	{ XK_KP_7,          XK_ANY_MOD,     "\033Ow",       +2,    0,    0},
+	{ XK_KP_8,          XK_ANY_MOD,     "\033Ox",       +2,    0,    0},
+	{ XK_KP_9,          XK_ANY_MOD,     "\033Oy",       +2,    0,    0},
 	{ XK_BackSpace,     XK_NO_MOD,      "\177",          0,    0,    0},
 	{ XK_Up,            ShiftMask,      "\033[1;2A",     0,    0,    0},
 	{ XK_Up,            ControlMask,    "\033[1;5A",     0,    0,    0},
diff -r c96fca73c600 -r 1b9f4b63550e st.c
--- a/st.c	Wed Nov 21 20:38:15 2012 +0100
+++ b/st.c	Sun Nov 25 09:23:02 2012 +0100
_AT_@ -194,6 +194,7 @@
 	int bot;	/* bottom scroll limit */
 	int mode;	/* terminal mode flags */
 	int esc;	/* escape state flags */
+	bool numlock;	/* lock numbers in keyboard */
 	bool *tabs;
 } Term;
 
_AT_@ -261,6 +262,7 @@
 /* function definitions used in config.h */
 static void xzoom(const Arg *);
 static void selpaste(const Arg *);
+static void numlock(const Arg *);
 
 /* Config.h for applying patches and the configuration. */
 #include "config.h"
_AT_@ -1100,6 +1102,7 @@
 		term.alt [row] = xmalloc(term.col * sizeof(Glyph));
 		term.dirty[row] = 0;
 	}
+	term.numlock = 1;
 	memset(term.tabs, 0, term.col * sizeof(*term.tabs));
 	/* setup screen */
 	treset();
_AT_@ -2700,6 +2703,12 @@
 	return true;
 }
 
+void
+numlock(const Arg *dummy)
+{
+	term.numlock ^= 1;
+}
+
 char*
 kmap(KeySym k, uint state) {
 	uint mask;
_AT_@ -2725,8 +2734,12 @@
 		if(!match(mask, state))
 			continue;
 
-		if((kp->appkey < 0 && IS_SET(MODE_APPKEYPAD)) ||
-				(kp->appkey > 0 && !IS_SET(MODE_APPKEYPAD))) {
+		if(kp->appkey > 0) {
+			if(!IS_SET(MODE_APPKEYPAD))
+				continue;
+			if(term.numlock && kp->appkey == 2)
+				continue;
+		} else if (kp->appkey < 0 && IS_SET(MODE_APPKEYPAD)) {
 			continue;
 		}
 
Received on Sun Nov 25 2012 - 09:25:26 CET

This archive was generated by hypermail 2.3.0 : Sun Nov 25 2012 - 09:36:09 CET