src/video/x11/SDL_x11window.c
author Jasper St. Pierre <jstpierre@mecheye.net>
Sun, 21 Jul 2013 00:57:31 -0400
changeset 7490 fc864efbc1a6
parent 7445 bf50f0b74811
child 7522 b186724247dd
permissions -rw-r--r--
Add support for the _NET_WM_BYPASS_COMPOSITOR hint This hints to window managers to unredirect the window to improve performance.
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
6885
700f1b25f77f Happy New Year!
Sam Lantinga <slouken@libsdl.org>
parents: 6662
diff changeset
     3
  Copyright (C) 1997-2013 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
6662
698c2e533a7e SDL no longer grabs the keyboard by default on X11.
Sam Lantinga <slouken@libsdl.org>
parents: 6638
diff changeset
    25
#include "SDL_hints.h"
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    26
#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
    27
#include "../SDL_pixels_c.h"
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    28
#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
    29
#include "../../events/SDL_mouse_c.h"
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    30
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    31
#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
    32
#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
    33
#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
    34
#include "SDL_x11xinput2.h"
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    35
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6167
diff changeset
    36
#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
    37
#include "SDL_x11opengles.h"
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3078
diff changeset
    38
#endif
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3078
diff changeset
    39
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
    40
#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
    41
#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
    42
#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
    43
3077
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
    44
#define _NET_WM_STATE_REMOVE    0l
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
    45
#define _NET_WM_STATE_ADD       1l
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
    46
#define _NET_WM_STATE_TOGGLE    2l
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
    47
6467
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
    48
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
    49
{
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
    50
    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
    51
}
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
    52
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
    53
{
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
    54
    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
    55
}
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
    56
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
    57
{
6480
d02a4369b3f5 Hopefully improved legacy fullscreen handling (it works now on my Ubuntu Unity system)
Sam Lantinga <slouken@libsdl.org>
parents: 6479
diff changeset
    58
    return ev->type == ConfigureNotify && ev->xconfigure.window == *((Window*)win);
d02a4369b3f5 Hopefully improved legacy fullscreen handling (it works now on my Ubuntu Unity system)
Sam Lantinga <slouken@libsdl.org>
parents: 6479
diff changeset
    59
}
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
    60
6467
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
    61
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
    62
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
    63
{
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
    64
    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
    65
    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
    66
}
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
    67
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
    68
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
    69
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
    70
{
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_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
    72
    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
    73
    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
    74
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
    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
    76
    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
    77
        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
    78
    } 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
    79
        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
    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
6540
44459e2f6e4d Fix the size to the windowed mode, not the fullscreen mode.
Sam Lantinga <slouken@libsdl.org>
parents: 6539
diff changeset
    83
#if 0
6481
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
    84
static SDL_bool
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
    85
X11_IsActionAllowed(SDL_Window *window, Atom action)
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
    86
{
6481
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
    87
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
    88
    Atom _NET_WM_ALLOWED_ACTIONS = data->videodata->_NET_WM_ALLOWED_ACTIONS;
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
    89
    Atom type;
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
    90
    Display *display = data->videodata->display;
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
    91
    int form;
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
    92
    unsigned long remain;
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
    93
    unsigned long len, i;
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
    94
    Atom *list;
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
    95
    SDL_bool ret = SDL_FALSE;
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
    96
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
    97
    if (XGetWindowProperty(display, data->xwindow, _NET_WM_ALLOWED_ACTIONS, 0, 1024, False, XA_ATOM, &type, &form, &len, &remain, (unsigned char **)&list) == Success)
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
    98
    {
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
    99
        for (i=0; i<len; ++i)
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
   100
        {
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
   101
            if (list[i] == action) {
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
   102
                ret = SDL_TRUE;
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
   103
                break;
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
   104
            }
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
   105
        }
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
   106
        XFree(list);
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
   107
    }
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
   108
    return ret;
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
   109
}
6540
44459e2f6e4d Fix the size to the windowed mode, not the fullscreen mode.
Sam Lantinga <slouken@libsdl.org>
parents: 6539
diff changeset
   110
#endif /* 0 */
6481
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
   111
6487
b18a011ecc45 Simplified the NetWM code a little bit, and it now operates on X11 Window
Sam Lantinga <slouken@libsdl.org>
parents: 6486
diff changeset
   112
void
b18a011ecc45 Simplified the NetWM code a little bit, and it now operates on X11 Window
Sam Lantinga <slouken@libsdl.org>
parents: 6486
diff changeset
   113
X11_SetNetWMState(_THIS, Window xwindow, Uint32 flags)
6481
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
   114
{
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
   115
    SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
6487
b18a011ecc45 Simplified the NetWM code a little bit, and it now operates on X11 Window
Sam Lantinga <slouken@libsdl.org>
parents: 6486
diff changeset
   116
    Display *display = videodata->display;
b18a011ecc45 Simplified the NetWM code a little bit, and it now operates on X11 Window
Sam Lantinga <slouken@libsdl.org>
parents: 6486
diff changeset
   117
    Atom _NET_WM_STATE = videodata->_NET_WM_STATE;
6486
e3264eea9607 Don't set the hidden netwm state, that would mean we don't want to be shown, which is bad.
Sam Lantinga <slouken@libsdl.org>
parents: 6485
diff changeset
   118
    /*Atom _NET_WM_STATE_HIDDEN = videodata->_NET_WM_STATE_HIDDEN;*/
6481
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
   119
    Atom _NET_WM_STATE_FOCUSED = videodata->_NET_WM_STATE_FOCUSED;
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
   120
    Atom _NET_WM_STATE_MAXIMIZED_VERT = videodata->_NET_WM_STATE_MAXIMIZED_VERT;
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
   121
    Atom _NET_WM_STATE_MAXIMIZED_HORZ = videodata->_NET_WM_STATE_MAXIMIZED_HORZ;
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
   122
    Atom _NET_WM_STATE_FULLSCREEN = videodata->_NET_WM_STATE_FULLSCREEN;
6487
b18a011ecc45 Simplified the NetWM code a little bit, and it now operates on X11 Window
Sam Lantinga <slouken@libsdl.org>
parents: 6486
diff changeset
   123
    Atom atoms[5];
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
   124
    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
   125
6486
e3264eea9607 Don't set the hidden netwm state, that would mean we don't want to be shown, which is bad.
Sam Lantinga <slouken@libsdl.org>
parents: 6485
diff changeset
   126
    /* The window manager sets this property, we shouldn't set it.
e3264eea9607 Don't set the hidden netwm state, that would mean we don't want to be shown, which is bad.
Sam Lantinga <slouken@libsdl.org>
parents: 6485
diff changeset
   127
       If we did, this would indicate to the window manager that we don't
e3264eea9607 Don't set the hidden netwm state, that would mean we don't want to be shown, which is bad.
Sam Lantinga <slouken@libsdl.org>
parents: 6485
diff changeset
   128
       actually want to be mapped during XMapRaised(), which would be bad.
e3264eea9607 Don't set the hidden netwm state, that would mean we don't want to be shown, which is bad.
Sam Lantinga <slouken@libsdl.org>
parents: 6485
diff changeset
   129
     *
6481
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
   130
    if (flags & SDL_WINDOW_HIDDEN) {
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
   131
        atoms[count++] = _NET_WM_STATE_HIDDEN;
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
   132
    }
6486
e3264eea9607 Don't set the hidden netwm state, that would mean we don't want to be shown, which is bad.
Sam Lantinga <slouken@libsdl.org>
parents: 6485
diff changeset
   133
    */
6481
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
   134
    if (flags & SDL_WINDOW_INPUT_FOCUS) {
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
   135
        atoms[count++] = _NET_WM_STATE_FOCUSED;
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
   136
    }
6481
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
   137
    if (flags & SDL_WINDOW_MAXIMIZED) {
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
   138
        atoms[count++] = _NET_WM_STATE_MAXIMIZED_VERT;
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
   139
        atoms[count++] = _NET_WM_STATE_MAXIMIZED_HORZ;
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
   140
    }
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
   141
    if (flags & SDL_WINDOW_FULLSCREEN) {
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
   142
        atoms[count++] = _NET_WM_STATE_FULLSCREEN;
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
   143
    }
6487
b18a011ecc45 Simplified the NetWM code a little bit, and it now operates on X11 Window
Sam Lantinga <slouken@libsdl.org>
parents: 6486
diff changeset
   144
    if (count > 0) {
b18a011ecc45 Simplified the NetWM code a little bit, and it now operates on X11 Window
Sam Lantinga <slouken@libsdl.org>
parents: 6486
diff changeset
   145
        XChangeProperty(display, xwindow, _NET_WM_STATE, XA_ATOM, 32,
b18a011ecc45 Simplified the NetWM code a little bit, and it now operates on X11 Window
Sam Lantinga <slouken@libsdl.org>
parents: 6486
diff changeset
   146
                        PropModeReplace, (unsigned char *)atoms, count);
b18a011ecc45 Simplified the NetWM code a little bit, and it now operates on X11 Window
Sam Lantinga <slouken@libsdl.org>
parents: 6486
diff changeset
   147
    } else {
b18a011ecc45 Simplified the NetWM code a little bit, and it now operates on X11 Window
Sam Lantinga <slouken@libsdl.org>
parents: 6486
diff changeset
   148
        XDeleteProperty(display, xwindow, _NET_WM_STATE);
b18a011ecc45 Simplified the NetWM code a little bit, and it now operates on X11 Window
Sam Lantinga <slouken@libsdl.org>
parents: 6486
diff changeset
   149
    }
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
   150
}
a4da6b906abb Fixed setting fullscreen and maximized states for windows that haven't been mapped yet.
Sam Lantinga <slouken@libsdl.org>
parents: 4521
diff changeset
   151
