src/video/x11/SDL_x11window.c
author Ryan C. Gordon <icculus@icculus.org>
Fri, 04 Mar 2016 19:41:16 -0500
changeset 10103 9cec5fe32bca
parent 10102 11b490897d27
permissions -rw-r--r--
x11: Fix a few more XMoveWindow() calls to adjust for border size. Also, fix my inability to do basic math ('+' should have been '-').
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
9998
f67cf37e9cd4 Updated copyright to 2016
Sam Lantinga <slouken@libsdl.org>
parents: 9899
diff changeset
     3
  Copyright (C) 1997-2016 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
*/
8093
b43765095a6f Make internal SDL sources include SDL_internal.h instead of SDL_config.h
Ryan C. Gordon <icculus@icculus.org>
parents: 7960
diff changeset
    21
#include "../../SDL_internal.h"
1951
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
7523
9e9ab1dc3811 Fixed bug 1919 - Window icon disappears as soon as a renderer is created
Sam Lantinga <slouken@libsdl.org>
parents: 7522
diff changeset
    25
#include "SDL_assert.h"
6662
698c2e533a7e SDL no longer grabs the keyboard by default on X11.
Sam Lantinga <slouken@libsdl.org>
parents: 6638
diff changeset
    26
#include "SDL_hints.h"
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    27
#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
    28
#include "../SDL_pixels_c.h"
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    29
#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
    30
#include "../../events/SDL_mouse_c.h"
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    31
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    32
#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
    33
#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
    34
#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
    35
#include "SDL_x11xinput2.h"
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    36
7659
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7632
diff changeset
    37
#if SDL_VIDEO_OPENGL_EGL
3161
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3078
diff changeset
    38
#include "SDL_x11opengles.h"
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3078
diff changeset
    39
#endif
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3078
diff changeset
    40
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
    41
#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
    42
#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
    43
#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
    44
3077
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
    45
#define _NET_WM_STATE_REMOVE    0l
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
    46
#define _NET_WM_STATE_ADD       1l
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
    47
#define _NET_WM_STATE_TOGGLE    2l
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
    48
6467
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
    49
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
    50
{
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
    51
    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
    52
}
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
    53
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
    54
{
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
    55
    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
    56
}
9838
5b9fa1c4d15b X11: isConfigureNotify() isn't used at the moment, comment it out.
Ryan C. Gordon <icculus@icculus.org>
parents: 9837
diff changeset
    57
5b9fa1c4d15b X11: isConfigureNotify() isn't used at the moment, comment it out.
Ryan C. Gordon <icculus@icculus.org>
parents: 9837
diff changeset
    58
/*
6467
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
    59
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
    60
{
6480
d02a4369b3f5 Hopefully improved legacy fullscreen handling (it works now on my Ubuntu Unity system)
Sam Lantinga <slouken@libsdl.org>
parents: 6479
diff changeset
    61
    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
    62
}
7632
d6a8fa507a45 Fixed bug 2027 - Full-screen appears to be broken - hang in SDL_DestroyWindow()
Sam Lantinga <slouken@libsdl.org>
parents: 7617
diff changeset
    63
static Bool
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7808
diff changeset
    64
X11_XIfEventTimeout(Display *display, XEvent *event_return, Bool (*predicate)(), XPointer arg, int timeoutMS)
7632
d6a8fa507a45 Fixed bug 2027 - Full-screen appears to be broken - hang in SDL_DestroyWindow()
Sam Lantinga <slouken@libsdl.org>
parents: 7617
diff changeset
    65
{
d6a8fa507a45 Fixed bug 2027 - Full-screen appears to be broken - hang in SDL_DestroyWindow()
Sam Lantinga <slouken@libsdl.org>
parents: 7617
diff changeset
    66
    Uint32 start = SDL_GetTicks();
d6a8fa507a45 Fixed bug 2027 - Full-screen appears to be broken - hang in SDL_DestroyWindow()
Sam Lantinga <slouken@libsdl.org>
parents: 7617
diff changeset
    67
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7808
diff changeset
    68
    while (!X11_XCheckIfEvent(display, event_return, predicate, arg)) {
7857
6388f5229bb7 Added a macro SDL_TICKS_PASSED() to correctly compare two 32-bit tick values.
Sam Lantinga <slouken@libsdl.org>
parents: 7827
diff changeset
    69
        if (SDL_TICKS_PASSED(SDL_GetTicks(), start + timeoutMS)) {
7632
d6a8fa507a45 Fixed bug 2027 - Full-screen appears to be broken - hang in SDL_DestroyWindow()
Sam Lantinga <slouken@libsdl.org>
parents: 7617
diff changeset
    70
            return False;
d6a8fa507a45 Fixed bug 2027 - Full-screen appears to be broken - hang in SDL_DestroyWindow()
Sam Lantinga <slouken@libsdl.org>
parents: 7617
diff changeset
    71
        }
d6a8fa507a45 Fixed bug 2027 - Full-screen appears to be broken - hang in SDL_DestroyWindow()
Sam Lantinga <slouken@libsdl.org>
parents: 7617
diff changeset
    72
    }
d6a8fa507a45 Fixed bug 2027 - Full-screen appears to be broken - hang in SDL_DestroyWindow()
Sam Lantinga <slouken@libsdl.org>
parents: 7617
diff changeset
    73
    return True;
d6a8fa507a45 Fixed bug 2027 - Full-screen appears to be broken - hang in SDL_DestroyWindow()
Sam Lantinga <slouken@libsdl.org>
parents: 7617
diff changeset
    74
}
d6a8fa507a45 Fixed bug 2027 - Full-screen appears to be broken - hang in SDL_DestroyWindow()
Sam Lantinga <slouken@libsdl.org>
parents: 7617
diff changeset
    75
*/
d6a8fa507a45 Fixed bug 2027 - Full-screen appears to be broken - hang in SDL_DestroyWindow()
Sam Lantinga <slouken@libsdl.org>
parents: 7617
diff changeset
    76
6467
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
    77
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
    78
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
    79
{
ec5a04e921d4 X11: Attempt to go fullscreen the way SDL 1.2 did it.
Ryan C. Gordon <icculus@icculus.org>
parents: 6466
diff changeset
    80
    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
    81
    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
    82
}
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
    83
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
    84
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
    85
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
    86
{
a4da6b906abb Fixed setting fullscreen and maximized states for windows that haven't been mapped yet.
Sam Lantinga <slouken@libsdl.org>
parents: 4521
diff changeset
    87
    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
    88
    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
    89
    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
    90
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7808
diff changeset
    91
    X11_XGetWindowAttributes(videodata->display, data->xwindow, &attr);
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
    92
    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
    93
        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
    94
    } 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
    95
        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
    96
    }
a4da6b906abb Fixed setting fullscreen and maximized states for windows that haven't been mapped yet.
Sam Lantinga <slouken@libsdl.org>
parents: 4521
diff changeset
    97
}
a4da6b906abb Fixed setting fullscreen and maximized states for windows that haven't been mapped yet.
Sam Lantinga <slouken@libsdl.org>
parents: 4521
diff changeset
    98
6540
44459e2f6e4d Fix the size to the windowed mode, not the fullscreen mode.
Sam Lantinga <slouken@libsdl.org>
parents: 6539
diff changeset
    99
#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
   100
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
   101
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
   102
{
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
   103
    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
   104
    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
   105
    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
   106
    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
   107
    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
   108
    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
   109
    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
   110
    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
   111
    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
   112
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7808
diff changeset
   113
    if (X11_XGetWindowProperty(display, data->xwindow, _NET_WM_ALLOWED_ACTIONS, 0, 1024, False, XA_ATOM, &type, &form, &len, &remain, (unsigned char **)&list) == Success)
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
        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
   116
        {
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
   117
            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
   118
                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
   119
                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
   120
            }
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
        }
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7808
diff changeset
   122
        X11_XFree(list);
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
   123
    }
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
   124
    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
   125
}
6540
44459e2f6e4d Fix the size to the windowed mode, not the fullscreen mode.
Sam Lantinga <slouken@libsdl.org>
parents: 6539
diff changeset
   126
#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
   127
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
   128
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
   129
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
   130
{
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
    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
   132
    Display *display = videodata->display;
10010
cc07869515b2 Added a few FIXMEs.
Ryan C. Gordon <icculus@icculus.org>
parents: 10007
diff changeset
   133
    /* !!! FIXME: just dereference videodata below instead of copying to locals. */
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
   134
    Atom _NET_WM_STATE = videodata->_NET_WM_STATE;
7678
286c42d7c5ed OCD fixes: Adds a space after /* (glory to regular expressions!)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7677
diff changeset
   135
    /* 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
   136
    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
   137
    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
   138
    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
   139
    Atom _NET_WM_STATE_FULLSCREEN = videodata->_NET_WM_STATE_FULLSCREEN;
10021
3beca914a2ad Added special window type flags.
Ryan C. Gordon <icculus@icculus.org>
parents: 10017
diff changeset
   140
    Atom _NET_WM_STATE_ABOVE = videodata->_NET_WM_STATE_ABOVE;
3beca914a2ad Added special window type flags.
Ryan C. Gordon <icculus@icculus.org>
parents: 10017
diff changeset
   141
    Atom _NET_WM_STATE_SKIP_TASKBAR = videodata->_NET_WM_STATE_SKIP_TASKBAR;
3beca914a2ad Added special window type flags.
Ryan C. Gordon <icculus@icculus.org>
parents: 10017
diff changeset
   142
    Atom _NET_WM_STATE_SKIP_PAGER = videodata->_NET_WM_STATE_SKIP_PAGER;
3beca914a2ad Added special window type flags.
Ryan C. Gordon <icculus@icculus.org>
parents: 10017
diff changeset
   143
    Atom atoms[16];
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
   144
    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
   145
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
   146
    /* 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
   147
       If we did, this would indicate to the window manager that we don't
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7808
diff changeset
   148
       actually want to be mapped during X11_XMapRaised(), which would be bad.
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
   149
     *
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
   150
    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
   151
        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
   152
    }
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
   153
    */
10021
3beca914a2ad Added special window type flags.
Ryan C. Gordon <icculus@icculus.org>
parents: 10017
diff changeset
   154
3beca914a2ad Added special window type flags.
Ryan C. Gordon <icculus@icculus.org>
parents: 10017
diff changeset
   155
    if (flags & SDL_WINDOW_ALWAYS_ON_TOP) {
3beca914a2ad Added special window type flags.
Ryan C. Gordon <icculus@icculus.org>
parents: 10017
diff changeset
   156
        atoms[count++] = _NET_WM_STATE_ABOVE;
3beca914a2ad Added special window type flags.
Ryan C. Gordon <icculus@icculus.org>
parents: 10017
diff changeset
   157
    }
3beca914a2ad Added special window type flags.
Ryan C. Gordon <icculus@icculus.org>
parents: 10017
diff changeset
   158
    if (flags & SDL_WINDOW_SKIP_TASKBAR) {
3beca914a2ad Added special window type flags.
Ryan C. Gordon <icculus@icculus.org>
parents: 10017
diff changeset
   159
        atoms[count++] = _NET_WM_STATE_SKIP_TASKBAR;
3beca914a2ad Added special window type flags.
Ryan C. Gordon <icculus@icculus.org>
parents: 10017
diff changeset
   160
        atoms[count++] = _NET_WM_STATE_SKIP_PAGER;
3beca914a2ad Added special window type flags.
Ryan C. Gordon <icculus@icculus.org>
parents: 10017
diff changeset
   161
    }
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
   162
    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
   163
        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
   164
    }
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
   165
    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
   166
        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
   167
        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
   168
    }
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
    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
   170
        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
   171
    }
10021
3beca914a2ad Added special window type flags.
Ryan C. Gordon <icculus@icculus.org>
parents: 10017
diff changeset
   172
3beca914a2ad Added special window type flags.
Ryan C. Gordon <icculus@icculus.org>
parents: 10017
diff changeset
   173
    SDL_assert(count <= SDL_arraysize(atoms));
