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