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 int parsewinsize(char*, Rectangle*, int*);
16 static void plan9cmap(void);
17 static int setupcmap(XWindow);
18 static XGC xgc(XDrawable, int, int);
20 Xprivate _x;
22 static int
23 xerror(XDisplay *d, XErrorEvent *e)
24 {
25 char buf[200];
27 if(e->request_code == 42) /* XSetInputFocus */
28 return 0;
29 if(e->request_code == 18) /* XChangeProperty */
30 return 0;
31 /*
32 * BadDrawable happens in apps that get resized a LOT,
33 * e.g. when KDE is configured to resize continuously
34 * during a window drag.
35 */
36 if(e->error_code == 9) /* BadDrawable */
37 return 0;
39 fprint(2, "X error: error_code=%d, request_code=%d, minor=%d disp=%p\n",
40 e->error_code, e->request_code, e->minor_code, d);
41 XGetErrorText(d, e->error_code, buf, sizeof buf);
42 fprint(2, "%s\n", buf);
43 return 0;
44 }
46 static int
47 xioerror(XDisplay *d)
48 {
49 /*print("X I/O error\n"); */
50 exit(0);
51 /*sysfatal("X I/O error\n");*/
52 abort();
53 return -1;
54 }
57 Memimage*
58 _xattach(char *label, char *winsize)
59 {
60 char *argv[2], *disp;
61 int i, havemin, height, mask, n, width, x, xrootid, y;
62 Rectangle r;
63 XClassHint classhint;
64 XDrawable pmid;
65 XPixmapFormatValues *pfmt;
66 XScreen *xscreen;
67 XSetWindowAttributes attr;
68 XSizeHints normalhint;
69 XTextProperty name;
70 XVisualInfo xvi;
71 XWindow xrootwin;
72 XWindowAttributes wattr;
73 XWMHints hint;
74 Atom atoms[2];
76 /*
77 if(XInitThreads() == 0){
78 fprint(2, "XInitThreads failed\n");
79 abort();
80 }
81 */
83 /*
84 * Connect to X server.
85 */
86 _x.display = XOpenDisplay(NULL);
87 if(_x.display == nil){
88 disp = getenv("DISPLAY");
89 werrstr("XOpenDisplay %s: %r", disp ? disp : ":0");
90 free(disp);
91 return nil;
92 }
93 _x.fd = ConnectionNumber(_x.display);
94 XSetErrorHandler(xerror);
95 XSetIOErrorHandler(xioerror);
96 xrootid = DefaultScreen(_x.display);
97 xrootwin = DefaultRootWindow(_x.display);
99 /*
100 * Figure out underlying screen format.
101 */
102 if(XMatchVisualInfo(_x.display, xrootid, 16, TrueColor, &xvi)
103 || XMatchVisualInfo(_x.display, xrootid, 16, DirectColor, &xvi)){
104 _x.vis = xvi.visual;
105 _x.depth = 16;
107 else
108 if(XMatchVisualInfo(_x.display, xrootid, 15, TrueColor, &xvi)
109 || XMatchVisualInfo(_x.display, xrootid, 15, DirectColor, &xvi)){
110 _x.vis = xvi.visual;
111 _x.depth = 15;
113 else
114 if(XMatchVisualInfo(_x.display, xrootid, 24, TrueColor, &xvi)
115 || XMatchVisualInfo(_x.display, xrootid, 24, DirectColor, &xvi)){
116 _x.vis = xvi.visual;
117 _x.depth = 24;
119 else
120 if(XMatchVisualInfo(_x.display, xrootid, 8, PseudoColor, &xvi)
121 || XMatchVisualInfo(_x.display, xrootid, 8, StaticColor, &xvi)){
122 if(_x.depth > 8){
123 werrstr("can't deal with colormapped depth %d screens",
124 _x.depth);
125 goto err0;
127 _x.vis = xvi.visual;
128 _x.depth = 8;
130 else{
131 _x.depth = DefaultDepth(_x.display, xrootid);
132 if(_x.depth != 8){
133 werrstr("can't understand depth %d screen", _x.depth);
134 goto err0;
136 _x.vis = DefaultVisual(_x.display, xrootid);
139 if(DefaultDepth(_x.display, xrootid) == _x.depth)
140 _x.usetable = 1;
142 /*
143 * _x.depth is only the number of significant pixel bits,
144 * not the total number of pixel bits. We need to walk the
145 * display list to find how many actual bits are used
146 * per pixel.
147 */
148 _x.chan = 0;
149 pfmt = XListPixmapFormats(_x.display, &n);
150 for(i=0; i<n; i++){
151 if(pfmt[i].depth == _x.depth){
152 switch(pfmt[i].bits_per_pixel){
153 case 1: /* untested */
154 _x.chan = GREY1;
155 break;
156 case 2: /* untested */
157 _x.chan = GREY2;
158 break;
159 case 4: /* untested */
160 _x.chan = GREY4;
161 break;
162 case 8:
163 _x.chan = CMAP8;
164 break;
165 case 15:
166 _x.chan = RGB15;
167 break;
168 case 16: /* how to tell RGB15? */
169 _x.chan = RGB16;
170 break;
171 case 24: /* untested (impossible?) */
172 _x.chan = RGB24;
173 break;
174 case 32:
175 _x.chan = XRGB32;
176 break;
180 if(_x.chan == 0){
181 werrstr("could not determine screen pixel format");
182 goto err0;
185 /*
186 * Set up color map if necessary.
187 */
188 xscreen = DefaultScreenOfDisplay(_x.display);
189 _x.cmap = DefaultColormapOfScreen(xscreen);
190 if(_x.vis->class != StaticColor){
191 plan9cmap();
192 setupcmap(xrootwin);
195 /*
196 * We get to choose the initial rectangle size.
197 * This is arbitrary. In theory we should read the
198 * command line and allow the traditional X options.
199 */
200 mask = 0;
201 x = 0;
202 y = 0;
203 if(winsize && winsize[0]){
204 if(parsewinsize(winsize, &r, &havemin) < 0)
205 sysfatal("%r");
206 }else{
207 /*
208 * Parse the various X resources. Thanks to Peter Canning.
209 */
210 char *screen_resources, *display_resources, *geom,
211 *geomrestype, *home, *file;
212 XrmDatabase database;
213 XrmValue geomres;
215 database = XrmGetDatabase(_x.display);
216 screen_resources = XScreenResourceString(xscreen);
217 if(screen_resources != nil){
218 XrmCombineDatabase(XrmGetStringDatabase(screen_resources), &database, False);
219 XFree(screen_resources);
222 display_resources = XResourceManagerString(_x.display);
223 if(display_resources == nil){
224 home = getenv("HOME");
225 if(home!=nil && (file=smprint("%s/.Xdefaults", home)) != nil){
226 XrmCombineFileDatabase(file, &database, False);
227 free(file);
229 free(home);
230 }else
231 XrmCombineDatabase(XrmGetStringDatabase(display_resources), &database, False);
233 geom = smprint("%s.geometry", label);
234 if(geom && XrmGetResource(database, geom, nil, &geomrestype, &geomres))
235 mask = XParseGeometry(geomres.addr, &x, &y, (uint*)&width, (uint*)&height);
236 free(geom);
238 if((mask & WidthValue) && (mask & HeightValue)){
239 r = Rect(0, 0, width, height);
240 }else{
241 r = Rect(0, 0, WidthOfScreen(xscreen)*3/4,
242 HeightOfScreen(xscreen)*3/4);
243 if(Dx(r) > Dy(r)*3/2)
244 r.max.x = r.min.x + Dy(r)*3/2;
245 if(Dy(r) > Dx(r)*3/2)
246 r.max.y = r.min.y + Dx(r)*3/2;
248 if(mask & XNegative){
249 x += WidthOfScreen(xscreen);
251 if(mask & YNegative){
252 y += HeightOfScreen(xscreen);
254 havemin = 0;
257 memset(&attr, 0, sizeof attr);
258 attr.colormap = _x.cmap;
259 attr.background_pixel = ~0;
260 attr.border_pixel = 0;
261 _x.drawable = XCreateWindow(
262 _x.display, /* display */
263 xrootwin, /* parent */
264 x, /* x */
265 y, /* y */
266 Dx(r), /* width */
267 Dy(r), /* height */
268 0, /* border width */
269 _x.depth, /* depth */
270 InputOutput, /* class */
271 _x.vis, /* visual */
272 /* valuemask */
273 CWBackPixel|CWBorderPixel|CWColormap,
274 &attr /* attributes (the above aren't?!) */
275 );
277 /*
278 * Label and other properties required by ICCCCM.
279 */
280 memset(&name, 0, sizeof name);
281 if(label == nil)
282 label = "pjw-face-here";
283 name.value = (uchar*)label;
284 name.encoding = XA_STRING;
285 name.format = 8;
286 name.nitems = strlen((char*)name.value);
288 memset(&normalhint, 0, sizeof normalhint);
289 normalhint.flags = PSize|PMaxSize;
290 if(winsize && winsize[0]){
291 normalhint.flags &= ~PSize;
292 normalhint.flags |= USSize;
293 normalhint.width = Dx(r);
294 normalhint.height = Dy(r);
295 }else{
296 if((mask & WidthValue) && (mask & HeightValue)){
297 normalhint.flags &= ~PSize;
298 normalhint.flags |= USSize;
299 normalhint.width = width;
300 normalhint.height = height;
302 if((mask & WidthValue) && (mask & HeightValue)){
303 normalhint.flags |= USPosition;
304 normalhint.x = x;
305 normalhint.y = y;
309 normalhint.max_width = WidthOfScreen(xscreen);
310 normalhint.max_height = HeightOfScreen(xscreen);
312 memset(&hint, 0, sizeof hint);
313 hint.flags = InputHint|StateHint;
314 hint.input = 1;
315 hint.initial_state = NormalState;
317 memset(&classhint, 0, sizeof classhint);
318 classhint.res_name = label;
319 classhint.res_class = label;
321 argv[0] = label;
322 argv[1] = nil;
324 XSetWMProperties(
325 _x.display, /* display */
326 _x.drawable, /* window */
327 &name, /* XA_WM_NAME property */
328 &name, /* XA_WM_ICON_NAME property */
329 argv, /* XA_WM_COMMAND */
330 1, /* argc */
331 &normalhint, /* XA_WM_NORMAL_HINTS */
332 &hint, /* XA_WM_HINTS */
333 &classhint /* XA_WM_CLASSHINTS */
334 );
335 XFlush(_x.display);
337 if(havemin){
338 XWindowChanges ch;
340 memset(&ch, 0, sizeof ch);
341 ch.x = r.min.x;
342 ch.y = r.min.y;
343 XConfigureWindow(_x.display, _x.drawable, CWX|CWY, &ch);
344 /*
345 * Must pretend origin is 0,0 for X.
346 */
347 r = Rect(0,0,Dx(r),Dy(r));
349 /*
350 * Look up clipboard atom.
351 */
352 _x.clipboard = XInternAtom(_x.display, "CLIPBOARD", False);
353 _x.utf8string = XInternAtom(_x.display, "UTF8_STRING", False);
354 _x.targets = XInternAtom(_x.display, "TARGETS", False);
355 _x.text = XInternAtom(_x.display, "TEXT", False);
356 _x.compoundtext = XInternAtom(_x.display, "COMPOUND_TEXT", False);
357 _x.takefocus = XInternAtom(_x.display, "WM_TAKE_FOCUS", False);
358 _x.losefocus = XInternAtom(_x.display, "_9WM_LOSE_FOCUS", False);
359 _x.wmprotos = XInternAtom(_x.display, "WM_PROTOCOLS", False);
361 atoms[0] = _x.takefocus;
362 atoms[1] = _x.losefocus;
363 XChangeProperty(_x.display, _x.drawable, _x.wmprotos, XA_ATOM, 32,
364 PropModeReplace, (uchar*)atoms, 2);
366 /*
367 * Put the window on the screen, check to see what size we actually got.
368 */
369 XMapWindow(_x.display, _x.drawable);
370 XSync(_x.display, False);
372 if(!XGetWindowAttributes(_x.display, _x.drawable, &wattr))
373 fprint(2, "XGetWindowAttributes failed\n");
374 else if(wattr.width && wattr.height){
375 if(wattr.width != Dx(r) || wattr.height != Dy(r)){
376 r.max.x = wattr.width;
377 r.max.y = wattr.height;
379 }else
380 fprint(2, "XGetWindowAttributes: bad attrs\n");
382 /*
383 * Allocate our local backing store.
384 */
385 _x.screenr = r;
386 _x.screenpm = XCreatePixmap(_x.display, _x.drawable, Dx(r), Dy(r), _x.depth);
387 _x.nextscreenpm = _x.screenpm;
388 _x.screenimage = _xallocmemimage(r, _x.chan, _x.screenpm);
390 /*
391 * Allocate some useful graphics contexts for the future.
392 */
393 _x.gcfill = xgc(_x.screenpm, FillSolid, -1);
394 _x.gccopy = xgc(_x.screenpm, -1, -1);
395 _x.gcsimplesrc = xgc(_x.screenpm, FillStippled, -1);
396 _x.gczero = xgc(_x.screenpm, -1, -1);
397 _x.gcreplsrc = xgc(_x.screenpm, FillTiled, -1);
399 pmid = XCreatePixmap(_x.display, _x.drawable, 1, 1, 1);
400 _x.gcfill0 = xgc(pmid, FillSolid, 0);
401 _x.gccopy0 = xgc(pmid, -1, -1);
402 _x.gcsimplesrc0 = xgc(pmid, FillStippled, -1);
403 _x.gczero0 = xgc(pmid, -1, -1);
404 _x.gcreplsrc0 = xgc(pmid, FillTiled, -1);
405 XFreePixmap(_x.display, pmid);
407 return _x.screenimage;
409 err0:
410 /*
411 * Should do a better job of cleaning up here.
412 */
413 XCloseDisplay(_x.display);
414 return nil;
417 int
418 _xsetlabel(char *label)
420 XTextProperty name;
422 /*
423 * Label and other properties required by ICCCCM.
424 */
425 memset(&name, 0, sizeof name);
426 if(label == nil)
427 label = "pjw-face-here";
428 name.value = (uchar*)label;
429 name.encoding = XA_STRING;
430 name.format = 8;
431 name.nitems = strlen((char*)name.value);
433 XSetWMProperties(
434 _x.display, /* display */
435 _x.drawable, /* window */
436 &name, /* XA_WM_NAME property */
437 &name, /* XA_WM_ICON_NAME property */
438 nil, /* XA_WM_COMMAND */
439 0, /* argc */
440 nil, /* XA_WM_NORMAL_HINTS */
441 nil, /* XA_WM_HINTS */
442 nil /* XA_WM_CLASSHINTS */
443 );
444 XFlush(_x.display);
445 return 0;
448 /*
449 * Create a GC with a particular fill style and XXX.
450 * Disable generation of GraphicsExpose/NoExpose events in the GC.
451 */
452 static XGC
453 xgc(XDrawable d, int fillstyle, int foreground)
455 XGC gc;
456 XGCValues v;
458 memset(&v, 0, sizeof v);
459 v.function = GXcopy;
460 v.graphics_exposures = False;
461 gc = XCreateGC(_x.display, d, GCFunction|GCGraphicsExposures, &v);
462 if(fillstyle != -1)
463 XSetFillStyle(_x.display, gc, fillstyle);
464 if(foreground != -1)
465 XSetForeground(_x.display, gc, 0);
466 return gc;
470 /*
471 * Initialize map with the Plan 9 rgbv color map.
472 */
473 static void
474 plan9cmap(void)
476 int r, g, b, cr, cg, cb, v, num, den, idx, v7, idx7;
477 static int once;
479 if(once)
480 return;
481 once = 1;
483 for(r=0; r!=4; r++)
484 for(g = 0; g != 4; g++)
485 for(b = 0; b!=4; b++)
486 for(v = 0; v!=4; v++){
487 den=r;
488 if(g > den)
489 den=g;
490 if(b > den)
491 den=b;
492 /* divide check -- pick grey shades */
493 if(den==0)
494 cr=cg=cb=v*17;
495 else {
496 num=17*(4*den+v);
497 cr=r*num/den;
498 cg=g*num/den;
499 cb=b*num/den;
501 idx = r*64 + v*16 + ((g*4 + b + v - r) & 15);
502 _x.map[idx].red = cr*0x0101;
503 _x.map[idx].green = cg*0x0101;
504 _x.map[idx].blue = cb*0x0101;
505 _x.map[idx].pixel = idx;
506 _x.map[idx].flags = DoRed|DoGreen|DoBlue;
508 v7 = v >> 1;
509 idx7 = r*32 + v7*16 + g*4 + b;
510 if((v & 1) == v7){
511 _x.map7to8[idx7][0] = idx;
512 if(den == 0) { /* divide check -- pick grey shades */
513 cr = ((255.0/7.0)*v7)+0.5;
514 cg = cr;
515 cb = cr;
517 else {
518 num=17*15*(4*den+v7*2)/14;
519 cr=r*num/den;
520 cg=g*num/den;
521 cb=b*num/den;
523 _x.map7[idx7].red = cr*0x0101;
524 _x.map7[idx7].green = cg*0x0101;
525 _x.map7[idx7].blue = cb*0x0101;
526 _x.map7[idx7].pixel = idx7;
527 _x.map7[idx7].flags = DoRed|DoGreen|DoBlue;
529 else
530 _x.map7to8[idx7][1] = idx;
534 /*
535 * Initialize and install the rgbv color map as a private color map
536 * for this application. It gets the best colors when it has the
537 * cursor focus.
539 * We always choose the best depth possible, but that might not
540 * be the default depth. On such "suboptimal" systems, we have to allocate an
541 * empty color map anyway, according to Axel Belinfante.
542 */
543 static int
544 setupcmap(XWindow w)
546 char buf[30];
547 int i;
548 u32int p, pp;
549 XColor c;
551 if(_x.depth <= 1)
552 return 0;
554 if(_x.depth >= 24) {
555 if(_x.usetable == 0)
556 _x.cmap = XCreateColormap(_x.display, w, _x.vis, AllocNone);
558 /*
559 * The pixel value returned from XGetPixel needs to
560 * be converted to RGB so we can call rgb2cmap()
561 * to translate between 24 bit X and our color. Unfortunately,
562 * the return value appears to be display server endian
563 * dependant. Therefore, we run some heuristics to later
564 * determine how to mask the int value correctly.
565 * Yeah, I know we can look at _x.vis->byte_order but
566 * some displays say MSB even though they run on LSB.
567 * Besides, this is more anal.
568 */
569 c = _x.map[19]; /* known to have different R, G, B values */
570 if(!XAllocColor(_x.display, _x.cmap, &c)){
571 werrstr("XAllocColor: %r");
572 return -1;
574 p = c.pixel;
575 pp = rgb2cmap((p>>16)&0xff,(p>>8)&0xff,p&0xff);
576 if(pp != _x.map[19].pixel) {
577 /* check if endian is other way */
578 pp = rgb2cmap(p&0xff,(p>>8)&0xff,(p>>16)&0xff);
579 if(pp != _x.map[19].pixel){
580 werrstr("cannot detect X server byte order");
581 return -1;
584 switch(_x.chan){
585 case RGB24:
586 _x.chan = BGR24;
587 break;
588 case XRGB32:
589 _x.chan = XBGR32;
590 break;
591 default:
592 werrstr("cannot byteswap channel %s",
593 chantostr(buf, _x.chan));
594 break;
597 }else if(_x.vis->class == TrueColor || _x.vis->class == DirectColor){
598 /*
599 * Do nothing. We have no way to express a
600 * mixed-endian 16-bit screen, so pretend they don't exist.
601 */
602 if(_x.usetable == 0)
603 _x.cmap = XCreateColormap(_x.display, w, _x.vis, AllocNone);
604 }else if(_x.vis->class == PseudoColor){
605 if(_x.usetable == 0){
606 _x.cmap = XCreateColormap(_x.display, w, _x.vis, AllocAll);
607 XStoreColors(_x.display, _x.cmap, _x.map, 256);
608 for(i = 0; i < 256; i++){
609 _x.tox11[i] = i;
610 _x.toplan9[i] = i;
612 }else{
613 for(i = 0; i < 128; i++){
614 c = _x.map7[i];
615 if(!XAllocColor(_x.display, _x.cmap, &c)){
616 werrstr("can't allocate colors in 7-bit map");
617 return -1;
619 _x.tox11[_x.map7to8[i][0]] = c.pixel;
620 _x.tox11[_x.map7to8[i][1]] = c.pixel;
621 _x.toplan9[c.pixel] = _x.map7to8[i][0];
624 }else{
625 werrstr("unsupported visual class %d", _x.vis->class);
626 return -1;
628 return 0;
631 void
632 _flushmemscreen(Rectangle r)
634 if(_x.nextscreenpm != _x.screenpm){
635 qlock(&_x.screenlock);
636 XSync(_x.display, False);
637 XFreePixmap(_x.display, _x.screenpm);
638 _x.screenpm = _x.nextscreenpm;
639 qunlock(&_x.screenlock);
642 if(r.min.x >= r.max.x || r.min.y >= r.max.y)
643 return;
644 XCopyArea(_x.display, _x.screenpm, _x.drawable, _x.gccopy, r.min.x, r.min.y,
645 Dx(r), Dy(r), r.min.x, r.min.y);
646 XFlush(_x.display);
649 void
650 _xexpose(XEvent *e)
652 XExposeEvent *xe;
653 Rectangle r;
655 qlock(&_x.screenlock);
656 if(_x.screenpm != _x.nextscreenpm){
657 qunlock(&_x.screenlock);
658 return;
660 xe = (XExposeEvent*)e;
661 r.min.x = xe->x;
662 r.min.y = xe->y;
663 r.max.x = xe->x+xe->width;
664 r.max.y = xe->y+xe->height;
665 XCopyArea(_x.display, _x.screenpm, _x.drawable, _x.gccopy, r.min.x, r.min.y,
666 Dx(r), Dy(r), r.min.x, r.min.y);
667 XSync(_x.display, False);
668 qunlock(&_x.screenlock);
671 int
672 _xdestroy(XEvent *e)
674 XDestroyWindowEvent *xe;
676 xe = (XDestroyWindowEvent*)e;
677 if(xe->window == _x.drawable){
678 _x.destroyed = 1;
679 return 1;
681 return 0;
684 int
685 _xconfigure(XEvent *e)
687 Rectangle r;
688 XConfigureEvent *xe = (XConfigureEvent*)e;
690 if(xe->width == Dx(_x.screenr) && xe->height == Dy(_x.screenr))
691 return 0;
692 r = Rect(0, 0, xe->width, xe->height);
693 qlock(&_x.screenlock);
694 if(_x.screenpm != _x.nextscreenpm){
695 XCopyArea(_x.display, _x.screenpm, _x.drawable, _x.gccopy, r.min.x, r.min.y,
696 Dx(r), Dy(r), r.min.x, r.min.y);
697 XSync(_x.display, False);
699 qunlock(&_x.screenlock);
700 _x.newscreenr = r;
701 return 1;
704 int
705 _xreplacescreenimage(void)
707 Memimage *m;
708 XDrawable pixmap;
709 Rectangle r;
711 r = _x.newscreenr;
712 if(eqrect(_x.screenr, r))
713 return 0;
715 pixmap = XCreatePixmap(_x.display, _x.drawable, Dx(r), Dy(r), _x.depth);
716 m = _xallocmemimage(r, _x.chan, pixmap);
717 if(_x.nextscreenpm != _x.screenpm)
718 XFreePixmap(_x.display, _x.nextscreenpm);
719 _x.nextscreenpm = pixmap;
720 _x.screenr = r;
721 _drawreplacescreenimage(m);
722 return 1;
725 static int
726 parsewinsize(char *s, Rectangle *r, int *havemin)
728 char c, *os;
729 int i, j, k, l;
731 os = s;
732 *havemin = 0;
733 *r = Rect(0,0,0,0);
734 if(!isdigit((uchar)*s))
735 goto oops;
736 i = strtol(s, &s, 0);
737 if(*s == 'x'){
738 s++;
739 if(!isdigit((uchar)*s))
740 goto oops;
741 j = strtol(s, &s, 0);
742 r->max.x = i;
743 r->max.y = j;
744 if(*s == 0)
745 return 0;
746 if(*s != '@')
747 goto oops;
749 s++;
750 if(!isdigit((uchar)*s))
751 goto oops;
752 i = strtol(s, &s, 0);
753 if(*s != ',' && *s != ' ')
754 goto oops;
755 s++;
756 if(!isdigit((uchar)*s))
757 goto oops;
758 j = strtol(s, &s, 0);
759 if(*s != 0)
760 goto oops;
761 *r = rectaddpt(*r, Pt(i,j));
762 *havemin = 1;
763 return 0;
766 c = *s;
767 if(c != ' ' && c != ',')
768 goto oops;
769 s++;
770 if(!isdigit((uchar)*s))
771 goto oops;
772 j = strtol(s, &s, 0);
773 if(*s != c)
774 goto oops;
775 s++;
776 if(!isdigit((uchar)*s))
777 goto oops;
778 k = strtol(s, &s, 0);
779 if(*s != c)
780 goto oops;
781 s++;
782 if(!isdigit((uchar)*s))
783 goto oops;
784 l = strtol(s, &s, 0);
785 if(*s != 0)
786 goto oops;
787 *r = Rect(i,j,k,l);
788 *havemin = 1;
789 return 0;
791 oops:
792 werrstr("bad syntax in window size '%s'", os);
793 return -1;