3beca914a2ad Added special window type flags.
Ryan C. Gordon <icculus@icculus.org>
parents: 10017
diff changeset
   174
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
   175
    if (count > 0) {
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7808
diff changeset
   176
        X11_XChangeProperty(display, xwindow, _NET_WM_STATE, XA_ATOM, 32,
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
   177
                        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
   178
    } else {
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7808
diff changeset
   179
        X11_XDeleteProperty(display, xwindow, _NET_WM_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
   180
    }
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
   181
}
a4da6b906abb Fixed setting fullscreen and maximized states for windows that haven't been mapped yet.
Sam Lantinga <slouken@libsdl.org>
parents: 4521
diff changeset
   182
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
   183
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
   184
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
   185
{
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
    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
   187
    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
   188
    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
   189
    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
   190
    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
   191
    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
   192
    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
   193
    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
   194
    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
   195
    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
   196
    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
   197
    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
   198
    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
   199
    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
   200
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7808
diff changeset
   201
    if (X11_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
   202
                           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
   203
                           &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
   204
                           &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
   205
        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
   206
        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
   207
        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
   208
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
   209
        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
   210
            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
   211
                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
   212
            } 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
   213
                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
   214
            } 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
   215
                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
   216
            } 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
   217
                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
   218
            } 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
   219
                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
   220
            }
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
   221
        }
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
   222
        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
   223
            flags |= SDL_WINDOW_MAXIMIZED;
10017
363c41b866cd x11: window managers might mark windows as FULLSCREEN _and_ MAXIMIZED.
Ryan C. Gordon <icculus@icculus.org>
parents: 10016
diff changeset
   224
        }
363c41b866cd x11: window managers might mark windows as FULLSCREEN _and_ MAXIMIZED.
Ryan C. Gordon <icculus@icculus.org>
parents: 10016
diff changeset
   225
363c41b866cd x11: window managers might mark windows as FULLSCREEN _and_ MAXIMIZED.
Ryan C. Gordon <icculus@icculus.org>
parents: 10016
diff changeset
   226
        if (fullscreen == 1) {
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
   227
            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
   228
        }
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7808
diff changeset
   229
        X11_XFree(propertyValue);
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
   230
    }
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
   231
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
   232
    /* FIXME, check the size hints for resizable */
7678
286c42d7c5ed OCD fixes: Adds a space after /* (glory to regular expressions!)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7677
diff changeset
   233
    /* 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
   234
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
   235
    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
   236
}
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
   237
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   238
static int
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   239
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
   240
{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   241
    SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   242
    SDL_WindowData *data;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   243
    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
   244
    int windowlistlength = videodata->windowlistlength;
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   245
    SDL_WindowData **windowlist = videodata->windowlist;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   246
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   247
    /* Allocate the window data */
2323
4ac07ae446d3 Fixed many valgrind errors. But, I broke testdyngl.
Bob Pendleton <bob@pendleton.com>
parents: 2322
diff changeset
   248
    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
   249
    if (!data) {
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 7007
diff changeset
   250
        return SDL_OutOfMemory();
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   251
    }
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
   252
    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
   253
    data->xwindow = w;
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   254
#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
   255
    if (SDL_X11_HAVE_UTF8 && videodata->im) {
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   256
        data->ic =
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7808
diff changeset
   257
            X11_XCreateIC(videodata->im, XNClientWindow, w, XNFocusWindow, w,
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   258
                       XNInputStyle, XIMPreeditNothing | XIMStatusNothing,
8707
d838991b3fb0 Fixed bug 2086 - valgrind memory not released
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
   259
                       NULL);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   260
    }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   261
#endif
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   262
    data->created = created;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   263
    data->videodata = videodata;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   264
2323
4ac07ae446d3 Fixed many valgrind errors. But, I broke testdyngl.
Bob Pendleton <bob@pendleton.com>
parents: 2322
diff changeset
   265
    /* 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
   266
3202e4826c57 more valgrind errors fixed. Plus I ran make indent which changed a few files.
Bob Pendleton <bob@pendleton.com>
parents: 2323
diff changeset
   267
    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
   268
        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
   269
        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
   270
    } 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
   271
        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
   272
            (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
   273
                                            (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
   274
                                             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
   275
        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
   276
            SDL_free(data);
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 7007
diff changeset
   277
            return SDL_OutOfMemory();
2323
4ac07ae446d3 Fixed many valgrind errors. But, I broke testdyngl.
Bob Pendleton <bob@pendleton.com>
parents: 2322
diff changeset
   278
        }
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
   279
        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
   280
        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
   281
        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
   282
        videodata->windowlist = windowlist;
2323
4ac07ae446d3 Fixed many valgrind errors. But, I broke testdyngl.
Bob Pendleton <bob@pendleton.com>
parents: 2322
diff changeset
   283
    }
4ac07ae446d3 Fixed many valgrind errors. But, I broke testdyngl.
Bob Pendleton <bob@pendleton.com>
parents: 2322
diff changeset
   284
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   285
    /* 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
   286
    {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   287
        XWindowAttributes attrib;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   288
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7808
diff changeset
   289
        X11_XGetWindowAttributes(data->videodata->display, w, &attrib);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   290
        window->x = attrib.x;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   291
        window->y = attrib.y;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   292
        window->w = attrib.width;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   293
        window->h = attrib.height;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   294
        if (attrib.map_state != IsUnmapped) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   295
            window->flags |= SDL_WINDOW_SHOWN;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   296
        } else {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   297
            window->flags &= ~SDL_WINDOW_SHOWN;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   298
        }
5182
073b86030262 Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents: 5088
diff changeset
   299
        data->visual = attrib.visual;
5466
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   300
        data->colormap = attrib.colormap;
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   301
    }
3077
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   302
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
   303
    window->flags |= X11_GetNetWMState(_this, w);
3077
9b58f26ede81 Implemented X11 maximized state control
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   304
6024
38e2f4644548 Set up window focus correctly when using an existing X11 window.
Ryan C. Gordon <icculus@icculus.org>
parents: 6023
diff changeset
   305
    {
38e2f4644548 Set up window focus correctly when using an existing X11 window.
Ryan C. Gordon <icculus@icculus.org>
parents: 6023
diff changeset
   306
        Window FocalWindow;
38e2f4644548 Set up window focus correctly when using an existing X11 window.
Ryan C. Gordon <icculus@icculus.org>
parents: 6023
diff changeset
   307
        int RevertTo=0;
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7808
diff changeset
   308
        X11_XGetInputFocus(data->videodata->display, &FocalWindow, &RevertTo);
6024
38e2f4644548 Set up window focus correctly when using an existing X11 window.
Ryan C. Gordon <icculus@icculus.org>
parents: 6023
diff changeset
   309
        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
   310
        {
38e2f4644548 Set up window focus correctly when using an existing X11 window.
Ryan C. Gordon <icculus@icculus.org>
parents: 6023
diff changeset
   311
            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
   312
        }
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
   313
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
   314
        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
   315
            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
   316
        }
38e2f4644548 Set up window focus correctly when using an existing X11 window.
Ryan C. Gordon <icculus@icculus.org>
parents: 6023
diff changeset
   317
38e2f4644548 Set up window focus correctly when using an existing X11 window.
Ryan C. Gordon <icculus@icculus.org>
parents: 6023
diff changeset
   318
        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
   319
            /* 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
   320
        }
38e2f4644548 Set up window focus correctly when using an existing X11 window.
Ryan C. Gordon <icculus@icculus.org>
parents: 6023
diff changeset
   321
    }
38e2f4644548 Set up window focus correctly when using an existing X11 window.
Ryan C. Gordon <icculus@icculus.org>
parents: 6023
diff changeset
   322
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   323
    /* 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
   324
    window->driverdata = data;
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   325
    return 0;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   326
}
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   327
6422
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   328
static void
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   329
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
   330
{
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   331
    /*
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   332
     * 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
   333
     *  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
   334
     *  Gnome is similar: just use the Motif atom.
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   335
     */
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   336
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7808
diff changeset
   337
    Atom WM_HINTS = X11_XInternAtom(display, "_MOTIF_WM_HINTS", True);
6422
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   338
    if (WM_HINTS != None) {
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   339
        /* Hints used by Motif compliant window managers */
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   340
        struct
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   341
        {
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   342
            unsigned long flags;
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   343
            unsigned long functions;
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   344
            unsigned long decorations;
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   345
            long input_mode;
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   346
            unsigned long status;
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   347
        } MWMHints = {
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   348
            (1L << 1), 0, border ? 1 : 0, 0, 0
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   349
        };
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   350
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7808
diff changeset
   351
        X11_XChangeProperty(display, window, WM_HINTS, WM_HINTS, 32,
6422
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   352
                        PropModeReplace, (unsigned char *) &MWMHints,
9460
1aa9826bb1bd the last parameter of XChangeProperty is the number of elements.. and when the element format is 32.. the element is "long" so we have 5 long elements here.
Edward Rudd <urkle@outoforder.cc>
parents: 9117
diff changeset
   353
                        sizeof(MWMHints) / sizeof(long));
6422
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   354
    } else {  /* set the transient hints instead, if necessary */
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7808
diff changeset
   355
        X11_XSetTransientForHint(display, window, RootWindow(display, screen));
6422
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   356
    }
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   357
}
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   358
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   359
int
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   360
X11_CreateWindow(_THIS, SDL_Window * window)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   361
{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   362
    SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   363
    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
   364
        (SDL_DisplayData *) SDL_GetDisplayForWindow(window)->driverdata;
7683
f7c061286490 Fixed crash if the IC isn't set up for some reason (bad X11 locale?)
Sam Lantinga <slouken@libsdl.org>
parents: 7678
diff changeset
   365
    SDL_WindowData *windowdata;
4521
50125e8aab94 Let the window manager know we're a "normal" window
Sam Lantinga <slouken@libsdl.org>
parents: 4520
diff changeset
   366
    Display *display = data->display;
50125e8aab94 Let the window manager know we're a "normal" window
Sam Lantinga <slouken@libsdl.org>
parents: 4520
diff changeset
   367
    int screen = displaydata->screen;
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   368
    Visual *visual;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   369
    int depth;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   370
    XSetWindowAttributes xattr;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   371
    Window w;
6462
5e09ac1aba80 allocate *Hint structures per Xlib docs
Edward Rudd <urkle@outoforder.cc>
parents: 6423
diff changeset
   372
    XSizeHints *sizehints;
5e09ac1aba80 allocate *Hint structures per Xlib docs
Edward Rudd <urkle@outoforder.cc>
parents: 6423
diff changeset
   373
    XWMHints *wmhints;
5e09ac1aba80 allocate *Hint structures per Xlib docs
Edward Rudd <urkle@outoforder.cc>
parents: 6423
diff changeset
   374
    XClassHint *classhints;
7490
fc864efbc1a6 Add support for the _NET_WM_BYPASS_COMPOSITOR hint
Jasper St. Pierre <jstpierre@mecheye.net>
parents: 7445
diff changeset
   375
    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
   376
    Atom _NET_WM_WINDOW_TYPE;
10021
3beca914a2ad Added special window type flags.
Ryan C. Gordon <icculus@icculus.org>
parents: 10017
diff changeset
   377
    Atom wintype;
3beca914a2ad Added special window type flags.
Ryan C. Gordon <icculus@icculus.org>
parents: 10017
diff changeset
   378
    const char *wintype_name = NULL;
3beca914a2ad Added special window type flags.
Ryan C. Gordon <icculus@icculus.org>
parents: 10017
diff changeset
   379
    int compositor = 1;
6167
c071e1372341 X11: Move to XSetWMProperties and add support to _NET_WM_PID
Marco Trevisan (Treviño) <mail@3v1n0.net>
parents: 6138
diff changeset
   380
    Atom _NET_WM_PID;
7001
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6970
diff changeset
   381
    Atom XdndAware, xdnd_version = 5;
8785
b74a32894c02 Fixed stack overflow in X11_CreateWindow() (thanks, rapha and Brad!).
Ryan C. Gordon <icculus@icculus.org>
parents: 8780
diff changeset
   382
    long 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
   383
7659
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7632
diff changeset
   384
#if SDL_VIDEO_OPENGL_GLX || SDL_VIDEO_OPENGL_EGL
7737
e9d463cb5b49 [SDL] X11+GL: Allow Visual override for GL windows.
pgriffais@spaceport
parents: 7723
diff changeset
   385
    if ((window->flags & SDL_WINDOW_OPENGL) &&
e9d463cb5b49 [SDL] X11+GL: Allow Visual override for GL windows.
pgriffais@spaceport
parents: 7723
diff changeset
   386
        !SDL_getenv("SDL_VIDEO_X11_VISUALID")) {
7723
aea98cc3e696 Fixes bug #2040, prepare SDL_GL_CONTEXT_EGL for deprecation on v2.1
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7683
diff changeset
   387
        XVisualInfo *vinfo = NULL;
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1951
diff changeset
   388
7659
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7632
diff changeset
   389
#if SDL_VIDEO_OPENGL_EGL
7808
627f256b0e56 Fixes X11 video backend compilation when no GL is available
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7750
diff changeset
   390
        if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES 
627f256b0e56 Fixes X11 video backend compilation when no GL is available
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7750
diff changeset
   391
#if SDL_VIDEO_OPENGL_GLX            
627f256b0e56 Fixes X11 video backend compilation when no GL is available
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7750
diff changeset
   392
            && ( !_this->gl_data || ! _this->gl_data->HAS_GLX_EXT_create_context_es2_profile )
627f256b0e56 Fixes X11 video backend compilation when no GL is available
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7750
diff changeset
   393
#endif
8780
2d8d64a681ad Fixed crash if the OpenGL library hasn't been loaded yet
Sam Lantinga <slouken@libsdl.org>
parents: 8707
diff changeset
   394
        ) {
6369
a92fbd27127b Fix OpenGL initialization when OpenGL and OpenGLES are both available.
Sam Lantinga <slouken@libsdl.org>
parents: 6343
diff changeset
   395
            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
   396
        } else
a92fbd27127b Fix OpenGL initialization when OpenGL and OpenGLES are both available.
Sam Lantinga <slouken@libsdl.org>
parents: 6343
diff changeset
   397
#endif
a92fbd27127b Fix OpenGL initialization when OpenGL and OpenGLES are both available.
Sam Lantinga <slouken@libsdl.org>
parents: 6343
diff changeset
   398
        {
6370
93187f7f7d5d Improved simultaneous support for OpenGL and OpenGL ES
Sam Lantinga <slouken@libsdl.org>
parents: 6369
diff changeset
   399
#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
   400
            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
   401
#endif
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1951
diff changeset
   402
        }
7723
aea98cc3e696 Fixes bug #2040, prepare SDL_GL_CONTEXT_EGL for deprecation on v2.1
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7683
diff changeset
   403
3161
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3078
diff changeset
   404
        if (!vinfo) {
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3078
diff changeset
   405
            return -1;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3078
diff changeset
   406
        }
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3078
diff changeset
   407
        visual = vinfo->visual;
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3078
diff changeset
   408
        depth = vinfo->depth;
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7808
diff changeset
   409
        X11_XFree(vinfo);
3161
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3078
diff changeset
   410
    } else
