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