devdraw: refactor, clean up mac screen

Also turn mac-srv.c into a generic srv.c,
so we can remove the duplication with x11-srv.c.
This commit is contained in:
Russ Cox 2020-01-09 21:47:14 -05:00
parent 843e5af198
commit b1a086dee9
7 changed files with 595 additions and 608 deletions

View file

@ -14,8 +14,6 @@
#include <drawfcall.h> #include <drawfcall.h>
#include "devdraw.h" #include "devdraw.h"
extern void _flushmemscreen(Rectangle);
static Draw sdraw; static Draw sdraw;
Client *client0; Client *client0;
static int drawuninstall(Client*, int); static int drawuninstall(Client*, int);
@ -32,6 +30,8 @@ _initdisplaymemimage(Client *c, Memimage *m)
c->op = SoverD; c->op = SoverD;
} }
// _drawreplacescreen replaces c's screen image with m.
// It is called by the host driver on the main host thread.
void void
_drawreplacescreenimage(Client *c, Memimage *m) _drawreplacescreenimage(Client *c, Memimage *m)
{ {
@ -141,7 +141,7 @@ addflush(Client *c, Rectangle r)
} }
/* emit current state */ /* emit current state */
if(c->flushrect.min.x < c->flushrect.max.x) if(c->flushrect.min.x < c->flushrect.max.x)
_flushmemscreen(c->flushrect); rpc_flushmemscreen(c, c->flushrect);
c->flushrect = r; c->flushrect = r;
c->waste = 0; c->waste = 0;
} }
@ -178,7 +178,7 @@ void
drawflush(Client *c) drawflush(Client *c)
{ {
if(c->flushrect.min.x < c->flushrect.max.x) if(c->flushrect.min.x < c->flushrect.max.x)
_flushmemscreen(c->flushrect); rpc_flushmemscreen(c, c->flushrect);
c->flushrect = Rect(10000, 10000, -10000, -10000); c->flushrect = Rect(10000, 10000, -10000, -10000);
} }

View file

@ -28,6 +28,8 @@ struct Kbdbuf
int wi; int wi;
int stall; int stall;
int alting; int alting;
Rune k[10];
int nk;
}; };
struct Mousebuf struct Mousebuf
@ -75,7 +77,7 @@ struct Client
int rfd; int rfd;
int wfd; int wfd;
void* view; const void* view;
QLock inputlk; QLock inputlk;
Kbdbuf kbd; Kbdbuf kbd;
@ -163,6 +165,22 @@ void _drawreplacescreenimage(Client*, Memimage*);
int _latin1(Rune*, int); int _latin1(Rune*, int);
int parsewinsize(char*, Rectangle*, int*); int parsewinsize(char*, Rectangle*, int*);
int mouseswap(int); int mouseswap(int);
void abortcompose(Client*);
void gfx_abortcompose(Client*);
void gfx_keystroke(Client*, int);
void gfx_mousetrack(Client*, int, int, int, uint);
void rpc_setmouse(Client*, Point);
void rpc_setcursor(Client*, Cursor*, Cursor2*);
void rpc_setlabel(Client*, char*);
void rpc_resizeimg(Client*);
void rpc_resizewindow(Client*, Rectangle);
void rpc_topwin(Client*);
char* rpc_getsnarf(void);
void rpc_putsnarf(char*);
Memimage *rpc_attachscreen(Client*, char*, char*);
void rpc_flushmemscreen(Client*, Rectangle);
extern Client *client0; extern Client *client0;
void servep9p(Client*);

View file

@ -1,19 +0,0 @@
#define setcursor dsetcursor
Memimage *attachscreen(Client*, char*, char*);
void setmouse(Point);
void setcursor(Cursor*, Cursor2*);
void setlabel(char*);
char* getsnarf(void);
void putsnarf(char*);
void topwin(void);
void mousetrack(Client*, int, int, int, uint);
void keystroke(Client*, int);
void kicklabel(char*);
void servep9p(Client*);
void resizeimg(Client*);
void resizewindow(Rectangle);

