diff options
author | Devin J. Pohly <djpohly@gmail.com> | 2017-10-11 08:47:14 -0500 |
---|---|---|
committer | Devin J. Pohly <djpohly@gmail.com> | 2018-02-25 21:53:24 -0600 |
commit | ed132e11271d18a5d8aa163096bc6192c694bc47 (patch) | |
tree | 81b7a8ef14efadfaee06e7848a1c7ab953cd5ce6 | |
parent | dbe8676d7d69651132bde2b6d9ec3787cbbc552a (diff) | |
download | st-patched-ed132e11271d18a5d8aa163096bc6192c694bc47.tar.bz2 st-patched-ed132e11271d18a5d8aa163096bc6192c694bc47.tar.xz st-patched-ed132e11271d18a5d8aa163096bc6192c694bc47.zip |
Move key-matching functions into x.c
Modifiers and keysyms are specific to X, and the functions match and
kmap are only used in x.c. Needed to global-ize the key arrays and
lengths from config.h (for now).
Signed-off-by: Devin J. Pohly <djpohly@gmail.com>
-rw-r--r-- | config.def.h | 6 | ||||
-rw-r--r-- | st.c | 58 | ||||
-rw-r--r-- | st.h | 18 | ||||
-rw-r--r-- | x.c | 48 |
4 files changed, 68 insertions, 62 deletions
diff --git a/config.def.h b/config.def.h index dd94be2..18cb31c 100644 --- a/config.def.h +++ b/config.def.h | |||
@@ -209,13 +209,13 @@ Shortcut shortcuts[] = { | |||
209 | * If you want keys other than the X11 function keys (0xFD00 - 0xFFFF) | 209 | * If you want keys other than the X11 function keys (0xFD00 - 0xFFFF) |
210 | * to be mapped below, add them to this array. | 210 | * to be mapped below, add them to this array. |
211 | */ | 211 | */ |
212 | static KeySym mappedkeys[] = { -1 }; | 212 | KeySym mappedkeys[] = { -1 }; |
213 | 213 | ||
214 | /* | 214 | /* |
215 | * State bits to ignore when matching key or button events. By default, | 215 | * State bits to ignore when matching key or button events. By default, |
216 | * numlock (Mod2Mask) and keyboard layout (XK_SWITCH_MOD) are ignored. | 216 | * numlock (Mod2Mask) and keyboard layout (XK_SWITCH_MOD) are ignored. |
217 | */ | 217 | */ |
218 | static uint ignoremod = Mod2Mask|XK_SWITCH_MOD; | 218 | uint ignoremod = Mod2Mask|XK_SWITCH_MOD; |
219 | 219 | ||
220 | /* | 220 | /* |
221 | * Override mouse-select while mask is active (when MODE_MOUSE is set). | 221 | * Override mouse-select while mask is active (when MODE_MOUSE is set). |
@@ -228,7 +228,7 @@ uint forceselmod = ShiftMask; | |||
228 | * This is the huge key array which defines all compatibility to the Linux | 228 | * This is the huge key array which defines all compatibility to the Linux |
229 | * world. Please decide about changes wisely. | 229 | * world. Please decide about changes wisely. |
230 | */ | 230 | */ |
231 | static Key key[] = { | 231 | Key key[] = { |
232 | /* keysym mask string appkey appcursor crlf */ | 232 | /* keysym mask string appkey appcursor crlf */ |
233 | { XK_KP_Home, ShiftMask, "\033[2J", 0, -1, 0}, | 233 | { XK_KP_Home, ShiftMask, "\033[2J", 0, -1, 0}, |
234 | { XK_KP_Home, ShiftMask, "\033[1;2H", 0, +1, 0}, | 234 | { XK_KP_Home, ShiftMask, "\033[1;2H", 0, +1, 0}, |
@@ -110,16 +110,6 @@ typedef struct { | |||
110 | int narg; /* nb of args */ | 110 | int narg; /* nb of args */ |
111 | } STREscape; | 111 | } STREscape; |
112 | 112 | ||
113 | typedef struct { | ||
114 | KeySym k; | ||
115 | uint mask; | ||
116 | char *s; | ||
117 | /* three valued logic variables: 0 indifferent, 1 on, -1 off */ | ||
118 | signed char appkey; /* application keypad */ | ||
119 | signed char appcursor; /* application cursor */ | ||
120 | signed char crlf; /* crlf mode */ | ||
121 | } Key; | ||
122 | |||
123 | /* function definitions used in config.h */ | 113 | /* function definitions used in config.h */ |
124 | static void clipcopy(const Arg *); | 114 | static void clipcopy(const Arg *); |
125 | static void clippaste(const Arg *); | 115 | static void clippaste(const Arg *); |
@@ -223,6 +213,8 @@ size_t colornamelen = LEN(colorname); | |||
223 | size_t mshortcutslen = LEN(mshortcuts); | 213 | size_t mshortcutslen = LEN(mshortcuts); |
224 | size_t shortcutslen = LEN(shortcuts); | 214 | size_t shortcutslen = LEN(shortcuts); |
225 | size_t selmaskslen = LEN(selmasks); | 215 | size_t selmaskslen = LEN(selmasks); |
216 | size_t keyslen = LEN(key); | ||
217 | size_t mappedkeyslen = LEN(mappedkeys); | ||
226 | 218 | ||
227 | ssize_t | 219 | ssize_t |
228 | xwrite(int fd, const char *s, size_t len) | 220 | xwrite(int fd, const char *s, size_t len) |
@@ -2550,54 +2542,8 @@ redraw(void) | |||
2550 | draw(); | 2542 | draw(); |
2551 | } | 2543 | } |
2552 | 2544 | ||
2553 | int | ||
2554 | match(uint mask, uint state) | ||
2555 | { | ||
2556 | return mask == XK_ANY_MOD || mask == (state & ~ignoremod); | ||
2557 | } | ||
2558 | |||
2559 | void | 2545 | void |
2560 | numlock(const Arg *dummy) | 2546 | numlock(const Arg *dummy) |
2561 | { | 2547 | { |
2562 | term.numlock ^= 1; | 2548 | term.numlock ^= 1; |
2563 | } | 2549 | } |
2564 | |||
2565 | char* | ||
2566 | kmap(KeySym k, uint state) | ||
2567 | { | ||
2568 | Key *kp; | ||
2569 | int i; | ||
2570 | |||
2571 | /* Check for mapped keys out of X11 function keys. */ | ||
2572 | for (i = 0; i < LEN(mappedkeys); i++) { | ||
2573 | if (mappedkeys[i] == k) | ||
2574 | break; | ||
2575 | } | ||
2576 | if (i == LEN(mappedkeys)) { | ||
2577 | if ((k & 0xFFFF) < 0xFD00) | ||
2578 | return NULL; | ||
2579 | } | ||
2580 | |||
2581 | for (kp = key; kp < key + LEN(key); kp++) { | ||
2582 | if (kp->k != k) | ||
2583 | continue; | ||
2584 | |||
2585 | if (!match(kp->mask, state)) | ||
2586 | continue; | ||
2587 | |||
2588 | if (IS_SET(MODE_APPKEYPAD) ? kp->appkey < 0 : kp->appkey > 0) | ||
2589 | continue; | ||
2590 | if (term.numlock && kp->appkey == 2) | ||
2591 | continue; | ||
2592 | |||
2593 | if (IS_SET(MODE_APPCURSOR) ? kp->appcursor < 0 : kp->appcursor > 0) | ||
2594 | continue; | ||
2595 | |||
2596 | if (IS_SET(MODE_CRLF) ? kp->crlf < 0 : kp->crlf > 0) | ||
2597 | continue; | ||
2598 | |||
2599 | return kp->s; | ||
2600 | } | ||
2601 | |||
2602 | return NULL; | ||
2603 | } | ||
@@ -176,6 +176,16 @@ typedef struct { | |||
176 | const Arg arg; | 176 | const Arg arg; |
177 | } Shortcut; | 177 | } Shortcut; |
178 | 178 | ||
179 | typedef struct { | ||
180 | KeySym k; | ||
181 | uint mask; | ||
182 | char *s; | ||
183 | /* three valued logic variables: 0 indifferent, 1 on, -1 off */ | ||
184 | signed char appkey; /* application keypad */ | ||
185 | signed char appcursor; /* application cursor */ | ||
186 | signed char crlf; /* crlf mode */ | ||
187 | } Key; | ||
188 | |||
179 | void die(const char *, ...); | 189 | void die(const char *, ...); |
180 | void redraw(void); | 190 | void redraw(void); |
181 | 191 | ||
@@ -184,7 +194,6 @@ void tnew(int, int); | |||
184 | void tresize(int, int); | 194 | void tresize(int, int); |
185 | void tsetdirt(int, int); | 195 | void tsetdirt(int, int); |
186 | void tsetdirtattr(int); | 196 | void tsetdirtattr(int); |
187 | int match(uint, uint); | ||
188 | void ttynew(void); | 197 | void ttynew(void); |
189 | size_t ttyread(void); | 198 | size_t ttyread(void); |
190 | void ttyresize(int, int); | 199 | void ttyresize(int, int); |
@@ -193,9 +202,7 @@ void ttywrite(const char *, size_t); | |||
193 | 202 | ||
194 | void resettitle(void); | 203 | void resettitle(void); |
195 | 204 | ||
196 | char *kmap(KeySym, uint); | ||
197 | void selclear(void); | 205 | void selclear(void); |
198 | |||
199 | void selinit(void); | 206 | void selinit(void); |
200 | void selnormalize(void); | 207 | void selnormalize(void); |
201 | int selected(int, int); | 208 | int selected(int, int); |
@@ -255,7 +262,12 @@ extern MouseShortcut mshortcuts[]; | |||
255 | extern size_t mshortcutslen; | 262 | extern size_t mshortcutslen; |
256 | extern Shortcut shortcuts[]; | 263 | extern Shortcut shortcuts[]; |
257 | extern size_t shortcutslen; | 264 | extern size_t shortcutslen; |
265 | extern KeySym mappedkeys[]; | ||
266 | extern size_t mappedkeyslen; | ||
267 | extern uint ignoremod; | ||
258 | extern uint forceselmod; | 268 | extern uint forceselmod; |
269 | extern Key key[]; | ||
270 | extern size_t keyslen; | ||
259 | extern uint selmasks[]; | 271 | extern uint selmasks[]; |
260 | extern size_t selmaskslen; | 272 | extern size_t selmaskslen; |
261 | extern char ascii_printable[]; | 273 | extern char ascii_printable[]; |
@@ -116,6 +116,8 @@ static void selrequest(XEvent *); | |||
116 | static void selcopy(Time); | 116 | static void selcopy(Time); |
117 | static void getbuttoninfo(XEvent *); | 117 | static void getbuttoninfo(XEvent *); |
118 | static void mousereport(XEvent *); | 118 | static void mousereport(XEvent *); |
119 | static char *kmap(KeySym, uint); | ||
120 | static int match(uint, uint); | ||
119 | 121 | ||
120 | static void run(void); | 122 | static void run(void); |
121 | static void usage(void); | 123 | static void usage(void); |
@@ -1603,6 +1605,52 @@ focus(XEvent *ev) | |||
1603 | } | 1605 | } |
1604 | } | 1606 | } |
1605 | 1607 | ||
1608 | int | ||
1609 | match(uint mask, uint state) | ||
1610 | { | ||
1611 | return mask == XK_ANY_MOD || mask == (state & ~ignoremod); | ||
1612 | } | ||
1613 | |||
1614 | char* | ||
1615 | kmap(KeySym k, uint state) | ||
1616 | { | ||
1617 | Key *kp; | ||
1618 | int i; | ||
1619 | |||
1620 | /* Check for mapped keys out of X11 function keys. */ | ||
1621 | for (i = 0; i < mappedkeyslen; i++) { | ||
1622 | if (mappedkeys[i] == k) | ||
1623 | break; | ||
1624 | } | ||
1625 | if (i == mappedkeyslen) { | ||
1626 | if ((k & 0xFFFF) < 0xFD00) | ||
1627 | return NULL; | ||
1628 | } | ||
1629 | |||
1630 | for (kp = key; kp < key + keyslen; kp++) { | ||
1631 | if (kp->k != k) | ||
1632 | continue; | ||
1633 | |||
1634 | if (!match(kp->mask, state)) | ||
1635 | continue; | ||
1636 | |||
1637 | if (IS_SET(MODE_APPKEYPAD) ? kp->appkey < 0 : kp->appkey > 0) | ||
1638 | continue; | ||
1639 | if (term.numlock && kp->appkey == 2) | ||
1640 | continue; | ||
1641 | |||
1642 | if (IS_SET(MODE_APPCURSOR) ? kp->appcursor < 0 : kp->appcursor > 0) | ||
1643 | continue; | ||
1644 | |||
1645 | if (IS_SET(MODE_CRLF) ? kp->crlf < 0 : kp->crlf > 0) | ||
1646 | continue; | ||
1647 | |||
1648 | return kp->s; | ||
1649 | } | ||
1650 | |||
1651 | return NULL; | ||
1652 | } | ||
1653 | |||
1606 | void | 1654 | void |
1607 | kpress(XEvent *ev) | 1655 | kpress(XEvent *ev) |
1608 | { | 1656 | { |