mirror of
https://github.com/9fans/plan9port.git
synced 2025-01-24 11:41:58 +00:00
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:
parent
843e5af198
commit
b1a086dee9
7 changed files with 595 additions and 608 deletions
|
@ -14,8 +14,6 @@
|
|||
#include <drawfcall.h>
|
||||
#include "devdraw.h"
|
||||
|
||||
extern void _flushmemscreen(Rectangle);
|
||||
|
||||
static Draw sdraw;
|
||||
Client *client0;
|
||||
static int drawuninstall(Client*, int);
|
||||
|
@ -32,6 +30,8 @@ _initdisplaymemimage(Client *c, Memimage *m)
|
|||
c->op = SoverD;
|
||||
}
|
||||
|
||||
// _drawreplacescreen replaces c's screen image with m.
|
||||
// It is called by the host driver on the main host thread.
|
||||
void
|
||||
_drawreplacescreenimage(Client *c, Memimage *m)
|
||||
{
|
||||
|
@ -141,7 +141,7 @@ addflush(Client *c, Rectangle r)
|
|||
}
|
||||
/* emit current state */
|
||||
if(c->flushrect.min.x < c->flushrect.max.x)
|
||||
_flushmemscreen(c->flushrect);
|
||||
rpc_flushmemscreen(c, c->flushrect);
|
||||
c->flushrect = r;
|
||||
c->waste = 0;
|
||||
}
|
||||
|
@ -178,7 +178,7 @@ void
|
|||
drawflush(Client *c)
|
||||
{
|
||||
if(c->flushrect.min.x < c->flushrect.max.x)
|
||||
_flushmemscreen(c->flushrect);
|
||||
rpc_flushmemscreen(c, c->flushrect);
|
||||
c->flushrect = Rect(10000, 10000, -10000, -10000);
|
||||
}
|
||||
|
||||
|
|
|
@ -28,6 +28,8 @@ struct Kbdbuf
|
|||
int wi;
|
||||
int stall;
|
||||
int alting;
|
||||
Rune k[10];
|
||||
int nk;
|
||||
};
|
||||
|
||||
struct Mousebuf
|
||||
|
@ -75,7 +77,7 @@ struct Client
|
|||
|
||||
int rfd;
|
||||
int wfd;
|
||||
void* view;
|
||||
const void* view;
|
||||
|
||||
QLock inputlk;
|
||||
Kbdbuf kbd;
|
||||
|
@ -163,6 +165,22 @@ void _drawreplacescreenimage(Client*, Memimage*);
|
|||
int _latin1(Rune*, int);
|
||||
int parsewinsize(char*, Rectangle*, 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;
|
||||
|
||||
void servep9p(Client*);
|
||||
|
|
|
@ -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
|
@ -9,6 +9,7 @@ WSYSOFILES=\
|
|||
devdraw.$O\
|
||||
latin1.$O\
|
||||
mouseswap.$O\
|
||||
srv.$O\
|
||||
winsize.$O\
|
||||
|
||||
<|sh ./mkwsysrules.sh
|
||||
|
@ -42,7 +43,7 @@ $O.macargv: $MACARGV
|
|||
$LD -o $target $prereq
|
||||
|
||||
%.$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
|
||||
|
||||
|
|
|
@ -53,8 +53,8 @@ if [ $WSYSTYPE = x11 ]; then
|
|||
echo 'WSYSOFILES=$WSYSOFILES '$XO
|
||||
echo 'WSYSHFILES=x11-inc.h x11-keysym2ucs.h x11-memdraw.h'
|
||||
elif [ $WSYSTYPE = mac ]; then
|
||||
echo 'WSYSOFILES=$WSYSOFILES mac-draw.o mac-screen.o mac-srv.o'
|
||||
echo 'WSYSHFILES=mac-screen.h'
|
||||
echo 'WSYSOFILES=$WSYSOFILES mac-draw.o mac-screen.o'
|
||||
echo 'WSYSHFILES='
|
||||
echo 'MACARGV=macargv.o'
|
||||
elif [ $WSYSTYPE = nowsys ]; then
|
||||
echo 'WSYSOFILES=nowsys.o'
|
||||
|
|
|
@ -13,12 +13,11 @@
|
|||
#include <cursor.h>
|
||||
#include <drawfcall.h>
|
||||
#include "devdraw.h"
|
||||
#include "mac-screen.h"
|
||||
|
||||
void runmsg(Client*, Wsysmsg*);
|
||||
void replymsg(Client*, Wsysmsg*);
|
||||
void matchkbd(Client*);
|
||||
void matchmouse(Client*);
|
||||
static void runmsg(Client*, Wsysmsg*);
|
||||
static void replymsg(Client*, Wsysmsg*);
|
||||
static void matchkbd(Client*);
|
||||
static void matchmouse(Client*);
|
||||
|
||||
int trace = 0;
|
||||
|
||||
|
@ -55,7 +54,7 @@ servep9p(Client *c)
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
static void
|
||||
replyerror(Client *c, Wsysmsg *m)
|
||||
{
|
||||
char err[256];
|
||||
|
@ -70,7 +69,7 @@ replyerror(Client *c, Wsysmsg *m)
|
|||
* Handle a single wsysmsg.
|
||||
* Might queue for later (kbd, mouse read)
|
||||
*/
|
||||
void
|
||||
static void
|
||||
runmsg(Client *c, Wsysmsg *m)
|
||||
{
|
||||
static uchar buf[65536];
|
||||
|
@ -80,7 +79,7 @@ runmsg(Client *c, Wsysmsg *m)
|
|||
switch(m->type){
|
||||
case Tinit:
|
||||
memimageinit();
|
||||
i = attachscreen(c, m->label, m->winsize);
|
||||
i = rpc_attachscreen(c, m->label, m->winsize);
|
||||
_initdisplaymemimage(c, i);
|
||||
replymsg(c, m);
|
||||
break;
|
||||
|
@ -110,23 +109,25 @@ runmsg(Client *c, Wsysmsg *m)
|
|||
break;
|
||||
|
||||
case Tmoveto:
|
||||
setmouse(m->mouse.xy);
|
||||
rpc_setmouse(c, m->mouse.xy);
|
||||
replymsg(c, m);
|
||||
break;
|
||||
|
||||
case Tcursor:
|
||||
if(m->arrowcursor)
|
||||
setcursor(nil, nil);
|
||||
else
|
||||
setcursor(&m->cursor, nil);
|
||||
rpc_setcursor(c, nil, nil);
|
||||
else {
|
||||
scalecursor(&m->cursor2, &m->cursor);
|
||||
rpc_setcursor(c, &m->cursor, &m->cursor2);
|
||||
}
|
||||
replymsg(c, m);
|
||||
break;
|
||||
|
||||
case Tcursor2:
|
||||
if(m->arrowcursor)
|
||||
setcursor(nil, nil);
|
||||
rpc_setcursor(c, nil, nil);
|
||||
else
|
||||
setcursor(&m->cursor, &m->cursor2);
|
||||
rpc_setcursor(c, &m->cursor, &m->cursor2);
|
||||
replymsg(c, m);
|
||||
break;
|
||||
|
||||
|
@ -136,12 +137,12 @@ runmsg(Client *c, Wsysmsg *m)
|
|||
break;
|
||||
|
||||
case Tlabel:
|
||||
kicklabel(m->label);
|
||||
rpc_setlabel(c, m->label);
|
||||
replymsg(c, m);
|
||||
break;
|
||||
|
||||
case Trdsnarf:
|
||||
m->snarf = getsnarf();
|
||||
m->snarf = rpc_getsnarf();
|
||||
replymsg(c, m);
|
||||
free(m->snarf);
|
||||
break;
|
||||
|
@ -177,12 +178,12 @@ runmsg(Client *c, Wsysmsg *m)
|
|||
break;
|
||||
|
||||
case Ttop:
|
||||
topwin();
|
||||
rpc_topwin(c);
|
||||
replymsg(c, m);
|
||||
break;
|
||||
|
||||
case Tresize:
|
||||
resizewindow(m->rect);
|
||||
rpc_resizewindow(c, m->rect);
|
||||
replymsg(c, m);
|
||||
break;
|
||||
}
|
||||
|
@ -192,7 +193,7 @@ runmsg(Client *c, Wsysmsg *m)
|
|||
* Reply to m.
|
||||
*/
|
||||
QLock replylock;
|
||||
void
|
||||
static void
|
||||
replymsg(Client *c, Wsysmsg *m)
|
||||
{
|
||||
int n;
|
||||
|
@ -224,7 +225,7 @@ replymsg(Client *c, Wsysmsg *m)
|
|||
/*
|
||||
* Match queued kbd reads with queued kbd characters.
|
||||
*/
|
||||
void
|
||||
static void
|
||||
matchkbd(Client *c)
|
||||
{
|
||||
Wsysmsg m;
|
||||
|
@ -243,14 +244,18 @@ matchkbd(Client *c)
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Match queued mouse reads with queued mouse events.
|
||||
*/
|
||||
void
|
||||
// matchmouse matches queued mouse reads with queued mouse events.
|
||||
// It must be called with c->inputlk held.
|
||||
static void
|
||||
matchmouse(Client *c)
|
||||
{
|
||||
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){
|
||||
m.type = Rrdmouse;
|
||||
m.tag = c->mousetags.t[c->mousetags.ri++];
|
||||
|
@ -271,10 +276,11 @@ matchmouse(Client *c)
|
|||
}
|
||||
|
||||
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;
|
||||
|
||||
qlock(&c->inputlk);
|
||||
if(x < c->mouserect.min.x)
|
||||
x = c->mouserect.min.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)
|
||||
y = c->mouserect.max.y;
|
||||
|
||||
qlock(&c->inputlk);
|
||||
// If reader has stopped reading, don't bother.
|
||||
// If reader is completely caught up, definitely queue.
|
||||
// Otherwise, queue only button change events.
|
||||
|
@ -310,36 +315,50 @@ mousetrack(Client *c, int x, int y, int b, uint ms)
|
|||
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)
|
||||
{
|
||||
qlock(&c->inputlk);
|
||||
if(canqlock(&c->inputlk)) {
|
||||
fprint(2, "misuse of kputc\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
c->kbd.r[c->kbd.wi++] = ch;
|
||||
if(c->kbd.wi == nelem(c->kbd.r))
|
||||
c->kbd.wi = 0;
|
||||
if(c->kbd.ri == c->kbd.wi)
|
||||
c->kbd.stall = 1;
|
||||
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);
|
||||
}
|
||||
|
||||
// gfx_keystroke records a single-rune keystroke.
|
||||
// It is called from the graphics thread with no locks held.
|
||||
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;
|
||||
|
||||
qlock(&c->inputlk);
|
||||
if(ch == Kalt){
|
||||
c->kbd.alting = !c->kbd.alting;
|
||||
nk = 0;
|
||||
c->kbd.nk = 0;
|
||||
qunlock(&c->inputlk);
|
||||
return;
|
||||
}
|
||||
if(ch == Kcmd+'r') {
|
||||
|
@ -349,30 +368,35 @@ keystroke(Client *c, int ch)
|
|||
c->forcedpi = 100;
|
||||
else
|
||||
c->forcedpi = 225;
|
||||
resizeimg(c);
|
||||
qunlock(&c->inputlk);
|
||||
rpc_resizeimg(c);
|
||||
return;
|
||||
}
|
||||
if(!c->kbd.alting){
|
||||
kputc(c, ch);
|
||||
qunlock(&c->inputlk);
|
||||
return;
|
||||
}
|
||||
if(nk >= nelem(k)) // should not happen
|
||||
nk = 0;
|
||||
k[nk++] = ch;
|
||||
ch = _latin1(k, nk);
|
||||
if(c->kbd.nk >= nelem(c->kbd.k)) // should not happen
|
||||
c->kbd.nk = 0;
|
||||
c->kbd.k[c->kbd.nk++] = ch;
|
||||
ch = _latin1(c->kbd.k, c->kbd.nk);
|
||||
if(ch > 0){
|
||||
c->kbd.alting = 0;
|
||||
kputc(c, ch);
|
||||
nk = 0;
|
||||
c->kbd.nk = 0;
|
||||
qunlock(&c->inputlk);
|
||||
return;
|
||||
}
|
||||
if(ch == -1){
|
||||
c->kbd.alting = 0;
|
||||
for(i=0; i<nk; i++)
|
||||
kputc(c, k[i]);
|
||||
nk = 0;
|
||||
for(i=0; i<c->kbd.nk; i++)
|
||||
kputc(c, c->kbd.k[i]);
|
||||
c->kbd.nk = 0;
|
||||
qunlock(&c->inputlk);
|
||||
return;
|
||||
}
|
||||
// need more input
|
||||
qunlock(&c->inputlk);
|
||||
return;
|
||||
}
|
Loading…
Reference in a new issue