6481
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
   152
Uint32
6487
b18a011ecc45 Simplified the NetWM code a little bit, and it now operates on X11 Window
Sam Lantinga <slouken@libsdl.org>
parents: 6486
diff changeset
   153
X11_GetNetWMState(_THIS, Window xwindow)
6481
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
   154
{
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
   155
    SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
6487
b18a011ecc45 Simplified the NetWM code a little bit, and it now operates on X11 Window
Sam Lantinga <slouken@libsdl.org>
parents: 6486
diff changeset
   156
    Display *display = videodata->display;
6481
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
   157
    Atom _NET_WM_STATE = videodata->_NET_WM_STATE;
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
   158
    Atom _NET_WM_STATE_HIDDEN = videodata->_NET_WM_STATE_HIDDEN;
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
   159
    Atom _NET_WM_STATE_FOCUSED = videodata->_NET_WM_STATE_FOCUSED;
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
   160
    Atom _NET_WM_STATE_MAXIMIZED_VERT = videodata->_NET_WM_STATE_MAXIMIZED_VERT;
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
   161
    Atom _NET_WM_STATE_MAXIMIZED_HORZ = videodata->_NET_WM_STATE_MAXIMIZED_HORZ;
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
   162
    Atom _NET_WM_STATE_FULLSCREEN = videodata->_NET_WM_STATE_FULLSCREEN;
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
   163
    Atom actualType;
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
   164
    int actualFormat;
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
   165
    unsigned long i, numItems, bytesAfter;
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
   166
    unsigned char *propertyValue = NULL;
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
   167
    long maxLength = 1024;
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
   168
    Uint32 flags = 0;
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
   169
6487
b18a011ecc45 Simplified the NetWM code a little bit, and it now operates on X11 Window
Sam Lantinga <slouken@libsdl.org>
parents: 6486
diff changeset
   170
    if (XGetWindowProperty(display, xwindow, _NET_WM_STATE,
6481
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
   171
                           0l, maxLength, False, XA_ATOM, &actualType,
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
   172
                           &actualFormat, &numItems, &bytesAfter,
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
   173
                           &propertyValue) == Success) {
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
   174
        Atom *atoms = (Atom *) propertyValue;
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
   175
        int maximized = 0;
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
   176
        int fullscreen = 0;
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
   177
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
   178
        for (i = 0; i < numItems; ++i) {
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
   179
            if (atoms[i] == _NET_WM_STATE_HIDDEN) {
6486
e3264eea9607 Don't set the hidden netwm state, that would mean we don't want to be shown, which is bad.
Sam Lantinga <slouken@libsdl.org>
parents: 6485
diff changeset
   180
                flags |= SDL_WINDOW_HIDDEN;
6481
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
   181
            } else if (atoms[i] == _NET_WM_STATE_FOCUSED) {
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
   182
                flags |= SDL_WINDOW_INPUT_FOCUS;
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
   183
            } else if (atoms[i] == _NET_WM_STATE_MAXIMIZED_VERT) {
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
   184
                maximized |= 1;
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
   185
            } else if (atoms[i] == _NET_WM_STATE_MAXIMIZED_HORZ) {
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
   186
                maximized |= 2;
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
   187
            } else if ( atoms[i] == _NET_WM_STATE_FULLSCREEN) {
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
   188
                fullscreen = 1;
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
   189
            }
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
   190
        }
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
   191
        if (maximized == 3) {
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
   192
            flags |= SDL_WINDOW_MAXIMIZED;
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
   193
        }  else if (fullscreen == 1) {
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
   194
            flags |= SDL_WINDOW_FULLSCREEN;
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
   195
        }
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
   196
        XFree(propertyValue);
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
   197
    }
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
   198
6484
b904bb684095 Don't base our resizable state on what the window manager decided, instead we want to base it on the size hints which we set.
Sam Lantinga <slouken@libsdl.org>
parents: 6483
diff changeset
   199
    /* FIXME, check the size hints for resizable */
b904bb684095 Don't base our resizable state on what the window manager decided, instead we want to base it on the size hints which we set.
Sam Lantinga <slouken@libsdl.org>
parents: 6483
diff changeset
   200
    /*flags |= SDL_WINDOW_RESIZABLE;*/
6481
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
   201
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
   202
    return flags;
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
   203
}
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
   204
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   205
static int
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   206
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
   207
{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   208
    SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   209
    SDL_WindowData *data;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   210
    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
   211
    int windowlistlength = videodata->windowlistlength;
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   212
    SDL_WindowData **windowlist = videodata->windowlist;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   213
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   214
    /* Allocate the window data */
2323
4ac07ae446d3 Fixed many valgrind errors. But, I broke testdyngl.
Bob Pendleton <bob@pendleton.com>
parents: 2322
diff changeset
   215
    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
   216
    if (!data) {
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 7007
diff changeset
   217
        return SDL_OutOfMemory();
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   218
    }
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
   219
    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
   220
    data->xwindow = w;
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   221
#ifdef X_HAVE_UTF8_STRING
7007
2381f4d531d1 Fixed XIM crash when locale is set to something not supported by X11.
Sam Lantinga <slouken@libsdl.org>
parents: 7001
diff changeset
   222
    if (SDL_X11_HAVE_UTF8 && videodata->im) {
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   223
        data->ic =
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   224
            pXCreateIC(videodata->im, XNClientWindow, w, XNFocusWindow, w,
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   225
                       XNInputStyle, XIMPreeditNothing | XIMStatusNothing,
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   226
                       XNResourceName, videodata->classname, XNResourceClass,
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   227
                       videodata->classname, NULL);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   228
    }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   229
#endif
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   230
    data->created = created;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   231
    data->videodata = videodata;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   232
2323
4ac07ae446d3 Fixed many valgrind errors. But, I broke testdyngl.
Bob Pendleton <bob@pendleton.com>
parents: 2322
diff changeset
   233
    /* 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
   234
3202e4826c57 more valgrind errors fixed. Plus I ran make indent which changed a few files.
Bob Pendleton <bob@pendleton.com>
parents: 2323
diff changeset
   235
    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
   236
        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
   237
        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
   238
    } 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
   239
        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
   240
            (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
   241
                                            (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
   242
                                             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
   243
        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
   244
            SDL_free(data);
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 7007
diff changeset
   245
            return SDL_OutOfMemory();
2323
4ac07ae446d3 Fixed many valgrind errors. But, I broke testdyngl.
Bob Pendleton <bob@pendleton.com>
parents: 2322
diff changeset
   246
        }
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
   247
        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
   248
        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
   249
        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
   250
        videodata->windowlist = windowlist;
2323
4ac07ae446d3 Fixed many valgrind errors. But, I broke testdyngl.
Bob Pendleton <bob@pendleton.com>
parents: 2322
diff changeset
   251
    }
4ac07ae446d3 Fixed many valgrind errors. But, I broke testdyngl.
Bob Pendleton <bob@pendleton.com>
parents: 2322
diff changeset
   252
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   253
    /* 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
   254
    {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   255
        XWindowAttributes attrib;
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
        XGetWindowAttributes(data->videodata->display, w, &attrib);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   258
        window->x = attrib.x;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   259
        window->y = attrib.y;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   260
        window->w = attrib.width;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   261
        window->h = attrib.height;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   262
        if (attrib.map_state != IsUnmapped) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   263
            window->flags |= SDL_WINDOW_SHOWN;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   264
        } else {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   265
            window->flags &= ~SDL_WINDOW_SHOWN;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   266
        }
5182
073b86030262 Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents: 5088
diff changeset
   267
        data->visual = attrib.visual;
5466
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   268
        data->colormap = attrib.colormap;
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   269
    }
3077
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   270
6487
b18a011ecc45 Simplified the NetWM code a little bit, and it now operates on X11 Window
Sam Lantinga <slouken@libsdl.org>
parents: 6486
diff changeset
   271
    window->flags |= X11_GetNetWMState(_this, w);
3077
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   272
6024
38e2f4644548 Set up window focus correctly when using an existing X11 window.
Ryan C. Gordon <icculus@icculus.org>
parents: 6023
diff changeset
   273
    {
38e2f4644548 Set up window focus correctly when using an existing X11 window.
Ryan C. Gordon <icculus@icculus.org>
parents: 6023
diff changeset
   274
        Window FocalWindow;
38e2f4644548 Set up window focus correctly when using an existing X11 window.
Ryan C. Gordon <icculus@icculus.org>
parents: 6023
diff changeset
   275
        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
   276
        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
   277
        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
   278
        {
38e2f4644548 Set up window focus correctly when using an existing X11 window.
Ryan C. Gordon <icculus@icculus.org>
parents: 6023
diff changeset
   279
            window->flags |= SDL_WINDOW_INPUT_FOCUS;
6481
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
   280
        }
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
   281
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
   282
        if (window->flags & SDL_WINDOW_INPUT_FOCUS) {
6024
38e2f4644548 Set up window focus correctly when using an existing X11 window.
Ryan C. Gordon <icculus@icculus.org>
parents: 6023
diff changeset
   283
            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
   284
        }
38e2f4644548 Set up window focus correctly when using an existing X11 window.
Ryan C. Gordon <icculus@icculus.org>
parents: 6023
diff changeset
   285
38e2f4644548 Set up window focus correctly when using an existing X11 window.
Ryan C. Gordon <icculus@icculus.org>
parents: 6023
diff changeset
   286
        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
   287
            /* 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
   288
        }
38e2f4644548 Set up window focus correctly when using an existing X11 window.
Ryan C. Gordon <icculus@icculus.org>
parents: 6023
diff changeset
   289
    }
38e2f4644548 Set up window focus correctly when using an existing X11 window.
Ryan C. Gordon <icculus@icculus.org>
parents: 6023
diff changeset
   290
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   291
    /* All done! */
6487
b18a011ecc45 Simplified the NetWM code a little bit, and it now operates on X11 Window
Sam Lantinga <slouken@libsdl.org>
parents: 6486
diff changeset
   292
    window->driverdata = data;
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   293
    return 0;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   294
}
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   295
6422
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   296
static void
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   297
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
   298
{
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   299
    /*
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   300
     * 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
   301
     *  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
   302
     *  Gnome is similar: just use the Motif atom.
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   303
     */
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   304
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   305
    Atom WM_HINTS = XInternAtom(display, "_MOTIF_WM_HINTS", True);
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   306
    if (WM_HINTS != None) {
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   307
        /* Hints used by Motif compliant window managers */
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   308
        struct
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   309
        {
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   310
            unsigned long flags;
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   311
            unsigned long functions;
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   312
            unsigned long decorations;
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   313
            long input_mode;
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   314
            unsigned long status;
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   315
        } MWMHints = {
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   316
            (1L << 1), 0, border ? 1 : 0, 0, 0
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   317
        };
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   318
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   319
        XChangeProperty(display, window, WM_HINTS, WM_HINTS, 32,
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   320
                        PropModeReplace, (unsigned char *) &MWMHints,
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   321
                        sizeof(MWMHints) / 4);
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   322
    } else {  /* set the transient hints instead, if necessary */
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   323
        XSetTransientForHint(display, window, RootWindow(display, screen));
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   324
    }
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   325
}
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   326
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   327
int
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   328
X11_CreateWindow(_THIS, SDL_Window * window)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   329
{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   330
    SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   331
    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
   332
        (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
   333
    Display *display = data->display;
50125e8aab94 Let the window manager know we're a "normal" window
Sam Lantinga <slouken@libsdl.org>
parents: 4520
diff changeset
   334
    int screen = displaydata->screen;
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   335
    Visual *visual;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   336
    int depth;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   337
    XSetWindowAttributes xattr;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   338
    Window w;
6462
5e09ac1aba80 allocate *Hint structures per Xlib docs
Edward Rudd <urkle@outoforder.cc>
parents: 6423
diff changeset
   339
    XSizeHints *sizehints;
5e09ac1aba80 allocate *Hint structures per Xlib docs
Edward Rudd <urkle@outoforder.cc>
parents: 6423
diff changeset
   340
    XWMHints *wmhints;
5e09ac1aba80 allocate *Hint structures per Xlib docs
Edward Rudd <urkle@outoforder.cc>
parents: 6423
diff changeset
   341
    XClassHint *classhints;
7490
fc864efbc1a6 Add support for the _NET_WM_BYPASS_COMPOSITOR hint
Jasper St. Pierre <jstpierre@mecheye.net>
parents: 7445
diff changeset
   342
    const long _NET_WM_BYPASS_COMPOSITOR_HINT_ON = 1;
fc864efbc1a6 Add support for the _NET_WM_BYPASS_COMPOSITOR hint
Jasper St. Pierre <jstpierre@mecheye.net>
parents: 7445
diff changeset
   343
    Atom _NET_WM_BYPASS_COMPOSITOR;
4521
50125e8aab94 Let the window manager know we're a "normal" window
Sam Lantinga <slouken@libsdl.org>
parents: 4520
diff changeset
   344
    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
   345
    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
   346
    Atom _NET_WM_PID;
7001
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6970
diff changeset
   347
    Atom XdndAware, xdnd_version = 5;
6045
b8e995dab018 Fix crash on X servers without UTF-8 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 6024
diff changeset
   348
    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
   349
6369
a92fbd27127b Fix OpenGL initialization when OpenGL and OpenGLES are both available.
Sam Lantinga <slouken@libsdl.org>
parents: 6343
diff changeset
   350
#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
   351
    if (window->flags & SDL_WINDOW_OPENGL) {
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1951
diff changeset
   352
        XVisualInfo *vinfo;
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1951
diff changeset
   353
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7037
diff changeset
   354
#if SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
6370
93187f7f7d5d Improved simultaneous support for OpenGL and OpenGL ES
Sam Lantinga <slouken@libsdl.org>
parents: 6369
diff changeset
   355
        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
   356
            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
   357
        } else
a92fbd27127b Fix OpenGL initialization when OpenGL and OpenGLES are both available.
Sam Lantinga <slouken@libsdl.org>
parents: 6343
diff changeset
   358
#endif
a92fbd27127b Fix OpenGL initialization when OpenGL and OpenGLES are both available.
Sam Lantinga <slouken@libsdl.org>
parents: 6343
diff changeset
   359
        {
6370
93187f7f7d5d Improved simultaneous support for OpenGL and OpenGL ES
Sam Lantinga <slouken@libsdl.org>
parents: 6369
diff changeset
   360
#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
   361
            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
   362
#endif
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1951
diff changeset
   363
        }
3161
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3078
diff changeset
   364
        if (!vinfo) {
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3078
diff changeset
   365
            return -1;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3078
diff changeset
   366
        }
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3078
diff changeset
   367
        visual = vinfo->visual;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3078
diff changeset
   368
        depth = vinfo->depth;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3078
diff changeset
   369
        XFree(vinfo);
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3078
diff changeset
   370
    } else
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3078
diff changeset
   371
#endif
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1951
diff changeset
   372
    {
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   373
        visual = displaydata->visual;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   374
        depth = displaydata->depth;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   375
    }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   376
5386
762e67f81fc7 Simplified the X11 window creation
Sam Lantinga <slouken@libsdl.org>
parents: 5305
diff changeset
   377
    xattr.override_redirect = False;
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   378
    xattr.background_pixel = 0;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   379
    xattr.border_pixel = 0;
5466
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   380
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   381
    if (visual->class == DirectColor) {
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   382
        XColor *colorcells;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   383
        int i;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   384
        int ncolors;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   385
        int rmax, gmax, bmax;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   386
        int rmask, gmask, bmask;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   387
        int rshift, gshift, bshift;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   388
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   389
        xattr.colormap =
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   390
            XCreateColormap(display, RootWindow(display, screen),
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   391
                            visual, AllocAll);
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   392
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   393
        /* 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
   394
        if (!xattr.colormap) {
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 7007
diff changeset
   395
            return SDL_SetError("Could not create writable colormap");
5466
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   396
        }
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
        /* 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
   399
        colorcells = SDL_malloc(visual->map_entries * sizeof(XColor));
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   400
        if (!colorcells) {
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 7007
diff changeset
   401
            return SDL_OutOfMemory();
5466
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   402
        }
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   403
        ncolors = visual->map_entries;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   404
        rmax = 0xffff;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   405
        gmax = 0xffff;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   406
        bmax = 0xffff;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   407
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   408
        rshift = 0;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   409
        rmask = visual->red_mask;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   410
        while (0 == (rmask & 1)) {
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   411
            rshift++;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   412
            rmask >>= 1;
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
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   415
        gshift = 0;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   416
        gmask = visual->green_mask;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   417
        while (0 == (gmask & 1)) {
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   418
            gshift++;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   419
            gmask >>= 1;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   420
        }
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   421
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   422
        bshift = 0;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   423
        bmask = visual->blue_mask;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   424
        while (0 == (bmask & 1)) {
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   425
            bshift++;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   426
            bmask >>= 1;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   427
        }
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   428
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   429
        /* build the color table pixel values */
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   430
        for (i = 0; i < ncolors; i++) {
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   431
            Uint32 red = (rmax * i) / (ncolors - 1);
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   432
            Uint32 green = (gmax * i) / (ncolors - 1);
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   433
            Uint32 blue = (bmax * i) / (ncolors - 1);
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   434
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   435
            Uint32 rbits = (rmask * i) / (ncolors - 1);
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   436
            Uint32 gbits = (gmask * i) / (ncolors - 1);
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   437
            Uint32 bbits = (bmask * i) / (ncolors - 1);
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   438
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   439
            Uint32 pix =
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   440
                (rbits << rshift) | (gbits << gshift) | (bbits << bshift);
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   441
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   442
            colorcells[i].pixel = pix;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   443
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   444
            colorcells[i].red = red;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   445
            colorcells[i].green = green;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   446
            colorcells[i].blue = blue;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   447
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   448
            colorcells[i].flags = DoRed | DoGreen | DoBlue;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   449
        }
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   450
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   451
        XStoreColors(display, xattr.colormap, colorcells, ncolors);
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   452
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   453
        SDL_free(colorcells);
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   454
    } else {
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   455
        xattr.colormap =
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   456
            XCreateColormap(display, RootWindow(display, screen),
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   457
                            visual, AllocNone);
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   458
    }
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   459
5386
762e67f81fc7 Simplified the X11 window creation
Sam Lantinga <slouken@libsdl.org>
parents: 5305
diff changeset
   460
    w = XCreateWindow(display, RootWindow(display, screen),
762e67f81fc7 Simplified the X11 window creation
Sam Lantinga <slouken@libsdl.org>
parents: 5305
diff changeset
   461
                      window->x, window->y, window->w, window->h,
762e67f81fc7 Simplified the X11 window creation
Sam Lantinga <slouken@libsdl.org>
parents: 5305
diff changeset
   462
                      0, depth, InputOutput, visual,
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   463
                      (CWOverrideRedirect | CWBackPixel | CWBorderPixel |
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   464
                       CWColormap), &xattr);
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1951
diff changeset
   465
    if (!w) {
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 7007
diff changeset
   466
        return SDL_SetError("Couldn't create window");
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1951
diff changeset
   467
    }
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6167
diff changeset
   468
#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
   469
    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
   470
        if (!_this->gles_data) {
494e0436525f More OpenGL ES fixes from Scott Percival
Sam Lantinga <slouken@libsdl.org>
parents: 6370
diff changeset
   471
            XDestroyWindow(display, w);
494e0436525f More OpenGL ES fixes from Scott Percival
Sam Lantinga <slouken@libsdl.org>
parents: 6370
diff changeset
   472
            return -1;
494e0436525f More OpenGL ES fixes from Scott Percival
Sam Lantinga <slouken@libsdl.org>
parents: 6370
diff changeset
   473
        }
494e0436525f More OpenGL ES fixes from Scott Percival
Sam Lantinga <slouken@libsdl.org>
parents: 6370
diff changeset
   474
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6167
diff changeset
   475
        /* 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
   476
        _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
   477
            _this->gles_data->eglCreateWindowSurface(_this->gles_data->
3161
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3078
diff changeset
   478
                                                 egl_display,
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3078
diff changeset
   479
                                                 _this->gles_data->egl_config,
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3078
diff changeset
   480
                                                 (NativeWindowType) w, NULL);
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3078
diff changeset
   481
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6167
diff changeset
   482
        if (_this->gles_data->egl_surface == EGL_NO_SURFACE) {
6373
494e0436525f More OpenGL ES fixes from Scott Percival
Sam Lantinga <slouken@libsdl.org>
parents: 6370
diff changeset
   483
            XDestroyWindow(display, w);
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 7007
diff changeset
   484
            return SDL_SetError("Could not create GLES window surface");
6188
e82023802002 Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
Sam Lantinga <slouken@libsdl.org>
parents: 6167
diff changeset
   485
        }
3161
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3078
diff changeset
   486
    }
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3078
diff changeset
   487
#endif
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   488
6422
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   489
    SetWindowBordered(display, screen, w,
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   490
                      (window->flags & SDL_WINDOW_BORDERLESS) == 0);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   491
6462
5e09ac1aba80 allocate *Hint structures per Xlib docs
Edward Rudd <urkle@outoforder.cc>
parents: 6423
diff changeset
   492
    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
   493
    /* Setup the normal size hints */
6462
5e09ac1aba80 allocate *Hint structures per Xlib docs
Edward Rudd <urkle@outoforder.cc>
parents: 6423
diff changeset
   494
    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
   495
    if (!(window->flags & SDL_WINDOW_RESIZABLE)) {
6462
5e09ac1aba80 allocate *Hint structures per Xlib docs
Edward Rudd <urkle@outoforder.cc>
parents: 6423
diff changeset
   496
        sizehints->min_width = sizehints->max_width = window->w;
5e09ac1aba80 allocate *Hint structures per Xlib docs
Edward Rudd <urkle@outoforder.cc>
parents: 6423
diff changeset
   497
        sizehints->min_height = sizehints->max_height = window->h;
5e09ac1aba80 allocate *Hint structures per Xlib docs
Edward Rudd <urkle@outoforder.cc>
parents: 6423
diff changeset
   498
        sizehints->flags |= (PMaxSize | PMinSize);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   499
    }
6462
5e09ac1aba80 allocate *Hint structures per Xlib docs
Edward Rudd <urkle@outoforder.cc>
parents: 6423
diff changeset
   500
    sizehints->x = window->x;
5e09ac1aba80 allocate *Hint structures per Xlib docs
Edward Rudd <urkle@outoforder.cc>
parents: 6423
diff changeset
   501
    sizehints->y = window->y;
5e09ac1aba80 allocate *Hint structures per Xlib docs
Edward Rudd <urkle@outoforder.cc>
parents: 6423
diff changeset
   502
    sizehints->flags |= USPosition;
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   503
6167
c071e1372341 X11: Move to XSetWMProperties and add support to _NET_WM_PID
Marco Trevisan (Treviño) <mail@3v1n0.net>
parents: 6138
diff changeset
   504
    /* 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
   505
    wmhints = XAllocWMHints();
5e09ac1aba80 allocate *Hint structures per Xlib docs
Edward Rudd <urkle@outoforder.cc>
parents: 6423
diff changeset
   506
    wmhints->input = True;
5e09ac1aba80 allocate *Hint structures per Xlib docs
Edward Rudd <urkle@outoforder.cc>
parents: 6423
diff changeset
   507
    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
   508
c071e1372341 X11: Move to XSetWMProperties and add support to _NET_WM_PID
Marco Trevisan (Treviño) <mail@3v1n0.net>
parents: 6138
diff changeset
   509
    /* 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
   510
    classhints = XAllocClassHint();
5e09ac1aba80 allocate *Hint structures per Xlib docs
Edward Rudd <urkle@outoforder.cc>
parents: 6423
diff changeset
   511
    classhints->res_name = data->classname;
5e09ac1aba80 allocate *Hint structures per Xlib docs
Edward Rudd <urkle@outoforder.cc>
parents: 6423
diff changeset
   512
    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
   513
c071e1372341 X11: Move to XSetWMProperties and add support to _NET_WM_PID
Marco Trevisan (Treviño) <mail@3v1n0.net>
parents: 6138
diff changeset
   514
    /* 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
   515
    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
   516
6462
5e09ac1aba80 allocate *Hint structures per Xlib docs
Edward Rudd <urkle@outoforder.cc>
parents: 6423
diff changeset
   517
    XFree(sizehints);
5e09ac1aba80 allocate *Hint structures per Xlib docs
Edward Rudd <urkle@outoforder.cc>
parents: 6423
diff changeset
   518
    XFree(wmhints);
5e09ac1aba80 allocate *Hint structures per Xlib docs
Edward Rudd <urkle@outoforder.cc>
parents: 6423
diff changeset
   519
    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
   520
    /* 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
   521
    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
   522
        _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
   523
        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
   524
                        (unsigned char *)&data->pid, 1);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   525
    }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   526
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
   527
    /* Set the window manager state */
6487
b18a011ecc45 Simplified the NetWM code a little bit, and it now operates on X11 Window
Sam Lantinga <slouken@libsdl.org>
parents: 6486
diff changeset
   528
    X11_SetNetWMState(_this, w, window->flags);
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
   529
4521
50125e8aab94 Let the window manager know we're a "normal" window
Sam Lantinga <slouken@libsdl.org>
parents: 4520
diff changeset
   530
    /* 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
   531
    _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
   532
    _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
   533
    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
   534
                    PropModeReplace,
50125e8aab94 Let the window manager know we're a "normal" window
Sam Lantinga <slouken@libsdl.org>
parents: 4520
diff changeset
   535
                    (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
   536
7490
fc864efbc1a6 Add support for the _NET_WM_BYPASS_COMPOSITOR hint
Jasper St. Pierre <jstpierre@mecheye.net>
parents: 7445
diff changeset
   537
    _NET_WM_BYPASS_COMPOSITOR = XInternAtom(display, "_NET_WM_BYPASS_COMPOSITOR", False);
fc864efbc1a6 Add support for the _NET_WM_BYPASS_COMPOSITOR hint
Jasper St. Pierre <jstpierre@mecheye.net>
parents: 7445
diff changeset
   538
    XChangeProperty(display, w, _NET_WM_BYPASS_COMPOSITOR, XA_CARDINAL, 32,
fc864efbc1a6 Add support for the _NET_WM_BYPASS_COMPOSITOR hint
Jasper St. Pierre <jstpierre@mecheye.net>
parents: 7445
diff changeset
   539
                    PropModeReplace,
fc864efbc1a6 Add support for the _NET_WM_BYPASS_COMPOSITOR hint
Jasper St. Pierre <jstpierre@mecheye.net>
parents: 7445
diff changeset
   540
                    (unsigned char *)&_NET_WM_BYPASS_COMPOSITOR_HINT_ON, 1);
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7037
diff changeset
   541
6638
3d221da309d3 X11: Handle _NET_WM_PING protocol, so window manager knows when app is hung up.
Ryan C. Gordon <icculus@icculus.org>
parents: 6575
diff changeset
   542
    {
3d221da309d3 X11: Handle _NET_WM_PING protocol, so window manager knows when app is hung up.
Ryan C. Gordon <icculus@icculus.org>
parents: 6575
diff changeset
   543
        Atom protocols[] = {
3d221da309d3 X11: Handle _NET_WM_PING protocol, so window manager knows when app is hung up.
Ryan C. Gordon <icculus@icculus.org>
parents: 6575
diff changeset
   544
            data->WM_DELETE_WINDOW, /* Allow window to be deleted by the WM */
3d221da309d3 X11: Handle _NET_WM_PING protocol, so window manager knows when app is hung up.
Ryan C. Gordon <icculus@icculus.org>
parents: 6575
diff changeset
   545
            data->_NET_WM_PING, /* Respond so WM knows we're alive */
3d221da309d3 X11: Handle _NET_WM_PING protocol, so window manager knows when app is hung up.
Ryan C. Gordon <icculus@icculus.org>
parents: 6575
diff changeset
   546
        };
