src/video/x11/SDL_x11dyn.c
author Sam Lantinga <slouken@libsdl.org>
Thu, 17 Oct 2013 17:38:55 -0700
changeset 7825 10be1bae0f7a
parent 7191 75360622e65f
child 7827 a03ec8de0426
permissions -rw-r--r--
Fixed compiler warning if dynamic X11 loading isn't enabled.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1950
a344e42bce3b Started work on the new X11 driver.
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: 5481
diff changeset
     2
  Simple DirectMedia Layer
6885
700f1b25f77f Happy New Year!
Sam Lantinga <slouken@libsdl.org>
parents: 6376
diff changeset
     3
  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
1950
a344e42bce3b Started work on the new X11 driver.
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: 5481
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: 5481
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: 5481
diff changeset
     7
  arising from the use of this software.
1950
a344e42bce3b Started work on the new X11 driver.
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: 5481
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: 5481
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: 5481
diff changeset
    11
  freely, subject to the following restrictions:
1950
a344e42bce3b Started work on the new X11 driver.
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: 5481
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: 5481
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: 5481
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: 5481
diff changeset
    16
     appreciated but is not required.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5481
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: 5481
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: 5481
diff changeset
    19
  3. This notice may not be removed or altered from any source distribution.
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    20
*/
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    21
#include "SDL_config.h"
a344e42bce3b Started work on the new X11 driver.
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: 5471
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: 5471
diff changeset
    24
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    25
#define DEBUG_DYNAMIC_X11 0
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    26
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    27
#include "SDL_x11dyn.h"
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    28
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    29
#if DEBUG_DYNAMIC_X11
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    30
#include <stdio.h>
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    31
#endif
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    32
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    33
#ifdef SDL_VIDEO_DRIVER_X11_DYNAMIC
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    34
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    35
#include "SDL_name.h"
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    36
#include "SDL_loadso.h"
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    37
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    38
typedef struct
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    39
{
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    40
    void *lib;
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    41
    const char *libname;
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    42
} x11dynlib;
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    43
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    44
#ifndef SDL_VIDEO_DRIVER_X11_DYNAMIC
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    45
#define SDL_VIDEO_DRIVER_X11_DYNAMIC NULL
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    46
#endif
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    47
#ifndef SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    48
#define SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT NULL
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    49
#endif
5471
179adad3ae6f Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5408
diff changeset
    50
#ifndef SDL_VIDEO_DRIVER_X11_DYNAMIC_XCURSOR
179adad3ae6f Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5408
diff changeset
    51
#define SDL_VIDEO_DRIVER_X11_DYNAMIC_XCURSOR NULL
179adad3ae6f Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5408
diff changeset
    52
#endif
5408
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    53
#ifndef SDL_VIDEO_DRIVER_X11_DYNAMIC_XINERAMA
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    54
#define SDL_VIDEO_DRIVER_X11_DYNAMIC_XINERAMA NULL
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    55
#endif
6311
4e5e46f43438 Initial support for XInput2 by Dimitris Zenios
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
    56
#ifndef SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT2
4e5e46f43438 Initial support for XInput2 by Dimitris Zenios
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
    57
#define SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT2 NULL
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    58
#endif
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    59
#ifndef SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    60
#define SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR NULL
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    61
#endif
3036
Bob Pendleton <bob@pendleton.com>
parents: 3025
diff changeset
    62
#ifndef SDL_VIDEO_DRIVER_X11_DYNAMIC_XSS
Bob Pendleton <bob@pendleton.com>
parents: 3025
diff changeset
    63
#define SDL_VIDEO_DRIVER_X11_DYNAMIC_XSS NULL
Bob Pendleton <bob@pendleton.com>
parents: 3025
diff changeset
    64
#endif
5408
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    65
#ifndef SDL_VIDEO_DRIVER_X11_DYNAMIC_XVIDMODE
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    66
#define SDL_VIDEO_DRIVER_X11_DYNAMIC_XVIDMODE NULL
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    67
#endif
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    68
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    69
static x11dynlib x11libs[] = {
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    70
    {NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC},
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    71
    {NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT},
5471
179adad3ae6f Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5408
diff changeset
    72
    {NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XCURSOR},
5408
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    73
    {NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XINERAMA},
6311
4e5e46f43438 Initial support for XInput2 by Dimitris Zenios
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
    74
    {NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT2},
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    75
    {NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR},
3025
54fac87e1f34 Added an API to enable/disable the screen saver.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
    76
    {NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XSS},
5408
35a63789c3f2 Dynamically load the Xinerama and xf86vmode extensions
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    77
    {NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XVIDMODE}
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    78
};
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    79
6376
f7ec45572c54 Should fix type-punning compiler warnings.
Ryan C. Gordon <icculus@icculus.org>
parents: 6311
diff changeset
    80
