From 17cee03cd164c2a33d106f376479d967aaeb2437 Mon Sep 17 00:00:00 2001 From: cutealien Date: Fri, 18 Dec 2009 12:37:25 +0000 Subject: [PATCH] ClearSystemMessages does now also just remove keyboard/mouse events on Linux. Should probably be parametrized in the long run. git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@3057 dfc29bdd-3216-0410-991c-e03cc46cb475 --- include/IrrlichtDevice.h | 4 ++-- source/Irrlicht/CIrrDeviceLinux.cpp | 22 ++++++++++++++++++---- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/include/IrrlichtDevice.h b/include/IrrlichtDevice.h index c2e0f093..5c003b5a 100644 --- a/include/IrrlichtDevice.h +++ b/include/IrrlichtDevice.h @@ -237,13 +237,13 @@ namespace irr virtual bool getGammaRamp(f32 &red, f32 &green, f32 &blue, f32 &brightness, f32 &contrast) =0; - //! Remove all messages pending in the system message loop + //! Remove messages pending in the system message loop /** This function is usually used after messages have been buffered for a longer time, for example when loading a large scene. Clearing the message loop prevents that mouse- or buttonclicks which users have pressed in the meantime will now trigger unexpected actions in the gui.
So far the following messages are cleared:
Win32: All keyboard and mouse messages
- Linux: All messages
+ Linux: All keyboard and mouse messages
All other devices are not yet supported here.
The function is still somewhat experimental, as the kind of messages we clear is based on just a few use-cases. If you think further messages should be cleared, or some messages should not be cleared here, then please tell us. */ diff --git a/source/Irrlicht/CIrrDeviceLinux.cpp b/source/Irrlicht/CIrrDeviceLinux.cpp index bf3b68f5..e1801a93 100644 --- a/source/Irrlicht/CIrrDeviceLinux.cpp +++ b/source/Irrlicht/CIrrDeviceLinux.cpp @@ -1814,6 +1814,19 @@ void CIrrDeviceLinux::copyToClipboard(const c8* text) const #endif } +#ifdef _IRR_COMPILE_WITH_X11_ +// return true if the passed event has the type passed in parameter arg +Bool PredicateIsEventType(Display *display, XEvent *event, XPointer arg) +{ + if ( event && event->type == (int)arg ) + { +// os::Printer::log("remove event:", core::stringc((int)arg).c_str(), ELL_INFORMATION); + return True; + } + return False; +} +#endif //_IRR_COMPILE_WITH_X11_ + //! Remove all messages pending in the system message loop void CIrrDeviceLinux::clearSystemMessages() { @@ -1821,10 +1834,11 @@ void CIrrDeviceLinux::clearSystemMessages() if (CreationParams.DriverType != video::EDT_NULL) { XEvent event; - while (XPending(display) > 0 ) - { - XNextEvent(display, &event); - } + while ( XCheckIfEvent(display, &event, PredicateIsEventType, (XPointer)ButtonPress) == True ) {} + while ( XCheckIfEvent(display, &event, PredicateIsEventType, (XPointer)ButtonRelease) == True ) {} + while ( XCheckIfEvent(display, &event, PredicateIsEventType, (XPointer)MotionNotify) == True ) {} + while ( XCheckIfEvent(display, &event, PredicateIsEventType, (XPointer)KeyRelease) == True ) {} + while ( XCheckIfEvent(display, &event, PredicateIsEventType, (XPointer)KeyPress) == True ) {} } #endif //_IRR_COMPILE_WITH_X11_ }