494559cc723b OpenPandora support added by David Carré
Sam Lantinga <slouken@libsdl.org>
parents: 3078
diff changeset
   411
#endif
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1951
diff changeset
   412
    {
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   413
        visual = displaydata->visual;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   414
        depth = displaydata->depth;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   415
    }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   416
10021
3beca914a2ad Added special window type flags.
Ryan C. Gordon <icculus@icculus.org>
parents: 10017
diff changeset
   417
    xattr.override_redirect = ((window->flags & SDL_WINDOW_TOOLTIP) || (window->flags & SDL_WINDOW_POPUP_MENU)) ? True : False;
7750
48acb5c00c4b Fixed bug 2101 - CWBackPixel causes weird window flickering on window resize
Sam Lantinga <slouken@libsdl.org>
parents: 7741
diff changeset
   418
    xattr.background_pixmap = None;
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   419
    xattr.border_pixel = 0;
5466
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
    if (visual->class == DirectColor) {
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   422
        XColor *colorcells;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   423
        int i;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   424
        int ncolors;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   425
        int rmax, gmax, bmax;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   426
        int rmask, gmask, bmask;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   427
        int rshift, gshift, bshift;
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
        xattr.colormap =
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7808
diff changeset
   430
            X11_XCreateColormap(display, RootWindow(display, screen),
5466
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   431
                            visual, AllocAll);
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   432
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   433
        /* 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
   434
        if (!xattr.colormap) {
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 7007
diff changeset
   435
            return SDL_SetError("Could not create writable colormap");
5466
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   436
        }
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   437
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   438
        /* 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
   439
        colorcells = SDL_malloc(visual->map_entries * sizeof(XColor));
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   440
        if (!colorcells) {
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 7007
diff changeset
   441
            return SDL_OutOfMemory();
5466
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   442
        }
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   443
        ncolors = visual->map_entries;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   444
        rmax = 0xffff;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   445
        gmax = 0xffff;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   446
        bmax = 0xffff;
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
        rshift = 0;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   449
        rmask = visual->red_mask;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   450
        while (0 == (rmask & 1)) {
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   451
            rshift++;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   452
            rmask >>= 1;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   453
        }
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   454
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   455
        gshift = 0;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   456
        gmask = visual->green_mask;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   457
        while (0 == (gmask & 1)) {
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   458
            gshift++;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   459
            gmask >>= 1;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   460
        }
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   461
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   462
        bshift = 0;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   463
        bmask = visual->blue_mask;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   464
        while (0 == (bmask & 1)) {
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   465
            bshift++;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   466
            bmask >>= 1;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   467
        }
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   468
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   469
        /* build the color table pixel values */
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   470
        for (i = 0; i < ncolors; i++) {
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   471
            Uint32 red = (rmax * i) / (ncolors - 1);
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   472
            Uint32 green = (gmax * i) / (ncolors - 1);
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   473
            Uint32 blue = (bmax * i) / (ncolors - 1);
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   474
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   475
            Uint32 rbits = (rmask * i) / (ncolors - 1);
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   476
            Uint32 gbits = (gmask * i) / (ncolors - 1);
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   477
            Uint32 bbits = (bmask * i) / (ncolors - 1);
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   478
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   479
            Uint32 pix =
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   480
                (rbits << rshift) | (gbits << gshift) | (bbits << bshift);
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   481
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   482
            colorcells[i].pixel = pix;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   483
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   484
            colorcells[i].red = red;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   485
            colorcells[i].green = green;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   486
            colorcells[i].blue = blue;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   487
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   488
            colorcells[i].flags = DoRed | DoGreen | DoBlue;
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   489
        }
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   490
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7808
diff changeset
   491
        X11_XStoreColors(display, xattr.colormap, colorcells, ncolors);
5466
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   492
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   493
        SDL_free(colorcells);
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   494
    } else {
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   495
        xattr.colormap =
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7808
diff changeset
   496
            X11_XCreateColormap(display, RootWindow(display, screen),
5466
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   497
                            visual, AllocNone);
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5386
diff changeset
   498
    }
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   499
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7808
diff changeset
   500
    w = X11_XCreateWindow(display, RootWindow(display, screen),
5386
762e67f81fc7 Simplified the X11 window creation
Sam Lantinga <slouken@libsdl.org>
parents: 5305
diff changeset
   501
                      window->x, window->y, window->w, window->h,
762e67f81fc7 Simplified the X11 window creation
Sam Lantinga <slouken@libsdl.org>
parents: 5305
diff changeset
   502
                      0, depth, InputOutput, visual,
7750
48acb5c00c4b Fixed bug 2101 - CWBackPixel causes weird window flickering on window resize
Sam Lantinga <slouken@libsdl.org>
parents: 7741
diff changeset
   503
                      (CWOverrideRedirect | CWBackPixmap | CWBorderPixel |
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   504
                       CWColormap), &xattr);
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1951
diff changeset
   505
    if (!w) {
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 7007
diff changeset
   506
        return SDL_SetError("Couldn't create window");
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1951
diff changeset
   507
    }
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   508
6422
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   509
    SetWindowBordered(display, screen, w,
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   510
                      (window->flags & SDL_WINDOW_BORDERLESS) == 0);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   511
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7808
diff changeset
   512
    sizehints = X11_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
   513
    /* Setup the normal size hints */
6462
5e09ac1aba80 allocate *Hint structures per Xlib docs
Edward Rudd <urkle@outoforder.cc>
parents: 6423
diff changeset
   514
    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
   515
    if (!(window->flags & SDL_WINDOW_RESIZABLE)) {
6462
5e09ac1aba80 allocate *Hint structures per Xlib docs
Edward Rudd <urkle@outoforder.cc>
parents: 6423
diff changeset
   516
        sizehints->min_width = sizehints->max_width = window->w;
5e09ac1aba80 allocate *Hint structures per Xlib docs
Edward Rudd <urkle@outoforder.cc>
parents: 6423
diff changeset
   517
        sizehints->min_height = sizehints->max_height = window->h;
5e09ac1aba80 allocate *Hint structures per Xlib docs
Edward Rudd <urkle@outoforder.cc>
parents: 6423
diff changeset
   518
        sizehints->flags |= (PMaxSize | PMinSize);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   519
    }
6462
5e09ac1aba80 allocate *Hint structures per Xlib docs
Edward Rudd <urkle@outoforder.cc>
parents: 6423
diff changeset
   520
    sizehints->x = window->x;
5e09ac1aba80 allocate *Hint structures per Xlib docs
Edward Rudd <urkle@outoforder.cc>
parents: 6423
diff changeset
   521
    sizehints->y = window->y;
5e09ac1aba80 allocate *Hint structures per Xlib docs
Edward Rudd <urkle@outoforder.cc>
parents: 6423
diff changeset
   522
    sizehints->flags |= USPosition;
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   523
6167
c071e1372341 X11: Move to XSetWMProperties and add support to _NET_WM_PID
Marco Trevisan (Treviño) <mail@3v1n0.net>
parents: 6138
diff changeset
   524
    /* Setup the input hints so we get keyboard input */
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7808
diff changeset
   525
    wmhints = X11_XAllocWMHints();
6462
5e09ac1aba80 allocate *Hint structures per Xlib docs
Edward Rudd <urkle@outoforder.cc>
parents: 6423
diff changeset
   526
    wmhints->input = True;
10023
d8015905fef6 x11: Put a matching window_group wmhint on every window created.
Ryan C. Gordon <icculus@icculus.org>
parents: 10021
diff changeset
   527
    wmhints->window_group = data->window_group;
d8015905fef6 x11: Put a matching window_group wmhint on every window created.
Ryan C. Gordon <icculus@icculus.org>
parents: 10021
diff changeset
   528
    wmhints->flags = InputHint | WindowGroupHint;
6167
c071e1372341 X11: Move to XSetWMProperties and add support to _NET_WM_PID
Marco Trevisan (Treviño) <mail@3v1n0.net>
parents: 6138
diff changeset
   529
c071e1372341 X11: Move to XSetWMProperties and add support to _NET_WM_PID
Marco Trevisan (Treviño) <mail@3v1n0.net>
parents: 6138
diff changeset
   530
    /* Setup the class hints so we can get an icon (AfterStep) */
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7808
diff changeset
   531
    classhints = X11_XAllocClassHint();
6462
5e09ac1aba80 allocate *Hint structures per Xlib docs
Edward Rudd <urkle@outoforder.cc>
parents: 6423
diff changeset
   532
    classhints->res_name = data->classname;
5e09ac1aba80 allocate *Hint structures per Xlib docs
Edward Rudd <urkle@outoforder.cc>
parents: 6423
diff changeset
   533
    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
   534
