mirror of
https://github.com/9fans/plan9port.git
synced 2025-01-24 11:41:58 +00:00
devdraw: use indirect impl interface
Setting up for a real window system.
This commit is contained in:
parent
162d0d5cd9
commit
94d381ec9d
4 changed files with 61 additions and 30 deletions
|
@ -143,7 +143,7 @@ addflush(Client *c, Rectangle r)
|
||||||
// during a resize.
|
// during a resize.
|
||||||
rpc_gfxdrawunlock();
|
rpc_gfxdrawunlock();
|
||||||
qunlock(&c->drawlk);
|
qunlock(&c->drawlk);
|
||||||
rpc_flush(c, fr);
|
c->impl->rpc_flush(c, fr);
|
||||||
qlock(&c->drawlk);
|
qlock(&c->drawlk);
|
||||||
rpc_gfxdrawlock();
|
rpc_gfxdrawlock();
|
||||||
}
|
}
|
||||||
|
@ -188,7 +188,7 @@ drawflush(Client *c)
|
||||||
// during a resize.
|
// during a resize.
|
||||||
rpc_gfxdrawunlock();
|
rpc_gfxdrawunlock();
|
||||||
qunlock(&c->drawlk);
|
qunlock(&c->drawlk);
|
||||||
rpc_flush(c, r);
|
c->impl->rpc_flush(c, r);
|
||||||
qlock(&c->drawlk);
|
qlock(&c->drawlk);
|
||||||
rpc_gfxdrawlock();
|
rpc_gfxdrawlock();
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ typedef struct Mousebuf Mousebuf;
|
||||||
typedef struct Tagbuf Tagbuf;
|
typedef struct Tagbuf Tagbuf;
|
||||||
|
|
||||||
typedef struct Client Client;
|
typedef struct Client Client;
|
||||||
|
typedef struct ClientImpl ClientImpl;
|
||||||
typedef struct DImage DImage;
|
typedef struct DImage DImage;
|
||||||
typedef struct DScreen DScreen;
|
typedef struct DScreen DScreen;
|
||||||
typedef struct CScreen CScreen;
|
typedef struct CScreen CScreen;
|
||||||
|
@ -43,6 +44,18 @@ struct Tagbuf
|
||||||
int wi;
|
int wi;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct ClientImpl
|
||||||
|
{
|
||||||
|
void (*rpc_resizeimg)(Client*);
|
||||||
|
void (*rpc_resizewindow)(Client*, Rectangle);
|
||||||
|
void (*rpc_setcursor)(Client*, Cursor*, Cursor2*);
|
||||||
|
void (*rpc_setlabel)(Client*, char*);
|
||||||
|
void (*rpc_setmouse)(Client*, Point);
|
||||||
|
void (*rpc_topwin)(Client*);
|
||||||
|
void (*rpc_bouncemouse)(Client*, Mouse);
|
||||||
|
void (*rpc_flush)(Client*, Rectangle);
|
||||||
|
};
|
||||||
|
|
||||||
struct Client
|
struct Client
|
||||||
{
|
{
|
||||||
int rfd;
|
int rfd;
|
||||||
|
@ -82,6 +95,7 @@ struct Client
|
||||||
int nname;
|
int nname;
|
||||||
DName* name;
|
DName* name;
|
||||||
int namevers;
|
int namevers;
|
||||||
|
ClientImpl* impl;
|
||||||
|
|
||||||
// Only accessed/modified by the graphics thread.
|
// Only accessed/modified by the graphics thread.
|
||||||
const void* view;
|
const void* view;
|
||||||
|
@ -196,17 +210,8 @@ void gfx_started(void);
|
||||||
Memimage *rpc_attach(Client*, char*, char*);
|
Memimage *rpc_attach(Client*, char*, char*);
|
||||||
char* rpc_getsnarf(void);
|
char* rpc_getsnarf(void);
|
||||||
void rpc_putsnarf(char*);
|
void rpc_putsnarf(char*);
|
||||||
void rpc_resizeimg(Client*);
|
|
||||||
void rpc_resizewindow(Client*, Rectangle);
|
|
||||||
void rpc_serve(Client*);
|
|
||||||
void rpc_setcursor(Client*, Cursor*, Cursor2*);
|
|
||||||
void rpc_setlabel(Client*, char*);
|
|
||||||
void rpc_setmouse(Client*, Point);
|
|
||||||
void rpc_shutdown(void);
|
void rpc_shutdown(void);
|
||||||
void rpc_topwin(Client*);
|
|
||||||
void rpc_main(void);
|
void rpc_main(void);
|
||||||
void rpc_bouncemouse(Client*, Mouse);
|
|
||||||
void rpc_flush(Client*, Rectangle);
|
|
||||||
|
|
||||||
// rpc_gfxdrawlock and rpc_gfxdrawunlock
|
// rpc_gfxdrawlock and rpc_gfxdrawunlock
|
||||||
// are called around drawing operations to lock and unlock
|
// are called around drawing operations to lock and unlock
|
||||||
|
|
|
@ -37,6 +37,27 @@ static void setprocname(const char*);
|
||||||
static uint keycvt(uint);
|
static uint keycvt(uint);
|
||||||
static uint msec(void);
|
static uint msec(void);
|
||||||
|
|
||||||
|
static void rpc_resizeimg(Client*);
|
||||||
|
static void rpc_resizewindow(Client*, Rectangle);
|
||||||
|
static void rpc_serve(Client*);
|
||||||
|
static void rpc_setcursor(Client*, Cursor*, Cursor2*);
|
||||||
|
static void rpc_setlabel(Client*, char*);
|
||||||
|
static void rpc_setmouse(Client*, Point);
|
||||||
|
static void rpc_topwin(Client*);
|
||||||
|
static void rpc_bouncemouse(Client*, Mouse);
|
||||||
|
static void rpc_flush(Client*, Rectangle);
|
||||||
|
|
||||||
|
static ClientImpl macimpl = {
|
||||||
|
rpc_resizeimg,
|
||||||
|
rpc_resizewindow,
|
||||||
|
rpc_setcursor,
|
||||||
|
rpc_setlabel,
|
||||||
|
rpc_setmouse,
|
||||||
|
rpc_topwin,
|
||||||
|
rpc_bouncemouse,
|
||||||
|
rpc_flush
|
||||||
|
};
|
||||||
|
|
||||||
@class DrawView;
|
@class DrawView;
|
||||||
@class DrawLayer;
|
@class DrawLayer;
|
||||||
|
|
||||||
|
@ -201,6 +222,7 @@ rpc_attach(Client *c, char *label, char *winsize)
|
||||||
{
|
{
|
||||||
LOG(@"attachscreen(%s, %s)", label, winsize);
|
LOG(@"attachscreen(%s, %s)", label, winsize);
|
||||||
|
|
||||||
|
c->impl = &macimpl;
|
||||||
dispatch_sync(dispatch_get_main_queue(), ^(void) {
|
dispatch_sync(dispatch_get_main_queue(), ^(void) {
|
||||||
@autoreleasepool {
|
@autoreleasepool {
|
||||||
DrawView *view = [[DrawView new] attach:c winsize:winsize label:label];
|
DrawView *view = [[DrawView new] attach:c winsize:winsize label:label];
|
||||||
|
@ -302,7 +324,7 @@ rpc_attach(Client *c, char *label, char *winsize)
|
||||||
|
|
||||||
// rpc_topwin moves the window to the top of the desktop.
|
// rpc_topwin moves the window to the top of the desktop.
|
||||||
// Called from an RPC thread with no client lock held.
|
// Called from an RPC thread with no client lock held.
|
||||||
void
|
static void
|
||||||
rpc_topwin(Client *c)
|
rpc_topwin(Client *c)
|
||||||
{
|
{
|
||||||
DrawView *view = (__bridge DrawView*)c->view;
|
DrawView *view = (__bridge DrawView*)c->view;
|
||||||
|
@ -319,7 +341,7 @@ rpc_topwin(Client *c)
|
||||||
// rpc_setlabel updates the client window's label.
|
// rpc_setlabel updates the client window's label.
|
||||||
// If label == nil, the call is a no-op.
|
// If label == nil, the call is a no-op.
|
||||||
// Called from an RPC thread with no client lock held.
|
// Called from an RPC thread with no client lock held.
|
||||||
void
|
static void
|
||||||
rpc_setlabel(Client *client, char *label)
|
rpc_setlabel(Client *client, char *label)
|
||||||
{
|
{
|
||||||
DrawView *view = (__bridge DrawView*)client->view;
|
DrawView *view = (__bridge DrawView*)client->view;
|
||||||
|
@ -344,7 +366,7 @@ rpc_setlabel(Client *client, char *label)
|
||||||
// rpc_setcursor updates the client window's cursor image.
|
// rpc_setcursor updates the client window's cursor image.
|
||||||
// Either c and c2 are both non-nil, or they are both nil to use the default arrow.
|
// Either c and c2 are both non-nil, or they are both nil to use the default arrow.
|
||||||
// Called from an RPC thread with no client lock held.
|
// Called from an RPC thread with no client lock held.
|
||||||
void
|
static void
|
||||||
rpc_setcursor(Client *client, Cursor *c, Cursor2 *c2)
|
rpc_setcursor(Client *client, Cursor *c, Cursor2 *c2)
|
||||||
{
|
{
|
||||||
DrawView *view = (__bridge DrawView*)client->view;
|
DrawView *view = (__bridge DrawView*)client->view;
|
||||||
|
@ -460,7 +482,7 @@ rpc_setcursor(Client *client, Cursor *c, Cursor2 *c2)
|
||||||
// rpc_flush flushes changes to view.img's rectangle r
|
// rpc_flush flushes changes to view.img's rectangle r
|
||||||
// to the on-screen window, making them visible.
|
// to the on-screen window, making them visible.
|
||||||
// Called from an RPC thread with no client lock held.
|
// Called from an RPC thread with no client lock held.
|
||||||
void
|
static void
|
||||||
rpc_flush(Client *client, Rectangle r)
|
rpc_flush(Client *client, Rectangle r)
|
||||||
{
|
{
|
||||||
DrawView *view = (__bridge DrawView*)client->view;
|
DrawView *view = (__bridge DrawView*)client->view;
|
||||||
|
@ -506,7 +528,7 @@ rpc_flush(Client *client, Rectangle r)
|
||||||
// rpc_resizeimg forces the client window to discard its current window and make a new one.
|
// rpc_resizeimg forces the client window to discard its current window and make a new one.
|
||||||
// It is called when the user types Cmd-R to toggle whether retina mode is forced.
|
// It is called when the user types Cmd-R to toggle whether retina mode is forced.
|
||||||
// Called from an RPC thread with no client lock held.
|
// Called from an RPC thread with no client lock held.
|
||||||
void
|
static void
|
||||||
rpc_resizeimg(Client *c)
|
rpc_resizeimg(Client *c)
|
||||||
{
|
{
|
||||||
DrawView *view = (__bridge DrawView*)c->view;
|
DrawView *view = (__bridge DrawView*)c->view;
|
||||||
|
@ -541,7 +563,7 @@ rpc_resizeimg(Client *c)
|
||||||
|
|
||||||
// rpc_resizewindow asks for the client window to be resized to size r.
|
// rpc_resizewindow asks for the client window to be resized to size r.
|
||||||
// Called from an RPC thread with no client lock held.
|
// Called from an RPC thread with no client lock held.
|
||||||
void
|
static void
|
||||||
rpc_resizewindow(Client *c, Rectangle r)
|
rpc_resizewindow(Client *c, Rectangle r)
|
||||||
{
|
{
|
||||||
DrawView *view = (__bridge DrawView*)c->view;
|
DrawView *view = (__bridge DrawView*)c->view;
|
||||||
|
@ -696,7 +718,7 @@ rpc_resizewindow(Client *c, Rectangle r)
|
||||||
|
|
||||||
// rpc_setmouse moves the mouse cursor.
|
// rpc_setmouse moves the mouse cursor.
|
||||||
// Called from an RPC thread with no client lock held.
|
// Called from an RPC thread with no client lock held.
|
||||||
void
|
static void
|
||||||
rpc_setmouse(Client *c, Point p)
|
rpc_setmouse(Client *c, Point p)
|
||||||
{
|
{
|
||||||
DrawView *view = (__bridge DrawView*)c->view;
|
DrawView *view = (__bridge DrawView*)c->view;
|
||||||
|
@ -1095,7 +1117,7 @@ rpc_putsnarf(char *s)
|
||||||
// rpc_bouncemouse is for sending a mouse event
|
// rpc_bouncemouse is for sending a mouse event
|
||||||
// back to the X11 window manager rio(1).
|
// back to the X11 window manager rio(1).
|
||||||
// Does not apply here.
|
// Does not apply here.
|
||||||
void
|
static void
|
||||||
rpc_bouncemouse(Client *c, Mouse m)
|
rpc_bouncemouse(Client *c, Mouse m)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,6 +54,7 @@ threadmain(int argc, char **argv)
|
||||||
usage();
|
usage();
|
||||||
}ARGEND
|
}ARGEND
|
||||||
|
|
||||||
|
memimageinit();
|
||||||
fmtinstall('H', encodefmt);
|
fmtinstall('H', encodefmt);
|
||||||
if((p = getenv("DEVDRAWTRACE")) != nil)
|
if((p = getenv("DEVDRAWTRACE")) != nil)
|
||||||
trace = atoi(p);
|
trace = atoi(p);
|
||||||
|
@ -202,8 +203,11 @@ runmsg(Client *c, Wsysmsg *m)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Tinit:
|
case Tinit:
|
||||||
memimageinit();
|
|
||||||
i = rpc_attach(c, m->label, m->winsize);
|
i = rpc_attach(c, m->label, m->winsize);
|
||||||
|
if(i == nil) {
|
||||||
|
replyerror(c, m);
|
||||||
|
break;
|
||||||
|
}
|
||||||
draw_initdisplaymemimage(c, i);
|
draw_initdisplaymemimage(c, i);
|
||||||
replymsg(c, m);
|
replymsg(c, m);
|
||||||
break;
|
break;
|
||||||
|
@ -241,35 +245,35 @@ runmsg(Client *c, Wsysmsg *m)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Tmoveto:
|
case Tmoveto:
|
||||||
rpc_setmouse(c, m->mouse.xy);
|
c->impl->rpc_setmouse(c, m->mouse.xy);
|
||||||
replymsg(c, m);
|
replymsg(c, m);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Tcursor:
|
case Tcursor:
|
||||||
if(m->arrowcursor)
|
if(m->arrowcursor)
|
||||||
rpc_setcursor(c, nil, nil);
|
c->impl->rpc_setcursor(c, nil, nil);
|
||||||
else {
|
else {
|
||||||
scalecursor(&m->cursor2, &m->cursor);
|
scalecursor(&m->cursor2, &m->cursor);
|
||||||
rpc_setcursor(c, &m->cursor, &m->cursor2);
|
c->impl->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)
|
||||||
rpc_setcursor(c, nil, nil);
|
c->impl->rpc_setcursor(c, nil, nil);
|
||||||
else
|
else
|
||||||
rpc_setcursor(c, &m->cursor, &m->cursor2);
|
c->impl->rpc_setcursor(c, &m->cursor, &m->cursor2);
|
||||||
replymsg(c, m);
|
replymsg(c, m);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Tbouncemouse:
|
case Tbouncemouse:
|
||||||
rpc_bouncemouse(c, m->mouse);
|
c->impl->rpc_bouncemouse(c, m->mouse);
|
||||||
replymsg(c, m);
|
replymsg(c, m);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Tlabel:
|
case Tlabel:
|
||||||
rpc_setlabel(c, m->label);
|
c->impl->rpc_setlabel(c, m->label);
|
||||||
replymsg(c, m);
|
replymsg(c, m);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -306,12 +310,12 @@ runmsg(Client *c, Wsysmsg *m)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Ttop:
|
case Ttop:
|
||||||
rpc_topwin(c);
|
c->impl->rpc_topwin(c);
|
||||||
replymsg(c, m);
|
replymsg(c, m);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Tresize:
|
case Tresize:
|
||||||
rpc_resizewindow(c, m->rect);
|
c->impl->rpc_resizewindow(c, m->rect);
|
||||||
replymsg(c, m);
|
replymsg(c, m);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -513,7 +517,7 @@ gfx_keystroke(Client *c, int ch)
|
||||||
else
|
else
|
||||||
c->forcedpi = 225;
|
c->forcedpi = 225;
|
||||||
qunlock(&c->eventlk);
|
qunlock(&c->eventlk);
|
||||||
rpc_resizeimg(c);
|
c->impl->rpc_resizeimg(c);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(!c->kbd.alting){
|
if(!c->kbd.alting){
|
||||||
|
|
Loading…
Reference in a new issue