src/video/x11/SDL_x11window.c
author Bob Pendleton <bob@pendleton.com>
Thu, 15 Jan 2009 21:35:42 +0000
changeset 3044 b36579172f27
parent 3009 546c022a9ae5
child 3052 b7197d7e8566
permissions -rw-r--r--
Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     1
/*
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     2
    SDL - Simple DirectMedia Layer
2859
99210400e8b9 Updated copyright date
Sam Lantinga <slouken@libsdl.org>
parents: 2725
diff changeset
     3
    Copyright (C) 1997-2009 Sam Lantinga
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     4
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     5
    This library is free software; you can redistribute it and/or
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     6
    modify it under the terms of the GNU Lesser General Public
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     7
    License as published by the Free Software Foundation; either
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     8
    version 2.1 of the License, or (at your option) any later version.
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     9
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    10
    This library is distributed in the hope that it will be useful,
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    13
    Lesser General Public License for more details.
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    14
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    15
    You should have received a copy of the GNU Lesser General Public
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    16
    License along with this library; if not, write to the Free Software
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    18
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    19
    Sam Lantinga
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    20
    slouken@libsdl.org
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    21
*/
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    22
#include "SDL_config.h"
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    23
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    24
#include "SDL_syswm.h"
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    25
#include "../SDL_sysvideo.h"
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    26
#include "../../events/SDL_keyboard_c.h"
2940
b93965a16fe0 Fixed X11 mouse motion/button events - it's not actually safe to cast mouse events to device events.
Sam Lantinga <slouken@libsdl.org>
parents: 2931
diff changeset
    27
#include "../../events/SDL_mouse_c.h"
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    28
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    29
#include "SDL_x11video.h"
2940
b93965a16fe0 Fixed X11 mouse motion/button events - it's not actually safe to cast mouse events to device events.
Sam Lantinga <slouken@libsdl.org>
parents: 2931
diff changeset
    30
#include "SDL_x11mouse.h"
3009
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
    31
#include "SDL_x11gamma.h"
2185
2032348afed1 This code adds support for DirectColor visuals to SDL 1.3. The support uses part of the Xmu library. To ensure that the library is
Bob Pendleton <bob@pendleton.com>
parents: 2143
diff changeset
    32
#include "../Xext/extensions/StdCmap.h"
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    33
2931
e705adf6f3dc Date: Mon, 29 Dec 2008 23:29:52 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2876
diff changeset
    34
static void
e705adf6f3dc Date: Mon, 29 Dec 2008 23:29:52 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2876
diff changeset
    35
X11_GetDisplaySize(_THIS, SDL_Window * window, int *w, int *h)
e705adf6f3dc Date: Mon, 29 Dec 2008 23:29:52 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2876
diff changeset
    36
{
e705adf6f3dc Date: Mon, 29 Dec 2008 23:29:52 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2876
diff changeset
    37
    SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
e705adf6f3dc Date: Mon, 29 Dec 2008 23:29:52 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2876
diff changeset
    38
    SDL_DisplayData *displaydata =
e705adf6f3dc Date: Mon, 29 Dec 2008 23:29:52 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2876
diff changeset
    39
        (SDL_DisplayData *) SDL_GetDisplayFromWindow(window)->driverdata;
e705adf6f3dc Date: Mon, 29 Dec 2008 23:29:52 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2876
diff changeset
    40
    XWindowAttributes attr;
e705adf6f3dc Date: Mon, 29 Dec 2008 23:29:52 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2876
diff changeset
    41
e705adf6f3dc Date: Mon, 29 Dec 2008 23:29:52 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2876
diff changeset
    42
    XGetWindowAttributes(data->display, RootWindow(data->display,
e705adf6f3dc Date: Mon, 29 Dec 2008 23:29:52 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2876
diff changeset
    43
                                                   displaydata->screen),
e705adf6f3dc Date: Mon, 29 Dec 2008 23:29:52 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2876
diff changeset
    44
                         &attr);
e705adf6f3dc Date: Mon, 29 Dec 2008 23:29:52 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2876
diff changeset
    45
    if (w) {
e705adf6f3dc Date: Mon, 29 Dec 2008 23:29:52 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2876
diff changeset
    46
        *w = attr.width;
e705adf6f3dc Date: Mon, 29 Dec 2008 23:29:52 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2876
diff changeset
    47
    }
e705adf6f3dc Date: Mon, 29 Dec 2008 23:29:52 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2876
diff changeset
    48
    if (h) {
e705adf6f3dc Date: Mon, 29 Dec 2008 23:29:52 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2876
diff changeset
    49
        *h = attr.height;
e705adf6f3dc Date: Mon, 29 Dec 2008 23:29:52 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2876
diff changeset
    50
    }
e705adf6f3dc Date: Mon, 29 Dec 2008 23:29:52 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2876
diff changeset
    51
}
e705adf6f3dc Date: Mon, 29 Dec 2008 23:29:52 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2876
diff changeset
    52
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    53
static int
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    54
SetupWindowData(_THIS, SDL_Window * window, Window w, BOOL created)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    55
{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    56
    SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    57
    SDL_WindowData *data;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    58
    int numwindows = videodata->numwindows;
2324
3202e4826c57 more valgrind errors fixed. Plus I ran make indent which changed a few files.
Bob Pendleton <bob@pendleton.com>
parents: 2323
diff changeset
    59
    int windowlistlength = videodata->windowlistlength;
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    60
    SDL_WindowData **windowlist = videodata->windowlist;
2323
4ac07ae446d3 Fixed many valgrind errors. But, I broke testdyngl.
Bob Pendleton <bob@pendleton.com>
parents: 2322
diff changeset
    61
    int index;
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    62
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    63
    /* Allocate the window data */
2323
4ac07ae446d3 Fixed many valgrind errors. But, I broke testdyngl.
Bob Pendleton <bob@pendleton.com>
parents: 2322
diff changeset
    64
    data = (SDL_WindowData *) SDL_calloc(1, sizeof(*data));
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    65
    if (!data) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    66
        SDL_OutOfMemory();
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    67
        return -1;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    68
    }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    69
    data->windowID = window->id;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    70
    data->window = w;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    71
#ifdef X_HAVE_UTF8_STRING
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    72
    if (SDL_X11_HAVE_UTF8) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    73
        data->ic =
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    74
            pXCreateIC(videodata->im, XNClientWindow, w, XNFocusWindow, w,
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    75
                       XNInputStyle, XIMPreeditNothing | XIMStatusNothing,
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    76
                       XNResourceName, videodata->classname, XNResourceClass,
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    77
                       videodata->classname, NULL);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    78
    }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    79
#endif
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    80
    data->created = created;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    81
    data->videodata = videodata;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    82
2323
4ac07ae446d3 Fixed many valgrind errors. But, I broke testdyngl.
Bob Pendleton <bob@pendleton.com>
parents: 2322
diff changeset
    83
    /* Associate the data with the window */
2324
3202e4826c57 more valgrind errors fixed. Plus I ran make indent which changed a few files.
Bob Pendleton <bob@pendleton.com>
parents: 2323
diff changeset
    84
