Skip to content

Commit

Permalink
devdraw, libdraw: handle keyboard runes > U+FFFF
Browse files Browse the repository at this point in the history
Runes in Plan 9 were limited to the 16-bit BMP when I drew up
the RPC protocol between graphical programs and devdraw
a long time ago. Now that they can be 32-bit, use a 32-bit wire
encoding too. A new message number to avoid problems with
other clients (like 9fans.net/go).

Add keyboard shortcut alt : , for U+1F602, face with tears of joy,
to test that it all works.
  • Loading branch information
rsc committed May 19, 2020
1 parent b4cc38f commit d25d0ca
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 8 deletions.
11 changes: 8 additions & 3 deletions include/drawfcall.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,19 @@ tag[1] Rbouncemouse
tag[1] Trdkbd
tag[1] Rrdkbd rune[2]
tag[1] Trdkbd4
tag[1] Rrdkbd4 rune[4]
tag[1] Tlabel label[s]
tag[1] Rlabel
tag[1] Rlabel
tag[1] Tctxt wsysid[s]
tag[1] Rctxt
tag[1] Tinit winsize[s] label[s] font[s]
tag[1] Rinit
tag[1] Trdsnarf
tag[1] Trdsnarf
tag[1] Rrdsnarf snarf[s]
tag[1] Twrsnarf snarf[s]
Expand All @@ -47,7 +50,7 @@ tag[1] Ttop
tag[1] Rtop
tag[1] Tresize rect[4*4]
tag[1] Rresize
tag[1] Rresize
*/


Expand Down Expand Up @@ -99,6 +102,8 @@ enum {
Rcursor2,
Tctxt = 30,
Rctxt,
Trdkbd4 = 32,
Rrdkbd4,
Tmax,
};

Expand Down
1 change: 1 addition & 0 deletions lib/keyboard
Original file line number Diff line number Diff line change
Expand Up @@ -584,3 +584,4 @@
F015 ZA  raw alt (plan 9 specific)
F016 ZS  raw shift (plan 9 specific)
F017 ZC  raw ctl (plan 9 specific)
1F602 :, 😂 face with tears of joy
2 changes: 1 addition & 1 deletion src/cmd/devdraw/mklatinkbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ readfile(char *fname)