3d221da309d3 X11: Handle _NET_WM_PING protocol, so window manager knows when app is hung up.
Ryan C. Gordon <icculus@icculus.org>
parents: 6575
diff changeset
   547
        XSetWMProtocols(display, w, protocols, sizeof (protocols) / sizeof (protocols[0]));
3d221da309d3 X11: Handle _NET_WM_PING protocol, so window manager knows when app is hung up.
Ryan C. Gordon <icculus@icculus.org>
parents: 6575
diff changeset
   548
    }
1951
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
    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
   551
        XDestroyWindow(display, w);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   552
        return -1;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   553
    }
5386
762e67f81fc7 Simplified the X11 window creation
Sam Lantinga <slouken@libsdl.org>
parents: 5305
diff changeset
   554
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
   555
#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
   556
    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
   557
        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
   558
                      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
   559
    }
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
   560
#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
   561
6316
a89c79a3f0cd 1.Moved all xinput2 functionality to its own file
Dimitris Zenios <dimitris.zenios@gmail.com>
parents: 6275
diff changeset
   562
    X11_Xinput2SelectTouch(_this, window);
a89c79a3f0cd 1.Moved all xinput2 functionality to its own file
Dimitris Zenios <dimitris.zenios@gmail.com>
parents: 6275
diff changeset
   563