3202e4826c57 more valgrind errors fixed. Plus I ran make indent which changed a few files.
Bob Pendleton <bob@pendleton.com>
parents: 2323
diff changeset
    85
    if (numwindows < windowlistlength) {
3202e4826c57 more valgrind errors fixed. Plus I ran make indent which changed a few files.
Bob Pendleton <bob@pendleton.com>
parents: 2323
diff changeset
    86
        windowlist[numwindows] = data;
3202e4826c57 more valgrind errors fixed. Plus I ran make indent which changed a few files.
Bob Pendleton <bob@pendleton.com>
parents: 2323
diff changeset
    87
        videodata->numwindows++;
3202e4826c57 more valgrind errors fixed. Plus I ran make indent which changed a few files.
Bob Pendleton <bob@pendleton.com>
parents: 2323
diff changeset
    88
    } else {
3202e4826c57 more valgrind errors fixed. Plus I ran make indent which changed a few files.
Bob Pendleton <bob@pendleton.com>
parents: 2323
diff changeset
    89
        windowlist =
3202e4826c57 more valgrind errors fixed. Plus I ran make indent which changed a few files.
Bob Pendleton <bob@pendleton.com>
parents: 2323
diff changeset
    90
            (SDL_WindowData **) SDL_realloc(windowlist,
3202e4826c57 more valgrind errors fixed. Plus I ran make indent which changed a few files.
Bob Pendleton <bob@pendleton.com>
parents: 2323
diff changeset
    91
                                            (numwindows +
3202e4826c57 more valgrind errors fixed. Plus I ran make indent which changed a few files.
Bob Pendleton <bob@pendleton.com>
parents: 2323
diff changeset
    92
                                             1) * sizeof(*windowlist));
3202e4826c57 more valgrind errors fixed. Plus I ran make indent which changed a few files.
Bob Pendleton <bob@pendleton.com>
parents: 2323
diff changeset
    93
        if (!windowlist) {
3202e4826c57 more valgrind errors fixed. Plus I ran make indent which changed a few files.
Bob Pendleton <bob@pendleton.com>
parents: 2323
diff changeset
    94
            SDL_OutOfMemory();
3202e4826c57 more valgrind errors fixed. Plus I ran make indent which changed a few files.
Bob Pendleton <bob@pendleton.com>
parents: 2323
diff changeset
    95
            SDL_free(data);
3202e4826c57 more valgrind errors fixed. Plus I ran make indent which changed a few files.
Bob Pendleton <bob@pendleton.com>
parents: 2323
diff changeset
    96
            return -1;
2323
4ac07ae446d3 Fixed many valgrind errors. But, I broke testdyngl.
Bob Pendleton <bob@pendleton.com>
parents: 2322
diff changeset
    97
        }
2324
3202e4826c57 more valgrind errors fixed. Plus I ran make indent which changed a few files.
Bob Pendleton <bob@pendleton.com>
parents: 2323
diff changeset
    98
        windowlist[numwindows] = data;
3202e4826c57 more valgrind errors fixed. Plus I ran make indent which changed a few files.
Bob Pendleton <bob@pendleton.com>
parents: 2323
diff changeset
    99
        videodata->numwindows++;
3202e4826c57 more valgrind errors fixed. Plus I ran make indent which changed a few files.
Bob Pendleton <bob@pendleton.com>
parents: 2323
diff changeset
   100
        videodata->windowlistlength++;
3202e4826c57 more valgrind errors fixed. Plus I ran make indent which changed a few files.
Bob Pendleton <bob@pendleton.com>
parents: 2323
diff changeset
   101
        videodata->windowlist = windowlist;
2323
4ac07ae446d3 Fixed many valgrind errors. But, I broke testdyngl.
Bob Pendleton <bob@pendleton.com>
parents: 2322
diff changeset
   102
    }
4ac07ae446d3 Fixed many valgrind errors. But, I broke testdyngl.
Bob Pendleton <bob@pendleton.com>
parents: 2322
diff changeset
   103
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   104
    /* Fill in the SDL window with the window data */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   105
    {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   106
        XWindowAttributes attrib;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   107
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   108
        XGetWindowAttributes(data->videodata->display, w, &attrib);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   109
        window->x = attrib.x;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   110
        window->y = attrib.y;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   111
        window->w = attrib.width;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   112
        window->h = attrib.height;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   113
        if (attrib.map_state != IsUnmapped) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   114
            window->flags |= SDL_WINDOW_SHOWN;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   115
        } else {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   116
            window->flags &= ~SDL_WINDOW_SHOWN;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   117
        }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   118
    }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   119
    /* FIXME: How can I tell?
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   120
       {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   121
       DWORD style = GetWindowLong(hwnd, GWL_STYLE);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   122
       if (style & WS_VISIBLE) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   123
       if (style & (WS_BORDER | WS_THICKFRAME)) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   124
       window->flags &= ~SDL_WINDOW_BORDERLESS;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   125
       } else {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   126
       window->flags |= SDL_WINDOW_BORDERLESS;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   127
       }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   128
       if (style & WS_THICKFRAME) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   129
       window->flags |= SDL_WINDOW_RESIZABLE;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   130
       } else {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   131
       window->flags &= ~SDL_WINDOW_RESIZABLE;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   132
       }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   133
       if (style & WS_MAXIMIZE) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   134
       window->flags |= SDL_WINDOW_MAXIMIZED;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   135
       } else {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   136
       window->flags &= ~SDL_WINDOW_MAXIMIZED;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   137
       }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   138
       if (style & WS_MINIMIZE) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   139
       window->flags |= SDL_WINDOW_MINIMIZED;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   140
       } else {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   141
       window->flags &= ~SDL_WINDOW_MINIMIZED;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   142
       }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   143
       }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   144
       if (GetFocus() == hwnd) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   145
       int index = data->videodata->keyboard;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   146
       window->flags |= SDL_WINDOW_INPUT_FOCUS;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   147
       SDL_SetKeyboardFocus(index, data->windowID);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   148
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   149
       if (window->flags & SDL_WINDOW_INPUT_GRABBED) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   150
       RECT rect;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   151
       GetClientRect(hwnd, &rect);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   152
       ClientToScreen(hwnd, (LPPOINT) & rect);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   153
       ClientToScreen(hwnd, (LPPOINT) & rect + 1);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   154
       ClipCursor(&rect);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   155
       }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   156
       }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   157
     */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   158
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   159
    /* All done! */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   160
    window->driverdata = data;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   161
    return 0;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   162
}
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   163
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   164
int
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   165
X11_CreateWindow(_THIS, SDL_Window * window)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   166
{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   167
    SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   168
    SDL_DisplayData *displaydata =
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1951
diff changeset
   169
        (SDL_DisplayData *) SDL_GetDisplayFromWindow(window)->driverdata;
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   170
    Visual *visual;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   171
    int depth;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   172
    XSetWindowAttributes xattr;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   173
    int x, y;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   174
    Window w;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   175
    XSizeHints *sizehints;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   176
    XWMHints *wmhints;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   177
    XClassHint *classhints;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   178
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   179
#if SDL_VIDEO_DRIVER_X11_XINERAMA
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   180
/* FIXME
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   181
    if ( use_xinerama ) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   182
        x = xinerama_info.x_org;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   183
        y = xinerama_info.y_org;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   184
    }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   185
*/
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   186
#endif
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1951
diff changeset
   187
#ifdef SDL_VIDEO_OPENGL_GLX
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   188
    if (window->flags & SDL_WINDOW_OPENGL) {
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1951
diff changeset
   189
        XVisualInfo *vinfo;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1951
diff changeset
   190
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1951
diff changeset
   191
        if (X11_GL_Initialize(_this) < 0) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1951
diff changeset
   192
            return -1;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1951
diff changeset
   193
        }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1951
diff changeset
   194
        vinfo = X11_GL_GetVisual(_this, data->display, displaydata->screen);
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1951
diff changeset
   195
        if (!vinfo) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1951
diff changeset
   196
            return -1;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1951
diff changeset
   197
        }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1951
diff changeset
   198
        visual = vinfo->visual;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1951
diff changeset
   199
        depth = vinfo->depth;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1951
diff changeset
   200
        XFree(vinfo);
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1951
diff changeset
   201
    } else
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1951
diff changeset
   202
#endif
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1951
diff changeset
   203
    {
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   204
        visual = displaydata->visual;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   205
        depth = displaydata->depth;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   206
    }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   207
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   208
    if (window->flags & SDL_WINDOW_FULLSCREEN) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   209
        xattr.override_redirect = True;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   210
    } else {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   211
        xattr.override_redirect = False;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   212
    }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   213
    xattr.background_pixel = 0;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   214
    xattr.border_pixel = 0;
2214
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
   215
