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