Blob


1 /*
2 * Some of the stuff in this file is not X-dependent and should be elsewhere.
3 */
4 #include <u.h>
5 #include "x11-inc.h"
6 #include <libc.h>
7 #include <draw.h>
8 #include <memdraw.h>
9 #include <keyboard.h>
10 #include <mouse.h>
11 #include <cursor.h>
12 #include "x11-memdraw.h"
14 static Memimage *xattach(char*);
15 static void plan9cmap(void);
16 static int setupcmap(XWindow);
17 static int xreplacescreenimage(void);
18 static XGC xgc(XDrawable, int, int);
19 static Image *getimage0(Display*, Image*);
21 Xprivate _x;
23 Display*
24 _initdisplay(void (*error)(Display*, char*), char *label)
25 {
26 Display *d;
27 Memimage *m;
29 /*
30 * This rfork(RFNOTEG) isn't exactly right,
31 * but we need some way to signal window
32 * closes. Right now we post a hangup
33 * note to the note group, which kills a whole
34 * lot more than just the current program
35 * if we don't do this.
36 */
37 rfork(RFNOTEG);
38 memimageinit();
40 d = mallocz(sizeof(Display), 1);
41 if(d == nil)
42 return nil;
44 d->buf = malloc(16000+5);
45 d->obuf = malloc(16000);
46 if(d->buf == nil || d->obuf == nil){
47 free(d->buf);
48 free(d->obuf);
49 free(d);
50 return nil;
51 }
52 d->bufsize = 16000;
53 d->obufsize = 16000;
54 d->bufp = d->buf;
55 d->obufp = d->obuf;
57 m = xattach(label);
58 if(m == nil){
59 free(d);
60 return nil;
61 }
63 d->error = error;
64 _initdisplaymemimage(d, m);
65 d->screenimage = getimage0(d, 0);
66 return d;
67 }
69 static Image*
70 getimage0(Display *d, Image *image)
71 {
72 char info[12*12+1];
73 uchar *a;
74 int n;
75 extern int _freeimage1(Image*);
77 /*
78 * If there's an old screen, it has id 0. The 'J' request below
79 * will try to install the new screen as id 0, so the old one
80 * must be freed first.
81 */
82 if(image){
83 _freeimage1(image);
84 memset(image, 0, sizeof(Image));
85 }
87 a = bufimage(d, 2);
88 a[0] = 'J';
89 a[1] = 'I';
90 if(flushimage(d, 0) < 0){
91 fprint(2, "cannot read screen info: %r\n");
92 abort();
93 }
95 n = _drawmsgread(d, info, sizeof info);
96 if(n != 12*12){
97 fprint(2, "short screen info\n");
98 abort();
99 }
101 if(image == nil){
102 image = mallocz(sizeof(Image), 1);
103 if(image == nil){
104 fprint(2, "cannot allocate image: %r\n");
105 abort();
109 image->display = d;
110 image->id = 0;
111 image->chan = strtochan(info+2*12);
112 image->depth = chantodepth(image->chan);
113 image->repl = atoi(info+3*12);
114 image->r.min.x = atoi(info+4*12);
115 image->r.min.y = atoi(info+5*12);
116 image->r.max.x = atoi(info+6*12);
117 image->r.max.y = atoi(info+7*12);
118 image->clipr.min.x = atoi(info+8*12);
119 image->clipr.min.y = atoi(info+9*12);
120 image->clipr.max.x = atoi(info+10*12);
121 image->clipr.max.y = atoi(info+11*12);
122 return image;
125 int
126 getwindow(Display *d, int ref)
128 Image *i;
129 Image *oi;
131 if(_x.destroyed)
132 postnote(PNGROUP, getpgrp(), "hangup");
133 if(xreplacescreenimage() == 0)
134 return 0;
136 /*
137 * Libdraw promises not to change the value of "screen",
138 * so we have to reuse the image structure
139 * memory we already have.
140 */
141 oi = d->screenimage;
142 i = getimage0(d, oi);
143 screen = d->screenimage = d->image = i;
144 // fprint(2, "getwindow %p -> %p\n", oi, i);
145 return 0;
148 static int
149 xerror(XDisplay *d, XErrorEvent *e)
151 char buf[200];
153 if(e->request_code == 42) /* XSetInputFocus */
154 return 0;
155 if(e->request_code == 18) /* XChangeProperty */
156 return 0;
158 print("X error: error_code=%d, request_code=%d, minor=%d disp=%p\n",
159 e->error_code, e->request_code, e->minor_code, d);
160 XGetErrorText(d, e->error_code, buf, sizeof buf);
161 print("%s\n", buf);
162 return 0;
165 static int
166 xioerror(XDisplay *d)
168 print("X I/O error\n");
169 abort();
170 return -1;
174 static Memimage*
175 xattach(char *label)
177 char *argv[2], *disp;
178 int i, n, xrootid;
179 Rectangle r;
180 XClassHint classhint;
181 XDrawable pmid;
182 XPixmapFormatValues *pfmt;
183 XScreen *xscreen;
184 XSetWindowAttributes attr;
185 XSizeHints normalhint;
186 XTextProperty name;
187 XVisualInfo xvi;
188 XWindow xrootwin;
189 XWindowAttributes wattr;
190 XWMHints hint;
191 Atom atoms[2];
193 /*
194 if(XInitThreads() == 0){
195 fprint(2, "XInitThreads failed\n");
196 abort();
198 */
200 /*
201 * Connect to X server.
202 */
203 _x.display = XOpenDisplay(NULL);
204 if(_x.display == nil){
205 disp = getenv("DISPLAY");
206 werrstr("XOpenDisplay %s: %r", disp ? disp : ":0");
207 free(disp);
208 return nil;
210 XSetErrorHandler(xerror);
211 XSetIOErrorHandler(xioerror);
212 xrootid = DefaultScreen(_x.display);
213 xrootwin = DefaultRootWindow(_x.display);
215 /*
216 * Figure out underlying screen format.
217 */
218 if(XMatchVisualInfo(_x.display, xrootid, 16, TrueColor, &xvi)
219 || XMatchVisualInfo(_x.display, xrootid, 16, DirectColor, &xvi)){
220 _x.vis = xvi.visual;
221 _x.depth = 16;
223 else
224 if(XMatchVisualInfo(_x.display, xrootid, 15, TrueColor, &xvi)
225 || XMatchVisualInfo(_x.display, xrootid, 15, DirectColor, &xvi)){
226 _x.vis = xvi.visual;
227 _x.depth = 15;
229 else
230 if(XMatchVisualInfo(_x.display, xrootid, 24, TrueColor, &xvi)
231 || XMatchVisualInfo(_x.display, xrootid, 24, DirectColor, &xvi)){
232 _x.vis = xvi.visual;
233 _x.depth = 24;
235 else
236 if(XMatchVisualInfo(_x.display, xrootid, 8, PseudoColor, &xvi)
237 || XMatchVisualInfo(_x.display, xrootid, 8, StaticColor, &xvi)){
238 if(_x.depth > 8){
239 werrstr("can't deal with colormapped depth %d screens",
240 _x.depth);
241 goto err0;
243 _x.vis = xvi.visual;
244 _x.depth = 8;
246 else{
247 _x.depth = DefaultDepth(_x.display, xrootid);
248 if(_x.depth != 8){
249 werrstr("can't understand depth %d screen", _x.depth);
250 goto err0;
252 _x.vis = DefaultVisual(_x.display, xrootid);
255 if(DefaultDepth(_x.display, xrootid) == _x.depth)
256 _x.usetable = 1;
258 /*
259 * _x.depth is only the number of significant pixel bits,
260 * not the total number of pixel bits. We need to walk the
261 * display list to find how many actual bits are used
262 * per pixel.
263 */
264 _x.chan = 0;
265 pfmt = XListPixmapFormats(_x.display, &n);
266 for(i=0; i<n; i++){
267 if(pfmt[i].depth == _x.depth){
268 switch(pfmt[i].bits_per_pixel){
269 case 1: /* untested */
270 _x.chan = GREY1;
271 break;
272 case 2: /* untested */
273 _x.chan = GREY2;
274 break;
275 case 4: /* untested */
276 _x.chan = GREY4;
277 break;
278 case 8:
279 _x.chan = CMAP8;
280 break;
281 case 15:
282 _x.chan = RGB15;
283 break;
284 case 16: /* how to tell RGB15? */
285 _x.chan = RGB16;
286 break;
287 case 24: /* untested (impossible?) */
288 _x.chan = RGB24;
289 break;
290 case 32:
291 _x.chan = XRGB32;
292 break;
296 if(_x.chan == 0){
297 werrstr("could not determine screen pixel format");
298 goto err0;
301 /*
302 * Set up color map if necessary.
303 */
304 xscreen = DefaultScreenOfDisplay(_x.display);
305 _x.cmap = DefaultColormapOfScreen(xscreen);
306 if(_x.vis->class != StaticColor){
307 plan9cmap();
308 setupcmap(xrootwin);
311 /*
312 * We get to choose the initial rectangle size.
313 * This is arbitrary. In theory we should read the
314 * command line and allow the traditional X options.
315 */
316 r = Rect(0, 0, WidthOfScreen(xscreen)*3/4,
317 HeightOfScreen(xscreen)*3/4);
319 memset(&attr, 0, sizeof attr);
320 attr.colormap = _x.cmap;
321 attr.background_pixel = ~0;
322 attr.border_pixel = 0;
323 _x.drawable = XCreateWindow(
324 _x.display, /* display */
325 xrootwin, /* parent */
326 0, /* x */
327 0, /* y */
328 Dx(r), /* width */
329 Dy(r), /* height */
330 0, /* border width */
331 _x.depth, /* depth */
332 InputOutput, /* class */
333 _x.vis, /* visual */
334 /* valuemask */
335 CWBackPixel|CWBorderPixel|CWColormap,
336 &attr /* attributes (the above aren't?!) */
337 );
339 /*
340 * Label and other properties required by ICCCCM.
341 */
342 memset(&name, 0, sizeof name);
343 if(label == nil)
344 label = "pjw-face-here";
345 name.value = (uchar*)label;
346 name.encoding = XA_STRING;
347 name.format = 8;
348 name.nitems = strlen((char*)name.value);
350 memset(&normalhint, 0, sizeof normalhint);
351 normalhint.flags = USSize|PMaxSize;
352 normalhint.max_width = WidthOfScreen(xscreen);
353 normalhint.max_height = HeightOfScreen(xscreen);
355 memset(&hint, 0, sizeof hint);
356 hint.flags = InputHint|StateHint;
357 hint.input = 1;
358 hint.initial_state = NormalState;
360 memset(&classhint, 0, sizeof classhint);
361 classhint.res_name = label;
362 classhint.res_class = label;
364 argv[0] = label;
365 argv[1] = nil;
367 XSetWMProperties(
368 _x.display, /* display */
369 _x.drawable, /* window */
370 &name, /* XA_WM_NAME property */
371 &name, /* XA_WM_ICON_NAME property */
372 argv, /* XA_WM_COMMAND */
373 1, /* argc */
374 &normalhint, /* XA_WM_NORMAL_HINTS */
375 &hint, /* XA_WM_HINTS */
376 &classhint /* XA_WM_CLASSHINTS */
377 );
378 XFlush(_x.display);
380 /*
381 * Look up clipboard atom.
382 */
383 _x.clipboard = XInternAtom(_x.display, "CLIPBOARD", False);
384 _x.utf8string = XInternAtom(_x.display, "UTF8_STRING", False);
385 _x.targets = XInternAtom(_x.display, "TARGETS", False);
386 _x.text = XInternAtom(_x.display, "TEXT", False);
387 _x.compoundtext = XInternAtom(_x.display, "COMPOUND_TEXT", False);
388 _x.takefocus = XInternAtom(_x.display, "WM_TAKE_FOCUS", False);
389 _x.losefocus = XInternAtom(_x.display, "_9WM_LOSE_FOCUS", False);
390 _x.wmprotos = XInternAtom(_x.display, "WM_PROTOCOLS", False);
392 atoms[0] = _x.takefocus;
393 atoms[1] = _x.losefocus;
394 XChangeProperty(_x.display, _x.drawable, _x.wmprotos, XA_ATOM, 32,
395 PropModeReplace, (uchar*)atoms, 2);
397 /*
398 * Put the window on the screen, check to see what size we actually got.
399 */
400 XMapWindow(_x.display, _x.drawable);
401 XSync(_x.display, False);
403 if(!XGetWindowAttributes(_x.display, _x.drawable, &wattr))
404 fprint(2, "XGetWindowAttributes failed\n");
405 else if(wattr.width && wattr.height){
406 if(wattr.width != Dx(r) || wattr.height != Dy(r)){
407 r.max.x = wattr.width;
408 r.max.y = wattr.height;
410 }else
411 fprint(2, "XGetWindowAttributes: bad attrs\n");
413 /*
414 * Allocate our local backing store.
415 */
416 _x.screenr = r;
417 _x.screenpm = XCreatePixmap(_x.display, _x.drawable, Dx(r), Dy(r), _x.depth);
418 _x.nextscreenpm = _x.screenpm;
419 _x.screenimage = _xallocmemimage(r, _x.chan, _x.screenpm);
421 /*
422 * Allocate some useful graphics contexts for the future.
423 */
424 _x.gcfill = xgc(_x.screenpm, FillSolid, -1);
425 _x.gccopy = xgc(_x.screenpm, -1, -1);
426 _x.gcsimplesrc = xgc(_x.screenpm, FillStippled, -1);
427 _x.gczero = xgc(_x.screenpm, -1, -1);
428 _x.gcreplsrc = xgc(_x.screenpm, FillTiled, -1);
430 pmid = XCreatePixmap(_x.display, _x.drawable, 1, 1, 1);
431 _x.gcfill0 = xgc(pmid, FillSolid, 0);
432 _x.gccopy0 = xgc(pmid, -1, -1);
433 _x.gcsimplesrc0 = xgc(pmid, FillStippled, -1);
434 _x.gczero0 = xgc(pmid, -1, -1);
435 _x.gcreplsrc0 = xgc(pmid, FillTiled, -1);
436 XFreePixmap(_x.display, pmid);
438 /*
439 * Lots of display connections for various procs.
440 */
441 _x.kbdcon = XOpenDisplay(NULL);
442 _x.mousecon = XOpenDisplay(NULL);
443 _x.snarfcon = XOpenDisplay(NULL);
445 if(0) fprint(2, "x: display=%p kbd=%p mouse=%p snarf=%p\n",
446 _x.display, _x.kbdcon, _x.mousecon, _x.snarfcon);
448 _x.black = xscreen->black_pixel;
449 _x.white = xscreen->white_pixel;
451 return _x.screenimage;
453 err0:
454 fprint(2, "%r\n");
455 /*
456 * Should do a better job of cleaning up here.
457 */
458 XCloseDisplay(_x.display);
459 return nil;
462 int
463 drawsetlabel(Display *d, char *label)
465 char *argv[2];
466 XClassHint classhint;
467 XTextProperty name;
469 /*
470 * Label and other properties required by ICCCCM.
471 */
472 memset(&name, 0, sizeof name);
473 if(label == nil)
474 label = "pjw-face-here";
475 name.value = (uchar*)label;
476 name.encoding = XA_STRING;
477 name.format = 8;
478 name.nitems = strlen((char*)name.value);
480 memset(&classhint, 0, sizeof classhint);
481 classhint.res_name = label;
482 classhint.res_class = label;
484 argv[0] = label;
485 argv[1] = nil;
487 XSetWMProperties(
488 _x.display, /* display */
489 _x.drawable, /* window */
490 &name, /* XA_WM_NAME property */
491 &name, /* XA_WM_ICON_NAME property */
492 argv, /* XA_WM_COMMAND */
493 1, /* argc */
494 nil, /* XA_WM_NORMAL_HINTS */
495 nil, /* XA_WM_HINTS */
496 &classhint /* XA_WM_CLASSHINTS */
497 );
498 XFlush(_x.display);
499 return 0;
502 /*
503 * Create a GC with a particular fill style and XXX.
504 * Disable generation of GraphicsExpose/NoExpose events in the GC.
505 */
506 static XGC
507 xgc(XDrawable d, int fillstyle, int foreground)
509 XGC gc;
510 XGCValues v;
512 memset(&v, 0, sizeof v);
513 v.function = GXcopy;
514 v.graphics_exposures = False;
515 gc = XCreateGC(_x.display, d, GCFunction|GCGraphicsExposures, &v);
516 if(fillstyle != -1)
517 XSetFillStyle(_x.display, gc, fillstyle);
518 if(foreground != -1)
519 XSetForeground(_x.display, gc, 0);
520 return gc;
524 /*
525 * Initialize map with the Plan 9 rgbv color map.
526 */
527 static void
528 plan9cmap(void)
530 int r, g, b, cr, cg, cb, v, num, den, idx, v7, idx7;
531 static int once;
533 if(once)
534 return;
535 once = 1;
537 for(r=0; r!=4; r++)
538 for(g = 0; g != 4; g++)
539 for(b = 0; b!=4; b++)
540 for(v = 0; v!=4; v++){
541 den=r;
542 if(g > den)
543 den=g;
544 if(b > den)
545 den=b;
546 /* divide check -- pick grey shades */
547 if(den==0)
548 cr=cg=cb=v*17;
549 else {
550 num=17*(4*den+v);
551 cr=r*num/den;
552 cg=g*num/den;
553 cb=b*num/den;
555 idx = r*64 + v*16 + ((g*4 + b + v - r) & 15);
556 _x.map[idx].red = cr*0x0101;
557 _x.map[idx].green = cg*0x0101;
558 _x.map[idx].blue = cb*0x0101;
559 _x.map[idx].pixel = idx;
560 _x.map[idx].flags = DoRed|DoGreen|DoBlue;
562 v7 = v >> 1;
563 idx7 = r*32 + v7*16 + g*4 + b;
564 if((v & 1) == v7){
565 _x.map7to8[idx7][0] = idx;
566 if(den == 0) { /* divide check -- pick grey shades */
567 cr = ((255.0/7.0)*v7)+0.5;
568 cg = cr;
569 cb = cr;
571 else {
572 num=17*15*(4*den+v7*2)/14;
573 cr=r*num/den;
574 cg=g*num/den;
575 cb=b*num/den;
577 _x.map7[idx7].red = cr*0x0101;
578 _x.map7[idx7].green = cg*0x0101;
579 _x.map7[idx7].blue = cb*0x0101;
580 _x.map7[idx7].pixel = idx7;
581 _x.map7[idx7].flags = DoRed|DoGreen|DoBlue;
583 else
584 _x.map7to8[idx7][1] = idx;
588 /*
589 * Initialize and install the rgbv color map as a private color map
590 * for this application. It gets the best colors when it has the
591 * cursor focus.
593 * We always choose the best depth possible, but that might not
594 * be the default depth. On such "suboptimal" systems, we have to allocate an
595 * empty color map anyway, according to Axel Belinfante.
596 */
597 static int
598 setupcmap(XWindow w)
600 char buf[30];
601 int i;
602 u32int p, pp;
603 XColor c;
605 if(_x.depth <= 1)
606 return 0;
608 if(_x.depth >= 24) {
609 if(_x.usetable == 0)
610 _x.cmap = XCreateColormap(_x.display, w, _x.vis, AllocNone);
612 /*
613 * The pixel value returned from XGetPixel needs to
614 * be converted to RGB so we can call rgb2cmap()
615 * to translate between 24 bit X and our color. Unfortunately,
616 * the return value appears to be display server endian
617 * dependant. Therefore, we run some heuristics to later
618 * determine how to mask the int value correctly.
619 * Yeah, I know we can look at _x.vis->byte_order but
620 * some displays say MSB even though they run on LSB.
621 * Besides, this is more anal.
622 */
623 c = _x.map[19]; /* known to have different R, G, B values */
624 if(!XAllocColor(_x.display, _x.cmap, &c)){
625 werrstr("XAllocColor: %r");
626 return -1;
628 p = c.pixel;
629 pp = rgb2cmap((p>>16)&0xff,(p>>8)&0xff,p&0xff);
630 if(pp != _x.map[19].pixel) {
631 /* check if endian is other way */
632 pp = rgb2cmap(p&0xff,(p>>8)&0xff,(p>>16)&0xff);
633 if(pp != _x.map[19].pixel){
634 werrstr("cannot detect X server byte order");
635 return -1;
638 switch(_x.chan){
639 case RGB24:
640 _x.chan = BGR24;
641 break;
642 case XRGB32:
643 _x.chan = XBGR32;
644 break;
645 default:
646 werrstr("cannot byteswap channel %s",
647 chantostr(buf, _x.chan));
648 break;
651 }else if(_x.vis->class == TrueColor || _x.vis->class == DirectColor){
652 /*
653 * Do nothing. We have no way to express a
654 * mixed-endian 16-bit screen, so pretend they don't exist.
655 */
656 if(_x.usetable == 0)
657 _x.cmap = XCreateColormap(_x.display, w, _x.vis, AllocNone);
658 }else if(_x.vis->class == PseudoColor){
659 if(_x.usetable == 0){
660 _x.cmap = XCreateColormap(_x.display, w, _x.vis, AllocAll);
661 XStoreColors(_x.display, _x.cmap, _x.map, 256);
662 for(i = 0; i < 256; i++){
663 _x.tox11[i] = i;
664 _x.toplan9[i] = i;
666 }else{
667 for(i = 0; i < 128; i++){
668 c = _x.map7[i];
669 if(!XAllocColor(_x.display, _x.cmap, &c)){
670 werrstr("can't allocate colors in 7-bit map");
671 return -1;
673 _x.tox11[_x.map7to8[i][0]] = c.pixel;
674 _x.tox11[_x.map7to8[i][1]] = c.pixel;
675 _x.toplan9[c.pixel] = _x.map7to8[i][0];
678 }else{
679 werrstr("unsupported visual class %d", _x.vis->class);
680 return -1;
682 return 0;
685 void
686 flushmemscreen(Rectangle r)
688 if(_x.nextscreenpm != _x.screenpm){
689 qlock(&_x.screenlock);
690 XSync(_x.display, False);
691 XFreePixmap(_x.display, _x.screenpm);
692 _x.screenpm = _x.nextscreenpm;
693 qunlock(&_x.screenlock);
696 if(r.min.x >= r.max.x || r.min.y >= r.max.y)
697 return;
698 XCopyArea(_x.display, _x.screenpm, _x.drawable, _x.gccopy, r.min.x, r.min.y,
699 Dx(r), Dy(r), r.min.x, r.min.y);
700 XFlush(_x.display);
703 void
704 _xexpose(XEvent *e, XDisplay *xd)
706 XExposeEvent *xe;
707 Rectangle r;
709 qlock(&_x.screenlock);
710 if(_x.screenpm != _x.nextscreenpm){
711 qunlock(&_x.screenlock);
712 return;
714 xe = (XExposeEvent*)e;
715 r.min.x = xe->x;
716 r.min.y = xe->y;
717 r.max.x = xe->x+xe->width;
718 r.max.y = xe->y+xe->height;
719 XCopyArea(xd, _x.screenpm, _x.drawable, _x.gccopy, r.min.x, r.min.y,
720 Dx(r), Dy(r), r.min.x, r.min.y);
721 XSync(xd, False);
722 qunlock(&_x.screenlock);
725 int
726 _xdestroy(XEvent *e, XDisplay *xd)
728 XDestroyWindowEvent *xe;
730 xe = (XDestroyWindowEvent*)e;
731 if(xe->window == _x.drawable){
732 _x.destroyed = 1;
733 return 1;
735 return 0;
738 int
739 _xconfigure(XEvent *e, XDisplay *xd)
741 Rectangle r;
742 XConfigureEvent *xe = (XConfigureEvent*)e;
744 if(xe->width == Dx(_x.screenr) && xe->height == Dy(_x.screenr))
745 return 0;
746 if(xe->width==0 || xe->height==0)
747 fprint(2, "ignoring resize to %dx%d\n", xe->width, xe->height);
748 r = Rect(0, 0, xe->width, xe->height);
749 qlock(&_x.screenlock);
750 if(_x.screenpm != _x.nextscreenpm){
751 XCopyArea(xd, _x.screenpm, _x.drawable, _x.gccopy, r.min.x, r.min.y,
752 Dx(r), Dy(r), r.min.x, r.min.y);
753 XSync(xd, False);
755 qunlock(&_x.screenlock);
756 _x.newscreenr = r;
757 return 1;
760 static int
761 xreplacescreenimage(void)
763 Memimage *m;
764 XDrawable pixmap;
765 Rectangle r;
767 r = _x.newscreenr;
768 if(eqrect(_x.screenr, r))
769 return 0;
771 pixmap = XCreatePixmap(_x.display, _x.drawable, Dx(r), Dy(r), _x.depth);
772 m = _xallocmemimage(r, _x.chan, pixmap);
773 if(_x.nextscreenpm != _x.screenpm)
774 XFreePixmap(_x.display, _x.nextscreenpm);
775 _x.nextscreenpm = pixmap;
776 _x.screenr = r;
777 _drawreplacescreenimage(m);
778 return 1;