void* get_xlib_handle() { void* ret_handle = NULL; char library[MAX_LIBRARY_PATH + 1]; const char * possible_locations[] = { "/usr/lib/libX11.so.6", //default_x11_location "/usr/lib/x86_64-linux-gnu/libX11.so.6", //debian_x11_location "/usr/lib/i386-linux-gnu/libX11.so.6", //ubuntu_32bit_x11_location "/usr/lib64/libX11.so.6", //opensuse_x11_location "/usr/lib32/libX11.so.6" }; int locations_len = sizeof(possible_locations) / sizeof(char*); uint16_t required_lib_arch; if (is_32bit_system() || is_emulated_32bit()) { required_lib_arch = EM_386; } else { required_lib_arch = EM_X86_64; } int suitable_xlib_index = find_xlib_by_arch(possible_locations, locations_len, required_lib_arch); int found_library = FALSE; if (suitable_xlib_index >= 0) { snprintf(library, MAX_LIBRARY_PATH, "%s", possible_locations[suitable_xlib_index]); found_library = TRUE; } else { found_library = find_xlib_by_env(library, required_lib_arch); } if (found_library == FALSE) { const char* desired_arch = (required_lib_arch == EM_386 ? "32-bit" : "64-bit"); fprintf(stderr, "None of the following is a %s version of Xlib:", desired_arch); int i; for (i = 0; i < locations_len; i++) { fprintf(stderr, " %s\n", possible_locations[i]); } return NULL; } ret_handle = dlopen(library, RTLD_LAZY); if (ret_handle == NULL) { fprintf(stderr, "Failed to dlopen %s\n", library); fprintf(stderr, "dlerror says: %s\n", dlerror()); } return ret_handle; }
void* get_xlib_handle() { void* ret_handle = NULL; char library[MAX_LIBRARY_PATH + 1]; // If we're not emulating a 32 bit mode (which is either native 32 bit // or native 64 bit) - use the ordinary path for libX11 if (is_emulated_32bit() == FALSE) { snprintf(library, MAX_LIBRARY_PATH, "/usr/lib/libX11.so.6"); } else { // Use a path that usually contains the 32 bit libs in a 64 bit system. snprintf(library, MAX_LIBRARY_PATH, "/usr/lib32/libX11.so.6"); } ret_handle = dlopen(library, RTLD_LAZY); if (ret_handle == NULL) { fprintf(stderr, "Failed to dlopen %s\n", library); fprintf(stderr, "dlerror says: %s\n", dlerror()); } return ret_handle; }
int XNextEvent(Display *display, XEvent *outEvent) { // Code to pull the real function handle from X11 library. void *handle = NULL; //This will turn the function proto into a function pointer declaration int (*real_func)(Display *display, XEvent *outEvent) = NULL; char library[MAX_LIBRARY_PATH + 1]; // If we're not emulating a 32 bit mode (which is either native 32 bit // or native 64 bit) - use the ordinary path for libX11 if (is_emulated_32bit() == FALSE) { snprintf(library, MAX_LIBRARY_PATH, "/usr/lib/libX11.so.6"); } else { // Use a path that usually contains the 32 bit libs in a 64 bit system. snprintf(library, MAX_LIBRARY_PATH, "/usr/lib32/libX11.so.6"); } handle = dlopen(library, RTLD_LAZY); if (handle == NULL) { fprintf(stderr, "Failed to dlopen %s\n", library); fprintf(stderr, "dlerror says: %s\n", dlerror()); return -1; } // The real event from XNextEvent XEvent realEvent; // Find the real function. real_func = dlsym(handle, "XNextEvent"); // Invoke the real function. int rf_ret = real_func(display, &realEvent); if (should_discard_event(&realEvent)) { // Fake an event! fake_visibility_event(outEvent, &realEvent); } else { *outEvent = realEvent; } return rf_ret; }