src/video/x11/SDL_x11window.c
author Sam Lantinga <slouken@libsdl.org>
Thu, 27 Sep 2012 13:23:34 -0700
changeset 6475 71d39944810b
parent 6473 a5adb68266d0
child 6477 1e99ebaf0b14
permissions -rwxr-xr-x
Fixed fullscreen origin for multi-head displays
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
/*
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5531
diff changeset
     2
  Simple DirectMedia Layer
6138
4c64952a58fb Happy New Year!
Sam Lantinga <slouken@libsdl.org>
parents: 6045
diff changeset
     3
  Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     4
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5531
diff changeset
     5
  This software is provided 'as-is', without any express or implied
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5531
diff changeset
     6
  warranty.  In no event will the authors be held liable for any damages
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5531
diff changeset
     7
  arising from the use of this software.
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     8
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5531
diff changeset
     9
  Permission is granted to anyone to use this software for any purpose,
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5531
diff changeset
    10
  including commercial applications, and to alter it and redistribute it
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5531
diff changeset
    11
  freely, subject to the following restrictions:
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    12
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5531
diff changeset
    13
  1. The origin of this software must not be misrepresented; you must not
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5531
diff changeset
    14
     claim that you wrote the original software. If you use this software
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5531
diff changeset
    15
     in a product, an acknowledgment in the product documentation would be
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5531
diff changeset
    16
     appreciated but is not required.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5531
diff changeset
    17
  2. Altered source versions must be plainly marked as such, and must not be
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5531
diff changeset
    18
     misrepresented as being the original software.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5531
diff changeset
    19
  3. This notice may not be removed or altered from any source distribution.
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    20
*/
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    21
#include "SDL_config.h"
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    22
5481
22dfc3958dc3 Fixed so code will compile with SDL_config_minimal.h
Sam Lantinga <slouken@libsdl.org>
parents: 5478
diff changeset
    23
#if SDL_VIDEO_DRIVER_X11
22dfc3958dc3 Fixed so code will compile with SDL_config_minimal.h
Sam Lantinga <slouken@libsdl.org>
parents: 5478
diff changeset
    24
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    25
#include "../SDL_sysvideo.h"
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
    26
#include "../SDL_pixels_c.h"
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    27
#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
    28
#include "../../events/SDL_mouse_c.h"
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    29
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    30
#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
    31
#include "SDL_x11mouse.h"
4782
b6930aefd008 Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 3697
diff changeset
    32
#include "SDL_x11shape.h"
6316
a89c79a3f0cd 1.Moved all xinput2 functionality to its own file
Dimitris Zenios <dimitris.zenios@gmail.com>
parents: 6275
diff changeset
    33
#include "SDL_x11xinput2.h"
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    34
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6167
diff changeset
    35
#if SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
3161
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3078
diff changeset
    36
#include "SDL_x11opengles.h"
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3078
diff changeset
    37
#endif
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3078
diff changeset
    38
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
    39
#include "SDL_timer.h"
3241
08c5964f2a34 Fixed a few issues compiling with Mac OS X 10.6
Sam Lantinga <slouken@libsdl.org>
parents: 3225
diff changeset
    40
#include "SDL_syswm.h"
6467
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
    41
#include "SDL_assert.h"
3241
08c5964f2a34 Fixed a few issues compiling with Mac OS X 10.6
Sam Lantinga <slouken@libsdl.org>
parents: 3225
diff changeset
    42
3077
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
    43
#define _NET_WM_STATE_REMOVE    0l
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
    44
#define _NET_WM_STATE_ADD       1l
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
    45
#define _NET_WM_STATE_TOGGLE    2l
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
    46
6467
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
    47
static Bool isMapNotify(Display *dpy, XEvent *ev, XPointer win)
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
    48
{
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
    49
    return ev->type == MapNotify && ev->xmap.window == *((Window*)win);
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
    50
}
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
    51
static Bool isUnmapNotify(Display *dpy, XEvent *ev, XPointer win)
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
    52
{
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
    53
    return ev->type == UnmapNotify && ev->xunmap.window == *((Window*)win);
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
    54
}
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
    55
static Bool isConfigureNotify(Display *dpy, XEvent *ev, XPointer win)
4518
a956a315fe67 Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents: 4510
diff changeset
    56
{
6467
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
    57
    return ev->type == ConfigureNotify && ev->xunmap.window == *((Window*)win);
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
    58
}
4518
a956a315fe67 Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents: 4510
diff changeset
    59
6467
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
    60
static SDL_bool
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
    61
X11_IsWindowLegacyFullscreen(_THIS, SDL_Window * window)
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
    62
{
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
    63
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
    64
    return (data->fswindow != 0);
4518
a956a315fe67 Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents: 4510
diff changeset
    65
}
a956a315fe67 Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents: 4510
diff changeset
    66
4522
a4da6b906abb Fixed setting fullscreen and maximized states for windows that haven't been mapped yet.
Sam Lantinga <slouken@libsdl.org>
parents: 4521
diff changeset
    67
static SDL_bool
a4da6b906abb Fixed setting fullscreen and maximized states for windows that haven't been mapped yet.
Sam Lantinga <slouken@libsdl.org>
parents: 4521
diff changeset
    68
X11_IsWindowMapped(_THIS, SDL_Window * window)
a4da6b906abb Fixed setting fullscreen and maximized states for windows that haven't been mapped yet.
Sam Lantinga <slouken@libsdl.org>
parents: 4521
diff changeset
    69
{
a4da6b906abb Fixed setting fullscreen and maximized states for windows that haven't been mapped yet.
Sam Lantinga <slouken@libsdl.org>
parents: 4521
diff changeset
    70
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
a4da6b906abb Fixed setting fullscreen and maximized states for windows that haven't been mapped yet.
Sam Lantinga <slouken@libsdl.org>
parents: 4521
diff changeset
    71
    SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
a4da6b906abb Fixed setting fullscreen and maximized states for windows that haven't been mapped yet.
Sam Lantinga <slouken@libsdl.org>
parents: 4521
diff changeset
    72
    XWindowAttributes attr;
a4da6b906abb Fixed setting fullscreen and maximized states for windows that haven't been mapped yet.
Sam Lantinga <slouken@libsdl.org>
parents: 4521
diff changeset
    73
a4da6b906abb Fixed setting fullscreen and maximized states for windows that haven't been mapped yet.
Sam Lantinga <slouken@libsdl.org>
parents: 4521
diff changeset
    74
    XGetWindowAttributes(videodata->display, data->xwindow, &attr);
a4da6b906abb Fixed setting fullscreen and maximized states for windows that haven't been mapped yet.
Sam Lantinga <slouken@libsdl.org>
parents: 4521
diff changeset
    75
    if (attr.map_state != IsUnmapped) {
a4da6b906abb Fixed setting fullscreen and maximized states for windows that haven't been mapped yet.
Sam Lantinga <slouken@libsdl.org>
parents: 4521
diff changeset
    76
        return SDL_TRUE;
a4da6b906abb Fixed setting fullscreen and maximized states for windows that haven't been mapped yet.
Sam Lantinga <slouken@libsdl.org>
parents: 4521
diff changeset
    77
    } else {
a4da6b906abb Fixed setting fullscreen and maximized states for windows that haven't been mapped yet.
Sam Lantinga <slouken@libsdl.org>
parents: 4521
diff changeset
    78
        return SDL_FALSE;
a4da6b906abb Fixed setting fullscreen and maximized states for windows that haven't been mapped yet.
Sam Lantinga <slouken@libsdl.org>
parents: 4521
diff changeset
    79
    }
a4da6b906abb Fixed setting fullscreen and maximized states for windows that haven't been mapped yet.
Sam Lantinga <slouken@libsdl.org>
parents: 4521
diff changeset
    80
}
a4da6b906abb Fixed setting fullscreen and maximized states for windows that haven't been mapped yet.
Sam Lantinga <slouken@libsdl.org>
parents: 4521
diff changeset
    81
a4da6b906abb Fixed setting fullscreen and maximized states for windows that haven't been mapped yet.
Sam Lantinga <slouken@libsdl.org>
parents: 4521
diff changeset
    82
static int
a4da6b906abb Fixed setting fullscreen and maximized states for windows that haven't been mapped yet.
Sam Lantinga <slouken@libsdl.org>
parents: 4521
diff changeset
    83
X11_GetWMStateProperty(_THIS, SDL_Window * window, Atom atoms[3])
a4da6b906abb Fixed setting fullscreen and maximized states for windows that haven't been mapped yet.
Sam Lantinga <slouken@libsdl.org>
parents: 4521
diff changeset
    84
{
a4da6b906abb Fixed setting fullscreen and maximized states for windows that haven't been mapped yet.
Sam Lantinga <slouken@libsdl.org>
parents: 4521
diff changeset
    85
    SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
a4da6b906abb Fixed setting fullscreen and maximized states for windows that haven't been mapped yet.
Sam Lantinga <slouken@libsdl.org>
parents: 4521
diff changeset
    86
    int count = 0;
a4da6b906abb Fixed setting fullscreen and maximized states for windows that haven't been mapped yet.
Sam Lantinga <slouken@libsdl.org>
parents: 4521
diff changeset
    87
a4da6b906abb Fixed setting fullscreen and maximized states for windows that haven't been mapped yet.
Sam Lantinga <slouken@libsdl.org>
parents: 4521
diff changeset
    88
    if (window->flags & SDL_WINDOW_FULLSCREEN) {
a4da6b906abb Fixed setting fullscreen and maximized states for windows that haven't been mapped yet.
Sam Lantinga <slouken@libsdl.org>
parents: 4521
diff changeset
    89
        atoms[count++] = data->_NET_WM_STATE_FULLSCREEN;
a4da6b906abb Fixed setting fullscreen and maximized states for windows that haven't been mapped yet.
Sam Lantinga <slouken@libsdl.org>
parents: 4521
diff changeset
    90
    }
a4da6b906abb Fixed setting fullscreen and maximized states for windows that haven't been mapped yet.
Sam Lantinga <slouken@libsdl.org>
parents: 4521
diff changeset
    91
    if (window->flags & SDL_WINDOW_MAXIMIZED) {
a4da6b906abb Fixed setting fullscreen and maximized states for windows that haven't been mapped yet.
Sam Lantinga <slouken@libsdl.org>
parents: 4521
diff changeset
    92
        atoms[count++] = data->_NET_WM_STATE_MAXIMIZED_VERT;
a4da6b906abb Fixed setting fullscreen and maximized states for windows that haven't been mapped yet.
Sam Lantinga <slouken@libsdl.org>
parents: 4521
diff changeset
    93
        atoms[count++] = data->_NET_WM_STATE_MAXIMIZED_HORZ;
a4da6b906abb Fixed setting fullscreen and maximized states for windows that haven't been mapped yet.
Sam Lantinga <slouken@libsdl.org>
parents: 4521
diff changeset
    94
    }
a4da6b906abb Fixed setting fullscreen and maximized states for windows that haven't been mapped yet.
Sam Lantinga <slouken@libsdl.org>
parents: 4521
diff changeset
    95
    return count;
a4da6b906abb Fixed setting fullscreen and maximized states for windows that haven't been mapped yet.
Sam Lantinga <slouken@libsdl.org>
parents: 4521
diff changeset
    96
}
a4da6b906abb Fixed setting fullscreen and maximized states for windows that haven't been mapped yet.
Sam Lantinga <slouken@libsdl.org>
parents: 4521
diff changeset
    97
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    98
static int
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    99
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
   100
{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   101
    SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   102
    SDL_WindowData *data;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   103
    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
   104
    int windowlistlength = videodata->windowlistlength;
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   105
    SDL_WindowData **windowlist = videodata->windowlist;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   106
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   107
    /* Allocate the window data */
2323
4ac07ae446d3 Fixed many valgrind errors. But, I broke testdyngl.
Bob Pendleton <bob@pendleton.com>
parents: 2322
diff changeset
   108
    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
   109
    if (!data) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   110
        SDL_OutOfMemory();
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   111
        return -1;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   112
    }
3685
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3241
diff changeset
   113
    data->window = window;
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3241
diff changeset
   114
    data->xwindow = w;
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   115
#ifdef X_HAVE_UTF8_STRING
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   116
    if (SDL_X11_HAVE_UTF8) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   117
        data->ic =
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   118
            pXCreateIC(videodata->im, XNClientWindow, w, XNFocusWindow, w,
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   119
                       XNInputStyle, XIMPreeditNothing | XIMStatusNothing,
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   120
                       XNResourceName, videodata->classname, XNResourceClass,
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   121
                       videodata->classname, NULL);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   122
    }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   123
#endif
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   124
    data->created = created;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   125
    data->videodata = videodata;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   126
