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 #if defined(TARGET_X11)
22 char *picture_filename;
23 char *picturemask_filename;
26 static void X11InitDisplay()
28 #if !defined(PLATFORM_MSDOS)
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);
44 #if !defined(PLATFORM_MSDOS)
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");
69 #endif /* !PLATFORM_MSDOS */
72 static DrawWindow X11InitWindow()
75 unsigned int border_width = 4;
77 unsigned long gc_valuemask;
78 #if !defined(PLATFORM_MSDOS)
79 XTextProperty windowName, iconName;
80 Pixmap icon_pixmap, iconmask_pixmap;
81 unsigned int icon_width, icon_height;
82 int icon_hot_x, icon_hot_y;
83 char icon_filename[256];
84 XSizeHints size_hints;
86 XClassHint class_hints;
87 char *window_name = WINDOW_TITLE_STRING;
88 char *icon_name = WINDOW_TITLE_STRING;
89 long window_event_mask;
90 Atom proto_atom = None, delete_atom = None;
92 int screen_width, screen_height;
93 int win_xpos = WIN_XPOS, win_ypos = WIN_YPOS;
94 unsigned long pen_fg = WhitePixel(display,screen);
95 unsigned long pen_bg = BlackPixel(display,screen);
96 const int width = WIN_XSIZE, height = WIN_YSIZE;
98 #if !defined(PLATFORM_MSDOS)
99 static struct IconFileInfo icon_pic =
106 screen_width = XDisplayWidth(display, screen);
107 screen_height = XDisplayHeight(display, screen);
109 win_xpos = (screen_width - width) / 2;
110 win_ypos = (screen_height - height) / 2;
112 window = XCreateSimpleWindow(display, RootWindow(display, screen),
113 win_xpos, win_ypos, width, height, border_width,
116 #if !defined(PLATFORM_MSDOS)
117 proto_atom = XInternAtom(display, "WM_PROTOCOLS", FALSE);
118 delete_atom = XInternAtom(display, "WM_DELETE_WINDOW", FALSE);
119 if ((proto_atom != None) && (delete_atom != None))
120 XChangeProperty(display, window, proto_atom, XA_ATOM, 32,
121 PropModePrepend, (unsigned char *) &delete_atom, 1);
123 sprintf(icon_filename, "%s/%s/%s",
124 options.ro_base_directory, GRAPHICS_DIRECTORY,
125 icon_pic.picture_filename);
126 XReadBitmapFile(display,window,icon_filename,
127 &icon_width,&icon_height,
128 &icon_pixmap,&icon_hot_x,&icon_hot_y);
130 Error(ERR_EXIT, "cannot read icon bitmap file '%s'", icon_filename);
132 sprintf(icon_filename, "%s/%s/%s",
133 options.ro_base_directory, GRAPHICS_DIRECTORY,
134 icon_pic.picturemask_filename);
135 XReadBitmapFile(display,window,icon_filename,
136 &icon_width,&icon_height,
137 &iconmask_pixmap,&icon_hot_x,&icon_hot_y);
138 if (!iconmask_pixmap)
139 Error(ERR_EXIT, "cannot read icon bitmap file '%s'", icon_filename);
141 size_hints.width = size_hints.min_width = size_hints.max_width = width;
142 size_hints.height = size_hints.min_height = size_hints.max_height = height;
143 size_hints.flags = PSize | PMinSize | PMaxSize;
145 if (win_xpos || win_ypos)
147 size_hints.x = win_xpos;
148 size_hints.y = win_ypos;
149 size_hints.flags |= PPosition;
152 if (!XStringListToTextProperty(&window_name, 1, &windowName))
153 Error(ERR_EXIT, "structure allocation for windowName failed");
155 if (!XStringListToTextProperty(&icon_name, 1, &iconName))
156 Error(ERR_EXIT, "structure allocation for iconName failed");
158 wm_hints.initial_state = NormalState;
159 wm_hints.input = True;
160 wm_hints.icon_pixmap = icon_pixmap;
161 wm_hints.icon_mask = iconmask_pixmap;
162 wm_hints.flags = StateHint | IconPixmapHint | IconMaskHint | InputHint;
164 class_hints.res_name = program_name;
165 class_hints.res_class = "Rocks'n'Diamonds";
167 XSetWMProperties(display, window, &windowName, &iconName,
168 NULL, 0, &size_hints, &wm_hints,
171 XFree(windowName.value);
172 XFree(iconName.value);
174 /* Select event types wanted */
176 ExposureMask | StructureNotifyMask | FocusChangeMask |
177 ButtonPressMask | ButtonReleaseMask | PointerMotionMask |
178 PointerMotionHintMask | KeyPressMask | KeyReleaseMask;
180 XSelectInput(display, window, window_event_mask);
183 /* create GC for drawing with window depth and background color (black) */
184 gc_values.graphics_exposures = False;
185 gc_values.foreground = pen_bg;
186 gc_values.background = pen_bg;
187 gc_valuemask = GCGraphicsExposures | GCForeground | GCBackground;
188 gc = XCreateGC(display, window, gc_valuemask, &gc_values);
193 inline void X11InitBufferedDisplay(DrawBuffer *backbuffer, DrawWindow *window)
196 *window = X11InitWindow();
198 XMapWindow(display, *window);
201 /* create additional buffer for double-buffering */
202 *backbuffer = CreateBitmap(WIN_XSIZE, WIN_YSIZE, DEFAULT_DEPTH);
203 pix[PIX_DB_BACK] = *backbuffer; /* 'backbuffer' is off-screen buffer */
206 #endif /* TARGET_X11 */