- /* get X server to connect to, if given as an argument */
- for (i=1;i<argc-1;i++)
- {
- char *dispstr="-display";
- int len=MAX(strlen(dispstr),strlen(argv[i]));
-
- if (len<4)
- continue;
- else if (!strncmp(argv[i],dispstr,len))
- {
- display_name=argv[i+1];
- break;
- }
- }
-
- /* connect to X server */
- if (!(display=XOpenDisplay(display_name)))
- {
- fprintf(stderr,"%s: cannot connect to X server %s\n",
- progname, XDisplayName(display_name));
- exit(-1);
- }
-
- screen = DefaultScreen(display);
- visual = DefaultVisual(display, screen);
- depth = DefaultDepth(display, screen);
- cmap = DefaultColormap(display, screen);
-
- /* look for good enough visual */
- vinfo_template.screen = screen;
- vinfo_template.class = (depth == 8 ? PseudoColor : TrueColor);
- vinfo_template.depth = depth;
- if ((vinfo = XGetVisualInfo(display, VisualScreenMask | VisualClassMask |
- VisualDepthMask, &vinfo_template, &num_visuals)))
- {
- visual = vinfo->visual;
- XFree((void *)vinfo);
- }
-
- /* got appropriate visual? */
- if (depth < 8)
- {
- printf("Sorry, displays with less than 8 bits per pixel not supported.\n");
- exit(-1);
- }
- else if ((depth ==8 && visual->class != PseudoColor) ||
- (depth > 8 && visual->class != TrueColor &&
- visual->class != DirectColor))
- {
- printf("Sorry, cannot get appropriate visual.\n");
- exit(-1);
- }
-}
-
-void InitWindow(int argc, char *argv[])
-{
- unsigned int border_width = 4;
- Pixmap icon_pixmap, iconmask_pixmap;
- unsigned int icon_width,icon_height;
- int icon_hot_x,icon_hot_y;
- char icon_filename[256];
- XSizeHints size_hints;
- XWMHints wm_hints;
- XClassHint class_hints;
- XTextProperty windowName, iconName;
- XGCValues gc_values;
- unsigned long gc_valuemask;
- char *window_name = WINDOWTITLE_STRING;
- char *icon_name = WINDOWTITLE_STRING;
- long window_event_mask;
- Atom proto_atom = None, delete_atom = None;
- int screen_width, screen_height;
- int win_xpos = WIN_XPOS, win_ypos = WIN_YPOS;
- unsigned long pen_fg = WhitePixel(display,screen);
- unsigned long pen_bg = BlackPixel(display,screen);
-
-#ifndef MSDOS
- static struct IconFileInfo icon_pic =
- {
- "rocks_icon.xbm",
- "rocks_iconmask.xbm"
- };
-#endif
-
- screen_width = XDisplayWidth(display, screen);
- screen_height = XDisplayHeight(display, screen);
-
- width = WIN_XSIZE;
- height = WIN_YSIZE;
-
- win_xpos = (screen_width - width) / 2;
- win_ypos = (screen_height - height) / 2;