2323
4ac07ae446d3 Fixed many valgrind errors. But, I broke testdyngl.
Bob Pendleton <bob@pendleton.com>
parents: 2322
diff changeset
   127
    /* 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
   128
3202e4826c57 more valgrind errors fixed. Plus I ran make indent which changed a few files.
Bob Pendleton <bob@pendleton.com>
parents: 2323
diff changeset
   129
    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
   130
        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
   131
        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
   132
    } 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
   133
        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
   134
            (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
   135
                                            (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
   136
                                             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
   137
        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
   138
            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
   139
            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
   140
            return -1;
2323
4ac07ae446d3 Fixed many valgrind errors. But, I broke testdyngl.
Bob Pendleton <bob@pendleton.com>
parents: 2322
diff changeset
   141
        }
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
   142
        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
   143
        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
   144
        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
   145
        videodata->windowlist = windowlist;
2323
4ac07ae446d3 Fixed many valgrind errors. But, I broke testdyngl.
Bob Pendleton <bob@pendleton.com>
parents: 2322
diff changeset
   146
    }
4ac07ae446d3 Fixed many valgrind errors. But, I broke testdyngl.
Bob Pendleton <bob@pendleton.com>
parents: 2322
diff changeset
   147
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   148
    /* 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
   149
    {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   150
        XWindowAttributes attrib;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   151
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   152
        XGetWindowAttributes(data->videodata->display, w, &attrib);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   153
        window->x = attrib.x;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   154
        window->y = attrib.y;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   155
        window->w = attrib.width;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   156
        window->h = attrib.height;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   157
        if (attrib.map_state != IsUnmapped) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   158
            window->flags |= SDL_WINDOW_SHOWN;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   159
        } else {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   160
            window->flags &= ~SDL_WINDOW_SHOWN;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   161
        }
5182
073b86030262 Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents: 5088
diff changeset
   162
        data->visual = attrib.visual;
5466
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   163
        data->colormap = attrib.colormap;
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   164
    }
3077
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   165
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   166
    {
4518
a956a315fe67 Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents: 4510
diff changeset
   167
        Atom _NET_WM_STATE = data->videodata->_NET_WM_STATE;
a956a315fe67 Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents: 4510
diff changeset
   168
        Atom _NET_WM_STATE_MAXIMIZED_VERT = data->videodata->_NET_WM_STATE_MAXIMIZED_VERT;
a956a315fe67 Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents: 4510
diff changeset
   169
        Atom _NET_WM_STATE_MAXIMIZED_HORZ = data->videodata->_NET_WM_STATE_MAXIMIZED_HORZ;
a956a315fe67 Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents: 4510
diff changeset
   170
        Atom _NET_WM_STATE_FULLSCREEN = data->videodata->_NET_WM_STATE_FULLSCREEN;
3077
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   171
        Atom actualType;
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   172
        int actualFormat;
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   173
        unsigned long i, numItems, bytesAfter;
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   174
        unsigned char *propertyValue = NULL;
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   175
        long maxLength = 1024;
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   176
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   177
        if (XGetWindowProperty(data->videodata->display, w, _NET_WM_STATE,
3078
Sam Lantinga <slouken@libsdl.org>
parents: 3077
diff changeset
   178
                               0l, maxLength, False, XA_ATOM, &actualType,
Sam Lantinga <slouken@libsdl.org>
parents: 3077
diff changeset
   179
                               &actualFormat, &numItems, &bytesAfter,
Sam Lantinga <slouken@libsdl.org>
parents: 3077
diff changeset
   180
                               &propertyValue) == Success) {
Sam Lantinga <slouken@libsdl.org>
parents: 3077
diff changeset
   181
            Atom *atoms = (Atom *) propertyValue;
3077
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   182
            int maximized = 0;
4518
a956a315fe67 Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents: 4510
diff changeset
   183
            int fullscreen = 0;
3077
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   184
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   185
            for (i = 0; i < numItems; ++i) {
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   186
                if (atoms[i] == _NET_WM_STATE_MAXIMIZED_VERT) {
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   187
                    maximized |= 1;
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   188
                } else if (atoms[i] == _NET_WM_STATE_MAXIMIZED_HORZ) {
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   189
                    maximized |= 2;
4518
a956a315fe67 Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents: 4510
diff changeset
   190
                } else if ( atoms[i] == _NET_WM_STATE_FULLSCREEN) {
a956a315fe67 Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents: 4510
diff changeset
   191
                    fullscreen = 1;
3077
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   192
                }
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   193
            }
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   194
            if (maximized == 3) {
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   195
                window->flags |= SDL_WINDOW_MAXIMIZED;
4518
a956a315fe67 Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents: 4510
diff changeset
   196
            }  else if (fullscreen == 1) {
a956a315fe67 Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents: 4510
diff changeset
   197
                window->flags |= SDL_WINDOW_FULLSCREEN;
3077
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   198
            }
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   199
            XFree(propertyValue);
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   200
        }
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   201
    }
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   202
6024
38e2f4644548 Set up window focus correctly when using an existing X11 window.
Ryan C. Gordon <icculus@icculus.org>
parents: 6023
diff changeset
   203
    {
38e2f4644548 Set up window focus correctly when using an existing X11 window.
Ryan C. Gordon <icculus@icculus.org>
parents: 6023
diff changeset
   204
        Window FocalWindow;
38e2f4644548 Set up window focus correctly when using an existing X11 window.
Ryan C. Gordon <icculus@icculus.org>
parents: 6023
diff changeset
   205
        int RevertTo=0;
38e2f4644548 Set up window focus correctly when using an existing X11 window.
Ryan C. Gordon <icculus@icculus.org>
parents: 6023
diff changeset
   206
        XGetInputFocus(data->videodata->display, &FocalWindow, &RevertTo);
38e2f4644548 Set up window focus correctly when using an existing X11 window.
Ryan C. Gordon <icculus@icculus.org>
parents: 6023
diff changeset
   207
        if (FocalWindow==w)
38e2f4644548 Set up window focus correctly when using an existing X11 window.
Ryan C. Gordon <icculus@icculus.org>
parents: 6023
diff changeset
   208
        {
38e2f4644548 Set up window focus correctly when using an existing X11 window.
Ryan C. Gordon <icculus@icculus.org>
parents: 6023
diff changeset
   209
            window->flags |= SDL_WINDOW_INPUT_FOCUS;
38e2f4644548 Set up window focus correctly when using an existing X11 window.
Ryan C. Gordon <icculus@icculus.org>
parents: 6023
diff changeset
   210
            SDL_SetKeyboardFocus(data->window);
38e2f4644548 Set up window focus correctly when using an existing X11 window.
Ryan C. Gordon <icculus@icculus.org>
parents: 6023
diff changeset
   211
        }
38e2f4644548 Set up window focus correctly when using an existing X11 window.
Ryan C. Gordon <icculus@icculus.org>
parents: 6023
diff changeset
   212
38e2f4644548 Set up window focus correctly when using an existing X11 window.
Ryan C. Gordon <icculus@icculus.org>
parents: 6023
diff changeset
   213
        if (window->flags & SDL_WINDOW_INPUT_GRABBED) {
38e2f4644548 Set up window focus correctly when using an existing X11 window.
Ryan C. Gordon <icculus@icculus.org>
parents: 6023
diff changeset
   214
            /* Tell x11 to clip mouse */
38e2f4644548 Set up window focus correctly when using an existing X11 window.
Ryan C. Gordon <icculus@icculus.org>
parents: 6023
diff changeset
   215
        }
38e2f4644548 Set up window focus correctly when using an existing X11 window.
Ryan C. Gordon <icculus@icculus.org>
parents: 6023
diff changeset
   216
    }