r = strtol(line, nil, 16);
p = strchr(line, ' ');
if(r == 0 || p != line+4 || p[0] != ' ' || p[1] != ' ') {
if(r == 0 || (p != line+4 && p != line+5) || p[0] != ' ' || (p == line+4 && p[1] != ' ')) {
fprint(2, "%s:%d: cannot parse line\n", fname, lineno);
continue;
}
Expand Down
9 changes: 7 additions & 2 deletions src/cmd/devdraw/srv.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,14 +229,15 @@ runmsg(Client *c, Wsysmsg *m)
break;

case Trdkbd:
case Trdkbd4:
qlock(&c->eventlk);
if((c->kbdtags.wi+1)%nelem(c->kbdtags.t) == c->kbdtags.ri) {
qunlock(&c->eventlk);
werrstr("too many queued keyboard reads");
replyerror(c, m);
break;
}
c->kbdtags.t[c->kbdtags.wi++] = m->tag;
c->kbdtags.t[c->kbdtags.wi++] = (m->tag<<1) | (m->type==Trdkbd4);
if(c->kbdtags.wi == nelem(c->kbdtags.t))
c->kbdtags.wi = 0;
c->kbd.stall = 0;
Expand Down Expand Up @@ -357,13 +358,17 @@ replymsg(Client *c, Wsysmsg *m)
static void
matchkbd(Client *c)
{
int tag;
Wsysmsg m;

if(c->kbd.stall)
return;
while(c->kbd.ri != c->kbd.wi && c->kbdtags.ri != c->kbdtags.wi){
tag = c->kbdtags.t[c->kbdtags.ri++];
m.type = Rrdkbd;
m.tag = c->kbdtags.t[c->kbdtags.ri++];
if(tag&1)
m.type = Rrdkbd4;
m.tag = tag>>1;
if(c->kbdtags.ri == nelem(c->kbdtags.t))
c->kbdtags.ri = 0;
m.rune = c->kbd.r[c->kbd.ri++];
Expand Down
2 changes: 1 addition & 1 deletion src/libdraw/drawclient.c
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ _displayrdkbd(Display *d, Rune *r)
{
Wsysmsg tx, rx;

tx.type = Trdkbd;
tx.type = Trdkbd4;
if(displayrpc(d, &tx, &rx, nil) < 0)
return -1;
*r = rx.rune;
Expand Down
15 changes: 15 additions & 0 deletions src/libdraw/drawfcall.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ sizeW2M(Wsysmsg *m)
case Rcursor:
case Rcursor2:
case Trdkbd:
case Trdkbd4:
case Rlabel:
case Rctxt:
case Rinit:
Expand All @@ -73,6 +74,8 @@ sizeW2M(Wsysmsg *m)
return 4+1+1+_stringsize(m->error);
case Rrdkbd:
return 4+1+1+2;
case Rrdkbd4:
return 4+1+1+4;
case Tlabel:
return 4+1+1+_stringsize(m->label);
case Tctxt:
Expand Down Expand Up @@ -117,6 +120,7 @@ convW2M(Wsysmsg *m, uchar *p, uint n)
case Rcursor:
case Rcursor2:
case Trdkbd:
case Trdkbd4:
case Rlabel:
case Rctxt:
case Rinit:
Expand Down Expand Up @@ -166,6 +170,9 @@ convW2M(Wsysmsg *m, uchar *p, uint n)
case Rrdkbd:
PUT2(p+6, m->rune);
break;
case Rrdkbd4:
PUT(p+6, m->rune);
break;
case Tlabel:
PUTSTRING(p+6, m->label);
break;
Expand Down Expand Up @@ -221,6 +228,7 @@ convM2W(uchar *p, uint n, Wsysmsg *m)
case Rcursor:
case Rcursor2:
case Trdkbd:
case Trdkbd4:
case Rlabel:
case Rctxt:
case Rinit:
Expand Down Expand Up @@ -270,6 +278,9 @@ convM2W(uchar *p, uint n, Wsysmsg *m)
case Rrdkbd:
GET2(p+6, m->rune);
break;
case Rrdkbd4:
GET(p+6, m->rune);
break;
case Tlabel:
GETSTRING(p+6, &m->label);
break;
Expand Down Expand Up @@ -360,6 +371,10 @@ drawfcallfmt(Fmt *fmt)
return fmtprint(fmt, "Trdkbd");
case Rrdkbd:
return fmtprint(fmt, "Rrdkbd rune=%C", m->rune);
case Trdkbd4:
return fmtprint(fmt, "Trdkbd4");
case Rrdkbd4:
return fmtprint(fmt, "Rrdkbd4 rune=%C", m->rune);
case Tlabel:
return fmtprint(fmt, "Tlabel label='%s'", m->label);
case Rlabel:
Expand Down
2 changes: 1 addition & 1 deletion src/libdraw/event.c
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ extract(int canblock)
}
}else if(i == Skeyboard){
if(eslave[i].rpc == nil)
eslave[i].rpc = startrpc(Trdkbd);
eslave[i].rpc = startrpc(Trdkbd4);
if(eslave[i].rpc){
/* if ready, don't block in select */
if(eslave[i].rpc->p)
Expand Down

2 comments on commit d25d0ca

@rsc
Copy link
Contributor Author

@rsc rsc commented on d25d0ca Oct 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I use fontsrv fonts (/mnt/font/...) on a Mac, which does good fallback.
I don't know as much about fontsrv on other systems.

@jxy
Copy link
Contributor

@jxy jxy commented on d25d0ca Oct 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.