aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDevin J. Pohly <djpohly@gmail.com>2017-10-11 08:47:14 -0500
committerDevin J. Pohly <djpohly@gmail.com>2018-02-25 21:53:24 -0600
commited132e11271d18a5d8aa163096bc6192c694bc47 (patch)
tree81b7a8ef14efadfaee06e7848a1c7ab953cd5ce6
parentdbe8676d7d69651132bde2b6d9ec3787cbbc552a (diff)
downloadst-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.h6
-rw-r--r--st.c58
-rw-r--r--st.h18
-rw-r--r--x.c48
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 */
212static KeySym mappedkeys[] = { -1 }; 212KeySym 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 */
218static uint ignoremod = Mod2Mask|XK_SWITCH_MOD; 218uint 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 */
231static Key key[] = { 231Key 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},
diff --git a/st.c b/st.c
index 839dc94..1a8fa1f 100644
--- a/st.c
+++ b/st.c
@@ -110,16 +110,6 @@ typedef struct {
110 int narg; /* nb of args */ 110 int narg; /* nb of args */
111} STREscape; 111} STREscape;
112 112
113typedef 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 */
124static void clipcopy(const Arg *); 114static void clipcopy(const Arg *);
125static void clippaste(const Arg *); 115static void clippaste(const Arg *);
@@ -223,6 +213,8 @@ size_t colornamelen = LEN(colorname);
223size_t mshortcutslen = LEN(mshortcuts); 213size_t mshortcutslen = LEN(mshortcuts);
224size_t shortcutslen = LEN(shortcuts); 214size_t shortcutslen = LEN(shortcuts);
225size_t selmaskslen = LEN(selmasks); 215size_t selmaskslen = LEN(selmasks);
216size_t keyslen = LEN(key);
217size_t mappedkeyslen = LEN(mappedkeys);
226 218
227ssize_t 219ssize_t
228xwrite(int fd, const char *s, size_t len) 220xwrite(int fd, const char *s, size_t len)
@@ -2550,54 +2542,8 @@ redraw(void)
2550 draw(); 2542 draw();
2551} 2543}
2552 2544
2553int
2554match(uint mask, uint state)
2555{
2556 return mask == XK_ANY_MOD || mask == (state & ~ignoremod);
2557}
2558
2559void 2545void
2560numlock(const Arg *dummy) 2546numlock(const Arg *dummy)
2561{ 2547{
2562 term.numlock ^= 1; 2548 term.numlock ^= 1;
2563} 2549}
2564
2565char*
2566kmap(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}
diff --git a/st.h b/st.h
index 372462d..c255b7c 100644
--- a/st.h
+++ b/st.h
@@ -176,6 +176,16 @@ typedef struct {
176 const Arg arg; 176 const Arg arg;
177} Shortcut; 177} Shortcut;
178 178
179typedef 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
179void die(const char *, ...); 189void die(const char *, ...);
180void redraw(void); 190void redraw(void);
181 191
@@ -184,7 +194,6 @@ void tnew(int, int);
184void tresize(int, int); 194void tresize(int, int);
185void tsetdirt(int, int); 195void tsetdirt(int, int);
186void tsetdirtattr(int); 196void tsetdirtattr(int);
187int match(uint, uint);
188void ttynew(void); 197void ttynew(void);
189size_t ttyread(void); 198size_t ttyread(void);
190void ttyresize(int, int); 199void ttyresize(int, int);
@@ -193,9 +202,7 @@ void ttywrite(const char *, size_t);
193 202
194void resettitle(void); 203void resettitle(void);
195 204
196char *kmap(KeySym, uint);
197void selclear(void); 205void selclear(void);
198
199void selinit(void); 206void selinit(void);
200void selnormalize(void); 207void selnormalize(void);
201int selected(int, int); 208int selected(int, int);
@@ -255,7 +262,12 @@ extern MouseShortcut mshortcuts[];
255extern size_t mshortcutslen; 262extern size_t mshortcutslen;
256extern Shortcut shortcuts[]; 263extern Shortcut shortcuts[];
257extern size_t shortcutslen; 264extern size_t shortcutslen;
265extern KeySym mappedkeys[];
266extern size_t mappedkeyslen;
267extern uint ignoremod;
258extern uint forceselmod; 268extern uint forceselmod;
269extern Key key[];
270extern size_t keyslen;
259extern uint selmasks[]; 271extern uint selmasks[];
260extern size_t selmaskslen; 272extern size_t selmaskslen;
261extern char ascii_printable[]; 273extern char ascii_printable[];
diff --git a/x.c b/x.c
index 1b656ac..371a467 100644
--- a/x.c
+++ b/x.c
@@ -116,6 +116,8 @@ static void selrequest(XEvent *);
116static void selcopy(Time); 116static void selcopy(Time);
117static void getbuttoninfo(XEvent *); 117static void getbuttoninfo(XEvent *);
118static void mousereport(XEvent *); 118static void mousereport(XEvent *);
119static char *kmap(KeySym, uint);
120static int match(uint, uint);
119 121
120static void run(void); 122static void run(void);
121static void usage(void); 123static void usage(void);
@@ -1603,6 +1605,52 @@ focus(XEvent *ev)
1603 } 1605 }
1604} 1606}
1605 1607
1608int
1609match(uint mask, uint state)
1610{
1611 return mask == XK_ANY_MOD || mask == (state & ~ignoremod);
1612}
1613
1614char*
1615kmap(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
1606void 1654void
1607kpress(XEvent *ev) 1655kpress(XEvent *ev)
1608{ 1656{