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