38e2f4644548 Set up window focus correctly when using an existing X11 window.
Ryan C. Gordon <icculus@icculus.org>
parents: 6023
diff changeset
   217
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   218
    /* FIXME: How can I tell?
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   219
       {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   220
       DWORD style = GetWindowLong(hwnd, GWL_STYLE);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   221
       if (style & WS_VISIBLE) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   222
       if (style & (WS_BORDER | WS_THICKFRAME)) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   223
       window->flags &= ~SDL_WINDOW_BORDERLESS;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   224
       } else {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   225
       window->flags |= SDL_WINDOW_BORDERLESS;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   226
       }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   227
       if (style & WS_THICKFRAME) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   228
       window->flags |= SDL_WINDOW_RESIZABLE;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   229
       } else {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   230
       window->flags &= ~SDL_WINDOW_RESIZABLE;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   231
       }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   232
       if (style & WS_MINIMIZE) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   233
       window->flags |= SDL_WINDOW_MINIMIZED;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   234
       } else {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   235
       window->flags &= ~SDL_WINDOW_MINIMIZED;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   236
       }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   237
       }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   238
       if (GetFocus() == hwnd) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   239
       int index = data->videodata->keyboard;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   240
       window->flags |= SDL_WINDOW_INPUT_FOCUS;
3685
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3241
diff changeset
   241
       SDL_SetKeyboardFocus(index, data->window);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   242
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   243
       if (window->flags & SDL_WINDOW_INPUT_GRABBED) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   244
       RECT rect;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   245
       GetClientRect(hwnd, &rect);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   246
       ClientToScreen(hwnd, (LPPOINT) & rect);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   247
       ClientToScreen(hwnd, (LPPOINT) & rect + 1);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   248
       ClipCursor(&rect);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   249
       }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   250
       }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   251
     */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   252
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   253
    /* All done! */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   254
    window->driverdata = data;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   255
    return 0;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   256
}
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   257
6422
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   258
static void
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   259
SetWindowBordered(Display *display, int screen, Window window, SDL_bool border)
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   260
{
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   261
    /*
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   262
     * this code used to check for KWM_WIN_DECORATION, but KDE hasn't
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   263
     *  supported it for years and years. It now respects _MOTIF_WM_HINTS.
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   264
     *  Gnome is similar: just use the Motif atom.
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   265
     */
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   266
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   267
    Atom WM_HINTS = XInternAtom(display, "_MOTIF_WM_HINTS", True);
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   268
    if (WM_HINTS != None) {
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   269
        /* Hints used by Motif compliant window managers */
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   270
        struct
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   271
        {
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   272
            unsigned long flags;
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   273
            unsigned long functions;
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   274
            unsigned long decorations;
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   275
            long input_mode;
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   276
            unsigned long status;
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   277
        } MWMHints = {
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   278
            (1L << 1), 0, border ? 1 : 0, 0, 0
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   279
        };
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   280
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   281
        XChangeProperty(display, window, WM_HINTS, WM_HINTS, 32,
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   282
                        PropModeReplace, (unsigned char *) &MWMHints,
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   283
                        sizeof(MWMHints) / 4);
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   284
    } else {  /* set the transient hints instead, if necessary */
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   285
        XSetTransientForHint(display, window, RootWindow(display, screen));
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   286
    }
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   287
}
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   288
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   289
int
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   290
X11_CreateWindow(_THIS, SDL_Window * window)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   291
{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   292
    SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   293
    SDL_DisplayData *displaydata =
5246
58265e606e4e Window coordinates are in the global space and windows are not tied to a particular display.
Sam Lantinga <slouken@libsdl.org>
parents: 5243
diff changeset
   294
        (SDL_DisplayData *) SDL_GetDisplayForWindow(window)->driverdata;
4521
50125e8aab94 Let the window manager know we're a "normal" window
Sam Lantinga <slouken@libsdl.org>
parents: 4520
diff changeset
   295
    Display *display = data->display;
50125e8aab94 Let the window manager know we're a "normal" window
Sam Lantinga <slouken@libsdl.org>
parents: 4520
diff changeset
   296
    int screen = displaydata->screen;
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   297
    Visual *visual;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   298
    int depth;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   299
    XSetWindowAttributes xattr;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   300
    Window w;
6462
5e09ac1aba80 allocate *Hint structures per Xlib docs
Edward Rudd <urkle@outoforder.cc>
parents: 6423
diff changeset
   301
    XSizeHints *sizehints;
5e09ac1aba80 allocate *Hint structures per Xlib docs
Edward Rudd <urkle@outoforder.cc>
parents: 6423
diff changeset
   302
    XWMHints *wmhints;
5e09ac1aba80 allocate *Hint structures per Xlib docs
Edward Rudd <urkle@outoforder.cc>
parents: 6423
diff changeset
   303
    XClassHint *classhints;
4521
50125e8aab94 Let the window manager know we're a "normal" window
Sam Lantinga <slouken@libsdl.org>
parents: 4520
diff changeset
   304
    Atom _NET_WM_WINDOW_TYPE;
50125e8aab94 Let the window manager know we're a "normal" window
Sam Lantinga <slouken@libsdl.org>
parents: 4520
diff changeset
   305
    Atom _NET_WM_WINDOW_TYPE_NORMAL;
6167
c071e1372341 X11: Move to XSetWMProperties and add support to _NET_WM_PID
Marco Trevisan (Treviño) <mail@3v1n0.net>
parents: 6138
diff changeset
   306
    Atom _NET_WM_PID;
4522
a4da6b906abb Fixed setting fullscreen and maximized states for windows that haven't been mapped yet.
Sam Lantinga <slouken@libsdl.org>
parents: 4521
diff changeset
   307
    int wmstate_count;
a4da6b906abb Fixed setting fullscreen and maximized states for windows that haven't been mapped yet.
Sam Lantinga <slouken@libsdl.org>
parents: 4521
diff changeset
   308
    Atom wmstate_atoms[3];
6045
b8e995dab018 Fix crash on X servers without UTF-8 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 6024
diff changeset
   309
    Uint32 fevent = 0;
4518
a956a315fe67 Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents: 4510
diff changeset
   310
6369
a92fbd27127b Fix OpenGL initialization when OpenGL and OpenGLES are both available.
Sam Lantinga <slouken@libsdl.org>
parents: 6343
diff changeset
   311
#if SDL_VIDEO_OPENGL_GLX || SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   312
    if (window->flags & SDL_WINDOW_OPENGL) {
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1951
diff changeset
   313
        XVisualInfo *vinfo;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1951
diff changeset
   314
6370
93187f7f7d5d Improved simultaneous support for OpenGL and OpenGL ES
Sam Lantinga <slouken@libsdl.org>
parents: 6369
diff changeset
   315
#if SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2        
93187f7f7d5d Improved simultaneous support for OpenGL and OpenGL ES
Sam Lantinga <slouken@libsdl.org>
parents: 6369
diff changeset
   316
        if (_this->gl_config.use_egl == 1) {
6369
a92fbd27127b Fix OpenGL initialization when OpenGL and OpenGLES are both available.
Sam Lantinga <slouken@libsdl.org>
parents: 6343
diff changeset
   317
            vinfo = X11_GLES_GetVisual(_this, display, screen);
a92fbd27127b Fix OpenGL initialization when OpenGL and OpenGLES are both available.
Sam Lantinga <slouken@libsdl.org>
parents: 6343
diff changeset
   318
        } else
a92fbd27127b Fix OpenGL initialization when OpenGL and OpenGLES are both available.
Sam Lantinga <slouken@libsdl.org>
parents: 6343
diff changeset
   319
#endif
a92fbd27127b Fix OpenGL initialization when OpenGL and OpenGLES are both available.
Sam Lantinga <slouken@libsdl.org>
parents: 6343
diff changeset
   320
        {
6370
93187f7f7d5d Improved simultaneous support for OpenGL and OpenGL ES
Sam Lantinga <slouken@libsdl.org>
parents: 6369
diff changeset
   321
#if SDL_VIDEO_OPENGL_GLX
6369
a92fbd27127b Fix OpenGL initialization when OpenGL and OpenGLES are both available.
Sam Lantinga <slouken@libsdl.org>
parents: 6343
diff changeset
   322
            vinfo = X11_GL_GetVisual(_this, display, screen);
6370
93187f7f7d5d Improved simultaneous support for OpenGL and OpenGL ES
Sam Lantinga <slouken@libsdl.org>
parents: 6369
diff changeset
   323
#endif
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1951
diff changeset
   324
        }
3161
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3078
diff changeset
   325
        if (!vinfo) {
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3078
diff changeset
   326
            return -1;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3078
diff changeset
   327
        }
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3078
diff changeset
   328
        visual = vinfo->visual;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3078
diff changeset
   329
        depth = vinfo->depth;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3078
diff changeset
   330
        XFree(vinfo);
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3078
diff changeset
   331
    } else
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3078
diff changeset
   332
#endif
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1951
diff changeset
   333
    {
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   334
        visual = displaydata->visual;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   335
        depth = displaydata->depth;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   336
    }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   337
5386
762e67f81fc7 Simplified the X11 window creation
Sam Lantinga <slouken@libsdl.org>
parents: 5305
diff changeset
   338
    xattr.override_redirect = False;
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   339
    xattr.background_pixel = 0;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   340
    xattr.border_pixel = 0;
5466
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   341
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   342
    if (visual->class == DirectColor) {
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   343
        XColor *colorcells;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   344
        int i;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   345
        int ncolors;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   346
        int rmax, gmax, bmax;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   347
        int rmask, gmask, bmask;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   348
        int rshift, gshift, bshift;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   349
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   350
        xattr.colormap =
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   351
            XCreateColormap(display, RootWindow(display, screen),
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   352
                            visual, AllocAll);
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   353
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   354
        /* If we can't create a colormap, then we must die */
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   355
        if (!xattr.colormap) {
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   356
            SDL_SetError("Could not create writable colormap");
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   357
            return -1;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   358
        }
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   359
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   360
        /* OK, we got a colormap, now fill it in as best as we can */
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   361
        colorcells = SDL_malloc(visual->map_entries * sizeof(XColor));
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   362
        if (!colorcells) {
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   363
            SDL_OutOfMemory();
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   364
            return -1;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   365
        }
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   366
        ncolors = visual->map_entries;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   367
        rmax = 0xffff;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   368
        gmax = 0xffff;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   369
        bmax = 0xffff;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   370
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   371
        rshift = 0;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   372
        rmask = visual->red_mask;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   373
        while (0 == (rmask & 1)) {
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   374
            rshift++;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   375
            rmask >>= 1;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   376
        }
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   377
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   378
        gshift = 0;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   379
        gmask = visual->green_mask;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   380
        while (0 == (gmask & 1)) {
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   381
            gshift++;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   382
            gmask >>= 1;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   383
        }
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   384
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   385
        bshift = 0;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   386
        bmask = visual->blue_mask;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   387
        while (0 == (bmask & 1)) {
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   388
            bshift++;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   389
            bmask >>= 1;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   390
        }
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   391
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   392
        /* build the color table pixel values */
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   393
        for (i = 0; i < ncolors; i++) {
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   394
            Uint32 red = (rmax * i) / (ncolors - 1);
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   395
            Uint32 green = (gmax * i) / (ncolors - 1);
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   396
            Uint32 blue = (bmax * i) / (ncolors - 1);
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   397
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   398
            Uint32 rbits = (rmask * i) / (ncolors - 1);
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   399
            Uint32 gbits = (gmask * i) / (ncolors - 1);
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   400
            Uint32 bbits = (bmask * i) / (ncolors - 1);
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   401
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   402
            Uint32 pix =
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   403
                (rbits << rshift) | (gbits << gshift) | (bbits << bshift);
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   404
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   405
            colorcells[i].pixel = pix;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   406
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   407
            colorcells[i].red = red;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   408
            colorcells[i].green = green;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   409
            colorcells[i].blue = blue;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   410
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   411
            colorcells[i].flags = DoRed | DoGreen | DoBlue;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   412
        }
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   413
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   414
        XStoreColors(display, xattr.colormap, colorcells, ncolors);
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   415
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   416
        SDL_free(colorcells);
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   417
    } else {
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   418
        xattr.colormap =
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   419
            XCreateColormap(display, RootWindow(display, screen),
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   420
                            visual, AllocNone);
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   421
    }
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   422
5386
762e67f81fc7 Simplified the X11 window creation
Sam Lantinga <slouken@libsdl.org>
parents: 5305
diff changeset
   423
    w = XCreateWindow(display, RootWindow(display, screen),
762e67f81fc7 Simplified the X11 window creation
Sam Lantinga <slouken@libsdl.org>
parents: 5305
diff changeset
   424
                      window->x, window->y, window->w, window->h,
762e67f81fc7 Simplified the X11 window creation
Sam Lantinga <slouken@libsdl.org>
parents: 5305
diff changeset
   425
                      0, depth, InputOutput, visual,
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   426
                      (CWOverrideRedirect | CWBackPixel | CWBorderPixel |
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   427
                       CWColormap), &xattr);
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1951
diff changeset
   428
    if (!w) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1951
diff changeset
   429
        SDL_SetError("Couldn't create window");
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1951
diff changeset
   430
        return -1;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1951
diff changeset
   431
    }
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6167
diff changeset
   432
#if SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
6373
494e0436525f More OpenGL ES fixes from Scott Percival
Sam Lantinga <slouken@libsdl.org>
parents: 6370
diff changeset
   433
    if ((window->flags & SDL_WINDOW_OPENGL) && (_this->gl_config.use_egl == 1)) {
494e0436525f More OpenGL ES fixes from Scott Percival
Sam Lantinga <slouken@libsdl.org>
parents: 6370
diff changeset
   434
        if (!_this->gles_data) {
494e0436525f More OpenGL ES fixes from Scott Percival
Sam Lantinga <slouken@libsdl.org>
parents: 6370
diff changeset
   435
            XDestroyWindow(display, w);
494e0436525f More OpenGL ES fixes from Scott Percival
Sam Lantinga <slouken@libsdl.org>
parents: 6370
diff changeset
   436
            return -1;
494e0436525f More OpenGL ES fixes from Scott Percival
Sam Lantinga <slouken@libsdl.org>
parents: 6370
diff changeset
   437
        }
494e0436525f More OpenGL ES fixes from Scott Percival
Sam Lantinga <slouken@libsdl.org>
parents: 6370
diff changeset
   438
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6167
diff changeset
   439
        /* Create the GLES window surface */
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6167
diff changeset
   440
        _this->gles_data->egl_surface =
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6167
diff changeset
   441
            _this->gles_data->eglCreateWindowSurface(_this->gles_data->
3161
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3078
diff changeset
   442
                                                 egl_display,
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3078
diff changeset
   443
                                                 _this->gles_data->egl_config,
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3078
diff changeset
   444
                                                 (NativeWindowType) w, NULL);
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3078
diff changeset
   445
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6167
diff changeset
   446
        if (_this->gles_data->egl_surface == EGL_NO_SURFACE) {
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6167
diff changeset
   447
            SDL_SetError("Could not create GLES window surface");
6373
494e0436525f More OpenGL ES fixes from Scott Percival
Sam Lantinga <slouken@libsdl.org>
parents: 6370
diff changeset
   448
            XDestroyWindow(display, w);
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6167
diff changeset
   449
            return -1;
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6167
diff changeset
   450
        }
3161
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3078
diff changeset
   451
    }
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3078
diff changeset
   452
#endif
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   453
6422
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   454
    SetWindowBordered(display, screen, w,
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   455
                      (window->flags & SDL_WINDOW_BORDERLESS) == 0);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   456
6462
5e09ac1aba80 allocate *Hint structures per Xlib docs
Edward Rudd <urkle@outoforder.cc>
parents: 6423
diff changeset
   457
    sizehints = XAllocSizeHints();
6167
c071e1372341 X11: Move to XSetWMProperties and add support to _NET_WM_PID
Marco Trevisan (Treviño) <mail@3v1n0.net>
parents: 6138
diff changeset
   458
    /* Setup the normal size hints */
6462
5e09ac1aba80 allocate *Hint structures per Xlib docs
Edward Rudd <urkle@outoforder.cc>
parents: 6423
diff changeset
   459
    sizehints->flags = 0;
6167
c071e1372341 X11: Move to XSetWMProperties and add support to _NET_WM_PID
Marco Trevisan (Treviño) <mail@3v1n0.net>
parents: 6138
diff changeset
   460
    if (!(window->flags & SDL_WINDOW_RESIZABLE)) {
6462
5e09ac1aba80 allocate *Hint structures per Xlib docs
Edward Rudd <urkle@outoforder.cc>
parents: 6423
diff changeset
   461
        sizehints->min_width = sizehints->max_width = window->w;
5e09ac1aba80 allocate *Hint structures per Xlib docs
Edward Rudd <urkle@outoforder.cc>
parents: 6423
diff changeset
   462
        sizehints->min_height = sizehints->max_height = window->h;
5e09ac1aba80 allocate *Hint structures per Xlib docs
Edward Rudd <urkle@outoforder.cc>
parents: 6423
diff changeset
   463
        sizehints->flags |= (PMaxSize | PMinSize);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   464
    }
6462
5e09ac1aba80 allocate *Hint structures per Xlib docs
Edward Rudd <urkle@outoforder.cc>
parents: 6423
diff changeset
   465
    sizehints->x = window->x;
5e09ac1aba80 allocate *Hint structures per Xlib docs
Edward Rudd <urkle@outoforder.cc>
parents: 6423
diff changeset
   466
    sizehints->y = window->y;
5e09ac1aba80 allocate *Hint structures per Xlib docs
Edward Rudd <urkle@outoforder.cc>
parents: 6423
diff changeset
   467
    sizehints->flags |= USPosition;
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   468
6167
c071e1372341 X11: Move to XSetWMProperties and add support to _NET_WM_PID
Marco Trevisan (Treviño) <mail@3v1n0.net>
parents: 6138
diff changeset
   469
    /* Setup the input hints so we get keyboard input */
6462
5e09ac1aba80 allocate *Hint structures per Xlib docs
Edward Rudd <urkle@outoforder.cc>
parents: 6423
diff changeset
   470
    wmhints = XAllocWMHints();
5e09ac1aba80 allocate *Hint structures per Xlib docs
Edward Rudd <urkle@outoforder.cc>
parents: 6423
diff changeset
   471
    wmhints->input = True;
5e09ac1aba80 allocate *Hint structures per Xlib docs
Edward Rudd <urkle@outoforder.cc>
parents: 6423
diff changeset
   472
    wmhints->flags = InputHint;
6167
c071e1372341 X11: Move to XSetWMProperties and add support to _NET_WM_PID
Marco Trevisan (Treviño) <mail@3v1n0.net>
parents: 6138
diff changeset
   473
c071e1372341 X11: Move to XSetWMProperties and add support to _NET_WM_PID
Marco Trevisan (Treviño) <mail@3v1n0.net>
parents: 6138
diff changeset
   474
    /* Setup the class hints so we can get an icon (AfterStep) */
6462
5e09ac1aba80 allocate *Hint structures per Xlib docs
Edward Rudd <urkle@outoforder.cc>
parents: 6423
diff changeset
   475
    classhints = XAllocClassHint();
