commit 4505f026e54bc9efe96d4e172612da2ff5482964
parent 027ba9cd86ee8ff9be11ab58d2b961e6cfc48acb
Author: robert <robertrussell.72001@gmail.com>
Date: Sat, 5 Jun 2021 18:20:18 -0700
Fix some obvious bugs
Diffstat:
| M | config.def.h | | | 42 | +++++++++++++++++++++--------------------- |
| M | x.c | | | 26 | ++++++++++++++------------ |
2 files changed, 35 insertions(+), 33 deletions(-)
diff --git a/config.def.h b/config.def.h
@@ -204,6 +204,20 @@ static Shortcut shortcuts[] = {
*/
static uint ignoremod = Mod2Mask|XK_SWITCH_MOD;
+#define CURS (1<<0)
+#define KPAD (1<<1)
+#define NMLK (1<<2)
+#define MODOFFS 3
+#define S (1<<3)
+#define A (1<<4)
+#define C (1<<5)
+#define ALLM (S|A|C)
+
+#define STR(s_) kencstr, .arg.str.l = sizeof(s_)-1, .arg.str.s = (s_)
+#define CSI(n_,m_,c_) kenccsi, .arg.csi.n = (n_), .arg.csi.m = (m_), .arg.csi.c = (c_)
+#define TILDE(n) CSI((n),0,'~')
+#define UNICODE(cp) CSI((cp),S,'u')
+
typedef union {
struct {
uint l;
@@ -249,35 +263,21 @@ kcsi(char *buf, size_t len, uint state, uint n, uchar m, char c)
{
uint mod;
- mod = (state >> MODOFFS) & ~arg.csi.m;
+ mod = (state & ~m) >> MODOFFS;
if (mod > 0)
- return snprintf(buf, len, "\033[%d;%d%c", arg.csi.n, mod+1, arg.csi.c);
+ return snprintf(buf, len, "\033[%d;%d%c", n, mod+1, c);
else if (n > 1)
- return snprintf(buf, len, "\033[%d%c", arg.csi.n, arg.csi.c);
+ return snprintf(buf, len, "\033[%d%c", n, c);
else
- return snprintf(buf, len, "\033[%c", arg.csi.c);
+ return snprintf(buf, len, "\033[%c", c);
}
int
kenccsi(char *buf, size_t len, KeySym sym, uint state, KeyArg arg)
{
- kcsi(buf, len, state, arg.csi.n, arg.csi.m, arg.csi.c)
+ kcsi(buf, len, state, arg.csi.n, arg.csi.m, arg.csi.c);
}
-#define CURS (1<<0)
-#define KPAD (1<<1)
-#define NMLK (1<<2)
-#define MODOFFS 3
-#define S (1<<3)
-#define A (1<<4)
-#define C (1<<5)
-#define ALLM (S|A|C)
-
-#define STR(s) kencstr, .arg.str.l = sizeof(s)-1, .arg.str.s = (s)
-#define CSI(n_,m_,c_) kenccsi, .arg.csi.n = (n_), .arg.csi.m = (m_), .arg.csi.c = (c_)
-#define TILDE(n) CSI((n),0,'~')
-#define UNICODE(cp) CSI((cp),S,'u')
-
Key keys[] = {
/* SHORTCUTS (must be first) */
/* XK_Print */
@@ -329,7 +329,7 @@ Key keys[] = {
{ XK_Find, 0, 0, TILDE(1) },
/* KEYPAD */
- { XK_KP_Enter, KPAD, NKLK|ALLM, STR("\033OM") },
+ { XK_KP_Enter, KPAD, NMLK|ALLM, STR("\033OM") },
{ XK_KP_Enter, 0, ALLM, STR("\r") },
{ XK_KP_Enter, A, C|S, STR("\033\r") },
{ XK_KP_Enter, 0, 0, CSI('\r',0,'u') },
@@ -358,7 +358,7 @@ Key keys[] = {
{ XK_KP_Begin, 0, 0, CSI(1,0,'E') },
{ XK_KP_Insert, 0, 0, TILDE(2) },
{ XK_KP_Delete, 0, 0, TILDE(3) },
- { XK_KP_Equal, KPAD, NKLK|ALLM, STR("\033OX") },
+ { XK_KP_Equal, KPAD, NMLK|ALLM, STR("\033OX") },
{ XK_KP_Multiply, KPAD, NMLK|ALLM, STR("\033Oj") },
{ XK_KP_Add, KPAD, NMLK|ALLM, STR("\033Ok") },
{ XK_KP_Separator, KPAD, NMLK|ALLM, STR("\033Ol") },
diff --git a/x.c b/x.c
@@ -1754,7 +1754,7 @@ match(uint mask, uint state)
int
scmatch(uint state, uint set, uint clr)
{
- return (set & ~state) | (clr & state) == 0;
+ return ((set & ~state) | (clr & state)) == 0;
}
void
@@ -1797,24 +1797,26 @@ kpress(XEvent *ev)
if (k->sym == ksym && scmatch(state, k->set, k->clr)) {
len = k->fn(buf, sizeof buf, ksym, state, k->arg);
ttywrite(buf, len, 1);
- return
+ return;
}
}
/* 3. latin 1 */
if (0x20 <= ksym && ksym < 0x7f) {
- if ((state&C) > 0 && !(0x40 <= ksym && ksym < 0x60)) {
- len = kcsi(buf, sizeof buf, state, ksym, S, 'u');
- ttywrite(buf, len, 1);
- return;
- }
buf[0] = ksym;
len = 1;
- if (state&C > 0)
- buf[0] -= 0x40;
- if (state&A > 0) {
+ if ((state&C) > 0) {
+ if ('a' <= ksym && ksym <= 'z') {
+ buf[0] -= 0x60;
+ } else {
+ len = kcsi(buf, sizeof buf, state, ksym, S, 'u');
+ ttywrite(buf, len, 1);
+ return;
+ }
+ }
+ if ((state&A) > 0) {
+ buf[1] = buf[0];
buf[0] = '\033';
- buf[1] = ksym;
len = 2;
}
ttywrite(buf, len, 1);
@@ -1825,7 +1827,7 @@ kpress(XEvent *ev)
return;
/* 4. modified UTF8-encoded unicode */
- if (state&ALLM > 0 && utf8decode(buf, &c, len) == len
+ if ((state&ALLM) > 0 && utf8decode(buf, &c, len) == len
&& c != UTF_INVALID) {
len = kcsi(buf, sizeof buf, state, c, S, 'u');
ttywrite(buf, len, 1);