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;
256 screenrect = Rect(0, 0, WidthOfScreen(xscreen), HeightOfScreen(xscreen));
257 windowrect = r;
259 memset(&attr, 0, sizeof attr);
260 attr.colormap = _x.cmap;
261 attr.background_pixel = ~0;
262 attr.border_pixel = 0;
263 _x.drawable = XCreateWindow(
264 _x.display, /* display */
265 xrootwin, /* parent */
266 x, /* x */
267 y, /* y */
268 Dx(r), /* width */
269 Dy(r), /* height */
270 0, /* border width */
271 _x.depth, /* depth */
272 InputOutput, /* class */
273 _x.vis, /* visual */
274 /* valuemask */
275 CWBackPixel|CWBorderPixel|CWColormap,
276 &attr /* attributes (the above aren't?!) */
277 );
279 /*
280 * Label and other properties required by ICCCCM.
281 */
282 memset(&name, 0, sizeof name);
283 if(label == nil)
284 label = "pjw-face-here";
285 name.value = (uchar*)label;
286 name.encoding = XA_STRING;
287 name.format = 8;
288 name.nitems = strlen((char*)name.value);
290 memset(&normalhint, 0, sizeof normalhint);
291 normalhint.flags = PSize|PMaxSize;
292 if(winsize && winsize[0]){
293 normalhint.flags &= ~PSize;
294 normalhint.flags |= USSize;
295 normalhint.width = Dx(r);
296 normalhint.height = Dy(r);
297 }else{
298 if((mask & WidthValue) && (mask & HeightValue)){
299 normalhint.flags &= ~PSize;
300 normalhint.flags |= USSize;
301 normalhint.width = width;
302 normalhint.height = height;
304 if((mask & WidthValue) && (mask & HeightValue)){
305 normalhint.flags |= USPosition;
306 normalhint.x = x;
307 normalhint.y = y;
311 normalhint.max_width = WidthOfScreen(xscreen);
312 normalhint.max_height = HeightOfScreen(xscreen);
314 memset(&hint, 0, sizeof hint);
315 hint.flags = InputHint|StateHint;
316 hint.input = 1;
317 hint.initial_state = NormalState;
319 memset(&classhint, 0, sizeof classhint);
320 classhint.res_name = label;
321 classhint.res_class = label;
323 argv[0] = label;
324 argv[1] = nil;
326 XSetWMProperties(
327 _x.display, /* display */
328 _x.drawable, /* window */
329 &name, /* XA_WM_NAME property */
330 &name, /* XA_WM_ICON_NAME property */
331 argv, /* XA_WM_COMMAND */
332 1, /* argc */
333 &normalhint, /* XA_WM_NORMAL_HINTS */
334 &hint, /* XA_WM_HINTS */
335 &classhint /* XA_WM_CLASSHINTS */
336 );
337 XFlush(_x.display);
339 if(havemin){
340 XWindowChanges ch;
342 memset(&ch, 0, sizeof ch);
343 ch.x = r.min.x;
344 ch.y = r.min.y;
345 XConfigureWindow(_x.display, _x.drawable, CWX|CWY, &ch);
346 /*
347 * Must pretend origin is 0,0 for X.
348 */
349 r = Rect(0,0,Dx(r),Dy(r));
351 /*
352 * Look up clipboard atom.
353 */
354 _x.clipboard = XInternAtom(_x.display, "CLIPBOARD", False);
355 _x.utf8string = XInternAtom(_x.display, "UTF8_STRING", False);
356 _x.targets = XInternAtom(_x.display, "TARGETS", False);
357 _x.text = XInternAtom(_x.display, "TEXT", False);
358 _x.compoundtext = XInternAtom(_x.display, "COMPOUND_TEXT", False);
359 _x.takefocus = XInternAtom(_x.display, "WM_TAKE_FOCUS", False);
360 _x.losefocus = XInternAtom(_x.display, "_9WM_LOSE_FOCUS", False);
361 _x.wmprotos = XInternAtom(_x.display, "WM_PROTOCOLS", False);
363 atoms[0] = _x.takefocus;
364 atoms[1] = _x.losefocus;
365 XChangeProperty(_x.display, _x.drawable, _x.wmprotos, XA_ATOM, 32,
366 PropModeReplace, (uchar*)atoms, 2);
368 /*
369 * Put the window on the screen, check to see what size we actually got.
370 */
371 XMapWindow(_x.display, _x.drawable);
372 XSync(_x.display, False);
374 if(!XGetWindowAttributes(_x.display, _x.drawable, &wattr))
375 fprint(2, "XGetWindowAttributes failed\n");
376 else if(wattr.width && wattr.height){
377 if(wattr.width != Dx(r) || wattr.height != Dy(r)){
378 r.max.x = wattr.width;
379 r.max.y = wattr.height;
381 }else
382 fprint(2, "XGetWindowAttributes: bad attrs\n");
384 /*
385 * Allocate our local backing store.
386 */
387 _x.screenr = r;
388 _x.screenpm = XCreatePixmap(_x.display, _x.drawable, Dx(r), Dy(r), _x.depth);
389 _x.nextscreenpm = _x.screenpm;
390 _x.screenimage = _xallocmemimage(r, _x.chan, _x.screenpm);
392 /*
393 * Allocate some useful graphics contexts for the future.
394 */
395 _x.gcfill = xgc(_x.screenpm, FillSolid, -1);
396 _x.gccopy = xgc(_x.screenpm, -1, -1);
397 _x.gcsimplesrc = xgc(_x.screenpm, FillStippled, -1);
398 _x.gczero = xgc(_x.screenpm, -1, -1);
399 _x.gcreplsrc = xgc(_x.screenpm, FillTiled, -1);
401 pmid = XCreatePixmap(_x.display, _x.drawable, 1, 1, 1);
402 _x.gcfill0 = xgc(pmid, FillSolid, 0);
403 _x.gccopy0 = xgc(pmid, -1, -1);
404 _x.gcsimplesrc0 = xgc(pmid, FillStippled, -1);
405 _x.gczero0 = xgc(pmid, -1, -1);
406 _x.gcreplsrc0 = xgc(pmid, FillTiled, -1);
407 XFreePixmap(_x.display, pmid);
409 return _x.screenimage;
411 err0:
412 /*
413 * Should do a better job of cleaning up here.
414 */
415 XCloseDisplay(_x.display);
416 return nil;
419 int
420 _xsetlabel(char *label)
422 XTextProperty name;
424 /*
425 * Label and other properties required by ICCCCM.
426 */
427 memset(&name, 0, sizeof name);
428 if(label == nil)
429 label = "pjw-face-here";
430 name.value = (uchar*)label;
431 name.encoding = XA_STRING;
432 name.format = 8;
433 name.nitems = strlen((char*)name.value);
435 XSetWMProperties(
436 _x.display, /* display */
437 _x.drawable, /* window */
438 &name, /* XA_WM_NAME property */
439 &name, /* XA_WM_ICON_NAME property */
440 nil, /* XA_WM_COMMAND */
441 0, /* argc */
442 nil, /* XA_WM_NORMAL_HINTS */
443 nil, /* XA_WM_HINTS */
444 nil /* XA_WM_CLASSHINTS */
445 );
446 XFlush(_x.display);
447 return 0;
450 /*
451 * Create a GC with a particular fill style and XXX.
452 * Disable generation of GraphicsExpose/NoExpose events in the GC.
453 */
454 static XGC
455 xgc(XDrawable d, int fillstyle, int foreground)
457 XGC gc;
458 XGCValues v;
460 memset(&v, 0, sizeof v);
461 v.function = GXcopy;
462 v.graphics_exposures = False;
463 gc = XCreateGC(_x.display, d, GCFunction|GCGraphicsExposures, &v);
464 if(fillstyle != -1)
465 XSetFillStyle(_x.display, gc, fillstyle);
466 if(foreground != -1)
467 XSetForeground(_x.display, gc, 0);
468 return gc;
472 /*
473 * Initialize map with the Plan 9 rgbv color map.
474 */
475 static void
476 plan9cmap(void)
478 int r, g, b, cr, cg, cb, v, num, den, idx, v7, idx7;
479 static int once;
481 if(once)
482 return;
483 once = 1;
485 for(r=0; r!=4; r++)
486 for(g = 0; g != 4; g++)
487 for(b = 0; b!=4; b++)
488 for(v = 0; v!=4; v++){
489 den=r;
490 if(g > den)
491 den=g;
492 if(b > den)
493 den=b;
494 /* divide check -- pick grey shades */
495 if(den==0)
496 cr=cg=cb=v*17;
497 else {
498 num=17*(4*den+v);
499 cr=r*num/den;
500 cg=g*num/den;
501 cb=b*num/den;
503 idx = r*64 + v*16 + ((g*4 + b + v - r) & 15);
504 _x.map[idx].red = cr*0x0101;
505 _x.map[idx].green = cg*0x0101;
506 _x.map[idx].blue = cb*0x0101;
507 _x.map[idx].pixel = idx;
508 _x.map[idx].flags = DoRed|DoGreen|DoBlue;
510 v7 = v >> 1;
511 idx7 = r*32 + v7*16 + g*4 + b;
512 if((v & 1) == v7){
513 _x.map7to8[idx7][0] = idx;
514 if(den == 0) { /* divide check -- pick grey shades */
515 cr = ((255.0/7.0)*v7)+0.5;
516 cg = cr;
517 cb = cr;
519 else {
520 num=17*15*(4*den+v7*2)/14;
521 cr=r*num/den;
522 cg=g*num/den;
523 cb=b*num/den;
525 _x.map7[idx7].red = cr*0x0101;
526 _x.map7[idx7].green = cg*0x0101;
527 _x.map7[idx7].blue = cb*0x0101;
528 _x.map7[idx7].pixel = idx7;
529 _x.map7[idx7].flags = DoRed|DoGreen|DoBlue;
531 else
532 _x.map7to8[idx7][1] = idx;
536 /*
537 * Initialize and install the rgbv color map as a private color map
538 * for this application. It gets the best colors when it has the
539 * cursor focus.
541 * We always choose the best depth possible, but that might not
542 * be the default depth. On such "suboptimal" systems, we have to allocate an
543 * empty color map anyway, according to Axel Belinfante.
544 */
545 static int
546 setupcmap(XWindow w)
548 char buf[30];
549 int i;
550 u32int p, pp;
551 XColor c;
553 if(_x.depth <= 1)
554 return 0;
556 if(_x.depth >= 24) {
557 if(_x.usetable == 0)
558 _x.cmap = XCreateColormap(_x.display, w, _x.vis, AllocNone);
560 /*
561 * The pixel value returned from XGetPixel needs to
562 * be converted to RGB so we can call rgb2cmap()
563 * to translate between 24 bit X and our color. Unfortunately,
564 * the return value appears to be display server endian
565 * dependant. Therefore, we run some heuristics to later
566 * determine how to mask the int value correctly.
567 * Yeah, I know we can look at _x.vis->byte_order but
568 * some displays say MSB even though they run on LSB.
569 * Besides, this is more anal.
570 */
571 c = _x.map[19]; /* known to have different R, G, B values */
572 if(!XAllocColor(_x.display, _x.cmap, &c)){
573 werrstr("XAllocColor: %r");
574 return -1;
576 p = c.pixel;
577 pp = rgb2cmap((p>>16)&0xff,(p>>8)&0xff,p&0xff);
578 if(pp != _x.map[19].pixel) {
579 /* check if endian is other way */
580 pp = rgb2cmap(p&0xff,(p>>8)&0xff,(p>>16)&0xff);
581 if(pp != _x.map[19].pixel){
582 werrstr("cannot detect X server byte order");
583 return -1;
586 switch(_x.chan){
587 case RGB24:
588 _x.chan = BGR24;
589 break;
590 case XRGB32:
591 _x.chan = XBGR32;
592 break;
593 default:
594 werrstr("cannot byteswap channel %s",
595 chantostr(buf, _x.chan));
596 break;
599 }else if(_x.vis->class == TrueColor || _x.vis->class == DirectColor){
600 /*
601 * Do nothing. We have no way to express a
602 * mixed-endian 16-bit screen, so pretend they don't exist.
603 */
604 if(_x.usetable == 0)
605 _x.cmap = XCreateColormap(_x.display, w, _x.vis, AllocNone);
606 }else if(_x.vis->class == PseudoColor){
607 if(_x.usetable == 0){
608 _x.cmap = XCreateColormap(_x.display, w, _x.vis, AllocAll);
609 XStoreColors(_x.display, _x.cmap, _x.map, 256);
610 for(i = 0; i < 256; i++){
611 _x.tox11[i] = i;
612 _x.toplan9[i] = i;
614 }else{
615 for(i = 0; i < 128; i++){
616 c = _x.map7[i];
617 if(!XAllocColor(_x.display, _x.cmap, &c)){
618 werrstr("can't allocate colors in 7-bit map");
619 return -1;
621 _x.tox11[_x.map7to8[i][0]] = c.pixel;
622 _x.tox11[_x.map7to8[i][1]] = c.pixel;
623 _x.toplan9[c.pixel] = _x.map7to8[i][0];
626 }else{
627 werrstr("unsupported visual class %d", _x.vis->class);
628 return -1;
630 return 0;
633 void
634 _flushmemscreen(Rectangle r)
636 if(_x.nextscreenpm != _x.screenpm){
637 qlock(&_x.screenlock);
638 XSync(_x.display, False);
639 XFreePixmap(_x.display, _x.screenpm);
640 _x.screenpm = _x.nextscreenpm;
641 qunlock(&_x.screenlock);
644 if(r.min.x >= r.max.x || r.min.y >= r.max.y)
645 return;
646 XCopyArea(_x.display, _x.screenpm, _x.drawable, _x.gccopy, r.min.x, r.min.y,
647 Dx(r), Dy(r), r.min.x, r.min.y);
648 XFlush(_x.display);
651 void
652 _xexpose(XEvent *e)
654 XExposeEvent *xe;
655 Rectangle r;
657 qlock(&_x.screenlock);
658 if(_x.screenpm != _x.nextscreenpm){
659 qunlock(&_x.screenlock);
660 return;
662 xe = (XExposeEvent*)e;
663 r.min.x = xe->x;
664 r.min.y = xe->y;
665 r.max.x = xe->x+xe->width;
666 r.max.y = xe->y+xe->height;
667 XCopyArea(_x.display, _x.screenpm, _x.drawable, _x.gccopy, r.min.x, r.min.y,
668 Dx(r), Dy(r), r.min.x, r.min.y);
669 XSync(_x.display, False);
670 qunlock(&_x.screenlock);
673 int
674 _xdestroy(XEvent *e)
676 XDestroyWindowEvent *xe;
678 xe = (XDestroyWindowEvent*)e;
679 if(xe->window == _x.drawable){
680 _x.destroyed = 1;
681 return 1;
683 return 0;
686 int
687 _xconfigure(XEvent *e)
689 Rectangle r;
690 XConfigureEvent *xe = (XConfigureEvent*)e;
692 if(!fullscreen){
693 int rx, ry;
694 XWindow w;
695 if(XTranslateCoordinates(_x.display, _x.drawable, DefaultRootWindow(_x.display), 0, 0, &rx, &ry, &w))
696 windowrect = Rect(rx, ry, rx+xe->width, ry+xe->height);
699 if(xe->width == Dx(_x.screenr) && xe->height == Dy(_x.screenr))
700 return 0;
701 r = Rect(0, 0, xe->width, xe->height);
703 qlock(&_x.screenlock);
704 if(_x.screenpm != _x.nextscreenpm){
705 XCopyArea(_x.display, _x.screenpm, _x.drawable, _x.gccopy, r.min.x, r.min.y,
706 Dx(r), Dy(r), r.min.x, r.min.y);
707 XSync(_x.display, False);
709 qunlock(&_x.screenlock);
710 _x.newscreenr = r;
711 return 1;
714 int
715 _xreplacescreenimage(void)
717 Memimage *m;
718 XDrawable pixmap;
719 Rectangle r;
721 r = _x.newscreenr;
723 pixmap = XCreatePixmap(_x.display, _x.drawable, Dx(r), Dy(r), _x.depth);
724 m = _xallocmemimage(r, _x.chan, pixmap);
725 if(_x.nextscreenpm != _x.screenpm)
726 XFreePixmap(_x.display, _x.nextscreenpm);
727 _x.nextscreenpm = pixmap;
728 _x.screenr = r;
729 _drawreplacescreenimage(m);
730 return 1;
733 static int
734 parsewinsize(char *s, Rectangle *r, int *havemin)
736 char c, *os;
737 int i, j, k, l;
739 os = s;
740 *havemin = 0;
741 *r = Rect(0,0,0,0);
742 if(!isdigit((uchar)*s))
743 goto oops;
744 i = strtol(s, &s, 0);
745 if(*s == 'x'){
746 s++;
747 if(!isdigit((uchar)*s))
748 goto oops;
749 j = strtol(s, &s, 0);
750 r->max.x = i;
751 r->max.y = j;
752 if(*s == 0)
753 return 0;
754 if(*s != '@')
755 goto oops;
757 s++;
758 if(!isdigit((uchar)*s))
759 goto oops;
760 i = strtol(s, &s, 0);
761 if(*s != ',' && *s != ' ')
762 goto oops;
763 s++;
764 if(!isdigit((uchar)*s))
765 goto oops;
766 j = strtol(s, &s, 0);
767 if(*s != 0)
768 goto oops;
769 *r = rectaddpt(*r, Pt(i,j));
770 *havemin = 1;
771 return 0;
774 c = *s;
775 if(c != ' ' && c != ',')
776 goto oops;
777 s++;
778 if(!isdigit((uchar)*s))
779 goto oops;
780 j = strtol(s, &s, 0);
781 if(*s != c)
782 goto oops;
783 s++;
784 if(!isdigit((uchar)*s))
785 goto oops;
786 k = strtol(s, &s, 0);
787 if(*s != c)
788 goto oops;
789 s++;
790 if(!isdigit((uchar)*s))
791 goto oops;
792 l = strtol(s, &s, 0);
793 if(*s != 0)
794 goto oops;
795 *r = Rect(i,j,k,l);
796 *havemin = 1;
797 return 0;
799 oops:
800 werrstr("bad syntax in window size '%s'", os);
801 return -1;