Re: [dev] [st] Fix the tab key

2012-11-15 Thread Roberto E. Vargas Caballero

Hello,

A new serie of patches that fix some problems detected in last serie:

- Tab problems
- Return problems in not newline modes
- arrow problems

Please, if you find some new errors (I am pretty sure something can happen)
notice me. This new series apply over the actual mercurial tip.

Best regards.
From 931003d3252ab1a0c97b762ae29c5f939db1de44 Mon Sep 17 00:00:00 2001
From: Roberto E. Vargas Caballero k...@shike2.com
Date: Wed, 14 Nov 2012 11:00:08 +0100
Subject: Fix tab key

When Shift + Tab is pressed X server send the event XK_ISO_Left_Tab with
ShiftMask, so this is the entry we need in config.def.h

This patch also revert the previous patch for this issue because it breaks
the keyboard.
---
 config.def.h |2 +-
 st.c |2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/config.def.h b/config.def.h
index 5d887fc..972285b 100644
--- a/config.def.h
+++ b/config.def.h
@@ -141,7 +141,7 @@ static Key key[] = {
 	{ XK_Right, ShiftMask,  \033[1;2C, 0,0,0},
 	{ XK_Right, ControlMask,\033[1;5C, 0,0,0},
 	{ XK_Right, Mod1Mask,   \033[1;3C, 0,0,0},
-	{ XK_Tab,   ShiftMask,  \033[Z,0,0,0},
+	{ XK_ISO_Left_Tab,  ShiftMask,  \033[Z,0,0,0},
 	{ XK_Return,XK_NO_MOD,  \n,0,0,   -1},
 	{ XK_Return,XK_NO_MOD,  \r\n,  0,0,   +1},
 	{ XK_Return,Mod1Mask,   \033\n,0,0,   -1},
diff --git a/st.c b/st.c
index ca4248a..932253c 100644
--- a/st.c
+++ b/st.c
@@ -2700,7 +2700,7 @@ kmap(KeySym k, uint state) {
 		if(kp-k != k)
 			continue;
 
-		if((state  mask) != mask ||
+		if((state  mask) != mask 
 (mask == XK_NO_MOD  state)) {
 			continue;
 		}
-- 
1.7.10.4

From b3c76defd2fc66584d221cadae3f8d85fb7fe0d5 Mon Sep 17 00:00:00 2001
From: Roberto E. Vargas Caballero k...@shike2.com
Date: Thu, 15 Nov 2012 10:59:07 +0100
Subject: Fix XK_NO_MOD and XK_ANY_MOD behavior

XK_NO_MOD match a key without modifiers and XK_ANY_MOD match a key does not
matter what modifiers are pressed to. Like they are mask the best value for
XK_ANY_MOD is all the bits to 1, so the and with any state will be equal to
the state. This also imply that is necessary check the case for XK_NO_MOD
(no modifiers at all) with some modifier in state, and the inverse
(some mask different to XK_ANY_MOD or XK_NO_MOD and no modifiers in state).
---
 st.c |   12 +++-
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/st.c b/st.c
index 932253c..b8b2bbf 100644
--- a/st.c
+++ b/st.c
@@ -59,8 +59,8 @@
 #define STR_ARG_SIZ   16
 #define DRAW_BUF_SIZ  20*1024
 #define UTF_SIZ   4
-#define XK_NO_MOD UINT_MAX
-#define XK_ANY_MOD0
+#define XK_ANY_MODUINT_MAX
+#define XK_NO_MOD 0
 
 #define REDRAW_TIMEOUT (80*1000) /* 80 ms */
 
@@ -2700,10 +2700,12 @@ kmap(KeySym k, uint state) {
 		if(kp-k != k)
 			continue;
 
-		if((state  mask) != mask 
-(mask == XK_NO_MOD  state)) {
+		if(mask == XK_NO_MOD  state)
+			continue;
+		if(mask != XK_ANY_MOD  mask != XK_NO_MOD  !state)
+			continue;
+		if((state  mask) != state)
 			continue;
-		}
 
 		if((kp-appkey  0  IS_SET(MODE_APPKEYPAD)) ||
 (kp-appkey  0  !IS_SET(MODE_APPKEYPAD))) {
-- 
1.7.10.4

From f752242029dc32ce6ce57bec3353e7f912931856 Mon Sep 17 00:00:00 2001
From: Roberto E. Vargas Caballero k...@shike2.com
Date: Thu, 15 Nov 2012 11:09:36 +0100
Subject: Use XK_ANY_MOD instead of XK_NO_MOD in key definition

Usually terminal emulators don't generate any sequence for a combination
they don't have registered, for example Shift + Next, but st behavior
previous to the keyboard patch generates the sequence without the modifier,
in this example Next. This patch uses the XK_ANY_MOD in order to get this
same behaviour.
---
 config.def.h |  114 ++
 1 file changed, 59 insertions(+), 55 deletions(-)

diff --git a/config.def.h b/config.def.h
index 972285b..bd5a888 100644
--- a/config.def.h
+++ b/config.def.h
@@ -72,91 +72,95 @@ static unsigned int defaultucs = 257;
  * * 0: no value
  * *  0: crlf mode is enabled
  * *  0: crlf mode is disabled
+ *
+ * Be careful with the order of the definitons because st searchs in
+ * this table sequencially, so any XK_ANY_MOD must be in the last
+ * position for a key.
  */
 
 /* key, mask, output, keypad, cursor, crlf */
 static Key key[] = {
 	/* keysym mask string keypad cursor crlf */
-	{ XK_KP_Home,   XK_NO_MOD,  \033[H,0,0,0},
 	{ XK_KP_Home,   ShiftMask,  \033[1;2H, 0,0,0},
-	{ XK_KP_Up, XK_NO_MOD,  \033Ox,   +1,0,0},
-	{ XK_KP_Up, XK_NO_MOD,  \033[A,0,   -1,0},
-	{ XK_KP_Up, XK_NO_MOD,  \033OA,0,   +1,0},
-	{ XK_KP_Down,   XK_NO_MOD,  \033Or,   +1,0,0},
-	{ XK_KP_Down,   

Re: [dev] [st] Fix the tab key

2012-11-15 Thread Eckehard Berns
 Please, if you find some new errors (I am pretty sure something can happen)
 notice me.

For me Shift+Insert inserts \E[2;2~ just before the selection.

-- 
Eckehard Berns



Re: [dev] [st] Fix the tab key

2012-11-15 Thread Christoph Lohmann
Greetings.

On Thu, 15 Nov 2012 15:43:25 +0100 Roberto E. Vargas Caballero 
k...@shike2.com wrote:
 
 Hello,
 
 A new serie of patches that fix some problems detected in last serie:
 
   - Tab problems
   - Return problems in not newline modes
   - arrow problems
 
 Please, if you find some new errors (I am pretty sure something can happen)
 notice me. This new series apply over the actual mercurial tip.

Thanks, most of the keys are working. Now Return is sending two line breaks.


Sincerely,

Christoph Lohmann





Re: [dev] [st] Fix the tab key

2012-11-15 Thread Roberto E. Vargas Caballero
On Thu, Nov 15, 2012 at 03:16:26PM +0100, Eckehard Berns wrote:
  Please, if you find some new errors (I am pretty sure something can happen)
  notice me.

 For me Shift+Insert inserts \E[2;2~ just before the selection.


I attach the patch which fix this problem.
From b06832d5f12d75daa8c640d91bc4ee97bad24bc2 Mon Sep 17 00:00:00 2001
From: Roberto E. Vargas Caballero k...@shike2.com
Date: Thu, 15 Nov 2012 18:18:24 +0100
Subject: Fix Shift + Insert shortcut

This patch apply the same code for shortcuts that it is used now for defined
keys. So it is possible use now XK_NO_MOD and XK_ANY_MOD for defining shortcuts.
---
 st.c |   35 ---
 1 file changed, 20 insertions(+), 15 deletions(-)

diff --git a/st.c b/st.c
index ba93f2f..477a8f8 100644
--- a/st.c
+++ b/st.c
@@ -65,7 +65,6 @@
 #define REDRAW_TIMEOUT (80*1000) /* 80 ms */
 
 /* macros */
-#define CLEANMASK(mask) (mask  (ShiftMask|ControlMask|Mod1Mask|Mod2Mask|Mod3Mask|Mod4Mask|Mod5Mask))
 #define SERRNO strerror(errno)
 #define MIN(a, b)  ((a)  (b) ? (a) : (b))
 #define MAX(a, b)  ((a)  (b) ? (b) : (a))
@@ -329,6 +328,7 @@ static void tsetmode(bool, bool, int *, int);
 static void tfulldirt(void);
 static void techo(char *, int);
 
+static inline bool match(uint, uint);
 static void ttynew(void);
 static void ttyread(void);
 static void ttyresize(void);
@@ -2696,23 +2696,29 @@ focus(XEvent *ev) {
 	}
 }
 
+inline bool
+match(uint mask, uint state) {
+	if(mask == XK_NO_MOD  state)
+		return false;
+	if(mask != XK_ANY_MOD  mask != XK_NO_MOD  !state)
+		return false;
+	if((state  mask) != state)
+		return false;
+	return true;
+}
+
 char*
 kmap(KeySym k, uint state) {
 	uint mask;
 	Key *kp;
 
-	state = ~Mod2Mask;
 	for(kp = key; kp  key + LEN(key); kp++) {
 		mask = kp-mask;
 
 		if(kp-k != k)
 			continue;
 
-		if(mask == XK_NO_MOD  state)
-			continue;
-		if(mask != XK_ANY_MOD  mask != XK_NO_MOD  !state)
-			continue;
-		if((state  mask) != state)
+		if(!match(mask, state))
 			continue;
 
 		if((kp-appkey  0  IS_SET(MODE_APPKEYPAD)) ||
@@ -2741,21 +2747,20 @@ kpress(XEvent *ev) {
 	XKeyEvent *e = ev-xkey;
 	KeySym ksym;
 	char xstr[31], buf[32], *customkey, *cp = buf;
-	int len, i;
+	int len;
 	Status status;
+	Shortcut *bp;
 
 	if (IS_SET(MODE_KBDLOCK))
 		return;
 
 	len = XmbLookupString(xw.xic, e, xstr, sizeof(xstr), ksym, status);
-
+	e-state = ~Mod2Mask;
 	/* 1. shortcuts */
-	for(i = 0; i  LEN(shortcuts); i++) {
-		if((ksym == shortcuts[i].keysym)
- (CLEANMASK(shortcuts[i].mod) == \
-	CLEANMASK(e-state))
- shortcuts[i].func) {
-			shortcuts[i].func((shortcuts[i].arg));
+	for(bp = shortcuts; bp  shortcuts + LEN(shortcuts); bp++) {
+		if(ksym == bp-keysym  match(bp-mod, e-state)) {
+			bp-func((bp-arg));
+			return;
 		}
 	}
 
-- 
1.7.10.4



Re: [dev] [st] Fix the tab key

2012-11-15 Thread Christoph Lohmann
Greetings.

On Thu, 15 Nov 2012 19:01:36 +0100 Roberto E. Vargas Caballero 
k...@shike2.com wrote:
 On Thu, Nov 15, 2012 at 03:16:26PM +0100, Eckehard Berns wrote:
   Please, if you find some new errors (I am pretty sure something can 
   happen)
   notice me.
 
  For me Shift+Insert inserts \E[2;2~ just before the selection.
 
 
 I attach the patch which fix this problem.

Thanks, applied.


Sincerely,

Christoph




Re: [dev] [st] Fix the tab key

2012-11-14 Thread Roberto E. Vargas Caballero

I forgot the patch, sorry.


On Wed, Nov 14, 2012 at 11:08:27AM +0100, Roberto E. Vargas Caballero wrote:
 Hello,

   After last patch serie tab key was not working correctly and this
 patch fix the problem. I also want to comment this line in kmap:

   state = ~Mod2Mask

 I don't know why this line is writing there, but it removes any combination
 using Super key. I think it is necessary remove this line.

 Best regards,
From d87011d514e2e20a962d482bb432825bc713087b Mon Sep 17 00:00:00 2001
From: Roberto E. Vargas Caballero k...@shike2.com
Date: Wed, 14 Nov 2012 11:00:08 +0100
Subject: Fix tab key

When Shift + Tab is pressed X server send the event XK_ISO_Left_Tab with
ShiftMask, so this is the entry we need in config.def.h

This patch also revert the previous patch for this issue because it breaks
the keyboard.
---
 config.def.h |2 +-
 st.c |2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/config.def.h b/config.def.h
index 7a785a3..68261a5 100644
--- a/config.def.h
+++ b/config.def.h
@@ -145,7 +145,7 @@ static Key key[] = {
 	{ XK_Right, ShiftMask,  \033[1;2C, 0,0,0},
 	{ XK_Right, ControlMask,\033[1;5C, 0,0,0},
 	{ XK_Right, Mod1Mask,   \033[1;3C, 0,0,0},
-	{ XK_Tab,   ShiftMask,  \033[Z,0,0,0},
+	{ XK_ISO_Left_Tab,  ShiftMask,  \033[Z,0,0,0},
 	{ XK_Return,XK_NO_MOD,  \n,0,0,   -1},
 	{ XK_Return,XK_NO_MOD,  \r\n,  0,0,   +1},
 	{ XK_Return,Mod1Mask,   \033\n,0,0,   -1},
diff --git a/st.c b/st.c
index ca4248a..932253c 100644
--- a/st.c
+++ b/st.c
@@ -2700,7 +2700,7 @@ kmap(KeySym k, uint state) {
 		if(kp-k != k)
 			continue;
 
-		if((state  mask) != mask ||
+		if((state  mask) != mask 
 (mask == XK_NO_MOD  state)) {
 			continue;
 		}
-- 
1.7.10.4