New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
X11: fix KeyPressed duplicated with IBus #1894
Conversation
I tested it with the following code to see KeyReleased events as well. #include <SFML/Graphics.hpp>
int main(int argc, char* argv[])
{
sf::RenderWindow window(sf::VideoMode(100, 100), "Keys");
window.setFramerateLimit(1 < argc ? std::atoi(argv[1]) : 60);
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
else if (event.type == sf::Event::KeyPressed)
printf("KeyPressed, Key=%d\n", (int)event.key.code);
else if (event.type == sf::Event::KeyReleased)
printf("KeyReleased, Key=%d\n", (int)event.key.code);
else if (event.type == sf::Event::TextEntered)
printf("TextEntered, Text=%d\n", (int)event.text.unicode);
}
window.clear();
window.display();
}
} cmake_minimum_required(VERSION 3.22)
project(test)
find_package(SFML 2.5 COMPONENTS graphics REQUIRED)
add_executable(test main.cpp)
target_link_libraries(test sfml-graphics)
install(TARGETS test DESTINATION .) It ran it against those versions of SFML:
So it does not seem to fix the issue. 🤔 As noticed in the previous PR, the environment variable |
Oh no. Key and text events should be two different kinds of things... Maybe we can keep track of which kinds of
This should not affect code discarding repeating key events. |
Went digging through SDL1.2 source code. What they're doing is like:
It basically assumes the IME filters every text event before re-sending it, which makes some sense. EDIT: No it does not make sense. Keys without text attached like the arrow keys are filtered but return only key presses on |
Any updates on this? |
@eXpl0it3r Um, maybe I can use a |
@kimci86 The updated code now uses a global Perhaps in the future we should use As for the bug under low framerates, well I suppose that's a (or maybe, one of many) design flaw of the entire X input stack and it makes (somewhat) sense for the input method to go crazy when it receives a repeated event and the previous filtered one is not even processed. The entire reasoning behind it is, to be frank, beyond me. |
Thank you for you commit, but it does not seem to be a good fix. With the test program at 25 fps (which is not extremely low in my opinion):
I don't know how it can be fixed. All I can think of for now is to check if IBus is used somehow (maybe environment variables) and fallback to previous implementation if so, but that is not really a fix and it makes the code harder to test with more variability. But for now, key events are not reliable 🤕 |
This should be resolved if we use scancodes instead of key codes, see the review.
I can't repeat that behaviour on my standard QWERTY, even with my keyboard layout set to AZERTY (pressing Q types A), but again that might be a IBus problem. Maybe you can add |
I am trying to understand and debug this. IBus seems to need some special handling. See libsdl-org/SDL#1659 |
That's not the same thing. SDL2 uses DBus to connect to the local IBus/Fcitx daemon, and send/receive events through the DBus connection, thus bypassing the entire X/XIM input stack. We're not doing that. If you want to look at some sample code, grab the SDL1.2 code. |
Just went through the hassle of installing a brand new Ubuntu 20.04 in a virtual machine, with GNOME and IBus bundled.
Well I set my keyboard layout to AZERTY, pressed and held the key on the right of Tab, and did not see any
|
IMHO doing some best-effort known key filtering, isn't really an acceptable solution. As soon as the best-effort isn't covered anymore, SFML shouldn't just send whatever combinations of pressed and released events. Why do we get with this change get weird released/pressed event behavior?
We don't guarantee the order of these events, as such this is fine and doesn't really need to be documented. |
The commit now uses a This does not work under keyboard layouts other than QWERTY, but once the scancode PR gets merged we can instead keep track of which scancodes are filtered, and things should work for any key pressed by a user as long as the scancodes are correct.
Because X is bad. The client have to manually feed the events to the IM, and the IM gives text by inserting ( Without XIM, text inputs look like:
Simple. But with XIM, things become messy:
We need to send
@binary1248 I really need your help on this. |
Superseded by #2242 |
Description
This PR is a small patch to not send
KeyPressed
events when the underlying X11 event is taken by the input method. It essentially only involves moving aif
statement to include the part sendingKeyPressed
events, and indenting.This fixes a bug in #1850 not discovered until @kimci86 tested it on GNOME with the bundled IM framework IBus. (here)
How to test this PR?
Dump
KeyPressed
events from a window.