14 #ifdef SDL_VIDEO_DRIVER_X11
20 #ifndef __EMSCRIPTEN__
21 #include <SDL2/SDL_syswm.h>
23 #include <SDL_syswm.h>
26 #ifdef SDL_VIDEO_DRIVER_X11_XINPUT2
27 #include <X11/extensions/XInput2.h>
28 #endif // SDL_VIDEO_DRIVER_X11_XINPUT2
34 SDL_SysWMinfo sysinfo;
35 SDL_VERSION(&sysinfo.version);
36 if (!SDL_GetWindowWMInfo(window, &sysinfo))
38 cerr <<
"Error: unable to get window manager information for the "
39 <<
"current window." << endl;
42 if (sysinfo.subsystem != SDL_SYSWM_X11)
44 cerr <<
"Error: created SDL window is not an X11 window." << endl;
47 Display *disp = sysinfo.info.x11.display;
48 Window
wnd = sysinfo.info.x11.window;
50 display_fds.emplace(window, ConnectionNumber(disp));
52 #ifdef SDL_VIDEO_DRIVER_X11_XINPUT2
55 Window root_win = DefaultRootWindow(disp);
56 unsigned char mask[4] = {0,0,0,0};
57 XIEventMask event_mask;
58 event_mask.deviceid = XIAllMasterDevices;
59 event_mask.mask_len =
sizeof(mask);
60 event_mask.mask = mask;
61 #ifdef SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT2
62 const char Xi_lib[] = SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT2;
64 const char Xi_lib[] =
"libXi.so";
66 typedef int (*XISelectEvents_ptr)(Display *, Window, XIEventMask *, int);
67 XISelectEvents_ptr XISelectEvents_ = NULL;
68 void *lib = SDL_LoadObject(Xi_lib);
72 (XISelectEvents_ptr)SDL_LoadFunction(lib,
"XISelectEvents");
74 if (XISelectEvents_ == NULL)
76 cerr <<
"Error accessing XISelectEvents!" << endl;
79 if (XISelectEvents_(disp, root_win, &event_mask, 1) != Success)
81 cerr <<
"Failed to disable XInput on the default root window!" << endl;
83 if (XISelectEvents_(disp, wnd, &event_mask, 1) != Success)
85 cerr <<
"Failed to disable XInput on the current window!" << endl;
87 #ifndef SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT2
88 SDL_UnloadObject(lib);
90 #endif // SDL_VIDEO_DRIVER_X11_XINPUT2
95 display_fds.erase(window);
101 pfd.emplace_back( pollfd{ event_pfd[0], POLLIN, 0 } );
103 for (
auto wnd : display_fds)
106 pfd.emplace_back( pollfd{
wnd.second, POLLIN, 0 } );
114 nstr = poll(pfd.data(), pfd.size(), 500);
116 while (nstr == -1 && errno == EINTR);
118 if (nstr == -1) { perror(
"poll()"); }
125 n = read(event_pfd[0], buf.data(), buf.size());
130 #endif // SDL_VIDEO_DRIVER_X11
thread_local SdlWindow * wnd