Unified · Split
| @@ -32,12 +32,12 @@ typedef struct Draw Draw; · 31 unmodified lines | ||
| 32 | 32 | typedef struct Client Client; |
| 33 | 33 | typedef struct FChar FChar; |
| 34 | 34 | typedef struct DImage DImage; |
| 35 | +typedef struct DName DName; | |
| 35 | 36 | typedef struct DScreen DScreen; |
| 36 | 37 | typedef struct Kbdbuf Kbdbuf; |
| 37 | 38 | typedef struct Mousebuf Mousebuf; |
| 38 | 39 | typedef struct Reqbuf Reqbuf; |
| 39 | 40 | typedef struct Window Window; |
| 40 | −typedef struct Wsysmsg Wsysmsg; | |
| 41 | 41 | |
| 42 | 42 | /* Drawing device */ |
| 43 | 43 | #define NHASH (1<<5) |
| @@ -45,24 +45,26 @@ typedef struct Wsysmsg Wsysmsg; · 1 unmodified line | ||
| 45 | 45 | |
| 46 | 46 | struct Draw |
| 47 | 47 | { |
| 48 | + int nname; | |
| 49 | + DName* name; | |
| 48 | 50 | Rectangle flushrect; |
| 49 | 51 | }; |
| 50 | 52 | |
| 51 | 53 | struct Client |
| 52 | 54 | { |
| 53 | − /*Ref r;*/ | |
| 54 | − DImage* dimage[NHASH]; | |
| 55 | + int r; // Ref | |
| 56 | + DImage* dimage[NHASH]; | |
| 55 | 57 | // CScreen* cscreen; |
| 56 | 58 | // Refresh* refresh; |
| 57 | −// Rendez refrend; | |
| 59 | +// Rendez refrend; | |
| 58 | 60 | Window *window; |
| 59 | −// uchar* readdata; | |
| 60 | −// int nreaddata; | |
| 61 | + uchar* readdata; | |
| 62 | + int nreaddata; | |
| 61 | 63 | int busy; |
| 62 | 64 | int clientid; |
| 63 | 65 | int slot; |
| 64 | 66 | // int refreshme; |
| 65 | −// int infoid; | |
| 67 | + int infoid; | |
| 66 | 68 | int op; |
| 67 | 69 | }; |
| 68 | 70 | |
| @@ -70,10 +72,10 @@ struct FChar · 1 unmodified line | ||
| 70 | 72 | { |
| 71 | 73 | int minx; /* left edge of bits */ |
| 72 | 74 | int maxx; /* right edge of bits */ |
| 73 | − uchar miny; /* first non-zero scan-line */ | |
| 74 | − uchar maxy; /* last non-zero scan-line + 1 */ | |
| 75 | − schar left; /* offset of baseline */ | |
| 76 | − uchar width; /* width of baseline */ | |
| 75 | + uchar miny; /* first non-zero scan-line */ | |
| 76 | + uchar maxy; /* last non-zero scan-line + 1 */ | |
| 77 | + schar left; /* offset of baseline */ | |
| 78 | + uchar width; /* width of baseline */ | |
| 77 | 79 | }; |
| 78 | 80 | |
| 79 | 81 | struct DImage |
| @@ -85,10 +87,18 @@ struct DImage · 5 unmodified lines | ||
| 85 | 87 | Memimage* image; |
| 86 | 88 | int ascent; |
| 87 | 89 | int nfchar; |
| 88 | − FChar* fchar; | |
| 89 | − DScreen* dscreen; /* 0 if not a window */ | |
| 90 | + FChar* fchar; | |
| 91 | + DScreen* dscreen; /* 0 if not a window */ | |
| 90 | 92 | DImage* fromname; /* image this one is derived from, by name */ |
| 91 | − DImage* next; | |
| 93 | + DImage* next; | |
| 94 | +}; | |
| 95 | + | |
| 96 | +struct DName | |
| 97 | +{ | |
| 98 | + char *name; | |
| 99 | + Client *client; | |
| 100 | + DImage* dimage; | |
| 101 | + int vers; | |
| 92 | 102 | }; |
| 93 | 103 | |
| 94 | 104 | struct DScreen |
| @@ -99,20 +109,20 @@ struct DScreen · 4 unmodified lines | ||
| 99 | 109 | DImage *dimage; |
| 100 | 110 | DImage *dfill; |
| 101 | 111 | Memscreen* screen; |
| 102 | − Client* owner; | |
| 112 | + Client* owner; | |
| 103 | 113 | DScreen* next; |
| 104 | 114 | }; |
| 105 | 115 | |
| 106 | 116 | /* Events */ |
| 107 | 117 | struct Kbdbuf |
| 108 | 118 | { |
| 109 | − Rune r[32]; | |
| 110 | − int ri; | |
| 111 | − int wi; | |
| 112 | − int stall; | |
| 119 | + Rune r[32]; | |
| 120 | + int ri; | |
| 121 | + int wi; | |
| 122 | + int stall; | |
| 113 | 123 | /* Used by kbdputc */ |
| 114 | 124 | uchar k[5*UTFmax]; |
| 115 | − int alting, nk; | |
| 125 | + int alting, nk; | |
| 116 | 126 | }; |
| 117 | 127 | |
| 118 | 128 | struct Mouse |
| @@ -142,23 +152,24 @@ struct Reqbuf · 23 unmodified lines | ||
| 142 | 152 | /* Window system */ |
| 143 | 153 | struct Window |
| 144 | 154 | { |
| 145 | − int id; | |
| 146 | − int deleted; | |
| 147 | − char *label; | |
| 148 | − Draw draw; | |
| 149 | − Kbdbuf kbd; | |
| 155 | + int id; | |
| 156 | + int deleted; | |
| 157 | + char *label; | |
| 158 | + Draw draw; | |
| 159 | + Kbdbuf kbd; | |
| 150 | 160 | Memimage *screenimage; |
| 151 | − Mousebuf mouse; | |
| 152 | − Reqbuf kbdreqs; | |
| 153 | − Reqbuf mousereqs; | |
| 154 | − Rectangle r; | |
| 155 | − void *x; | |
| 161 | + Memdata screendata; | |
| 162 | + Mousebuf mouse; | |
| 163 | + Reqbuf kbdreqs; | |
| 164 | + Reqbuf mousereqs; | |
| 165 | + Rectangle r; | |
| 166 | + void *x; | |
| 156 | 167 | }; |
| 157 | 168 | |
| 158 | 169 | /* Global Vars */ |
| 159 | −int debuglevel; | |
| 160 | −int nwindow; | |
| 161 | −Window **window; | |
| 162 | −int nclient; | |
| 163 | −Client** client; | |
| 170 | +int debuglevel; | |
| 171 | +int nwindow; | |
| 172 | +Window **window; | |
| 173 | +int nclient; | |
| 174 | +Client **client; | |
| 164 | 175 | |
| @@ -6,7 +6,15 @@ · 5 unmodified lines | ||
| 6 | 6 | #include "dat.h" |
| 7 | 7 | #include "fns.h" |
| 8 | 8 | |
| 9 | +/* Error messages */ | |
| 10 | +static char | |
| 11 | + Enodrawimage[] = "unknown id for draw image", | |
| 12 | + Eoldname[] = "named image no longer valid"; | |
| 13 | + | |
| 14 | +DImage* drawlookup(Client*, int, int); | |
| 15 | + | |
| 9 | 16 | int nclient = 0; |
| 17 | +char *error = nil; | |
| 10 | 18 | |
| 11 | 19 | Client* |
| 12 | 20 | drawnewclient(Window *w) |
| @@ -30,10 +38,9 @@ drawnewclient(Window *w) · 17 unmodified lines | ||
| 30 | 38 | nclient++; |
| 31 | 39 | cp[i] = 0; |
| 32 | 40 | } |
| 33 | − cl = malloc(sizeof(Client)); | |
| 41 | + cl = mallocz(sizeof(Client), 1); | |
| 34 | 42 | if(cl == 0) |
| 35 | 43 | return 0; |
| 36 | − memset(cl, 0, sizeof(Client)); | |
| 37 | 44 | cl->slot = i; |
| 38 | 45 | cl->clientid = ++clientid; |
| 39 | 46 | cl->op = SoverD; |
| @@ -64,9 +71,102 @@ drawinstall(Client *client, int id, Memimage *i, DScreen *dscreen) · 24 unmodified lines | ||
| 64 | 71 | return i; |
| 65 | 72 | } |
| 66 | 73 | |
| 74 | +void | |
| 75 | +readdrawctl(char *buf, Client *cl) | |
| 76 | +{ | |
| 77 | + int n; | |
| 78 | + DImage *di; | |
| 79 | + Memimage *i; | |
| 80 | + | |
| 81 | + if(cl->infoid < 0) | |
| 82 | + error = Enodrawimage; | |
| 83 | + if(cl->infoid == 0){ | |
| 84 | + i = cl->window->screenimage; | |
| 85 | + if(i == nil) | |
| 86 | + error = Enodrawimage; | |
| 87 | + }else{ | |
| 88 | + di = drawlookup(cl, cl->infoid, 1); | |
| 89 | + if(di == nil) | |
| 90 | + error = Enodrawimage; | |
| 91 | + i = di->image; | |
| 92 | + } | |
| 93 | + n = sprint(buf, "%11d %11d %11s %11d %11d %11d %11d %11d %11d %11d %11d %11d ", | |
| 94 | + cl->clientid, cl->infoid, chantostr(buf, i->chan), (i->flags&Frepl)==Frepl, | |
| 95 | + i->r.min.x, i->r.min.y, i->r.max.x, i->r.max.y, | |
| 96 | + i->clipr.min.x, i->clipr.min.y, i->clipr.max.x, i->clipr.max.y); | |
| 97 | + cl->infoid = -1; | |
| 98 | +} | |
| 99 | + | |
| 100 | +void | |
| 101 | +drawmesg(Client *client, void *av, int n) | |
| 102 | +{ | |
| 103 | +} | |
| 104 | + | |
| 105 | +static | |
| 67 | 106 | int |
| 68 | −initscreenimage(Memimage *m) | |
| 107 | +drawcmp(char *a, char *b, int n) | |
| 108 | +{ | |
| 109 | + if(strlen(a) != n) | |
| 110 | + return 1; | |
| 111 | + return memcmp(a, b, n); | |
| 112 | +} | |
| 113 | + | |
| 114 | +DName* | |
| 115 | +drawlookupname(Draw *draw, int n, char *str) | |
| 69 | 116 | { |
| 70 | − // TODO: inferno-os/emu/port/devdraw.c:855,881 | |
| 117 | + DName *name, *ename; | |
| 118 | + | |
| 119 | + name = draw->name; | |
| 120 | + ename = &name[draw->nname]; | |
| 121 | + for(; name<ename; name++) | |
| 122 | + if(drawcmp(name->name, str, n) == 0) | |
| 123 | + return name; | |
| 124 | + return 0; | |
| 125 | +} | |
| 126 | + | |
| 127 | +int | |
| 128 | +drawgoodname(Draw *draw, DImage *d) | |
| 129 | +{ | |
| 130 | + DName *n; | |
| 131 | + | |
| 132 | + /* if window, validate the screen's own images */ | |
| 133 | + if(d->dscreen) | |
| 134 | + if(drawgoodname(draw, d->dscreen->dimage) == 0 | |
| 135 | + || drawgoodname(draw, d->dscreen->dfill) == 0) | |
| 136 | + return 0; | |
| 137 | + if(d->name == nil) | |
| 138 | + return 1; | |
| 139 | + n = drawlookupname(draw, strlen(d->name), d->name); | |
| 140 | + if(n==nil || n->vers!=d->vers) | |
| 141 | + return 0; | |
| 71 | 142 | return 1; |
| 72 | 143 | } |
| 144 | + | |
| 145 | +DImage* | |
| 146 | +drawlookup(Client *client, int id, int checkname) | |
| 147 | +{ | |
| 148 | + DImage *d; | |
| 149 | + Draw *draw; | |
| 150 | + | |
| 151 | + d = client->dimage[id&HASHMASK]; | |
| 152 | + while(d){ | |
| 153 | + if(d->id == id){ | |
| 154 | + draw = &client->window->draw; | |
| 155 | + if(checkname && !drawgoodname(draw, d)) | |
| 156 | + error = Eoldname; | |
| 157 | + return d; | |
| 158 | + } | |
| 159 | + d = d->next; | |
| 160 | + } | |
| 161 | + return 0; | |
| 162 | +} | |
| 163 | + | |
| 164 | +char* | |
| 165 | +drawerr(void) | |
| 166 | +{ | |
| 167 | + char *err; | |
| 168 | + | |
| 169 | + err = error; | |
| 170 | + error = nil; | |
| 171 | + return err; | |
| 172 | +} | |
| @@ -4,7 +4,9 @@ · 3 unmodified lines | ||
| 4 | 4 | /* Devdraw */ |
| 5 | 5 | Client* drawnewclient(Window*); |
| 6 | 6 | Memimage* drawinstall(Client*, int, Memimage*, DScreen*); |
| 7 | −int initscreenimage(Memimage*); | |
| 7 | +void readdrawctl(char*, Client*); | |
| 8 | +void drawmesg(Client*, void*, int); | |
| 9 | +char* drawerr(void); | |
| 8 | 10 | |
| 9 | 11 | /* Keyboard */ |
| 10 | 12 | void writekbd(Window*, int); |
| @@ -16,6 +16,9 @@ union IxpFileIdU { · 15 unmodified lines | ||
| 16 | 16 | }; |
| 17 | 17 | #include <ixp_srvutil.h> |
| 18 | 18 | |
| 19 | +#define incref(r) ((*r) = ++(*r)) | |
| 20 | +#define decref(r) ((*r) = --(*r)) | |
| 21 | + | |
| 19 | 22 | /* Constants */ |
| 20 | 23 | enum { |
| 21 | 24 | /* Dirs */ |
| @@ -281,10 +284,11 @@ fs_open(Ixp9Req *r) { · 259 unmodified lines | ||
| 281 | 284 | return; |
| 282 | 285 | } |
| 283 | 286 | cl->busy = 1; |
| 284 | − d = &cl->window->draw; | |
| 287 | + w = cl->window; | |
| 288 | + d = &w->draw; | |
| 285 | 289 | d->flushrect = Rect(10000, 10000, -10000, -10000); |
| 286 | − // drawinstall(cl, 0, screenimage, 0); | |
| 287 | − // incref(&cl->r); | |
| 290 | + drawinstall(cl, 0, w->screenimage, 0); | |
| 291 | + incref(&cl->r); | |
| 288 | 292 | break; |
| 289 | 293 | case FsFMouse: |
| 290 | 294 | w = f->p.window; |
| @@ -315,8 +319,9 @@ fs_walk(Ixp9Req *r) { · 24 unmodified lines | ||
| 315 | 319 | |
| 316 | 320 | void |
| 317 | 321 | fs_read(Ixp9Req *r) { |
| 318 | − char buf[512]; | |
| 322 | + char buf[512], *err; | |
| 319 | 323 | IxpFileId *f; |
| 324 | + Client *cl; | |
| 320 | 325 | Window *w; |
| 321 | 326 | |
| 322 | 327 | debug("fs_read(%p)\n", r); |
| @@ -338,14 +343,28 @@ fs_read(Ixp9Req *r) { · 15 unmodified lines | ||
| 338 | 343 | ixp_pending_respond(r); |
| 339 | 344 | return; |
| 340 | 345 | } |
| 346 | + cl = f->p.client; | |
| 341 | 347 | switch(f->tab.type) { |
| 342 | − case FsFData: | |
| 343 | − sprint(buf, "%d", f->p.client->clientid); | |
| 348 | + case FsFCtl: | |
| 349 | + readdrawctl(buf, cl); | |
| 350 | + err = drawerr(); | |
| 351 | + if(err != nil) { | |
| 352 | + ixp_respond(r, err); | |
| 353 | + return; | |
| 354 | + } | |
| 344 | 355 | ixp_srv_readbuf(r, buf, strlen(buf)); |
| 356 | + return; | |
| 357 | + case FsFData: | |
| 358 | + if(cl->readdata == nil) { | |
| 359 | + ixp_respond(r, "no draw data"); | |
| 360 | + return; | |
| 361 | + } | |
| 362 | + ixp_srv_readbuf(r, cl->readdata, cl->nreaddata); | |
| 345 | 363 | ixp_respond(r, nil); |
| 364 | + free(cl->readdata); | |
| 365 | + cl->readdata = nil; | |
| 346 | 366 | return; |
| 347 | 367 | case FsFNew: |
| 348 | − case FsFCtl: | |
| 349 | 368 | case FsFColormap: |
| 350 | 369 | case FsFRefresh: |
| 351 | 370 | return; |
| @@ -420,6 +439,7 @@ fs_write(Ixp9Req *r) { · 68 unmodified lines | ||
| 420 | 439 | char *label; |
| 421 | 440 | IxpFileId *f; |
| 422 | 441 | Window *w; |
| 442 | + Client *cl; | |
| 423 | 443 | |
| 424 | 444 | debug("fs_write(%p)\n", r); |
| 425 | 445 | |
| @@ -433,10 +453,22 @@ fs_write(Ixp9Req *r) { · 7 unmodified lines | ||
| 433 | 453 | return; |
| 434 | 454 | } |
| 435 | 455 | |
| 456 | + cl = f->p.client; | |
| 436 | 457 | switch(f->tab.type) { |
| 458 | + case FsFData: | |
| 459 | + r->ofcall.io.count = r->ifcall.io.count; | |
| 460 | + drawmesg(cl, r->ifcall.twrite.data, r->ofcall.rwrite.count); | |
| 461 | + // drawwakeall(); | |
| 462 | + ixp_respond(r, nil); | |
| 463 | + return; | |
| 437 | 464 | case FsFNew: |
| 438 | 465 | case FsFCtl: |
| 439 | − case FsFData: | |
| 466 | + r->ofcall.io.count = r->ifcall.io.count; | |
| 467 | + if(r->ofcall.io.count != 4) | |
| 468 | + ixp_respond(r, "unknown draw control request"); | |
| 469 | + cl->infoid = BGLONG((uchar*)r->ifcall.twrite.data); | |
| 470 | + ixp_respond(r, nil); | |
| 471 | + return; | |
| 440 | 472 | case FsFColormap: |
| 441 | 473 | case FsFRefresh: |
| 442 | 474 | return; |
| @@ -14,13 +14,12 @@ newwin(char *label, char *winsize) · 13 unmodified lines | ||
| 14 | 14 | static int id = 0; |
| 15 | 15 | Window *w; |
| 16 | 16 | |
| 17 | − if(!(w = malloc(sizeof(Window)))) | |
| 17 | + if(!(w = mallocz(sizeof(Window), 1))) | |
| 18 | 18 | return nil; |
| 19 | 19 | if(!(window = realloc(window, ++nwindow*sizeof(Window*)))) |
| 20 | 20 | return nil; |
| 21 | 21 | window[nwindow-1] = w; |
| 22 | 22 | |
| 23 | − memset(w, 0, sizeof(*w)); | |
| 24 | 23 | w->id = id++; |
| 25 | 24 | w->label = label; |
| 26 | 25 | |
| @@ -34,7 +34,7 @@ xattach(Window *w, char *winsize) · 33 unmodified lines | ||
| 34 | 34 | w->r = xmapwin(xw, havemin, w->r); |
| 35 | 35 | w->x = xw; |
| 36 | 36 | w->screenimage = xallocmemimage(w, w->r, xconn.chan, xw->screenpm); |
| 37 | − initscreenimage(w->screenimage); | |
| 37 | + // initscreenimage(w); | |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | Rectangle |