jdk/src/solaris/native/sun/awt/splashscreen/splashscreen_sys.c
author yan
Fri, 08 Aug 2008 03:32:34 -0700
changeset 1188 44c63c47def9
parent 1178 4734cf2a22bf
parent 715 f16baef3a20e
child 5506 202f599c92aa
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
715
f16baef3a20e 6719955: Update copyright year
xdono
parents: 422
diff changeset
     2
 * Copyright 2005-2008 Sun Microsystems, Inc.  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
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
#include "splashscreen_impl.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
#include <X11/Xlib.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
#include <X11/Xutil.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
#include <X11/extensions/shape.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
#include <X11/Xmd.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
#include <X11/Xatom.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
#include <X11/cursorfont.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
#include <sys/types.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
#include <pthread.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
#include <signal.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
#include <unistd.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
#include <sys/time.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
#include <errno.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
#include <iconv.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
#include <langinfo.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
#include <locale.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
#include <fcntl.h>
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);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
void SplashReconfigureNow(Splash * splash) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    SplashCenter(splash);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    if (splash->window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        XUnmapWindow(splash->display, splash->window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        XMoveResizeWindow(splash->display, splash->window,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
            splash->x, splash->y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
            splash->width, splash->height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        SplashUpdateSizeHints(splash);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    if (splash->maskRequired) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        SplashUpdateShape(splash);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        SplashRevertShape(splash);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    SplashRedrawWindow(splash);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
sendctl(Splash * splash, char code) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
//    if (splash->isVisible>0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    if (splash && splash->controlpipe[1]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        write(splash->controlpipe[1], &code, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
HandleError(Display * disp, XErrorEvent * err) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    // silently ignore non-fatal errors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    char msg[0x1000];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    char buf[0x1000];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    XGetErrorText(disp, err->error_code, msg, sizeof(msg));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    fprintf(stderr, "Xerror %s, XID %x, ser# %d\n", msg, err->resourceid,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        err->serial);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    sprintf(buf, "%d", err->request_code);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    XGetErrorDatabaseText(disp, "XRequest", buf, "Unknown", msg, sizeof(msg));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    fprintf(stderr, "Major opcode %d (%s)\n", err->request_code, msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    if (err->request_code > 128) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        fprintf(stderr, "Minor opcode %d\n", err->minor_code);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
HandleIOError(Display * display) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    // for really bad errors, we should exit the thread we're on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    SplashCleanup(SplashGetInstance());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    pthread_exit(NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
SplashInitPlatform(Splash * splash) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    int shapeVersionMajor, shapeVersionMinor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    // This setting enables the synchronous Xlib mode!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    // Don't use it == 1 in production builds!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
#if (defined DEBUG)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    _Xdebug = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    pthread_mutex_init(&splash->lock, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    // We should not ignore any errors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
    //XSetErrorHandler(HandleError);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
//    XSetIOErrorHandler(HandleIOError);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    XSetIOErrorHandler(NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    splash->display = XOpenDisplay(NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    if (!splash->display) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        splash->isVisible = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
    shapeSupported = XShapeQueryExtension(splash->display, &shapeEventBase,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            &shapeErrorBase);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    if (shapeSupported) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        XShapeQueryVersion(splash->display, &shapeVersionMajor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
                &shapeVersionMinor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    splash->screen = XDefaultScreenOfDisplay(splash->display);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    splash->visual = XDefaultVisualOfScreen(splash->screen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    switch (splash->visual->class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    case TrueColor: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
            int depth = XDefaultDepthOfScreen(splash->screen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
            splash->byteAlignment = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            splash->maskRequired = shapeSupported;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
            initFormat(&splash->screenFormat, splash->visual->red_mask,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
                    splash->visual->green_mask, splash->visual->blue_mask, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
            splash->screenFormat.byteOrder =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
                (XImageByteOrder(splash->display) == LSBFirst ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                 BYTE_ORDER_LSBFIRST : BYTE_ORDER_MSBFIRST);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
            splash->screenFormat.depthBytes = (depth + 7) / 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
            // TrueColor depth probably can't be less
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
            // than 8 bits, and it's always byte padded
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    case PseudoColor: {
422
5b2da06c1acc 6603312: Segmentation fault running java -jar SwingSet2.jar in 256 color mode
anthony
parents: 2
diff changeset
   440
            int availableColors;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
            int numColors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
            int numComponents[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
            unsigned long colorIndex[SPLASH_COLOR_MAP_SIZE];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
            XColor xColors[SPLASH_COLOR_MAP_SIZE];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
            int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
            int depth = XDefaultDepthOfScreen(splash->screen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
            int scale = 65535 / MAX_COLOR_VALUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
422
5b2da06c1acc 6603312: Segmentation fault running java -jar SwingSet2.jar in 256 color mode
anthony
parents: 2
diff changeset
   449
            availableColors = GetNumAvailableColors(splash->display, splash->screen,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                    splash->visual->map_entries);
422
5b2da06c1acc 6603312: Segmentation fault running java -jar SwingSet2.jar in 256 color mode
anthony
parents: 2
diff changeset
   451
            numColors = quantizeColors(availableColors, numComponents);
5b2da06c1acc 6603312: Segmentation fault running java -jar SwingSet2.jar in 256 color mode
anthony
parents: 2
diff changeset
   452
            if (numColors > availableColors) {
5b2da06c1acc 6603312: Segmentation fault running java -jar SwingSet2.jar in 256 color mode
anthony
parents: 2
diff changeset
   453
                // 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
   454
                // 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
   455
                XCloseDisplay(splash->display);
5b2da06c1acc 6603312: Segmentation fault running java -jar SwingSet2.jar in 256 color mode
anthony
parents: 2
diff changeset
   456
                splash->isVisible = -1;
5b2da06c1acc 6603312: Segmentation fault running java -jar SwingSet2.jar in 256 color mode
anthony
parents: 2
diff changeset
   457
                splash->display = NULL;
5b2da06c1acc 6603312: Segmentation fault running java -jar SwingSet2.jar in 256 color mode
anthony
parents: 2
diff changeset
   458
                splash->screen = NULL;
5b2da06c1acc 6603312: Segmentation fault running java -jar SwingSet2.jar in 256 color mode
anthony
parents: 2
diff changeset
   459
                splash->visual = NULL;
5b2da06c1acc 6603312: Segmentation fault running java -jar SwingSet2.jar in 256 color mode
anthony
parents: 2
diff changeset
   460
                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
   461
                return;
5b2da06c1acc 6603312: Segmentation fault running java -jar SwingSet2.jar in 256 color mode
anthony
parents: 2
diff changeset
   462
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
            splash->cmap = AllocColors(splash->display, splash->screen,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
                    numColors, colorIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
            for (i = 0; i < numColors; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                splash->colorIndex[i] = colorIndex[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
            initColorCube(numComponents, splash->colorMap, splash->dithers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                    splash->colorIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
            for (i = 0; i < numColors; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                xColors[i].pixel = colorIndex[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
                xColors[i].red = (unsigned short)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
                    QUAD_RED(splash->colorMap[colorIndex[i]]) * scale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                xColors[i].green = (unsigned short)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                    QUAD_GREEN(splash->colorMap[colorIndex[i]]) * scale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                xColors[i].blue = (unsigned short)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                    QUAD_BLUE(splash->colorMap[colorIndex[i]]) * scale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
                xColors[i].flags = DoRed | DoGreen | DoBlue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
            XStoreColors(splash->display, splash->cmap, xColors, numColors);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
            initFormat(&splash->screenFormat, 0, 0, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
            splash->screenFormat.colorIndex = splash->colorIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
            splash->screenFormat.depthBytes = (depth + 7) / 8;  // or always 8?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
            splash->screenFormat.colorMap = splash->colorMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
            splash->screenFormat.dithers = splash->dithers;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
            splash->screenFormat.numColors = numColors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
            splash->screenFormat.byteOrder = BYTE_ORDER_NATIVE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        ; /* FIXME: should probably be fixed, but javaws splash screen doesn't support other visuals either */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
SplashCleanupPlatform(Splash * splash) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
    if (splash->frames) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        for (i = 0; i < splash->frameCount; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
            if (splash->frames[i].rects) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
                free(splash->frames[i].rects);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
                splash->frames[i].rects = NULL;
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
    splash->maskRequired = shapeSupported;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
SplashDonePlatform(Splash * splash) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
    pthread_mutex_destroy(&splash->lock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
    if (splash->cmap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
        unsigned long colorIndex[SPLASH_COLOR_MAP_SIZE];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        for (i = 0; i < splash->screenFormat.numColors; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
            colorIndex[i] = splash->colorIndex[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        FreeColors(splash->display, splash->screen,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
                splash->screenFormat.numColors, colorIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
    if (splash->window)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        XDestroyWindow(splash->display, splash->window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
    if (splash->wmHints)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        XFree(splash->wmHints);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
    if (splash->cursor)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
        XFreeCursor(splash->display, splash->cursor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
    if (splash->display)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
        XCloseDisplay(splash->display);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
SplashEventLoop(Splash * splash) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
    /*      Different from win32 implementation - this loop
1178
4734cf2a22bf 6704896: FD_SET usage can cause stack corruption (sol)
anthony
parents: 422
diff changeset
   538
       uses poll timeouts instead of a timer */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
    /* we should have splash _locked_ on entry!!! */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
    int xconn = XConnectionNumber(splash->display);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
    while (1) {
1178
4734cf2a22bf 6704896: FD_SET usage can cause stack corruption (sol)
anthony
parents: 422
diff changeset
   544
        struct pollfd pfd[2];
4734cf2a22bf 6704896: FD_SET usage can cause stack corruption (sol)
anthony
parents: 422
diff changeset
   545
        int timeout = -1;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        int ctl = splash->controlpipe[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        int rc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
        int pipes_empty;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
1178
4734cf2a22bf 6704896: FD_SET usage can cause stack corruption (sol)
anthony
parents: 422
diff changeset
   550
        pfd[0].fd = xconn;
4734cf2a22bf 6704896: FD_SET usage can cause stack corruption (sol)
anthony
parents: 422
diff changeset
   551
        pfd[0].events = POLLIN | POLLPRI;
4734cf2a22bf 6704896: FD_SET usage can cause stack corruption (sol)
anthony
parents: 422
diff changeset
   552
4734cf2a22bf 6704896: FD_SET usage can cause stack corruption (sol)
anthony
parents: 422
diff changeset
   553
        pfd[1].fd = ctl;
4734cf2a22bf 6704896: FD_SET usage can cause stack corruption (sol)
anthony
parents: 422
diff changeset
   554
        pfd[1].events = POLLIN | POLLPRI;
4734cf2a22bf 6704896: FD_SET usage can cause stack corruption (sol)
anthony
parents: 422
diff changeset
   555
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
        errno = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
        if (splash->isVisible>0 && SplashIsStillLooping(splash)) {
1178
4734cf2a22bf 6704896: FD_SET usage can cause stack corruption (sol)
anthony
parents: 422
diff changeset
   558
            timeout = splash->time + splash->frames[splash->currentFrame].delay
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
                - SplashTime();
1178
4734cf2a22bf 6704896: FD_SET usage can cause stack corruption (sol)
anthony
parents: 422
diff changeset
   560
            if (timeout < 0) {
4734cf2a22bf 6704896: FD_SET usage can cause stack corruption (sol)
anthony
parents: 422
diff changeset
   561
                timeout = 0;
4734cf2a22bf 6704896: FD_SET usage can cause stack corruption (sol)
anthony
parents: 422
diff changeset
   562
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
        SplashUnlock(splash);
1178
4734cf2a22bf 6704896: FD_SET usage can cause stack corruption (sol)
anthony
parents: 422
diff changeset
   565
        rc = poll(pfd, 2, timeout);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
        SplashLock(splash);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
        if (splash->isVisible>0 && SplashTime() >= splash->time +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
                splash->frames[splash->currentFrame].delay) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
            SplashNextFrame(splash);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
            SplashUpdateShape(splash);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
            SplashRedrawWindow(splash);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
        if (rc <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
            errno = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
            continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
        pipes_empty = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
        while(!pipes_empty) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
            char buf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
            pipes_empty = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
            if (read(ctl, &buf, sizeof(buf)) > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
                pipes_empty = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
                switch (buf) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
                case SPLASHCTL_UPDATE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
                    if (splash->isVisible>0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
                        SplashRedrawWindow(splash);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
                case SPLASHCTL_RECONFIGURE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
                    if (splash->isVisible>0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
                        SplashReconfigureNow(splash);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
                case SPLASHCTL_QUIT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
            // we're not using "while(XPending)", processing one event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
            // at a time to avoid control pipe starvation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
            if (XPending(splash->display)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
                XEvent evt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
                pipes_empty = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
                XNextEvent(splash->display, &evt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
                switch (evt.type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
                    case Expose:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
                        if (splash->isVisible>0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
                            // we're doing full redraw so we just
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
                            // skip the remaining painting events in the queue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
                            while(XCheckTypedEvent(splash->display, Expose,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
                                &evt));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
                            SplashRedrawWindow(splash);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
                    /* ... */
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
/*  we can't use OverrideRedirect for the window as the window should not be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
    always-on-top, so we must set appropriate wm hints
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
    this functions sets olwm, mwm and EWMH hints for undecorated window at once
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
    It works for: mwm, openbox, wmaker, metacity, KWin (FIXME: test more wm's)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
    Should work for: fvwm2.5.x, blackbox, olwm
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
    Maybe works for: enlightenment, icewm
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
    Does not work for: twm, fvwm2.4.7
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
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
SplashRemoveDecoration(Splash * splash) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
    Atom atom_set;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
    Atom atom_list[4];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
    /* the struct below was copied from MwmUtil.h */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
    struct PROPMOTIFWMHINTS {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
    /* 32-bit property items are stored as long on the client (whether
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
     * that means 32 bits or 64).  XChangeProperty handles the conversion
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
     * to the actual 32-bit quantities sent to the server.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
        unsigned long   flags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
        unsigned long   functions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
        unsigned long   decorations;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
        long            inputMode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
        unsigned long   status;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
    mwm_hints;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
    /* WM_TAKE_FOCUS hint to avoid wm's transfer of focus to this window */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
    /* WM_DELETE_WINDOW hint to avoid closing this window with Alt-F4. See bug 6474035 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
    atom_set = XInternAtom(splash->display, "WM_PROTOCOLS", True);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
    if (atom_set != None) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
        atom_list[0] = XInternAtom(splash->display, "WM_TAKE_FOCUS", True);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
        atom_list[1] = XInternAtom(splash->display, "WM_DELETE_WINDOW", True);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
        XChangeProperty(splash->display, splash->window, atom_set, XA_ATOM, 32,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
                PropModeReplace, (unsigned char *) atom_list, 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
    }
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
    atom_set = XInternAtom(splash->display, "_MOTIF_WM_HINTS", True);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
    if (atom_set != None) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
        /* flags for decoration and functions */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
        mwm_hints.flags = (1L << 1) | (1L << 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
        mwm_hints.decorations = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
        mwm_hints.functions = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
        XChangeProperty(splash->display, splash->window, atom_set, atom_set,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
                32, PropModeReplace, (unsigned char *) &mwm_hints, 5);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
    /* olwm hints */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
    atom_set = XInternAtom(splash->display, "_OL_DECOR_DEL", True);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
    if (atom_set != None) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
        atom_list[0] = XInternAtom(splash->display, "_OL_DECOR_RESIZE", True);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
        atom_list[1] = XInternAtom(splash->display, "_OL_DECOR_HEADER", True);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
        atom_list[2] = XInternAtom(splash->display, "_OL_DECOR_PIN", True);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
        atom_list[3] = XInternAtom(splash->display, "_OL_DECOR_CLOSE", True);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
        XChangeProperty(splash->display, splash->window, atom_set, XA_ATOM, 32,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
                PropModeReplace, (unsigned char *) atom_list, 4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
    /* generic EMWH hints
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
       we do not set _NET_WM_WINDOW_TYPE to _NET_WM_WINDOW_TYPE_SPLASH
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
       hint support due to gnome making this window always-on-top
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
       so we have to set _NET_WM_STATE and _NET_WM_ALLOWED_ACTIONS correctly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
       _NET_WM_STATE: SKIP_TASKBAR and SKIP_PAGER
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
       _NET_WM_ALLOWED_ACTIONS: disable all actions */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
    atom_set = XInternAtom(splash->display, "_NET_WM_STATE", True);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
    if (atom_set != None) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
        atom_list[0] = XInternAtom(splash->display,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
                "_NET_WM_STATE_SKIP_TASKBAR", True);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
        atom_list[1] = XInternAtom(splash->display,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
                "_NET_WM_STATE_SKIP_PAGER", True);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
        XChangeProperty(splash->display, splash->window, atom_set, XA_ATOM, 32,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
                PropModeReplace, (unsigned char *) atom_list, 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
    atom_set = XInternAtom(splash->display, "_NET_WM_ALLOWED_ACTIONS", True);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
    if (atom_set != None) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
        XChangeProperty(splash->display, splash->window, atom_set, XA_ATOM, 32,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
                PropModeReplace, (unsigned char *) atom_list, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
SplashPThreadDestructor(void *arg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
    /* this will be used in case of emergency thread exit on xlib error */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
    Splash *splash = (Splash *) arg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
    if (splash) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
        SplashCleanup(splash);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
void *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
SplashScreenThread(void *param) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
    Splash *splash = (Splash *) param;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
//    pthread_key_t key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
//    pthread_key_create(&key, SplashPThreadDestructor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
//    pthread_setspecific(key, splash);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
    SplashLock(splash);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
    pipe(splash->controlpipe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
    fcntl(splash->controlpipe[0], F_SETFL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
        fcntl(splash->controlpipe[0], F_GETFL, 0) | O_NONBLOCK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
    splash->time = SplashTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
    SplashCreateWindow(splash);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
    fflush(stdout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
    if (splash->window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
        SplashRemoveDecoration(splash);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
        XStoreName(splash->display, splash->window, "Java");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
        XMapRaised(splash->display, splash->window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
        SplashUpdateShape(splash);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
        SplashRedrawWindow(splash);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
        SplashEventLoop(splash);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
    SplashUnlock(splash);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
    SplashDone(splash);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
    splash->isVisible=-1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
SplashCreateThread(Splash * splash) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
    pthread_t thr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
    pthread_attr_t attr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
    int rc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
    pthread_attr_init(&attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
    rc = pthread_create(&thr, &attr, SplashScreenThread, (void *) splash);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
SplashLock(Splash * splash) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
    pthread_mutex_lock(&splash->lock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
SplashUnlock(Splash * splash) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
    pthread_mutex_unlock(&splash->lock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
SplashClosePlatform(Splash * splash) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
    sendctl(splash, SPLASHCTL_QUIT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
SplashUpdate(Splash * splash) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
    sendctl(splash, SPLASHCTL_UPDATE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
SplashReconfigure(Splash * splash) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
    sendctl(splash, SPLASHCTL_RECONFIGURE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
}