2945
e38423786728 Fixed DirectColor visual window creation problem
Sam Lantinga <slouken@libsdl.org>
parents: 2942
diff changeset
   216
    if (visual->class == PseudoColor) {
3044
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
   217
        printf("asking for PseudoColor\n");
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
   218
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
   219
        Status status;
2214
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
   220
        XStandardColormap cmap;
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
   221
        XColor *colorcells;
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
   222
        Colormap colormap;
3044
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
   223
	Sint32 pix;
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
   224
        Sint32 ncolors;
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
   225
        Sint32 nbits;
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
   226
        Sint32 rmax, gmax, bmax;
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
   227
	Sint32 rwidth, gwidth, bwidth;
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
   228
        Sint32 rmask, gmask, bmask;
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
   229
        Sint32 rshift, gshift, bshift;
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
   230
	Sint32 r, g, b;
2185
2032348afed1 This code adds support for DirectColor visuals to SDL 1.3. The support uses part of the Xmu library. To ensure that the library is
Bob Pendleton <bob@pendleton.com>
parents: 2143
diff changeset
   231
3044
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
   232
        /* Is the colormap we need already registered in SDL? */
2214
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
   233
        if (colormap =
3044
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
   234
            X11_LookupColormap(data->display,
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
   235
                               displaydata->screen, visual->visualid)) {
2214
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
   236
            xattr.colormap = colormap;
3044
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
   237
/*             printf("found existing colormap\n"); */
2214
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
   238
        } else {
3044
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
   239
            /* The colormap is not known to SDL so we will create it */
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
   240
            colormap = XCreateColormap(data->display,
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
   241
                                       RootWindow(data->display,
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
   242
                                                  displaydata->screen),
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
   243
                                       visual, AllocAll);
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
   244
/*             printf("colormap = %x\n", colormap); */
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
   245
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
   246
            /* If we can't create a colormap, then we must die */
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
   247
            if (!colormap) {
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
   248
                SDL_SetError
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
   249
                    ("Couldn't create window: Could not create writable colormap");
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
   250
                return -1;
2185
2032348afed1 This code adds support for DirectColor visuals to SDL 1.3. The support uses part of the Xmu library. To ensure that the library is
Bob Pendleton <bob@pendleton.com>
parents: 2143
diff changeset
   251
            }
2213
59a667370c57 make indent
Bob Pendleton <bob@pendleton.com>
parents: 2211
diff changeset
   252
3044
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
   253
            /* OK, we got a colormap, now fill it in as best as we can */
2214
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
   254
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
   255
            colorcells = SDL_malloc(visual->map_entries * sizeof(XColor));
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
   256
            if (NULL == colorcells) {
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
   257
                SDL_SetError("out of memory in X11_CreateWindow");
2185
2032348afed1 This code adds support for DirectColor visuals to SDL 1.3. The support uses part of the Xmu library. To ensure that the library is
Bob Pendleton <bob@pendleton.com>
parents: 2143
diff changeset
   258
                return -1;
2032348afed1 This code adds support for DirectColor visuals to SDL 1.3. The support uses part of the Xmu library. To ensure that the library is
Bob Pendleton <bob@pendleton.com>
parents: 2143
diff changeset
   259
            }
3044
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
   260
2214
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
   261
            ncolors = visual->map_entries;
3044
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
   262
	    nbits = visual->bits_per_rgb;
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
   263
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
   264
/* 	    printf("ncolors = %d nbits = %d\n", ncolors, nbits); */
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
   265
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
   266
	    /* what if ncolors != (1 << nbits)? That can happen on a
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
   267
	       true PseudoColor display.  I'm assuming that we will
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
   268
	       always have ncolors == (1 << nbits)*/
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
   269
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
   270
	    /* I'm making a lot of assumptions here. */
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
   271
	    
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
   272
	    /* Compute the width of each field. If there is one extra
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
   273
	       bit, give it to green. If there are two extra bits give
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
   274
	       them to red and greed.  We can get extra bits when the
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
   275
	       number of bits per pixel is not a multiple of 3. For
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
   276
	       example when we have 16 bits per pixel and need a 5/6/5
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
   277
	       layout for the RGB fields */
2214
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
   278
3044
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
   279
	    rwidth = (nbits / 3) + (((nbits % 3) == 2) ? 1 : 0);
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
   280
	    gwidth = (nbits / 3) + (((nbits % 3) >= 1) ? 1 : 0);
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
   281
	    bwidth = (nbits / 3);
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
   282
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
   283
            rshift = gwidth + bwidth;
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
   284
            gshift = bwidth;
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
   285
            bshift = 0;
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
   286
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
   287
            rmax = 1 << rwidth;
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
   288
            gmax = 1 << gwidth;
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
   289
            bmax = 1 << bwidth;
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
   290
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
   291
            rmask = rmax - 1;
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
   292
            gmask = gmax - 1;
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
   293
            bmask = bmax - 1;
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
   294
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
   295
/*             printf("red   mask = %4x shift = %4d width = %d\n", rmask, rshift, rwidth); */
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
   296
/*             printf("green mask = %4x shift = %4d width = %d\n", gmask, gshift, gwidth); */
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
   297
/*             printf("blue  mask = %4x shift = %4d width = %d\n", bmask, bshift, bwidth); */
2214
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
   298
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
   299
            /* build the color table pixel values */
3044
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
   300
	    pix = 0;
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
   301
	    for (r = 0; r < rmax; r++) {
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
   302
	      for (g = 0; g < gmax; g++) {
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
   303
		for (b = 0; b < bmax; b++) {
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
   304
		  colorcells[pix].pixel = (r << rshift) | (g << gshift) | (b << bshift);
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
   305
		  colorcells[pix].red   = (0xffff * r) / rmask;
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
   306
		  colorcells[pix].green = (0xffff * g) / gmask;
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
   307
		  colorcells[pix].blue  = (0xffff * b) / bmask;
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
   308
/* 		  printf("%4x:%4x [%4x %4x %4x]\n",  */
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
   309
/* 			 pix,  */
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
   310
/* 			 colorcells[pix].pixel, */
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
   311
/* 			 colorcells[pix].red, */
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
   312
/* 			 colorcells[pix].green, */
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
   313
/* 			 colorcells[pix].blue); */
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
   314
		  pix++;
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
   315
		}
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
   316
	      }
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
   317
	    }
2214
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
   318
3044
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
   319
/*             status = */
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
   320
/*                 XStoreColors(data->display, colormap, colorcells, ncolors); */
2214
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
   321
e7164a4dac62 Added gamma table support to X11. Also now supports DirectColor visuals.
Bob Pendleton <bob@pendleton.com>
parents: 2213
diff changeset
   322
            xattr.colormap = colormap;
3044
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
   323
            X11_TrackColormap(data->display, displaydata->screen,
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
   324
                              colormap, visual, NULL);
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
   325
3009
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   326
            SDL_free(colorcells);
2185
2032348afed1 This code adds support for DirectColor visuals to SDL 1.3. The support uses part of the Xmu library. To ensure that the library is
Bob Pendleton <bob@pendleton.com>
parents: 2143
diff changeset
   327
        }
2945
e38423786728 Fixed DirectColor visual window creation problem
Sam Lantinga <slouken@libsdl.org>
parents: 2942
diff changeset
   328
    } else if (visual->class == DirectColor) {
3009
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   329
        Status status;
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   330
        XStandardColormap cmap;
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   331
        XColor *colorcells;
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   332
        Colormap colormap;
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   333
        int i;
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   334
        int ncolors;
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   335
        int rmax, gmax, bmax;
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   336
        int rmask, gmask, bmask;
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   337
        int rshift, gshift, bshift;
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   338
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   339
        /* Is the colormap we need already registered in SDL? */
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   340
        if (colormap =
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   341
            X11_LookupColormap(data->display,
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   342
                               displaydata->screen, visual->visualid)) {
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   343
            xattr.colormap = colormap;
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   344
/*             printf("found existing colormap\n"); */
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   345
        } else {
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   346
            /* The colormap is not known to SDL so we will create it */
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   347
            colormap = XCreateColormap(data->display,
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   348
                                       RootWindow(data->display,
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   349
                                                  displaydata->screen),
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   350
                                       visual, AllocAll);
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   351
/*             printf("colormap = %x\n", colormap); */
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   352
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   353
            /* If we can't create a colormap, then we must die */
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   354
            if (!colormap) {
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   355
                SDL_SetError
3044
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 3009
diff changeset
   356
                    ("Couldn't create window: Could not create writable colormap");
3009
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   357
                return -1;
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   358
            }
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   359
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   360
            /* OK, we got a colormap, now fill it in as best as we can */
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   361
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   362
            colorcells = SDL_malloc(visual->map_entries * sizeof(XColor));
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   363
            if (NULL == colorcells) {
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   364
                SDL_SetError("out of memory in X11_CreateWindow");
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   365
                return -1;
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   366
            }
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   367
            ncolors = visual->map_entries;
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   368
            rmax = 0xffff;
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   369
            gmax = 0xffff;
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   370
            bmax = 0xffff;
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   371
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   372
            rshift = 0;
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   373
            rmask = visual->red_mask;
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   374
            while (0 == (rmask & 1)) {
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   375
                rshift++;
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   376
                rmask >>= 1;
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   377
            }
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   378
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   379
/*             printf("rmask = %4x rshift = %4d\n", rmask, rshift); */
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   380
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   381
            gshift = 0;
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   382
            gmask = visual->green_mask;
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   383
            while (0 == (gmask & 1)) {
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   384
                gshift++;
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   385
                gmask >>= 1;
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   386
            }
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   387
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   388
/*             printf("gmask = %4x gshift = %4d\n", gmask, gshift); */
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   389
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   390
            bshift = 0;
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   391
            bmask = visual->blue_mask;
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   392
            while (0 == (bmask & 1)) {
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   393
                bshift++;
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   394
                bmask >>= 1;
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   395
            }
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   396
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   397
/*             printf("bmask = %4x bshift = %4d\n", bmask, bshift); */
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   398
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   399
            /* build the color table pixel values */
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   400
            for (i = 0; i < ncolors; i++) {
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   401
                Uint32 red = (rmax * i) / (ncolors - 1);
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   402
                Uint32 green = (gmax * i) / (ncolors - 1);
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   403
                Uint32 blue = (bmax * i) / (ncolors - 1);
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   404
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   405
                Uint32 rbits = (rmask * i) / (ncolors - 1);
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   406
                Uint32 gbits = (gmask * i) / (ncolors - 1);
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   407
                Uint32 bbits = (bmask * i) / (ncolors - 1);
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   408
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   409
                Uint32 pix =
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   410
                    (rbits << rshift) | (gbits << gshift) | (bbits << bshift);
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   411
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   412
                colorcells[i].pixel = pix;
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   413
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   414
                colorcells[i].red = red;
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   415
                colorcells[i].green = green;
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   416
                colorcells[i].blue = blue;
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   417
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   418
                colorcells[i].flags = DoRed | DoGreen | DoBlue;
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   419
/* 		printf("%2d:%4x [%4x %4x %4x]\n", i, pix, red, green, blue); */
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   420
            }
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   421
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   422
            status =
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   423
                XStoreColors(data->display, colormap, colorcells, ncolors);
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   424
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   425
            xattr.colormap = colormap;
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   426
            X11_TrackColormap(data->display, displaydata->screen,
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   427
                              colormap, visual, colorcells);
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   428
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   429
            SDL_free(colorcells);
546c022a9ae5 Changed and hopefully fixed support for DirectColor with support for gammaramps.
Bob Pendleton <bob@pendleton.com>
parents: 2990
diff changeset
   430
        }
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   431
    } else {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   432
        xattr.colormap =
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   433
            XCreateColormap(data->display,
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   434
                            RootWindow(data->display, displaydata->screen),
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   435
                            visual, AllocNone);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   436
    }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   437