5e09ac1aba80 allocate *Hint structures per Xlib docs
Edward Rudd <urkle@outoforder.cc>
parents: 6423
diff changeset
   476
    classhints->res_name = data->classname;
5e09ac1aba80 allocate *Hint structures per Xlib docs
Edward Rudd <urkle@outoforder.cc>
parents: 6423
diff changeset
   477
    classhints->res_class = data->classname;
6167
c071e1372341 X11: Move to XSetWMProperties and add support to _NET_WM_PID
Marco Trevisan (Treviño) <mail@3v1n0.net>
parents: 6138
diff changeset
   478
c071e1372341 X11: Move to XSetWMProperties and add support to _NET_WM_PID
Marco Trevisan (Treviño) <mail@3v1n0.net>
parents: 6138
diff changeset
   479
    /* Set the size, input and class hints, and define WM_CLIENT_MACHINE and WM_LOCALE_NAME */
6462
5e09ac1aba80 allocate *Hint structures per Xlib docs
Edward Rudd <urkle@outoforder.cc>
parents: 6423
diff changeset
   480
    XSetWMProperties(display, w, NULL, NULL, NULL, 0, sizehints, wmhints, classhints);
6167
c071e1372341 X11: Move to XSetWMProperties and add support to _NET_WM_PID
Marco Trevisan (Treviño) <mail@3v1n0.net>
parents: 6138
diff changeset
   481
6462
5e09ac1aba80 allocate *Hint structures per Xlib docs
Edward Rudd <urkle@outoforder.cc>
parents: 6423
diff changeset
   482
    XFree(sizehints);
5e09ac1aba80 allocate *Hint structures per Xlib docs
Edward Rudd <urkle@outoforder.cc>
parents: 6423
diff changeset
   483
    XFree(wmhints);
5e09ac1aba80 allocate *Hint structures per Xlib docs
Edward Rudd <urkle@outoforder.cc>
parents: 6423
diff changeset
   484
    XFree(classhints);
6167
c071e1372341 X11: Move to XSetWMProperties and add support to _NET_WM_PID
Marco Trevisan (Treviño) <mail@3v1n0.net>
parents: 6138
diff changeset
   485
    /* Set the PID related to the window for the given hostname, if possible */
c071e1372341 X11: Move to XSetWMProperties and add support to _NET_WM_PID
Marco Trevisan (Treviño) <mail@3v1n0.net>
parents: 6138
diff changeset
   486
    if (data->pid > 0) {
c071e1372341 X11: Move to XSetWMProperties and add support to _NET_WM_PID
Marco Trevisan (Treviño) <mail@3v1n0.net>
parents: 6138
diff changeset
   487
        _NET_WM_PID = XInternAtom(display, "_NET_WM_PID", False);
c071e1372341 X11: Move to XSetWMProperties and add support to _NET_WM_PID
Marco Trevisan (Treviño) <mail@3v1n0.net>
parents: 6138
diff changeset
   488
        XChangeProperty(display, w, _NET_WM_PID, XA_CARDINAL, 32, PropModeReplace,
c071e1372341 X11: Move to XSetWMProperties and add support to _NET_WM_PID
Marco Trevisan (Treviño) <mail@3v1n0.net>
parents: 6138
diff changeset
   489
                        (unsigned char *)&data->pid, 1);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   490
    }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   491
4522
a4da6b906abb Fixed setting fullscreen and maximized states for windows that haven't been mapped yet.
Sam Lantinga <slouken@libsdl.org>
parents: 4521
diff changeset
   492
    /* Set the window manager state */
a4da6b906abb Fixed setting fullscreen and maximized states for windows that haven't been mapped yet.
Sam Lantinga <slouken@libsdl.org>
parents: 4521
diff changeset
   493
    wmstate_count = X11_GetWMStateProperty(_this, window, wmstate_atoms);
a4da6b906abb Fixed setting fullscreen and maximized states for windows that haven't been mapped yet.
Sam Lantinga <slouken@libsdl.org>
parents: 4521
diff changeset
   494
    if (wmstate_count > 0) {
a4da6b906abb Fixed setting fullscreen and maximized states for windows that haven't been mapped yet.
Sam Lantinga <slouken@libsdl.org>
parents: 4521
diff changeset
   495
        XChangeProperty(display, w, data->_NET_WM_STATE, XA_ATOM, 32,
a4da6b906abb Fixed setting fullscreen and maximized states for windows that haven't been mapped yet.
Sam Lantinga <slouken@libsdl.org>
parents: 4521
diff changeset
   496
                        PropModeReplace,
a4da6b906abb Fixed setting fullscreen and maximized states for windows that haven't been mapped yet.
Sam Lantinga <slouken@libsdl.org>
parents: 4521
diff changeset
   497
                        (unsigned char *)wmstate_atoms, wmstate_count);
a4da6b906abb Fixed setting fullscreen and maximized states for windows that haven't been mapped yet.
Sam Lantinga <slouken@libsdl.org>
parents: 4521
diff changeset
   498
    } else {
a4da6b906abb Fixed setting fullscreen and maximized states for windows that haven't been mapped yet.
Sam Lantinga <slouken@libsdl.org>
parents: 4521
diff changeset
   499
        XDeleteProperty(display, w, data->_NET_WM_STATE);
4518
a956a315fe67 Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents: 4510
diff changeset
   500
    }
a956a315fe67 Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents: 4510
diff changeset
   501
4521
50125e8aab94 Let the window manager know we're a "normal" window
Sam Lantinga <slouken@libsdl.org>
parents: 4520
diff changeset
   502
    /* Let the window manager know we're a "normal" window */
50125e8aab94 Let the window manager know we're a "normal" window
Sam Lantinga <slouken@libsdl.org>
parents: 4520
diff changeset
   503
    _NET_WM_WINDOW_TYPE = XInternAtom(display, "_NET_WM_WINDOW_TYPE", False);
50125e8aab94 Let the window manager know we're a "normal" window
Sam Lantinga <slouken@libsdl.org>
parents: 4520
diff changeset
   504
    _NET_WM_WINDOW_TYPE_NORMAL = XInternAtom(display, "_NET_WM_WINDOW_TYPE_NORMAL", False);
50125e8aab94 Let the window manager know we're a "normal" window
Sam Lantinga <slouken@libsdl.org>
parents: 4520
diff changeset
   505
    XChangeProperty(display, w, _NET_WM_WINDOW_TYPE, XA_ATOM, 32,
50125e8aab94 Let the window manager know we're a "normal" window
Sam Lantinga <slouken@libsdl.org>
parents: 4520
diff changeset
   506
                    PropModeReplace,
50125e8aab94 Let the window manager know we're a "normal" window
Sam Lantinga <slouken@libsdl.org>
parents: 4520
diff changeset
   507
                    (unsigned char *)&_NET_WM_WINDOW_TYPE_NORMAL, 1);
50125e8aab94 Let the window manager know we're a "normal" window
Sam Lantinga <slouken@libsdl.org>
parents: 4520
diff changeset
   508
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   509
    /* Allow the window to be deleted by the window manager */
4521
50125e8aab94 Let the window manager know we're a "normal" window
Sam Lantinga <slouken@libsdl.org>
parents: 4520
diff changeset
   510
    XSetWMProtocols(display, w, &data->WM_DELETE_WINDOW, 1);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   511
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   512
    if (SetupWindowData(_this, window, w, SDL_TRUE) < 0) {
4521
50125e8aab94 Let the window manager know we're a "normal" window
Sam Lantinga <slouken@libsdl.org>
parents: 4520
diff changeset
   513
        XDestroyWindow(display, w);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   514
        return -1;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   515
    }
5386
762e67f81fc7 Simplified the X11 window creation
Sam Lantinga <slouken@libsdl.org>
parents: 5305
diff changeset
   516
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
   517
#ifdef X_HAVE_UTF8_STRING
6045
b8e995dab018 Fix crash on X servers without UTF-8 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 6024
diff changeset
   518
    if (SDL_X11_HAVE_UTF8) {
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
   519
        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
   520
                      XNFilterEvents, &fevent, NULL);
2718
abacf2555bb4 Removed unneccesary code lines. Fixed mousename bug. Added lacking code in mousebutton
Szymon Wilczek <kazeuser@gmail.com>
parents: 2710
diff changeset
   521
    }
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
   522
#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
   523
6316
a89c79a3f0cd 1.Moved all xinput2 functionality to its own file
Dimitris Zenios <dimitris.zenios@gmail.com>
parents: 6275
diff changeset
   524
    X11_Xinput2SelectTouch(_this, window);
a89c79a3f0cd 1.Moved all xinput2 functionality to its own file
Dimitris Zenios <dimitris.zenios@gmail.com>
parents: 6275
diff changeset
   525
6045
b8e995dab018 Fix crash on X servers without UTF-8 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 6024
diff changeset
   526
    XSelectInput(display, w,
b8e995dab018 Fix crash on X servers without UTF-8 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 6024
diff changeset
   527
                 (FocusChangeMask | EnterWindowMask | LeaveWindowMask |
b8e995dab018 Fix crash on X servers without UTF-8 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 6024
diff changeset
   528
                 ExposureMask | ButtonPressMask | ButtonReleaseMask |
b8e995dab018 Fix crash on X servers without UTF-8 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 6024
diff changeset
   529
                 PointerMotionMask | KeyPressMask | KeyReleaseMask |
b8e995dab018 Fix crash on X servers without UTF-8 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 6024
diff changeset
   530
                 PropertyChangeMask | StructureNotifyMask |
b8e995dab018 Fix crash on X servers without UTF-8 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 6024
diff changeset
   531
                 KeymapStateMask | fevent));
b8e995dab018 Fix crash on X servers without UTF-8 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 6024
diff changeset
   532
5031
5e3291605ad0 Added XFlush() so changes happen immediately instead of waiting for the next event loop.
Sam Lantinga <slouken@libsdl.org>
parents: 4937
diff changeset
   533
    XFlush(display);
5e3291605ad0 Added XFlush() so changes happen immediately instead of waiting for the next event loop.
Sam Lantinga <slouken@libsdl.org>
parents: 4937
diff changeset
   534
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   535
    return 0;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   536
}
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   537
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   538
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
   539
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
   540
{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   541
    Window w = (Window) data;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   542
4518
a956a315fe67 Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents: 4510
diff changeset
   543
    window->title = X11_GetWindowTitle(_this, w);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   544
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   545
    if (SetupWindowData(_this, window, w, SDL_FALSE) < 0) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   546
        return -1;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   547
    }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   548
    return 0;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   549
}
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   550
4518
a956a315fe67 Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents: 4510
diff changeset
   551
char *
a956a315fe67 Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents: 4510
diff changeset
   552
X11_GetWindowTitle(_THIS, Window xwindow)
a956a315fe67 Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents: 4510
diff changeset
   553
{
a956a315fe67 Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents: 4510
diff changeset
   554
    SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
a956a315fe67 Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents: 4510
diff changeset
   555
    Display *display = data->display;
a956a315fe67 Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents: 4510
diff changeset
   556
    int status, real_format;
a956a315fe67 Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents: 4510
diff changeset
   557
    Atom real_type;
a956a315fe67 Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents: 4510
diff changeset
   558
    unsigned long items_read, items_left;
a956a315fe67 Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents: 4510
diff changeset
   559
    unsigned char *propdata;
a956a315fe67 Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents: 4510
diff changeset
   560
    char *title = NULL;
a956a315fe67 Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents: 4510
diff changeset
   561
a956a315fe67 Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents: 4510
diff changeset
   562
    status = XGetWindowProperty(display, xwindow, data->_NET_WM_NAME,
a956a315fe67 Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents: 4510
diff changeset
   563
                0L, 8192L, False, data->UTF8_STRING, &real_type, &real_format,
a956a315fe67 Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents: 4510
diff changeset
   564
                &items_read, &items_left, &propdata);
6023
6279958d571d XGetWindowProperty() can report success but still give you a NULL pointer.
Ryan C. Gordon <icculus@icculus.org>
parents: 5981
diff changeset
   565
    if (status == Success && propdata) {
4518
a956a315fe67 Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents: 4510
diff changeset
   566
        title = SDL_strdup(SDL_static_cast(char*, propdata));
a956a315fe67 Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents: 4510
diff changeset
   567
        XFree(propdata);
a956a315fe67 Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents: 4510
diff changeset
   568
    } else {
a956a315fe67 Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents: 4510
diff changeset
   569
        status = XGetWindowProperty(display, xwindow, XA_WM_NAME,
a956a315fe67 Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents: 4510
diff changeset
   570
                    0L, 8192L, False, XA_STRING, &real_type, &real_format,
a956a315fe67 Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents: 4510
diff changeset
   571
                    &items_read, &items_left, &propdata);
6023
6279958d571d XGetWindowProperty() can report success but still give you a NULL pointer.
Ryan C. Gordon <icculus@icculus.org>
parents: 5981
diff changeset
   572
        if (status == Success && propdata) {
4518
a956a315fe67 Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents: 4510
diff changeset
   573
            title = SDL_iconv_string("UTF-8", "", SDL_static_cast(char*, propdata), items_read+1);
a956a315fe67 Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents: 4510
diff changeset
   574
        } else {
a956a315fe67 Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents: 4510
diff changeset
   575
            title = SDL_strdup("");
a956a315fe67 Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents: 4510
diff changeset
   576
        }
a956a315fe67 Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents: 4510
diff changeset
   577
    }
a956a315fe67 Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents: 4510
diff changeset
   578
    return title;
a956a315fe67 Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents: 4510
diff changeset
   579
}
a956a315fe67 Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents: 4510
diff changeset
   580
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   581
void
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   582
X11_SetWindowTitle(_THIS, SDL_Window * window)
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
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   585
    Display *display = data->videodata->display;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   586
    XTextProperty titleprop, iconprop;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   587
    Status status;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   588
    const char *title = window->title;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   589
    const char *icon = NULL;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   590
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   591
#ifdef X_HAVE_UTF8_STRING
4518
a956a315fe67 Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents: 4510
diff changeset
   592
    Atom _NET_WM_NAME = data->videodata->_NET_WM_NAME;
