diff options
| author | 3gg <3gg@shellblade.net> | 2025-12-27 12:03:39 -0800 |
|---|---|---|
| committer | 3gg <3gg@shellblade.net> | 2025-12-27 12:03:39 -0800 |
| commit | 5a079a2d114f96d4847d1ee305d5b7c16eeec50e (patch) | |
| tree | 8926ab44f168acf787d8e19608857b3af0f82758 /contrib/SDL-3.2.8/src/video/x11/SDL_x11dyn.c | |
Initial commit
Diffstat (limited to 'contrib/SDL-3.2.8/src/video/x11/SDL_x11dyn.c')
| -rw-r--r-- | contrib/SDL-3.2.8/src/video/x11/SDL_x11dyn.c | 211 |
1 files changed, 211 insertions, 0 deletions
diff --git a/contrib/SDL-3.2.8/src/video/x11/SDL_x11dyn.c b/contrib/SDL-3.2.8/src/video/x11/SDL_x11dyn.c new file mode 100644 index 0000000..7c48ed5 --- /dev/null +++ b/contrib/SDL-3.2.8/src/video/x11/SDL_x11dyn.c | |||
| @@ -0,0 +1,211 @@ | |||
| 1 | /* | ||
| 2 | Simple DirectMedia Layer | ||
| 3 | Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org> | ||
| 4 | |||
| 5 | This software is provided 'as-is', without any express or implied | ||
| 6 | warranty. In no event will the authors be held liable for any damages | ||
| 7 | arising from the use of this software. | ||
| 8 | |||
| 9 | Permission is granted to anyone to use this software for any purpose, | ||
| 10 | including commercial applications, and to alter it and redistribute it | ||
| 11 | freely, subject to the following restrictions: | ||
| 12 | |||
| 13 | 1. The origin of this software must not be misrepresented; you must not | ||
| 14 | claim that you wrote the original software. If you use this software | ||
| 15 | in a product, an acknowledgment in the product documentation would be | ||
| 16 | appreciated but is not required. | ||
| 17 | 2. Altered source versions must be plainly marked as such, and must not be | ||
| 18 | misrepresented as being the original software. | ||
| 19 | 3. This notice may not be removed or altered from any source distribution. | ||
| 20 | */ | ||
| 21 | #include "SDL_internal.h" | ||
| 22 | |||
| 23 | #ifdef SDL_VIDEO_DRIVER_X11 | ||
| 24 | |||
| 25 | #define DEBUG_DYNAMIC_X11 0 | ||
| 26 | |||
| 27 | #include "SDL_x11dyn.h" | ||
| 28 | |||
| 29 | #if DEBUG_DYNAMIC_X11 | ||
| 30 | #include <stdio.h> | ||
| 31 | #endif | ||
| 32 | |||
| 33 | #ifdef SDL_VIDEO_DRIVER_X11_DYNAMIC | ||
| 34 | |||
| 35 | typedef struct | ||
| 36 | { | ||
| 37 | SDL_SharedObject *lib; | ||
| 38 | const char *libname; | ||
| 39 | } x11dynlib; | ||
| 40 | |||
| 41 | #ifndef SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT | ||
| 42 | #define SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT NULL | ||
| 43 | #endif | ||
| 44 | #ifndef SDL_VIDEO_DRIVER_X11_DYNAMIC_XCURSOR | ||
| 45 | #define SDL_VIDEO_DRIVER_X11_DYNAMIC_XCURSOR NULL | ||
| 46 | #endif | ||
| 47 | #ifndef SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT2 | ||
| 48 | #define SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT2 NULL | ||
| 49 | #endif | ||
| 50 | #ifndef SDL_VIDEO_DRIVER_X11_DYNAMIC_XFIXES | ||
| 51 | #define SDL_VIDEO_DRIVER_X11_DYNAMIC_XFIXES NULL | ||
| 52 | #endif | ||
| 53 | #ifndef SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR | ||
| 54 | #define SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR NULL | ||
| 55 | #endif | ||
| 56 | #ifndef SDL_VIDEO_DRIVER_X11_DYNAMIC_XSS | ||
| 57 | #define SDL_VIDEO_DRIVER_X11_DYNAMIC_XSS NULL | ||
| 58 | #endif | ||
| 59 | |||
| 60 | static x11dynlib x11libs[] = { | ||
| 61 | { NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC }, | ||
| 62 | { NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT }, | ||
| 63 | { NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XCURSOR }, | ||
| 64 | { NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT2 }, | ||
| 65 | { NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XFIXES }, | ||
| 66 | { NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR }, | ||
| 67 | { NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XSS } | ||
| 68 | }; | ||
| 69 | |||
| 70 | static void *X11_GetSym(const char *fnname, int *pHasModule) | ||
| 71 | { | ||
| 72 | int i; | ||
| 73 | void *fn = NULL; | ||
| 74 | for (i = 0; i < SDL_arraysize(x11libs); i++) { | ||
| 75 | if (x11libs[i].lib) { | ||
| 76 | fn = SDL_LoadFunction(x11libs[i].lib, fnname); | ||
| 77 | if (fn) { | ||
| 78 | break; | ||
| 79 | } | ||
| 80 | } | ||
| 81 | } | ||
| 82 | |||
| 83 | #if DEBUG_DYNAMIC_X11 | ||
| 84 | if (fn) | ||
| 85 | printf("X11: Found '%s' in %s (%p)\n", fnname, x11libs[i].libname, fn); | ||
| 86 | else | ||
| 87 | printf("X11: Symbol '%s' NOT FOUND!\n", fnname); | ||
| 88 | #endif | ||
| 89 | |||
| 90 | if (!fn) { | ||
| 91 | *pHasModule = 0; // kill this module. | ||
| 92 | } | ||
| 93 | |||
| 94 | return fn; | ||
| 95 | } | ||
| 96 | |||
| 97 | #endif // SDL_VIDEO_DRIVER_X11_DYNAMIC | ||
| 98 | |||
| 99 | // Define all the function pointers and wrappers... | ||
| 100 | #define SDL_X11_SYM(rc, fn, params, args, ret) SDL_DYNX11FN_##fn X11_##fn = NULL; | ||
| 101 | #include "SDL_x11sym.h" | ||
| 102 | |||
| 103 | // Annoying varargs entry point... | ||
| 104 | #ifdef X_HAVE_UTF8_STRING | ||
| 105 | SDL_DYNX11FN_XCreateIC X11_XCreateIC = NULL; | ||
| 106 | SDL_DYNX11FN_XGetICValues X11_XGetICValues = NULL; | ||
| 107 | SDL_DYNX11FN_XSetICValues X11_XSetICValues = NULL; | ||
| 108 | SDL_DYNX11FN_XVaCreateNestedList X11_XVaCreateNestedList = NULL; | ||
| 109 | #endif | ||
| 110 | |||
| 111 | /* These SDL_X11_HAVE_* flags are here whether you have dynamic X11 or not. */ | ||
| 112 | #define SDL_X11_MODULE(modname) int SDL_X11_HAVE_##modname = 0; | ||
| 113 | #include "SDL_x11sym.h" | ||
| 114 | |||
| 115 | static int x11_load_refcount = 0; | ||
| 116 | |||
| 117 | void SDL_X11_UnloadSymbols(void) | ||
| 118 | { | ||
| 119 | // Don't actually unload if more than one module is using the libs... | ||
| 120 | if (x11_load_refcount > 0) { | ||
| 121 | if (--x11_load_refcount == 0) { | ||
| 122 | #ifdef SDL_VIDEO_DRIVER_X11_DYNAMIC | ||
| 123 | int i; | ||
| 124 | #endif | ||
| 125 | |||
| 126 | // set all the function pointers to NULL. | ||
| 127 | #define SDL_X11_MODULE(modname) SDL_X11_HAVE_##modname = 0; | ||
| 128 | #define SDL_X11_SYM(rc, fn, params, args, ret) X11_##fn = NULL; | ||
| 129 | #include "SDL_x11sym.h" | ||
| 130 | |||
| 131 | #ifdef X_HAVE_UTF8_STRING | ||
| 132 | X11_XCreateIC = NULL; | ||
| 133 | X11_XGetICValues = NULL; | ||
| 134 | X11_XSetICValues = NULL; | ||
| 135 | X11_XVaCreateNestedList = NULL; | ||
| 136 | #endif | ||
| 137 | |||
| 138 | #ifdef SDL_VIDEO_DRIVER_X11_DYNAMIC | ||
| 139 | for (i = 0; i < SDL_arraysize(x11libs); i++) { | ||
| 140 | if (x11libs[i].lib) { | ||
| 141 | SDL_UnloadObject(x11libs[i].lib); | ||
| 142 | x11libs[i].lib = NULL; | ||
| 143 | } | ||
| 144 | } | ||
| 145 | #endif | ||
| 146 | } | ||
| 147 | } | ||
| 148 | } | ||
| 149 | |||
| 150 | // returns non-zero if all needed symbols were loaded. | ||
| 151 | bool SDL_X11_LoadSymbols(void) | ||
| 152 | { | ||
| 153 | bool result = true; // always succeed if not using Dynamic X11 stuff. | ||
| 154 | |||
| 155 | // deal with multiple modules (dga, x11, etc) needing these symbols... | ||
| 156 | if (x11_load_refcount++ == 0) { | ||
| 157 | #ifdef SDL_VIDEO_DRIVER_X11_DYNAMIC | ||
| 158 | int i; | ||
| 159 | int *thismod = NULL; | ||
| 160 | for (i = 0; i < SDL_arraysize(x11libs); i++) { | ||
| 161 | if (x11libs[i].libname) { | ||
| 162 | x11libs[i].lib = SDL_LoadObject(x11libs[i].libname); | ||
| 163 | } | ||
| 164 | } | ||
| 165 | |||
| 166 | #define SDL_X11_MODULE(modname) SDL_X11_HAVE_##modname = 1; // default yes | ||
| 167 | #include "SDL_x11sym.h" | ||
| 168 | |||
| 169 | #define SDL_X11_MODULE(modname) thismod = &SDL_X11_HAVE_##modname; | ||
| 170 | #define SDL_X11_SYM(a, fn, x, y, z) X11_##fn = (SDL_DYNX11FN_##fn)X11_GetSym(#fn, thismod); | ||
| 171 | #include "SDL_x11sym.h" | ||
| 172 | |||
| 173 | #ifdef X_HAVE_UTF8_STRING | ||
| 174 | X11_XCreateIC = (SDL_DYNX11FN_XCreateIC) | ||
| 175 | X11_GetSym("XCreateIC", &SDL_X11_HAVE_UTF8); | ||
| 176 | X11_XGetICValues = (SDL_DYNX11FN_XGetICValues) | ||
| 177 | X11_GetSym("XGetICValues", &SDL_X11_HAVE_UTF8); | ||
| 178 | X11_XSetICValues = (SDL_DYNX11FN_XSetICValues) | ||
| 179 | X11_GetSym("XSetICValues", &SDL_X11_HAVE_UTF8); | ||
| 180 | X11_XVaCreateNestedList = (SDL_DYNX11FN_XVaCreateNestedList) | ||
| 181 | X11_GetSym("XVaCreateNestedList", &SDL_X11_HAVE_UTF8); | ||
| 182 | #endif | ||
| 183 | |||
| 184 | if (SDL_X11_HAVE_BASEXLIB) { | ||
| 185 | // all required symbols loaded. | ||
| 186 | SDL_ClearError(); | ||
| 187 | } else { | ||
| 188 | // in case something got loaded... | ||
| 189 | SDL_X11_UnloadSymbols(); | ||
| 190 | result = false; | ||
| 191 | } | ||
| 192 | |||
| 193 | #else // no dynamic X11 | ||
| 194 | |||
| 195 | #define SDL_X11_MODULE(modname) SDL_X11_HAVE_##modname = 1; // default yes | ||
| 196 | #define SDL_X11_SYM(a, fn, x, y, z) X11_##fn = (SDL_DYNX11FN_##fn)fn; | ||
| 197 | #include "SDL_x11sym.h" | ||
| 198 | |||
| 199 | #ifdef X_HAVE_UTF8_STRING | ||
| 200 | X11_XCreateIC = XCreateIC; | ||
| 201 | X11_XGetICValues = XGetICValues; | ||
| 202 | X11_XSetICValues = XSetICValues; | ||
| 203 | X11_XVaCreateNestedList = XVaCreateNestedList; | ||
| 204 | #endif | ||
| 205 | #endif | ||
| 206 | } | ||
| 207 | |||
| 208 | return result; | ||
| 209 | } | ||
| 210 | |||
| 211 | #endif // SDL_VIDEO_DRIVER_X11 | ||
