2
|
1 |
/*
|
|
2 |
* Copyright 2005-2007 Sun Microsystems, Inc. All Rights Reserved.
|
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation. Sun designates this
|
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
|
9 |
* by Sun in the LICENSE file that accompanied this code.
|
|
10 |
*
|
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
15 |
* accompanied this code).
|
|
16 |
*
|
|
17 |
* You should have received a copy of the GNU General Public License version
|
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
20 |
*
|
|
21 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or
|
|
23 |
* have any questions.
|
|
24 |
*/
|
|
25 |
|
|
26 |
#include "splashscreen_impl.h"
|
|
27 |
#include <X11/Xlib.h>
|
|
28 |
#include <X11/Xutil.h>
|
|
29 |
#include <X11/extensions/shape.h>
|
|
30 |
#include <X11/Xmd.h>
|
|
31 |
#include <X11/Xatom.h>
|
|
32 |
#include <X11/cursorfont.h>
|
|
33 |
#include <sys/types.h>
|
|
34 |
#include <pthread.h>
|
|
35 |
#include <signal.h>
|
|
36 |
#include <unistd.h>
|
|
37 |
#include <sys/time.h>
|
|
38 |
#include <errno.h>
|
|
39 |
#include <iconv.h>
|
|
40 |
#include <langinfo.h>
|
|
41 |
#include <locale.h>
|
|
42 |
#include <fcntl.h>
|
|
43 |
|
|
44 |
static Bool shapeSupported;
|
|
45 |
static int shapeEventBase, shapeErrorBase;
|
|
46 |
|
|
47 |
void SplashRemoveDecoration(Splash * splash);
|
|
48 |
|
|
49 |
|
|
50 |
/* Could use npt but decided to cut down on linked code size */
|
|
51 |
char* SplashConvertStringAlloc(const char* in, int* size) {
|
|
52 |
const char *codeset;
|
|
53 |
const char *codeset_out;
|
|
54 |
iconv_t cd;
|
|
55 |
size_t rc;
|
|
56 |
char *buf = NULL, *out;
|
|
57 |
size_t bufSize, inSize, outSize;
|
|
58 |
const char* old_locale;
|
|
59 |
|
|
60 |
if (!in) {
|
|
61 |
return NULL;
|
|
62 |
}
|
|
63 |
old_locale = setlocale(LC_ALL, "");
|
|
64 |
|
|
65 |
codeset = nl_langinfo(CODESET);
|
|
66 |
if ( codeset == NULL || codeset[0] == 0 ) {
|
|
67 |
goto done;
|
|
68 |
}
|
|
69 |
/* we don't need BOM in output so we choose native BE or LE encoding here */
|
|
70 |
codeset_out = (platformByteOrder()==BYTE_ORDER_MSBFIRST) ?
|
|
71 |
"UCS-2BE" : "UCS-2LE";
|
|
72 |
|
|
73 |
cd = iconv_open(codeset_out, codeset);
|
|
74 |
if (cd == (iconv_t)-1 ) {
|
|
75 |
goto done;
|
|
76 |
}
|
|
77 |
inSize = strlen(in);
|
|
78 |
bufSize = inSize*2; // need 2 bytes per char for UCS-2, this is
|
|
79 |
// 2 bytes per source byte max
|
|
80 |
buf = malloc(bufSize);
|
|
81 |
out = buf; outSize = bufSize;
|
|
82 |
/* linux iconv wants char** source and solaris wants const char**...
|
|
83 |
cast to void* */
|
|
84 |
rc = iconv(cd, (void*)&in, &inSize, &out, &outSize);
|
|
85 |
iconv_close(cd);
|
|
86 |
|
|
87 |
if (rc == (size_t)-1) {
|
|
88 |
free(buf);
|
|
89 |
buf = NULL;
|
|
90 |
} else {
|
|
91 |
if (size) {
|
|
92 |
*size = (bufSize-outSize)/2; /* bytes to wchars */
|
|
93 |
}
|
|
94 |
}
|
|
95 |
done:
|
|
96 |
setlocale(LC_ALL, old_locale);
|
|
97 |
return buf;
|
|
98 |
}
|
|
99 |
|
|
100 |
void
|
|
101 |
SplashInitFrameShape(Splash * splash, int imageIndex) {
|
|
102 |
ImageRect maskRect;
|
|
103 |
XRectangle *rects;
|
|
104 |
SplashImage *frame = splash->frames + imageIndex;
|
|
105 |
|
|
106 |
frame->rects = NULL;
|
|
107 |
frame->numRects = 0;
|
|
108 |
|
|
109 |
if (!splash->maskRequired)
|
|
110 |
return;
|
|
111 |
if (!shapeSupported)
|
|
112 |
return;
|
|
113 |
initRect(&maskRect, 0, 0, splash->width, splash->height, 1,
|
|
114 |
splash->width * splash->imageFormat.depthBytes,
|
|
115 |
splash->frames[imageIndex].bitmapBits, &splash->imageFormat);
|
|
116 |
rects =
|
|
117 |
malloc(sizeof(XRectangle) * (splash->width / 2 + 1) * splash->height);
|
|
118 |
|
|
119 |
frame->numRects = BitmapToYXBandedRectangles(&maskRect, rects);
|
|
120 |
frame->rects = malloc(frame->numRects * sizeof(XRectangle));
|
|
121 |
memcpy(frame->rects, rects, frame->numRects * sizeof(XRectangle));
|
|
122 |
free(rects);
|
|
123 |
}
|
|
124 |
|
|
125 |
unsigned
|
|
126 |
SplashTime(void) {
|
|
127 |
struct timeval tv;
|
|
128 |
struct timezone tz;
|
|
129 |
unsigned long long msec;
|
|
130 |
|
|
131 |
gettimeofday(&tv, &tz);
|
|
132 |
msec = (unsigned long long) tv.tv_sec * 1000 +
|
|
133 |
(unsigned long long) tv.tv_usec / 1000;
|
|
134 |
|
|
135 |
return (unsigned) msec;
|
|
136 |
}
|
|
137 |
|
|
138 |
void
|
|
139 |
msec2timeval(unsigned time, struct timeval *tv) {
|
|
140 |
tv->tv_sec = time / 1000;
|
|
141 |
tv->tv_usec = (time % 1000) * 1000;
|
|
142 |
}
|
|
143 |
|
|
144 |
int
|
|
145 |
GetNumAvailableColors(Display * display, Screen * screen, unsigned map_entries) {
|
|
146 |
unsigned long pmr[1];
|
|
147 |
unsigned long pr[SPLASH_COLOR_MAP_SIZE];
|
|
148 |
unsigned nFailed, nAllocated, done = 0, nPlanes = 0;
|
|
149 |
Colormap cmap;
|
|
150 |
unsigned numColors = SPLASH_COLOR_MAP_SIZE; // never try allocating more than that
|
|
151 |
|
|
152 |
if (numColors > map_entries) {
|
|
153 |
numColors = map_entries;
|
|
154 |
}
|
|
155 |
cmap = XDefaultColormapOfScreen(screen);
|
|
156 |
nAllocated = 0; /* lower bound */
|
|
157 |
nFailed = numColors + 1; /* upper bound */
|
|
158 |
|
|
159 |
/* Binary search to determine the number of available cells */
|
|
160 |
for (done = 0; !done;) {
|
|
161 |
if (XAllocColorCells(display, cmap, 0, pmr, nPlanes, pr, numColors)) {
|
|
162 |
nAllocated = numColors;
|
|
163 |
XFreeColors(display, cmap, pr, numColors, 0);
|
|
164 |
if (nAllocated < (nFailed - 1)) {
|
|
165 |
numColors = (nAllocated + nFailed) / 2;
|
|
166 |
} else
|
|
167 |
done = 1;
|
|
168 |
} else {
|
|
169 |
nFailed = numColors;
|
|
170 |
if (nFailed > (nAllocated + 1))
|
|
171 |
numColors = (nAllocated + nFailed) / 2;
|
|
172 |
else
|
|
173 |
done = 1;
|
|
174 |
}
|
|
175 |
}
|
|
176 |
return nAllocated;
|
|
177 |
}
|
|
178 |
|
|
179 |
Colormap
|
|
180 |
AllocColors(Display * display, Screen * screen, int numColors,
|
|
181 |
unsigned long *pr) {
|
|
182 |
unsigned long pmr[1];
|
|
183 |
Colormap cmap = XDefaultColormapOfScreen(screen);
|
|
184 |
|
|
185 |
XAllocColorCells(display, cmap, 0, pmr, 0, pr, numColors);
|
|
186 |
return cmap;
|
|
187 |
}
|
|
188 |
|
|
189 |
void
|
|
190 |
FreeColors(Display * display, Screen * screen, int numColors,
|
|
191 |
unsigned long *pr) {
|
|
192 |
Colormap cmap = XDefaultColormapOfScreen(screen);
|
|
193 |
|
|
194 |
XFreeColors(display, cmap, pr, numColors, 0);
|
|
195 |
}
|
|
196 |
|
|
197 |
static void SplashCenter(Splash * splash) {
|
|
198 |
Atom type, atom, actual_type;
|
|
199 |
int status, actual_format;
|
|
200 |
unsigned long nitems, bytes_after;
|
|
201 |
CARD16 *prop = NULL;
|
|
202 |
|
|
203 |
/* try centering using Xinerama hint
|
|
204 |
if there's no hint, use the center of the screen */
|
|
205 |
atom = XInternAtom(splash->display, "XINERAMA_CENTER_HINT", True);
|
|
206 |
if (atom != None) {
|
|
207 |
status = XGetWindowProperty(splash->display,
|
|
208 |
XRootWindowOfScreen(splash->screen), atom, 0, 1, False, XA_INTEGER,
|
|
209 |
&actual_type, &actual_format, &nitems,
|
|
210 |
&bytes_after, (unsigned char**)(&prop));
|
|
211 |
if (status == Success && actual_type != None && prop != NULL) {
|
|
212 |
splash->x = prop[0] - splash->width/2;
|
|
213 |
splash->y = prop[1] - splash->height/2;
|
|
214 |
XFree(prop);
|
|
215 |
return;
|
|
216 |
}
|
|
217 |
if (prop != NULL) {
|
|
218 |
XFree(prop);
|
|
219 |
}
|
|
220 |
}
|
|
221 |
splash->x = (XWidthOfScreen(splash->screen) - splash->width) / 2;
|
|
222 |
splash->y = (XHeightOfScreen(splash->screen) - splash->height) / 2;
|
|
223 |
}
|
|
224 |
|
|
225 |
static void SplashUpdateSizeHints(Splash * splash) {
|
|
226 |
if (splash->window) {
|
|
227 |
XSizeHints sizeHints;
|
|
228 |
|
|
229 |
sizeHints.flags = USPosition | PPosition | USSize | PSize | PMinSize | PMaxSize | PWinGravity;
|
|
230 |
sizeHints.width = sizeHints.base_width = sizeHints.min_width = sizeHints.max_width = splash->width;
|
|
231 |
sizeHints.height = sizeHints.base_height = sizeHints.min_height = sizeHints.max_height = splash->height;
|
|
232 |
sizeHints.win_gravity = NorthWestGravity;
|
|
233 |
|
|
234 |
XSetWMNormalHints(splash->display, splash->window, &sizeHints);
|
|
235 |
}
|
|
236 |
}
|
|
237 |
|
|
238 |
void
|
|
239 |
SplashCreateWindow(Splash * splash) {
|
|
240 |
XSizeHints sizeHints;
|
|
241 |
|
|
242 |
XSetWindowAttributes attr;
|
|
243 |
|
|
244 |
attr.backing_store = NotUseful;
|
|
245 |
attr.colormap = XDefaultColormapOfScreen(splash->screen);
|
|
246 |
attr.save_under = True;
|
|
247 |
attr.cursor = splash->cursor = XCreateFontCursor(splash->display, XC_watch);
|
|
248 |
attr.event_mask = ExposureMask;
|
|
249 |
|
|
250 |
SplashCenter(splash);
|
|
251 |
|
|
252 |
splash->window = XCreateWindow(splash->display, XRootWindowOfScreen(splash->screen),
|
|
253 |
splash->x, splash->y, splash->width, splash->height, 0, CopyFromParent,
|
|
254 |
InputOutput, CopyFromParent, CWColormap | CWBackingStore | CWSaveUnder | CWCursor | CWEventMask,
|
|
255 |
&attr);
|
|
256 |
SplashUpdateSizeHints(splash);
|
|
257 |
|
|
258 |
|
|
259 |
splash->wmHints = XAllocWMHints();
|
|
260 |
if (splash->wmHints) {
|
|
261 |
splash->wmHints->flags = InputHint | StateHint;
|
|
262 |
splash->wmHints->input = False;
|
|
263 |
splash->wmHints->initial_state = NormalState;
|
|
264 |
XSetWMHints(splash->display, splash->window, splash->wmHints);
|
|
265 |
}
|
|
266 |
}
|
|
267 |
|
|
268 |
/* for changing the visible shape of a window to an nonrectangular form */
|
|
269 |
void
|
|
270 |
SplashUpdateShape(Splash * splash) {
|
|
271 |
if (!shapeSupported)
|
|
272 |
return;
|
|
273 |
if (!splash->maskRequired) {
|
|
274 |
return;
|
|
275 |
}
|
|
276 |
XShapeCombineRectangles(splash->display, splash->window, ShapeClip, 0, 0,
|
|
277 |
splash->frames[splash->currentFrame].rects,
|
|
278 |
splash->frames[splash->currentFrame].numRects, ShapeSet, YXBanded);
|
|
279 |
XShapeCombineRectangles(splash->display, splash->window, ShapeBounding,
|
|
280 |
0, 0, splash->frames[splash->currentFrame].rects,
|
|
281 |
splash->frames[splash->currentFrame].numRects, ShapeSet, YXBanded);
|
|
282 |
}
|
|
283 |
|
|
284 |
/* for reverting the visible shape of a window to an rectangular form */
|
|
285 |
void
|
|
286 |
SplashRevertShape(Splash * splash) {
|
|
287 |
if (!shapeSupported)
|
|
288 |
return;
|
|
289 |
if (splash->maskRequired)
|
|
290 |
return;
|
|
291 |
|
|
292 |
XShapeCombineMask (splash->display, splash->window, ShapeClip,
|
|
293 |
0, 0, None, ShapeSet);
|
|
294 |
XShapeCombineMask (splash->display, splash->window , ShapeBounding,
|
|
295 |
0, 0, None, ShapeSet);
|
|
296 |
}
|
|
297 |
|
|
298 |
int
|
|
299 |
ByteOrderToX(int byteOrder) {
|
|
300 |
if (byteOrder == BYTE_ORDER_NATIVE)
|
|
301 |
byteOrder = platformByteOrder();
|
|
302 |
switch (byteOrder) {
|
|
303 |
case BYTE_ORDER_LSBFIRST:
|
|
304 |
return LSBFirst;
|
|
305 |
case BYTE_ORDER_MSBFIRST:
|
|
306 |
return MSBFirst;
|
|
307 |
default:
|
|
308 |
return -1;
|
|
309 |
}
|
|
310 |
}
|
|
311 |
|
|
312 |
void
|
|
313 |
SplashRedrawWindow(Splash * splash) {
|
|
314 |
XImage *ximage;
|
|
315 |
|
|
316 |
// making this method redraw a part of the image does not make
|
|
317 |
// much sense as SplashUpdateScreenData always re-generates
|
|
318 |
// the image completely, so whole window is always redrawn
|
|
319 |
|
|
320 |
SplashUpdateScreenData(splash);
|
|
321 |
ximage = XCreateImage(splash->display, splash->visual,
|
|
322 |
splash->screenFormat.depthBytes * 8, ZPixmap, 0, (char *) NULL,
|
|
323 |
splash->width, splash->height, 8, 0);
|
|
324 |
ximage->data = (char *) splash->screenData;
|
|
325 |
ximage->bits_per_pixel = ximage->depth;
|
|
326 |
ximage->bytes_per_line = ximage->depth * ximage->width / 8;
|
|
327 |
ximage->byte_order = ByteOrderToX(splash->screenFormat.byteOrder);
|
|
328 |
ximage->bitmap_unit = 8;
|
|
329 |
XPutImage(splash->display, splash->window,
|
|
330 |
XDefaultGCOfScreen(splash->screen), ximage, 0, 0, 0, 0,
|
|
331 |
splash->width, splash->height);
|
|
332 |
ximage->data = NULL;
|
|
333 |
XDestroyImage(ximage);
|
|
334 |
SplashRemoveDecoration(splash);
|
|
335 |
XMapWindow(splash->display, splash->window);
|
|
336 |
}
|
|
337 |
|
|
338 |
void SplashReconfigureNow(Splash * splash) {
|
|
339 |
SplashCenter(splash);
|
|
340 |
if (splash->window) {
|
|
341 |
XUnmapWindow(splash->display, splash->window);
|
|
342 |
XMoveResizeWindow(splash->display, splash->window,
|
|
343 |
splash->x, splash->y,
|
|
344 |
splash->width, splash->height);
|
|
345 |
SplashUpdateSizeHints(splash);
|
|
346 |
}
|
|
347 |
if (splash->maskRequired) {
|
|
348 |
SplashUpdateShape(splash);
|
|
349 |
} else {
|
|
350 |
SplashRevertShape(splash);
|
|
351 |
}
|
|
352 |
SplashRedrawWindow(splash);
|
|
353 |
}
|
|
354 |
|
|
355 |
|
|
356 |
void
|
|
357 |
sendctl(Splash * splash, char code) {
|
|
358 |
// if (splash->isVisible>0) {
|
|
359 |
if (splash && splash->controlpipe[1]) {
|
|
360 |
write(splash->controlpipe[1], &code, 1);
|
|
361 |
}
|
|
362 |
}
|
|
363 |
|
|
364 |
int
|
|
365 |
HandleError(Display * disp, XErrorEvent * err) {
|
|
366 |
// silently ignore non-fatal errors
|
|
367 |
/*
|
|
368 |
char msg[0x1000];
|
|
369 |
char buf[0x1000];
|
|
370 |
XGetErrorText(disp, err->error_code, msg, sizeof(msg));
|
|
371 |
fprintf(stderr, "Xerror %s, XID %x, ser# %d\n", msg, err->resourceid,
|
|
372 |
err->serial);
|
|
373 |
sprintf(buf, "%d", err->request_code);
|
|
374 |
XGetErrorDatabaseText(disp, "XRequest", buf, "Unknown", msg, sizeof(msg));
|
|
375 |
fprintf(stderr, "Major opcode %d (%s)\n", err->request_code, msg);
|
|
376 |
if (err->request_code > 128) {
|
|
377 |
fprintf(stderr, "Minor opcode %d\n", err->minor_code);
|
|
378 |
}
|
|
379 |
*/
|
|
380 |
return 0;
|
|
381 |
}
|
|
382 |
|
|
383 |
int
|
|
384 |
HandleIOError(Display * display) {
|
|
385 |
// for really bad errors, we should exit the thread we're on
|
|
386 |
SplashCleanup(SplashGetInstance());
|
|
387 |
pthread_exit(NULL);
|
|
388 |
return 0;
|
|
389 |
}
|
|
390 |
|
|
391 |
void
|
|
392 |
SplashInitPlatform(Splash * splash) {
|
|
393 |
int shapeVersionMajor, shapeVersionMinor;
|
|
394 |
|
|
395 |
// This setting enables the synchronous Xlib mode!
|
|
396 |
// Don't use it == 1 in production builds!
|
|
397 |
#if (defined DEBUG)
|
|
398 |
_Xdebug = 1;
|
|
399 |
#endif
|
|
400 |
|
|
401 |
pthread_mutex_init(&splash->lock, NULL);
|
|
402 |
|
|
403 |
// We should not ignore any errors.
|
|
404 |
//XSetErrorHandler(HandleError);
|
|
405 |
// XSetIOErrorHandler(HandleIOError);
|
|
406 |
XSetIOErrorHandler(NULL);
|
|
407 |
splash->display = XOpenDisplay(NULL);
|
|
408 |
if (!splash->display) {
|
|
409 |
splash->isVisible = -1;
|
|
410 |
return;
|
|
411 |
}
|
|
412 |
|
|
413 |
shapeSupported = XShapeQueryExtension(splash->display, &shapeEventBase,
|
|
414 |
&shapeErrorBase);
|
|
415 |
if (shapeSupported) {
|
|
416 |
XShapeQueryVersion(splash->display, &shapeVersionMajor,
|
|
417 |
&shapeVersionMinor);
|
|
418 |
}
|
|
419 |
|
|
420 |
splash->screen = XDefaultScreenOfDisplay(splash->display);
|
|
421 |
splash->visual = XDefaultVisualOfScreen(splash->screen);
|
|
422 |
switch (splash->visual->class) {
|
|
423 |
case TrueColor: {
|
|
424 |
int depth = XDefaultDepthOfScreen(splash->screen);
|
|
425 |
|
|
426 |
splash->byteAlignment = 1;
|
|
427 |
splash->maskRequired = shapeSupported;
|
|
428 |
initFormat(&splash->screenFormat, splash->visual->red_mask,
|
|
429 |
splash->visual->green_mask, splash->visual->blue_mask, 0);
|
|
430 |
splash->screenFormat.byteOrder =
|
|
431 |
(XImageByteOrder(splash->display) == LSBFirst ?
|
|
432 |
BYTE_ORDER_LSBFIRST : BYTE_ORDER_MSBFIRST);
|
|
433 |
splash->screenFormat.depthBytes = (depth + 7) / 8;
|
|
434 |
// TrueColor depth probably can't be less
|
|
435 |
// than 8 bits, and it's always byte padded
|
|
436 |
break;
|
|
437 |
}
|
|
438 |
case PseudoColor: {
|
|
439 |
int numColors;
|
|
440 |
int numComponents[3];
|
|
441 |
unsigned long colorIndex[SPLASH_COLOR_MAP_SIZE];
|
|
442 |
XColor xColors[SPLASH_COLOR_MAP_SIZE];
|
|
443 |
int i;
|
|
444 |
int depth = XDefaultDepthOfScreen(splash->screen);
|
|
445 |
int scale = 65535 / MAX_COLOR_VALUE;
|
|
446 |
|
|
447 |
numColors = GetNumAvailableColors(splash->display, splash->screen,
|
|
448 |
splash->visual->map_entries);
|
|
449 |
numColors = quantizeColors(numColors, numComponents);
|
|
450 |
splash->cmap = AllocColors(splash->display, splash->screen,
|
|
451 |
numColors, colorIndex);
|
|
452 |
for (i = 0; i < numColors; i++) {
|
|
453 |
splash->colorIndex[i] = colorIndex[i];
|
|
454 |
}
|
|
455 |
initColorCube(numComponents, splash->colorMap, splash->dithers,
|
|
456 |
splash->colorIndex);
|
|
457 |
for (i = 0; i < numColors; i++) {
|
|
458 |
xColors[i].pixel = colorIndex[i];
|
|
459 |
xColors[i].red = (unsigned short)
|
|
460 |
QUAD_RED(splash->colorMap[colorIndex[i]]) * scale;
|
|
461 |
xColors[i].green = (unsigned short)
|
|
462 |
QUAD_GREEN(splash->colorMap[colorIndex[i]]) * scale;
|
|
463 |
xColors[i].blue = (unsigned short)
|
|
464 |
QUAD_BLUE(splash->colorMap[colorIndex[i]]) * scale;
|
|
465 |
xColors[i].flags = DoRed | DoGreen | DoBlue;
|
|
466 |
}
|
|
467 |
XStoreColors(splash->display, splash->cmap, xColors, numColors);
|
|
468 |
initFormat(&splash->screenFormat, 0, 0, 0, 0);
|
|
469 |
splash->screenFormat.colorIndex = splash->colorIndex;
|
|
470 |
splash->screenFormat.depthBytes = (depth + 7) / 8; // or always 8?
|
|
471 |
splash->screenFormat.colorMap = splash->colorMap;
|
|
472 |
splash->screenFormat.dithers = splash->dithers;
|
|
473 |
splash->screenFormat.numColors = numColors;
|
|
474 |
splash->screenFormat.byteOrder = BYTE_ORDER_NATIVE;
|
|
475 |
break;
|
|
476 |
}
|
|
477 |
default:
|
|
478 |
; /* FIXME: should probably be fixed, but javaws splash screen doesn't support other visuals either */
|
|
479 |
}
|
|
480 |
}
|
|
481 |
|
|
482 |
|
|
483 |
void
|
|
484 |
SplashCleanupPlatform(Splash * splash) {
|
|
485 |
int i;
|
|
486 |
|
|
487 |
if (splash->frames) {
|
|
488 |
for (i = 0; i < splash->frameCount; i++) {
|
|
489 |
if (splash->frames[i].rects) {
|
|
490 |
free(splash->frames[i].rects);
|
|
491 |
splash->frames[i].rects = NULL;
|
|
492 |
}
|
|
493 |
}
|
|
494 |
}
|
|
495 |
splash->maskRequired = shapeSupported;
|
|
496 |
}
|
|
497 |
|
|
498 |
void
|
|
499 |
SplashDonePlatform(Splash * splash) {
|
|
500 |
pthread_mutex_destroy(&splash->lock);
|
|
501 |
if (splash->cmap) {
|
|
502 |
unsigned long colorIndex[SPLASH_COLOR_MAP_SIZE];
|
|
503 |
int i;
|
|
504 |
|
|
505 |
for (i = 0; i < splash->screenFormat.numColors; i++) {
|
|
506 |
colorIndex[i] = splash->colorIndex[i];
|
|
507 |
}
|
|
508 |
FreeColors(splash->display, splash->screen,
|
|
509 |
splash->screenFormat.numColors, colorIndex);
|
|
510 |
}
|
|
511 |
if (splash->window)
|
|
512 |
XDestroyWindow(splash->display, splash->window);
|
|
513 |
if (splash->wmHints)
|
|
514 |
XFree(splash->wmHints);
|
|
515 |
if (splash->cursor)
|
|
516 |
XFreeCursor(splash->display, splash->cursor);
|
|
517 |
if (splash->display)
|
|
518 |
XCloseDisplay(splash->display);
|
|
519 |
}
|
|
520 |
|
|
521 |
void
|
|
522 |
SplashEventLoop(Splash * splash) {
|
|
523 |
|
|
524 |
/* Different from win32 implementation - this loop
|
|
525 |
uses select timeouts instead of a timer */
|
|
526 |
/* we should have splash _locked_ on entry!!! */
|
|
527 |
|
|
528 |
int xconn = XConnectionNumber(splash->display);
|
|
529 |
|
|
530 |
while (1) {
|
|
531 |
int ctl = splash->controlpipe[0];
|
|
532 |
fd_set fds[2];
|
|
533 |
int n = 0;
|
|
534 |
struct timeval tv, *ptv;
|
|
535 |
int rc;
|
|
536 |
int time;
|
|
537 |
int pipes_empty;
|
|
538 |
|
|
539 |
FD_ZERO(fds);
|
|
540 |
FD_SET(xconn, fds);
|
|
541 |
if (xconn+1 > n)
|
|
542 |
n = xconn+1;
|
|
543 |
FD_SET(ctl, fds);
|
|
544 |
if (ctl+1 > n)
|
|
545 |
n = ctl+1;
|
|
546 |
errno = 0;
|
|
547 |
if (splash->isVisible>0 && SplashIsStillLooping(splash)) {
|
|
548 |
time = splash->time + splash->frames[splash->currentFrame].delay
|
|
549 |
- SplashTime();
|
|
550 |
if (time < 0)
|
|
551 |
time = 0;
|
|
552 |
msec2timeval(time, &tv);
|
|
553 |
ptv = &tv;
|
|
554 |
} else {
|
|
555 |
ptv = NULL;
|
|
556 |
}
|
|
557 |
SplashUnlock(splash);
|
|
558 |
rc = select(n, fds, NULL, NULL, ptv);
|
|
559 |
SplashLock(splash);
|
|
560 |
if (splash->isVisible>0 && SplashTime() >= splash->time +
|
|
561 |
splash->frames[splash->currentFrame].delay) {
|
|
562 |
SplashNextFrame(splash);
|
|
563 |
SplashUpdateShape(splash);
|
|
564 |
SplashRedrawWindow(splash);
|
|
565 |
}
|
|
566 |
if (rc <= 0) {
|
|
567 |
errno = 0;
|
|
568 |
continue;
|
|
569 |
}
|
|
570 |
pipes_empty = 0;
|
|
571 |
while(!pipes_empty) {
|
|
572 |
char buf;
|
|
573 |
|
|
574 |
pipes_empty = 1;
|
|
575 |
if (read(ctl, &buf, sizeof(buf)) > 0) {
|
|
576 |
pipes_empty = 0;
|
|
577 |
switch (buf) {
|
|
578 |
case SPLASHCTL_UPDATE:
|
|
579 |
if (splash->isVisible>0) {
|
|
580 |
SplashRedrawWindow(splash);
|
|
581 |
}
|
|
582 |
break;
|
|
583 |
case SPLASHCTL_RECONFIGURE:
|
|
584 |
if (splash->isVisible>0) {
|
|
585 |
SplashReconfigureNow(splash);
|
|
586 |
}
|
|
587 |
break;
|
|
588 |
case SPLASHCTL_QUIT:
|
|
589 |
return;
|
|
590 |
}
|
|
591 |
}
|
|
592 |
// we're not using "while(XPending)", processing one event
|
|
593 |
// at a time to avoid control pipe starvation
|
|
594 |
if (XPending(splash->display)) {
|
|
595 |
XEvent evt;
|
|
596 |
|
|
597 |
pipes_empty = 0;
|
|
598 |
XNextEvent(splash->display, &evt);
|
|
599 |
switch (evt.type) {
|
|
600 |
case Expose:
|
|
601 |
if (splash->isVisible>0) {
|
|
602 |
// we're doing full redraw so we just
|
|
603 |
// skip the remaining painting events in the queue
|
|
604 |
while(XCheckTypedEvent(splash->display, Expose,
|
|
605 |
&evt));
|
|
606 |
SplashRedrawWindow(splash);
|
|
607 |
}
|
|
608 |
break;
|
|
609 |
/* ... */
|
|
610 |
}
|
|
611 |
}
|
|
612 |
}
|
|
613 |
}
|
|
614 |
}
|
|
615 |
|
|
616 |
/* we can't use OverrideRedirect for the window as the window should not be
|
|
617 |
always-on-top, so we must set appropriate wm hints
|
|
618 |
|
|
619 |
this functions sets olwm, mwm and EWMH hints for undecorated window at once
|
|
620 |
|
|
621 |
It works for: mwm, openbox, wmaker, metacity, KWin (FIXME: test more wm's)
|
|
622 |
Should work for: fvwm2.5.x, blackbox, olwm
|
|
623 |
Maybe works for: enlightenment, icewm
|
|
624 |
Does not work for: twm, fvwm2.4.7
|
|
625 |
|
|
626 |
*/
|
|
627 |
|
|
628 |
void
|
|
629 |
SplashRemoveDecoration(Splash * splash) {
|
|
630 |
Atom atom_set;
|
|
631 |
Atom atom_list[4];
|
|
632 |
|
|
633 |
/* the struct below was copied from MwmUtil.h */
|
|
634 |
|
|
635 |
struct PROPMOTIFWMHINTS {
|
|
636 |
/* 32-bit property items are stored as long on the client (whether
|
|
637 |
* that means 32 bits or 64). XChangeProperty handles the conversion
|
|
638 |
* to the actual 32-bit quantities sent to the server.
|
|
639 |
*/
|
|
640 |
unsigned long flags;
|
|
641 |
unsigned long functions;
|
|
642 |
unsigned long decorations;
|
|
643 |
long inputMode;
|
|
644 |
unsigned long status;
|
|
645 |
}
|
|
646 |
mwm_hints;
|
|
647 |
|
|
648 |
/* WM_TAKE_FOCUS hint to avoid wm's transfer of focus to this window */
|
|
649 |
/* WM_DELETE_WINDOW hint to avoid closing this window with Alt-F4. See bug 6474035 */
|
|
650 |
atom_set = XInternAtom(splash->display, "WM_PROTOCOLS", True);
|
|
651 |
if (atom_set != None) {
|
|
652 |
atom_list[0] = XInternAtom(splash->display, "WM_TAKE_FOCUS", True);
|
|
653 |
atom_list[1] = XInternAtom(splash->display, "WM_DELETE_WINDOW", True);
|
|
654 |
|
|
655 |
XChangeProperty(splash->display, splash->window, atom_set, XA_ATOM, 32,
|
|
656 |
PropModeReplace, (unsigned char *) atom_list, 2);
|
|
657 |
}
|
|
658 |
|
|
659 |
/* mwm hints */
|
|
660 |
atom_set = XInternAtom(splash->display, "_MOTIF_WM_HINTS", True);
|
|
661 |
if (atom_set != None) {
|
|
662 |
/* flags for decoration and functions */
|
|
663 |
mwm_hints.flags = (1L << 1) | (1L << 0);
|
|
664 |
mwm_hints.decorations = 0;
|
|
665 |
mwm_hints.functions = 0;
|
|
666 |
XChangeProperty(splash->display, splash->window, atom_set, atom_set,
|
|
667 |
32, PropModeReplace, (unsigned char *) &mwm_hints, 5);
|
|
668 |
}
|
|
669 |
|
|
670 |
/* olwm hints */
|
|
671 |
atom_set = XInternAtom(splash->display, "_OL_DECOR_DEL", True);
|
|
672 |
if (atom_set != None) {
|
|
673 |
atom_list[0] = XInternAtom(splash->display, "_OL_DECOR_RESIZE", True);
|
|
674 |
atom_list[1] = XInternAtom(splash->display, "_OL_DECOR_HEADER", True);
|
|
675 |
atom_list[2] = XInternAtom(splash->display, "_OL_DECOR_PIN", True);
|
|
676 |
atom_list[3] = XInternAtom(splash->display, "_OL_DECOR_CLOSE", True);
|
|
677 |
XChangeProperty(splash->display, splash->window, atom_set, XA_ATOM, 32,
|
|
678 |
PropModeReplace, (unsigned char *) atom_list, 4);
|
|
679 |
}
|
|
680 |
|
|
681 |
/* generic EMWH hints
|
|
682 |
we do not set _NET_WM_WINDOW_TYPE to _NET_WM_WINDOW_TYPE_SPLASH
|
|
683 |
hint support due to gnome making this window always-on-top
|
|
684 |
so we have to set _NET_WM_STATE and _NET_WM_ALLOWED_ACTIONS correctly
|
|
685 |
_NET_WM_STATE: SKIP_TASKBAR and SKIP_PAGER
|
|
686 |
_NET_WM_ALLOWED_ACTIONS: disable all actions */
|
|
687 |
atom_set = XInternAtom(splash->display, "_NET_WM_STATE", True);
|
|
688 |
if (atom_set != None) {
|
|
689 |
atom_list[0] = XInternAtom(splash->display,
|
|
690 |
"_NET_WM_STATE_SKIP_TASKBAR", True);
|
|
691 |
atom_list[1] = XInternAtom(splash->display,
|
|
692 |
"_NET_WM_STATE_SKIP_PAGER", True);
|
|
693 |
XChangeProperty(splash->display, splash->window, atom_set, XA_ATOM, 32,
|
|
694 |
PropModeReplace, (unsigned char *) atom_list, 2);
|
|
695 |
}
|
|
696 |
atom_set = XInternAtom(splash->display, "_NET_WM_ALLOWED_ACTIONS", True);
|
|
697 |
if (atom_set != None) {
|
|
698 |
XChangeProperty(splash->display, splash->window, atom_set, XA_ATOM, 32,
|
|
699 |
PropModeReplace, (unsigned char *) atom_list, 0);
|
|
700 |
}
|
|
701 |
}
|
|
702 |
|
|
703 |
void
|
|
704 |
SplashPThreadDestructor(void *arg) {
|
|
705 |
/* this will be used in case of emergency thread exit on xlib error */
|
|
706 |
Splash *splash = (Splash *) arg;
|
|
707 |
|
|
708 |
if (splash) {
|
|
709 |
SplashCleanup(splash);
|
|
710 |
}
|
|
711 |
}
|
|
712 |
|
|
713 |
void *
|
|
714 |
SplashScreenThread(void *param) {
|
|
715 |
Splash *splash = (Splash *) param;
|
|
716 |
// pthread_key_t key;
|
|
717 |
|
|
718 |
// pthread_key_create(&key, SplashPThreadDestructor);
|
|
719 |
// pthread_setspecific(key, splash);
|
|
720 |
|
|
721 |
SplashLock(splash);
|
|
722 |
pipe(splash->controlpipe);
|
|
723 |
fcntl(splash->controlpipe[0], F_SETFL,
|
|
724 |
fcntl(splash->controlpipe[0], F_GETFL, 0) | O_NONBLOCK);
|
|
725 |
splash->time = SplashTime();
|
|
726 |
SplashCreateWindow(splash);
|
|
727 |
fflush(stdout);
|
|
728 |
if (splash->window) {
|
|
729 |
SplashRemoveDecoration(splash);
|
|
730 |
XStoreName(splash->display, splash->window, "Java");
|
|
731 |
XMapRaised(splash->display, splash->window);
|
|
732 |
SplashUpdateShape(splash);
|
|
733 |
SplashRedrawWindow(splash);
|
|
734 |
SplashEventLoop(splash);
|
|
735 |
}
|
|
736 |
SplashUnlock(splash);
|
|
737 |
SplashDone(splash);
|
|
738 |
|
|
739 |
splash->isVisible=-1;
|
|
740 |
return 0;
|
|
741 |
}
|
|
742 |
|
|
743 |
void
|
|
744 |
SplashCreateThread(Splash * splash) {
|
|
745 |
pthread_t thr;
|
|
746 |
pthread_attr_t attr;
|
|
747 |
int rc;
|
|
748 |
|
|
749 |
pthread_attr_init(&attr);
|
|
750 |
rc = pthread_create(&thr, &attr, SplashScreenThread, (void *) splash);
|
|
751 |
}
|
|
752 |
|
|
753 |
void
|
|
754 |
SplashLock(Splash * splash) {
|
|
755 |
pthread_mutex_lock(&splash->lock);
|
|
756 |
}
|
|
757 |
|
|
758 |
void
|
|
759 |
SplashUnlock(Splash * splash) {
|
|
760 |
pthread_mutex_unlock(&splash->lock);
|
|
761 |
}
|
|
762 |
|
|
763 |
void
|
|
764 |
SplashClosePlatform(Splash * splash) {
|
|
765 |
sendctl(splash, SPLASHCTL_QUIT);
|
|
766 |
}
|
|
767 |
|
|
768 |
void
|
|
769 |
SplashUpdate(Splash * splash) {
|
|
770 |
sendctl(splash, SPLASHCTL_UPDATE);
|
|
771 |
}
|
|
772 |
|
|
773 |
void
|
|
774 |
SplashReconfigure(Splash * splash) {
|
|
775 |
sendctl(splash, SPLASHCTL_RECONFIGURE);
|
|
776 |
}
|