2876
Sam Lantinga <slouken@libsdl.org>
parents: 2875
diff changeset
   438
    if ((window->flags & SDL_WINDOW_FULLSCREEN)
Sam Lantinga <slouken@libsdl.org>
parents: 2875
diff changeset
   439
        || window->x == SDL_WINDOWPOS_CENTERED) {
2931
e705adf6f3dc Date: Mon, 29 Dec 2008 23:29:52 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2876
diff changeset
   440
        X11_GetDisplaySize(_this, window, &x, NULL);
e705adf6f3dc Date: Mon, 29 Dec 2008 23:29:52 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2876
diff changeset
   441
        x = (x - window->w) / 2;
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   442
    } else if (window->x == SDL_WINDOWPOS_UNDEFINED) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   443
        x = 0;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   444
    } else {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   445
        x = window->x;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   446
    }
2876
Sam Lantinga <slouken@libsdl.org>
parents: 2875
diff changeset
   447
    if ((window->flags & SDL_WINDOW_FULLSCREEN)
Sam Lantinga <slouken@libsdl.org>
parents: 2875
diff changeset
   448
        || window->y == SDL_WINDOWPOS_CENTERED) {
2931
e705adf6f3dc Date: Mon, 29 Dec 2008 23:29:52 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2876
diff changeset
   449
        X11_GetDisplaySize(_this, window, NULL, &y);
e705adf6f3dc Date: Mon, 29 Dec 2008 23:29:52 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2876
diff changeset
   450
        y = (y - window->h) / 2;
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   451
    } else if (window->y == SDL_WINDOWPOS_UNDEFINED) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   452
        y = 0;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   453
    } else {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   454
        y = window->y;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   455
    }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   456
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   457
    w = XCreateWindow(data->display,
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   458
                      RootWindow(data->display, displaydata->screen), x, y,
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   459
                      window->w, window->h, 0, depth, InputOutput, visual,
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   460
                      (CWOverrideRedirect | CWBackPixel | CWBorderPixel |
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   461
                       CWColormap), &xattr);
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1951
diff changeset
   462
    if (!w) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1951
diff changeset
   463
#ifdef SDL_VIDEO_OPENGL_GLX
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1951
diff changeset
   464
        if (window->flags & SDL_WINDOW_OPENGL) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1951
diff changeset
   465
            X11_GL_Shutdown(_this);
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1951
diff changeset
   466
        }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1951
diff changeset
   467
#endif
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1951
diff changeset
   468
        SDL_SetError("Couldn't create window");
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1951
diff changeset
   469
        return -1;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1951
diff changeset
   470
    }
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   471
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   472
    sizehints = XAllocSizeHints();
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   473
    if (sizehints) {
2876
Sam Lantinga <slouken@libsdl.org>
parents: 2875
diff changeset
   474
        if ((window->flags & SDL_WINDOW_RESIZABLE)
Sam Lantinga <slouken@libsdl.org>
parents: 2875
diff changeset
   475
            && !(window->flags & SDL_WINDOW_FULLSCREEN)) {
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   476
            sizehints->min_width = 32;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   477
            sizehints->min_height = 32;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   478
            sizehints->max_height = 4096;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   479
            sizehints->max_width = 4096;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   480
        } else {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   481
            sizehints->min_width = sizehints->max_width = window->w;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   482
            sizehints->min_height = sizehints->max_height = window->h;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   483
        }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   484
        sizehints->flags = PMaxSize | PMinSize;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   485
        if (!(window->flags & SDL_WINDOW_FULLSCREEN)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   486
            && window->x != SDL_WINDOWPOS_UNDEFINED
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   487
            && window->y != SDL_WINDOWPOS_UNDEFINED) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   488
            sizehints->x = x;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   489
            sizehints->y = y;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   490
            sizehints->flags |= USPosition;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   491
        }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   492
        XSetWMNormalHints(data->display, w, sizehints);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   493
        XFree(sizehints);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   494
    }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   495