a956a315fe67 Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents: 4510
diff changeset
   593
    Atom _NET_WM_ICON_NAME = data->videodata->_NET_WM_ICON_NAME;
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   594
#endif
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   595
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   596
    if (title != NULL) {
2143
e906da4414a3 Fix for bug #447 merged from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents: 1956
diff changeset
   597
        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
   598
        if (!title_locale) {
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   599
            SDL_OutOfMemory();
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   600
            return;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   601
        }
2143
e906da4414a3 Fix for bug #447 merged from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents: 1956
diff changeset
   602
        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
   603
        SDL_free(title_locale);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   604
        if (status) {
3685
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3241
diff changeset
   605
            XSetTextProperty(display, data->xwindow, &titleprop, XA_WM_NAME);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   606
            XFree(titleprop.value);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   607
        }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   608
#ifdef X_HAVE_UTF8_STRING
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   609
        if (SDL_X11_HAVE_UTF8) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   610
            status =
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   611
                Xutf8TextListToTextProperty(display, (char **) &title, 1,
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   612
                                            XUTF8StringStyle, &titleprop);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   613
            if (status == Success) {
3685
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3241
diff changeset
   614
                XSetTextProperty(display, data->xwindow, &titleprop,
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   615
                                 _NET_WM_NAME);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   616
                XFree(titleprop.value);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   617
            }
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
#endif
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   620
    }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   621
    if (icon != NULL) {
2143
e906da4414a3 Fix for bug #447 merged from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents: 1956
diff changeset
   622
        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
   623
        if (!icon_locale) {
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   624
            SDL_OutOfMemory();
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   625
            return;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   626
        }
2143
e906da4414a3 Fix for bug #447 merged from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents: 1956
diff changeset
   627
        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
   628
        SDL_free(icon_locale);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   629
        if (status) {
3685
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3241
diff changeset
   630
            XSetTextProperty(display, data->xwindow, &iconprop,
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   631
                             XA_WM_ICON_NAME);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   632
            XFree(iconprop.value);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   633
        }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   634
#ifdef X_HAVE_UTF8_STRING
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   635
        if (SDL_X11_HAVE_UTF8) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   636
            status =
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   637
                Xutf8TextListToTextProperty(display, (char **) &icon, 1,
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   638
                                            XUTF8StringStyle, &iconprop);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   639
            if (status == Success) {
3685
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3241
diff changeset
   640
                XSetTextProperty(display, data->xwindow, &iconprop,
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   641
                                 _NET_WM_ICON_NAME);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   642
                XFree(iconprop.value);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   643
            }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   644
        }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   645
#endif
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   646
    }
5031
5e3291605ad0 Added XFlush() so changes happen immediately instead of waiting for the next event loop.
Sam Lantinga <slouken@libsdl.org>
parents: 4937
diff changeset
   647
    XFlush(display);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   648
}
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   649
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   650
void
2967
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
   651
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
   652
{
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
   653
    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
   654
    Display *display = data->videodata->display;
4518
a956a315fe67 Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents: 4510
diff changeset
   655
    Atom _NET_WM_ICON = data->videodata->_NET_WM_ICON;
2967
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
   656
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
   657
    if (icon) {
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
   658
        SDL_PixelFormat format;
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
   659
        SDL_Surface *surface;
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
   660
        int propsize;
4528
f06faa886423 Fixed bug 1022
Sam Lantinga <slouken@libsdl.org>
parents: 4524
diff changeset
   661
        long *propdata;
2967
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
   662
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
   663
        /* Convert the icon to ARGB for modern window managers */
5288
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   664
        SDL_InitFormat(&format, SDL_PIXELFORMAT_ARGB8888);
2967
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
   665
        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
   666
        if (!surface) {
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
   667
            return;
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
   668
        }
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
   669
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
   670
        /* Set the _NET_WM_ICON property */
2990
Sam Lantinga <slouken@libsdl.org>
parents: 2967
diff changeset
   671
        propsize = 2 + (icon->w * icon->h);
4566
40c833d951a1 Fixed memory corruption on AMD64
Sam Lantinga <slouken@libsdl.org>
parents: 4555
diff changeset
   672
        propdata = SDL_malloc(propsize * sizeof(long));
2967
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
   673
        if (propdata) {
4528
f06faa886423 Fixed bug 1022
Sam Lantinga <slouken@libsdl.org>
parents: 4524
diff changeset
   674
            int x, y;
f06faa886423 Fixed bug 1022
Sam Lantinga <slouken@libsdl.org>
parents: 4524
diff changeset
   675
            Uint32 *src;
f06faa886423 Fixed bug 1022
Sam Lantinga <slouken@libsdl.org>
parents: 4524
diff changeset
   676
            long *dst;
f06faa886423 Fixed bug 1022
Sam Lantinga <slouken@libsdl.org>
parents: 4524
diff changeset
   677
2967
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
   678
            propdata[0] = icon->w;
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
   679
            propdata[1] = icon->h;
4528
f06faa886423 Fixed bug 1022
Sam Lantinga <slouken@libsdl.org>
parents: 4524
diff changeset
   680
            dst = &propdata[2];
f06faa886423 Fixed bug 1022
Sam Lantinga <slouken@libsdl.org>
parents: 4524
diff changeset
   681
            for (y = 0; y < icon->h; ++y) {
f06faa886423 Fixed bug 1022
Sam Lantinga <slouken@libsdl.org>
parents: 4524
diff changeset
   682
                src = (Uint32*)((Uint8*)surface->pixels + y * surface->pitch);
f06faa886423 Fixed bug 1022
Sam Lantinga <slouken@libsdl.org>
parents: 4524
diff changeset
   683
                for (x = 0; x < icon->w; ++x) {
f06faa886423 Fixed bug 1022
Sam Lantinga <slouken@libsdl.org>
parents: 4524
diff changeset
   684
                    *dst++ = *src++;
f06faa886423 Fixed bug 1022
Sam Lantinga <slouken@libsdl.org>
parents: 4524
diff changeset
   685
                }
f06faa886423 Fixed bug 1022
Sam Lantinga <slouken@libsdl.org>
parents: 4524
diff changeset
   686
            }
3685
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3241
diff changeset
   687
            XChangeProperty(display, data->xwindow, _NET_WM_ICON, XA_CARDINAL,
2990
Sam Lantinga <slouken@libsdl.org>
parents: 2967
diff changeset
   688
                            32, PropModeReplace, (unsigned char *) propdata,
Sam Lantinga <slouken@libsdl.org>
parents: 2967
diff changeset
   689
                            propsize);
2967
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
   690
        }
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
   691
        SDL_FreeSurface(surface);
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
   692
    } else {
3685
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3241
diff changeset
   693
        XDeleteProperty(display, data->xwindow, _NET_WM_ICON);
2967
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
   694
    }
5031
5e3291605ad0 Added XFlush() so changes happen immediately instead of waiting for the next event loop.
Sam Lantinga <slouken@libsdl.org>
parents: 4937
diff changeset
   695
    XFlush(display);
2967
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
   696
}
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
   697
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
   698
void
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   699
X11_SetWindowPosition(_THIS, SDL_Window * window)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   700
{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   701
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   702
    Display *display = data->videodata->display;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   703
5478
6b65ff3cee62 Fixed bug 1167 (SDL_WINDOWPOS_CENTERED doesn't work if used right after fullscreen -> windowed switch)
Sam Lantinga <slouken@libsdl.org>
parents: 5466
diff changeset
   704
    XMoveWindow(display, data->xwindow, window->x, window->y);
5031
5e3291605ad0 Added XFlush() so changes happen immediately instead of waiting for the next event loop.
Sam Lantinga <slouken@libsdl.org>
parents: 4937
diff changeset
   705
    XFlush(display);
1951
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
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   708
void
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   709
X11_SetWindowSize(_THIS, SDL_Window * window)
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
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   712
    Display *display = data->videodata->display;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   713
4937
24d44c7c4c63 Don't crash when resizing non-shaped windows
Sam Lantinga <slouken@libsdl.org>
parents: 4902
diff changeset
   714
    if (SDL_IsShapedWindow(window))
4782
b6930aefd008 Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 3697
diff changeset
   715
        X11_ResizeWindowShape(window);
5531
477f550f6efd Fixed setting programmatically setting the size of a window on X11 for non-resizable windows.
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
   716
    if (!(window->flags & SDL_WINDOW_RESIZABLE)) {
477f550f6efd Fixed setting programmatically setting the size of a window on X11 for non-resizable windows.
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
   717
         /* Apparently, if the X11 Window is set to a 'non-resizable' window, you cannot resize it using the XResizeWindow, thus
477f550f6efd Fixed setting programmatically setting the size of a window on X11 for non-resizable windows.
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
   718
            we must set the size hints to adjust the window size.*/
477f550f6efd Fixed setting programmatically setting the size of a window on X11 for non-resizable windows.
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
   719
         XSizeHints *sizehints = XAllocSizeHints();
477f550f6efd Fixed setting programmatically setting the size of a window on X11 for non-resizable windows.
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
   720
         long userhints;
477f550f6efd Fixed setting programmatically setting the size of a window on X11 for non-resizable windows.
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
   721
477f550f6efd Fixed setting programmatically setting the size of a window on X11 for non-resizable windows.
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
   722
         XGetWMNormalHints(display, data->xwindow, sizehints, &userhints);
477f550f6efd Fixed setting programmatically setting the size of a window on X11 for non-resizable windows.
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
   723
6343
e94f912d20b9 Fix SDL_SetWindowSize with X11 non-RESIZABLE windows, patch by Pierre-Loup.
Sam Lantinga <slouken@libsdl.org>
parents: 6336
diff changeset
   724
         sizehints->min_width = sizehints->max_width = window->w;
5531
477f550f6efd Fixed setting programmatically setting the size of a window on X11 for non-resizable windows.
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
   725
         sizehints->min_height = sizehints->max_height = window->h;
477f550f6efd Fixed setting programmatically setting the size of a window on X11 for non-resizable windows.
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
   726
477f550f6efd Fixed setting programmatically setting the size of a window on X11 for non-resizable windows.
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
   727
         XSetWMNormalHints(display, data->xwindow, sizehints);
477f550f6efd Fixed setting programmatically setting the size of a window on X11 for non-resizable windows.
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
   728
477f550f6efd Fixed setting programmatically setting the size of a window on X11 for non-resizable windows.
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
   729
         XFree(sizehints);
477f550f6efd Fixed setting programmatically setting the size of a window on X11 for non-resizable windows.
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
   730
    } else
477f550f6efd Fixed setting programmatically setting the size of a window on X11 for non-resizable windows.
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
   731
        XResizeWindow(display, data->xwindow, window->w, window->h);
5031
5e3291605ad0 Added XFlush() so changes happen immediately instead of waiting for the next event loop.
Sam Lantinga <slouken@libsdl.org>
parents: 4937
diff changeset
   732
    XFlush(display);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   733
}
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   734
6422
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   735
void
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   736
X11_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered)
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   737
{
6423
339c0ccf6250 Make the X11 SetBordered event tapdancing more robust, restore focus, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 6422
diff changeset
   738
    const SDL_bool focused = ((window->flags & SDL_WINDOW_INPUT_FOCUS) != 0);
339c0ccf6250 Make the X11 SetBordered event tapdancing more robust, restore focus, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 6422
diff changeset
   739
    const SDL_bool visible = ((window->flags & SDL_WINDOW_HIDDEN) == 0);
6422
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   740
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   741
    SDL_DisplayData *displaydata =
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   742
        (SDL_DisplayData *) SDL_GetDisplayForWindow(window)->driverdata;
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   743
    Display *display = data->videodata->display;
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   744
    XEvent event;
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   745
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   746
    SetWindowBordered(display, displaydata->screen, data->xwindow, bordered);
6423
339c0ccf6250 Make the X11 SetBordered event tapdancing more robust, restore focus, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 6422
diff changeset
   747
    XFlush(display);
6422
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   748
    XIfEvent(display, &event, &isConfigureNotify, (XPointer)&data->xwindow);
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   749
6423
339c0ccf6250 Make the X11 SetBordered event tapdancing more robust, restore focus, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 6422
diff changeset
   750
    if (visible) {
339c0ccf6250 Make the X11 SetBordered event tapdancing more robust, restore focus, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 6422
diff changeset
   751
        XWindowAttributes attr;
339c0ccf6250 Make the X11 SetBordered event tapdancing more robust, restore focus, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 6422
diff changeset
   752
        do {
339c0ccf6250 Make the X11 SetBordered event tapdancing more robust, restore focus, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 6422
diff changeset
   753
            XSync(display, False);
339c0ccf6250 Make the X11 SetBordered event tapdancing more robust, restore focus, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 6422
diff changeset
   754
            XGetWindowAttributes(display, data->xwindow, &attr);
339c0ccf6250 Make the X11 SetBordered event tapdancing more robust, restore focus, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 6422
diff changeset
   755
        } while (attr.map_state != IsViewable);
339c0ccf6250 Make the X11 SetBordered event tapdancing more robust, restore focus, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 6422
diff changeset
   756
339c0ccf6250 Make the X11 SetBordered event tapdancing more robust, restore focus, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 6422
diff changeset
   757
        if (focused) {
339c0ccf6250 Make the X11 SetBordered event tapdancing more robust, restore focus, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 6422
diff changeset
   758
            XSetInputFocus(display, data->xwindow, RevertToParent, CurrentTime);
339c0ccf6250 Make the X11 SetBordered event tapdancing more robust, restore focus, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 6422
diff changeset
   759
        }
339c0ccf6250 Make the X11 SetBordered event tapdancing more robust, restore focus, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 6422
diff changeset
   760
    }
339c0ccf6250 Make the X11 SetBordered event tapdancing more robust, restore focus, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 6422
diff changeset
   761
6422
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   762
    /* make sure these don't make it to the real event queue if they fired here. */
6423
339c0ccf6250 Make the X11 SetBordered event tapdancing more robust, restore focus, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 6422
diff changeset
   763
    XSync(display, False);
339c0ccf6250 Make the X11 SetBordered event tapdancing more robust, restore focus, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 6422
diff changeset
   764
    XCheckIfEvent(display, &event, &isUnmapNotify, (XPointer)&data->xwindow);
339c0ccf6250 Make the X11 SetBordered event tapdancing more robust, restore focus, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 6422
diff changeset
   765
    XCheckIfEvent(display, &event, &isMapNotify, (XPointer)&data->xwindow);
6422
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   766
}
6336
6e6163b6ba69 Fixed issue with tiling window managers (bug 1246)
Sam Lantinga <slouken@libsdl.org>
parents: 6331
diff changeset
   767
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   768
void
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   769
X11_ShowWindow(_THIS, SDL_Window * window)
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
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   772
    Display *display = data->videodata->display;