6045
b8e995dab018 Fix crash on X servers without UTF-8 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 6024
diff changeset
   564
    XSelectInput(display, w,
b8e995dab018 Fix crash on X servers without UTF-8 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 6024
diff changeset
   565
                 (FocusChangeMask | EnterWindowMask | LeaveWindowMask |
b8e995dab018 Fix crash on X servers without UTF-8 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 6024
diff changeset
   566
                 ExposureMask | ButtonPressMask | ButtonReleaseMask |
b8e995dab018 Fix crash on X servers without UTF-8 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 6024
diff changeset
   567
                 PointerMotionMask | KeyPressMask | KeyReleaseMask |
b8e995dab018 Fix crash on X servers without UTF-8 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 6024
diff changeset
   568
                 PropertyChangeMask | StructureNotifyMask |
b8e995dab018 Fix crash on X servers without UTF-8 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 6024
diff changeset
   569
                 KeymapStateMask | fevent));
b8e995dab018 Fix crash on X servers without UTF-8 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 6024
diff changeset
   570
7001
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6970
diff changeset
   571
    XdndAware = XInternAtom(display, "XdndAware", False);
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6970
diff changeset
   572
    XChangeProperty(display, w, XdndAware, XA_ATOM, 32,
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6970
diff changeset
   573
                 PropModeReplace,
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7037
diff changeset
   574
                 (unsigned char*)&xdnd_version, 1);
