aboutsummaryrefslogtreecommitdiff
path: root/st.c
diff options
context:
space:
mode:
authorRoberto E. Vargas Caballero <k0ga@shike2.com>2012-11-13 20:04:45 +0100
committerRoberto E. Vargas Caballero <k0ga@shike2.com>2012-11-13 20:04:45 +0100
commitea782bfc5d34d712bc9391e498935d2d27f3116c (patch)
tree64cda24a549c2ff74a68f0540239d5a49d3e0677 /st.c
parent93f31166bfff317e050dde1723cfa8302c6f85d3 (diff)
Remove hardcoded keys form kpress
Some keys were in the Key array while others were hardcoded in kpress().This cause some problems with some keys which can generate more of one string based in the configuration of the terminal. --- config.def.h | 70 ++++++++++++++++++++++++++++++++++++++++----------------- st.c | 71 +++++++++++++++++++++++++--------------------------------- 2 files changed, 79 insertions(+), 62 deletions(-)
Diffstat (limited to 'st.c')
-rw-r--r--st.c71
1 files changed, 30 insertions, 41 deletions
diff --git a/st.c b/st.c
index 02a3502..14408c5 100644
--- a/st.c
+++ b/st.c
@@ -228,6 +228,10 @@ typedef struct {
KeySym k;
uint mask;
char s[ESC_BUF_SIZ];
+ /* three valued logic variables: 0 indifferent, 1 on, -1 off */
+ signed char appkey; /* application keypad */
+ signed char appcursor; /* application cursor */
+ signed char crlf; /* crlf mode */
} Key;
/* TODO: use better name for vars... */
@@ -2686,17 +2690,29 @@ focus(XEvent *ev) {
char*
kmap(KeySym k, uint state) {
- int i;
uint mask;
+ Key *kp;
state &= ~Mod2Mask;
- for(i = 0; i < LEN(key); i++) {
- mask = key[i].mask;
+ for(kp = key; kp < key + LEN(key); kp++) {
+ mask = kp->mask;
- if(key[i].k == k && ((state & mask) == mask
- || (mask == XK_NO_MOD && !state))) {
- return (char*)key[i].s;
- }
+ if(kp->k != k)
+ continue;
+ if((state & mask) != mask &&
+ (mask == XK_NO_MOD && state))
+ continue;
+ if((kp->appkey < 0 && IS_SET(MODE_APPKEYPAD)) ||
+ (kp->appkey > 0 && !IS_SET(MODE_APPKEYPAD)))
+ continue;
+ if((kp->appcursor < 0 && IS_SET(MODE_APPCURSOR)) ||
+ (kp->appcursor > 0 && !IS_SET(MODE_APPCURSOR)))
+ continue;
+ if((kp->crlf < 0 && IS_SET(MODE_CRLF)) ||
+ (kp->crlf > 0 && !IS_SET(MODE_CRLF)))
+ continue;
+
+ return kp->s;
}
return NULL;
}
@@ -2706,14 +2722,12 @@ kpress(XEvent *ev) {
XKeyEvent *e = &ev->xkey;
KeySym ksym;
char xstr[31], buf[32], *customkey, *cp = buf;
- int len, meta, shift, i;
+ int len, i;
Status status;
if (IS_SET(MODE_KBDLOCK))
return;
- meta = e->state & Mod1Mask;
- shift = e->state & ShiftMask;
len = XmbLookupString(xw.xic, e, xstr, sizeof(xstr), &ksym, &status);
/* 1. shortcuts */
@@ -2732,39 +2746,14 @@ kpress(XEvent *ev) {
memcpy(buf, customkey, len);
/* 2. hardcoded (overrides X lookup) */
} else {
- switch(ksym) {
- case XK_Up:
- case XK_Down:
- case XK_Left:
- case XK_Right:
- /* XXX: shift up/down doesn't work */
- sprintf(buf, "\033%c%c",
- IS_SET(MODE_APPKEYPAD) ? 'O' : '[',
- (shift ? "dacb":"DACB")[ksym - XK_Left]);
- len = 3;
- break;
- case XK_Return:
- len = 0;
- if(meta)
- *cp++ = '\033', len++;
-
- *cp++ = '\r', len++;
-
- if(IS_SET(MODE_CRLF))
- *cp = '\n', len++;
- break;
- /* 3. X lookup */
- default:
- if(len == 0)
- return;
+ if(len == 0)
+ return;
- if (len == 1 && meta)
- *cp++ = '\033';
+ if (len == 1 && e->state & Mod1Mask)
+ *cp++ = '\033';
- memcpy(cp, xstr, len);
- len = cp - buf + len;
- break;
- }
+ memcpy(cp, xstr, len);
+ len = cp - buf + len;
}
ttywrite(buf, len);
if(IS_SET(MODE_ECHO))