2876
Sam Lantinga <slouken@libsdl.org>
parents: 2875
diff changeset
   496
    if (window->flags & (SDL_WINDOW_BORDERLESS | SDL_WINDOW_FULLSCREEN)) {
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   497
        SDL_bool set;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   498
        Atom WM_HINTS;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   499
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   500
        /* We haven't modified the window manager hints yet */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   501
        set = SDL_FALSE;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   502
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   503
        /* First try to set MWM hints */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   504
        WM_HINTS = XInternAtom(data->display, "_MOTIF_WM_HINTS", True);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   505
        if (WM_HINTS != None) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   506
            /* Hints used by Motif compliant window managers */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   507
            struct
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   508
            {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   509
                unsigned long flags;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   510
                unsigned long functions;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   511
                unsigned long decorations;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   512
                long input_mode;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   513
                unsigned long status;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   514
            } MWMHints = {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   515
            (1L << 1), 0, 0, 0, 0};
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   516
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   517
            XChangeProperty(data->display, w, WM_HINTS, WM_HINTS, 32,
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   518
                            PropModeReplace, (unsigned char *) &MWMHints,
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   519
                            sizeof(MWMHints) / sizeof(long));
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   520
            set = SDL_TRUE;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   521
        }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   522
        /* Now try to set KWM hints */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   523
        WM_HINTS = XInternAtom(data->display, "KWM_WIN_DECORATION", True);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   524
        if (WM_HINTS != None) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   525
            long KWMHints = 0;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   526
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   527
            XChangeProperty(data->display, w,
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   528
                            WM_HINTS, WM_HINTS, 32,
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   529
                            PropModeReplace,
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   530
                            (unsigned char *) &KWMHints,
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   531
                            sizeof(KWMHints) / sizeof(long));
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   532
            set = SDL_TRUE;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   533
        }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   534
        /* Now try to set GNOME hints */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   535
        WM_HINTS = XInternAtom(data->display, "_WIN_HINTS", True);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   536
        if (WM_HINTS != None) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   537
            long GNOMEHints = 0;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   538
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   539
            XChangeProperty(data->display, w,
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   540
                            WM_HINTS, WM_HINTS, 32,
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   541
                            PropModeReplace,
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   542
                            (unsigned char *) &GNOMEHints,
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   543
                            sizeof(GNOMEHints) / sizeof(long));
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   544
            set = SDL_TRUE;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   545
        }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   546
        /* Finally set the transient hints if necessary */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   547
        if (!set) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   548
            XSetTransientForHint(data->display, w,
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   549
                                 RootWindow(data->display,
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   550
                                            displaydata->screen));
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   551
        }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   552
    } else {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   553
        SDL_bool set;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   554
        Atom WM_HINTS;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   555
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   556
        /* We haven't modified the window manager hints yet */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   557
        set = SDL_FALSE;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   558
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   559
        /* First try to unset MWM hints */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   560
        WM_HINTS = XInternAtom(data->display, "_MOTIF_WM_HINTS", True);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   561
        if (WM_HINTS != None) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   562
            XDeleteProperty(data->display, w, WM_HINTS);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   563
            set = SDL_TRUE;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   564
        }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   565
        /* Now try to unset KWM hints */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   566
        WM_HINTS = XInternAtom(data->display, "KWM_WIN_DECORATION", True);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   567
        if (WM_HINTS != None) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   568
            XDeleteProperty(data->display, w, WM_HINTS);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   569
            set = SDL_TRUE;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   570
        }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   571
        /* Now try to unset GNOME hints */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   572
        WM_HINTS = XInternAtom(data->display, "_WIN_HINTS", True);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   573
        if (WM_HINTS != None) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   574
            XDeleteProperty(data->display, w, WM_HINTS);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   575
            set = SDL_TRUE;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   576
        }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   577
        /* Finally unset the transient hints if necessary */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   578
        if (!set) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   579
            /* NOTE: Does this work? */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   580
            XSetTransientForHint(data->display, w, None);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   581
        }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   582
    }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   583
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   584
    /* Tell KDE to keep fullscreen windows on top */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   585
    if (window->flags & SDL_WINDOW_FULLSCREEN) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   586
        XEvent ev;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   587
        long mask;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   588
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   589
        SDL_zero(ev);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   590
        ev.xclient.type = ClientMessage;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   591
        ev.xclient.window = RootWindow(data->display, displaydata->screen);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   592
        ev.xclient.message_type =
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   593
            XInternAtom(data->display, "KWM_KEEP_ON_TOP", False);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   594
        ev.xclient.format = 32;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   595
        ev.xclient.data.l[0] = w;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   596
        ev.xclient.data.l[1] = CurrentTime;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   597
        XSendEvent(data->display,
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   598
                   RootWindow(data->display, displaydata->screen), False,
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   599
                   SubstructureRedirectMask, &ev);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   600
    }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   601
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   602
    /* Set the input hints so we get keyboard input */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   603
    wmhints = XAllocWMHints();
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   604
    if (wmhints) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   605
        wmhints->input = True;
1956
ba0d62354872 Simplified driver window creation code.
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   606
        wmhints->flags = InputHint;
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   607
        XSetWMHints(data->display, w, wmhints);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   608
        XFree(wmhints);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   609
    }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   610
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   611
    /* Set the class hints so we can get an icon (AfterStep) */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   612
    classhints = XAllocClassHint();
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   613
    if (classhints != NULL) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   614
        classhints->res_name = data->classname;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   615
        classhints->res_class = data->classname;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   616
        XSetClassHint(data->display, w, classhints);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   617
        XFree(classhints);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   618
    }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   619
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   620
    /* Allow the window to be deleted by the window manager */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   621
    XSetWMProtocols(data->display, w, &data->WM_DELETE_WINDOW, 1);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   622
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   623
    if (SetupWindowData(_this, window, w, SDL_TRUE) < 0) {
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1951
diff changeset
   624
#ifdef SDL_VIDEO_OPENGL_GLX
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1951
diff changeset
   625
        if (window->flags & SDL_WINDOW_OPENGL) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1951
diff changeset
   626
            X11_GL_Shutdown(_this);
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1951
diff changeset
   627
        }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1951
diff changeset
   628
#endif
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   629
        XDestroyWindow(data->display, w);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   630
        return -1;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   631
    }