7001
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6970
diff changeset
   575
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
   576
    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
   577
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   578
    return 0;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   579
}
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   580
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   581
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
   582
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
   583
{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   584
    Window w = (Window) data;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   585
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
   586
    window->title = X11_GetWindowTitle(_this, w);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   587
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   588
    if (SetupWindowData(_this, window, w, SDL_FALSE) < 0) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   589
        return -1;
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
    return 0;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   592
}
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   593
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
   594
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
   595
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
   596
{
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
   597
    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
   598
    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
   599
    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
   600
    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
   601
    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
   602
    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
   603
    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
   604
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
   605
    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
   606
                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
   607
                &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
   608
    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
   609
        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
   610
        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
   611
    } 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
   612
        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
   613
                    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
   614
                    &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
   615
        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
   616
            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
   617
        } 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
   618
            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
   619
        }
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
   620
    }
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
   621
    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
   622
}
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
   623
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   624
void
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   625
X11_SetWindowTitle(_THIS, SDL_Window * window)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   626
{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   627
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   628
    Display *display = data->videodata->display;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   629
    XTextProperty titleprop, iconprop;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   630
    Status status;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   631
    const char *title = window->title;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   632
    const char *icon = NULL;
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
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
   635
    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
   636
    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
   637
#endif
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   638
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   639
    if (title != NULL) {
2143
e906da4414a3 Fix for bug #447 merged from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents: 1956
diff changeset
   640
        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
   641
        if (!title_locale) {
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   642
            SDL_OutOfMemory();
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   643
            return;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   644
        }
2143
e906da4414a3 Fix for bug #447 merged from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents: 1956
diff changeset
   645
        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
   646
        SDL_free(title_locale);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   647
        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
   648
            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
   649
            XFree(titleprop.value);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   650
        }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   651
#ifdef X_HAVE_UTF8_STRING
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   652
        if (SDL_X11_HAVE_UTF8) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   653
            status =
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   654
                Xutf8TextListToTextProperty(display, (char **) &title, 1,
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   655
                                            XUTF8StringStyle, &titleprop);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   656
            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
   657
                XSetTextProperty(display, data->xwindow, &titleprop,
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   658
                                 _NET_WM_NAME);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   659
                XFree(titleprop.value);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   660
            }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   661
        }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   662
#endif
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   663
    }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   664
    if (icon != NULL) {
2143
e906da4414a3 Fix for bug #447 merged from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents: 1956
diff changeset
   665
        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
   666
        if (!icon_locale) {
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   667
            SDL_OutOfMemory();
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   668
            return;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   669
        }
2143
e906da4414a3 Fix for bug #447 merged from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents: 1956
diff changeset
   670
        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
   671
        SDL_free(icon_locale);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   672
        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
   673
            XSetTextProperty(display, data->xwindow, &iconprop,
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   674
                             XA_WM_ICON_NAME);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   675
            XFree(iconprop.value);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   676
        }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   677
#ifdef X_HAVE_UTF8_STRING
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   678
        if (SDL_X11_HAVE_UTF8) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   679
            status =
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   680
                Xutf8TextListToTextProperty(display, (char **) &icon, 1,
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   681
                                            XUTF8StringStyle, &iconprop);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   682
            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
   683
                XSetTextProperty(display, data->xwindow, &iconprop,
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   684
                                 _NET_WM_ICON_NAME);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   685
                XFree(iconprop.value);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   686
            }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   687
        }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   688
#endif
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   689
    }
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
   690
    XFlush(display);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   691
}
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   692
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   693
void
2967
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
   694
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
   695
{
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
   696
    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
   697
    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
   698
    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
   699
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
   700
    if (icon) {
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
   701
        SDL_PixelFormat format;
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
   702
        SDL_Surface *surface;
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
   703
        int propsize;
4528
f06faa886423 Fixed bug 1022
Sam Lantinga <slouken@libsdl.org>
parents: 4524
diff changeset
   704
        long *propdata;
2967
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
   705
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
   706
        /* Convert the icon to ARGB for modern window managers */
5288
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   707
        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
   708
        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
   709
        if (!surface) {
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
   710
            return;
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
   711
        }
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
   712
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
   713
        /* Set the _NET_WM_ICON property */
2990
Sam Lantinga <slouken@libsdl.org>
parents: 2967
diff changeset
   714
        propsize = 2 + (icon->w * icon->h);
4566
40c833d951a1 Fixed memory corruption on AMD64
Sam Lantinga <slouken@libsdl.org>
parents: 4555
diff changeset
   715
        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
   716
        if (propdata) {
4528
f06faa886423 Fixed bug 1022
Sam Lantinga <slouken@libsdl.org>
parents: 4524
diff changeset
   717
            int x, y;
f06faa886423 Fixed bug 1022
Sam Lantinga <slouken@libsdl.org>
parents: 4524
diff changeset
   718
            Uint32 *src;
f06faa886423 Fixed bug 1022
Sam Lantinga <slouken@libsdl.org>
parents: 4524
diff changeset
   719
            long *dst;
f06faa886423 Fixed bug 1022
Sam Lantinga <slouken@libsdl.org>
parents: 4524
diff changeset
   720
2967
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
   721
            propdata[0] = icon->w;
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
   722
            propdata[1] = icon->h;
4528
f06faa886423 Fixed bug 1022
Sam Lantinga <slouken@libsdl.org>
parents: 4524
diff changeset
   723
            dst = &propdata[2];
f06faa886423 Fixed bug 1022
Sam Lantinga <slouken@libsdl.org>
parents: 4524
diff changeset
   724
            for (y = 0; y < icon->h; ++y) {
f06faa886423 Fixed bug 1022
Sam Lantinga <slouken@libsdl.org>
parents: 4524
diff changeset
   725
                src = (Uint32*)((Uint8*)surface->pixels + y * surface->pitch);
f06faa886423 Fixed bug 1022
Sam Lantinga <slouken@libsdl.org>
parents: 4524
diff changeset
   726
                for (x = 0; x < icon->w; ++x) {
f06faa886423 Fixed bug 1022
Sam Lantinga <slouken@libsdl.org>
parents: 4524
diff changeset
   727
                    *dst++ = *src++;
f06faa886423 Fixed bug 1022
Sam Lantinga <slouken@libsdl.org>
parents: 4524
diff changeset
   728
                }
f06faa886423 Fixed bug 1022
Sam Lantinga <slouken@libsdl.org>
parents: 4524
diff changeset
   729
            }
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
   730
            XChangeProperty(display, data->xwindow, _NET_WM_ICON, XA_CARDINAL,
2990
Sam Lantinga <slouken@libsdl.org>
parents: 2967
diff changeset
   731
                            32, PropModeReplace, (unsigned char *) propdata,
Sam Lantinga <slouken@libsdl.org>
parents: 2967
diff changeset
   732
                            propsize);
2967
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
   733
        }
6562
c52863165594 Fixed memory leak in X11_SetWindowIcon().
Ryan C. Gordon <icculus@icculus.org>
parents: 6541
diff changeset
   734
        SDL_free(propdata);
2967
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
   735
        SDL_FreeSurface(surface);
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
   736
    } 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
   737
        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
   738
    }
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
   739
    XFlush(display);
