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;
116 #if !defined(PLATFORM_MSDOS)
117 static struct IconFileInfo icon_pic =
125 screen_width = XDisplayWidth(display, screen);
126 screen_height = XDisplayHeight(display, screen);
128 win_xpos = (screen_width - width) / 2;
129 win_ypos = (screen_height - height) / 2;
131 new_window->drawable = XCreateSimpleWindow(display,
132 RootWindow(display, screen),
134 width, height, border_width,
137 #if !defined(PLATFORM_MSDOS)
138 proto_atom = XInternAtom(display, "WM_PROTOCOLS", FALSE);
139 delete_atom = XInternAtom(display, "WM_DELETE_WINDOW", FALSE);
140 if ((proto_atom != None) && (delete_atom != None))
141 XChangeProperty(display, new_window->drawable, proto_atom, XA_ATOM, 32,
142 PropModePrepend, (unsigned char *) &delete_atom, 1);
145 sprintf(icon_filename, "%s/%s/%s",
146 options.ro_base_directory, GRAPHICS_DIRECTORY,
147 icon_pic.picture_filename);
149 XReadBitmapFile(display, new_window->drawable, program.x11_icon_filename,
150 &icon_width, &icon_height,
151 &icon_pixmap, &icon_hot_x, &icon_hot_y);
153 Error(ERR_EXIT, "cannot read icon bitmap file '%s'", icon_filename);
156 sprintf(icon_filename, "%s/%s/%s",
157 options.ro_base_directory, GRAPHICS_DIRECTORY,
158 icon_pic.picturemask_filename);
160 XReadBitmapFile(display, new_window->drawable, program.x11_iconmask_filename,
161 &icon_width, &icon_height,
162 &iconmask_pixmap, &icon_hot_x, &icon_hot_y);
163 if (!iconmask_pixmap)
164 Error(ERR_EXIT, "cannot read icon bitmap file '%s'", icon_filename);
166 size_hints.width = size_hints.min_width = size_hints.max_width = width;
167 size_hints.height = size_hints.min_height = size_hints.max_height = height;
168 size_hints.flags = PSize | PMinSize | PMaxSize;
170 if (win_xpos || win_ypos)
172 size_hints.x = win_xpos;
173 size_hints.y = win_ypos;
174 size_hints.flags |= PPosition;
177 if (!XStringListToTextProperty(&window_name, 1, &windowName))
178 Error(ERR_EXIT, "structure allocation for windowName failed");
180 if (!XStringListToTextProperty(&icon_name, 1, &iconName))
181 Error(ERR_EXIT, "structure allocation for iconName failed");
183 wm_hints.initial_state = NormalState;
184 wm_hints.input = True;
185 wm_hints.icon_pixmap = icon_pixmap;
186 wm_hints.icon_mask = iconmask_pixmap;
187 wm_hints.flags = StateHint | IconPixmapHint | IconMaskHint | InputHint;
189 class_hints.res_name = program.command_basename;
190 class_hints.res_class = program.program_title;
192 XSetWMProperties(display, new_window->drawable, &windowName, &iconName,
193 NULL, 0, &size_hints, &wm_hints,
196 XFree(windowName.value);
197 XFree(iconName.value);
199 /* Select event types wanted */
201 ExposureMask | StructureNotifyMask | FocusChangeMask |
202 ButtonPressMask | ButtonReleaseMask | PointerMotionMask |
203 PointerMotionHintMask | KeyPressMask | KeyReleaseMask;
205 XSelectInput(display, new_window->drawable, window_event_mask);
208 /* create GC for drawing with window depth and background color (black) */
209 gc_values.graphics_exposures = False;
210 gc_values.foreground = pen_bg;
211 gc_values.background = pen_bg;
212 gc_valuemask = GCGraphicsExposures | GCForeground | GCBackground;
214 XCreateGC(display, new_window->drawable, gc_valuemask, &gc_values);
219 #endif /* TARGET_X11 */