include/SDL_syswm.h
author Ryan C. Gordon <icculus@icculus.org>
Sun, 11 Jun 2017 00:50:26 -0400
changeset 11088 69452f9839d5
parent 11065 9e8d300d50da
child 11287 4d2a6202caa4
permissions -rw-r--r--
syswm: prevent buffer overflow if SDL and app have different config headers.

This only affects Wayland and DirectFB, as a Unix system generally has X11
support. Other platforms also have different sizes for the C union in
question, but are likely the only target for that platform, etc.

Apps that might run on Wayland or DirectFB will need to be compiled against
new headers from an official 2.0.6 release, or be prepared to force the x11
target, or not use SDL_GetWindowWMInfo().

Fixes Bugzilla #3428.
slouken@0
     1
/*
slouken@5535
     2
  Simple DirectMedia Layer
slouken@10737
     3
  Copyright (C) 1997-2017 Sam Lantinga <slouken@libsdl.org>
slouken@0
     4
slouken@5535
     5
  This software is provided 'as-is', without any express or implied
slouken@5535
     6
  warranty.  In no event will the authors be held liable for any damages
slouken@5535
     7
  arising from the use of this software.
slouken@0
     8
slouken@5535
     9
  Permission is granted to anyone to use this software for any purpose,
slouken@5535
    10
  including commercial applications, and to alter it and redistribute it
slouken@5535
    11
  freely, subject to the following restrictions:
slouken@0
    12
slouken@5535
    13
  1. The origin of this software must not be misrepresented; you must not
slouken@5535
    14
     claim that you wrote the original software. If you use this software
slouken@5535
    15
     in a product, an acknowledgment in the product documentation would be
slouken@5535
    16
     appreciated but is not required.
slouken@5535
    17
  2. Altered source versions must be plainly marked as such, and must not be
slouken@5535
    18
     misrepresented as being the original software.
slouken@5535
    19
  3. This notice may not be removed or altered from any source distribution.
slouken@0
    20
*/
slouken@0
    21
slouken@1895
    22
/**
slouken@3407
    23
 *  \file SDL_syswm.h
slouken@7191
    24
 *
slouken@3407
    25
 *  Include file for SDL custom system window manager hooks.
slouken@1895
    26
 */
slouken@0
    27
slouken@10638
    28
#ifndef SDL_syswm_h_
slouken@10638
    29
#define SDL_syswm_h_
slouken@0
    30
slouken@1356
    31
#include "SDL_stdinc.h"
slouken@1358
    32
#include "SDL_error.h"
slouken@1895
    33
#include "SDL_video.h"
slouken@0
    34
#include "SDL_version.h"
slouken@0
    35
slouken@0
    36
#include "begin_code.h"
slouken@0
    37
/* Set up for C function definitions, even when using C++ */
slouken@0
    38
#ifdef __cplusplus
slouken@0
    39
