JUCE
JUCE copied to clipboard
[Bug]: Components steal X11 focus when clicked
trafficstars
Detailed steps on how to reproduce the bug
- Embed a JUCE component in an X11-based application using the
windowIgnoresKeyPressesflag:
component->addToDesktop(juce::ComponentPeer::windowIgnoresKeyPresses, hostWindow);
- Run application and verify that application's keyboard shortcuts work.
- Click on the JUCE component
- Observe that the application's keyboard shortcuts no longer work.
What is the expected behaviour?
JUCE Components using windowIgnoresKeyPresses should not steal keyboard focus when clicked.
The root of the problem appears to be a call to juce::LinuxComponentPeer::grabFocus made by juce::LinuxComponentPeer::toFront in XWindowSystem::handleButtonPressEvent (see stacktrace).
Once this happens, the host application stops receiving keyboard events.
Commenting out the grabFocus call in toFront stops JUCE stealing input focus, but stops PopupMenu menus appearing correctly.
Interestingly, showing a PopupMenu menu and dismissing it by clicking outside the JUCE Component restores input focus to the host application.
Operating systems
Linux
What versions of the operating systems?
Linux Mint 20.3
Architectures
x86_64
Stacktrace
#0 juce::XWindowSystem::grabFocus (this=0x555555c39a50, windowH=96468996) at /home/nick/Repos/amsynth/vendor/JUCE/modules/juce_gui_basics/native/x11/juce_linux_XWindowSystem.cpp:2049
#1 0x00005555558e6ea0 in juce::LinuxComponentPeer::grabFocus (this=0x5555563972b0) at /home/nick/Repos/amsynth/vendor/JUCE/modules/juce_gui_basics/native/juce_linux_Windowing.cpp:295
#2 0x00005555558e6d6e in juce::LinuxComponentPeer::toFront (this=0x5555563972b0, makeActive=true) at /home/nick/Repos/amsynth/vendor/JUCE/modules/juce_gui_basics/native/juce_linux_Windowing.cpp:265
#3 0x0000555555879c0f in juce::XWindowSystem::handleButtonPressEvent (this=0x555555c39a50, peer=0x5555563972b0, buttonPressEvent=..., buttonModifierFlag=16) at /home/nick/Repos/amsynth/vendor/JUCE/modules/juce_gui_basics/native/x11/juce_linux_XWindowSystem.cpp:3540
#4 0x0000555555879d81 in juce::XWindowSystem::handleButtonPressEvent (this=0x555555c39a50, peer=0x5555563972b0, buttonPressEvent=...) at /home/nick/Repos/amsynth/vendor/JUCE/modules/juce_gui_basics/native/x11/juce_linux_XWindowSystem.cpp:3558
#5 0x00005555558790e3 in juce::XWindowSystem::handleWindowMessage (this=0x555555c39a50, peer=0x5555563972b0, event=...) at /home/nick/Repos/amsynth/vendor/JUCE/modules/juce_gui_basics/native/x11/juce_linux_XWindowSystem.cpp:3322
#6 0x000055555587b319 in juce::XWindowSystem::windowMessageReceive (event=...) at /home/nick/Repos/amsynth/vendor/JUCE/modules/juce_gui_basics/native/x11/juce_linux_XWindowSystem.cpp:3909
#7 0x00005555558788fb in <lambda(int)>::operator()(int) const (__closure=0x555556379c00) at /home/nick/Repos/amsynth/vendor/JUCE/modules/juce_gui_basics/native/x11/juce_linux_XWindowSystem.cpp:3245
#8 0x0000555555887eeb in std::_Function_handler<void(int), juce::XWindowSystem::initialiseXDisplay()::<lambda(int)> >::_M_invoke(const std::_Any_data &, int &&) (__functor=..., __args#0=@0x7fffffffdb34: 22) at /usr/include/c++/9/bits/std_function.h:300
#9 0x00005555556d25d6 in std::function<void (int)>::operator()(int) const (this=0x555556379c00, __args#0=22) at /usr/include/c++/9/bits/std_function.h:688
#10 0x00005555556c8378 in <lambda()>::operator()(void) const (__closure=0x555556379c00) at /home/nick/Repos/amsynth/vendor/JUCE/modules/juce_events/native/juce_linux_Messaging.cpp:357
#11 0x00005555556c8a86 in std::_Function_handler<void(), juce::LinuxEventLoop::registerFdCallback(int, std::function<void(int)>, short int)::<lambda()> >::_M_invoke(const std::_Any_data &) (__functor=...) at /usr/include/c++/9/bits/std_function.h:300
#12 0x00005555556981f4 in std::function<void ()>::operator()() const (this=0x555556379da0) at /usr/include/c++/9/bits/std_function.h:688
#13 0x00005555556cdb53 in juce::InternalRunLoop::dispatchPendingEvents (this=0x555555c2f0c0) at /home/nick/Repos/amsynth/vendor/JUCE/modules/juce_events/native/juce_linux_Messaging.cpp:180
#14 0x00005555556c831c in juce::dispatchNextMessageOnSystemQueue (returnIfNoPendingMessages=true) at /home/nick/Repos/amsynth/vendor/JUCE/modules/juce_events/native/juce_linux_Messaging.cpp:340
Plug-in formats (if applicable)
No response
Plug-in host applications (DAWs) (if applicable)
No response
Testing on the develop branch
The bug is present on the develop branch
Code of Conduct
- [X] I agree to follow the Code of Conduct