ref: b503317e6c71100ce331e24715d8cc538781840b
parent: 1ddcc3285eb5ade62c7ce95c800c0665981e3361
author: Sigrid Solveig Haflínudóttir <248148+ftrvxmtrx@users.noreply.github.com>
date: Sun Dec 16 19:19:54 EST 2012
kbd/kbdbind: initial version
--- /dev/null
+++ b/kbd/kbdbind.c
@@ -1,0 +1,72 @@
+#include <u.h>
+#include <libc.h>
+
+enum {
+ NumF = 12
+};
+
+static char *funcs[NumF];
+
+void main(int, char**) {
+ funcs[0] = "Fi";
+ funcs[1] = "Ru";
+ funcs[2] = "window";
+
+ int in = open("/dev/kbd", OREAD);
+ if(in < 0)
+ sysfatal("open failed: %r");
+
+ int p[2];
+ pipe(p);
+ int fd = create("/srv/kbdbind", OWRITE, 0600);
+ if(fd < 0)
+ sysfatal("create failed: %r");
+ fprint(fd, "%d", p[0]);
+ close(fd);
+ close(p[0]);
+ int out = p[1];
+
+ for(;;) {
+ uchar b[128];
+ long size = read(in, b, sizeof(b));
+
+ if(size < 0)
+ break;
+ for(long i = 0; i < size;) {
+ int isfunc =
+ size >= 5 &&
+ (b[i] == 'k' || b[i] == 'c') &&
+ b[i+1] == 0xef &&
+ b[i+2] == 0x80 &&
+ (b[i+3] >= 0x81 && b[i+3] <= (0x81+NumF));
+ int funcid = isfunc ? b[i+3] - 0x81 : -1;
+
+ if(funcid < 0 || funcs[funcid] == nil) {
+ int k = i;
+ for(; i < size; i++) {
+ if(!b[i]) {
+ i++;
+ break;
+ }
+ }
+ if(i - k > 0) {
+ write(out, &b[k], i - k);
+ }
+ } else {
+ int down = b[i] == 'k';
+ i += 5;
+ if(!down)
+ continue;
+ switch(rfork(RFFDG|RFREND|RFPROC|RFNOWAIT)) {
+ case 0:
+ if(execl("/bin/rc", "/bin/rc", funcs[funcid], 0) < 0)
+ fprint(2, "execl failed: %r");
+ break;
+ case -1:
+ fprint(2, "rfork failed: %r");
+ break;
+ }
+ }
+ }
+ }
+}
--- /dev/null
+++ b/kbd/mkfile
@@ -1,0 +1,7 @@
+</$objtype/mkfile
+
+TARG=kbdbind
+OFILES=kbdbind.$O
+BIN=/$objtype/bin
+
+</sys/src/cmd/mkone
--- /dev/null
+++ b/kbd/rio-kbd-file-option.patch
@@ -1,0 +1,92 @@
+diff -r 9e12b43399af sys/man/1/rio
+--- a/sys/man/1/rio Fri Dec 14 17:16:50 2012 +0100
++++ b/sys/man/1/rio Sun Dec 16 22:38:55 2012 +0100
+@@ -10,6 +10,9 @@
+ .BI "-k '"kbdcmd '
+ ]
+ [
++.BI "-K '"kbdfile '
++]
++[
+ .B -s
+ ]
+ [
+@@ -89,6 +92,14 @@
+ program described in
+ .IR bitsyload (1)
+ is the usual choice.
++The
++.B -K
++option instructs
++.I rio
++to read keyboard input from
++.I kbdfile
++instead of a default
++.BR /dev/kbd .
+ .PP
+ The
+ .B -s
+diff -r 9e12b43399af sys/man/4/rio
+--- a/sys/man/4/rio Fri Dec 14 17:16:50 2012 +0100
++++ b/sys/man/4/rio Sun Dec 16 22:38:55 2012 +0100
+@@ -12,6 +12,10 @@
+ .BI ' kbdcmd '
+ ]
+ [
++.B -K
++.BI ' kbdfile '
++]
++[
+ .B -s
+ ]
+ [
+diff -r 9e12b43399af sys/src/cmd/rio/rio.c
+--- a/sys/src/cmd/rio/rio.c Fri Dec 14 17:16:50 2012 +0100
++++ b/sys/src/cmd/rio/rio.c Sun Dec 16 22:38:55 2012 +0100
+@@ -45,6 +45,7 @@
+ Channel* initkbd(void);
+
+ char *fontname;
++char *kbdname;
+
+ enum
+ {
+@@ -112,7 +113,7 @@
+ void
+ usage(void)
+ {
+- fprint(2, "usage: rio [-b] [-f font] [-i initcmd] [-k kbdcmd] [-s]\n");
++ fprint(2, "usage: rio [-b] [-f font] [-i initcmd] [-k kbdcmd] [-K kbdfile] [-s]\n");
+ exits("usage");
+ }
+
+@@ -153,6 +154,11 @@
+ if(kbdin == nil)
+ usage();
+ break;
++ case 'K':
++ kbdname = ARGF();
++ if(kbdname == nil)
++ usage();
++ break;
+ case 's':
+ scrolling = TRUE;
+ break;
+@@ -164,6 +170,8 @@
+ startdir = estrdup(buf);
+ if(fontname == nil)
+ fontname = getenv("font");
++ if(kbdname == nil)
++ kbdname = "/dev/kbd";
+ s = getenv("tabstop");
+ if(s != nil)
+ maxtab = strtol(s, nil, 0);
+@@ -1302,7 +1310,7 @@
+ if(sendp(c, nil) <= 0)
+ return;
+
+- if((kfd = open("/dev/kbd", OREAD)) >= 0){
++ if((kfd = open(kbdname, OREAD)) >= 0){
+ close(fd);
+
+ /* read kbd state */