extern "C" {
slouken@0
    40
#endif
slouken@0
    41
slouken@3407
    42
/**
slouken@3407
    43
 *  \file SDL_syswm.h
slouken@7191
    44
 *
slouken@3407
    45
 *  Your application has access to a special type of event ::SDL_SYSWMEVENT,
slouken@3407
    46
 *  which contains window-manager specific information and arrives whenever
slouken@3407
    47
 *  an unhandled window event occurs.  This event is ignored by default, but
slouken@3407
    48
 *  you can enable it with SDL_EventState().
slouken@3407
    49
 */
slouken@0
    50
#ifdef SDL_PROTOTYPES_ONLY
slouken@0
    51
struct SDL_SysWMinfo;
slouken@0
    52
#else
slouken@0
    53
slouken@5062
    54
#if defined(SDL_VIDEO_DRIVER_WINDOWS)
jorgen@8968
    55
#ifndef WIN32_LEAN_AND_MEAN
slouken@4900
    56
#define WIN32_LEAN_AND_MEAN
jorgen@8968
    57
#endif
slouken@4900
    58
#include <windows.h>
slouken@4900
    59
#endif
slouken@4900
    60
dludwig@8463
    61
#if defined(SDL_VIDEO_DRIVER_WINRT)
dludwig@8527
    62
#include <Inspectable.h>
dludwig@8463
    63
#endif
dludwig@8463
    64
slouken@1361
    65
/* This is the structure for custom window manager events */
slouken@1626
    66
#if defined(SDL_VIDEO_DRIVER_X11)
icculus@1133
    67
#if defined(__APPLE__) && defined(__MACH__)
slouken@1487
    68
/* conflicts with Quickdraw.h */
icculus@1133
    69
#define Cursor X11Cursor
icculus@1133
    70
#endif
icculus@1133
    71
slouken@0
    72
#include <X11/Xlib.h>
slouken@0
    73
#include <X11/Xatom.h>
slouken@0
    74
icculus@1133
    75
#if defined(__APPLE__) && defined(__MACH__)
slouken@1487
    76
/* matches the re-define above */
icculus@1133
    77
#undef Cursor
icculus@1133
    78
#endif
icculus@1133
    79
slouken@4899
    80
#endif /* defined(SDL_VIDEO_DRIVER_X11) */
slouken@4899
    81
slouken@4899
    82
#if defined(SDL_VIDEO_DRIVER_DIRECTFB)
slouken@5199
    83
#include <directfb.h>
slouken@4899
    84
#endif
slouken@4900
    85
slouken@4900
    86
#if defined(SDL_VIDEO_DRIVER_COCOA)
slouken@4900
    87
#ifdef __OBJC__
jorgen@8812
    88
@class NSWindow;
slouken@4900
    89
#else
slouken@4900
    90
typedef struct _NSWindow NSWindow;
slouken@4900
    91
#endif
slouken@4900
    92
#endif
slouken@4900
    93
slouken@5056
    94
#if defined(SDL_VIDEO_DRIVER_UIKIT)
slouken@5056
    95
#ifdef __OBJC__
slouken@5056
    96
#include <UIKit/UIKit.h>
slouken@5056
    97
#else
slouken@5056
    98
typedef struct _UIWindow UIWindow;
dludwig@8305
    99
typedef struct _UIViewController UIViewController;
slouken@5056
   100
#endif
slime73@9540
   101
typedef Uint32 GLuint;
slouken@5056
   102
#endif
slouken@5056
   103
slouken@8799
   104
#if defined(SDL_VIDEO_DRIVER_ANDROID)
slouken@8799
   105
typedef struct ANativeWindow ANativeWindow;
slouken@8799
   106
typedef void *EGLSurface;
slouken@8799
   107
#endif
slouken@8799
   108
slouken@10055
   109
#if defined(SDL_VIDEO_DRIVER_VIVANTE)
slouken@10055
   110
#include "SDL_egl.h"
slouken@10055
   111
#endif
slouken@10055
   112
slouken@7191
   113
/**
slouken@4900
   114
 *  These are the various supported windowing subsystems
slouken@3407
   115
 */
slouken@1895
   116
typedef enum
slouken@1895
   117
{
slouken@4900
   118
    SDL_SYSWM_UNKNOWN,
slouken@4900
   119
    SDL_SYSWM_WINDOWS,
slouken@4899
   120
    SDL_SYSWM_X11,
slouken@4899
   121
    SDL_SYSWM_DIRECTFB,
slouken@4900
   122
    SDL_SYSWM_COCOA,
slouken@5056
   123
    SDL_SYSWM_UIKIT,
gabomdq@8134
   124
    SDL_SYSWM_WAYLAND,
icculus@8153
   125
    SDL_SYSWM_MIR,
slouken@8799
   126
    SDL_SYSWM_WINRT,
slouken@10055
   127
    SDL_SYSWM_ANDROID,
slouken@10055
   128
    SDL_SYSWM_VIVANTE
slouken@0
   129
} SDL_SYSWM_TYPE;
slouken@0
   130
slouken@3407
   131
/**
slouken@4900
   132
 *  The custom event structure.
slouken@3407
   133
 */
slouken@1895
   134
struct SDL_SysWMmsg
slouken@1895
   135
{
slouken@1895
   136
    SDL_version version;
slouken@1895
   137
    SDL_SYSWM_TYPE subsystem;
slouken@1895
   138
    union
slouken@1895
   139
    {
slouken@5062
   140
#if defined(SDL_VIDEO_DRIVER_WINDOWS)
slouken@4900
   141
        struct {
slouken@4900
   142
            HWND hwnd;                  /**< The window for the message */
slouken@4900
   143
            UINT msg;                   /**< The type of message */
slouken@4900
   144
            WPARAM wParam;              /**< WORD message parameter */
slouken@4900
   145
            LPARAM lParam;              /**< LONG message parameter */
slouken@4900
   146
        } win;
slouken@5065
   147
#endif
slouken@5065
   148
#if defined(SDL_VIDEO_DRIVER_X11)
slouken@4900
   149
        struct {
slouken@4900
   150
            XEvent event;
slouken@4900
   151
        } x11;
slouken@5065
   152
#endif
slouken@5065
   153
#if defined(SDL_VIDEO_DRIVER_DIRECTFB)
slouken@4900
   154
        struct {
slouken@4900
   155
            DFBEvent event;
slouken@4900
   156
        } dfb;
slouken@5065
   157
#endif
slouken@5065
   158
#if defined(SDL_VIDEO_DRIVER_COCOA)
slouken@4900
   159
        struct
slouken@4900
   160
        {
jorgen@9153
   161
            /* Latest version of Xcode clang complains about empty structs in C v. C++:
jorgen@9153
   162
                 error: empty struct has size 0 in C, size 1 in C++
jorgen@9153
   163
             */
jorgen@9153
   164
            int dummy;
slouken@4900
   165
            /* No Cocoa window events yet */
slouken@4900
   166
        } cocoa;
slouken@5065
   167
#endif
slouken@5065
   168
#if defined(SDL_VIDEO_DRIVER_UIKIT)
slouken@5056
   169
        struct
slouken@5056
   170
        {
slime73@9586
   171
            int dummy;
slouken@5056
   172
            /* No UIKit window events yet */
slouken@5056
   173
        } uikit;
slouken@5065
   174
#endif
slouken@10055
   175
#if defined(SDL_VIDEO_DRIVER_VIVANTE)
slouken@10055
   176
        struct
slouken@10055
   177
        {
slouken@10055
   178
            int dummy;
slouken@10055
   179
            /* No Vivante window events yet */
slouken@10055
   180
        } vivante;
slouken@10055
   181
#endif
slouken@5063
   182
        /* Can't have an empty union */
slouken@5063
   183
        int dummy;
slouken@5056
   184
    } msg;
slouken@0
   185
};
slouken@0
   186
slouken@3407
   187
/**
slouken@4900
   188
 *  The custom window manager information structure.
slouken@3407
   189
 *
slouken@3407
   190
 *  When this structure is returned, it holds information about which
slouken@3407
   191
 *  low level system it is using, and will be one of SDL_SYSWM_TYPE.
slouken@0
   192
 */
slouken@1895
   193
struct SDL_SysWMinfo
slouken@1895
   194
{
slouken@1895
   195
    SDL_version version;
slouken@1895
   196
    SDL_SYSWM_TYPE subsystem;
slouken@1895
   197
    union
slouken@1895
   198
    {
slouken@5062
   199
#if defined(SDL_VIDEO_DRIVER_WINDOWS)
slouken@4900
   200
        struct
slouken@4900
   201
        {
slouken@4903
   202
            HWND window;                /**< The window handle */
icculus@9422
   203
            HDC hdc;                    /**< The window device context */
slouken@10634
   204
            HINSTANCE hinstance;        /**< The instance handle */
slouken@4900
   205
        } win;
slouken@5065
   206
#endif
dludwig@8411
   207
#if defined(SDL_VIDEO_DRIVER_WINRT)
dludwig@8411
   208
        struct
dludwig@8411
   209
        {
dludwig@8527
   210
            IInspectable * window;      /**< The WinRT CoreWindow */
dludwig@8411
   211
        } winrt;
dludwig@8411
   212
#endif
slouken@5065
   213
#if defined(SDL_VIDEO_DRIVER_X11)
slouken@1895
   214
        struct
slouken@1895
   215
        {
slouken@4900
   216
            Display *display;           /**< The X11 display */
slouken@4903
   217
            Window window;              /**< The X11 window */
slouken@1895
   218
        } x11;
slouken@5065
   219
#endif
slouken@5065
   220
#if defined(SDL_VIDEO_DRIVER_DIRECTFB)
slouken@4899
   221
        struct
slouken@4899
   222
        {
slouken@4903
   223
            IDirectFB *dfb;             /**< The directfb main interface */
slouken@4903
   224
            IDirectFBWindow *window;    /**< The directfb window handle */
slouken@4903
   225
            IDirectFBSurface *surface;  /**< The directfb client surface */
slouken@4900
   226
        } dfb;
slouken@5065
   227
#endif
slouken@5065
   228
#if defined(SDL_VIDEO_DRIVER_COCOA)
slouken@4900
   229
        struct
slouken@4900
   230
        {
slouken@9099
   231
#if defined(__OBJC__) && defined(__has_feature) && __has_feature(objc_arc)
philipp@11065
   232
            NSWindow __unsafe_unretained *window; /**< The Cocoa window */
icculus@9035
   233
#else
philipp@11065
   234
            NSWindow *window;                     /**< The Cocoa window */
icculus@9035
   235
#endif
slouken@4900
   236
        } cocoa;
slouken@5065
   237
#endif
slouken@5065
   238
#if defined(SDL_VIDEO_DRIVER_UIKIT)
slouken@5056
   239
        struct
slouken@5056
   240
        {
slouken@9099
   241
#if defined(__OBJC__) && defined(__has_feature) && __has_feature(objc_arc)
philipp@11065
   242
            UIWindow __unsafe_unretained *window; /**< The UIKit window */
icculus@9035
   243
#else
philipp@11065
   244
            UIWindow *window;                     /**< The UIKit window */
icculus@9035
   245
#endif
philipp@11065
   246
            GLuint framebuffer; /**< The GL view's Framebuffer Object. It must be bound when rendering to the screen using GL. */
philipp@11065
   247
            GLuint colorbuffer; /**< The GL view's color Renderbuffer Object. It must be bound when SDL_GL_SwapWindow is called. */
philipp@11065
   248
            GLuint resolveFramebuffer; /**< The Framebuffer Object which holds the resolve color Renderbuffer, when MSAA is used. */
slouken@5056
   249
        } uikit;
slouken@5065
   250
#endif
gabomdq@8134
   251
#if defined(SDL_VIDEO_DRIVER_WAYLAND)
gabomdq@8134
   252
        struct
gabomdq@8134
   253
        {
gabomdq@8134
   254
            struct wl_display *display;            /**< Wayland display */
gabomdq@8134
   255
            struct wl_surface *surface;            /**< Wayland surface */
gabomdq@8134
   256
            struct wl_shell_surface *shell_surface; /**< Wayland shell_surface (window manager handle) */
gabomdq@8134
   257
        } wl;
gabomdq@8134
   258
#endif
icculus@8155
   259
#if defined(SDL_VIDEO_DRIVER_MIR)
icculus@8155
   260
        struct
icculus@8155
   261
        {
brandon@8731
   262
            struct MirConnection *connection;  /**< Mir display server connection */
brandon@8731
   263
            struct MirSurface *surface;  /**< Mir surface */
icculus@8155
   264
        } mir;
icculus@8155
   265
#endif
icculus@8155
   266
slouken@8799
   267
#if defined(SDL_VIDEO_DRIVER_ANDROID)
slouken@8799
   268
        struct
slouken@8799
   269
        {
slouken@8799
   270
            ANativeWindow *window;
slouken@8799
   271
            EGLSurface surface;
slouken@8799
   272
        } android;
slouken@8799
   273
#endif
slouken@8799
   274
slouken@10055
   275
#if defined(SDL_VIDEO_DRIVER_VIVANTE)
slouken@10055
   276
        struct
slouken@10055
   277
        {
slouken@10055
   278
            EGLNativeDisplayType display;
slouken@10055
   279
            EGLNativeWindowType window;
slouken@10055
   280
        } vivante;
slouken@10055
   281
#endif
slouken@10055
   282
icculus@11088
   283
        /* Make sure this union is always 64 bytes (8 64-bit pointers). */
icculus@11088
   284
        /* Be careful not to overflow this if you add a new target! */
icculus@11088
   285
        Uint8 dummy[64];
slouken@5056
   286
    } info;
slouken@1895
   287
};
slouken@0
   288
slouken@0
   289
#endif /* SDL_PROTOTYPES_ONLY */
slouken@0
   290
slouken@1895
   291
typedef struct SDL_SysWMinfo SDL_SysWMinfo;
slouken@1895
   292
slouken@0
   293
/* Function prototypes */
slouken@1895
   294
/**
slouken@3407
   295
 *  \brief This function allows access to driver-dependent window information.
slouken@7191
   296
 *
slouken@4530
   297
 *  \param window The window about which information is being requested
slouken@7191
   298
 *  \param info This structure must be initialized with the SDL version, and is
slouken@3407
   299
 *              then filled in with information about the given window.
slouken@7191
   300
 *
slouken@7191
   301
 *  \return SDL_TRUE if the function is implemented and the version member of
slouken@3407
   302
 *          the \c info struct is valid, SDL_FALSE otherwise.
slouken@7191
   303
 *
slouken@3407
   304
 *  You typically use this function like this:
slouken@3407
   305
 *  \code
slouken@4895
   306
 *  SDL_SysWMinfo info;
slouken@3407
   307
 *  SDL_VERSION(&info.version);
slouken@7455
   308
 *  if ( SDL_GetWindowWMInfo(window, &info) ) { ... }
slouken@3407
   309
 *  \endcode
slouken@0
   310
 */
slouken@3685
   311
extern DECLSPEC SDL_bool SDLCALL SDL_GetWindowWMInfo(SDL_Window * window,
slouken@1895
   312
                                                     SDL_SysWMinfo * info);
slouken@0
   313
slouken@0
   314
slouken@0
   315
/* Ends C function definitions when using C++ */
slouken@0
   316
#ifdef __cplusplus
slouken@0
   317
}
slouken@0
   318
#endif
slouken@0
   319
#include "close_code.h"
slouken@0
   320
slouken@10638
   321
#endif /* SDL_syswm_h_ */
slouken@1895
   322
slouken@1895
   323
/* vi: set ts=4 sw=4 expandtab: */