Atlas - SDL_x11dyn.c
Home / ext / SDL / src / video / x11 Lines: 3 | Size: 7652 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)][FILE BEGIN]1/* 2 Simple DirectMedia Layer 3 Copyright (C) 1997-2025 Sam Lantinga <[email protected]> 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 35typedef struct 36{ 37 SDL_SharedObject *lib; 38 const char *libname; 39} x11dynlib; 40 41SDL_ELF_NOTE_DLOPEN( 42 "x11", 43 "Support for video through X11 backend", 44 SDL_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED, 45 SDL_VIDEO_DRIVER_X11_DYNAMIC 46) 47 48#ifdef SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT 49SDL_ELF_NOTE_DLOPEN( 50 "x11", 51 "Support for video through X11 backend", 52 SDL_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED, 53 SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT 54) 55#else 56#define SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT NULL 57#endif 58 59#ifdef SDL_VIDEO_DRIVER_X11_DYNAMIC_XCURSOR 60SDL_ELF_NOTE_DLOPEN( 61 "x11", 62 "Support for video through X11 backend", 63 SDL_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED, 64 SDL_VIDEO_DRIVER_X11_DYNAMIC_XCURSOR 65) 66#else 67#define SDL_VIDEO_DRIVER_X11_DYNAMIC_XCURSOR NULL 68#endif 69 70#ifdef SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT2 71SDL_ELF_NOTE_DLOPEN( 72 "x11", 73 "Support for video through X11 backend", 74 SDL_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED, 75 SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT2 76) 77#else 78#define SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT2 NULL 79#endif 80 81#ifdef SDL_VIDEO_DRIVER_X11_DYNAMIC_XFIXES 82SDL_ELF_NOTE_DLOPEN( 83 "x11", 84 "Support for video through X11 backend", 85 SDL_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED, 86 SDL_VIDEO_DRIVER_X11_DYNAMIC_XFIXES 87) 88#else 89#define SDL_VIDEO_DRIVER_X11_DYNAMIC_XFIXES NULL 90#endif 91 92#ifdef SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR 93SDL_ELF_NOTE_DLOPEN( 94 "x11", 95 "Support for video through X11 backend", 96 SDL_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED, 97 SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR 98) 99#else 100#define SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR NULL 101#endif 102 103#ifdef SDL_VIDEO_DRIVER_X11_DYNAMIC_XSS 104SDL_ELF_NOTE_DLOPEN( 105 "x11", 106 "Support for video through X11 backend", 107 SDL_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED, 108 SDL_VIDEO_DRIVER_X11_DYNAMIC_XSS 109) 110#else 111#define SDL_VIDEO_DRIVER_X11_DYNAMIC_XSS NULL 112#endif 113 114#ifdef SDL_VIDEO_DRIVER_X11_DYNAMIC_XTEST 115SDL_ELF_NOTE_DLOPEN( 116 "x11", 117 "Support for video through X11 backend", 118 SDL_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED, 119 SDL_VIDEO_DRIVER_X11_DYNAMIC_XTEST 120) 121#else 122#define SDL_VIDEO_DRIVER_X11_DYNAMIC_XTEST NULL 123#endif 124 125static x11dynlib x11libs[] = { 126 { NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC }, 127 { NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT }, 128 { NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XCURSOR }, 129 { NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT2 }, 130 { NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XFIXES }, 131 { NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR }, 132 { NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XSS }, 133 { NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XTEST } 134}; 135 136static void *X11_GetSym(const char *fnname, int *pHasModule) 137{ 138 int i; 139 void *fn = NULL; 140 for (i = 0; i < SDL_arraysize(x11libs); i++) { 141 if (x11libs[i].lib) { 142 fn = SDL_LoadFunction(x11libs[i].lib, fnname); 143 if (fn) { 144 break; 145 } 146 } 147 } 148 149#if DEBUG_DYNAMIC_X11 150 if (fn) 151 printf("X11: Found '%s' in %s (%p)\n", fnname, x11libs[i].libname, fn); 152 else 153 printf("X11: Symbol '%s' NOT FOUND!\n", fnname); 154#endif 155 156 if (!fn) { 157 *pHasModule = 0; // kill this module. 158 } 159 160 return fn; 161} 162 163#endif // SDL_VIDEO_DRIVER_X11_DYNAMIC 164 165// Define all the function pointers and wrappers... 166#define SDL_X11_SYM(rc, fn, params) SDL_DYNX11FN_##fn X11_##fn = NULL; 167#include "SDL_x11sym.h" 168 169/* These SDL_X11_HAVE_* flags are here whether you have dynamic X11 or not. */ 170#define SDL_X11_MODULE(modname) int SDL_X11_HAVE_##modname = 0; 171#include "SDL_x11sym.h" 172 173static int x11_load_refcount = 0; 174 175void SDL_X11_UnloadSymbols(void) 176{ 177 // Don't actually unload if more than one module is using the libs... 178 if (x11_load_refcount > 0) { 179 if (--x11_load_refcount == 0) { 180#ifdef SDL_VIDEO_DRIVER_X11_DYNAMIC 181 int i; 182#endif 183 184 // set all the function pointers to NULL. 185#define SDL_X11_MODULE(modname) SDL_X11_HAVE_##modname = 0; 186#define SDL_X11_SYM(rc, fn, params) X11_##fn = NULL; 187#include "SDL_x11sym.h" 188 189#ifdef X_HAVE_UTF8_STRING 190 X11_XCreateIC = NULL; 191 X11_XGetICValues = NULL; 192 X11_XSetICValues = NULL; 193 X11_XVaCreateNestedList = NULL; 194#endif 195 196#ifdef SDL_VIDEO_DRIVER_X11_DYNAMIC 197 for (i = 0; i < SDL_arraysize(x11libs); i++) { 198 if (x11libs[i].lib) { 199 SDL_UnloadObject(x11libs[i].lib); 200 x11libs[i].lib = NULL; 201 } 202 } 203#endif 204 } 205 } 206} 207 208// returns non-zero if all needed symbols were loaded. 209bool SDL_X11_LoadSymbols(void) 210{ 211 bool result = true; // always succeed if not using Dynamic X11 stuff. 212 213 // deal with multiple modules (dga, x11, etc) needing these symbols... 214 if (x11_load_refcount++ == 0) { 215#ifdef SDL_VIDEO_DRIVER_X11_DYNAMIC 216 int i; 217 int *thismod = NULL; 218 for (i = 0; i < SDL_arraysize(x11libs); i++) { 219 if (x11libs[i].libname) { 220 x11libs[i].lib = SDL_LoadObject(x11libs[i].libname); 221 } 222 } 223 224#define SDL_X11_MODULE(modname) SDL_X11_HAVE_##modname = 1; // default yes 225#include "SDL_x11sym.h" 226 227#define SDL_X11_MODULE(modname) thismod = &SDL_X11_HAVE_##modname; 228#define SDL_X11_SYM(rc, fn, params) X11_##fn = (SDL_DYNX11FN_##fn)X11_GetSym(#fn, thismod); 229#include "SDL_x11sym.h" 230 231#ifdef X_HAVE_UTF8_STRING 232 X11_XCreateIC = (SDL_DYNX11FN_XCreateIC) 233 X11_GetSym("XCreateIC", &SDL_X11_HAVE_UTF8); 234 X11_XGetICValues = (SDL_DYNX11FN_XGetICValues) 235 X11_GetSym("XGetICValues", &SDL_X11_HAVE_UTF8); 236 X11_XSetICValues = (SDL_DYNX11FN_XSetICValues) 237 X11_GetSym("XSetICValues", &SDL_X11_HAVE_UTF8); 238 X11_XVaCreateNestedList = (SDL_DYNX11FN_XVaCreateNestedList) 239 X11_GetSym("XVaCreateNestedList", &SDL_X11_HAVE_UTF8); 240#endif 241 242 if (SDL_X11_HAVE_BASEXLIB) { 243 // all required symbols loaded. 244 SDL_ClearError(); 245 } else { 246 // in case something got loaded... 247 SDL_X11_UnloadSymbols(); 248 result = false; 249 } 250 251#else // no dynamic X11 252 253#define SDL_X11_MODULE(modname) SDL_X11_HAVE_##modname = 1; // default yes 254#define SDL_X11_SYM(rc, fn, params) X11_##fn = (SDL_DYNX11FN_##fn)fn; 255#include "SDL_x11sym.h" 256 257#ifdef X_HAVE_UTF8_STRING 258 X11_XCreateIC = XCreateIC; 259 X11_XGetICValues = XGetICValues; 260 X11_XSetICValues = XSetICValues; 261 X11_XVaCreateNestedList = XVaCreateNestedList; 262#endif 263#endif 264 } 265 266 return result; 267} 268 269#endif // SDL_VIDEO_DRIVER_X11 270[FILE END](C) 2025 0x4248 (C) 2025 4248 Media and 4248 Systems, All part of 0x4248 See LICENCE files for more information. Not all files are by 0x4248 always check Licencing.