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 ***********************************************************/
19 #if defined(TARGET_X11)
21 static void X11InitDisplay();
22 static DrawWindow X11InitWindow();
24 inline void X11InitVideoDisplay(void)
26 /* initialize X11 video */
29 /* set default X11 depth */
30 video.default_depth = XDefaultDepth(display, screen);
33 inline void X11InitVideoBuffer(DrawBuffer *backbuffer, DrawWindow *window)
35 *window = X11InitWindow();
37 XMapWindow(display, (*window)->drawable);
40 /* create additional (off-screen) buffer for double-buffering */
41 *backbuffer = CreateBitmap(video.width, video.height, video.depth);
44 static void X11InitDisplay()
46 #if !defined(PLATFORM_MSDOS)
47 XVisualInfo vinfo_template, *vinfo;
52 /* connect to X server */
53 if (!(display = XOpenDisplay(options.display_name)))
54 Error(ERR_EXIT, "cannot connect to X server %s",
55 XDisplayName(options.display_name));
57 screen = DefaultScreen(display);
58 visual = DefaultVisual(display, screen);
59 depth = DefaultDepth(display, screen);
60 cmap = DefaultColormap(display, screen);
62 #if !defined(PLATFORM_MSDOS)
63 /* look for good enough visual */
64 vinfo_template.screen = screen;
65 vinfo_template.class = (depth == 8 ? PseudoColor : TrueColor);
66 vinfo_template.depth = depth;
67 if ((vinfo = XGetVisualInfo(display, VisualScreenMask | VisualClassMask |
68 VisualDepthMask, &vinfo_template, &num_visuals)))
70 visual = vinfo->visual;
74 /* got appropriate visual? */
77 printf("Sorry, displays with less than 8 bits per pixel not supported.\n");
80 else if ((depth ==8 && visual->class != PseudoColor) ||
81 (depth > 8 && visual->class != TrueColor &&
82 visual->class != DirectColor))
84 printf("Sorry, cannot get appropriate visual.\n");
87 #endif /* !PLATFORM_MSDOS */
90 static DrawWindow X11InitWindow()
92 DrawWindow new_window = CreateBitmapStruct();
93 unsigned int border_width = 4;
95 unsigned long gc_valuemask;
96 #if !defined(PLATFORM_MSDOS)
97 XTextProperty windowName, iconName;
98 Pixmap icon_pixmap, iconmask_pixmap;
99 unsigned int icon_width, icon_height;
100 int icon_hot_x, icon_hot_y;
101 char icon_filename[256];
102 XSizeHints size_hints;
104 XClassHint class_hints;
105 char *window_name = program.window_title;
106 char *icon_name = program.window_title;
107 long window_event_mask;
108 Atom proto_atom = None, delete_atom = None;
110 int screen_width, screen_height;
111 int win_xpos, win_ypos;
112 unsigned long pen_fg = WhitePixel(display,screen);
113 unsigned long pen_bg = BlackPixel(display,screen);
114 const int width = video.width, height = video.height;
117 #if !defined(PLATFORM_MSDOS)
118 static struct IconFileInfo icon_pic =
126 screen_width = XDisplayWidth(display, screen);
127 screen_height = XDisplayHeight(display, screen);
129 win_xpos = (screen_width - width) / 2;
130 win_ypos = (screen_height - height) / 2;
132 new_window->drawable = XCreateSimpleWindow(display,
133 RootWindow(display, screen),
135 width, height, border_width,
138 #if !defined(PLATFORM_MSDOS)
139 proto_atom = XInternAtom(display, "WM_PROTOCOLS", FALSE);
140 delete_atom = XInternAtom(display, "WM_DELETE_WINDOW", FALSE);
141 if ((proto_atom != None) && (delete_atom != None))
142 XChangeProperty(display, new_window->drawable, proto_atom, XA_ATOM, 32,
143 PropModePrepend, (unsigned char *) &delete_atom, 1);
146 sprintf(icon_filename, "%s/%s/%s",
147 options.ro_base_directory, GRAPHICS_DIRECTORY,
148 icon_pic.picture_filename);
150 XReadBitmapFile(display, new_window->drawable, program.x11_icon_filename,
151 &icon_width, &icon_height,
152 &icon_pixmap, &icon_hot_x, &icon_hot_y);
154 Error(ERR_EXIT, "cannot read icon bitmap file '%s'", icon_filename);
157 sprintf(icon_filename, "%s/%s/%s",
158 options.ro_base_directory, GRAPHICS_DIRECTORY,
159 icon_pic.picturemask_filename);
161 XReadBitmapFile(display, new_window->drawable, program.x11_iconmask_filename,
162 &icon_width, &icon_height,
163 &iconmask_pixmap, &icon_hot_x, &icon_hot_y);
164 if (!iconmask_pixmap)
165 Error(ERR_EXIT, "cannot read icon bitmap file '%s'", icon_filename);
167 size_hints.width = size_hints.min_width = size_hints.max_width = width;
168 size_hints.height = size_hints.min_height = size_hints.max_height = height;
169 size_hints.flags = PSize | PMinSize | PMaxSize;
171 if (win_xpos || win_ypos)
173 size_hints.x = win_xpos;
174 size_hints.y = win_ypos;
175 size_hints.flags |= PPosition;
178 if (!XStringListToTextProperty(&window_name, 1, &windowName))
179 Error(ERR_EXIT, "structure allocation for windowName failed");
181 if (!XStringListToTextProperty(&icon_name, 1, &iconName))
182 Error(ERR_EXIT, "structure allocation for iconName failed");
184 wm_hints.initial_state = NormalState;
185 wm_hints.input = True;
186 wm_hints.icon_pixmap = icon_pixmap;
187 wm_hints.icon_mask = iconmask_pixmap;
188 wm_hints.flags = StateHint | IconPixmapHint | IconMaskHint | InputHint;
190 class_hints.res_name = program.command_basename;
191 class_hints.res_class = program.program_title;
193 XSetWMProperties(display, new_window->drawable, &windowName, &iconName,
194 NULL, 0, &size_hints, &wm_hints,
197 XFree(windowName.value);
198 XFree(iconName.value);
200 /* Select event types wanted */
202 ExposureMask | StructureNotifyMask | FocusChangeMask |
203 ButtonPressMask | ButtonReleaseMask | PointerMotionMask |
204 PointerMotionHintMask | KeyPressMask | KeyReleaseMask;
206 XSelectInput(display, new_window->drawable, window_event_mask);
209 /* create GC for drawing with window depth and background color (black) */
210 gc_values.graphics_exposures = False;
211 gc_values.foreground = pen_bg;
212 gc_values.background = pen_bg;
213 gc_valuemask = GCGraphicsExposures | GCForeground | GCBackground;
215 XCreateGC(display, new_window->drawable, gc_valuemask, &gc_values);
220 #endif /* TARGET_X11 */