6336
6e6163b6ba69 Fixed issue with tiling window managers (bug 1246)
Sam Lantinga <slouken@libsdl.org>
parents: 6331
diff changeset
   773
    XEvent event;
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   774
3685
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3241
diff changeset
   775
    XMapRaised(display, data->xwindow);
6336
6e6163b6ba69 Fixed issue with tiling window managers (bug 1246)
Sam Lantinga <slouken@libsdl.org>
parents: 6331
diff changeset
   776
    /* Blocking wait for "MapNotify" event.
6e6163b6ba69 Fixed issue with tiling window managers (bug 1246)
Sam Lantinga <slouken@libsdl.org>
parents: 6331
diff changeset
   777
     * We use XIfEvent because XWindowEvent takes a mask rather than a type, 
6e6163b6ba69 Fixed issue with tiling window managers (bug 1246)
Sam Lantinga <slouken@libsdl.org>
parents: 6331
diff changeset
   778
     * and XCheckTypedWindowEvent doesn't block */
6e6163b6ba69 Fixed issue with tiling window managers (bug 1246)
Sam Lantinga <slouken@libsdl.org>
parents: 6331
diff changeset
   779
    XIfEvent(display, &event, &isMapNotify, (XPointer)&data->xwindow);
5031
5e3291605ad0 Added XFlush() so changes happen immediately instead of waiting for the next event loop.
Sam Lantinga <slouken@libsdl.org>
parents: 4937
diff changeset
   780
    XFlush(display);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   781
}
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   782
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   783
void
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   784
X11_HideWindow(_THIS, SDL_Window * window)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   785
{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   786
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   787
    Display *display = data->videodata->display;
6336
6e6163b6ba69 Fixed issue with tiling window managers (bug 1246)
Sam Lantinga <slouken@libsdl.org>
parents: 6331
diff changeset
   788
    XEvent event;
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   789
3685
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3241
diff changeset
   790
    XUnmapWindow(display, data->xwindow);
6336
6e6163b6ba69 Fixed issue with tiling window managers (bug 1246)
Sam Lantinga <slouken@libsdl.org>
parents: 6331
diff changeset
   791
    /* Blocking wait for "UnmapNotify" event */
6e6163b6ba69 Fixed issue with tiling window managers (bug 1246)
Sam Lantinga <slouken@libsdl.org>
parents: 6331
diff changeset
   792
    XIfEvent(display, &event, &isUnmapNotify, (XPointer)&data->xwindow);    
5031
5e3291605ad0 Added XFlush() so changes happen immediately instead of waiting for the next event loop.
Sam Lantinga <slouken@libsdl.org>
parents: 4937
diff changeset
   793
    XFlush(display);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   794
}
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   795
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   796
void
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   797
X11_RaiseWindow(_THIS, SDL_Window * window)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   798
{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   799
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   800
    Display *display = data->videodata->display;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   801
3685
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3241
diff changeset
   802
    XRaiseWindow(display, data->xwindow);
5031
5e3291605ad0 Added XFlush() so changes happen immediately instead of waiting for the next event loop.
Sam Lantinga <slouken@libsdl.org>
parents: 4937
diff changeset
   803
    XFlush(display);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   804
}
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   805
3077
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   806
static void
5302
b1b9ec9874ba Implemented X11 fullscreen toggling with modern window managers
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   807
SetWindowMaximized(_THIS, SDL_Window * window, SDL_bool maximized)
3077
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   808
{
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   809
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   810
    SDL_DisplayData *displaydata =
5246
58265e606e4e Window coordinates are in the global space and windows are not tied to a particular display.
Sam Lantinga <slouken@libsdl.org>
parents: 5243
diff changeset
   811
        (SDL_DisplayData *) SDL_GetDisplayForWindow(window)->driverdata;
3077
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   812
    Display *display = data->videodata->display;
4518
a956a315fe67 Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents: 4510
diff changeset
   813
    Atom _NET_WM_STATE = data->videodata->_NET_WM_STATE;
a956a315fe67 Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents: 4510
diff changeset
   814
    Atom _NET_WM_STATE_MAXIMIZED_VERT = data->videodata->_NET_WM_STATE_MAXIMIZED_VERT;
a956a315fe67 Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents: 4510
diff changeset
   815
    Atom _NET_WM_STATE_MAXIMIZED_HORZ = data->videodata->_NET_WM_STATE_MAXIMIZED_HORZ;
4522
a4da6b906abb Fixed setting fullscreen and maximized states for windows that haven't been mapped yet.
Sam Lantinga <slouken@libsdl.org>
parents: 4521
diff changeset
   816
    Atom _NET_WM_STATE_FULLSCREEN = data->videodata->_NET_WM_STATE_FULLSCREEN;
a4da6b906abb Fixed setting fullscreen and maximized states for windows that haven't been mapped yet.
Sam Lantinga <slouken@libsdl.org>
parents: 4521
diff changeset
   817
a4da6b906abb Fixed setting fullscreen and maximized states for windows that haven't been mapped yet.
Sam Lantinga <slouken@libsdl.org>
parents: 4521
diff changeset
   818
    if (X11_IsWindowMapped(_this, window)) {
a4da6b906abb Fixed setting fullscreen and maximized states for windows that haven't been mapped yet.
Sam Lantinga <slouken@libsdl.org>
parents: 4521
diff changeset
   819
        XEvent e;
a4da6b906abb Fixed setting fullscreen and maximized states for windows that haven't been mapped yet.
Sam Lantinga <slouken@libsdl.org>
parents: 4521
diff changeset
   820
4524
a256e1dadf3f Zero any fields not explicitly filled in.
Sam Lantinga <slouken@libsdl.org>
parents: 4522
diff changeset
   821
        SDL_zero(e);
4522
a4da6b906abb Fixed setting fullscreen and maximized states for windows that haven't been mapped yet.
Sam Lantinga <slouken@libsdl.org>
parents: 4521
diff changeset
   822
        e.xany.type = ClientMessage;
a4da6b906abb Fixed setting fullscreen and maximized states for windows that haven't been mapped yet.
Sam Lantinga <slouken@libsdl.org>
parents: 4521
diff changeset
   823
        e.xclient.message_type = _NET_WM_STATE;
a4da6b906abb Fixed setting fullscreen and maximized states for windows that haven't been mapped yet.
Sam Lantinga <slouken@libsdl.org>
parents: 4521
diff changeset
   824
        e.xclient.format = 32;
a4da6b906abb Fixed setting fullscreen and maximized states for windows that haven't been mapped yet.
Sam Lantinga <slouken@libsdl.org>
parents: 4521
diff changeset
   825
        e.xclient.window = data->xwindow;
a4da6b906abb Fixed setting fullscreen and maximized states for windows that haven't been mapped yet.
Sam Lantinga <slouken@libsdl.org>
parents: 4521
diff changeset
   826
        e.xclient.data.l[0] =
a4da6b906abb Fixed setting fullscreen and maximized states for windows that haven't been mapped yet.
Sam Lantinga <slouken@libsdl.org>
parents: 4521
diff changeset
   827
            maximized ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE;
a4da6b906abb Fixed setting fullscreen and maximized states for windows that haven't been mapped yet.
Sam Lantinga <slouken@libsdl.org>
parents: 4521
diff changeset
   828
        e.xclient.data.l[1] = _NET_WM_STATE_MAXIMIZED_VERT;
a4da6b906abb Fixed setting fullscreen and maximized states for windows that haven't been mapped yet.
Sam Lantinga <slouken@libsdl.org>
parents: 4521
diff changeset
   829
        e.xclient.data.l[2] = _NET_WM_STATE_MAXIMIZED_HORZ;
a4da6b906abb Fixed setting fullscreen and maximized states for windows that haven't been mapped yet.
Sam Lantinga <slouken@libsdl.org>
parents: 4521
diff changeset
   830
        e.xclient.data.l[3] = 0l;
3077
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   831
4522
a4da6b906abb Fixed setting fullscreen and maximized states for windows that haven't been mapped yet.
Sam Lantinga <slouken@libsdl.org>
parents: 4521
diff changeset
   832
        XSendEvent(display, RootWindow(display, displaydata->screen), 0,
a4da6b906abb Fixed setting fullscreen and maximized states for windows that haven't been mapped yet.
Sam Lantinga <slouken@libsdl.org>
parents: 4521
diff changeset
   833
                   SubstructureNotifyMask | SubstructureRedirectMask, &e);
a4da6b906abb Fixed setting fullscreen and maximized states for windows that haven't been mapped yet.
Sam Lantinga <slouken@libsdl.org>
parents: 4521
diff changeset
   834
    } else {
a4da6b906abb Fixed setting fullscreen and maximized states for windows that haven't been mapped yet.
Sam Lantinga <slouken@libsdl.org>
parents: 4521
diff changeset
   835
        int count = 0;
a4da6b906abb Fixed setting fullscreen and maximized states for windows that haven't been mapped yet.
Sam Lantinga <slouken@libsdl.org>
parents: 4521
diff changeset
   836
        Atom atoms[3];
3077
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   837
4522
a4da6b906abb Fixed setting fullscreen and maximized states for windows that haven't been mapped yet.
Sam Lantinga <slouken@libsdl.org>
parents: 4521
diff changeset
   838
        if (window->flags & SDL_WINDOW_FULLSCREEN) {
a4da6b906abb Fixed setting fullscreen and maximized states for windows that haven't been mapped yet.
Sam Lantinga <slouken@libsdl.org>
parents: 4521
diff changeset
   839
            atoms[count++] = _NET_WM_STATE_FULLSCREEN;
a4da6b906abb Fixed setting fullscreen and maximized states for windows that haven't been mapped yet.
Sam Lantinga <slouken@libsdl.org>
parents: 4521
diff changeset
   840
        }
a4da6b906abb Fixed setting fullscreen and maximized states for windows that haven't been mapped yet.
Sam Lantinga <slouken@libsdl.org>
parents: 4521
diff changeset
   841
        if (maximized) {
a4da6b906abb Fixed setting fullscreen and maximized states for windows that haven't been mapped yet.
Sam Lantinga <slouken@libsdl.org>
parents: 4521
diff changeset
   842
            atoms[count++] = _NET_WM_STATE_MAXIMIZED_VERT;
a4da6b906abb Fixed setting fullscreen and maximized states for windows that haven't been mapped yet.
Sam Lantinga <slouken@libsdl.org>
parents: 4521
diff changeset
   843
            atoms[count++] = _NET_WM_STATE_MAXIMIZED_HORZ;
a4da6b906abb Fixed setting fullscreen and maximized states for windows that haven't been mapped yet.
Sam Lantinga <slouken@libsdl.org>
parents: 4521
diff changeset
   844
        }
a4da6b906abb Fixed setting fullscreen and maximized states for windows that haven't been mapped yet.
Sam Lantinga <slouken@libsdl.org>
parents: 4521
diff changeset
   845
        if (count > 0) {
a4da6b906abb Fixed setting fullscreen and maximized states for windows that haven't been mapped yet.
Sam Lantinga <slouken@libsdl.org>
parents: 4521
diff changeset
   846
            XChangeProperty(display, data->xwindow, _NET_WM_STATE, XA_ATOM, 32,
a4da6b906abb Fixed setting fullscreen and maximized states for windows that haven't been mapped yet.
Sam Lantinga <slouken@libsdl.org>
parents: 4521
diff changeset
   847
                            PropModeReplace, (unsigned char *)atoms, count);
a4da6b906abb Fixed setting fullscreen and maximized states for windows that haven't been mapped yet.
Sam Lantinga <slouken@libsdl.org>
parents: 4521
diff changeset
   848
        } else {
a4da6b906abb Fixed setting fullscreen and maximized states for windows that haven't been mapped yet.
Sam Lantinga <slouken@libsdl.org>
parents: 4521
diff changeset
   849
            XDeleteProperty(display, data->xwindow, _NET_WM_STATE);
a4da6b906abb Fixed setting fullscreen and maximized states for windows that haven't been mapped yet.
Sam Lantinga <slouken@libsdl.org>
parents: 4521
diff changeset
   850
        }
a4da6b906abb Fixed setting fullscreen and maximized states for windows that haven't been mapped yet.
Sam Lantinga <slouken@libsdl.org>
parents: 4521
diff changeset
   851
    }
5031
5e3291605ad0 Added XFlush() so changes happen immediately instead of waiting for the next event loop.
Sam Lantinga <slouken@libsdl.org>
parents: 4937
diff changeset
   852
    XFlush(display);
3077
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   853
}
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   854
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   855
void
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   856
X11_MaximizeWindow(_THIS, SDL_Window * window)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   857
{
5302
b1b9ec9874ba Implemented X11 fullscreen toggling with modern window managers
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   858
    SetWindowMaximized(_this, window, SDL_TRUE);
1951
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
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   861
void
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   862
X11_MinimizeWindow(_THIS, SDL_Window * window)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   863
{
4518
a956a315fe67 Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents: 4510
diff changeset
   864
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
a956a315fe67 Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents: 4510
diff changeset
   865
    SDL_DisplayData *displaydata =
5246
58265e606e4e Window coordinates are in the global space and windows are not tied to a particular display.
Sam Lantinga <slouken@libsdl.org>
parents: 5243
diff changeset
   866
        (SDL_DisplayData *) SDL_GetDisplayForWindow(window)->driverdata;
4518
a956a315fe67 Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents: 4510
diff changeset
   867
    Display *display = data->videodata->display;
a956a315fe67 Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents: 4510
diff changeset
   868
 
a956a315fe67 Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents: 4510
diff changeset
   869
    XIconifyWindow(display, data->xwindow, displaydata->screen);
5031
5e3291605ad0 Added XFlush() so changes happen immediately instead of waiting for the next event loop.
Sam Lantinga <slouken@libsdl.org>
parents: 4937
diff changeset
   870
    XFlush(display);
1951
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
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   873
void
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   874
X11_RestoreWindow(_THIS, SDL_Window * window)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   875
{
5302
b1b9ec9874ba Implemented X11 fullscreen toggling with modern window managers
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   876
    SetWindowMaximized(_this, window, SDL_FALSE);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   877
    X11_ShowWindow(_this, window);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   878
}
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   879
6466
ebe165c00fab On Compiz (etc?), _NET_WM_ACTION_FULLSCREEN needs the window to be resizable.
Ryan C. Gordon <icculus@icculus.org>
parents: 6462
diff changeset
   880
static Bool
ebe165c00fab On Compiz (etc?), _NET_WM_ACTION_FULLSCREEN needs the window to be resizable.
Ryan C. Gordon <icculus@icculus.org>
parents: 6462
diff changeset
   881
isActionAllowed(SDL_WindowData *data, Atom action)
ebe165c00fab On Compiz (etc?), _NET_WM_ACTION_FULLSCREEN needs the window to be resizable.
Ryan C. Gordon <icculus@icculus.org>
parents: 6462
diff changeset
   882
{
ebe165c00fab On Compiz (etc?), _NET_WM_ACTION_FULLSCREEN needs the window to be resizable.
Ryan C. Gordon <icculus@icculus.org>
parents: 6462
diff changeset
   883
    Atom _NET_WM_ALLOWED_ACTIONS = data->videodata->_NET_WM_ALLOWED_ACTIONS;
ebe165c00fab On Compiz (etc?), _NET_WM_ACTION_FULLSCREEN needs the window to be resizable.
Ryan C. Gordon <icculus@icculus.org>
parents: 6462
diff changeset
   884
    Atom type;
ebe165c00fab On Compiz (etc?), _NET_WM_ACTION_FULLSCREEN needs the window to be resizable.
Ryan C. Gordon <icculus@icculus.org>
parents: 6462
diff changeset
   885
    Display *display = data->videodata->display;
ebe165c00fab On Compiz (etc?), _NET_WM_ACTION_FULLSCREEN needs the window to be resizable.
Ryan C. Gordon <icculus@icculus.org>
parents: 6462
diff changeset
   886
    int form;
ebe165c00fab On Compiz (etc?), _NET_WM_ACTION_FULLSCREEN needs the window to be resizable.
Ryan C. Gordon <icculus@icculus.org>
parents: 6462
diff changeset
   887
    unsigned long remain;
ebe165c00fab On Compiz (etc?), _NET_WM_ACTION_FULLSCREEN needs the window to be resizable.
Ryan C. Gordon <icculus@icculus.org>
parents: 6462
diff changeset
   888
    unsigned long len, i;
ebe165c00fab On Compiz (etc?), _NET_WM_ACTION_FULLSCREEN needs the window to be resizable.
Ryan C. Gordon <icculus@icculus.org>
parents: 6462
diff changeset
   889
    Atom *list;
ebe165c00fab On Compiz (etc?), _NET_WM_ACTION_FULLSCREEN needs the window to be resizable.
Ryan C. Gordon <icculus@icculus.org>
parents: 6462
diff changeset
   890
    Bool ret = False;
ebe165c00fab On Compiz (etc?), _NET_WM_ACTION_FULLSCREEN needs the window to be resizable.
Ryan C. Gordon <icculus@icculus.org>
parents: 6462
diff changeset
   891
    if (XGetWindowProperty(display, data->xwindow, _NET_WM_ALLOWED_ACTIONS, 0, 1024, False, XA_ATOM, &type, &form, &len, &remain, (unsigned char **)&list) == Success)
ebe165c00fab On Compiz (etc?), _NET_WM_ACTION_FULLSCREEN needs the window to be resizable.
Ryan C. Gordon <icculus@icculus.org>
parents: 6462
diff changeset
   892
    {
ebe165c00fab On Compiz (etc?), _NET_WM_ACTION_FULLSCREEN needs the window to be resizable.
Ryan C. Gordon <icculus@icculus.org>
parents: 6462
diff changeset
   893
        for (i=0; i<len; ++i)
ebe165c00fab On Compiz (etc?), _NET_WM_ACTION_FULLSCREEN needs the window to be resizable.
Ryan C. Gordon <icculus@icculus.org>
parents: 6462
diff changeset
   894
        {
ebe165c00fab On Compiz (etc?), _NET_WM_ACTION_FULLSCREEN needs the window to be resizable.
Ryan C. Gordon <icculus@icculus.org>
parents: 6462
diff changeset
   895
            if (list[i] == action) {
ebe165c00fab On Compiz (etc?), _NET_WM_ACTION_FULLSCREEN needs the window to be resizable.
Ryan C. Gordon <icculus@icculus.org>
parents: 6462
diff changeset
   896
                ret = True;
ebe165c00fab On Compiz (etc?), _NET_WM_ACTION_FULLSCREEN needs the window to be resizable.
Ryan C. Gordon <icculus@icculus.org>
parents: 6462
diff changeset
   897
                break;
ebe165c00fab On Compiz (etc?), _NET_WM_ACTION_FULLSCREEN needs the window to be resizable.
Ryan C. Gordon <icculus@icculus.org>
parents: 6462
diff changeset
   898
            }
ebe165c00fab On Compiz (etc?), _NET_WM_ACTION_FULLSCREEN needs the window to be resizable.
Ryan C. Gordon <icculus@icculus.org>
parents: 6462
diff changeset
   899
        }
ebe165c00fab On Compiz (etc?), _NET_WM_ACTION_FULLSCREEN needs the window to be resizable.
Ryan C. Gordon <icculus@icculus.org>
parents: 6462
diff changeset
   900
        XFree(list);
ebe165c00fab On Compiz (etc?), _NET_WM_ACTION_FULLSCREEN needs the window to be resizable.
Ryan C. Gordon <icculus@icculus.org>
parents: 6462
diff changeset
   901
    }
ebe165c00fab On Compiz (etc?), _NET_WM_ACTION_FULLSCREEN needs the window to be resizable.
Ryan C. Gordon <icculus@icculus.org>
parents: 6462
diff changeset
   902
    return ret;
ebe165c00fab On Compiz (etc?), _NET_WM_ACTION_FULLSCREEN needs the window to be resizable.
Ryan C. Gordon <icculus@icculus.org>
parents: 6462
diff changeset
   903
}
ebe165c00fab On Compiz (etc?), _NET_WM_ACTION_FULLSCREEN needs the window to be resizable.
Ryan C. Gordon <icculus@icculus.org>
parents: 6462
diff changeset
   904
6467
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
   905
/* This asks the Window Manager to handle fullscreen for us. Most don't do it right, though. */
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
   906
static void
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
   907
X11_SetWindowFullscreenViaWM(_THIS, SDL_Window * window, SDL_VideoDisplay * _display, SDL_bool fullscreen)
5302
b1b9ec9874ba Implemented X11 fullscreen toggling with modern window managers
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   908
{
b1b9ec9874ba Implemented X11 fullscreen toggling with modern window managers
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   909
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
5305
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5302
diff changeset
   910
    SDL_DisplayData *displaydata = (SDL_DisplayData *) _display->driverdata;
5302
b1b9ec9874ba Implemented X11 fullscreen toggling with modern window managers
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   911
    Display *display = data->videodata->display;
b1b9ec9874ba Implemented X11 fullscreen toggling with modern window managers
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   912
    Atom _NET_WM_STATE = data->videodata->_NET_WM_STATE;
b1b9ec9874ba Implemented X11 fullscreen toggling with modern window managers
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   913
    Atom _NET_WM_STATE_MAXIMIZED_VERT = data->videodata->_NET_WM_STATE_MAXIMIZED_VERT;
b1b9ec9874ba Implemented X11 fullscreen toggling with modern window managers
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   914
    Atom _NET_WM_STATE_MAXIMIZED_HORZ = data->videodata->_NET_WM_STATE_MAXIMIZED_HORZ;
b1b9ec9874ba Implemented X11 fullscreen toggling with modern window managers
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   915
    Atom _NET_WM_STATE_FULLSCREEN = data->videodata->_NET_WM_STATE_FULLSCREEN;
b1b9ec9874ba Implemented X11 fullscreen toggling with modern window managers
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   916
b1b9ec9874ba Implemented X11 fullscreen toggling with modern window managers
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   917
    if (X11_IsWindowMapped(_this, window)) {
b1b9ec9874ba Implemented X11 fullscreen toggling with modern window managers
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   918
        XEvent e;
b1b9ec9874ba Implemented X11 fullscreen toggling with modern window managers
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   919
6466
ebe165c00fab On Compiz (etc?), _NET_WM_ACTION_FULLSCREEN needs the window to be resizable.
Ryan C. Gordon <icculus@icculus.org>
parents: 6462
diff changeset
   920
        if (isActionAllowed(data, data->videodata->_NET_WM_ACTION_FULLSCREEN) == False)
ebe165c00fab On Compiz (etc?), _NET_WM_ACTION_FULLSCREEN needs the window to be resizable.
Ryan C. Gordon <icculus@icculus.org>
parents: 6462
diff changeset
   921
        {
ebe165c00fab On Compiz (etc?), _NET_WM_ACTION_FULLSCREEN needs the window to be resizable.
Ryan C. Gordon <icculus@icculus.org>
parents: 6462
diff changeset
   922
            /* We aren't allowed to go into fullscreen mode... */
ebe165c00fab On Compiz (etc?), _NET_WM_ACTION_FULLSCREEN needs the window to be resizable.
Ryan C. Gordon <icculus@icculus.org>
parents: 6462
diff changeset
   923
            if ((window->flags & SDL_WINDOW_RESIZABLE) == 0) {
ebe165c00fab On Compiz (etc?), _NET_WM_ACTION_FULLSCREEN needs the window to be resizable.
Ryan C. Gordon <icculus@icculus.org>
parents: 6462
diff changeset
   924
                /* ...and we aren't resizable. Compiz refuses fullscreen toggle in this case. */
ebe165c00fab On Compiz (etc?), _NET_WM_ACTION_FULLSCREEN needs the window to be resizable.
Ryan C. Gordon <icculus@icculus.org>
parents: 6462
diff changeset
   925
                XSizeHints *sizehints = XAllocSizeHints();
ebe165c00fab On Compiz (etc?), _NET_WM_ACTION_FULLSCREEN needs the window to be resizable.
Ryan C. Gordon <icculus@icculus.org>
parents: 6462
diff changeset
   926
                long flags = 0;
ebe165c00fab On Compiz (etc?), _NET_WM_ACTION_FULLSCREEN needs the window to be resizable.
Ryan C. Gordon <icculus@icculus.org>
parents: 6462
diff changeset
   927
                XGetWMNormalHints(display, data->xwindow, sizehints, &flags);
ebe165c00fab On Compiz (etc?), _NET_WM_ACTION_FULLSCREEN needs the window to be resizable.
Ryan C. Gordon <icculus@icculus.org>
parents: 6462
diff changeset
   928
                /* set the resize flags on */
ebe165c00fab On Compiz (etc?), _NET_WM_ACTION_FULLSCREEN needs the window to be resizable.
Ryan C. Gordon <icculus@icculus.org>
parents: 6462
diff changeset
   929
                sizehints->flags |= PMinSize | PMaxSize;
ebe165c00fab On Compiz (etc?), _NET_WM_ACTION_FULLSCREEN needs the window to be resizable.
Ryan C. Gordon <icculus@icculus.org>
parents: 6462
diff changeset
   930
                if (fullscreen) {
ebe165c00fab On Compiz (etc?), _NET_WM_ACTION_FULLSCREEN needs the window to be resizable.
Ryan C. Gordon <icculus@icculus.org>
parents: 6462
diff changeset
   931
                    /* we are going fullscreen so turn the flags off */
ebe165c00fab On Compiz (etc?), _NET_WM_ACTION_FULLSCREEN needs the window to be resizable.
Ryan C. Gordon <icculus@icculus.org>
parents: 6462
diff changeset
   932
                    sizehints->flags ^= (PMinSize | PMaxSize);
ebe165c00fab On Compiz (etc?), _NET_WM_ACTION_FULLSCREEN needs the window to be resizable.
Ryan C. Gordon <icculus@icculus.org>
parents: 6462
diff changeset
   933
                } else {
ebe165c00fab On Compiz (etc?), _NET_WM_ACTION_FULLSCREEN needs the window to be resizable.
Ryan C. Gordon <icculus@icculus.org>
parents: 6462
diff changeset
   934
                    /* Reset the min/max width height to make the window non-resizable again */
ebe165c00fab On Compiz (etc?), _NET_WM_ACTION_FULLSCREEN needs the window to be resizable.
Ryan C. Gordon <icculus@icculus.org>
parents: 6462
diff changeset
   935
                    sizehints->min_width = sizehints->max_width = window->w;
ebe165c00fab On Compiz (etc?), _NET_WM_ACTION_FULLSCREEN needs the window to be resizable.
Ryan C. Gordon <icculus@icculus.org>
parents: 6462
diff changeset
   936
                    sizehints->min_height = sizehints->max_height = window->h;
ebe165c00fab On Compiz (etc?), _NET_WM_ACTION_FULLSCREEN needs the window to be resizable.
Ryan C. Gordon <icculus@icculus.org>
parents: 6462
diff changeset
   937
                }
ebe165c00fab On Compiz (etc?), _NET_WM_ACTION_FULLSCREEN needs the window to be resizable.
Ryan C. Gordon <icculus@icculus.org>
parents: 6462
diff changeset
   938
                XSetWMNormalHints(display, data->xwindow, sizehints);
ebe165c00fab On Compiz (etc?), _NET_WM_ACTION_FULLSCREEN needs the window to be resizable.
Ryan C. Gordon <icculus@icculus.org>
parents: 6462
diff changeset
   939
                XFree(sizehints);
ebe165c00fab On Compiz (etc?), _NET_WM_ACTION_FULLSCREEN needs the window to be resizable.
Ryan C. Gordon <icculus@icculus.org>
parents: 6462
diff changeset
   940
            }
ebe165c00fab On Compiz (etc?), _NET_WM_ACTION_FULLSCREEN needs the window to be resizable.
Ryan C. Gordon <icculus@icculus.org>
parents: 6462
diff changeset
   941
        }
ebe165c00fab On Compiz (etc?), _NET_WM_ACTION_FULLSCREEN needs the window to be resizable.
Ryan C. Gordon <icculus@icculus.org>
parents: 6462
diff changeset
   942
        
5302
b1b9ec9874ba Implemented X11 fullscreen toggling with modern window managers
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   943
        SDL_zero(e);
b1b9ec9874ba Implemented X11 fullscreen toggling with modern window managers
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   944
        e.xany.type = ClientMessage;
b1b9ec9874ba Implemented X11 fullscreen toggling with modern window managers
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   945
        e.xclient.message_type = _NET_WM_STATE;
b1b9ec9874ba Implemented X11 fullscreen toggling with modern window managers
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   946
        e.xclient.format = 32;
b1b9ec9874ba Implemented X11 fullscreen toggling with modern window managers
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   947
        e.xclient.window = data->xwindow;
b1b9ec9874ba Implemented X11 fullscreen toggling with modern window managers
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   948
        e.xclient.data.l[0] =
b1b9ec9874ba Implemented X11 fullscreen toggling with modern window managers
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   949
            fullscreen ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE;
b1b9ec9874ba Implemented X11 fullscreen toggling with modern window managers
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   950
        e.xclient.data.l[1] = _NET_WM_STATE_FULLSCREEN;
b1b9ec9874ba Implemented X11 fullscreen toggling with modern window managers
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   951
        e.xclient.data.l[3] = 0l;
b1b9ec9874ba Implemented X11 fullscreen toggling with modern window managers
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   952
b1b9ec9874ba Implemented X11 fullscreen toggling with modern window managers
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   953
        XSendEvent(display, RootWindow(display, displaydata->screen), 0,
b1b9ec9874ba Implemented X11 fullscreen toggling with modern window managers
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   954
                   SubstructureNotifyMask | SubstructureRedirectMask, &e);
b1b9ec9874ba Implemented X11 fullscreen toggling with modern window managers
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   955
    } else {
b1b9ec9874ba Implemented X11 fullscreen toggling with modern window managers
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   956
        int count = 0;
b1b9ec9874ba Implemented X11 fullscreen toggling with modern window managers
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   957
        Atom atoms[3];
b1b9ec9874ba Implemented X11 fullscreen toggling with modern window managers
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   958
b1b9ec9874ba Implemented X11 fullscreen toggling with modern window managers
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   959
        if (fullscreen) {
b1b9ec9874ba Implemented X11 fullscreen toggling with modern window managers
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   960
            atoms[count++] = _NET_WM_STATE_FULLSCREEN;
b1b9ec9874ba Implemented X11 fullscreen toggling with modern window managers
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   961
        }
b1b9ec9874ba Implemented X11 fullscreen toggling with modern window managers
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   962
        if (window->flags & SDL_WINDOW_MAXIMIZED) {
b1b9ec9874ba Implemented X11 fullscreen toggling with modern window managers
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   963
            atoms[count++] = _NET_WM_STATE_MAXIMIZED_VERT;
b1b9ec9874ba Implemented X11 fullscreen toggling with modern window managers
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   964
            atoms[count++] = _NET_WM_STATE_MAXIMIZED_HORZ;
b1b9ec9874ba Implemented X11 fullscreen toggling with modern window managers
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   965
        }
b1b9ec9874ba Implemented X11 fullscreen toggling with modern window managers
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   966
        if (count > 0) {
b1b9ec9874ba Implemented X11 fullscreen toggling with modern window managers
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   967
            XChangeProperty(display, data->xwindow, _NET_WM_STATE, XA_ATOM, 32,
b1b9ec9874ba Implemented X11 fullscreen toggling with modern window managers
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   968
                            PropModeReplace, (unsigned char *)atoms, count);
b1b9ec9874ba Implemented X11 fullscreen toggling with modern window managers
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   969
        } else {
b1b9ec9874ba Implemented X11 fullscreen toggling with modern window managers
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   970
            XDeleteProperty(display, data->xwindow, _NET_WM_STATE);
b1b9ec9874ba Implemented X11 fullscreen toggling with modern window managers
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   971
        }
b1b9ec9874ba Implemented X11 fullscreen toggling with modern window managers
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   972
    }
b1b9ec9874ba Implemented X11 fullscreen toggling with modern window managers
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   973
    XFlush(display);
b1b9ec9874ba Implemented X11 fullscreen toggling with modern window managers
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   974
}
b1b9ec9874ba Implemented X11 fullscreen toggling with modern window managers
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   975
6467
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
   976
static __inline__ int
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
   977
maxint(const int a, const int b)
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
   978
{
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
   979
    return (a > b ? a : b);
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
   980
}
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
   981
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
   982
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
   983
/* This handles fullscreen itself, outside the Window Manager. */
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
   984
static void
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
   985
X11_BeginWindowFullscreenLegacy(_THIS, SDL_Window * window, SDL_VideoDisplay * _display)
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
   986
{
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
   987
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
   988
    SDL_DisplayData *displaydata = (SDL_DisplayData *) _display->driverdata;
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
   989
    Visual *visual = data->visual;
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
   990
    Display *display = data->videodata->display;
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
   991
    const int screen = displaydata->screen;
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
   992
    Window root = RootWindow(display, screen);
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
   993
    const int def_vis = (visual == DefaultVisual(display, screen));
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
   994
    const int w = maxint(window->w, _display->current_mode.w);
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
   995
    const int h = maxint(window->h, _display->current_mode.h);
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
   996
    unsigned long xattrmask = 0;
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
   997
    XSetWindowAttributes xattr;
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
   998
    XEvent ev;
6475
71d39944810b Fixed fullscreen origin for multi-head displays
Sam Lantinga <slouken@libsdl.org>
parents: 6473
diff changeset
   999
    SDL_Rect rect;
6467
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
  1000
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
  1001
    if ( data->fswindow ) {
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
  1002
        return;  /* already fullscreen, I hope. */
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
  1003
    }
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
  1004
6475
71d39944810b Fixed fullscreen origin for multi-head displays
Sam Lantinga <slouken@libsdl.org>
parents: 6473
diff changeset
  1005
    X11_GetDisplayBounds(_this, _display, &rect);
71d39944810b Fixed fullscreen origin for multi-head displays
Sam Lantinga <slouken@libsdl.org>
parents: 6473
diff changeset
  1006
6467
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
  1007
    /* Ungrab the input so that we can move the mouse around */
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
  1008
    XUngrabPointer(display, CurrentTime);
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
  1009
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
  1010
    #if SDL_VIDEO_DRIVER_X11_XINERAMA
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
  1011
    /* !!! FIXME: there was some Xinerama code in 1.2 here to set x,y to the origin of a specific screen. */
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
  1012
    #endif
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
  1013
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
  1014
    SDL_zero(xattr);
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
  1015
    xattr.override_redirect = True;
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
  1016
    xattrmask |= CWOverrideRedirect;
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
  1017
    xattr.background_pixel = def_vis ? BlackPixel(display, screen) : 0;
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
  1018
    xattrmask |= CWBackPixel;
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
  1019
    xattr.border_pixel = 0;
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
  1020
    xattrmask |= CWBorderPixel;
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
  1021
    xattr.colormap = data->colormap;
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
  1022
    xattrmask |= CWColormap;
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
  1023
6475
71d39944810b Fixed fullscreen origin for multi-head displays
Sam Lantinga <slouken@libsdl.org>
parents: 6473
diff changeset
  1024
    data->fswindow = XCreateWindow(display, root,
71d39944810b Fixed fullscreen origin for multi-head displays
Sam Lantinga <slouken@libsdl.org>
parents: 6473
diff changeset
  1025
                                   rect.x, rect.y, rect.w, rect.h, 0,
6467
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
  1026
                                   displaydata->depth, InputOutput,
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
  1027
                                   visual, xattrmask, &xattr);
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
  1028
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
  1029
    XSelectInput(display, data->fswindow, StructureNotifyMask);
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
  1030
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
  1031
    XSetWindowBackground(display, data->fswindow, 0);
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
  1032
    XClearWindow(display, data->fswindow);
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
  1033
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
  1034
    XMapRaised(display, data->fswindow);
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
  1035
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
  1036
    /* Wait to be mapped, filter Unmap event out if it arrives. */
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
  1037
    XIfEvent(display, &ev, &isMapNotify, (XPointer)&data->fswindow);
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
  1038
    XCheckIfEvent(display, &ev, &isUnmapNotify, (XPointer)&data->fswindow);
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
  1039
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
  1040
#if SDL_VIDEO_DRIVER_X11_XVIDMODE
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
  1041
    if ( displaydata->use_vidmode ) {
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
  1042
        XF86VidModeLockModeSwitch(display, screen, True);
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
  1043
    }
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
  1044
#endif
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
  1045
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
  1046
    XInstallColormap(display, data->colormap);
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
  1047