diff options
author | Roberto E. Vargas Caballero <k0ga@shike2.com> | 2012-11-13 20:04:45 +0100 |
---|---|---|
committer | Roberto E. Vargas Caballero <k0ga@shike2.com> | 2012-11-13 20:04:45 +0100 |
commit | ea782bfc5d34d712bc9391e498935d2d27f3116c (patch) | |
tree | 64cda24a549c2ff74a68f0540239d5a49d3e0677 /st.c | |
parent | 93f31166bfff317e050dde1723cfa8302c6f85d3 (diff) | |
download | st-ea782bfc5d34d712bc9391e498935d2d27f3116c.tar.gz st-ea782bfc5d34d712bc9391e498935d2d27f3116c.zip |
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.c | 71 |
1 files changed, 30 insertions, 41 deletions
@@ -228,6 +228,10 @@ typedef struct { | |||
228 | KeySym k; | 228 | KeySym k; |
229 | uint mask; | 229 | uint mask; |
230 | char s[ESC_BUF_SIZ]; | 230 | char s[ESC_BUF_SIZ]; |
231 | /* three valued logic variables: 0 indifferent, 1 on, -1 off */ | ||
232 | signed char appkey; /* application keypad */ | ||
233 | signed char appcursor; /* application cursor */ | ||
234 | signed char crlf; /* crlf mode */ | ||
231 | } Key; | 235 | } Key; |
232 | 236 | ||
233 | /* TODO: use better name for vars... */ | 237 | /* TODO: use better name for vars... */ |
@@ -2686,17 +2690,29 @@ focus(XEvent *ev) { | |||
2686 | 2690 | ||
2687 | char* | 2691 | char* |
2688 | kmap(KeySym k, uint state) { | 2692 | kmap(KeySym k, uint state) { |
2689 | int i; | ||
2690 | uint mask; | 2693 | uint mask; |
2694 | Key *kp; | ||
2691 | 2695 | ||
2692 | state &= ~Mod2Mask; | 2696 | state &= ~Mod2Mask; |
2693 | for(i = 0; i < LEN(key); i++) { | 2697 | for(kp = key; kp < key + LEN(key); kp++) { |
2694 | mask = key[i].mask; | 2698 | mask = kp->mask; |
2695 | 2699 | ||
2696 | if(key[i].k == k && ((state & mask) == mask | 2700 | if(kp->k != k) |
2697 | || (mask == XK_NO_MOD && !state))) { | 2701 | continue; |
2698 | return (char*)key[i].s; | 2702 | if((state & mask) != mask && |
2699 | } | 2703 | (mask == XK_NO_MOD && state)) |
2704 | continue; | ||
2705 | if((kp->appkey < 0 && IS_SET(MODE_APPKEYPAD)) || | ||
2706 | (kp->appkey > 0 && !IS_SET(MODE_APPKEYPAD))) | ||
2707 | continue; | ||
2708 | if((kp->appcursor < 0 && IS_SET(MODE_APPCURSOR)) || | ||
2709 | (kp->appcursor > 0 && !IS_SET(MODE_APPCURSOR))) | ||
2710 | continue; | ||
2711 | if((kp->crlf < 0 && IS_SET(MODE_CRLF)) || | ||
2712 | (kp->crlf > 0 && !IS_SET(MODE_CRLF))) | ||
2713 | continue; | ||
2714 | |||
2715 | return kp->s; | ||
2700 | } | 2716 | } |
2701 | return NULL; | 2717 | return NULL; |
2702 | } | 2718 | } |
@@ -2706,14 +2722,12 @@ kpress(XEvent *ev) { | |||
2706 | XKeyEvent *e = &ev->xkey; | 2722 | XKeyEvent *e = &ev->xkey; |
2707 | KeySym ksym; | 2723 | KeySym ksym; |
2708 | char xstr[31], buf[32], *customkey, *cp = buf; | 2724 | char xstr[31], buf[32], *customkey, *cp = buf; |
2709 | int len, meta, shift, i; | 2725 | int len, i; |
2710 | Status status; | 2726 | Status status; |
2711 | 2727 | ||
2712 | if (IS_SET(MODE_KBDLOCK)) | 2728 | if (IS_SET(MODE_KBDLOCK)) |
2713 | return; | 2729 | return; |
2714 | 2730 | ||
2715 | meta = e->state & Mod1Mask; | ||
2716 | shift = e->state & ShiftMask; | ||
2717 | len = XmbLookupString(xw.xic, e, xstr, sizeof(xstr), &ksym, &status); | 2731 | len = XmbLookupString(xw.xic, e, xstr, sizeof(xstr), &ksym, &status); |
2718 | 2732 | ||
2719 | /* 1. shortcuts */ | 2733 | /* 1. shortcuts */ |
@@ -2732,39 +2746,14 @@ kpress(XEvent *ev) { | |||
2732 | memcpy(buf, customkey, len); | 2746 | memcpy(buf, customkey, len); |
2733 | /* 2. hardcoded (overrides X lookup) */ | 2747 | /* 2. hardcoded (overrides X lookup) */ |
2734 | } else { | 2748 | } else { |
2735 | switch(ksym) { | 2749 | if(len == 0) |
2736 | case XK_Up: | 2750 | return; |
2737 | case XK_Down: | ||
2738 | case XK_Left: | ||
2739 | case XK_Right: | ||
2740 | /* XXX: shift up/down doesn't work */ | ||
2741 | sprintf(buf, "\033%c%c", | ||
2742 | IS_SET(MODE_APPKEYPAD) ? 'O' : '[', | ||
2743 | (shift ? "dacb":"DACB")[ksym - XK_Left]); | ||
2744 | len = 3; | ||
2745 | break; | ||
2746 | case XK_Return: | ||
2747 | len = 0; | ||
2748 | if(meta) | ||
2749 | *cp++ = '\033', len++; | ||
2750 | |||
2751 | *cp++ = '\r', len++; | ||
2752 | |||
2753 | if(IS_SET(MODE_CRLF)) | ||
2754 | *cp = '\n', len++; | ||
2755 | break; | ||
2756 | /* 3. X lookup */ | ||
2757 | default: | ||
2758 | if(len == 0) | ||
2759 | return; | ||
2760 | 2751 | ||
2761 | if (len == 1 && meta) | 2752 | if (len == 1 && e->state & Mod1Mask) |
2762 | *cp++ = '\033'; | 2753 | *cp++ = '\033'; |
2763 | 2754 | ||
2764 | memcpy(cp, xstr, len); | 2755 | memcpy(cp, xstr, len); |
2765 | len = cp - buf + len; | 2756 | len = cp - buf + len; |
2766 | break; | ||
2767 | } | ||
2768 | } | 2757 | } |
2769 | ttywrite(buf, len); | 2758 | ttywrite(buf, len); |
2770 | if(IS_SET(MODE_ECHO)) | 2759 | if(IS_SET(MODE_ECHO)) |