2967
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
   740
}
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
   741
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
   742
void
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   743
X11_SetWindowPosition(_THIS, SDL_Window * window)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   744
{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   745
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   746
    Display *display = data->videodata->display;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   747
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
   748
    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
   749
    XFlush(display);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   750
}
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   751
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   752
void
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   753
X11_SetWindowSize(_THIS, SDL_Window * window)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   754
{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   755
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   756
    Display *display = data->videodata->display;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   757
6481
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
   758
    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
   759
        X11_ResizeWindowShape(window);
6481
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
   760
    }
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
   761
    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
   762
         /* 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
   763
            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
   764
         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
   765
         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
   766
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
   767
         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
   768
6343
e94f912d20b9 Fix SDL_SetWindowSize with X11 non-RESIZABLE windows, patch by Pierre-Loup.
Sam Lantinga <slouken@libsdl.org>
parents: 6336
diff changeset
   769
         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
   770
         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
   771
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
   772
         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
   773
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
   774
         XFree(sizehints);
6541
be103236441d Poke window managers to get them to respect the resize hints.
Sam Lantinga <slouken@libsdl.org>
parents: 6540
diff changeset
   775
be103236441d Poke window managers to get them to respect the resize hints.
Sam Lantinga <slouken@libsdl.org>
parents: 6540
diff changeset
   776
        /* From Pierre-Loup:
6899
f75b1bd8eabc Fix SDL_SetWindowSize on certain WMs.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6885
diff changeset
   777
           WMs each have their little quirks with that.  When you change the
f75b1bd8eabc Fix SDL_SetWindowSize on certain WMs.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6885
diff changeset
   778
           size hints, they get a ConfigureNotify event with the
f75b1bd8eabc Fix SDL_SetWindowSize on certain WMs.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6885
diff changeset
   779
           WM_NORMAL_SIZE_HINTS Atom.  They all save the hints then, but they
f75b1bd8eabc Fix SDL_SetWindowSize on certain WMs.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6885
diff changeset
   780
           don't all resize the window right away to enforce the new hints.
6541
be103236441d Poke window managers to get them to respect the resize hints.
Sam Lantinga <slouken@libsdl.org>
parents: 6540
diff changeset
   781
6899
f75b1bd8eabc Fix SDL_SetWindowSize on certain WMs.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6885
diff changeset
   782
           Some of them resize only after:
f75b1bd8eabc Fix SDL_SetWindowSize on certain WMs.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6885
diff changeset
   783
            - A user-initiated move or resize
f75b1bd8eabc Fix SDL_SetWindowSize on certain WMs.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6885
diff changeset
   784
            - A code-initiated move or resize
f75b1bd8eabc Fix SDL_SetWindowSize on certain WMs.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6885
diff changeset
   785
            - Hiding & showing window (Unmap & map)
6541
be103236441d Poke window managers to get them to respect the resize hints.
Sam Lantinga <slouken@libsdl.org>
parents: 6540
diff changeset
   786
6899
f75b1bd8eabc Fix SDL_SetWindowSize on certain WMs.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6885
diff changeset
   787
           The following move & resize seems to help a lot of WMs that didn't
f75b1bd8eabc Fix SDL_SetWindowSize on certain WMs.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6885
diff changeset
   788
           properly update after the hints were changed. We don't do a
f75b1bd8eabc Fix SDL_SetWindowSize on certain WMs.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6885
diff changeset
   789
           hide/show, because there are supposedly subtle problems with doing so
f75b1bd8eabc Fix SDL_SetWindowSize on certain WMs.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6885
diff changeset
   790
           and transitioning from windowed to fullscreen in Unity.
f75b1bd8eabc Fix SDL_SetWindowSize on certain WMs.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6885
diff changeset
   791
         */
f75b1bd8eabc Fix SDL_SetWindowSize on certain WMs.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6885
diff changeset
   792
        XResizeWindow(display, data->xwindow, window->w, window->h);
f75b1bd8eabc Fix SDL_SetWindowSize on certain WMs.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6885
diff changeset
   793
        XMoveWindow(display, data->xwindow, window->x, window->y);
6541
be103236441d Poke window managers to get them to respect the resize hints.
Sam Lantinga <slouken@libsdl.org>
parents: 6540
diff changeset
   794
        XRaiseWindow(display, data->xwindow);
6481
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
   795
    } else {
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
   796
        XResizeWindow(display, data->xwindow, window->w, window->h);
6481
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
   797
    }
6899
f75b1bd8eabc Fix SDL_SetWindowSize on certain WMs.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6885
diff changeset
   798
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
   799
    XFlush(display);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   800
}
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   801
6422
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   802
void
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   803
X11_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered)
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   804
{
6423
339c0ccf6250 Make the X11 SetBordered event tapdancing more robust, restore focus, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 6422
diff changeset
   805
    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
   806
    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
   807
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   808
    SDL_DisplayData *displaydata =
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   809
        (SDL_DisplayData *) SDL_GetDisplayForWindow(window)->driverdata;
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   810
    Display *display = data->videodata->display;
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   811
    XEvent event;
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   812
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   813
    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
   814
    XFlush(display);
6422
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   815
    XIfEvent(display, &event, &isConfigureNotify, (XPointer)&data->xwindow);
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   816
6423
339c0ccf6250 Make the X11 SetBordered event tapdancing more robust, restore focus, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 6422
diff changeset
   817
    if (visible) {
339c0ccf6250 Make the X11 SetBordered event tapdancing more robust, restore focus, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 6422
diff changeset
   818
        XWindowAttributes attr;
339c0ccf6250 Make the X11 SetBordered event tapdancing more robust, restore focus, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 6422
diff changeset
   819
        do {
339c0ccf6250 Make the X11 SetBordered event tapdancing more robust, restore focus, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 6422
diff changeset
   820
            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
   821
            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
   822
        } 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
   823
339c0ccf6250 Make the X11 SetBordered event tapdancing more robust, restore focus, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 6422
diff changeset
   824
        if (focused) {
339c0ccf6250 Make the X11 SetBordered event tapdancing more robust, restore focus, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 6422
diff changeset
   825
            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
   826
        }
339c0ccf6250 Make the X11 SetBordered event tapdancing more robust, restore focus, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 6422
diff changeset
   827
    }
339c0ccf6250 Make the X11 SetBordered event tapdancing more robust, restore focus, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 6422
diff changeset
   828
6422
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   829
    /* 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
   830
    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
   831
    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
   832
    XCheckIfEvent(display, &event, &isMapNotify, (XPointer)&data->xwindow);
6422
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   833
}
6336
6e6163b6ba69 Fixed issue with tiling window managers (bug 1246)
Sam Lantinga <slouken@libsdl.org>
parents: 6331
diff changeset
   834
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   835
void
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   836
X11_ShowWindow(_THIS, SDL_Window * window)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   837
{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   838
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   839
    Display *display = data->videodata->display;
6336
6e6163b6ba69 Fixed issue with tiling window managers (bug 1246)
Sam Lantinga <slouken@libsdl.org>
parents: 6331
diff changeset
   840
    XEvent event;
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   841
6483
4b51ff3dcf74 Only map/unmap if the window isn't already in the correct state.
Sam Lantinga <slouken@libsdl.org>
parents: 6481
diff changeset
   842
    if (!X11_IsWindowMapped(_this, window)) {
4b51ff3dcf74 Only map/unmap if the window isn't already in the correct state.
Sam Lantinga <slouken@libsdl.org>
parents: 6481
diff changeset
   843
        XMapRaised(display, data->xwindow);
4b51ff3dcf74 Only map/unmap if the window isn't already in the correct state.
Sam Lantinga <slouken@libsdl.org>
parents: 6481
diff changeset
   844
        /* Blocking wait for "MapNotify" event.
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7037
diff changeset
   845
         * We use XIfEvent because XWindowEvent takes a mask rather than a type,
6483
4b51ff3dcf74 Only map/unmap if the window isn't already in the correct state.
Sam Lantinga <slouken@libsdl.org>
parents: 6481
diff changeset
   846
         * and XCheckTypedWindowEvent doesn't block */
4b51ff3dcf74 Only map/unmap if the window isn't already in the correct state.
Sam Lantinga <slouken@libsdl.org>
parents: 6481
diff changeset
   847
        XIfEvent(display, &event, &isMapNotify, (XPointer)&data->xwindow);
4b51ff3dcf74 Only map/unmap if the window isn't already in the correct state.
Sam Lantinga <slouken@libsdl.org>
parents: 6481
diff changeset
   848
        XFlush(display);
4b51ff3dcf74 Only map/unmap if the window isn't already in the correct state.
Sam Lantinga <slouken@libsdl.org>
parents: 6481
diff changeset
   849
    }
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   850
}
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   851
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   852
void
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   853
X11_HideWindow(_THIS, SDL_Window * window)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   854
{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   855
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   856
    Display *display = data->videodata->display;
6336
6e6163b6ba69 Fixed issue with tiling window managers (bug 1246)
Sam Lantinga <slouken@libsdl.org>
parents: 6331
diff changeset
   857
    XEvent event;
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   858
6483
4b51ff3dcf74 Only map/unmap if the window isn't already in the correct state.
Sam Lantinga <slouken@libsdl.org>
parents: 6481
diff changeset
   859
    if (X11_IsWindowMapped(_this, window)) {
4b51ff3dcf74 Only map/unmap if the window isn't already in the correct state.
Sam Lantinga <slouken@libsdl.org>
parents: 6481
diff changeset
   860
        XUnmapWindow(display, data->xwindow);
4b51ff3dcf74 Only map/unmap if the window isn't already in the correct state.
Sam Lantinga <slouken@libsdl.org>
parents: 6481
diff changeset
   861
        /* Blocking wait for "UnmapNotify" event */
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7037
diff changeset
   862
        XIfEvent(display, &event, &isUnmapNotify, (XPointer)&data->xwindow);
6483
4b51ff3dcf74 Only map/unmap if the window isn't already in the correct state.
Sam Lantinga <slouken@libsdl.org>
parents: 6481
diff changeset
   863
        XFlush(display);
4b51ff3dcf74 Only map/unmap if the window isn't already in the correct state.
Sam Lantinga <slouken@libsdl.org>
parents: 6481
diff changeset
   864
    }
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   865
}
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   866
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   867
void
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   868
X11_RaiseWindow(_THIS, SDL_Window * window)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   869
{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   870
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   871
    Display *display = data->videodata->display;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   872
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
   873
    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
   874
    XFlush(display);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   875
}
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   876
3077
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   877
static void
5302
b1b9ec9874ba Implemented X11 fullscreen toggling with modern window managers
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   878
SetWindowMaximized(_THIS, SDL_Window * window, SDL_bool maximized)
3077
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   879
{
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   880
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   881
    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
   882
        (SDL_DisplayData *) SDL_GetDisplayForWindow(window)->driverdata;
3077
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   883
    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
   884
    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
   885
    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
   886
    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
   887
a4da6b906abb Fixed setting fullscreen and maximized states for windows that haven't been mapped yet.
Sam Lantinga <slouken@libsdl.org>
parents: 4521
diff changeset
   888
    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
   889
        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
   890
4524
a256e1dadf3f Zero any fields not explicitly filled in.
Sam Lantinga <slouken@libsdl.org>
parents: 4522
diff changeset
   891
        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
   892
        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
   893
        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
   894
        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
   895
        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
   896
        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
   897
            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
   898
        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
   899
        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
   900
        e.xclient.data.l[3] = 0l;
3077
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   901
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
   902
        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
   903
                   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
   904
    } else {
6481
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
   905
        Uint32 flags;
3077
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   906
6481
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
   907
        flags = window->flags;
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
   908
        if (maximized) {
6481
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
   909
            flags |= SDL_WINDOW_MAXIMIZED;
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
   910
        } else {
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
   911
            flags &= ~SDL_WINDOW_MAXIMIZED;
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
   912
        }
6487
b18a011ecc45 Simplified the NetWM code a little bit, and it now operates on X11 Window
Sam Lantinga <slouken@libsdl.org>
parents: 6486
diff changeset
   913
        X11_SetNetWMState(_this, data->xwindow, flags);
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
   914
    }
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
   915
    XFlush(display);