File diff suppressed because it is too large Load diff

View file

@ -9,6 +9,7 @@ WSYSOFILES=\
devdraw.$O\ devdraw.$O\
latin1.$O\ latin1.$O\
mouseswap.$O\ mouseswap.$O\
srv.$O\
winsize.$O\ winsize.$O\
<|sh ./mkwsysrules.sh <|sh ./mkwsysrules.sh
@ -42,7 +43,7 @@ $O.macargv: $MACARGV
$LD -o $target $prereq $LD -o $target $prereq
%.$O: %.m %.$O: %.m
$CC $CFLAGS $OBJCFLAGS -o $target $stem.m $CC $CFLAGS $OBJCFLAGS -fobjc-arc -o $target $stem.m
CLEANFILES=$O.devdraw $O.macargv $O.drawclient $O.mklatinkbd latin1.h CLEANFILES=$O.devdraw $O.macargv $O.drawclient $O.mklatinkbd latin1.h

View file

@ -53,8 +53,8 @@ if [ $WSYSTYPE = x11 ]; then
echo 'WSYSOFILES=$WSYSOFILES '$XO echo 'WSYSOFILES=$WSYSOFILES '$XO
echo 'WSYSHFILES=x11-inc.h x11-keysym2ucs.h x11-memdraw.h' echo 'WSYSHFILES=x11-inc.h x11-keysym2ucs.h x11-memdraw.h'
elif [ $WSYSTYPE = mac ]; then elif [ $WSYSTYPE = mac ]; then
echo 'WSYSOFILES=$WSYSOFILES mac-draw.o mac-screen.o mac-srv.o' echo 'WSYSOFILES=$WSYSOFILES mac-draw.o mac-screen.o'
echo 'WSYSHFILES=mac-screen.h' echo 'WSYSHFILES='
echo 'MACARGV=macargv.o' echo 'MACARGV=macargv.o'
elif [ $WSYSTYPE = nowsys ]; then elif [ $WSYSTYPE = nowsys ]; then
echo 'WSYSOFILES=nowsys.o' echo 'WSYSOFILES=nowsys.o'

View file

