23 #if SDL_VIDEO_DRIVER_X11
35 #include "../../events/SDL_events_c.h"
36 #include "../../events/SDL_mouse_c.h"
37 #include "../../events/SDL_touch_c.h"
53 static void X11_ReadProperty(SDL_x11Prop *
p, Display *disp, Window
w, Atom prop)
59 unsigned long bytes_left;
63 if (ret != 0) XFree(ret);
64 XGetWindowProperty(disp, w, prop, 0, bytes_fetch, False, AnyPropertyType, &type, &fmt, &count, &bytes_left, &ret);
65 bytes_fetch += bytes_left;
66 }
while (bytes_left != 0);
76 static Atom X11_PickTarget(Display *disp, Atom list[],
int list_count)
81 for (i=0; i < list_count && request == None; i++) {
82 name = XGetAtomName(disp, list[i]);
83 if (strcmp(
"text/uri-list", name)==0) request = list[
i];
91 static Atom X11_PickTargetFromAtoms(Display *disp, Atom a0, Atom a1, Atom a2)
95 if (a0 != None) atom[count++] = a0;
96 if (a1 != None) atom[count++] = a1;
97 if (a2 != None) atom[count++] = a2;
98 return X11_PickTarget(disp, atom, count);
102 struct KeyRepeatCheckData
108 static Bool X11_KeyRepeatCheckIfEvent(Display *
display, XEvent *chkev,
111 struct KeyRepeatCheckData *
d = (
struct KeyRepeatCheckData *) arg;
112 if (chkev->type == KeyPress &&
113 chkev->xkey.keycode == d->event->xkey.keycode &&
114 chkev->xkey.time - d->event->xkey.time < 2)
122 static SDL_bool X11_KeyRepeat(Display *display, XEvent *
event)
125 struct KeyRepeatCheckData d;
128 if (XPending(display))
134 static Bool X11_IsWheelCheckIfEvent(Display *display, XEvent *chkev,
137 XEvent *
event = (XEvent *) arg;
139 if (chkev->type == ButtonRelease &&
140 (event->xbutton.button == Button4 || event->xbutton.button == Button5) &&
141 chkev->xbutton.button ==
event->xbutton.button &&
142 chkev->xbutton.time ==
event->xbutton.time)
147 static SDL_bool X11_IsWheelEvent(Display * display,XEvent * event,
int * ticks)
150 if (XPending(display)) {
161 if (
XCheckIfEvent(display, &relevent, X11_IsWheelCheckIfEvent,
166 if (event->xbutton.button == Button4) {
169 else if (event->xbutton.button == Button5) {
181 static char* X11_URIToLocal(
char* uri) {
185 if (memcmp(uri,
"file:/",6) == 0) uri += 6;
186 else if (strstr(uri,
":/") !=
NULL)
return file;
188 local = uri[0] !=
'/' || ( uri[0] !=
'\0' && uri[1] ==
'/' );
191 if ( !local && uri[0] ==
'/' && uri[2] !=
'/' ) {
192 char* hostname_end = strchr( uri+1,
'/' );
193 if ( hostname_end !=
NULL ) {
194 char hostname[ 257 ];
195 if ( gethostname( hostname, 255 ) == 0 ) {
196 hostname[ 256 ] =
'\0';
197 if ( memcmp( uri+1, hostname, hostname_end - ( uri+1 )) == 0 ) {
198 uri = hostname_end + 1;
206 if ( uri[1] ==
'/' ) {
215 #if SDL_VIDEO_DRIVER_X11_SUPPORTS_GENERIC_EVENTS
216 static void X11_HandleGenericEvent(
SDL_VideoData *videodata,XEvent event)
220 if (XGetEventData(videodata->
display, cookie)) {
222 XFreeEventData(videodata->
display, cookie);
232 printf(
"window %p: Dispatching FocusIn\n", data);
235 #ifdef X_HAVE_UTF8_STRING
237 XSetICFocus(data->
ic);
246 printf(
"window %p: Dispatching FocusOut\n", data);
249 #ifdef X_HAVE_UTF8_STRING
251 XUnsetICFocus(data->
ic);
271 X11_DispatchEvent(
_THIS)
274 Display *display = videodata->
display;
278 XClientMessageEvent
m;
281 XNextEvent(display, &xevent);
285 if (XFilterEvent(&xevent, None) == True) {
287 printf(
"Filtered event type = %d display = %d window = %d\n",
288 xevent.type, xevent.xany.display, xevent.xany.window);
299 wmmsg.
msg.x11.event = xevent;
303 #if SDL_VIDEO_DRIVER_X11_SUPPORTS_GENERIC_EVENTS
304 if(xevent.type == GenericEvent) {
305 X11_HandleGenericEvent(videodata,xevent);
311 printf(
"type = %d display = %d window = %d\n",
312 xevent.type, xevent.xany.display, xevent.xany.window);
329 switch (xevent.type) {
334 printf(
"window %p: EnterNotify! (%d,%d,%d)\n", data,
337 xevent.xcrossing.mode);
338 if (xevent.xcrossing.mode == NotifyGrab)
339 printf(
"Mode: NotifyGrab\n");
340 if (xevent.xcrossing.mode == NotifyUngrab)
341 printf(
"Mode: NotifyUngrab\n");
353 printf(
"window %p: LeaveNotify! (%d,%d,%d)\n", data,
356 xevent.xcrossing.mode);
357 if (xevent.xcrossing.mode == NotifyGrab)
358 printf(
"Mode: NotifyGrab\n");
359 if (xevent.xcrossing.mode == NotifyUngrab)
360 printf(
"Mode: NotifyUngrab\n");
366 if (xevent.xcrossing.mode != NotifyGrab &&
367 xevent.xcrossing.mode != NotifyUngrab &&
368 xevent.xcrossing.detail != NotifyInferior) {
376 if (xevent.xfocus.detail == NotifyInferior) {
378 printf(
"window %p: FocusIn (NotifierInferior, ignoring)\n", data);
383 printf(
"window %p: FocusIn!\n", data);
405 if (xevent.xfocus.detail == NotifyInferior) {
408 printf(
"window %p: FocusOut (NotifierInferior, ignoring)\n", data);
413 printf(
"window %p: FocusOut!\n", data);
423 printf(
"window %p: KeymapNotify!\n", data);
434 printf(
"window %p: MappingNotify!\n", data);
442 KeyCode keycode = xevent.xkey.keycode;
443 KeySym keysym = NoSymbol;
448 printf(
"window %p: KeyPress (X11 keycode = 0x%X)\n", data, xevent.xkey.keycode);
453 int min_keycode, max_keycode;
454 XDisplayKeycodes(display, &min_keycode, &max_keycode);
455 #if SDL_VIDEO_DRIVER_X11_HAS_XKBKEYCODETOKEYSYM
456 keysym = XkbKeycodeToKeysym(display, keycode, 0, 0);
458 keysym = XKeycodeToKeysym(display, keycode, 0);
461 "The key you just pressed is not recognized by SDL. To help get this fixed, please report this to the SDL mailing list <sdl@libsdl.org> X11 KeyCode %d (%d), X11 KeySym 0x%lX (%s).\n",
462 keycode, keycode - min_keycode, keysym,
468 #ifdef X_HAVE_UTF8_STRING
470 Xutf8LookupString(data->
ic, &xevent.xkey, text,
sizeof(text),
484 KeyCode keycode = xevent.xkey.keycode;
487 printf(
"window %p: KeyRelease (X11 keycode = 0x%X)\n", data, xevent.xkey.keycode);
489 if (X11_KeyRepeat(display, &xevent)) {
500 printf(
"window %p: UnmapNotify!\n", data);
502 X11_DispatchUnmapNotify(data);
509 printf(
"window %p: MapNotify!\n", data);
511 X11_DispatchMapNotify(data);
516 case ConfigureNotify:{
518 printf(
"window %p: ConfigureNotify! (position: %d,%d, size: %dx%d)\n", data,
519 xevent.xconfigure.x, xevent.xconfigure.y,
520 xevent.xconfigure.width, xevent.xconfigure.height);
525 xevent.xconfigure.x, xevent.xconfigure.y);
530 xevent.xconfigure.width,
531 xevent.xconfigure.height);
542 if (xevent.xclient.message_type == videodata->
XdndEnter) {
543 SDL_bool use_list = xevent.xclient.data.l[1] & 1;
545 xdnd_version = ( xevent.xclient.data.l[1] >> 24);
551 data->
xdnd_req = X11_PickTarget(display, (Atom*)p.data, p.count);
555 data->
xdnd_req = X11_PickTargetFromAtoms(display, xevent.xclient.data.l[2], xevent.xclient.data.l[3], xevent.xclient.data.l[4]);
558 else if (xevent.xclient.message_type == videodata->
XdndPosition) {
561 memset(&
m, 0,
sizeof(XClientMessageEvent));
562 m.type = ClientMessage;
563 m.display = xevent.xclient.display;
564 m.window = xevent.xclient.data.l[0];
573 XSendEvent(display, xevent.xclient.data.l[0], False, NoEventMask, (XEvent*)&
m);
576 else if(xevent.xclient.message_type == videodata->
XdndDrop) {
579 memset(&
m, 0,
sizeof(XClientMessageEvent));
580 m.type = ClientMessage;
581 m.display = xevent.xclient.display;
582 m.window = xevent.xclient.data.l[0];
588 XSendEvent(display, xevent.xclient.data.l[0], False, NoEventMask, (XEvent*)&
m);
591 if(xdnd_version >= 1) {
598 else if ((xevent.xclient.message_type == videodata->
WM_PROTOCOLS) &&
599 (xevent.xclient.format == 32) &&
600 (xevent.xclient.data.l[0] == videodata->
_NET_WM_PING)) {
601 Window root = DefaultRootWindow(display);
604 printf(
"window %p: _NET_WM_PING\n", data);
606 xevent.xclient.window = root;
607 XSendEvent(display, root, False, SubstructureRedirectMask | SubstructureNotifyMask, &xevent);
611 else if ((xevent.xclient.message_type == videodata->
WM_PROTOCOLS) &&
612 (xevent.xclient.format == 32) &&
616 printf(
"window %p: WM_DELETE_WINDOW\n", data);
627 printf(
"window %p: Expose (count = %d)\n", data, xevent.xexpose.count);
637 printf(
"window %p: X11 motion: %d,%d\n", xevent.xmotion.x, xevent.xmotion.y);
647 if (X11_IsWheelEvent(display,&xevent,&ticks)) {
660 case PropertyNotify:{
662 unsigned char *propdata;
663 int status, real_format;
665 unsigned long items_read, items_left,
i;
667 char *name = XGetAtomName(display, xevent.xproperty.atom);
669 printf(
"window %p: PropertyNotify: %s %s\n", data, name, (xevent.xproperty.state == PropertyDelete) ?
"deleted" :
"changed");
673 status = XGetWindowProperty(display, data->
xwindow, xevent.xproperty.atom, 0L, 8192L, False, AnyPropertyType, &real_type, &real_format, &items_read, &items_left, &propdata);
674 if (status == Success && items_read > 0) {
675 if (real_type == XA_INTEGER) {
676 int *
values = (
int *)propdata;
679 for (i = 0; i < items_read; i++) {
680 printf(
" %d", values[i]);
683 }
else if (real_type == XA_CARDINAL) {
684 if (real_format == 32) {
688 for (i = 0; i < items_read; i++) {
689 printf(
" %d", values[i]);
692 }
else if (real_format == 16) {
696 for (i = 0; i < items_read; i++) {
697 printf(
" %d", values[i]);
700 }
else if (real_format == 8) {
704 for (i = 0; i < items_read; i++) {
705 printf(
" %d", values[i]);
709 }
else if (real_type == XA_STRING ||
711 printf(
"{ \"%s\" }\n", propdata);
712 }
else if (real_type == XA_ATOM) {
713 Atom *atoms = (Atom *)propdata;
716 for (i = 0; i < items_read; i++) {
717 char *name = XGetAtomName(display, atoms[i]);
725 char *name = XGetAtomName(display, real_type);
726 printf(
"Unknown type: %ld (%s)\n", real_type, name ? name :
"UNKNOWN");
732 if (status == Success) {
745 if (flags & SDL_WINDOW_HIDDEN) {
746 X11_DispatchUnmapNotify(data);
748 X11_DispatchMapNotify(data);
756 case SelectionRequest: {
757 XSelectionRequestEvent *req;
760 unsigned long nbytes;
761 unsigned long overflow;
762 unsigned char *seln_data;
764 req = &xevent.xselectionrequest;
766 printf(
"window %p: SelectionRequest (requestor = %ld, target = %ld)\n", data,
767 req->requestor, req->target);
771 sevent.xany.type = SelectionNotify;
772 sevent.xselection.selection = req->selection;
773 sevent.xselection.target = None;
774 sevent.xselection.property = None;
775 sevent.xselection.requestor = req->requestor;
776 sevent.xselection.time = req->time;
777 if (XGetWindowProperty(display, DefaultRootWindow(display),
778 XA_CUT_BUFFER0, 0, INT_MAX/4, False, req->target,
779 &sevent.xselection.target, &seln_format, &nbytes,
780 &overflow, &seln_data) == Success) {
781 Atom XA_TARGETS =
XInternAtom(display,
"TARGETS", 0);
782 if (sevent.xselection.target == req->target) {
783 XChangeProperty(display, req->requestor, req->property,
784 sevent.xselection.target, seln_format, PropModeReplace,
786 sevent.xselection.property = req->property;
787 }
else if (XA_TARGETS == req->target) {
788 Atom SupportedFormats[] = { sevent.xselection.target, XA_TARGETS };
789 XChangeProperty(display, req->requestor, req->property,
790 XA_ATOM, 32, PropModeReplace,
791 (
unsigned char*)SupportedFormats,
792 sizeof(SupportedFormats)/
sizeof(*SupportedFormats));
793 sevent.xselection.property = req->property;
797 XSendEvent(display, req->requestor, False, 0, &sevent);
798 XSync(display, False);
802 case SelectionNotify: {
804 printf(
"window %p: SelectionNotify (requestor = %ld, target = %ld)\n", data,
805 xevent.xselection.requestor, xevent.xselection.target);
807 Atom
target = xevent.xselection.target;
816 char *scan = (
char*)p.data;
831 if (*scan == 0x0A &&
length > 0) {
835 fn = X11_URIToLocal(uri);
852 m.type = ClientMessage;
862 XSync(display, False);
872 printf(
"window %p: Unhandled event %d\n", data, xevent.type);
880 X11_HandleFocusChanges(
_THIS)
892 X11_DispatchFocusIn(data);
894 X11_DispatchFocusOut(data);
904 X11_Pending(Display * display)
908 if (XEventsQueued(display, QueuedAlready)) {
914 static struct timeval zero_time;
918 x11_fd = ConnectionNumber(display);
920 FD_SET(x11_fd, &fdset);
921 if (select(x11_fd + 1, &fdset,
NULL,
NULL, &zero_time) == 1) {
922 return (XPending(display));
932 int SDL_GetNumTouch(
void);
933 void SDL_dbus_screensaver_tickle(
_THIS);
945 XResetScreenSaver(data->
display);
948 SDL_dbus_screensaver_tickle(
_this);
956 while (X11_Pending(data->
display)) {
957 X11_DispatchEvent(
_this);
961 X11_HandleFocusChanges(
_this);
968 #if SDL_VIDEO_DRIVER_X11_XSCRNSAVER
971 int major_version, minor_version;
973 if (SDL_X11_HAVE_XSS) {
975 if (!XScreenSaverQueryExtension(data->
display, &dummy, &dummy) ||
976 !XScreenSaverQueryVersion(data->
display,
977 &major_version, &minor_version) ||
978 major_version < 1 || (major_version == 1 && minor_version < 1)) {
983 XResetScreenSaver(data->
display);
989 SDL_dbus_screensaver_tickle(
_this);
void X11_PumpEvents(_THIS)
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int int int return Display Window Cursor return Display Window return Display Drawable GC int int unsigned int unsigned int return Display Drawable GC int int _Xconst char int return Display Drawable GC int int unsigned int unsigned int return Display return Display Cursor return Display GC return XModifierKeymap return char Display Window int return Display return Display Atom return Display Window XWindowAttributes return Display Window return Display XEvent Bool(*) XPointer return Display Window Bool unsigned int int int Window Cursor Time return Display Window int return KeySym return Display _Xconst char Bool return Display _Xconst char retur XLookupString)
SDL_Mouse * SDL_GetMouse(void)
void SDL_SetKeyboardFocus(SDL_Window *window)
GLint GLenum GLsizei GLsizei GLsizei GLint GLenum GLenum type
Uint32 X11_GetNetWMState(_THIS, Window xwindow)
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int int int return Display Window Cursor return Display Window return Display Drawable GC int int unsigned int unsigned int return Display Drawable GC int int _Xconst char int return Display Drawable GC int int unsigned int unsigned int retur XFlush)
DECLSPEC void SDLCALL SDL_free(void *mem)
SDL_WindowData ** windowlist
EGLImageKHR EGLint * name
int SDL_SendWindowEvent(SDL_Window *window, Uint8 windowevent, int data1, int data2)
return Display return Display Bool Bool int d
void SDL_SetMouseFocus(SDL_Window *window)
SDL_bool selection_waiting
int SDL_SendSysWMEvent(SDL_SysWMmsg *message)
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int int int return Display Window Cursor return Display Window return Display Drawable GC int int unsigned int unsigned int return Display Drawable GC int int _Xconst char int return Display Drawable GC int int unsigned int unsigned int return Display return Display Cursor return Display GC return XModifierKeymap return char Display Window int return Display return Display Atom return Display Window XWindowAttributes return Display Window return Display XEvent Bool(*) XPointer return Display Window Bool unsigned int int int Window Cursor Time return Display Window int return KeySym return Display _Xconst char Bool return Display _Xconst char return XKeyEvent char int KeySym XComposeStatus return Display int int int XVisualInfo return Display Window int int return _Xconst char return Display XEvent return Display Drawable GC XImage int int int int unsigned int unsigned int return Display Window Window Window int int int int unsigned int return Display Window Window int int return Display Window unsigned int unsigned int retur XSendEvent)
int SDL_SendKeyboardKey(Uint8 state, SDL_Scancode scancode)
#define SDL_VERSION(x)
Macro to determine SDL version program was compiled against.
static SDL_VideoDevice * _this
EGLContext EGLenum target
uint32_t Uint32
An unsigned 32-bit integer type.
DECLSPEC Uint32 SDLCALL SDL_GetTicks(void)
Get the number of milliseconds since the SDL library initialization.
return Display return Display Bool Bool int int int return XCheckIfEvent
Uint32 screensaver_activity
Uint32 pending_focus_time
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int int int return Display Window Cursor return Display Window return Display Drawable GC int int unsigned int unsigned int return Display Drawable GC int int _Xconst char int return Display Drawable GC int int unsigned int unsigned int return Display return Display Cursor return Display GC return XModifierKeymap return char Display Window int return Display return Display Atom return Display Window XWindowAttributes return Display Window return Display XEvent Bool(*) XPointer return Display Window Bool unsigned int int int Window Cursor Time return Display Window int return KeySym retur XInternAtom)
#define SDL_GetEventState(type)
void X11_SuspendScreenSaver(_THIS)
int SDL_SendMouseMotion(SDL_Window *window, SDL_MouseID mouseID, int relative, int x, int y)
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
struct SDL_VideoData * videodata
int SDL_SendKeyboardText(const char *text)
DECLSPEC void *SDLCALL SDL_memset(void *dst, int c, size_t len)
union SDL_SysWMmsg::@77 msg
GLint GLenum GLsizei GLsizei GLsizei GLint GLenum format
DECLSPEC void *SDLCALL SDL_malloc(size_t size)
void X11_UpdateKeymap(_THIS)
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int int int return Display Window Cursor return Display Window return Display Drawable GC int int unsigned int unsigned int return Display Drawable GC int int _Xconst char int return Display Drawable GC int int unsigned int unsigned int return Display return Display Cursor return Display GC return XModifierKeymap return char Display Window int return Display return Display Atom return Display Window XWindowAttributes return Display Window return Display XEvent Bool(*) XPointer return Display Window Bool unsigned int int int Window Cursor Time return Display Window int retur XKeysymToString)
#define PENDING_FOCUS_IN_TIME
DECLSPEC void *SDLCALL SDL_memcpy(void *dst, const void *src, size_t len)
GLenum GLsizei GLsizei GLsizei GLsizei GLbitfield flags
uint8_t Uint8
An unsigned 8-bit integer type.
int SDL_SendDropFile(const char *file)
XConfigureEvent last_xconfigure
int SDL_SendMouseWheel(SDL_Window *window, SDL_MouseID mouseID, int x, int y)
SDL_bool suspend_screensaver
GLint GLint GLint GLint GLint w
uint16_t Uint16
An unsigned 16-bit integer type.
#define SDL_TEXTINPUTEVENT_TEXT_SIZE
DECLSPEC SDL_Window *SDLCALL SDL_GetKeyboardFocus(void)
Get the window which currently has keyboard focus.
PendingFocusEnum pending_focus
int SDL_SendMouseButton(SDL_Window *window, SDL_MouseID mouseID, Uint8 state, Uint8 button)
#define PENDING_FOCUS_OUT_TIME
GLint GLsizei const GLuint64 * values