static void *
f7ec45572c54 Should fix type-punning compiler warnings.
Ryan C. Gordon <icculus@icculus.org>
parents: 6311
diff changeset
    81
X11_GetSym(const char *fnname, int *pHasModule)
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    82
{
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    83
    int i;
6376
f7ec45572c54 Should fix type-punning compiler warnings.
Ryan C. Gordon <icculus@icculus.org>
parents: 6311
diff changeset
    84
    void *fn = NULL;
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    85
    for (i = 0; i < SDL_TABLESIZE(x11libs); i++) {
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    86
        if (x11libs[i].lib != NULL) {
6376
f7ec45572c54 Should fix type-punning compiler warnings.
Ryan C. Gordon <icculus@icculus.org>
parents: 6311
diff changeset
    87
            fn = SDL_LoadFunction(x11libs[i].lib, fnname);
f7ec45572c54 Should fix type-punning compiler warnings.
Ryan C. Gordon <icculus@icculus.org>
parents: 6311
diff changeset
    88
            if (fn != NULL)
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    89
                break;
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    90
        }
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    91
    }
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    92
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    93
#if DEBUG_DYNAMIC_X11
6376
f7ec45572c54 Should fix type-punning compiler warnings.
Ryan C. Gordon <icculus@icculus.org>
parents: 6311
diff changeset
    94
    if (fn != NULL)
f7ec45572c54 Should fix type-punning compiler warnings.
Ryan C. Gordon <icculus@icculus.org>
parents: 6311
diff changeset
    95
        printf("X11: Found '%s' in %s (%p)\n", fnname, x11libs[i].libname, fn);
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    96
    else
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    97
        printf("X11: Symbol '%s' NOT FOUND!\n", fnname);
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    98
#endif
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    99
6376
f7ec45572c54 Should fix type-punning compiler warnings.
Ryan C. Gordon <icculus@icculus.org>
parents: 6311
diff changeset
   100
    if (fn == NULL)
f7ec45572c54 Should fix type-punning compiler warnings.
Ryan C. Gordon <icculus@icculus.org>
parents: 6311
diff changeset
   101
        *pHasModule = 0;  /* kill this module. */
f7ec45572c54 Should fix type-punning compiler warnings.
Ryan C. Gordon <icculus@icculus.org>
parents: 6311
diff changeset
   102
f7ec45572c54 Should fix type-punning compiler warnings.
Ryan C. Gordon <icculus@icculus.org>
parents: 6311
diff changeset
   103
    return fn;
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   104
}
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   105
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   106
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   107
/* Define all the function pointers and wrappers... */
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   108
#define SDL_X11_MODULE(modname)
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   109
#define SDL_X11_SYM(rc,fn,params,args,ret) \
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6898
diff changeset
   110
    typedef rc (*SDL_DYNX11FN_##fn) params; \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6898
diff changeset
   111
    static SDL_DYNX11FN_##fn p##fn = NULL; \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6898
diff changeset
   112
    rc fn params { ret p##fn args ; }
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   113
#include "SDL_x11sym.h"
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   114
#undef SDL_X11_MODULE
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   115
#undef SDL_X11_SYM
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   116
#endif /* SDL_VIDEO_DRIVER_X11_DYNAMIC */
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   117
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   118
/* Annoying varargs entry point... */
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   119
#ifdef X_HAVE_UTF8_STRING
6376
f7ec45572c54 Should fix type-punning compiler warnings.
Ryan C. Gordon <icculus@icculus.org>
parents: 6311
diff changeset
   120
typedef XIC(*SDL_DYNX11FN_XCreateIC) (XIM,...);
f7ec45572c54 Should fix type-punning compiler warnings.
Ryan C. Gordon <icculus@icculus.org>
parents: 6311
diff changeset
   121
SDL_DYNX11FN_XCreateIC pXCreateIC = NULL;
f7ec45572c54 Should fix type-punning compiler warnings.
Ryan C. Gordon <icculus@icculus.org>
parents: 6311
diff changeset
   122
typedef char *(*SDL_DYNX11FN_XGetICValues) (XIC, ...);
f7ec45572c54 Should fix type-punning compiler warnings.
Ryan C. Gordon <icculus@icculus.org>
parents: 6311
diff changeset
   123
SDL_DYNX11FN_XGetICValues pXGetICValues = NULL;
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   124
#endif
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   125
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   126
/* These SDL_X11_HAVE_* flags are here whether you have dynamic X11 or not. */
6026
a7142857e885 SDL_X11_HAVE_* should default (and reset) to zero.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   127
#define SDL_X11_MODULE(modname) int SDL_X11_HAVE_##modname = 0;
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   128
#define SDL_X11_SYM(rc,fn,params,args,ret)
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   129
#include "SDL_x11sym.h"
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   130
#undef SDL_X11_MODULE
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   131
#undef SDL_X11_SYM
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   132
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   133
7825
10be1bae0f7a Fixed compiler warning if dynamic X11 loading isn't enabled.
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   134
#ifdef SDL_VIDEO_DRIVER_X11_DYNAMIC
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   135
static int x11_load_refcount = 0;
7825
10be1bae0f7a Fixed compiler warning if dynamic X11 loading isn't enabled.
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   136
#endif
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   137
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   138
void
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   139
SDL_X11_UnloadSymbols(void)
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   140
{
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   141
#ifdef SDL_VIDEO_DRIVER_X11_DYNAMIC
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   142
    /* Don't actually unload if more than one module is using the libs... */
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   143
    if (x11_load_refcount > 0) {
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   144
        if (--x11_load_refcount == 0) {
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   145
            int i;
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   146
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   147
            /* set all the function pointers to NULL. */
6026
a7142857e885 SDL_X11_HAVE_* should default (and reset) to zero.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   148
#define SDL_X11_MODULE(modname) SDL_X11_HAVE_##modname = 0;
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   149
#define SDL_X11_SYM(rc,fn,params,args,ret) p##fn = NULL;
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   150
#include "SDL_x11sym.h"
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   151
#undef SDL_X11_MODULE
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   152
#undef SDL_X11_SYM
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   153
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   154
#ifdef X_HAVE_UTF8_STRING
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   155
            pXCreateIC = NULL;
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: 2120
diff changeset
   156
            pXGetICValues = NULL;
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   157
#endif
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   158
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   159
            for (i = 0; i < SDL_TABLESIZE(x11libs); i++) {
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   160
                if (x11libs[i].lib != NULL) {
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   161
                    SDL_UnloadObject(x11libs[i].lib);
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   162
                    x11libs[i].lib = NULL;
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   163
                }
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   164
            }
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   165
        }
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   166
    }
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   167
#endif
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   168
}
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   169
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   170
/* returns non-zero if all needed symbols were loaded. */
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   171
int
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   172
SDL_X11_LoadSymbols(void)
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   173
{
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   174
    int rc = 1;                 /* always succeed if not using Dynamic X11 stuff. */
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   175
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   176
#ifdef SDL_VIDEO_DRIVER_X11_DYNAMIC
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   177
    /* deal with multiple modules (dga, x11, etc) needing these symbols... */
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   178
    if (x11_load_refcount++ == 0) {
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   179
        int i;
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   180
        int *thismod = NULL;
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   181
        for (i = 0; i < SDL_TABLESIZE(x11libs); i++) {
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   182
            if (x11libs[i].libname != NULL) {
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   183
                x11libs[i].lib = SDL_LoadObject(x11libs[i].libname);
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   184
            }
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   185
        }
6030
50560ca58f80 Fix X11 dynamic loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 6026
diff changeset
   186
50560ca58f80 Fix X11 dynamic loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 6026
diff changeset
   187
#define SDL_X11_MODULE(modname) SDL_X11_HAVE_##modname = 1; /* default yes */
50560ca58f80 Fix X11 dynamic loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 6026
diff changeset
   188
#define SDL_X11_SYM(a,fn,x,y,z)
50560ca58f80 Fix X11 dynamic loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 6026
diff changeset
   189
#include "SDL_x11sym.h"
50560ca58f80 Fix X11 dynamic loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 6026
diff changeset
   190
#undef SDL_X11_MODULE
50560ca58f80 Fix X11 dynamic loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 6026
diff changeset
   191
#undef SDL_X11_SYM
50560ca58f80 Fix X11 dynamic loading.
Ryan C. Gordon <icculus@icculus.org>
parents: 6026
diff changeset
   192
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   193
#define SDL_X11_MODULE(modname) thismod = &SDL_X11_HAVE_##modname;
6376
f7ec45572c54 Should fix type-punning compiler warnings.
Ryan C. Gordon <icculus@icculus.org>
parents: 6311
diff changeset
   194
#define SDL_X11_SYM(a,fn,x,y,z) p##fn = (SDL_DYNX11FN_##fn) X11_GetSym(#fn,thismod);
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   195
#include "SDL_x11sym.h"
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   196
#undef SDL_X11_MODULE
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   197
#undef SDL_X11_SYM
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   198
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   199
#ifdef X_HAVE_UTF8_STRING
6376
f7ec45572c54 Should fix type-punning compiler warnings.
Ryan C. Gordon <icculus@icculus.org>
parents: 6311
diff changeset
   200
        pXCreateIC = (SDL_DYNX11FN_XCreateIC)
f7ec45572c54 Should fix type-punning compiler warnings.
Ryan C. Gordon <icculus@icculus.org>
parents: 6311
diff changeset
   201
                        X11_GetSym("XCreateIC", &SDL_X11_HAVE_UTF8);
f7ec45572c54 Should fix type-punning compiler warnings.
Ryan C. Gordon <icculus@icculus.org>
parents: 6311
diff changeset
   202
        pXGetICValues = (SDL_DYNX11FN_XGetICValues)
f7ec45572c54 Should fix type-punning compiler warnings.
Ryan C. Gordon <icculus@icculus.org>
parents: 6311
diff changeset
   203
                        X11_GetSym("XGetICValues", &SDL_X11_HAVE_UTF8);
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   204
#endif
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   205
2120
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2118
diff changeset
   206
        if (SDL_X11_HAVE_BASEXLIB) {
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2118
diff changeset
   207
            /* all required symbols loaded. */
2118
238db749017a Merged r3062:3063 from branches/SDL-1.2: clear inaccurate x11dyn error strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 1950
diff changeset
   208
            SDL_ClearError();
238db749017a Merged r3062:3063 from branches/SDL-1.2: clear inaccurate x11dyn error strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 1950
diff changeset
   209
        } else {
2120
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2118
diff changeset
   210
            /* in case something got loaded... */
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2118
diff changeset
   211
            SDL_X11_UnloadSymbols();
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   212
            rc = 0;
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   213
        }
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   214
    }
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   215
#else
6898
d0159180a95f Fixed bug where if X11 is not dynamically loaded, then we think none of the X11 modules are available.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   216
#define SDL_X11_MODULE(modname) SDL_X11_HAVE_##modname = 1; /* default yes */
d0159180a95f Fixed bug where if X11 is not dynamically loaded, then we think none of the X11 modules are available.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   217
#define SDL_X11_SYM(a,fn,x,y,z)
d0159180a95f Fixed bug where if X11 is not dynamically loaded, then we think none of the X11 modules are available.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   218
#include "SDL_x11sym.h"
d0159180a95f Fixed bug where if X11 is not dynamically loaded, then we think none of the X11 modules are available.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   219
#undef SDL_X11_MODULE
d0159180a95f Fixed bug where if X11 is not dynamically loaded, then we think none of the X11 modules are available.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   220
#undef SDL_X11_SYM
d0159180a95f Fixed bug where if X11 is not dynamically loaded, then we think none of the X11 modules are available.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   221
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   222
#ifdef X_HAVE_UTF8_STRING
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   223
    pXCreateIC = XCreateIC;
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: 2120
diff changeset
   224
    pXGetICValues = XGetICValues;
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   225
#endif
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   226
#endif
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   227
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   228
    return rc;
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   229
}
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   230
5481
22dfc3958dc3 Fixed so code will compile with SDL_config_minimal.h
Sam Lantinga <slouken@libsdl.org>
parents: 5471
diff changeset
   231
#endif /* SDL_VIDEO_DRIVER_X11 */
22dfc3958dc3 Fixed so code will compile with SDL_config_minimal.h
Sam Lantinga <slouken@libsdl.org>
parents: 5471
diff changeset
   232
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   233
/* vi: set ts=4 sw=4 expandtab: */