10 static char deffontname[] = "*default*";
13 int debuglockdisplay = 1;
30 initdraw(void (*error)(Display*, char*), char *fontname, char *label)
35 rfork(RFNOTEG); /* x11-event.c will postnote hangup */
36 display = _initdisplay(error, label); /* sets screen too */
41 display->screenimage = display->image;
46 df = getdefont(display);
47 display->defaultsubfont = df;
49 fprint(2, "imageinit: can't open default subfont: %r\n");
51 closedisplay(display);
56 fontname = getenv("font"); /* leak */
59 * Build fonts with caches==depth of screen, for speed.
60 * If conversion were faster, we'd use 0 and save memory.
63 snprint(buf, sizeof buf, "%d %d\n0 %d\t%s\n", df->height, df->ascent,
64 df->n-1, deffontname);
65 /*BUG: Need something better for this installsubfont("*default*", df); */
66 font = buildfont(display, buf, deffontname);
68 fprint(2, "initdraw: can't open default font: %r\n");
72 font = openfont(display, fontname); /* BUG: grey fonts */
74 fprint(2, "initdraw: can't open font %s: %r\n", fontname);
78 display->defaultfont = font;
80 display->white = allocimage(display, Rect(0,0,1,1), GREY1, 1, DWhite);
81 display->black = allocimage(display, Rect(0,0,1,1), GREY1, 1, DBlack);
82 if(display->white == nil || display->black == nil){
83 fprint(2, "initdraw: can't allocate white and black");
86 display->opaque = display->white;
87 display->transparent = display->black;
89 _screen = allocscreen(display->image, display->white, 0);
90 screen = _allocwindow(nil, _screen, display->image->r, Refnone, DWhite);
91 display->screenimage = screen;
92 draw(screen, screen->r, display->white, nil, ZP);
93 flushimage(display, 1);
96 * I don't see any reason to go away gracefully,
97 * and if some other proc exits holding the display
98 * lock, this atexit call never finishes.
100 * atexit(drawshutdown);
106 * Call with d unlocked.
107 * Note that disp->defaultfont and defaultsubfont are not freed here.
110 closedisplay(Display *disp)
119 if(disp->oldlabel[0]){
120 snprint(buf, sizeof buf, "%s/label", disp->windir);
121 fd = open(buf, OWRITE);
123 write(fd, disp->oldlabel, strlen(disp->oldlabel));
131 freeimage(disp->white);
133 freeimage(disp->black);
138 lockdisplay(Display *disp)
140 if(debuglockdisplay){
141 /* avoid busy looping; it's rare we collide anyway */
142 while(!canqlock(&disp->qlock)){
143 fprint(1, "proc %d waiting for display lock...\n", getpid());
151 unlockdisplay(Display *disp)
153 qunlock(&disp->qlock);
157 drawerror(Display *d, char *s)
164 errstr(err, sizeof err);
165 fprint(2, "draw: %s: %s\n", s, err);
180 if(_drawmsgwrite(d, d->buf, n) != n){
182 fprint(2, "flushimage fail: d=%p: %r\n", d); /**/
183 d->bufp = d->buf; /* might as well; chance of continuing */
191 flushimage(Display *d, int visible)
194 *d->bufp++ = 'v'; /* five bytes always reserved for this */
195 if(d->_isnewdisplay){
196 BPLONG(d->bufp, d->screenimage->id);
204 bufimage(Display *d, int n)
208 if(n<0 || d == nil || n>d->bufsize){
210 werrstr("bad count in bufimage");
213 if(d->bufp+n > d->buf+d->bufsize)