1 /***********************************************************
2 * Rocks'n'Diamonds -- McDuffin Strikes Back! *
3 *----------------------------------------------------------*
4 * ©1995 Artsoft Development *
6 * 33659 Bielefeld-Senne *
7 * Telefon: (0521) 493245 *
8 * eMail: aeglos@valinor.owl.de *
9 * aeglos@uni-paderborn.de *
10 * q99492@pbhrzx.uni-paderborn.de *
11 *----------------------------------------------------------*
13 ***********************************************************/
15 #ifdef USE_X11_LIBRARY
22 char *picture_filename;
23 char *picturemask_filename;
26 static void X11InitDisplay()
29 XVisualInfo vinfo_template, *vinfo;
34 /* connect to X server */
35 if (!(display = XOpenDisplay(options.display_name)))
36 Error(ERR_EXIT, "cannot connect to X server %s",
37 XDisplayName(options.display_name));
39 screen = DefaultScreen(display);
40 visual = DefaultVisual(display, screen);
41 depth = DefaultDepth(display, screen);
42 cmap = DefaultColormap(display, screen);
45 /* look for good enough visual */
46 vinfo_template.screen = screen;
47 vinfo_template.class = (depth == 8 ? PseudoColor : TrueColor);
48 vinfo_template.depth = depth;
49 if ((vinfo = XGetVisualInfo(display, VisualScreenMask | VisualClassMask |
50 VisualDepthMask, &vinfo_template, &num_visuals)))
52 visual = vinfo->visual;
56 /* got appropriate visual? */
59 printf("Sorry, displays with less than 8 bits per pixel not supported.\n");
62 else if ((depth ==8 && visual->class != PseudoColor) ||
63 (depth > 8 && visual->class != TrueColor &&
64 visual->class != DirectColor))
66 printf("Sorry, cannot get appropriate visual.\n");
72 static void X11InitWindow()
74 unsigned int border_width = 4;
76 unsigned long gc_valuemask;
78 XTextProperty windowName, iconName;
79 Pixmap icon_pixmap, iconmask_pixmap;
80 unsigned int icon_width, icon_height;
81 int icon_hot_x, icon_hot_y;
82 char icon_filename[256];
83 XSizeHints size_hints;
85 XClassHint class_hints;
86 char *window_name = WINDOW_TITLE_STRING;
87 char *icon_name = WINDOW_TITLE_STRING;
88 long window_event_mask;
89 Atom proto_atom = None, delete_atom = None;
91 int screen_width, screen_height;
92 int win_xpos = WIN_XPOS, win_ypos = WIN_YPOS;
93 unsigned long pen_fg = WhitePixel(display,screen);
94 unsigned long pen_bg = BlackPixel(display,screen);
95 const int width = WIN_XSIZE, height = WIN_YSIZE;
98 static struct IconFileInfo icon_pic =
105 screen_width = XDisplayWidth(display, screen);
106 screen_height = XDisplayHeight(display, screen);
108 win_xpos = (screen_width - width) / 2;
109 win_ypos = (screen_height - height) / 2;
111 window = XCreateSimpleWindow(display, RootWindow(display, screen),
112 win_xpos, win_ypos, width, height, border_width,
116 proto_atom = XInternAtom(display, "WM_PROTOCOLS", FALSE);
117 delete_atom = XInternAtom(display, "WM_DELETE_WINDOW", FALSE);
118 if ((proto_atom != None) && (delete_atom != None))
119 XChangeProperty(display, window, proto_atom, XA_ATOM, 32,
120 PropModePrepend, (unsigned char *) &delete_atom, 1);
122 sprintf(icon_filename, "%s/%s/%s",
123 options.ro_base_directory, GRAPHICS_DIRECTORY,
124 icon_pic.picture_filename);
125 XReadBitmapFile(display,window,icon_filename,
126 &icon_width,&icon_height,
127 &icon_pixmap,&icon_hot_x,&icon_hot_y);
129 Error(ERR_EXIT, "cannot read icon bitmap file '%s'", icon_filename);
131 sprintf(icon_filename, "%s/%s/%s",
132 options.ro_base_directory, GRAPHICS_DIRECTORY,
133 icon_pic.picturemask_filename);
134 XReadBitmapFile(display,window,icon_filename,
135 &icon_width,&icon_height,
136 &iconmask_pixmap,&icon_hot_x,&icon_hot_y);
137 if (!iconmask_pixmap)
138 Error(ERR_EXIT, "cannot read icon bitmap file '%s'", icon_filename);
140 size_hints.width = size_hints.min_width = size_hints.max_width = width;
141 size_hints.height = size_hints.min_height = size_hints.max_height = height;
142 size_hints.flags = PSize | PMinSize | PMaxSize;
144 if (win_xpos || win_ypos)
146 size_hints.x = win_xpos;
147 size_hints.y = win_ypos;
148 size_hints.flags |= PPosition;
151 if (!XStringListToTextProperty(&window_name, 1, &windowName))
152 Error(ERR_EXIT, "structure allocation for windowName failed");
154 if (!XStringListToTextProperty(&icon_name, 1, &iconName))
155 Error(ERR_EXIT, "structure allocation for iconName failed");
157 wm_hints.initial_state = NormalState;
158 wm_hints.input = True;
159 wm_hints.icon_pixmap = icon_pixmap;
160 wm_hints.icon_mask = iconmask_pixmap;
161 wm_hints.flags = StateHint | IconPixmapHint | IconMaskHint | InputHint;
163 class_hints.res_name = program_name;
164 class_hints.res_class = "Rocks'n'Diamonds";
166 XSetWMProperties(display, window, &windowName, &iconName,
167 NULL, 0, &size_hints, &wm_hints,
170 XFree(windowName.value);
171 XFree(iconName.value);
173 /* Select event types wanted */
175 ExposureMask | StructureNotifyMask | FocusChangeMask |
176 ButtonPressMask | ButtonReleaseMask | PointerMotionMask |
177 PointerMotionHintMask | KeyPressMask | KeyReleaseMask;
179 XSelectInput(display, window, window_event_mask);
182 /* create GC for drawing with window depth and background color (black) */
183 gc_values.graphics_exposures = False;
184 gc_values.foreground = pen_bg;
185 gc_values.background = pen_bg;
186 gc_valuemask = GCGraphicsExposures | GCForeground | GCBackground;
187 gc = XCreateGC(display, window, gc_valuemask, &gc_values);
190 inline void X11InitBufferedDisplay(DrawBuffer *unused1, DrawWindow *unused2)
195 XMapWindow(display, window);
198 pix[PIX_DB_BACK] = CreateBitmap(WIN_XSIZE, WIN_YSIZE, DEFAULT_DEPTH);
201 #endif /* USE_X11_LIBRARY */