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 ***********************************************************/
17 #if defined(TARGET_X11)
26 char *picture_filename;
27 char *picturemask_filename;
31 static void X11InitDisplay();
32 static DrawWindow X11InitWindow();
34 inline void X11InitVideoDisplay(void)
36 /* initialize X11 video */
39 /* set default X11 depth */
40 video.default_depth = XDefaultDepth(display, screen);
43 inline void X11InitVideoBuffer(DrawBuffer *backbuffer, DrawWindow *window)
45 *window = X11InitWindow();
47 XMapWindow(display, *window);
50 /* create additional (off-screen) buffer for double-buffering */
51 *backbuffer = CreateBitmap(video.width, video.height, video.depth);
54 static void X11InitDisplay()
56 #if !defined(PLATFORM_MSDOS)
57 XVisualInfo vinfo_template, *vinfo;
62 /* connect to X server */
63 if (!(display = XOpenDisplay(options.display_name)))
64 Error(ERR_EXIT, "cannot connect to X server %s",
65 XDisplayName(options.display_name));
67 screen = DefaultScreen(display);
68 visual = DefaultVisual(display, screen);
69 depth = DefaultDepth(display, screen);
70 cmap = DefaultColormap(display, screen);
72 #if !defined(PLATFORM_MSDOS)
73 /* look for good enough visual */
74 vinfo_template.screen = screen;
75 vinfo_template.class = (depth == 8 ? PseudoColor : TrueColor);
76 vinfo_template.depth = depth;
77 if ((vinfo = XGetVisualInfo(display, VisualScreenMask | VisualClassMask |
78 VisualDepthMask, &vinfo_template, &num_visuals)))
80 visual = vinfo->visual;
84 /* got appropriate visual? */
87 printf("Sorry, displays with less than 8 bits per pixel not supported.\n");
90 else if ((depth ==8 && visual->class != PseudoColor) ||
91 (depth > 8 && visual->class != TrueColor &&
92 visual->class != DirectColor))
94 printf("Sorry, cannot get appropriate visual.\n");
97 #endif /* !PLATFORM_MSDOS */
100 static DrawWindow X11InitWindow()
103 unsigned int border_width = 4;
105 unsigned long gc_valuemask;
106 #if !defined(PLATFORM_MSDOS)
107 XTextProperty windowName, iconName;
108 Pixmap icon_pixmap, iconmask_pixmap;
109 unsigned int icon_width, icon_height;
110 int icon_hot_x, icon_hot_y;
111 char icon_filename[256];
112 XSizeHints size_hints;
114 XClassHint class_hints;
115 char *window_name = program.window_title;
116 char *icon_name = program.window_title;
117 long window_event_mask;
118 Atom proto_atom = None, delete_atom = None;
120 int screen_width, screen_height;
121 int win_xpos, win_ypos;
122 unsigned long pen_fg = WhitePixel(display,screen);
123 unsigned long pen_bg = BlackPixel(display,screen);
124 const int width = video.width, height = video.height;
127 #if !defined(PLATFORM_MSDOS)
128 static struct IconFileInfo icon_pic =
136 screen_width = XDisplayWidth(display, screen);
137 screen_height = XDisplayHeight(display, screen);
139 win_xpos = (screen_width - width) / 2;
140 win_ypos = (screen_height - height) / 2;
142 window = XCreateSimpleWindow(display, RootWindow(display, screen),
143 win_xpos, win_ypos, width, height, border_width,
146 #if !defined(PLATFORM_MSDOS)
147 proto_atom = XInternAtom(display, "WM_PROTOCOLS", FALSE);
148 delete_atom = XInternAtom(display, "WM_DELETE_WINDOW", FALSE);
149 if ((proto_atom != None) && (delete_atom != None))
150 XChangeProperty(display, window, proto_atom, XA_ATOM, 32,
151 PropModePrepend, (unsigned char *) &delete_atom, 1);
154 sprintf(icon_filename, "%s/%s/%s",
155 options.ro_base_directory, GRAPHICS_DIRECTORY,
156 icon_pic.picture_filename);
158 XReadBitmapFile(display, window, program.x11_icon_filename,
159 &icon_width, &icon_height,
160 &icon_pixmap, &icon_hot_x, &icon_hot_y);
162 Error(ERR_EXIT, "cannot read icon bitmap file '%s'", icon_filename);
165 sprintf(icon_filename, "%s/%s/%s",
166 options.ro_base_directory, GRAPHICS_DIRECTORY,
167 icon_pic.picturemask_filename);
169 XReadBitmapFile(display, window, program.x11_iconmask_filename,
170 &icon_width, &icon_height,
171 &iconmask_pixmap, &icon_hot_x, &icon_hot_y);
172 if (!iconmask_pixmap)
173 Error(ERR_EXIT, "cannot read icon bitmap file '%s'", icon_filename);
175 size_hints.width = size_hints.min_width = size_hints.max_width = width;
176 size_hints.height = size_hints.min_height = size_hints.max_height = height;
177 size_hints.flags = PSize | PMinSize | PMaxSize;
179 if (win_xpos || win_ypos)
181 size_hints.x = win_xpos;
182 size_hints.y = win_ypos;
183 size_hints.flags |= PPosition;
186 if (!XStringListToTextProperty(&window_name, 1, &windowName))
187 Error(ERR_EXIT, "structure allocation for windowName failed");
189 if (!XStringListToTextProperty(&icon_name, 1, &iconName))
190 Error(ERR_EXIT, "structure allocation for iconName failed");
192 wm_hints.initial_state = NormalState;
193 wm_hints.input = True;
194 wm_hints.icon_pixmap = icon_pixmap;
195 wm_hints.icon_mask = iconmask_pixmap;
196 wm_hints.flags = StateHint | IconPixmapHint | IconMaskHint | InputHint;
198 class_hints.res_name = program.command_name;
199 class_hints.res_class = program.program_title;
201 XSetWMProperties(display, window, &windowName, &iconName,
202 NULL, 0, &size_hints, &wm_hints,
205 XFree(windowName.value);
206 XFree(iconName.value);
208 /* Select event types wanted */
210 ExposureMask | StructureNotifyMask | FocusChangeMask |
211 ButtonPressMask | ButtonReleaseMask | PointerMotionMask |
212 PointerMotionHintMask | KeyPressMask | KeyReleaseMask;
214 XSelectInput(display, window, window_event_mask);
217 /* create GC for drawing with window depth and background color (black) */
218 gc_values.graphics_exposures = False;
219 gc_values.foreground = pen_bg;
220 gc_values.background = pen_bg;
221 gc_valuemask = GCGraphicsExposures | GCForeground | GCBackground;
222 gc = XCreateGC(display, window, gc_valuemask, &gc_values);
227 #endif /* TARGET_X11 */