ref: 811c3e8d7806adb1bfc766d9963021934ecef84c
parent: d50ca72774732c059c34286e2a74919c16a17c20
author: ftrvxmtrx <[email protected]>
date: Fri May 17 21:01:34 EDT 2013
nusb/kb: use a flag to indicate extended code; fix the most unix-friendly key on se/fi kbd layout
--- a/sys/src/cmd/nusb/kb/kb.c
+++ b/sys/src/cmd/nusb/kb/kb.c
@@ -57,6 +57,11 @@
*/
/*
+ * scan codes >= 0x80 are extended (E0 XX)
+ */
+#define isext(sc) ((sc) >= 0x80)
+
+/*
* key code to scan code; for the page table used by
* the logitech bluetooth keyboard.
*/
@@ -70,15 +75,15 @@
[0x28] 0x1c, 0x1, 0xe, 0xf, 0x39, 0xc, 0xd, 0x1a,
[0x30] 0x1b, 0x2b, 0x2b, 0x27, 0x28, 0x29, 0x33, 0x34,
[0x38] 0x35, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40,
-[0x40] 0x41, 0x42, 0x43, 0x44, 0x57, 0x58, 0x63, 0x46,
-[0x48] 0x77, 0x52, 0x47, 0x49, 0x53, 0x4f, 0x51, 0x4d,
-[0x50] 0x4b, 0x50, 0x48, 0x45, 0x35, 0x37, 0x4a, 0x4e,
-[0x58] 0x1c, 0x4f, 0x50, 0x51, 0x4b, 0x4c, 0x4d, 0x47,
-[0x60] 0x48, 0x49, 0x52, 0x53, 0x56, 0x7f, 0x74, 0x75,
-[0x68] 0x55, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
-[0x70] 0x78, 0x79, 0x7a, 0x7b, 0x0, 0x0, 0x0, 0x0,
-[0x78] 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x71,
-[0x80] 0x73, 0x72, 0x0, 0x0, 0x0, 0x7c, 0x0, 0x0,
+[0x40] 0x41, 0x42, 0x43, 0x44, 0x57, 0x58, 0xe3, 0x46,
+[0x48] 0xf7, 0xd2, 0xc7, 0xc9, 0xd3, 0xcf, 0xd1, 0xcd,
+[0x50] 0xc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SCesc1, 0};
- s[1] = sc;
- if(esc && sc != 0)
+ s[1] = sc&Keymask;
+ if(s[1] == 0)
+ return;
+
+ s[1] |= up;
+ if(isext(sc))
write(fd, s, 2);
- else if(sc != 0)
+ else
write(fd, s+1, 1);
}
@@ -563,7 +572,7 @@
Channel *repeatc, *sleepc;
int kbdinfd;
ulong l, t;
- uchar esc1, sc;
+ uchar sc;
Alt a[3];
repeatc = f->repeatc;
@@ -590,13 +599,14 @@
l = recvul(repeatc);
continue;
}
- esc1 = l >> 8;
sc = l;
+ if((l>>8) != 0)
+ sc |= 0x80;
t = Kbdelay;
if(alt(a) == 1){
t = Kbrepeat;
while(alt(a) == 1)
- putscan(kbdinfd, esc1, sc);
+ putscan(kbdinfd, sc, 0);
}
}
if(sleepc != nil)
@@ -612,11 +622,11 @@
}
static void
-startrepeat(KDev *f, uchar esc1, uchar sc)
+startrepeat(KDev *f, uchar sc)
{
ulong c;
- if(esc1)
+ if(isext(sc))
c = SCesc1 << 8 | (sc & 0xff);
else
c = sc;
@@ -623,8 +633,6 @@
sendul(f->repeatc, c);
}
-#define hasesc1(sc) (((sc) >= 0x47) || ((sc) == 0x38))
-
/*
* This routine diffs the state with the last known state
* and invents the scan codes that would have been sent
@@ -654,8 +662,8 @@
break;
if(j == n && buf[i] != 0){
dk = sctab[buf[i]];
- putscan(fd, hasesc1(dk), dk);
- startrepeat(f, hasesc1(dk), dk);
+ putscan(fd, dk, 0);
+ startrepeat(f, dk);
}
}
@@ -667,7 +675,7 @@
break;
if(j == n && obuf[i] != 0){
uk = sctab[obuf[i]];
- putscan(fd, hasesc1(uk), uk|Keyup);
+ putscan(fd, uk, Keyup);
}
}
if(uk && (dk == 0 || dk == uk)){