diff options
Diffstat (limited to 'st.c')
| -rw-r--r-- | st.c | 21 |
1 files changed, 19 insertions, 2 deletions
| @@ -93,6 +93,11 @@ typedef struct { | |||
| 93 | int cw; /* char width */ | 93 | int cw; /* char width */ |
| 94 | } XWindow; | 94 | } XWindow; |
| 95 | 95 | ||
| 96 | typedef struct { | ||
| 97 | KeySym k; | ||
| 98 | char s[ESCSIZ]; | ||
| 99 | } Key; | ||
| 100 | |||
| 96 | #include "config.h" | 101 | #include "config.h" |
| 97 | 102 | ||
| 98 | /* Drawing Context */ | 103 | /* Drawing Context */ |
| @@ -146,6 +151,7 @@ static void xinit(void); | |||
| 146 | static void xscroll(void); | 151 | static void xscroll(void); |
| 147 | 152 | ||
| 148 | static void expose(XEvent *); | 153 | static void expose(XEvent *); |
| 154 | static char * kmap(KeySym); | ||
| 149 | static void kpress(XEvent *); | 155 | static void kpress(XEvent *); |
| 150 | static void resize(XEvent *); | 156 | static void resize(XEvent *); |
| 151 | 157 | ||
| @@ -1005,11 +1011,21 @@ expose(XEvent *ev) { | |||
| 1005 | draw(SCredraw); | 1011 | draw(SCredraw); |
| 1006 | } | 1012 | } |
| 1007 | 1013 | ||
| 1014 | char * | ||
| 1015 | kmap(KeySym k) { | ||
| 1016 | int i; | ||
| 1017 | for(i = 0; i < LEN(key); i++) | ||
| 1018 | if(key[i].k == k) | ||
| 1019 | return (char*)key[i].s; | ||
| 1020 | return NULL; | ||
| 1021 | } | ||
| 1022 | |||
| 1008 | void | 1023 | void |
| 1009 | kpress(XEvent *ev) { | 1024 | kpress(XEvent *ev) { |
| 1010 | XKeyEvent *e = &ev->xkey; | 1025 | XKeyEvent *e = &ev->xkey; |
| 1011 | KeySym ksym; | 1026 | KeySym ksym; |
| 1012 | char buf[32]; | 1027 | char buf[32]; |
| 1028 | char *customkey; | ||
| 1013 | int len; | 1029 | int len; |
| 1014 | int meta; | 1030 | int meta; |
| 1015 | int shift; | 1031 | int shift; |
| @@ -1017,8 +1033,9 @@ kpress(XEvent *ev) { | |||
| 1017 | meta = e->state & Mod1Mask; | 1033 | meta = e->state & Mod1Mask; |
| 1018 | shift = e->state & ShiftMask; | 1034 | shift = e->state & ShiftMask; |
| 1019 | len = XLookupString(e, buf, sizeof(buf), &ksym, NULL); | 1035 | len = XLookupString(e, buf, sizeof(buf), &ksym, NULL); |
| 1020 | if(key[ksym]) | 1036 | |
| 1021 | ttywrite(key[ksym], strlen(key[ksym])); | 1037 | if(customkey = kmap(ksym)) |
| 1038 | ttywrite(customkey, strlen(customkey)); | ||
| 1022 | else if(len > 0) { | 1039 | else if(len > 0) { |
| 1023 | buf[sizeof(buf)-1] = '\0'; | 1040 | buf[sizeof(buf)-1] = '\0'; |
| 1024 | if(meta && len == 1) | 1041 | if(meta && len == 1) |
