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