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)
23 char *picture_filename;
24 char *picturemask_filename;
27 static void X11InitDisplay()
29 #if !defined(PLATFORM_MSDOS)
30 XVisualInfo vinfo_template, *vinfo;
35 /* connect to X server */
36 if (!(display = XOpenDisplay(options.display_name)))
37 Error(ERR_EXIT, "cannot connect to X server %s",
38 XDisplayName(options.display_name));
40 screen = DefaultScreen(display);
41 visual = DefaultVisual(display, screen);
42 depth = DefaultDepth(display, screen);
43 cmap = DefaultColormap(display, screen);
45 #if !defined(PLATFORM_MSDOS)
46 /* look for good enough visual */
47 vinfo_template.screen = screen;
48 vinfo_template.class = (depth == 8 ? PseudoColor : TrueColor);
49 vinfo_template.depth = depth;
50 if ((vinfo = XGetVisualInfo(display, VisualScreenMask | VisualClassMask |
51 VisualDepthMask, &vinfo_template, &num_visuals)))
53 visual = vinfo->visual;
57 /* got appropriate visual? */
60 printf("Sorry, displays with less than 8 bits per pixel not supported.\n");
63 else if ((depth ==8 && visual->class != PseudoColor) ||
64 (depth > 8 && visual->class != TrueColor &&
65 visual->class != DirectColor))
67 printf("Sorry, cannot get appropriate visual.\n");
70 #endif /* !PLATFORM_MSDOS */
73 static DrawWindow X11InitWindow()
76 unsigned int border_width = 4;
78 unsigned long gc_valuemask;
79 #if !defined(PLATFORM_MSDOS)
80 XTextProperty windowName, iconName;
81 Pixmap icon_pixmap, iconmask_pixmap;
82 unsigned int icon_width, icon_height;
83 int icon_hot_x, icon_hot_y;
84 char icon_filename[256];
85 XSizeHints size_hints;
87 XClassHint class_hints;
88 char *window_name = WINDOW_TITLE_STRING;
89 char *icon_name = WINDOW_TITLE_STRING;
90 long window_event_mask;
91 Atom proto_atom = None, delete_atom = None;
93 int screen_width, screen_height;
94 int win_xpos = WIN_XPOS, win_ypos = WIN_YPOS;
95 unsigned long pen_fg = WhitePixel(display,screen);
96 unsigned long pen_bg = BlackPixel(display,screen);
97 const int width = WIN_XSIZE, height = WIN_YSIZE;
99 #if !defined(PLATFORM_MSDOS)
100 static struct IconFileInfo icon_pic =
107 screen_width = XDisplayWidth(display, screen);
108 screen_height = XDisplayHeight(display, screen);
110 win_xpos = (screen_width - width) / 2;
111 win_ypos = (screen_height - height) / 2;
113 window = XCreateSimpleWindow(display, RootWindow(display, screen),
114 win_xpos, win_ypos, width, height, border_width,
117 #if !defined(PLATFORM_MSDOS)
118 proto_atom = XInternAtom(display, "WM_PROTOCOLS", FALSE);
119 delete_atom = XInternAtom(display, "WM_DELETE_WINDOW", FALSE);
120 if ((proto_atom != None) && (delete_atom != None))
121 XChangeProperty(display, window, proto_atom, XA_ATOM, 32,
122 PropModePrepend, (unsigned char *) &delete_atom, 1);
124 sprintf(icon_filename, "%s/%s/%s",
125 options.ro_base_directory, GRAPHICS_DIRECTORY,
126 icon_pic.picture_filename);
127 XReadBitmapFile(display,window,icon_filename,
128 &icon_width,&icon_height,
129 &icon_pixmap,&icon_hot_x,&icon_hot_y);
131 Error(ERR_EXIT, "cannot read icon bitmap file '%s'", icon_filename);
133 sprintf(icon_filename, "%s/%s/%s",
134 options.ro_base_directory, GRAPHICS_DIRECTORY,
135 icon_pic.picturemask_filename);
136 XReadBitmapFile(display,window,icon_filename,
137 &icon_width,&icon_height,
138 &iconmask_pixmap,&icon_hot_x,&icon_hot_y);
139 if (!iconmask_pixmap)
140 Error(ERR_EXIT, "cannot read icon bitmap file '%s'", icon_filename);
142 size_hints.width = size_hints.min_width = size_hints.max_width = width;
143 size_hints.height = size_hints.min_height = size_hints.max_height = height;
144 size_hints.flags = PSize | PMinSize | PMaxSize;
146 if (win_xpos || win_ypos)
148 size_hints.x = win_xpos;
149 size_hints.y = win_ypos;
150 size_hints.flags |= PPosition;
153 if (!XStringListToTextProperty(&window_name, 1, &windowName))
154 Error(ERR_EXIT, "structure allocation for windowName failed");
156 if (!XStringListToTextProperty(&icon_name, 1, &iconName))
157 Error(ERR_EXIT, "structure allocation for iconName failed");
159 wm_hints.initial_state = NormalState;
160 wm_hints.input = True;
161 wm_hints.icon_pixmap = icon_pixmap;
162 wm_hints.icon_mask = iconmask_pixmap;
163 wm_hints.flags = StateHint | IconPixmapHint | IconMaskHint | InputHint;
165 class_hints.res_name = program_name;
166 class_hints.res_class = "Rocks'n'Diamonds";
168 XSetWMProperties(display, window, &windowName, &iconName,
169 NULL, 0, &size_hints, &wm_hints,
172 XFree(windowName.value);
173 XFree(iconName.value);
175 /* Select event types wanted */
177 ExposureMask | StructureNotifyMask | FocusChangeMask |
178 ButtonPressMask | ButtonReleaseMask | PointerMotionMask |
179 PointerMotionHintMask | KeyPressMask | KeyReleaseMask;
181 XSelectInput(display, window, window_event_mask);
184 /* create GC for drawing with window depth and background color (black) */
185 gc_values.graphics_exposures = False;
186 gc_values.foreground = pen_bg;
187 gc_values.background = pen_bg;
188 gc_valuemask = GCGraphicsExposures | GCForeground | GCBackground;
189 gc = XCreateGC(display, window, gc_valuemask, &gc_values);
194 inline void X11InitBufferedDisplay(DrawBuffer *backbuffer, DrawWindow *window)
197 *window = X11InitWindow();
199 XMapWindow(display, *window);
202 /* create additional buffer for double-buffering */
203 *backbuffer = CreateBitmap(WIN_XSIZE, WIN_YSIZE, DEFAULT_DEPTH);
204 pix[PIX_DB_BACK] = *backbuffer; /* 'backbuffer' is off-screen buffer */
207 #endif /* TARGET_X11 */