From f5e4b9205fbd77329b418073296b1cecbd1d3ee2 Mon Sep 17 00:00:00 2001 From: Peter Veenstra Date: Tue, 11 Dec 2018 15:45:37 +0000 Subject: [PATCH] Add workaround for the problem of locking the mouse in windowed mode with X.org 1.20.1. (thanks to DosFreak and ny00123 for their help with testing and debugging) Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@4177 --- src/gui/sdlmain.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/gui/sdlmain.cpp b/src/gui/sdlmain.cpp index 251bdb12..05eecfbb 100644 --- a/src/gui/sdlmain.cpp +++ b/src/gui/sdlmain.cpp @@ -1522,6 +1522,12 @@ bool GFX_IsFullscreen(void) { #define DB_POLLSKIP 1 #endif +#if defined(LINUX) +#define SDL_XORG_FIX 1 +#else +#define SDL_XORG_FIX 0 +#endif + void GFX_Events() { //Don't poll too often. This can be heavy on the OS, especially Macs. //In idle mode 3000-4000 polls are done per second without this check. @@ -1545,6 +1551,19 @@ void GFX_Events() { } #endif while (SDL_PollEvent(&event)) { +#if SDL_XORG_FIX + // Special code for broken SDL with Xorg 1.20.1, where pairs of inputfocus gain and loss events are generated + // when locking the mouse in windowed mode. + if (event.type == SDL_ACTIVEEVENT && event.active.state == SDL_APPINPUTFOCUS && event.active.gain == 0) { + SDL_Event test; //Check if the next event would undo this one. + if (SDL_PeepEvents(&test,1,SDL_PEEKEVENT,SDL_ACTIVEEVENTMASK) == 1 && test.active.state == SDL_APPINPUTFOCUS && test.active.gain == 1) { + // Skip both events. + SDL_PeepEvents(&test,1,SDL_GETEVENT,SDL_ACTIVEEVENTMASK); + continue; + } + } +#endif + switch (event.type) { case SDL_ACTIVEEVENT: if (event.active.state & SDL_APPINPUTFOCUS) {