c071e1372341 X11: Move to XSetWMProperties and add support to _NET_WM_PID
Marco Trevisan (Treviño) <mail@3v1n0.net>
parents: 6138
diff changeset
   535
    /* Set the size, input and class hints, and define WM_CLIENT_MACHINE and WM_LOCALE_NAME */
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7808
diff changeset
   536
    X11_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
   537
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7808
diff changeset
   538
    X11_XFree(sizehints);
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7808
diff changeset
   539
    X11_XFree(wmhints);
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7808
diff changeset
   540
    X11_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
   541
    /* 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
   542
    if (data->pid > 0) {
10014
906340c8c820 x11: _NET_WM_PID needs a long, not a pid_t, I think.
Ryan C. Gordon <icculus@icculus.org>
parents: 10011
diff changeset
   543
        long pid = (long) data->pid;
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7808
diff changeset
   544
        _NET_WM_PID = X11_XInternAtom(display, "_NET_WM_PID", False);
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7808
diff changeset
   545
        X11_XChangeProperty(display, w, _NET_WM_PID, XA_CARDINAL, 32, PropModeReplace,
10014
906340c8c820 x11: _NET_WM_PID needs a long, not a pid_t, I think.
Ryan C. Gordon <icculus@icculus.org>
parents: 10011
diff changeset
   546
                        (unsigned char *) &pid, 1);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   547
    }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   548
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
   549
    /* 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
   550
    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
   551
10021
3beca914a2ad Added special window type flags.
Ryan C. Gordon <icculus@icculus.org>
parents: 10017
diff changeset
   552
    compositor = 2;  /* don't disable compositing except for "normal" windows */
3beca914a2ad Added special window type flags.
Ryan C. Gordon <icculus@icculus.org>
parents: 10017
diff changeset
   553
3beca914a2ad Added special window type flags.
Ryan C. Gordon <icculus@icculus.org>
parents: 10017
diff changeset
   554
    if (window->flags & SDL_WINDOW_UTILITY) {
3beca914a2ad Added special window type flags.
Ryan C. Gordon <icculus@icculus.org>
parents: 10017
diff changeset
   555
        wintype_name = "_NET_WM_WINDOW_TYPE_UTILITY";
3beca914a2ad Added special window type flags.
Ryan C. Gordon <icculus@icculus.org>
parents: 10017
diff changeset
   556
    } else if (window->flags & SDL_WINDOW_TOOLTIP) {
3beca914a2ad Added special window type flags.
Ryan C. Gordon <icculus@icculus.org>
parents: 10017
diff changeset
   557
        wintype_name = "_NET_WM_WINDOW_TYPE_TOOLTIP";
3beca914a2ad Added special window type flags.
Ryan C. Gordon <icculus@icculus.org>
parents: 10017
diff changeset
   558
    } else if (window->flags & SDL_WINDOW_POPUP_MENU) {
3beca914a2ad Added special window type flags.
Ryan C. Gordon <icculus@icculus.org>
parents: 10017
diff changeset
   559
        wintype_name = "_NET_WM_WINDOW_TYPE_POPUP_MENU";
3beca914a2ad Added special window type flags.
Ryan C. Gordon <icculus@icculus.org>
parents: 10017
diff changeset
   560
    } else {
3beca914a2ad Added special window type flags.
Ryan C. Gordon <icculus@icculus.org>
parents: 10017
diff changeset
   561
        wintype_name = "_NET_WM_WINDOW_TYPE_NORMAL";
3beca914a2ad Added special window type flags.
Ryan C. Gordon <icculus@icculus.org>
parents: 10017
diff changeset
   562
        compositor = 1;  /* disable compositing for "normal" windows */
3beca914a2ad Added special window type flags.
Ryan C. Gordon <icculus@icculus.org>
parents: 10017
diff changeset
   563
    }
3beca914a2ad Added special window type flags.
Ryan C. Gordon <icculus@icculus.org>
parents: 10017
diff changeset
   564
3beca914a2ad Added special window type flags.
Ryan C. Gordon <icculus@icculus.org>
parents: 10017
diff changeset
   565
    /* Let the window manager know what type of window we are. */
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7808
diff changeset
   566
    _NET_WM_WINDOW_TYPE = X11_XInternAtom(display, "_NET_WM_WINDOW_TYPE", False);
10021
3beca914a2ad Added special window type flags.
Ryan C. Gordon <icculus@icculus.org>
parents: 10017
diff changeset
   567
    wintype = X11_XInternAtom(display, wintype_name, False);
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7808
diff changeset
   568
    X11_XChangeProperty(display, w, _NET_WM_WINDOW_TYPE, XA_ATOM, 32,
10021
3beca914a2ad Added special window type flags.
Ryan C. Gordon <icculus@icculus.org>
parents: 10017
diff changeset
   569
                    PropModeReplace, (unsigned char *)&wintype, 1);
4521
50125e8aab94 Let the window manager know we're a "normal" window
Sam Lantinga <slouken@libsdl.org>
parents: 4520
diff changeset
   570
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7808
diff changeset
   571
    _NET_WM_BYPASS_COMPOSITOR = X11_XInternAtom(display, "_NET_WM_BYPASS_COMPOSITOR", False);
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7808
diff changeset
   572
    X11_XChangeProperty(display, w, _NET_WM_BYPASS_COMPOSITOR, XA_CARDINAL, 32,
7490
fc864efbc1a6 Add support for the _NET_WM_BYPASS_COMPOSITOR hint
Jasper St. Pierre <jstpierre@mecheye.net>
parents: 7445
diff changeset
   573
                    PropModeReplace,
10021
3beca914a2ad Added special window type flags.
Ryan C. Gordon <icculus@icculus.org>
parents: 10017
diff changeset
   574
                    (unsigned char *)&compositor, 1);
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7037
diff changeset
   575
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
   576
    {
10029
4c992fd19316 Added SDL_WINDOWEVENT_TAKE_FOCUS.
Ryan C. Gordon <icculus@icculus.org>
parents: 10027
diff changeset
   577
        Atom protocols[3];
9899
25d1e99080ce Add SDL_HINT_VIDEO_X11_NET_WM_PING to allow disabling
Sam Lantinga <slouken@libsdl.org>
parents: 9838
diff changeset
   578
        int proto_count = 0;
25d1e99080ce Add SDL_HINT_VIDEO_X11_NET_WM_PING to allow disabling
Sam Lantinga <slouken@libsdl.org>
parents: 9838
diff changeset
   579
        const char *ping_hint;
25d1e99080ce Add SDL_HINT_VIDEO_X11_NET_WM_PING to allow disabling
Sam Lantinga <slouken@libsdl.org>
parents: 9838
diff changeset
   580
10029
4c992fd19316 Added SDL_WINDOWEVENT_TAKE_FOCUS.
Ryan C. Gordon <icculus@icculus.org>
parents: 10027
diff changeset
   581
        protocols[proto_count++] = data->WM_DELETE_WINDOW; /* Allow window to be deleted by the WM */
4c992fd19316 Added SDL_WINDOWEVENT_TAKE_FOCUS.
Ryan C. Gordon <icculus@icculus.org>
parents: 10027
diff changeset
   582
        protocols[proto_count++] = data->WM_TAKE_FOCUS; /* Since we will want to set input focus explicitly */
4c992fd19316 Added SDL_WINDOWEVENT_TAKE_FOCUS.
Ryan C. Gordon <icculus@icculus.org>
parents: 10027
diff changeset
   583
9899
25d1e99080ce Add SDL_HINT_VIDEO_X11_NET_WM_PING to allow disabling
Sam Lantinga <slouken@libsdl.org>
parents: 9838
diff changeset
   584
        ping_hint = SDL_GetHint(SDL_HINT_VIDEO_X11_NET_WM_PING);
25d1e99080ce Add SDL_HINT_VIDEO_X11_NET_WM_PING to allow disabling
Sam Lantinga <slouken@libsdl.org>
parents: 9838
diff changeset
   585
        /* Default to using ping if there is no hint */
25d1e99080ce Add SDL_HINT_VIDEO_X11_NET_WM_PING to allow disabling
Sam Lantinga <slouken@libsdl.org>
parents: 9838
diff changeset
   586
        if (!ping_hint || SDL_atoi(ping_hint)) {
10029
4c992fd19316 Added SDL_WINDOWEVENT_TAKE_FOCUS.
Ryan C. Gordon <icculus@icculus.org>
parents: 10027
diff changeset
   587
            protocols[proto_count++] = data->_NET_WM_PING; /* Respond so WM knows we're alive */
9899
25d1e99080ce Add SDL_HINT_VIDEO_X11_NET_WM_PING to allow disabling
Sam Lantinga <slouken@libsdl.org>
parents: 9838
diff changeset
   588
        }
25d1e99080ce Add SDL_HINT_VIDEO_X11_NET_WM_PING to allow disabling
Sam Lantinga <slouken@libsdl.org>
parents: 9838
diff changeset
   589
25d1e99080ce Add SDL_HINT_VIDEO_X11_NET_WM_PING to allow disabling
Sam Lantinga <slouken@libsdl.org>
parents: 9838
diff changeset
   590
        SDL_assert(proto_count <= sizeof(protocols) / sizeof(protocols[0]));
25d1e99080ce Add SDL_HINT_VIDEO_X11_NET_WM_PING to allow disabling
Sam Lantinga <slouken@libsdl.org>
parents: 9838
diff changeset
   591
25d1e99080ce Add SDL_HINT_VIDEO_X11_NET_WM_PING to allow disabling
Sam Lantinga <slouken@libsdl.org>
parents: 9838
diff changeset
   592
        X11_XSetWMProtocols(display, w, protocols, proto_count);
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
   593
    }
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   594
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   595
    if (SetupWindowData(_this, window, w, SDL_TRUE) < 0) {
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7808
diff changeset
   596
        X11_XDestroyWindow(display, w);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   597
        return -1;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   598
    }
7683
f7c061286490 Fixed crash if the IC isn't set up for some reason (bad X11 locale?)
Sam Lantinga <slouken@libsdl.org>
parents: 7678
diff changeset
   599
    windowdata = (SDL_WindowData *) window->driverdata;
5386
762e67f81fc7 Simplified the X11 window creation
Sam Lantinga <slouken@libsdl.org>
parents: 5305
diff changeset
   600
7659
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7632
diff changeset
   601
#if SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
7723
aea98cc3e696 Fixes bug #2040, prepare SDL_GL_CONTEXT_EGL for deprecation on v2.1
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7683
diff changeset
   602
    if ((window->flags & SDL_WINDOW_OPENGL) && 
7808
627f256b0e56 Fixes X11 video backend compilation when no GL is available
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7750
diff changeset
   603
        _this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES
627f256b0e56 Fixes X11 video backend compilation when no GL is available
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7750
diff changeset
   604
#if SDL_VIDEO_OPENGL_GLX            
627f256b0e56 Fixes X11 video backend compilation when no GL is available
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7750
diff changeset
   605
        && ( !_this->gl_data || ! _this->gl_data->HAS_GLX_EXT_create_context_es2_profile )
627f256b0e56 Fixes X11 video backend compilation when no GL is available
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7750
diff changeset
   606
#endif  
627f256b0e56 Fixes X11 video backend compilation when no GL is available
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7750
diff changeset
   607
    ) {
7960
904d473b8845 [X11] Fix up compilation when EGL headers are not present.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7857
diff changeset
   608
#if SDL_VIDEO_OPENGL_EGL  
7659
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7632
diff changeset
   609
        if (!_this->egl_data) {
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7808
diff changeset
   610
            X11_XDestroyWindow(display, w);
7659
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7632
diff changeset
   611
            return -1;
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7632
diff changeset
   612
        }
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7632
diff changeset
   613
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7632
diff changeset
   614
        /* Create the GLES window surface */
7683
f7c061286490 Fixed crash if the IC isn't set up for some reason (bad X11 locale?)
Sam Lantinga <slouken@libsdl.org>
parents: 7678
diff changeset
   615
        windowdata->egl_surface = SDL_EGL_CreateSurface(_this, (NativeWindowType) w);
7659
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7632
diff changeset
   616
7683
f7c061286490 Fixed crash if the IC isn't set up for some reason (bad X11 locale?)
Sam Lantinga <slouken@libsdl.org>
parents: 7678
diff changeset
   617
        if (windowdata->egl_surface == EGL_NO_SURFACE) {
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7808
diff changeset
   618
            X11_XDestroyWindow(display, w);
7659
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7632
diff changeset
   619
            return SDL_SetError("Could not create GLES window surface");
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7632
diff changeset
   620
        }
7960
904d473b8845 [X11] Fix up compilation when EGL headers are not present.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7857
diff changeset
   621
#else
904d473b8845 [X11] Fix up compilation when EGL headers are not present.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7857
diff changeset
   622
        return SDL_SetError("Could not create GLES window surface (no EGL support available)");
904d473b8845 [X11] Fix up compilation when EGL headers are not present.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7857
diff changeset
   623
#endif /* SDL_VIDEO_OPENGL_EGL */
7659
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7632
diff changeset
   624
    }
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7632
diff changeset
   625