2325
c7bcf84ba1b9 Next version of internationalized input for X11. On my machine (famous last words :-) with a US English keyboard and locale I can compose ` and e and get a text
Bob Pendleton <bob@pendleton.com>
parents: 2324
diff changeset
   632
#ifdef X_HAVE_UTF8_STRING
c7bcf84ba1b9 Next version of internationalized input for X11. On my machine (famous last words :-) with a US English keyboard and locale I can compose ` and e and get a text
Bob Pendleton <bob@pendleton.com>
parents: 2324
diff changeset
   633
    {
c7bcf84ba1b9 Next version of internationalized input for X11. On my machine (famous last words :-) with a US English keyboard and locale I can compose ` and e and get a text
Bob Pendleton <bob@pendleton.com>
parents: 2324
diff changeset
   634
        Uint32 fevent = 0;
c7bcf84ba1b9 Next version of internationalized input for X11. On my machine (famous last words :-) with a US English keyboard and locale I can compose ` and e and get a text
Bob Pendleton <bob@pendleton.com>
parents: 2324
diff changeset
   635
        pXGetICValues(((SDL_WindowData *) window->driverdata)->ic,
c7bcf84ba1b9 Next version of internationalized input for X11. On my machine (famous last words :-) with a US English keyboard and locale I can compose ` and e and get a text
Bob Pendleton <bob@pendleton.com>
parents: 2324
diff changeset
   636
                      XNFilterEvents, &fevent, NULL);
c7bcf84ba1b9 Next version of internationalized input for X11. On my machine (famous last words :-) with a US English keyboard and locale I can compose ` and e and get a text
Bob Pendleton <bob@pendleton.com>
parents: 2324
diff changeset
   637
        XSelectInput(data->display, w,
c7bcf84ba1b9 Next version of internationalized input for X11. On my machine (famous last words :-) with a US English keyboard and locale I can compose ` and e and get a text
Bob Pendleton <bob@pendleton.com>
parents: 2324
diff changeset
   638
                     (FocusChangeMask | EnterWindowMask | LeaveWindowMask |
c7bcf84ba1b9 Next version of internationalized input for X11. On my machine (famous last words :-) with a US English keyboard and locale I can compose ` and e and get a text
Bob Pendleton <bob@pendleton.com>
parents: 2324
diff changeset
   639
                      ExposureMask | ButtonPressMask | ButtonReleaseMask |
c7bcf84ba1b9 Next version of internationalized input for X11. On my machine (famous last words :-) with a US English keyboard and locale I can compose ` and e and get a text
Bob Pendleton <bob@pendleton.com>
parents: 2324
diff changeset
   640
                      PointerMotionMask | KeyPressMask | KeyReleaseMask |
c7bcf84ba1b9 Next version of internationalized input for X11. On my machine (famous last words :-) with a US English keyboard and locale I can compose ` and e and get a text
Bob Pendleton <bob@pendleton.com>
parents: 2324
diff changeset
   641
                      PropertyChangeMask | StructureNotifyMask |
c7bcf84ba1b9 Next version of internationalized input for X11. On my machine (famous last words :-) with a US English keyboard and locale I can compose ` and e and get a text
Bob Pendleton <bob@pendleton.com>
parents: 2324
diff changeset
   642
                      KeymapStateMask | fevent));
c7bcf84ba1b9 Next version of internationalized input for X11. On my machine (famous last words :-) with a US English keyboard and locale I can compose ` and e and get a text
Bob Pendleton <bob@pendleton.com>
parents: 2324
diff changeset
   643
    }
c7bcf84ba1b9 Next version of internationalized input for X11. On my machine (famous last words :-) with a US English keyboard and locale I can compose ` and e and get a text
Bob Pendleton <bob@pendleton.com>
parents: 2324
diff changeset
   644
#else
2718
abacf2555bb4 Removed unneccesary code lines. Fixed mousename bug. Added lacking code in mousebutton
Szymon Wilczek <kazeuser@gmail.com>
parents: 2710
diff changeset
   645
    {
abacf2555bb4 Removed unneccesary code lines. Fixed mousename bug. Added lacking code in mousebutton
Szymon Wilczek <kazeuser@gmail.com>
parents: 2710
diff changeset
   646
        XSelectInput(data->display, w,
2725
Sam Lantinga <slouken@libsdl.org>
parents: 2718
diff changeset
   647
                     (FocusChangeMask | EnterWindowMask | LeaveWindowMask |
Sam Lantinga <slouken@libsdl.org>
parents: 2718
diff changeset
   648
                      ExposureMask | ButtonPressMask | ButtonReleaseMask |
Sam Lantinga <slouken@libsdl.org>
parents: 2718
diff changeset
   649
                      PointerMotionMask | KeyPressMask | KeyReleaseMask |
Sam Lantinga <slouken@libsdl.org>
parents: 2718
diff changeset
   650
                      PropertyChangeMask | StructureNotifyMask |
Sam Lantinga <slouken@libsdl.org>
parents: 2718
diff changeset
   651
                      KeymapStateMask));
2718
abacf2555bb4 Removed unneccesary code lines. Fixed mousename bug. Added lacking code in mousebutton
Szymon Wilczek <kazeuser@gmail.com>
parents: 2710
diff changeset
   652
    }
2325
c7bcf84ba1b9 Next version of internationalized input for X11. On my machine (famous last words :-) with a US English keyboard and locale I can compose ` and e and get a text
Bob Pendleton <bob@pendleton.com>
parents: 2324
diff changeset
   653
#endif
c7bcf84ba1b9 Next version of internationalized input for X11. On my machine (famous last words :-) with a US English keyboard and locale I can compose ` and e and get a text
Bob Pendleton <bob@pendleton.com>
parents: 2324
diff changeset
   654
2940
b93965a16fe0 Fixed X11 mouse motion/button events - it's not actually safe to cast mouse events to device events.
Sam Lantinga <slouken@libsdl.org>
parents: 2931
diff changeset
   655
#if SDL_VIDEO_DRIVER_X11_XINPUT
2710
44e49d3fa6cf Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2325
diff changeset
   656
    /* we're informing the display what extension events we want to receive from it */
2940
b93965a16fe0 Fixed X11 mouse motion/button events - it's not actually safe to cast mouse events to device events.
Sam Lantinga <slouken@libsdl.org>
parents: 2931
diff changeset
   657
    {
b93965a16fe0 Fixed X11 mouse motion/button events - it's not actually safe to cast mouse events to device events.
Sam Lantinga <slouken@libsdl.org>
parents: 2931
diff changeset
   658
        int i, j, n = 0;
b93965a16fe0 Fixed X11 mouse motion/button events - it's not actually safe to cast mouse events to device events.
Sam Lantinga <slouken@libsdl.org>
parents: 2931
diff changeset
   659
        XEventClass xevents[256];
b93965a16fe0 Fixed X11 mouse motion/button events - it's not actually safe to cast mouse events to device events.
Sam Lantinga <slouken@libsdl.org>
parents: 2931
diff changeset
   660
b93965a16fe0 Fixed X11 mouse motion/button events - it's not actually safe to cast mouse events to device events.
Sam Lantinga <slouken@libsdl.org>
parents: 2931
diff changeset
   661
        for (i = 0; i < SDL_GetNumMice(); ++i) {
b93965a16fe0 Fixed X11 mouse motion/button events - it's not actually safe to cast mouse events to device events.
Sam Lantinga <slouken@libsdl.org>
parents: 2931
diff changeset
   662
            SDL_Mouse *mouse;
b93965a16fe0 Fixed X11 mouse motion/button events - it's not actually safe to cast mouse events to device events.
Sam Lantinga <slouken@libsdl.org>
parents: 2931
diff changeset
   663
            X11_MouseData *data;
b93965a16fe0 Fixed X11 mouse motion/button events - it's not actually safe to cast mouse events to device events.
Sam Lantinga <slouken@libsdl.org>
parents: 2931
diff changeset
   664
b93965a16fe0 Fixed X11 mouse motion/button events - it's not actually safe to cast mouse events to device events.
Sam Lantinga <slouken@libsdl.org>
parents: 2931
diff changeset
   665
            mouse = SDL_GetMouse(i);
2942
Sam Lantinga <slouken@libsdl.org>
parents: 2940
diff changeset
   666
            data = (X11_MouseData *) mouse->driverdata;
2940
b93965a16fe0 Fixed X11 mouse motion/button events - it's not actually safe to cast mouse events to device events.
Sam Lantinga <slouken@libsdl.org>
parents: 2931
diff changeset
   667
            if (!data) {
b93965a16fe0 Fixed X11 mouse motion/button events - it's not actually safe to cast mouse events to device events.
Sam Lantinga <slouken@libsdl.org>
parents: 2931
diff changeset
   668
                continue;
b93965a16fe0 Fixed X11 mouse motion/button events - it's not actually safe to cast mouse events to device events.
Sam Lantinga <slouken@libsdl.org>
parents: 2931
diff changeset
   669
            }
b93965a16fe0 Fixed X11 mouse motion/button events - it's not actually safe to cast mouse events to device events.
Sam Lantinga <slouken@libsdl.org>
parents: 2931
diff changeset
   670
b93965a16fe0 Fixed X11 mouse motion/button events - it's not actually safe to cast mouse events to device events.
Sam Lantinga <slouken@libsdl.org>
parents: 2931
diff changeset
   671
            for (j = 0; j < data->num_xevents; ++j) {
b93965a16fe0 Fixed X11 mouse motion/button events - it's not actually safe to cast mouse events to device events.
Sam Lantinga <slouken@libsdl.org>
parents: 2931
diff changeset
   672
                xevents[n++] = data->xevents[j];
b93965a16fe0 Fixed X11 mouse motion/button events - it's not actually safe to cast mouse events to device events.
Sam Lantinga <slouken@libsdl.org>
parents: 2931
diff changeset
   673
            }
b93965a16fe0 Fixed X11 mouse motion/button events - it's not actually safe to cast mouse events to device events.
Sam Lantinga <slouken@libsdl.org>
parents: 2931
diff changeset
   674
        }
b93965a16fe0 Fixed X11 mouse motion/button events - it's not actually safe to cast mouse events to device events.
Sam Lantinga <slouken@libsdl.org>
parents: 2931
diff changeset
   675
        if (n > 0) {
b93965a16fe0 Fixed X11 mouse motion/button events - it's not actually safe to cast mouse events to device events.
Sam Lantinga <slouken@libsdl.org>
parents: 2931
diff changeset
   676
            XSelectExtensionEvent(data->display, w, xevents, n);
b93965a16fe0 Fixed X11 mouse motion/button events - it's not actually safe to cast mouse events to device events.
Sam Lantinga <slouken@libsdl.org>
parents: 2931
diff changeset
   677
        }
b93965a16fe0 Fixed X11 mouse motion/button events - it's not actually safe to cast mouse events to device events.
Sam Lantinga <slouken@libsdl.org>
parents: 2931
diff changeset
   678
    }
b93965a16fe0 Fixed X11 mouse motion/button events - it's not actually safe to cast mouse events to device events.
Sam Lantinga <slouken@libsdl.org>
parents: 2931
diff changeset
   679
#endif
2710
44e49d3fa6cf Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2325
diff changeset
   680
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   681
    return 0;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   682
}
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   683
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   684
int
2324
3202e4826c57 more valgrind errors fixed. Plus I ran make indent which changed a few files.
Bob Pendleton <bob@pendleton.com>
parents: 2323
diff changeset
   685
X11_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   686
{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   687
    Window w = (Window) data;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   688
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   689
    /* FIXME: Query the title from the existing window */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   690
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   691
    if (SetupWindowData(_this, window, w, SDL_FALSE) < 0) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   692
        return -1;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   693
    }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   694
    return 0;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   695
}
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   696
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   697
void
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   698
X11_SetWindowTitle(_THIS, SDL_Window * window)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   699
{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   700
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   701
    Display *display = data->videodata->display;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   702
    XTextProperty titleprop, iconprop;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   703
    Status status;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   704
    const char *title = window->title;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   705
    const char *icon = NULL;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   706
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   707
#ifdef X_HAVE_UTF8_STRING
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   708
    Atom _NET_WM_NAME = 0;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   709
    Atom _NET_WM_ICON_NAME = 0;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   710
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   711
    /* Look up some useful Atoms */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   712
    if (SDL_X11_HAVE_UTF8) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   713
        _NET_WM_NAME = XInternAtom(display, "_NET_WM_NAME", False);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   714
        _NET_WM_ICON_NAME = XInternAtom(display, "_NET_WM_ICON_NAME", False);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   715
    }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   716
#endif
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   717
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   718
    if (title != NULL) {
2143
e906da4414a3 Fix for bug #447 merged from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents: 1956
diff changeset
   719
        char *title_locale = SDL_iconv_utf8_locale(title);
e906da4414a3 Fix for bug #447 merged from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents: 1956
diff changeset
   720
        if (!title_locale) {
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   721
            SDL_OutOfMemory();
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   722
            return;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   723
        }
2143
e906da4414a3 Fix for bug #447 merged from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents: 1956
diff changeset
   724
        status = XStringListToTextProperty(&title_locale, 1, &titleprop);
e906da4414a3 Fix for bug #447 merged from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents: 1956
diff changeset
   725
        SDL_free(title_locale);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   726
        if (status) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   727
            XSetTextProperty(display, data->window, &titleprop, XA_WM_NAME);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   728
            XFree(titleprop.value);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   729
        }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   730
#ifdef X_HAVE_UTF8_STRING
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   731
        if (SDL_X11_HAVE_UTF8) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   732
            status =
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   733
                Xutf8TextListToTextProperty(display, (char **) &title, 1,
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   734
                                            XUTF8StringStyle, &titleprop);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   735
            if (status == Success) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   736
                XSetTextProperty(display, data->window, &titleprop,
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   737
                                 _NET_WM_NAME);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   738
                XFree(titleprop.value);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   739
            }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   740
        }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   741
#endif
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   742
    }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   743
    if (icon != NULL) {
2143
e906da4414a3 Fix for bug #447 merged from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents: 1956
diff changeset
   744
        char *icon_locale = SDL_iconv_utf8_locale(icon);
e906da4414a3 Fix for bug #447 merged from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents: 1956
diff changeset
   745
        if (!icon_locale) {
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   746
            SDL_OutOfMemory();
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   747
            return;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   748
        }
2143
e906da4414a3 Fix for bug #447 merged from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents: 1956
diff changeset
   749
        status = XStringListToTextProperty(&icon_locale, 1, &iconprop);
e906da4414a3 Fix for bug #447 merged from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents: 1956
diff changeset
   750
        SDL_free(icon_locale);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   751
        if (status) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   752
            XSetTextProperty(display, data->window, &iconprop,
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   753
                             XA_WM_ICON_NAME);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   754
            XFree(iconprop.value);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   755
        }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   756
#ifdef X_HAVE_UTF8_STRING
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   757
        if (SDL_X11_HAVE_UTF8) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   758
            status =
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   759
                Xutf8TextListToTextProperty(display, (char **) &icon, 1,
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   760
                                            XUTF8StringStyle, &iconprop);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   761
            if (status == Success) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   762
                XSetTextProperty(display, data->window, &iconprop,
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   763
                                 _NET_WM_ICON_NAME);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   764
                XFree(iconprop.value);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   765
            }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   766
        }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   767
#endif
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   768
    }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   769
}
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   770
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   771
void
2967
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
   772
X11_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon)
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
   773
{
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
   774
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
   775
    Display *display = data->videodata->display;
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
   776
    Atom _NET_WM_ICON = XInternAtom(display, "_NET_WM_ICON", False);
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
   777
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
   778
    if (icon) {
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
   779
        SDL_PixelFormat format;
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
   780
        SDL_Surface *surface;
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
   781
        int propsize;
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
   782
        Uint32 *propdata;
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
   783
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
   784
        /* Convert the icon to ARGB for modern window managers */
2990
Sam Lantinga <slouken@libsdl.org>
parents: 2967
diff changeset
   785
        SDL_InitFormat(&format, 32, 0x00FF0000, 0x0000FF00, 0x000000FF,
Sam Lantinga <slouken@libsdl.org>
parents: 2967
diff changeset
   786
                       0xFF000000);
2967
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
   787
        surface = SDL_ConvertSurface(icon, &format, 0);
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
   788
        if (!surface) {
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
   789
            return;
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
   790
        }
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
   791
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
   792
        /* Set the _NET_WM_ICON property */
2990
Sam Lantinga <slouken@libsdl.org>
parents: 2967
diff changeset
   793
        propsize = 2 + (icon->w * icon->h);
2967
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
   794
        propdata = SDL_malloc(propsize * sizeof(Uint32));
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
   795
        if (propdata) {
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
   796
            propdata[0] = icon->w;
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
   797
            propdata[1] = icon->h;
2990
Sam Lantinga <slouken@libsdl.org>
parents: 2967
diff changeset
   798
            SDL_memcpy(&propdata[2], surface->pixels,
Sam Lantinga <slouken@libsdl.org>
parents: 2967
diff changeset
   799
                       surface->h * surface->pitch);
Sam Lantinga <slouken@libsdl.org>
parents: 2967
diff changeset
   800
            XChangeProperty(display, data->window, _NET_WM_ICON, XA_CARDINAL,
Sam Lantinga <slouken@libsdl.org>
parents: 2967
diff changeset
   801
                            32, PropModeReplace, (unsigned char *) propdata,
Sam Lantinga <slouken@libsdl.org>
parents: 2967
diff changeset
   802
                            propsize);
2967
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
   803
        }
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
   804
        SDL_FreeSurface(surface);
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
   805
    } else {
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
   806
        XDeleteProperty(display, data->window, _NET_WM_ICON);
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
   807
    }
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
   808
}
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
   809
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
   810
void
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   811
X11_SetWindowPosition(_THIS, SDL_Window * window)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   812
{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   813
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   814
    SDL_DisplayData *displaydata =
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1951
diff changeset
   815
        (SDL_DisplayData *) SDL_GetDisplayFromWindow(window)->driverdata;
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   816
    Display *display = data->videodata->display;
2875
91a7e08cd238 * Implemented X11 fullscreen input grab
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   817
    int x, y;
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   818
2876
Sam Lantinga <slouken@libsdl.org>
parents: 2875
diff changeset
   819
    if ((window->flags & SDL_WINDOW_FULLSCREEN)
Sam Lantinga <slouken@libsdl.org>
parents: 2875
diff changeset
   820
        || window->x == SDL_WINDOWPOS_CENTERED) {
2931
e705adf6f3dc Date: Mon, 29 Dec 2008 23:29:52 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2876
diff changeset
   821
        X11_GetDisplaySize(_this, window, &x, NULL);
e705adf6f3dc Date: Mon, 29 Dec 2008 23:29:52 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2876
diff changeset
   822
        x = (x - window->w) / 2;
2875
91a7e08cd238 * Implemented X11 fullscreen input grab
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   823
    } else {
91a7e08cd238 * Implemented X11 fullscreen input grab
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   824
        x = window->x;
91a7e08cd238 * Implemented X11 fullscreen input grab
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   825
    }
2876
Sam Lantinga <slouken@libsdl.org>
parents: 2875
diff changeset
   826
    if ((window->flags & SDL_WINDOW_FULLSCREEN)
Sam Lantinga <slouken@libsdl.org>
parents: 2875
diff changeset
   827
        || window->y == SDL_WINDOWPOS_CENTERED) {
2931
e705adf6f3dc Date: Mon, 29 Dec 2008 23:29:52 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2876
diff changeset
   828
        X11_GetDisplaySize(_this, window, NULL, &y);
e705adf6f3dc Date: Mon, 29 Dec 2008 23:29:52 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2876
diff changeset
   829
        y = (y - window->h) / 2;
2875
91a7e08cd238 * Implemented X11 fullscreen input grab
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   830
    } else {
91a7e08cd238 * Implemented X11 fullscreen input grab
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   831
        y = window->y;
91a7e08cd238 * Implemented X11 fullscreen input grab
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   832
    }
91a7e08cd238 * Implemented X11 fullscreen input grab
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   833
    XMoveWindow(display, data->window, x, y);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   834
}
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   835
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   836
void
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   837
X11_SetWindowSize(_THIS, SDL_Window * window)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   838
{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   839
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   840
    Display *display = data->videodata->display;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   841
2931
e705adf6f3dc Date: Mon, 29 Dec 2008 23:29:52 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2876
diff changeset
   842
    XResizeWindow(display, data->window, window->w, window->h);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   843
}
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   844
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   845
void
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   846
X11_ShowWindow(_THIS, SDL_Window * window)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   847
{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   848
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   849
    Display *display = data->videodata->display;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   850
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   851
    XMapRaised(display, data->window);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   852
}
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   853
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   854
void
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   855
X11_HideWindow(_THIS, SDL_Window * window)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   856
{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   857
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   858
    Display *display = data->videodata->display;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   859
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   860
    XUnmapWindow(display, data->window);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   861
}
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   862
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   863
void
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   864
X11_RaiseWindow(_THIS, SDL_Window * window)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   865
{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   866
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   867
    Display *display = data->videodata->display;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   868
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   869
    XRaiseWindow(display, data->window);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   870
}
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   871
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   872
void
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   873
X11_MaximizeWindow(_THIS, SDL_Window * window)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   874
{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   875
    /* FIXME: is this even possible? */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   876
}
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   877
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   878
void
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   879
X11_MinimizeWindow(_THIS, SDL_Window * window)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   880
{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   881
    X11_HideWindow(_this, window);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   882
}
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   883
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   884
void
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   885
X11_RestoreWindow(_THIS, SDL_Window * window)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   886
{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   887
    X11_ShowWindow(_this, window);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   888
}
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   889
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   890
void
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   891
X11_SetWindowGrab(_THIS, SDL_Window * window)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   892
{
2875
91a7e08cd238 * Implemented X11 fullscreen input grab
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   893
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
91a7e08cd238 * Implemented X11 fullscreen input grab
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   894
    Display *display = data->videodata->display;
91a7e08cd238 * Implemented X11 fullscreen input grab
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   895
2876
Sam Lantinga <slouken@libsdl.org>
parents: 2875
diff changeset
   896
    if ((window->flags & (SDL_WINDOW_INPUT_GRABBED | SDL_WINDOW_FULLSCREEN))
Sam Lantinga <slouken@libsdl.org>
parents: 2875
diff changeset
   897
        && (window->flags & SDL_WINDOW_INPUT_FOCUS)) {
2875
91a7e08cd238 * Implemented X11 fullscreen input grab
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   898
        /* Try to grab the mouse */
2876
Sam Lantinga <slouken@libsdl.org>
parents: 2875
diff changeset
   899
        for (;;) {
Sam Lantinga <slouken@libsdl.org>
parents: 2875
diff changeset
   900
            int result =
Sam Lantinga <slouken@libsdl.org>
parents: 2875
diff changeset
   901
                XGrabPointer(display, data->window, True, 0, GrabModeAsync,
Sam Lantinga <slouken@libsdl.org>
parents: 2875
diff changeset
   902
                             GrabModeAsync, data->window, None, CurrentTime);
Sam Lantinga <slouken@libsdl.org>
parents: 2875
diff changeset
   903
            if (result == GrabSuccess) {
2875
91a7e08cd238 * Implemented X11 fullscreen input grab
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   904
                break;
91a7e08cd238 * Implemented X11 fullscreen input grab
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   905
            }
91a7e08cd238 * Implemented X11 fullscreen input grab
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   906
            SDL_Delay(100);
91a7e08cd238 * Implemented X11 fullscreen input grab
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   907
        }
91a7e08cd238 * Implemented X11 fullscreen input grab
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   908
91a7e08cd238 * Implemented X11 fullscreen input grab
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   909
        /* Raise the window if we grab the mouse */
91a7e08cd238 * Implemented X11 fullscreen input grab
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   910
        XRaiseWindow(display, data->window);
91a7e08cd238 * Implemented X11 fullscreen input grab
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   911
91a7e08cd238 * Implemented X11 fullscreen input grab
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   912
        /* Now grab the keyboard */
2876
Sam Lantinga <slouken@libsdl.org>
parents: 2875
diff changeset
   913
        XGrabKeyboard(display, data->window, True, GrabModeAsync,
Sam Lantinga <slouken@libsdl.org>
parents: 2875
diff changeset
   914
                      GrabModeAsync, CurrentTime);
2875
91a7e08cd238 * Implemented X11 fullscreen input grab
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   915
    } else {
91a7e08cd238 * Implemented X11 fullscreen input grab
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   916
        XUngrabPointer(display, CurrentTime);
91a7e08cd238 * Implemented X11 fullscreen input grab
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   917
        XUngrabKeyboard(display, CurrentTime);
91a7e08cd238 * Implemented X11 fullscreen input grab
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   918
    }
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   919
}
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   920
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   921
void
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   922
X11_DestroyWindow(_THIS, SDL_Window * window)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   923
{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   924
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
2323
4ac07ae446d3 Fixed many valgrind errors. But, I broke testdyngl.
Bob Pendleton <bob@pendleton.com>
parents: 2322
diff changeset
   925
    window->driverdata = NULL;
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   926
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   927
    if (data) {
2323
4ac07ae446d3 Fixed many valgrind errors. But, I broke testdyngl.
Bob Pendleton <bob@pendleton.com>
parents: 2322
diff changeset
   928
        SDL_VideoData *videodata = (SDL_VideoData *) data->videodata;
4ac07ae446d3 Fixed many valgrind errors. But, I broke testdyngl.
Bob Pendleton <bob@pendleton.com>
parents: 2322
diff changeset
   929
        Display *display = videodata->display;
4ac07ae446d3 Fixed many valgrind errors. But, I broke testdyngl.
Bob Pendleton <bob@pendleton.com>
parents: 2322
diff changeset
   930
        int numwindows = videodata->numwindows;
4ac07ae446d3 Fixed many valgrind errors. But, I broke testdyngl.
Bob Pendleton <bob@pendleton.com>
parents: 2322
diff changeset
   931
        SDL_WindowData **windowlist = videodata->windowlist;
4ac07ae446d3 Fixed many valgrind errors. But, I broke testdyngl.
Bob Pendleton <bob@pendleton.com>
parents: 2322
diff changeset
   932
        int i;
4ac07ae446d3 Fixed many valgrind errors. But, I broke testdyngl.
Bob Pendleton <bob@pendleton.com>
parents: 2322
diff changeset
   933
4ac07ae446d3 Fixed many valgrind errors. But, I broke testdyngl.
Bob Pendleton <bob@pendleton.com>
parents: 2322
diff changeset
   934
        if (windowlist) {
2324
3202e4826c57 more valgrind errors fixed. Plus I ran make indent which changed a few files.
Bob Pendleton <bob@pendleton.com>
parents: 2323
diff changeset
   935
            for (i = 0; i < numwindows; ++i) {
3202e4826c57 more valgrind errors fixed. Plus I ran make indent which changed a few files.
Bob Pendleton <bob@pendleton.com>
parents: 2323
diff changeset
   936
                if (windowlist[i] && (windowlist[i]->windowID == window->id)) {
3202e4826c57 more valgrind errors fixed. Plus I ran make indent which changed a few files.
Bob Pendleton <bob@pendleton.com>
parents: 2323
diff changeset
   937
                    windowlist[i] = windowlist[numwindows - 1];
3202e4826c57 more valgrind errors fixed. Plus I ran make indent which changed a few files.
Bob Pendleton <bob@pendleton.com>
parents: 2323
diff changeset
   938
                    windowlist[numwindows - 1] = NULL;
3202e4826c57 more valgrind errors fixed. Plus I ran make indent which changed a few files.
Bob Pendleton <bob@pendleton.com>
parents: 2323
diff changeset
   939
                    videodata->numwindows--;
3202e4826c57 more valgrind errors fixed. Plus I ran make indent which changed a few files.
Bob Pendleton <bob@pendleton.com>
parents: 2323
diff changeset
   940
                    break;
3202e4826c57 more valgrind errors fixed. Plus I ran make indent which changed a few files.
Bob Pendleton <bob@pendleton.com>
parents: 2323
diff changeset
   941
                }
2323
4ac07ae446d3 Fixed many valgrind errors. But, I broke testdyngl.
Bob Pendleton <bob@pendleton.com>
parents: 2322
diff changeset
   942
            }
4ac07ae446d3 Fixed many valgrind errors. But, I broke testdyngl.
Bob Pendleton <bob@pendleton.com>
parents: 2322
diff changeset
   943
        }
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1951
diff changeset
   944
#ifdef SDL_VIDEO_OPENGL_GLX
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1951
diff changeset
   945
        if (window->flags & SDL_WINDOW_OPENGL) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1951
diff changeset
   946
            X11_GL_Shutdown(_this);
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1951
diff changeset
   947
        }
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   948
#endif
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   949
#ifdef X_HAVE_UTF8_STRING
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   950
        if (data->ic) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   951
            XDestroyIC(data->ic);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   952
        }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   953
#endif
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   954
        if (data->created) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   955
            XDestroyWindow(display, data->window);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   956
        }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   957
        SDL_free(data);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   958
    }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   959
}
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   960
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   961
SDL_bool
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   962
X11_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   963
{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   964
    if (info->version.major <= SDL_MAJOR_VERSION) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   965
        /* FIXME! */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   966
        return SDL_TRUE;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   967
    } else {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   968
        SDL_SetError("Application not compiled with SDL %d.%d\n",
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   969
                     SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   970
        return SDL_FALSE;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   971
    }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   972
}
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   973
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   974
/* vi: set ts=4 sw=4 expandtab: */