- int ix;
- int fullscreen = 0;
- int on_root = 0;
-
- int undef = -65536;
- int x = undef, y = undef;
- int w = 500, h = 500;
- char *dpystr = (char *) getenv ("DISPLAY");
- char *geom = 0;
- int screen;
- Visual *visual;
- XWindowAttributes xgwa;
- XSetWindowAttributes xswa;
- unsigned long xswa_mask = 0;
- XSizeHints hints;
- GLXContext glx_context = 0;
-
- memset (&hints, 0, sizeof(hints));
-
- for (ix=1; ix<*argc; ix++)
- {
- if (argv[ix][0] == '-' && argv[ix][1] == '-')
- argv[ix]++;
- if (!strcmp(argv[ix], "-geometry") ||
- !strcmp(argv[ix], "-geom"))
- {
- if (on_root || fullscreen) usage();
- geom = argv[++ix];
- }
- else if (!strcmp(argv[ix], "-display") ||
- !strcmp(argv[ix], "-disp") ||
- !strcmp(argv[ix], "-dpy") ||
- !strcmp(argv[ix], "-d"))
- dpystr = argv[++ix];
- else if (!strcmp(argv[ix], "-root"))
- {
- if (geom || fullscreen) usage();
- on_root = 1;
- }
- else if (!strcmp(argv[ix], "-fullscreen") ||
- !strcmp(argv[ix], "-full"))
- {
- if (on_root || geom) usage();
- fullscreen = 1;
- }
- else if (!strcmp(argv[ix], "-wireframe") ||
- !strcmp(argv[ix], "-wire"))
- {
- wireframe = 1;
- }
- else
- {
- usage();
- }
- }
-
- dpy = XOpenDisplay (dpystr);
- if (!dpy) exit (1);
-
- screen = DefaultScreen (dpy);
-
- XA_WM_PROTOCOLS = XInternAtom (dpy, "WM_PROTOCOLS", False);
- XA_WM_DELETE_WINDOW = XInternAtom (dpy, "WM_DELETE_WINDOW", False);
-
- if (on_root)
- {
- window = RootWindow (dpy, screen);
- XGetWindowAttributes (dpy, window, &xgwa);
- visual = xgwa.visual;
- w = xgwa.width;
- h = xgwa.height;
- }
- else
- {
- int ww = WidthOfScreen (DefaultScreenOfDisplay (dpy));
- int hh = HeightOfScreen (DefaultScreenOfDisplay (dpy));
-
- if (fullscreen)
- {
- w = ww;
- h = hh;
- }
- else if (geom)
- {
- /* Since we're not linking against Xt or GLUT, we get to parse
- the `-geometry' argument ourselves. YAY.
- */
- char c;
- if (4 == sscanf (geom, "=%dx%d+%d+%d%c", &w, &h, &x, &y, &c))
- ;
- else if (4 == sscanf (geom, "=%dx%d-%d+%d%c", &w, &h, &x, &y, &c))
- x = ww-w-x;
- else if (4 == sscanf (geom, "=%dx%d+%d-%d%c", &w, &h, &x, &y, &c))
- y = hh-h-y;
- else if (4 == sscanf (geom, "=%dx%d-%d-%d%c", &w, &h, &x, &y, &c))
- x = ww-w-x, y = hh-h-y;
- else if (2 == sscanf (geom, "=%dx%d%c", &w, &h, &c))
- ;
- else if (2 == sscanf (geom, "+%d+%d%c", &x, &y, &c))
- ;
- else if (2 == sscanf (geom, "-%d+%d%c", &x, &y, &c))
- x = ww-w-x;
- else if (2 == sscanf (geom, "+%d-%d%c", &x, &y, &c))
- y = hh-h-y;
- else if (2 == sscanf (geom, "-%d-%d%c", &x, &y, &c))
- x = ww-w-x, y = hh-h-y;
- else
- {
- fprintf (stderr, "%s: unparsable geometry: %s\n",
- progname, geom);
- exit (1);
- }
-
- hints.flags = USSize;
- hints.width = w;
- hints.height = h;
- if (x != undef && y != undef)
- {
- hints.flags |= USPosition;
- hints.x = x;
- hints.y = y;
- }
- }