3077
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   916
}
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   917
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   918
void
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   919
X11_MaximizeWindow(_THIS, SDL_Window * window)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   920
{
5302
b1b9ec9874ba Implemented X11 fullscreen toggling with modern window managers
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   921
    SetWindowMaximized(_this, window, SDL_TRUE);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   922
}
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   923
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   924
void
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   925
X11_MinimizeWindow(_THIS, SDL_Window * window)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   926
{
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
   927
    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
   928
    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
   929
        (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
   930
    Display *display = data->videodata->display;
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7037
diff changeset
   931
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
   932
    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
   933
    XFlush(display);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   934
}
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   935
6970
e0db39f7afb0 Make it so SDL_RestoreWindow() implements the _NET_ACTIVE_WINDOW protocol which some window managers require to restore full screen windows. CR: saml
Sam Lantinga <slouken@libsdl.org>
parents: 6899
diff changeset
   936
static void
e0db39f7afb0 Make it so SDL_RestoreWindow() implements the _NET_ACTIVE_WINDOW protocol which some window managers require to restore full screen windows. CR: saml
Sam Lantinga <slouken@libsdl.org>
parents: 6899
diff changeset
   937
SetWindowActive(_THIS, SDL_Window * window)
e0db39f7afb0 Make it so SDL_RestoreWindow() implements the _NET_ACTIVE_WINDOW protocol which some window managers require to restore full screen windows. CR: saml
Sam Lantinga <slouken@libsdl.org>
parents: 6899
diff changeset
   938
{
e0db39f7afb0 Make it so SDL_RestoreWindow() implements the _NET_ACTIVE_WINDOW protocol which some window managers require to restore full screen windows. CR: saml
Sam Lantinga <slouken@libsdl.org>
parents: 6899
diff changeset
   939
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
e0db39f7afb0 Make it so SDL_RestoreWindow() implements the _NET_ACTIVE_WINDOW protocol which some window managers require to restore full screen windows. CR: saml
Sam Lantinga <slouken@libsdl.org>
parents: 6899
diff changeset
   940
    SDL_DisplayData *displaydata =
e0db39f7afb0 Make it so SDL_RestoreWindow() implements the _NET_ACTIVE_WINDOW protocol which some window managers require to restore full screen windows. CR: saml
Sam Lantinga <slouken@libsdl.org>
parents: 6899
diff changeset
   941
        (SDL_DisplayData *) SDL_GetDisplayForWindow(window)->driverdata;
e0db39f7afb0 Make it so SDL_RestoreWindow() implements the _NET_ACTIVE_WINDOW protocol which some window managers require to restore full screen windows. CR: saml
Sam Lantinga <slouken@libsdl.org>
parents: 6899
diff changeset
   942
    Display *display = data->videodata->display;
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7037
diff changeset
   943
    Atom _NET_ACTIVE_WINDOW = data->videodata->_NET_ACTIVE_WINDOW;
6970
e0db39f7afb0 Make it so SDL_RestoreWindow() implements the _NET_ACTIVE_WINDOW protocol which some window managers require to restore full screen windows. CR: saml
Sam Lantinga <slouken@libsdl.org>
parents: 6899
diff changeset
   944
e0db39f7afb0 Make it so SDL_RestoreWindow() implements the _NET_ACTIVE_WINDOW protocol which some window managers require to restore full screen windows. CR: saml
Sam Lantinga <slouken@libsdl.org>
parents: 6899
diff changeset
   945
    if (X11_IsWindowMapped(_this, window)) {
e0db39f7afb0 Make it so SDL_RestoreWindow() implements the _NET_ACTIVE_WINDOW protocol which some window managers require to restore full screen windows. CR: saml
Sam Lantinga <slouken@libsdl.org>
parents: 6899
diff changeset
   946
        XEvent e;
e0db39f7afb0 Make it so SDL_RestoreWindow() implements the _NET_ACTIVE_WINDOW protocol which some window managers require to restore full screen windows. CR: saml
Sam Lantinga <slouken@libsdl.org>
parents: 6899
diff changeset
   947
e0db39f7afb0 Make it so SDL_RestoreWindow() implements the _NET_ACTIVE_WINDOW protocol which some window managers require to restore full screen windows. CR: saml
Sam Lantinga <slouken@libsdl.org>
parents: 6899
diff changeset
   948
        SDL_zero(e);
e0db39f7afb0 Make it so SDL_RestoreWindow() implements the _NET_ACTIVE_WINDOW protocol which some window managers require to restore full screen windows. CR: saml
Sam Lantinga <slouken@libsdl.org>
parents: 6899
diff changeset
   949
        e.xany.type = ClientMessage;
e0db39f7afb0 Make it so SDL_RestoreWindow() implements the _NET_ACTIVE_WINDOW protocol which some window managers require to restore full screen windows. CR: saml
Sam Lantinga <slouken@libsdl.org>
parents: 6899
diff changeset
   950
        e.xclient.message_type = _NET_ACTIVE_WINDOW;
e0db39f7afb0 Make it so SDL_RestoreWindow() implements the _NET_ACTIVE_WINDOW protocol which some window managers require to restore full screen windows. CR: saml
Sam Lantinga <slouken@libsdl.org>
parents: 6899
diff changeset
   951
        e.xclient.format = 32;
e0db39f7afb0 Make it so SDL_RestoreWindow() implements the _NET_ACTIVE_WINDOW protocol which some window managers require to restore full screen windows. CR: saml
Sam Lantinga <slouken@libsdl.org>
parents: 6899
diff changeset
   952
        e.xclient.window = data->xwindow;
e0db39f7afb0 Make it so SDL_RestoreWindow() implements the _NET_ACTIVE_WINDOW protocol which some window managers require to restore full screen windows. CR: saml
Sam Lantinga <slouken@libsdl.org>
parents: 6899
diff changeset
   953
        e.xclient.data.l[0] = 1;  /* source indication. 1 = application */
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7037
diff changeset
   954
        e.xclient.data.l[1] = CurrentTime;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7037
diff changeset
   955
        e.xclient.data.l[2] = 0;
6970
e0db39f7afb0 Make it so SDL_RestoreWindow() implements the _NET_ACTIVE_WINDOW protocol which some window managers require to restore full screen windows. CR: saml
Sam Lantinga <slouken@libsdl.org>
parents: 6899
diff changeset
   956
e0db39f7afb0 Make it so SDL_RestoreWindow() implements the _NET_ACTIVE_WINDOW protocol which some window managers require to restore full screen windows. CR: saml
Sam Lantinga <slouken@libsdl.org>
parents: 6899
diff changeset
   957
        XSendEvent(display, RootWindow(display, displaydata->screen), 0,
e0db39f7afb0 Make it so SDL_RestoreWindow() implements the _NET_ACTIVE_WINDOW protocol which some window managers require to restore full screen windows. CR: saml
Sam Lantinga <slouken@libsdl.org>
parents: 6899
diff changeset
   958
                   SubstructureNotifyMask | SubstructureRedirectMask, &e);
e0db39f7afb0 Make it so SDL_RestoreWindow() implements the _NET_ACTIVE_WINDOW protocol which some window managers require to restore full screen windows. CR: saml
Sam Lantinga <slouken@libsdl.org>
parents: 6899
diff changeset
   959
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7037
diff changeset
   960
        XFlush(display);
6970
e0db39f7afb0 Make it so SDL_RestoreWindow() implements the _NET_ACTIVE_WINDOW protocol which some window managers require to restore full screen windows. CR: saml
Sam Lantinga <slouken@libsdl.org>
parents: 6899
diff changeset
   961
    }
e0db39f7afb0 Make it so SDL_RestoreWindow() implements the _NET_ACTIVE_WINDOW protocol which some window managers require to restore full screen windows. CR: saml
Sam Lantinga <slouken@libsdl.org>
parents: 6899
diff changeset
   962
}
e0db39f7afb0 Make it so SDL_RestoreWindow() implements the _NET_ACTIVE_WINDOW protocol which some window managers require to restore full screen windows. CR: saml
Sam Lantinga <slouken@libsdl.org>
parents: 6899
diff changeset
   963
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   964
void
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   965
X11_RestoreWindow(_THIS, SDL_Window * window)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   966
{
5302
b1b9ec9874ba Implemented X11 fullscreen toggling with modern window managers
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   967
    SetWindowMaximized(_this, window, SDL_FALSE);
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7037
diff changeset
   968
    SetWindowActive(_this, window);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   969
    X11_ShowWindow(_this, window);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   970
}
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   971
6467
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
   972
/* 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
   973
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
   974
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
   975
{
b1b9ec9874ba Implemented X11 fullscreen toggling with modern window managers
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   976
    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
   977
    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
   978
    Display *display = data->videodata->display;
b1b9ec9874ba Implemented X11 fullscreen toggling with modern window managers
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   979
    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
   980
    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
   981
b1b9ec9874ba Implemented X11 fullscreen toggling with modern window managers
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   982
    if (X11_IsWindowMapped(_this, window)) {
b1b9ec9874ba Implemented X11 fullscreen toggling with modern window managers
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   983
        XEvent e;
b1b9ec9874ba Implemented X11 fullscreen toggling with modern window managers
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   984
6539
c76274e7f32a Always set the size hints for consistent behavior with all window managers, and it wasn't resetting when switching back from fullscreen mode.
Sam Lantinga <slouken@libsdl.org>
parents: 6501
diff changeset
   985
        if (!(window->flags & SDL_WINDOW_RESIZABLE)) {
c76274e7f32a Always set the size hints for consistent behavior with all window managers, and it wasn't resetting when switching back from fullscreen mode.
Sam Lantinga <slouken@libsdl.org>
parents: 6501
diff changeset
   986
            /* Compiz refuses fullscreen toggle if we're not resizable, so update the hints so we
c76274e7f32a Always set the size hints for consistent behavior with all window managers, and it wasn't resetting when switching back from fullscreen mode.
Sam Lantinga <slouken@libsdl.org>
parents: 6501
diff changeset
   987
               can be resized to the fullscreen resolution (or reset so we're not resizable again) */
c76274e7f32a Always set the size hints for consistent behavior with all window managers, and it wasn't resetting when switching back from fullscreen mode.
Sam Lantinga <slouken@libsdl.org>
parents: 6501
diff changeset
   988
            XSizeHints *sizehints = XAllocSizeHints();
c76274e7f32a Always set the size hints for consistent behavior with all window managers, and it wasn't resetting when switching back from fullscreen mode.
Sam Lantinga <slouken@libsdl.org>
parents: 6501
diff changeset
   989
            long flags = 0;
c76274e7f32a Always set the size hints for consistent behavior with all window managers, and it wasn't resetting when switching back from fullscreen mode.
Sam Lantinga <slouken@libsdl.org>
parents: 6501
diff changeset
   990
            XGetWMNormalHints(display, data->xwindow, sizehints, &flags);
c76274e7f32a Always set the size hints for consistent behavior with all window managers, and it wasn't resetting when switching back from fullscreen mode.
Sam Lantinga <slouken@libsdl.org>
parents: 6501
diff changeset
   991
            /* set the resize flags on */
c76274e7f32a Always set the size hints for consistent behavior with all window managers, and it wasn't resetting when switching back from fullscreen mode.
Sam Lantinga <slouken@libsdl.org>
parents: 6501
diff changeset
   992
            if (fullscreen) {
c76274e7f32a Always set the size hints for consistent behavior with all window managers, and it wasn't resetting when switching back from fullscreen mode.
Sam Lantinga <slouken@libsdl.org>
parents: 6501
diff changeset
   993
                /* we are going fullscreen so turn the flags off */
c76274e7f32a Always set the size hints for consistent behavior with all window managers, and it wasn't resetting when switching back from fullscreen mode.
Sam Lantinga <slouken@libsdl.org>
parents: 6501
diff changeset
   994
                sizehints->flags &= ~(PMinSize | PMaxSize);
c76274e7f32a Always set the size hints for consistent behavior with all window managers, and it wasn't resetting when switching back from fullscreen mode.
Sam Lantinga <slouken@libsdl.org>
parents: 6501
diff changeset
   995
            } else {
c76274e7f32a Always set the size hints for consistent behavior with all window managers, and it wasn't resetting when switching back from fullscreen mode.
Sam Lantinga <slouken@libsdl.org>
parents: 6501
diff changeset
   996
                /* Reset the min/max width height to make the window non-resizable again */
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
   997
                sizehints->flags |= PMinSize | PMaxSize;
6540
44459e2f6e4d Fix the size to the windowed mode, not the fullscreen mode.
Sam Lantinga <slouken@libsdl.org>
parents: 6539
diff changeset
   998
                sizehints->min_width = sizehints->max_width = window->windowed.w;
44459e2f6e4d Fix the size to the windowed mode, not the fullscreen mode.
Sam Lantinga <slouken@libsdl.org>
parents: 6539
diff changeset
   999
                sizehints->min_height = sizehints->max_height = window->windowed.h;
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
  1000
            }
6539
c76274e7f32a Always set the size hints for consistent behavior with all window managers, and it wasn't resetting when switching back from fullscreen mode.
Sam Lantinga <slouken@libsdl.org>
parents: 6501
diff changeset
  1001
            XSetWMNormalHints(display, data->xwindow, sizehints);
c76274e7f32a Always set the size hints for consistent behavior with all window managers, and it wasn't resetting when switching back from fullscreen mode.
Sam Lantinga <slouken@libsdl.org>
parents: 6501
diff changeset
  1002
            XFree(sizehints);
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
  1003
        }