@ -13,12 +13,11 @@
#include <cursor.h> #include <cursor.h>
#include <drawfcall.h> #include <drawfcall.h>
#include "devdraw.h" #include "devdraw.h"
#include "mac-screen.h"
void runmsg(Client*, Wsysmsg*); static void runmsg(Client*, Wsysmsg*);
void replymsg(Client*, Wsysmsg*); static void replymsg(Client*, Wsysmsg*);
void matchkbd(Client*); static void matchkbd(Client*);
void matchmouse(Client*); static void matchmouse(Client*);
int trace = 0; int trace = 0;
@ -55,7 +54,7 @@ servep9p(Client *c)
} }
} }
void static void
replyerror(Client *c, Wsysmsg *m) replyerror(Client *c, Wsysmsg *m)
{ {
char err[256]; char err[256];
@ -70,7 +69,7 @@ replyerror(Client *c, Wsysmsg *m)
* Handle a single wsysmsg. * Handle a single wsysmsg.
* Might queue for later (kbd, mouse read) * Might queue for later (kbd, mouse read)
*/ */
void static void
runmsg(Client *c, Wsysmsg *m) runmsg(Client *c, Wsysmsg *m)
{ {
static uchar buf[65536]; static uchar buf[65536];
@ -80,7 +79,7 @@ runmsg(Client *c, Wsysmsg *m)
switch(m->type){ switch(m->type){
case Tinit: case Tinit:
memimageinit(); memimageinit();
i = attachscreen(c, m->label, m->winsize); i = rpc_attachscreen(c, m->label, m->winsize);
_initdisplaymemimage(c, i); _initdisplaymemimage(c, i);
replymsg(c, m); replymsg(c, m);
break; break;
@ -110,23 +109,25 @@ runmsg(Client *c, Wsysmsg *m)
break; break;
case Tmoveto: case Tmoveto:
setmouse(m->mouse.xy); rpc_setmouse(c, m->mouse.xy);
replymsg(c, m); replymsg(c, m);
break; break;
case Tcursor: case Tcursor:
if(m->arrowcursor) if(m->arrowcursor)
setcursor(nil, nil); rpc_setcursor(c, nil, nil);
else else {
setcursor(&m->cursor, nil); scalecursor(&m->cursor2, &m->cursor);
rpc_setcursor(c, &m->cursor, &m->cursor2);
}
replymsg(c, m); replymsg(c, m);
break; break;
case Tcursor2: case Tcursor2:
if(m->arrowcursor) if(m->arrowcursor)
setcursor(nil, nil); rpc_setcursor(c, nil, nil);
else else
setcursor(&m->cursor, &m->cursor2); rpc_setcursor(c, &m->cursor, &m->cursor2);
replymsg(c, m); replymsg(c, m);
break; break;
@ -136,12 +137,12 @@ runmsg(Client *c, Wsysmsg *m)
break; break;
case Tlabel: case Tlabel:
kicklabel(m->label); rpc_setlabel(c, m->label);
replymsg(c, m); replymsg(c, m);
break; break;
case Trdsnarf: case Trdsnarf:
m->snarf = getsnarf(); m->snarf = rpc_getsnarf();
replymsg(c, m); replymsg(c, m);
free(m->snarf); free(m->snarf);
break; break;
@ -177,12 +178,12 @@ runmsg(Client *c, Wsysmsg *m)
break; break;
case Ttop: case Ttop:
topwin(); rpc_topwin(c);
replymsg(c, m); replymsg(c, m);
break; break;
case Tresize: case Tresize:
resizewindow(m->rect); rpc_resizewindow(c, m->rect);
replymsg(c, m); replymsg(c, m);
break; break;
} }
@ -192,7 +193,7 @@ runmsg(Client *c, Wsysmsg *m)
* Reply to m. * Reply to m.
*/ */
QLock replylock; QLock replylock;
void static void
replymsg(Client *c, Wsysmsg *m) replymsg(Client *c, Wsysmsg *m)
{ {
int n; int n;
@ -224,7 +225,7 @@ replymsg(Client *c, Wsysmsg *m)
/* /*
* Match queued kbd reads with queued kbd characters. * Match queued kbd reads with queued kbd characters.
*/ */
void static void
matchkbd(Client *c) matchkbd(Client *c)
{ {
Wsysmsg m; Wsysmsg m;
@ -243,14 +244,18 @@ matchkbd(Client *c)
} }
} }
/* // matchmouse matches queued mouse reads with queued mouse events.
* Match queued mouse reads with queued mouse events. // It must be called with c->inputlk held.
*/ static void
void
matchmouse(Client *c) matchmouse(Client *c)
{ {
Wsysmsg m; Wsysmsg m;
if(canqlock(&c->inputlk)) {
fprint(2, "misuse of matchmouse\n");
abort();
}
while(c->mouse.ri != c->mouse.wi && c->mousetags.ri != c->mousetags.wi){ while(c->mouse.ri != c->mouse.wi && c->mousetags.ri != c->mousetags.wi){
m.type = Rrdmouse; m.type = Rrdmouse;
m.tag = c->mousetags.t[c->mousetags.ri++]; m.tag = c->mousetags.t[c->mousetags.ri++];
@ -271,10 +276,11 @@ matchmouse(Client *c)
} }
void void
mousetrack(Client *c, int x, int y, int b, uint ms) gfx_mousetrack(Client *c, int x, int y, int b, uint ms)
{ {
Mouse *m; Mouse *m;
qlock(&c->inputlk);
if(x < c->mouserect.min.x) if(x < c->mouserect.min.x)
x = c->mouserect.min.x; x = c->mouserect.min.x;
if(x > c->mouserect.max.x) if(x > c->mouserect.max.x)
@ -284,7 +290,6 @@ mousetrack(Client *c, int x, int y, int b, uint ms)
if(y > c->mouserect.max.y) if(y > c->mouserect.max.y)
y = c->mouserect.max.y; y = c->mouserect.max.y;
qlock(&c->inputlk);
// If reader has stopped reading, don't bother. // If reader has stopped reading, don't bother.
// If reader is completely caught up, definitely queue. // If reader is completely caught up, definitely queue.
// Otherwise, queue only button change events. // Otherwise, queue only button change events.
@ -310,36 +315,50 @@ mousetrack(Client *c, int x, int y, int b, uint ms)
qunlock(&c->inputlk); qunlock(&c->inputlk);
} }
void // kputc adds ch to the keyboard buffer.
// It must be called with c->inputlk held.
static void
kputc(Client *c, int ch) kputc(Client *c, int ch)
{ {
qlock(&c->inputlk); if(canqlock(&c->inputlk)) {
fprint(2, "misuse of kputc\n");
abort();
}
c->kbd.r[c->kbd.wi++] = ch; c->kbd.r[c->kbd.wi++] = ch;
if(c->kbd.wi == nelem(c->kbd.r)) if(c->kbd.wi == nelem(c->kbd.r))
c->kbd.wi = 0; c->kbd.wi = 0;
if(c->kbd.ri == c->kbd.wi) if(c->kbd.ri == c->kbd.wi)
c->kbd.stall = 1; c->kbd.stall = 1;
matchkbd(c); matchkbd(c);
}
// gfx_abortcompose stops any pending compose sequence,
// because a mouse button has been clicked.
// It is called from the graphics thread with no locks held.
void
gfx_abortcompose(Client *c)
{
qlock(&c->inputlk);
if(c->kbd.alting) {
c->kbd.alting = 0;
c->kbd.nk = 0;
}
qunlock(&c->inputlk); qunlock(&c->inputlk);
} }
// gfx_keystroke records a single-rune keystroke.
// It is called from the graphics thread with no locks held.
void void
abortcompose(Client *c) gfx_keystroke(Client *c, int ch)
{ {
if(c->kbd.alting)
keystroke(c, Kalt);
}
void
keystroke(Client *c, int ch)
{
static Rune k[10];
static int nk;
int i; int i;
qlock(&c->inputlk);
if(ch == Kalt){ if(ch == Kalt){
c->kbd.alting = !c->kbd.alting; c->kbd.alting = !c->kbd.alting;
nk = 0; c->kbd.nk = 0;
qunlock(&c->inputlk);
return; return;
} }
if(ch == Kcmd+'r') { if(ch == Kcmd+'r') {
@ -349,30 +368,35 @@ keystroke(Client *c, int ch)
c->forcedpi = 100; c->forcedpi = 100;
else else
c->forcedpi = 225; c->forcedpi = 225;
resizeimg(c); qunlock(&c->inputlk);
rpc_resizeimg(c);
return; return;
} }
if(!c->kbd.alting){ if(!c->kbd.alting){
kputc(c, ch); kputc(c, ch);
qunlock(&c->inputlk);
return; return;
} }
if(nk >= nelem(k)) // should not happen if(c->kbd.nk >= nelem(c->kbd.k)) // should not happen
nk = 0; c->kbd.nk = 0;
k[nk++] = ch; c->kbd.k[c->kbd.nk++] = ch;
ch = _latin1(k, nk); ch = _latin1(c->kbd.k, c->kbd.nk);
if(ch > 0){ if(ch > 0){
c->kbd.alting = 0; c->kbd.alting = 0;
kputc(c, ch); kputc(c, ch);
nk = 0; c->kbd.nk = 0;
qunlock(&c->inputlk);
return; return;
} }
if(ch == -1){ if(ch == -1){
c->kbd.alting = 0; c->kbd.alting = 0;
for(i=0; i<nk; i++) for(i=0; i<c->kbd.nk; i++)
kputc(c, k[i]); kputc(c, c->kbd.k[i]);
nk = 0; c->kbd.nk = 0;
qunlock(&c->inputlk);
return; return;
} }
// need more input // need more input
qunlock(&c->inputlk);
return; return;
} }