0N/A/*
4341N/A * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A#include "splashscreen_impl.h"
0N/A#include <X11/Xlib.h>
0N/A#include <X11/Xutil.h>
0N/A#include <X11/extensions/shape.h>
0N/A#include <X11/Xmd.h>
0N/A#include <X11/Xatom.h>
0N/A#include <X11/cursorfont.h>
0N/A#include <sys/types.h>
0N/A#include <pthread.h>
0N/A#include <signal.h>
0N/A#include <unistd.h>
0N/A#include <sys/time.h>
0N/A#include <errno.h>
0N/A#include <iconv.h>
0N/A#include <langinfo.h>
0N/A#include <locale.h>
0N/A#include <fcntl.h>
550N/A#include <poll.h>
6295N/A#include <sizecalc.h>
0N/A
0N/Astatic Bool shapeSupported;
0N/Astatic int shapeEventBase, shapeErrorBase;
0N/A
0N/Avoid SplashRemoveDecoration(Splash * splash);
0N/A
0N/A
0N/A/* Could use npt but decided to cut down on linked code size */
0N/Achar* SplashConvertStringAlloc(const char* in, int* size) {
0N/A const char *codeset;
0N/A const char *codeset_out;
0N/A iconv_t cd;
0N/A size_t rc;
0N/A char *buf = NULL, *out;
0N/A size_t bufSize, inSize, outSize;
0N/A const char* old_locale;
0N/A
0N/A if (!in) {
0N/A return NULL;
0N/A }
0N/A old_locale = setlocale(LC_ALL, "");
0N/A
0N/A codeset = nl_langinfo(CODESET);
0N/A if ( codeset == NULL || codeset[0] == 0 ) {
0N/A goto done;
0N/A }
0N/A /* we don't need BOM in output so we choose native BE or LE encoding here */
0N/A codeset_out = (platformByteOrder()==BYTE_ORDER_MSBFIRST) ?
0N/A "UCS-2BE" : "UCS-2LE";
0N/A
0N/A cd = iconv_open(codeset_out, codeset);
0N/A if (cd == (iconv_t)-1 ) {
0N/A goto done;
0N/A }
0N/A inSize = strlen(in);
6295N/A buf = SAFE_SIZE_ARRAY_ALLOC(malloc, inSize, 2);
6295N/A if (!buf) {
6295N/A return NULL;
6295N/A }
0N/A bufSize = inSize*2; // need 2 bytes per char for UCS-2, this is
0N/A // 2 bytes per source byte max
0N/A out = buf; outSize = bufSize;
0N/A /* linux iconv wants char** source and solaris wants const char**...
0N/A cast to void* */
0N/A rc = iconv(cd, (void*)&in, &inSize, &out, &outSize);
0N/A iconv_close(cd);
0N/A
0N/A if (rc == (size_t)-1) {
0N/A free(buf);
0N/A buf = NULL;
0N/A } else {
0N/A if (size) {
0N/A *size = (bufSize-outSize)/2; /* bytes to wchars */
0N/A }
0N/A }
0N/Adone:
0N/A setlocale(LC_ALL, old_locale);
0N/A return buf;
0N/A}
0N/A
0N/Avoid
0N/ASplashInitFrameShape(Splash * splash, int imageIndex) {
0N/A ImageRect maskRect;
0N/A XRectangle *rects;
0N/A SplashImage *frame = splash->frames + imageIndex;
0N/A
0N/A frame->rects = NULL;
0N/A frame->numRects = 0;
0N/A
0N/A if (!splash->maskRequired)
0N/A return;
0N/A if (!shapeSupported)
0N/A return;
0N/A initRect(&maskRect, 0, 0, splash->width, splash->height, 1,
0N/A splash->width * splash->imageFormat.depthBytes,
0N/A splash->frames[imageIndex].bitmapBits, &splash->imageFormat);
6295N/A if (!IS_SAFE_SIZE_MUL(splash->width / 2 + 1, splash->height)) {
6295N/A return;
6295N/A }
6295N/A rects = SAFE_SIZE_ARRAY_ALLOC(malloc,
6295N/A sizeof(XRectangle), (splash->width / 2 + 1) * splash->height);
6295N/A if (!rects) {
6295N/A return;
6295N/A }
0N/A
0N/A frame->numRects = BitmapToYXBandedRectangles(&maskRect, rects);
6295N/A frame->rects = SAFE_SIZE_ARRAY_ALLOC(malloc, frame->numRects, sizeof(XRectangle));
6295N/A if (frame->rects) { // handle the error after the if(){}
6295N/A memcpy(frame->rects, rects, frame->numRects * sizeof(XRectangle));
6295N/A }
0N/A free(rects);
0N/A}
0N/A
0N/Aunsigned
0N/ASplashTime(void) {
0N/A struct timeval tv;
0N/A struct timezone tz;
0N/A unsigned long long msec;
0N/A
0N/A gettimeofday(&tv, &tz);
0N/A msec = (unsigned long long) tv.tv_sec * 1000 +
0N/A (unsigned long long) tv.tv_usec / 1000;
0N/A
0N/A return (unsigned) msec;
0N/A}
0N/A
0N/Avoid
0N/Amsec2timeval(unsigned time, struct timeval *tv) {
0N/A tv->tv_sec = time / 1000;
0N/A tv->tv_usec = (time % 1000) * 1000;
0N/A}
0N/A
0N/Aint
0N/AGetNumAvailableColors(Display * display, Screen * screen, unsigned map_entries) {
0N/A unsigned long pmr[1];
0N/A unsigned long pr[SPLASH_COLOR_MAP_SIZE];
0N/A unsigned nFailed, nAllocated, done = 0, nPlanes = 0;
0N/A Colormap cmap;
0N/A unsigned numColors = SPLASH_COLOR_MAP_SIZE; // never try allocating more than that
0N/A
0N/A if (numColors > map_entries) {
0N/A numColors = map_entries;
0N/A }
0N/A cmap = XDefaultColormapOfScreen(screen);
0N/A nAllocated = 0; /* lower bound */
0N/A nFailed = numColors + 1; /* upper bound */
0N/A
0N/A /* Binary search to determine the number of available cells */
0N/A for (done = 0; !done;) {
0N/A if (XAllocColorCells(display, cmap, 0, pmr, nPlanes, pr, numColors)) {
0N/A nAllocated = numColors;
0N/A XFreeColors(display, cmap, pr, numColors, 0);
0N/A if (nAllocated < (nFailed - 1)) {
0N/A numColors = (nAllocated + nFailed) / 2;
0N/A } else
0N/A done = 1;
0N/A } else {
0N/A nFailed = numColors;
0N/A if (nFailed > (nAllocated + 1))
0N/A numColors = (nAllocated + nFailed) / 2;
0N/A else
0N/A done = 1;
0N/A }
0N/A }
0N/A return nAllocated;
0N/A}
0N/A
0N/AColormap
0N/AAllocColors(Display * display, Screen * screen, int numColors,
0N/A unsigned long *pr) {
0N/A unsigned long pmr[1];
0N/A Colormap cmap = XDefaultColormapOfScreen(screen);
0N/A
0N/A XAllocColorCells(display, cmap, 0, pmr, 0, pr, numColors);
0N/A return cmap;
0N/A}
0N/A
0N/Avoid
0N/AFreeColors(Display * display, Screen * screen, int numColors,
0N/A unsigned long *pr) {
0N/A Colormap cmap = XDefaultColormapOfScreen(screen);
0N/A
0N/A XFreeColors(display, cmap, pr, numColors, 0);
0N/A}
0N/A
0N/Astatic void SplashCenter(Splash * splash) {
0N/A Atom type, atom, actual_type;
0N/A int status, actual_format;
0N/A unsigned long nitems, bytes_after;
0N/A CARD16 *prop = NULL;
0N/A
0N/A /* try centering using Xinerama hint
0N/A if there's no hint, use the center of the screen */
0N/A atom = XInternAtom(splash->display, "XINERAMA_CENTER_HINT", True);
0N/A if (atom != None) {
0N/A status = XGetWindowProperty(splash->display,
0N/A XRootWindowOfScreen(splash->screen), atom, 0, 1, False, XA_INTEGER,
0N/A &actual_type, &actual_format, &nitems,
0N/A &bytes_after, (unsigned char**)(&prop));
0N/A if (status == Success && actual_type != None && prop != NULL) {
0N/A splash->x = prop[0] - splash->width/2;
0N/A splash->y = prop[1] - splash->height/2;
0N/A XFree(prop);
0N/A return;
0N/A }
0N/A if (prop != NULL) {
0N/A XFree(prop);
0N/A }
0N/A }
0N/A splash->x = (XWidthOfScreen(splash->screen) - splash->width) / 2;
0N/A splash->y = (XHeightOfScreen(splash->screen) - splash->height) / 2;
0N/A}
0N/A
0N/Astatic void SplashUpdateSizeHints(Splash * splash) {
0N/A if (splash->window) {
0N/A XSizeHints sizeHints;
0N/A
0N/A sizeHints.flags = USPosition | PPosition | USSize | PSize | PMinSize | PMaxSize | PWinGravity;
0N/A sizeHints.width = sizeHints.base_width = sizeHints.min_width = sizeHints.max_width = splash->width;
0N/A sizeHints.height = sizeHints.base_height = sizeHints.min_height = sizeHints.max_height = splash->height;
0N/A sizeHints.win_gravity = NorthWestGravity;
0N/A
0N/A XSetWMNormalHints(splash->display, splash->window, &sizeHints);
0N/A }
0N/A}
0N/A
0N/Avoid
0N/ASplashCreateWindow(Splash * splash) {
0N/A XSizeHints sizeHints;
0N/A
0N/A XSetWindowAttributes attr;
0N/A
0N/A attr.backing_store = NotUseful;
0N/A attr.colormap = XDefaultColormapOfScreen(splash->screen);
0N/A attr.save_under = True;
0N/A attr.cursor = splash->cursor = XCreateFontCursor(splash->display, XC_watch);
0N/A attr.event_mask = ExposureMask;
0N/A
0N/A SplashCenter(splash);
0N/A
0N/A splash->window = XCreateWindow(splash->display, XRootWindowOfScreen(splash->screen),
0N/A splash->x, splash->y, splash->width, splash->height, 0, CopyFromParent,
0N/A InputOutput, CopyFromParent, CWColormap | CWBackingStore | CWSaveUnder | CWCursor | CWEventMask,
0N/A &attr);
0N/A SplashUpdateSizeHints(splash);
0N/A
0N/A
0N/A splash->wmHints = XAllocWMHints();
0N/A if (splash->wmHints) {
0N/A splash->wmHints->flags = InputHint | StateHint;
0N/A splash->wmHints->input = False;
0N/A splash->wmHints->initial_state = NormalState;
0N/A XSetWMHints(splash->display, splash->window, splash->wmHints);
0N/A }
0N/A}
0N/A
0N/A/* for changing the visible shape of a window to an nonrectangular form */
0N/Avoid
0N/ASplashUpdateShape(Splash * splash) {
0N/A if (!shapeSupported)
0N/A return;
0N/A if (!splash->maskRequired) {
0N/A return;
0N/A }
0N/A XShapeCombineRectangles(splash->display, splash->window, ShapeClip, 0, 0,
0N/A splash->frames[splash->currentFrame].rects,
0N/A splash->frames[splash->currentFrame].numRects, ShapeSet, YXBanded);
0N/A XShapeCombineRectangles(splash->display, splash->window, ShapeBounding,
0N/A 0, 0, splash->frames[splash->currentFrame].rects,
0N/A splash->frames[splash->currentFrame].numRects, ShapeSet, YXBanded);
0N/A}
0N/A
0N/A/* for reverting the visible shape of a window to an rectangular form */
0N/Avoid
0N/ASplashRevertShape(Splash * splash) {
0N/A if (!shapeSupported)
0N/A return;
0N/A if (splash->maskRequired)
0N/A return;
0N/A
0N/A XShapeCombineMask (splash->display, splash->window, ShapeClip,
0N/A 0, 0, None, ShapeSet);
0N/A XShapeCombineMask (splash->display, splash->window , ShapeBounding,
0N/A 0, 0, None, ShapeSet);
0N/A}
0N/A
0N/Aint
0N/AByteOrderToX(int byteOrder) {
0N/A if (byteOrder == BYTE_ORDER_NATIVE)
0N/A byteOrder = platformByteOrder();
0N/A switch (byteOrder) {
0N/A case BYTE_ORDER_LSBFIRST:
0N/A return LSBFirst;
0N/A case BYTE_ORDER_MSBFIRST:
0N/A return MSBFirst;
0N/A default:
0N/A return -1;
0N/A }
0N/A}
0N/A
0N/Avoid
0N/ASplashRedrawWindow(Splash * splash) {
0N/A XImage *ximage;
0N/A
0N/A // making this method redraw a part of the image does not make
0N/A // much sense as SplashUpdateScreenData always re-generates
0N/A // the image completely, so whole window is always redrawn
0N/A
0N/A SplashUpdateScreenData(splash);
0N/A ximage = XCreateImage(splash->display, splash->visual,
0N/A splash->screenFormat.depthBytes * 8, ZPixmap, 0, (char *) NULL,
0N/A splash->width, splash->height, 8, 0);
0N/A ximage->data = (char *) splash->screenData;
0N/A ximage->bits_per_pixel = ximage->depth;
0N/A ximage->bytes_per_line = ximage->depth * ximage->width / 8;
0N/A ximage->byte_order = ByteOrderToX(splash->screenFormat.byteOrder);
0N/A ximage->bitmap_unit = 8;
0N/A XPutImage(splash->display, splash->window,
0N/A XDefaultGCOfScreen(splash->screen), ximage, 0, 0, 0, 0,
0N/A splash->width, splash->height);
0N/A ximage->data = NULL;
0N/A XDestroyImage(ximage);
0N/A SplashRemoveDecoration(splash);
0N/A XMapWindow(splash->display, splash->window);
4341N/A XFlush(splash->display);
0N/A}
0N/A
0N/Avoid SplashReconfigureNow(Splash * splash) {
0N/A SplashCenter(splash);
0N/A if (splash->window) {
0N/A XUnmapWindow(splash->display, splash->window);
0N/A XMoveResizeWindow(splash->display, splash->window,
0N/A splash->x, splash->y,
0N/A splash->width, splash->height);
0N/A SplashUpdateSizeHints(splash);
0N/A }
0N/A if (splash->maskRequired) {
0N/A SplashUpdateShape(splash);
0N/A } else {
0N/A SplashRevertShape(splash);
0N/A }
0N/A SplashRedrawWindow(splash);
0N/A}
0N/A
0N/A
0N/Avoid
0N/Asendctl(Splash * splash, char code) {
0N/A// if (splash->isVisible>0) {
0N/A if (splash && splash->controlpipe[1]) {
0N/A write(splash->controlpipe[1], &code, 1);
0N/A }
0N/A}
0N/A
0N/Aint
0N/AHandleError(Display * disp, XErrorEvent * err) {
0N/A // silently ignore non-fatal errors
0N/A /*
0N/A char msg[0x1000];
0N/A char buf[0x1000];
0N/A XGetErrorText(disp, err->error_code, msg, sizeof(msg));
0N/A fprintf(stderr, "Xerror %s, XID %x, ser# %d\n", msg, err->resourceid,
0N/A err->serial);
0N/A sprintf(buf, "%d", err->request_code);
0N/A XGetErrorDatabaseText(disp, "XRequest", buf, "Unknown", msg, sizeof(msg));
0N/A fprintf(stderr, "Major opcode %d (%s)\n", err->request_code, msg);
0N/A if (err->request_code > 128) {
0N/A fprintf(stderr, "Minor opcode %d\n", err->minor_code);
0N/A }
0N/A */
0N/A return 0;
0N/A}
0N/A
0N/Aint
0N/AHandleIOError(Display * display) {
0N/A // for really bad errors, we should exit the thread we're on
0N/A SplashCleanup(SplashGetInstance());
0N/A pthread_exit(NULL);
0N/A return 0;
0N/A}
0N/A
0N/Avoid
0N/ASplashInitPlatform(Splash * splash) {
0N/A int shapeVersionMajor, shapeVersionMinor;
0N/A
0N/A // This setting enables the synchronous Xlib mode!
0N/A // Don't use it == 1 in production builds!
0N/A#if (defined DEBUG)
0N/A _Xdebug = 1;
0N/A#endif
0N/A
0N/A pthread_mutex_init(&splash->lock, NULL);
0N/A
0N/A // We should not ignore any errors.
0N/A //XSetErrorHandler(HandleError);
0N/A// XSetIOErrorHandler(HandleIOError);
0N/A XSetIOErrorHandler(NULL);
0N/A splash->display = XOpenDisplay(NULL);
0N/A if (!splash->display) {
0N/A splash->isVisible = -1;
0N/A return;
0N/A }
0N/A
0N/A shapeSupported = XShapeQueryExtension(splash->display, &shapeEventBase,
0N/A &shapeErrorBase);
0N/A if (shapeSupported) {
0N/A XShapeQueryVersion(splash->display, &shapeVersionMajor,
0N/A &shapeVersionMinor);
0N/A }
0N/A
0N/A splash->screen = XDefaultScreenOfDisplay(splash->display);
0N/A splash->visual = XDefaultVisualOfScreen(splash->screen);
0N/A switch (splash->visual->class) {
0N/A case TrueColor: {
0N/A int depth = XDefaultDepthOfScreen(splash->screen);
0N/A
0N/A splash->byteAlignment = 1;
0N/A splash->maskRequired = shapeSupported;
0N/A initFormat(&splash->screenFormat, splash->visual->red_mask,
0N/A splash->visual->green_mask, splash->visual->blue_mask, 0);
0N/A splash->screenFormat.byteOrder =
0N/A (XImageByteOrder(splash->display) == LSBFirst ?
0N/A BYTE_ORDER_LSBFIRST : BYTE_ORDER_MSBFIRST);
0N/A splash->screenFormat.depthBytes = (depth + 7) / 8;
0N/A // TrueColor depth probably can't be less
0N/A // than 8 bits, and it's always byte padded
0N/A break;
0N/A }
0N/A case PseudoColor: {
199N/A int availableColors;
0N/A int numColors;
0N/A int numComponents[3];
0N/A unsigned long colorIndex[SPLASH_COLOR_MAP_SIZE];
0N/A XColor xColors[SPLASH_COLOR_MAP_SIZE];
0N/A int i;
0N/A int depth = XDefaultDepthOfScreen(splash->screen);
0N/A int scale = 65535 / MAX_COLOR_VALUE;
0N/A
199N/A availableColors = GetNumAvailableColors(splash->display, splash->screen,
0N/A splash->visual->map_entries);
199N/A numColors = quantizeColors(availableColors, numComponents);
199N/A if (numColors > availableColors) {
199N/A // Could not allocate the color cells. Most probably
199N/A // the pool got exhausted. Disable the splash screen.
199N/A XCloseDisplay(splash->display);
199N/A splash->isVisible = -1;
199N/A splash->display = NULL;
199N/A splash->screen = NULL;
199N/A splash->visual = NULL;
199N/A fprintf(stderr, "Warning: unable to initialize the splashscreen. Not enough available color cells.\n");
199N/A return;
199N/A }
0N/A splash->cmap = AllocColors(splash->display, splash->screen,
0N/A numColors, colorIndex);
0N/A for (i = 0; i < numColors; i++) {
0N/A splash->colorIndex[i] = colorIndex[i];
0N/A }
0N/A initColorCube(numComponents, splash->colorMap, splash->dithers,
0N/A splash->colorIndex);
0N/A for (i = 0; i < numColors; i++) {
0N/A xColors[i].pixel = colorIndex[i];
0N/A xColors[i].red = (unsigned short)
0N/A QUAD_RED(splash->colorMap[colorIndex[i]]) * scale;
0N/A xColors[i].green = (unsigned short)
0N/A QUAD_GREEN(splash->colorMap[colorIndex[i]]) * scale;
0N/A xColors[i].blue = (unsigned short)
0N/A QUAD_BLUE(splash->colorMap[colorIndex[i]]) * scale;
0N/A xColors[i].flags = DoRed | DoGreen | DoBlue;
0N/A }
0N/A XStoreColors(splash->display, splash->cmap, xColors, numColors);
0N/A initFormat(&splash->screenFormat, 0, 0, 0, 0);
0N/A splash->screenFormat.colorIndex = splash->colorIndex;
0N/A splash->screenFormat.depthBytes = (depth + 7) / 8; // or always 8?
0N/A splash->screenFormat.colorMap = splash->colorMap;
0N/A splash->screenFormat.dithers = splash->dithers;
0N/A splash->screenFormat.numColors = numColors;
0N/A splash->screenFormat.byteOrder = BYTE_ORDER_NATIVE;
0N/A break;
0N/A }
0N/A default:
0N/A ; /* FIXME: should probably be fixed, but javaws splash screen doesn't support other visuals either */
0N/A }
0N/A}
0N/A
0N/A
0N/Avoid
0N/ASplashCleanupPlatform(Splash * splash) {
0N/A int i;
0N/A
0N/A if (splash->frames) {
0N/A for (i = 0; i < splash->frameCount; i++) {
0N/A if (splash->frames[i].rects) {
0N/A free(splash->frames[i].rects);
0N/A splash->frames[i].rects = NULL;
0N/A }
0N/A }
0N/A }
0N/A splash->maskRequired = shapeSupported;
0N/A}
0N/A
0N/Avoid
0N/ASplashDonePlatform(Splash * splash) {
0N/A pthread_mutex_destroy(&splash->lock);
0N/A if (splash->cmap) {
0N/A unsigned long colorIndex[SPLASH_COLOR_MAP_SIZE];
0N/A int i;
0N/A
0N/A for (i = 0; i < splash->screenFormat.numColors; i++) {
0N/A colorIndex[i] = splash->colorIndex[i];
0N/A }
0N/A FreeColors(splash->display, splash->screen,
0N/A splash->screenFormat.numColors, colorIndex);
0N/A }
0N/A if (splash->window)
0N/A XDestroyWindow(splash->display, splash->window);
0N/A if (splash->wmHints)
0N/A XFree(splash->wmHints);
0N/A if (splash->cursor)
0N/A XFreeCursor(splash->display, splash->cursor);
0N/A if (splash->display)
0N/A XCloseDisplay(splash->display);
0N/A}
0N/A
0N/Avoid
0N/ASplashEventLoop(Splash * splash) {
0N/A
0N/A /* Different from win32 implementation - this loop
550N/A uses poll timeouts instead of a timer */
0N/A /* we should have splash _locked_ on entry!!! */
0N/A
0N/A int xconn = XConnectionNumber(splash->display);
0N/A
0N/A while (1) {
550N/A struct pollfd pfd[2];
550N/A int timeout = -1;
0N/A int ctl = splash->controlpipe[0];
0N/A int rc;
0N/A int pipes_empty;
0N/A
550N/A pfd[0].fd = xconn;
550N/A pfd[0].events = POLLIN | POLLPRI;
550N/A
550N/A pfd[1].fd = ctl;
550N/A pfd[1].events = POLLIN | POLLPRI;
550N/A
0N/A errno = 0;
0N/A if (splash->isVisible>0 && SplashIsStillLooping(splash)) {
550N/A timeout = splash->time + splash->frames[splash->currentFrame].delay
0N/A - SplashTime();
550N/A if (timeout < 0) {
550N/A timeout = 0;
550N/A }
0N/A }
0N/A SplashUnlock(splash);
550N/A rc = poll(pfd, 2, timeout);
0N/A SplashLock(splash);
0N/A if (splash->isVisible>0 && SplashTime() >= splash->time +
0N/A splash->frames[splash->currentFrame].delay) {
0N/A SplashNextFrame(splash);
0N/A SplashUpdateShape(splash);
0N/A SplashRedrawWindow(splash);
0N/A }
0N/A if (rc <= 0) {
0N/A errno = 0;
0N/A continue;
0N/A }
0N/A pipes_empty = 0;
0N/A while(!pipes_empty) {
0N/A char buf;
0N/A
0N/A pipes_empty = 1;
0N/A if (read(ctl, &buf, sizeof(buf)) > 0) {
0N/A pipes_empty = 0;
0N/A switch (buf) {
0N/A case SPLASHCTL_UPDATE:
0N/A if (splash->isVisible>0) {
0N/A SplashRedrawWindow(splash);
0N/A }
0N/A break;
0N/A case SPLASHCTL_RECONFIGURE:
0N/A if (splash->isVisible>0) {
0N/A SplashReconfigureNow(splash);
0N/A }
0N/A break;
0N/A case SPLASHCTL_QUIT:
0N/A return;
0N/A }
0N/A }
0N/A // we're not using "while(XPending)", processing one event
0N/A // at a time to avoid control pipe starvation
0N/A if (XPending(splash->display)) {
0N/A XEvent evt;
0N/A
0N/A pipes_empty = 0;
0N/A XNextEvent(splash->display, &evt);
0N/A switch (evt.type) {
0N/A case Expose:
0N/A if (splash->isVisible>0) {
0N/A // we're doing full redraw so we just
0N/A // skip the remaining painting events in the queue
0N/A while(XCheckTypedEvent(splash->display, Expose,
0N/A &evt));
0N/A SplashRedrawWindow(splash);
0N/A }
0N/A break;
0N/A /* ... */
0N/A }
0N/A }
0N/A }
0N/A }
0N/A}
0N/A
0N/A/* we can't use OverrideRedirect for the window as the window should not be
0N/A always-on-top, so we must set appropriate wm hints
0N/A
0N/A this functions sets olwm, mwm and EWMH hints for undecorated window at once
0N/A
0N/A It works for: mwm, openbox, wmaker, metacity, KWin (FIXME: test more wm's)
0N/A Should work for: fvwm2.5.x, blackbox, olwm
0N/A Maybe works for: enlightenment, icewm
0N/A Does not work for: twm, fvwm2.4.7
0N/A
0N/A*/
0N/A
0N/Avoid
0N/ASplashRemoveDecoration(Splash * splash) {
0N/A Atom atom_set;
0N/A Atom atom_list[4];
0N/A
0N/A /* the struct below was copied from MwmUtil.h */
0N/A
0N/A struct PROPMOTIFWMHINTS {
0N/A /* 32-bit property items are stored as long on the client (whether
0N/A * that means 32 bits or 64). XChangeProperty handles the conversion
0N/A * to the actual 32-bit quantities sent to the server.
0N/A */
0N/A unsigned long flags;
0N/A unsigned long functions;
0N/A unsigned long decorations;
0N/A long inputMode;
0N/A unsigned long status;
0N/A }
0N/A mwm_hints;
0N/A
0N/A /* WM_TAKE_FOCUS hint to avoid wm's transfer of focus to this window */
0N/A /* WM_DELETE_WINDOW hint to avoid closing this window with Alt-F4. See bug 6474035 */
0N/A atom_set = XInternAtom(splash->display, "WM_PROTOCOLS", True);
0N/A if (atom_set != None) {
0N/A atom_list[0] = XInternAtom(splash->display, "WM_TAKE_FOCUS", True);
0N/A atom_list[1] = XInternAtom(splash->display, "WM_DELETE_WINDOW", True);
0N/A
0N/A XChangeProperty(splash->display, splash->window, atom_set, XA_ATOM, 32,
0N/A PropModeReplace, (unsigned char *) atom_list, 2);
0N/A }
0N/A
0N/A /* mwm hints */
0N/A atom_set = XInternAtom(splash->display, "_MOTIF_WM_HINTS", True);
0N/A if (atom_set != None) {
0N/A /* flags for decoration and functions */
0N/A mwm_hints.flags = (1L << 1) | (1L << 0);
0N/A mwm_hints.decorations = 0;
0N/A mwm_hints.functions = 0;
0N/A XChangeProperty(splash->display, splash->window, atom_set, atom_set,
0N/A 32, PropModeReplace, (unsigned char *) &mwm_hints, 5);
0N/A }
0N/A
0N/A /* olwm hints */
0N/A atom_set = XInternAtom(splash->display, "_OL_DECOR_DEL", True);
0N/A if (atom_set != None) {
0N/A atom_list[0] = XInternAtom(splash->display, "_OL_DECOR_RESIZE", True);
0N/A atom_list[1] = XInternAtom(splash->display, "_OL_DECOR_HEADER", True);
0N/A atom_list[2] = XInternAtom(splash->display, "_OL_DECOR_PIN", True);
0N/A atom_list[3] = XInternAtom(splash->display, "_OL_DECOR_CLOSE", True);
0N/A XChangeProperty(splash->display, splash->window, atom_set, XA_ATOM, 32,
0N/A PropModeReplace, (unsigned char *) atom_list, 4);
0N/A }
0N/A
0N/A /* generic EMWH hints
0N/A we do not set _NET_WM_WINDOW_TYPE to _NET_WM_WINDOW_TYPE_SPLASH
0N/A hint support due to gnome making this window always-on-top
0N/A so we have to set _NET_WM_STATE and _NET_WM_ALLOWED_ACTIONS correctly
0N/A _NET_WM_STATE: SKIP_TASKBAR and SKIP_PAGER
0N/A _NET_WM_ALLOWED_ACTIONS: disable all actions */
0N/A atom_set = XInternAtom(splash->display, "_NET_WM_STATE", True);
0N/A if (atom_set != None) {
0N/A atom_list[0] = XInternAtom(splash->display,
0N/A "_NET_WM_STATE_SKIP_TASKBAR", True);
0N/A atom_list[1] = XInternAtom(splash->display,
0N/A "_NET_WM_STATE_SKIP_PAGER", True);
0N/A XChangeProperty(splash->display, splash->window, atom_set, XA_ATOM, 32,
0N/A PropModeReplace, (unsigned char *) atom_list, 2);
0N/A }
0N/A atom_set = XInternAtom(splash->display, "_NET_WM_ALLOWED_ACTIONS", True);
0N/A if (atom_set != None) {
0N/A XChangeProperty(splash->display, splash->window, atom_set, XA_ATOM, 32,
0N/A PropModeReplace, (unsigned char *) atom_list, 0);
0N/A }
0N/A}
0N/A
0N/Avoid
0N/ASplashPThreadDestructor(void *arg) {
0N/A /* this will be used in case of emergency thread exit on xlib error */
0N/A Splash *splash = (Splash *) arg;
0N/A
0N/A if (splash) {
0N/A SplashCleanup(splash);
0N/A }
0N/A}
0N/A
0N/Avoid *
0N/ASplashScreenThread(void *param) {
0N/A Splash *splash = (Splash *) param;
0N/A// pthread_key_t key;
0N/A
0N/A// pthread_key_create(&key, SplashPThreadDestructor);
0N/A// pthread_setspecific(key, splash);
0N/A
0N/A SplashLock(splash);
0N/A pipe(splash->controlpipe);
0N/A fcntl(splash->controlpipe[0], F_SETFL,
0N/A fcntl(splash->controlpipe[0], F_GETFL, 0) | O_NONBLOCK);
0N/A splash->time = SplashTime();
0N/A SplashCreateWindow(splash);
0N/A fflush(stdout);
0N/A if (splash->window) {
0N/A SplashRemoveDecoration(splash);
0N/A XStoreName(splash->display, splash->window, "Java");
0N/A XMapRaised(splash->display, splash->window);
0N/A SplashUpdateShape(splash);
0N/A SplashRedrawWindow(splash);
0N/A SplashEventLoop(splash);
0N/A }
0N/A SplashUnlock(splash);
0N/A SplashDone(splash);
0N/A
0N/A splash->isVisible=-1;
0N/A return 0;
0N/A}
0N/A
0N/Avoid
0N/ASplashCreateThread(Splash * splash) {
0N/A pthread_t thr;
0N/A pthread_attr_t attr;
0N/A int rc;
0N/A
0N/A pthread_attr_init(&attr);
0N/A rc = pthread_create(&thr, &attr, SplashScreenThread, (void *) splash);
0N/A}
0N/A
0N/Avoid
0N/ASplashLock(Splash * splash) {
0N/A pthread_mutex_lock(&splash->lock);
0N/A}
0N/A
0N/Avoid
0N/ASplashUnlock(Splash * splash) {
0N/A pthread_mutex_unlock(&splash->lock);
0N/A}
0N/A
0N/Avoid
0N/ASplashClosePlatform(Splash * splash) {
0N/A sendctl(splash, SPLASHCTL_QUIT);
0N/A}
0N/A
0N/Avoid
0N/ASplashUpdate(Splash * splash) {
0N/A sendctl(splash, SPLASHCTL_UPDATE);
0N/A}
0N/A
0N/Avoid
0N/ASplashReconfigure(Splash * splash) {
0N/A sendctl(splash, SPLASHCTL_RECONFIGURE);
0N/A}