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