1 /***********************************************************
2 * Artsoft Retro-Game Library *
3 *----------------------------------------------------------*
4 * (c) 1994-2000 Artsoft Entertainment *
6 * Detmolder Strasse 189 *
9 * e-mail: info@artsoft.org *
10 *----------------------------------------------------------*
12 ***********************************************************/
18 #if defined(TARGET_X11)
20 static void X11InitDisplay();
21 static DrawWindow *X11InitWindow();
23 inline void X11InitVideoDisplay(void)
25 /* initialize X11 video */
28 /* set default X11 depth */
29 video.default_depth = XDefaultDepth(display, screen);
32 inline void X11InitVideoBuffer(DrawBuffer **backbuffer, DrawWindow **window)
34 *window = X11InitWindow();
36 XMapWindow(display, (*window)->drawable);
39 /* create additional (off-screen) buffer for double-buffering */
40 *backbuffer = CreateBitmap(video.width, video.height, video.depth);
43 static void X11InitDisplay()
45 #if !defined(PLATFORM_MSDOS)
46 XVisualInfo vinfo_template, *vinfo;
51 /* connect to X server */
52 if (!(display = XOpenDisplay(options.display_name)))
53 Error(ERR_EXIT, "cannot connect to X server %s",
54 XDisplayName(options.display_name));
56 screen = DefaultScreen(display);
57 visual = DefaultVisual(display, screen);
58 depth = DefaultDepth(display, screen);
59 cmap = DefaultColormap(display, screen);
61 #if !defined(PLATFORM_MSDOS)
62 /* look for good enough visual */
63 vinfo_template.screen = screen;
64 vinfo_template.class = (depth == 8 ? PseudoColor : TrueColor);
65 vinfo_template.depth = depth;
66 if ((vinfo = XGetVisualInfo(display, VisualScreenMask | VisualClassMask |
67 VisualDepthMask, &vinfo_template, &num_visuals)))
69 visual = vinfo->visual;
73 /* got appropriate visual? */
76 printf("Sorry, displays with less than 8 bits per pixel not supported.\n");
79 else if ((depth ==8 && visual->class != PseudoColor) ||
80 (depth > 8 && visual->class != TrueColor &&
81 visual->class != DirectColor))
83 printf("Sorry, cannot get appropriate visual.\n");
86 #endif /* !PLATFORM_MSDOS */
89 static DrawWindow *X11InitWindow()
91 DrawWindow *new_window = CreateBitmapStruct();
92 unsigned int border_width = 4;
94 unsigned long gc_valuemask;
95 #if !defined(PLATFORM_MSDOS)
96 XTextProperty windowName, iconName;
97 Pixmap icon_pixmap, iconmask_pixmap;
98 unsigned int icon_width, icon_height;
99 int icon_hot_x, icon_hot_y;
100 char icon_filename[256];
101 XSizeHints size_hints;
103 XClassHint class_hints;
104 char *window_name = program.window_title;
105 char *icon_name = program.window_title;
106 long window_event_mask;
107 Atom proto_atom = None, delete_atom = None;
109 int screen_width, screen_height;
110 int win_xpos, win_ypos;
111 unsigned long pen_fg = WhitePixel(display,screen);
112 unsigned long pen_bg = BlackPixel(display,screen);
113 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);
217 /* create GCs for line drawing (black and white) */
220 gc_values.graphics_exposures = False;
221 gc_values.foreground = (i ? pen_fg : pen_bg);
222 gc_values.background = pen_bg;
223 gc_values.line_width = 4;
224 gc_values.line_style = LineSolid;
225 gc_values.cap_style = CapRound;
226 gc_values.join_style = JoinRound;
228 gc_valuemask = GCGraphicsExposures | GCForeground | GCBackground |
229 GCLineWidth | GCLineStyle | GCCapStyle | GCJoinStyle;
230 new_window->line_gc[i] =
231 XCreateGC(display, new_window->drawable, gc_valuemask, &gc_values);
237 #endif /* TARGET_X11 */