aboutsummaryrefslogtreecommitdiffstats
path: root/x.c
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 /x.c
parentdbe8676d7d69651132bde2b6d9ec3787cbbc552a (diff)
downloadst-ed132e11271d18a5d8aa163096bc6192c694bc47.tar.gz
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>
Diffstat (limited to 'x.c')
-rw-r--r--x.c48
1 files changed, 48 insertions, 0 deletions
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 *);
static void selcopy(Time);
static void getbuttoninfo(XEvent *);
static void mousereport(XEvent *);
+static char *kmap(KeySym, uint);
+static int match(uint, uint);
static void run(void);
static void usage(void);
@@ -1603,6 +1605,52 @@ focus(XEvent *ev)
}
}
+int
+match(uint mask, uint state)
+{
+ return mask == XK_ANY_MOD || mask == (state & ~ignoremod);
+}
+
+char*
+kmap(KeySym k, uint state)
+{
+ Key *kp;
+ int i;
+
+ /* Check for mapped keys out of X11 function keys. */
+ for (i = 0; i < mappedkeyslen; i++) {
+ if (mappedkeys[i] == k)
+ break;
+ }
+ if (i == mappedkeyslen) {
+ if ((k & 0xFFFF) < 0xFD00)
+ return NULL;
+ }
+
+ for (kp = key; kp < key + keyslen; kp++) {
+ if (kp->k != k)
+ continue;
+
+ if (!match(kp->mask, state))
+ continue;
+
+ if (IS_SET(MODE_APPKEYPAD) ? kp->appkey < 0 : kp->appkey > 0)
+ continue;
+ if (term.numlock && kp->appkey == 2)
+ continue;
+
+ if (IS_SET(MODE_APPCURSOR) ? kp->appcursor < 0 : kp->appcursor > 0)
+ continue;
+
+ if (IS_SET(MODE_CRLF) ? kp->crlf < 0 : kp->crlf > 0)
+ continue;
+
+ return kp->s;
+ }
+
+ return NULL;
+}
+
void
kpress(XEvent *ev)
{
remember that computers suck.