6539
c76274e7f32a Always set the size hints for consistent behavior with all window managers, and it wasn't resetting when switching back from fullscreen mode.
Sam Lantinga <slouken@libsdl.org>
parents: 6501
diff changeset
  1004
5302
b1b9ec9874ba Implemented X11 fullscreen toggling with modern window managers
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
  1005
        SDL_zero(e);
b1b9ec9874ba Implemented X11 fullscreen toggling with modern window managers
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
  1006
        e.xany.type = ClientMessage;
b1b9ec9874ba Implemented X11 fullscreen toggling with modern window managers
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
  1007
        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
  1008
        e.xclient.format = 32;
b1b9ec9874ba Implemented X11 fullscreen toggling with modern window managers
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
  1009
        e.xclient.window = data->xwindow;
b1b9ec9874ba Implemented X11 fullscreen toggling with modern window managers
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
  1010
        e.xclient.data.l[0] =
b1b9ec9874ba Implemented X11 fullscreen toggling with modern window managers
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
  1011
            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
  1012
        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
  1013
        e.xclient.data.l[3] = 0l;
b1b9ec9874ba Implemented X11 fullscreen toggling with modern window managers
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
  1014
b1b9ec9874ba Implemented X11 fullscreen toggling with modern window managers
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
  1015
        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
  1016
                   SubstructureNotifyMask | SubstructureRedirectMask, &e);
b1b9ec9874ba Implemented X11 fullscreen toggling with modern window managers
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
  1017
    } else {
6481
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff changeset
  1018
        Uint32 flags;
5302
b1b9ec9874ba Implemented X11 fullscreen toggling with modern window managers
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
  1019
6481
fab4b15b17e9 Compositing window managers can show and hide windows without ever affecting the mapped state. However they do send NetWM protocol messages to indicate this is happening.
Sam Lantinga <slouken@libsdl.org>
parents: 6480
diff