Fix duplicated KeyPressed events with X11

Co-authored-by: Edgaru089 <sjs333@outlook.com>
This commit is contained in:
kimci86 2022-10-10 00:31:53 +02:00 committed by Lukas Dürrenberger
parent 65ef0619c8
commit b11328f386

View File

@ -34,6 +34,7 @@
#include <SFML/System/Mutex.hpp> #include <SFML/System/Mutex.hpp>
#include <SFML/System/Lock.hpp> #include <SFML/System/Lock.hpp>
#include <SFML/System/Sleep.hpp> #include <SFML/System/Sleep.hpp>
#include <bitset> // <X11/Xlibint.h> defines min/max as macros, so <bitset> has to come before that
#include <X11/Xlibint.h> #include <X11/Xlibint.h>
#include <X11/Xutil.h> #include <X11/Xutil.h>
#include <X11/Xatom.h> #include <X11/Xatom.h>
@ -68,6 +69,7 @@ namespace
{ {
sf::priv::WindowImplX11* fullscreenWindow = NULL; sf::priv::WindowImplX11* fullscreenWindow = NULL;
std::vector<sf::priv::WindowImplX11*> allWindows; std::vector<sf::priv::WindowImplX11*> allWindows;
std::bitset<256> isKeyFiltered;
sf::Mutex allWindowsMutex; sf::Mutex allWindowsMutex;
sf::String windowManagerName; sf::String windowManagerName;
@ -1901,10 +1903,30 @@ bool WindowImplX11::processEvent(XEvent& windowEvent)
event.key.control = windowEvent.xkey.state & ControlMask; event.key.control = windowEvent.xkey.state & ControlMask;
event.key.shift = windowEvent.xkey.state & ShiftMask; event.key.shift = windowEvent.xkey.state & ShiftMask;
event.key.system = windowEvent.xkey.state & Mod4Mask; event.key.system = windowEvent.xkey.state & Mod4Mask;
pushEvent(event);
// Generate a TextEntered event const bool filtered = XFilterEvent(&windowEvent, None);
if (!XFilterEvent(&windowEvent, None))
// Generate a KeyPressed event if needed
if (filtered)
{
pushEvent(event);
isKeyFiltered.set(windowEvent.xkey.keycode);
}
else
{
// Push a KeyPressed event if the key has never been filtered before
// (a KeyPressed event would have already been pushed if it had been filtered).
//
// Some dummy IMs (like the built-in one you get by setting XMODIFIERS=@im=none)
// never filter events away, and we have to take care of that.
//
// In addition, ignore text-only KeyPress events generated by IMs (with keycode set to 0).
if (!isKeyFiltered.test(windowEvent.xkey.keycode) && windowEvent.xkey.keycode != 0)
pushEvent(event);
}
// Generate TextEntered events if needed
if (!filtered)
{ {
#ifdef X_HAVE_UTF8_STRING #ifdef X_HAVE_UTF8_STRING
if (m_inputContext) if (m_inputContext)