#endif
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7632
diff changeset
   626
    
ac4ce59c40e7 Fixes bug #2037, common EGL code for Android and X11
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7632
diff changeset
   627
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
   628
#ifdef X_HAVE_UTF8_STRING
7683
f7c061286490 Fixed crash if the IC isn't set up for some reason (bad X11 locale?)
Sam Lantinga <slouken@libsdl.org>
parents: 7678
diff changeset
   629
    if (SDL_X11_HAVE_UTF8 && windowdata->ic) {
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7808
diff changeset
   630
        X11_XGetICValues(windowdata->ic, 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
   631
    }
2325
c7bcf84ba1b9 Next version of internationalized input for X11. On my machine (famous last words :-) with a US English keyboard and locale I can compose ` and e and get a text
Bob Pendleton <bob@pendleton.com>
parents: 2324
diff changeset
   632
#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
   633
6316
a89c79a3f0cd 1.Moved all xinput2 functionality to its own file
Dimitris Zenios <dimitris.zenios@gmail.com>
parents: 6275
diff changeset
   634
    X11_Xinput2SelectTouch(_this, window);
a89c79a3f0cd 1.Moved all xinput2 functionality to its own file
Dimitris Zenios <dimitris.zenios@gmail.com>
parents: 6275
diff changeset
   635
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7808
diff changeset
   636
    X11_XSelectInput(display, w,
6045
b8e995dab018 Fix crash on X servers without UTF-8 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 6024
diff changeset
   637
                 (FocusChangeMask | EnterWindowMask | LeaveWindowMask |
b8e995dab018 Fix crash on X servers without UTF-8 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 6024
diff changeset
   638
                 ExposureMask | ButtonPressMask | ButtonReleaseMask |
b8e995dab018 Fix crash on X servers without UTF-8 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 6024
diff changeset
   639
                 PointerMotionMask | KeyPressMask | KeyReleaseMask |
b8e995dab018 Fix crash on X servers without UTF-8 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 6024
diff changeset
   640
                 PropertyChangeMask | StructureNotifyMask |
b8e995dab018 Fix crash on X servers without UTF-8 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 6024
diff changeset
   641
                 KeymapStateMask | fevent));
b8e995dab018 Fix crash on X servers without UTF-8 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 6024
diff changeset
   642
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7808
diff changeset
   643
    XdndAware = X11_XInternAtom(display, "XdndAware", False);
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7808
diff changeset
   644
    X11_XChangeProperty(display, w, XdndAware, XA_ATOM, 32,
7001
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6970
diff changeset
   645
                 PropModeReplace,
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7037
diff changeset
   646
                 (unsigned char*)&xdnd_version, 1);
7001
ccc0d3207639 XDnD implementation from Davey Taylor, need some cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 6970
diff changeset
   647
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7808
diff changeset
   648
    X11_XFlush(display);
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
   649
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   650
    return 0;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   651
}
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   652
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   653
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
   654
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
   655
{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   656
    Window w = (Window) data;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   657
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
   658
    window->title = X11_GetWindowTitle(_this, w);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   659
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   660
    if (SetupWindowData(_this, window, w, SDL_FALSE) < 0) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   661
        return -1;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   662
    }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   663
    return 0;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   664
}
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   665
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
   666
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
   667
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
   668
{
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
   669
    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
   670
    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
   671
    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
   672
    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
   673
    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
   674
    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
   675
    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
   676
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7808
diff changeset
   677
    status = X11_XGetWindowProperty(display, xwindow, data->_NET_WM_NAME,
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
   678
                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
   679
                &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
   680
    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
   681
        title = SDL_strdup(SDL_static_cast(char*, propdata));
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7808
diff changeset
   682
        X11_XFree(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
   683
    } else {
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7808
diff changeset
   684
        status = X11_XGetWindowProperty(display, xwindow, XA_WM_NAME,
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
   685
                    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
   686
                    &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
   687
        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
   688
            title = SDL_iconv_string("UTF-8", "", SDL_static_cast(char*, propdata), items_read+1);
9117
236241f5d225 Fixed memory leak getting the X11 window title
Sam Lantinga <slouken@libsdl.org>
parents: 8978
diff changeset
   689
            X11_XFree(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
   690
        } 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
   691
            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
   692
        }
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
   693
    }
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
   694
    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
   695
}
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
   696
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   697
void
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   698
X11_SetWindowTitle(_THIS, SDL_Window * window)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   699
{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   700
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   701
    Display *display = data->videodata->display;
9479
daeaa68d7acf Removed unused variable.
Ryan C. Gordon <icculus@icculus.org>
parents: 9478
diff changeset
   702
    XTextProperty titleprop;
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   703
    Status status;
9474
067b78126485 SDL_SetWindowTitle() should never set a NULL pointer for the title string.
Ryan C. Gordon <icculus@icculus.org>
parents: 9460
diff changeset
   704
    const char *title = window->title ? window->title : "";
067b78126485 SDL_SetWindowTitle() should never set a NULL pointer for the title string.
Ryan C. Gordon <icculus@icculus.org>
parents: 9460
diff changeset
   705
    char *title_locale = NULL;
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   706
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   707
#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
   708
    Atom _NET_WM_NAME = data->videodata->_NET_WM_NAME;
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   709
#endif
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   710
9474
067b78126485 SDL_SetWindowTitle() should never set a NULL pointer for the title string.
Ryan C. Gordon <icculus@icculus.org>
parents: 9460
diff changeset
   711
    title_locale = SDL_iconv_utf8_locale(title);
067b78126485 SDL_SetWindowTitle() should never set a NULL pointer for the title string.
Ryan C. Gordon <icculus@icculus.org>
parents: 9460
diff changeset
   712
    if (!title_locale) {
067b78126485 SDL_SetWindowTitle() should never set a NULL pointer for the title string.
Ryan C. Gordon <icculus@icculus.org>
parents: 9460
diff changeset
   713
        SDL_OutOfMemory();
067b78126485 SDL_SetWindowTitle() should never set a NULL pointer for the title string.
Ryan C. Gordon <icculus@icculus.org>
parents: 9460
diff changeset
   714
        return;
067b78126485 SDL_SetWindowTitle() should never set a NULL pointer for the title string.
Ryan C. Gordon <icculus@icculus.org>
parents: 9460
diff changeset
   715
    }
067b78126485 SDL_SetWindowTitle() should never set a NULL pointer for the title string.
Ryan C. Gordon <icculus@icculus.org>
parents: 9460
diff changeset
   716
067b78126485 SDL_SetWindowTitle() should never set a NULL pointer for the title string.
Ryan C. Gordon <icculus@icculus.org>
parents: 9460
diff changeset
   717
    status = X11_XStringListToTextProperty(&title_locale, 1, &titleprop);
067b78126485 SDL_SetWindowTitle() should never set a NULL pointer for the title string.
Ryan C. Gordon <icculus@icculus.org>
parents: 9460
diff changeset
   718
    SDL_free(title_locale);
067b78126485 SDL_SetWindowTitle() should never set a NULL pointer for the title string.
Ryan C. Gordon <icculus@icculus.org>
parents: 9460
diff changeset
   719
    if (status) {
067b78126485 SDL_SetWindowTitle() should never set a NULL pointer for the title string.
Ryan C. Gordon <icculus@icculus.org>
parents: 9460
diff changeset
   720
        X11_XSetTextProperty(display, data->xwindow, &titleprop, XA_WM_NAME);
067b78126485 SDL_SetWindowTitle() should never set a NULL pointer for the title string.
Ryan C. Gordon <icculus@icculus.org>
parents: 9460
diff changeset
   721
        X11_XFree(titleprop.value);
067b78126485 SDL_SetWindowTitle() should never set a NULL pointer for the title string.
Ryan C. Gordon <icculus@icculus.org>
parents: 9460
diff changeset
   722
    }
067b78126485 SDL_SetWindowTitle() should never set a NULL pointer for the title string.
Ryan C. Gordon <icculus@icculus.org>
parents: 9460
diff changeset
   723
#ifdef X_HAVE_UTF8_STRING
067b78126485 SDL_SetWindowTitle() should never set a NULL pointer for the title string.
Ryan C. Gordon <icculus@icculus.org>
parents: 9460
diff changeset
   724
    if (SDL_X11_HAVE_UTF8) {
067b78126485 SDL_SetWindowTitle() should never set a NULL pointer for the title string.
Ryan C. Gordon <icculus@icculus.org>
parents: 9460
diff changeset
   725
        status = X11_Xutf8TextListToTextProperty(display, (char **) &title, 1,
067b78126485 SDL_SetWindowTitle() should never set a NULL pointer for the title string.
Ryan C. Gordon <icculus@icculus.org>
parents: 9460
diff changeset
   726
                                            XUTF8StringStyle, &titleprop);
067b78126485 SDL_SetWindowTitle() should never set a NULL pointer for the title string.
Ryan C. Gordon <icculus@icculus.org>
parents: 9460
diff changeset
   727
        if (status == Success) {
067b78126485 SDL_SetWindowTitle() should never set a NULL pointer for the title string.
Ryan C. Gordon <icculus@icculus.org>
parents: 9460
diff changeset
   728
            X11_XSetTextProperty(display, data->xwindow, &titleprop,
067b78126485 SDL_SetWindowTitle() should never set a NULL pointer for the title string.
Ryan C. Gordon <icculus@icculus.org>
parents: 9460
diff changeset
   729
                                 _NET_WM_NAME);
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7808
diff changeset
   730
            X11_XFree(titleprop.value);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   731
        }
9474
067b78126485 SDL_SetWindowTitle() should never set a NULL pointer for the title string.
Ryan C. Gordon <icculus@icculus.org>
parents: 9460
diff changeset
   732
    }
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   733
#endif
9474
067b78126485 SDL_SetWindowTitle() should never set a NULL pointer for the title string.
Ryan C. Gordon <icculus@icculus.org>
parents: 9460
diff changeset
   734
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7808
diff changeset
   735
    X11_XFlush(display);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   736
}
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   737
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   738
void
2967
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
   739
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
   740
{
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
   741
    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
   742
    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
   743
    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
   744
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
   745
    if (icon) {
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
   746
        int propsize;
4528
f06faa886423 Fixed bug 1022
Sam Lantinga <slouken@libsdl.org>
parents: 4524
diff changeset
   747
        long *propdata;
2967
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
   748
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
   749
        /* Set the _NET_WM_ICON property */
7523
9e9ab1dc3811 Fixed bug 1919 - Window icon disappears as soon as a renderer is created
Sam Lantinga <slouken@libsdl.org>
parents: 7522
diff changeset
   750
        SDL_assert(icon->format->format == SDL_PIXELFORMAT_ARGB8888);
2990
Sam Lantinga <slouken@libsdl.org>
parents: 2967
diff changeset
   751
        propsize = 2 + (icon->w * icon->h);
4566
40c833d951a1 Fixed memory corruption on AMD64
Sam Lantinga <slouken@libsdl.org>
parents: 4555
diff changeset
   752
        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
   753
        if (propdata) {
4528
f06faa886423 Fixed bug 1022
Sam Lantinga <slouken@libsdl.org>
parents: 4524
diff changeset
   754
            int x, y;
f06faa886423 Fixed bug 1022
Sam Lantinga <slouken@libsdl.org>
parents: 4524
diff changeset
   755
            Uint32 *src;
f06faa886423 Fixed bug 1022
Sam Lantinga <slouken@libsdl.org>
parents: 4524
diff changeset
   756
            long *dst;
f06faa886423 Fixed bug 1022
Sam Lantinga <slouken@libsdl.org>
parents: 4524
diff changeset
   757
2967
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
   758
            propdata[0] = icon->w;
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
   759
            propdata[1] = icon->h;
4528
f06faa886423 Fixed bug 1022
Sam Lantinga <slouken@libsdl.org>
parents: 4524
diff changeset
   760
            dst = &propdata[2];
f06faa886423 Fixed bug 1022
Sam Lantinga <slouken@libsdl.org>
parents: 4524
diff changeset
   761
            for (y = 0; y < icon->h; ++y) {
7523
9e9ab1dc3811 Fixed bug 1919 - Window icon disappears as soon as a renderer is created
Sam Lantinga <slouken@libsdl.org>
parents: 7522
diff changeset
   762
                src = (Uint32*)((Uint8*)icon->pixels + y * icon->pitch);
4528
f06faa886423 Fixed bug 1022
Sam Lantinga <slouken@libsdl.org>
parents: 4524
diff changeset
   763
                for (x = 0; x < icon->w; ++x) {
f06faa886423 Fixed bug 1022
Sam Lantinga <slouken@libsdl.org>
parents: 4524
diff changeset
   764
                    *dst++ = *src++;
f06faa886423 Fixed bug 1022
Sam Lantinga <slouken@libsdl.org>
parents: 4524
diff changeset
   765
                }
f06faa886423 Fixed bug 1022
Sam Lantinga <slouken@libsdl.org>
parents: 4524
diff changeset
   766
            }
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7808
diff changeset
   767
            X11_XChangeProperty(display, data->xwindow, _NET_WM_ICON, XA_CARDINAL,
2990
Sam Lantinga <slouken@libsdl.org>
parents: 2967
diff changeset
   768
                            32, PropModeReplace, (unsigned char *) propdata,
Sam Lantinga <slouken@libsdl.org>
parents: 2967
diff changeset
   769
                            propsize);
2967
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
   770
        }
6562
c52863165594 Fixed memory leak in X11_SetWindowIcon().
Ryan C. Gordon <icculus@icculus.org>
parents: 6541
diff changeset
   771
        SDL_free(propdata);
2967
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
   772
    } else {
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7808
diff changeset
   773
        X11_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
   774
    }
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7808
diff changeset
   775
    X11_XFlush(display);
2967
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
   776
}
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
   777
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2945
diff changeset
   778
void
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   779
X11_SetWindowPosition(_THIS, SDL_Window * window)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   780
{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   781
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   782
    Display *display = data->videodata->display;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   783
10103
9cec5fe32bca x11: Fix a few more XMoveWindow() calls to adjust for border size.
Ryan C. Gordon <icculus@icculus.org>
parents: 10102
diff changeset
   784
    X11_XMoveWindow(display, data->xwindow, window->x - data->border_left, window->y - data->border_top);
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7808
diff changeset
   785
    X11_XFlush(display);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   786
}
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   787
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   788
void
7617
918703f5cff8 Fixed bug 2007 - SDL_SetWindowMinimumSize() not implemented on X11 (thanks Rainer!)
Sam Lantinga <slouken@libsdl.org>
parents: 7566
diff changeset
   789
X11_SetWindowMinimumSize(_THIS, SDL_Window * window)
918703f5cff8 Fixed bug 2007 - SDL_SetWindowMinimumSize() not implemented on X11 (thanks Rainer!)
Sam Lantinga <slouken@libsdl.org>
parents: 7566
diff changeset
   790
{
918703f5cff8 Fixed bug 2007 - SDL_SetWindowMinimumSize() not implemented on X11 (thanks Rainer!)
Sam Lantinga <slouken@libsdl.org>
parents: 7566
diff changeset
   791
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
918703f5cff8 Fixed bug 2007 - SDL_SetWindowMinimumSize() not implemented on X11 (thanks Rainer!)
Sam Lantinga <slouken@libsdl.org>
parents: 7566
diff changeset
   792
    Display *display = data->videodata->display;
918703f5cff8 Fixed bug 2007 - SDL_SetWindowMinimumSize() not implemented on X11 (thanks Rainer!)
Sam Lantinga <slouken@libsdl.org>
parents: 7566
diff changeset
   793
918703f5cff8 Fixed bug 2007 - SDL_SetWindowMinimumSize() not implemented on X11 (thanks Rainer!)
Sam Lantinga <slouken@libsdl.org>
parents: 7566
diff changeset
   794
    if (window->flags & SDL_WINDOW_RESIZABLE) {
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7808
diff changeset
   795
         XSizeHints *sizehints = X11_XAllocSizeHints();
7617
918703f5cff8 Fixed bug 2007 - SDL_SetWindowMinimumSize() not implemented on X11 (thanks Rainer!)
Sam Lantinga <slouken@libsdl.org>
parents: 7566
diff changeset
   796
         long userhints;
918703f5cff8 Fixed bug 2007 - SDL_SetWindowMinimumSize() not implemented on X11 (thanks Rainer!)
Sam Lantinga <slouken@libsdl.org>
parents: 7566
diff changeset
   797
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7808
diff changeset
   798
         X11_XGetWMNormalHints(display, data->xwindow, sizehints, &userhints);
7617
918703f5cff8 Fixed bug 2007 - SDL_SetWindowMinimumSize() not implemented on X11 (thanks Rainer!)
Sam Lantinga <slouken@libsdl.org>
parents: 7566
diff changeset
   799
918703f5cff8 Fixed bug 2007 - SDL_SetWindowMinimumSize() not implemented on X11 (thanks Rainer!)
Sam Lantinga <slouken@libsdl.org>
parents: 7566
diff changeset
   800
         sizehints->min_width = window->min_w;
918703f5cff8 Fixed bug 2007 - SDL_SetWindowMinimumSize() not implemented on X11 (thanks Rainer!)
Sam Lantinga <slouken@libsdl.org>
parents: 7566
diff changeset
   801
         sizehints->min_height = window->min_h;
918703f5cff8 Fixed bug 2007 - SDL_SetWindowMinimumSize() not implemented on X11 (thanks Rainer!)
Sam Lantinga <slouken@libsdl.org>
parents: 7566
diff changeset
   802
         sizehints->flags |= PMinSize;
918703f5cff8 Fixed bug 2007 - SDL_SetWindowMinimumSize() not implemented on X11 (thanks Rainer!)
Sam Lantinga <slouken@libsdl.org>
parents: 7566
diff changeset
   803
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7808
diff changeset
   804
         X11_XSetWMNormalHints(display, data->xwindow, sizehints);
7617
918703f5cff8 Fixed bug 2007 - SDL_SetWindowMinimumSize() not implemented on X11 (thanks Rainer!)
Sam Lantinga <slouken@libsdl.org>
parents: 7566
diff changeset
   805
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7808
diff changeset
   806
         X11_XFree(sizehints);
7617
918703f5cff8 Fixed bug 2007 - SDL_SetWindowMinimumSize() not implemented on X11 (thanks Rainer!)
Sam Lantinga <slouken@libsdl.org>
parents: 7566
diff changeset
   807
918703f5cff8 Fixed bug 2007 - SDL_SetWindowMinimumSize() not implemented on X11 (thanks Rainer!)
Sam Lantinga <slouken@libsdl.org>
parents: 7566
diff changeset
   808
        /* See comment in X11_SetWindowSize. */
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7808
diff changeset
   809
        X11_XResizeWindow(display, data->xwindow, window->w, window->h);
10103
9cec5fe32bca x11: Fix a few more XMoveWindow() calls to adjust for border size.
Ryan C. Gordon <icculus@icculus.org>
parents: 10102
diff changeset
   810
        X11_XMoveWindow(display, data->xwindow, window->x - data->border_left, window->y - data->border_top);
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7808
diff changeset
   811
        X11_XRaiseWindow(display, data->xwindow);
7617
918703f5cff8 Fixed bug 2007 - SDL_SetWindowMinimumSize() not implemented on X11 (thanks Rainer!)
Sam Lantinga <slouken@libsdl.org>
parents: 7566
diff changeset
   812
    }
918703f5cff8 Fixed bug 2007 - SDL_SetWindowMinimumSize() not implemented on X11 (thanks Rainer!)
Sam Lantinga <slouken@libsdl.org>
parents: 7566
diff changeset
   813
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7808
diff changeset
   814
    X11_XFlush(display);
7617
918703f5cff8 Fixed bug 2007 - SDL_SetWindowMinimumSize() not implemented on X11 (thanks Rainer!)
Sam Lantinga <slouken@libsdl.org>
parents: 7566
diff changeset
   815
}
918703f5cff8 Fixed bug 2007 - SDL_SetWindowMinimumSize() not implemented on X11 (thanks Rainer!)
Sam Lantinga <slouken@libsdl.org>
parents: 7566
diff changeset
   816
918703f5cff8 Fixed bug 2007 - SDL_SetWindowMinimumSize() not implemented on X11 (thanks Rainer!)
Sam Lantinga <slouken@libsdl.org>
parents: 7566
diff changeset
   817
void
918703f5cff8 Fixed bug 2007 - SDL_SetWindowMinimumSize() not implemented on X11 (thanks Rainer!)
Sam Lantinga <slouken@libsdl.org>
parents: 7566
diff changeset
   818
X11_SetWindowMaximumSize(_THIS, SDL_Window * window)
918703f5cff8 Fixed bug 2007 - SDL_SetWindowMinimumSize() not implemented on X11 (thanks Rainer!)
Sam Lantinga <slouken@libsdl.org>
parents: 7566
diff changeset
   819
{
918703f5cff8 Fixed bug 2007 - SDL_SetWindowMinimumSize() not implemented on X11 (thanks Rainer!)
Sam Lantinga <slouken@libsdl.org>
parents: 7566
diff changeset
   820
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
918703f5cff8 Fixed bug 2007 - SDL_SetWindowMinimumSize() not implemented on X11 (thanks Rainer!)
Sam Lantinga <slouken@libsdl.org>
parents: 7566
diff changeset
   821
    Display *display = data->videodata->display;
918703f5cff8 Fixed bug 2007 - SDL_SetWindowMinimumSize() not implemented on X11 (thanks Rainer!)
Sam Lantinga <slouken@libsdl.org>
parents: 7566
diff changeset
   822
918703f5cff8 Fixed bug 2007 - SDL_SetWindowMinimumSize() not implemented on X11 (thanks Rainer!)
Sam Lantinga <slouken@libsdl.org>
parents: 7566
diff changeset
   823
    if (window->flags & SDL_WINDOW_RESIZABLE) {
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7808
diff changeset
   824
         XSizeHints *sizehints = X11_XAllocSizeHints();
7617
918703f5cff8 Fixed bug 2007 - SDL_SetWindowMinimumSize() not implemented on X11 (thanks Rainer!)
Sam Lantinga <slouken@libsdl.org>
parents: 7566
diff changeset
   825
         long userhints;
918703f5cff8 Fixed bug 2007 - SDL_SetWindowMinimumSize() not implemented on X11 (thanks Rainer!)
Sam Lantinga <slouken@libsdl.org>
parents: 7566
diff changeset
   826
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7808
diff changeset
   827
         X11_XGetWMNormalHints(display, data->xwindow, sizehints, &userhints);
7617
918703f5cff8 Fixed bug 2007 - SDL_SetWindowMinimumSize() not implemented on X11 (thanks Rainer!)
Sam Lantinga <slouken@libsdl.org>
parents: 7566
diff changeset
   828
918703f5cff8 Fixed bug 2007 - SDL_SetWindowMinimumSize() not implemented on X11 (thanks Rainer!)
Sam Lantinga <slouken@libsdl.org>
parents: 7566
diff changeset
   829
         sizehints->max_width = window->max_w;
918703f5cff8 Fixed bug 2007 - SDL_SetWindowMinimumSize() not implemented on X11 (thanks Rainer!)
Sam Lantinga <slouken@libsdl.org>
parents: 7566
diff changeset
   830
         sizehints->max_height = window->max_h;
918703f5cff8 Fixed bug 2007 - SDL_SetWindowMinimumSize() not implemented on X11 (thanks Rainer!)
Sam Lantinga <slouken@libsdl.org>
parents: 7566
diff changeset
   831
         sizehints->flags |= PMaxSize;
918703f5cff8 Fixed bug 2007 - SDL_SetWindowMinimumSize() not implemented on X11 (thanks Rainer!)
Sam Lantinga <slouken@libsdl.org>
parents: 7566
diff changeset
   832
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7808
diff changeset
   833
         X11_XSetWMNormalHints(display, data->xwindow, sizehints);
7617
918703f5cff8 Fixed bug 2007 - SDL_SetWindowMinimumSize() not implemented on X11 (thanks Rainer!)
Sam Lantinga <slouken@libsdl.org>
parents: 7566
diff changeset
   834
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7808
diff changeset
   835
         X11_XFree(sizehints);
7617
918703f5cff8 Fixed bug 2007 - SDL_SetWindowMinimumSize() not implemented on X11 (thanks Rainer!)
Sam Lantinga <slouken@libsdl.org>
parents: 7566
diff changeset
   836
918703f5cff8 Fixed bug 2007 - SDL_SetWindowMinimumSize() not implemented on X11 (thanks Rainer!)
Sam Lantinga <slouken@libsdl.org>
parents: 7566
diff changeset
   837
        /* See comment in X11_SetWindowSize. */
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7808
diff changeset
   838
        X11_XResizeWindow(display, data->xwindow, window->w, window->h);
10103
9cec5fe32bca x11: Fix a few more XMoveWindow() calls to adjust for border size.
Ryan C. Gordon <icculus@icculus.org>
parents: 10102
diff changeset
   839
        X11_XMoveWindow(display, data->xwindow, window->x - data->border_left, window->y - data->border_top);
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7808
diff changeset
   840
        X11_XRaiseWindow(display, data->xwindow);
7617
918703f5cff8 Fixed bug 2007 - SDL_SetWindowMinimumSize() not implemented on X11 (thanks Rainer!)
Sam Lantinga <slouken@libsdl.org>
parents: 7566
diff changeset
   841
    }
918703f5cff8 Fixed bug 2007 - SDL_SetWindowMinimumSize() not implemented on X11 (thanks Rainer!)
Sam Lantinga <slouken@libsdl.org>
parents: 7566
diff changeset
   842
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7808
diff changeset
   843
    X11_XFlush(display);
7617
918703f5cff8 Fixed bug 2007 - SDL_SetWindowMinimumSize() not implemented on X11 (thanks Rainer!)
Sam Lantinga <slouken@libsdl.org>
parents: 7566
diff changeset
   844
}
918703f5cff8 Fixed bug 2007 - SDL_SetWindowMinimumSize() not implemented on X11 (thanks Rainer!)
Sam Lantinga <slouken@libsdl.org>
parents: 7566
diff changeset
   845
918703f5cff8 Fixed bug 2007 - SDL_SetWindowMinimumSize() not implemented on X11 (thanks Rainer!)
Sam Lantinga <slouken@libsdl.org>
parents: 7566
diff changeset
   846
void
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   847
X11_SetWindowSize(_THIS, SDL_Window * window)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   848
{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   849
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   850
    Display *display = data->videodata->display;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   851
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
   852
    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
   853
        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
   854
    }
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
   855
    if (!(window->flags & SDL_WINDOW_RESIZABLE)) {
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7808
diff changeset
   856
         /* Apparently, if the X11 Window is set to a 'non-resizable' window, you cannot resize it using the X11_XResizeWindow, thus
7677
871d43c6968a OCD fixes: Adds a space before */
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7659
diff changeset
   857
            we must set the size hints to adjust the window size. */
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7808
diff changeset
   858
         XSizeHints *sizehints = X11_XAllocSizeHints();
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
   859
         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
   860
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7808
diff changeset
   861
         X11_XGetWMNormalHints(display, data->xwindow, sizehints, &userhints);
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
   862
6343
e94f912d20b9 Fix SDL_SetWindowSize with X11 non-RESIZABLE windows, patch by Pierre-Loup.
Sam Lantinga <slouken@libsdl.org>
parents: 6336
diff changeset
   863
         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
   864
         sizehints->min_height = sizehints->max_height = window->h;
7617
918703f5cff8 Fixed bug 2007 - SDL_SetWindowMinimumSize() not implemented on X11 (thanks Rainer!)
Sam Lantinga <slouken@libsdl.org>
parents: 7566
diff changeset
   865
         sizehints->flags |= PMinSize | PMaxSize;
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
   866
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7808
diff changeset
   867
         X11_XSetWMNormalHints(display, data->xwindow, sizehints);
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
   868
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7808
diff changeset
   869
         X11_XFree(sizehints);
6541
be103236441d Poke window managers to get them to respect the resize hints.
Sam Lantinga <slouken@libsdl.org>
parents: 6540
diff changeset
   870
be103236441d Poke window managers to get them to respect the resize hints.
Sam Lantinga <slouken@libsdl.org>
parents: 6540
diff changeset
   871
        /* From Pierre-Loup:
6899
f75b1bd8eabc Fix SDL_SetWindowSize on certain WMs.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6885
diff changeset
   872
           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
   873
           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
   874
           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
   875
           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
   876
6899
f75b1bd8eabc Fix SDL_SetWindowSize on certain WMs.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6885
diff changeset
   877
           Some of them resize only after:
f75b1bd8eabc Fix SDL_SetWindowSize on certain WMs.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6885
diff changeset
   878
            - A user-initiated move or resize
f75b1bd8eabc Fix SDL_SetWindowSize on certain WMs.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6885
diff changeset
   879
            - A code-initiated move or resize
f75b1bd8eabc Fix SDL_SetWindowSize on certain WMs.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6885
diff changeset
   880
            - 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
   881
6899
f75b1bd8eabc Fix SDL_SetWindowSize on certain WMs.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6885
diff changeset
   882
           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
   883
           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
   884
           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
   885
           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
   886
         */
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7808
diff changeset
   887
        X11_XResizeWindow(display, data->xwindow, window->w, window->h);
10103
9cec5fe32bca x11: Fix a few more XMoveWindow() calls to adjust for border size.
Ryan C. Gordon <icculus@icculus.org>
parents: 10102
diff changeset
   888
        X11_XMoveWindow(display, data->xwindow, window->x - data->border_left, window->y - data->border_top);
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7808
diff changeset
   889
        X11_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
   890
    } else {
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7808
diff changeset
   891
        X11_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
   892
    }
6899
f75b1bd8eabc Fix SDL_SetWindowSize on certain WMs.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6885
diff changeset
   893
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7808
diff changeset
   894
    X11_XFlush(display);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   895
}
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   896
10024
9a1189c7b891 Added SDL_GetWindowBordersSize().
Ryan C. Gordon <icculus@icculus.org>
parents: 10023
diff changeset
   897
int
9a1189c7b891 Added SDL_GetWindowBordersSize().
Ryan C. Gordon <icculus@icculus.org>
parents: 10023
diff changeset
   898
X11_GetWindowBordersSize(_THIS, SDL_Window * window, int *top, int *left, int *bottom, int *right)
9a1189c7b891 Added SDL_GetWindowBordersSize().
Ryan C. Gordon <icculus@icculus.org>
parents: 10023
diff changeset
   899
{
9a1189c7b891 Added SDL_GetWindowBordersSize().
Ryan C. Gordon <icculus@icculus.org>
parents: 10023
diff changeset
   900
    SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
9a1189c7b891 Added SDL_GetWindowBordersSize().
Ryan C. Gordon <icculus@icculus.org>
parents: 10023
diff changeset
   901
10102
11b490897d27 x11: Deal with window borders better.
Ryan C. Gordon <icculus@icculus.org>
parents: 10084
diff changeset
   902
    *left = data->border_left;
11b490897d27 x11: Deal with window borders better.
Ryan C. Gordon <icculus@icculus.org>
parents: 10084
diff changeset
   903
    *right = data->border_right;
11b490897d27 x11: Deal with window borders better.
Ryan C. Gordon <icculus@icculus.org>
parents: 10084
diff changeset
   904
    *top = data->border_top;
11b490897d27 x11: Deal with window borders better.
Ryan C. Gordon <icculus@icculus.org>
parents: 10084
diff changeset
   905
    *bottom = data->border_bottom;
10024
9a1189c7b891 Added SDL_GetWindowBordersSize().
Ryan C. Gordon <icculus@icculus.org>
parents: 10023
diff changeset
   906
10102
11b490897d27 x11: Deal with window borders better.
Ryan C. Gordon <icculus@icculus.org>
parents: 10084
diff changeset
   907
    return 0;
10024
9a1189c7b891 Added SDL_GetWindowBordersSize().
Ryan C. Gordon <icculus@icculus.org>
parents: 10023
diff changeset
   908
}
9a1189c7b891 Added SDL_GetWindowBordersSize().
Ryan C. Gordon <icculus@icculus.org>
parents: 10023
diff changeset
   909
10025
bf4f8cde1c54 Added SDL_SetWindowOpacity() and SDL_GetWindowOpacity().
Ryan C. Gordon <icculus@icculus.org>
parents: 10024
diff changeset
   910
int
bf4f8cde1c54 Added SDL_SetWindowOpacity() and SDL_GetWindowOpacity().
Ryan C. Gordon <icculus@icculus.org>
parents: 10024
diff changeset
   911
X11_SetWindowOpacity(_THIS, SDL_Window * window, float opacity)
bf4f8cde1c54 Added SDL_SetWindowOpacity() and SDL_GetWindowOpacity().
Ryan C. Gordon <icculus@icculus.org>
parents: 10024
diff changeset
   912
{
bf4f8cde1c54 Added SDL_SetWindowOpacity() and SDL_GetWindowOpacity().
Ryan C. Gordon <icculus@icculus.org>
parents: 10024
diff changeset
   913
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
bf4f8cde1c54 Added SDL_SetWindowOpacity() and SDL_GetWindowOpacity().
Ryan C. Gordon <icculus@icculus.org>
parents: 10024
diff changeset
   914
    Display *display = data->videodata->display;
bf4f8cde1c54 Added SDL_SetWindowOpacity() and SDL_GetWindowOpacity().
Ryan C. Gordon <icculus@icculus.org>
parents: 10024
diff changeset
   915
    Atom _NET_WM_WINDOW_OPACITY = data->videodata->_NET_WM_WINDOW_OPACITY;
bf4f8cde1c54 Added SDL_SetWindowOpacity() and SDL_GetWindowOpacity().
Ryan C. Gordon <icculus@icculus.org>
parents: 10024
diff changeset
   916
bf4f8cde1c54 Added SDL_SetWindowOpacity() and SDL_GetWindowOpacity().
Ryan C. Gordon <icculus@icculus.org>
parents: 10024
diff changeset
   917
    if (opacity == 1.0f) {
bf4f8cde1c54 Added SDL_SetWindowOpacity() and SDL_GetWindowOpacity().
Ryan C. Gordon <icculus@icculus.org>
parents: 10024
diff changeset
   918
        X11_XDeleteProperty(display, data->xwindow, _NET_WM_WINDOW_OPACITY);
bf4f8cde1c54 Added SDL_SetWindowOpacity() and SDL_GetWindowOpacity().
Ryan C. Gordon <icculus@icculus.org>
parents: 10024
diff changeset
   919
    } else  {
bf4f8cde1c54 Added SDL_SetWindowOpacity() and SDL_GetWindowOpacity().
Ryan C. Gordon <icculus@icculus.org>
parents: 10024
diff changeset
   920
        const Uint32 FullyOpaque = 0xFFFFFFFF;
bf4f8cde1c54 Added SDL_SetWindowOpacity() and SDL_GetWindowOpacity().
Ryan C. Gordon <icculus@icculus.org>
parents: 10024
diff changeset
   921
        const long alpha = (long) ((double)opacity * (double)FullyOpaque);
bf4f8cde1c54 Added SDL_SetWindowOpacity() and SDL_GetWindowOpacity().
Ryan C. Gordon <icculus@icculus.org>
parents: 10024
diff changeset
   922
        X11_XChangeProperty(display, data->xwindow, _NET_WM_WINDOW_OPACITY, XA_CARDINAL, 32,
bf4f8cde1c54 Added SDL_SetWindowOpacity() and SDL_GetWindowOpacity().
Ryan C. Gordon <icculus@icculus.org>
parents: 10024
diff changeset
   923
            PropModeReplace, (unsigned char *)&alpha, 1);
bf4f8cde1c54 Added SDL_SetWindowOpacity() and SDL_GetWindowOpacity().
Ryan C. Gordon <icculus@icculus.org>
parents: 10024
diff changeset
   924
    }
bf4f8cde1c54 Added SDL_SetWindowOpacity() and SDL_GetWindowOpacity().
Ryan C. Gordon <icculus@icculus.org>
parents: 10024
diff changeset
   925
bf4f8cde1c54 Added SDL_SetWindowOpacity() and SDL_GetWindowOpacity().
Ryan C. Gordon <icculus@icculus.org>
parents: 10024
diff changeset
   926
    return 0;
bf4f8cde1c54 Added SDL_SetWindowOpacity() and SDL_GetWindowOpacity().
Ryan C. Gordon <icculus@icculus.org>
parents: 10024
diff changeset
   927
}
bf4f8cde1c54 Added SDL_SetWindowOpacity() and SDL_GetWindowOpacity().
Ryan C. Gordon <icculus@icculus.org>
parents: 10024
diff changeset
   928
10027
f7ab0613164a Added SDL_SetWindowModalFor().
Ryan C. Gordon <icculus@icculus.org>
parents: 10026
diff changeset
   929
int 
f7ab0613164a Added SDL_SetWindowModalFor().
Ryan C. Gordon <icculus@icculus.org>
parents: 10026
diff changeset
   930
X11_SetWindowModalFor(_THIS, SDL_Window * modal_window, SDL_Window * parent_window) {
f7ab0613164a Added SDL_SetWindowModalFor().
Ryan C. Gordon <icculus@icculus.org>
parents: 10026
diff changeset
   931
    SDL_WindowData *data = (SDL_WindowData *) modal_window->driverdata;
f7ab0613164a Added SDL_SetWindowModalFor().
Ryan C. Gordon <icculus@icculus.org>
parents: 10026
diff changeset
   932
    SDL_WindowData *parent_data = (SDL_WindowData *) parent_window->driverdata;
f7ab0613164a Added SDL_SetWindowModalFor().
Ryan C. Gordon <icculus@icculus.org>
parents: 10026
diff changeset
   933
    Display *display = data->videodata->display;
f7ab0613164a Added SDL_SetWindowModalFor().
Ryan C. Gordon <icculus@icculus.org>
parents: 10026
diff changeset
   934
f7ab0613164a Added SDL_SetWindowModalFor().
Ryan C. Gordon <icculus@icculus.org>
parents: 10026
diff changeset
   935
    X11_XSetTransientForHint(display, data->xwindow, parent_data->xwindow);
f7ab0613164a Added SDL_SetWindowModalFor().
Ryan C. Gordon <icculus@icculus.org>
parents: 10026
diff changeset
   936
    return 0;
f7ab0613164a Added SDL_SetWindowModalFor().
Ryan C. Gordon <icculus@icculus.org>
parents: 10026
diff changeset
   937
}
f7ab0613164a Added SDL_SetWindowModalFor().
Ryan C. Gordon <icculus@icculus.org>
parents: 10026
diff changeset
   938
10026
5f73f513b9f5 Added SDL_SetWindowInputFocus().
Ryan C. Gordon <icculus@icculus.org>
parents: 10025
diff changeset
   939
int
5f73f513b9f5 Added SDL_SetWindowInputFocus().
Ryan C. Gordon <icculus@icculus.org>
parents: 10025
diff changeset
   940
X11_SetWindowInputFocus(_THIS, SDL_Window * window) 
5f73f513b9f5 Added SDL_SetWindowInputFocus().
Ryan C. Gordon <icculus@icculus.org>
parents: 10025
diff changeset
   941
{
5f73f513b9f5 Added SDL_SetWindowInputFocus().
Ryan C. Gordon <icculus@icculus.org>
parents: 10025
diff changeset
   942
    if (X11_IsWindowMapped(_this, window)) {
5f73f513b9f5 Added SDL_SetWindowInputFocus().
Ryan C. Gordon <icculus@icculus.org>
parents: 10025
diff changeset
   943
        SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
5f73f513b9f5 Added SDL_SetWindowInputFocus().
Ryan C. Gordon <icculus@icculus.org>
parents: 10025
diff changeset
   944
        Display *display = data->videodata->display;
5f73f513b9f5 Added SDL_SetWindowInputFocus().
Ryan C. Gordon <icculus@icculus.org>
parents: 10025
diff changeset
   945
        X11_XSetInputFocus(display, data->xwindow, RevertToNone, CurrentTime);
5f73f513b9f5 Added SDL_SetWindowInputFocus().
Ryan C. Gordon <icculus@icculus.org>
parents: 10025
diff changeset
   946
        X11_XFlush(display);
5f73f513b9f5 Added SDL_SetWindowInputFocus().
Ryan C. Gordon <icculus@icculus.org>
parents: 10025
diff changeset
   947
        return 0;
5f73f513b9f5 Added SDL_SetWindowInputFocus().
Ryan C. Gordon <icculus@icculus.org>
parents: 10025
diff changeset
   948
    }
5f73f513b9f5 Added SDL_SetWindowInputFocus().
Ryan C. Gordon <icculus@icculus.org>
parents: 10025
diff changeset
   949
    return -1;
5f73f513b9f5 Added SDL_SetWindowInputFocus().
Ryan C. Gordon <icculus@icculus.org>
parents: 10025
diff changeset
   950
}
5f73f513b9f5 Added SDL_SetWindowInputFocus().
Ryan C. Gordon <icculus@icculus.org>
parents: 10025
diff changeset
   951
6422
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   952
void
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   953
X11_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered)
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   954
{
6423
339c0ccf6250 Make the X11 SetBordered event tapdancing more robust, restore focus, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 6422
diff changeset
   955
    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
   956
    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
   957
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   958
    SDL_DisplayData *displaydata =
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   959
        (SDL_DisplayData *) SDL_GetDisplayForWindow(window)->driverdata;
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   960
    Display *display = data->videodata->display;
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   961
    XEvent event;
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   962
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   963
    SetWindowBordered(display, displaydata->screen, data->xwindow, bordered);
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7808
diff changeset
   964
    X11_XFlush(display);
6422
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   965
6423
339c0ccf6250 Make the X11 SetBordered event tapdancing more robust, restore focus, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 6422
diff changeset
   966
    if (visible) {
339c0ccf6250 Make the X11 SetBordered event tapdancing more robust, restore focus, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 6422
diff changeset
   967
        XWindowAttributes attr;
339c0ccf6250 Make the X11 SetBordered event tapdancing more robust, restore focus, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 6422
diff changeset
   968
        do {
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7808
diff changeset
   969
            X11_XSync(display, False);
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7808
diff changeset
   970
            X11_XGetWindowAttributes(display, data->xwindow, &attr);
6423
339c0ccf6250 Make the X11 SetBordered event tapdancing more robust, restore focus, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 6422
diff changeset
   971
        } 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
   972
339c0ccf6250 Make the X11 SetBordered event tapdancing more robust, restore focus, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 6422
diff changeset
   973
        if (focused) {
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7808
diff changeset
   974
            X11_XSetInputFocus(display, data->xwindow, RevertToParent, CurrentTime);
6423
339c0ccf6250 Make the X11 SetBordered event tapdancing more robust, restore focus, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 6422
diff changeset
   975
        }
339c0ccf6250 Make the X11 SetBordered event tapdancing more robust, restore focus, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 6422
diff changeset
   976
    }
339c0ccf6250 Make the X11 SetBordered event tapdancing more robust, restore focus, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 6422
diff changeset
   977
6422
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   978
    /* make sure these don't make it to the real event queue if they fired here. */
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7808
diff changeset
   979
    X11_XSync(display, False);
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7808
diff changeset
   980
    X11_XCheckIfEvent(display, &event, &isUnmapNotify, (XPointer)&data->xwindow);
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7808
diff changeset
   981
    X11_XCheckIfEvent(display, &event, &isMapNotify, (XPointer)&data->xwindow);
6422
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6373
diff changeset
   982
}
6336
6e6163b6ba69 Fixed issue with tiling window managers (bug 1246)
Sam Lantinga <slouken@libsdl.org>
parents: 6331
diff changeset
   983
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   984
void
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   985
X11_ShowWindow(_THIS, SDL_Window * window)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   986
{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   987
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   988
    Display *display = data->videodata->display;
6336
6e6163b6ba69 Fixed issue with tiling window managers (bug 1246)
Sam Lantinga <slouken@libsdl.org>
parents: 6331
diff changeset
   989
    XEvent event;
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   990
6483
4b51ff3dcf74 Only map/unmap if the window isn't already in the correct state.
Sam Lantinga <slouken@libsdl.org>
parents: 6481
diff changeset
   991
    if (!X11_IsWindowMapped(_this, window)) {
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7808
diff changeset
   992
        X11_XMapRaised(display, 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
   993
        /* Blocking wait for "MapNotify" event.
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7808
diff changeset
   994
         * We use X11_XIfEvent because pXWindowEvent 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
   995
         * and XCheckTypedWindowEvent doesn't block */
7827
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7808
diff changeset
   996
        X11_XIfEvent(display, &event, &isMapNotify, (XPointer)&data->xwindow);
a03ec8de0426 Don't supply duplicate X11 symbols inside SDL.
Ryan C. Gordon <icculus@icculus.org>
parents: 7808
diff changeset
   997
        X11_XFlush(display);
6483
4b51ff3dcf74 Only map/unmap if the window isn't already in the correct state.
Sam Lantinga <slouken@libsdl.org>
parents: 6481
diff changeset
   998
    }
9683
aa4e4768c6c1 X11: Force the window focus during ShowWindow if there's no window manager.
Ryan C. Gordon <icculus@icculus.org>
parents: 9619
diff changeset
   999
9794
5aa6018e18ed Fixed style
Sam Lantinga <slouken@libsdl.org>
parents: 9793
diff changeset
  1000
    if (!data->videodata->net_wm) {
9683
aa4e4768c6c1 X11: Force the window focus during ShowWindow if there's no window manager.
Ryan C. Gordon <icculus@icculus.org>
parents: 9619
diff changeset
  1001
        /* no WM means no FocusIn event, which confuses us. Force it. */
aa4e4768c6c1 X11: Force the window focus during ShowWindow if there's no window manager.
Ryan C. Gordon <icculus@icculus.org>
parents: 9619
diff changeset
  1002
        X11_XSetInputFocus(display, data->xwindow, RevertToNone, CurrentTime);
aa4e4768c6c1 X11: Force the window focus during ShowWindow if there's no window manager.
Ryan C. Gordon <icculus@icculus.org>
parents: 9619
diff changeset
  1003
        X11_XFlush(display);
aa4e4768c6c1 X11: Force the window focus during ShowWindow if there's no window manager.
Ryan C. Gordon <icculus@icculus.org>
parents: 9619
diff changeset
  1004
    }
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1005
}
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1006
7177581dc9fa Initial work on X11 window code in.