Keyboard Focus Bug On Linux

When grabbing keyboard focus with a JUCE component in Linux, it seems to take focus away from other applications. On macOS and Windows these calls only take focus away from the other JUCE components in our plugins.

Here’s a PIP for quick testing. We ran on Debian 9 with a text editor open. Every timerCallback() the text editor app had focus taken away from it but remained in the foreground, which was not the same behavior as running on my macOS machine.

/*******************************************************************************
 The block below describes the properties of this PIP. A PIP is a short snippet
 of code that can be read by the Projucer and used to generate a JUCE project.

 BEGIN_JUCE_PIP_METADATA

  name:             UnfocusTest

  dependencies:     juce_core, juce_data_structures, juce_events, juce_graphics, juce_gui_basics
  exporters:        linux_make

  type:             Component
  mainClass:        MyComponent

 END_JUCE_PIP_METADATA

*******************************************************************************/

#pragma once

class MyComponent   : public Component,
					  public Timer
{
public:
    MyComponent()
    {
        setSize (600, 400);
        startTimer(1000);
    }

    ~MyComponent()
    {
    }

    void timerCallback () override
    {
    	unfocusAllComponents();
    }

    void paint (Graphics& g) override
    {
        g.fillAll(
        	getLookAndFeel().findColour(ResizableWindow::backgroundColourId)
        );
    }

private:
    JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MyComponent)
};

Is this only in a plug-in setting? Your pip works fine on Ubuntu. I let your PiP run in the background while editing in gedit and everything seems to be working.

Hey Fabian,

We encountered it while running that PIP as well as our plugin

Perhaps it could be distro or WM/DE specific? I’ll try it out in Ubuntu and see, if it only really happens on that Debian setup that would be okay

You are using the newest version of JUCE right? I just remembered that we fixed a bug over a year ago where JUCE would steal the focus from any other application running - exactly like you describe.

We’re currently on 5.3.1

A user reported a similar problem with our VST3 plugin. Tested with bitwig and reaper. Most time the TextEditor component loses its focus and it is impossible to enter a text.

System configuration:
OS: Manjaro 21.2.5 Qonos
Kernel: x86_64 Linux 5.16.14-1-MANJARO
EN: GNOME 41.4
WM: Mother

It works fine on our Ubuntu test machine.

The problem occurs only with Wayland

Just to confirm I’m seeing this as well; TextEditor input focus appears reliably broken when using Wayland. This is a different issue to the OP I think.

I can almost get it to work, if I manually call grabKeyboardFocus on the editor. This works as long as I don’t click on any other component first. I can make edits, commit or abort the change with return / esc, and then make subsequent edits etc. However, as soon as I click on any other component, it becomes impossible to interact with the TextEditor.

Similarly, if I open the plugin window and first click on some other component before creating the TextEditor, then it will never get keyboard focus (this appears to be irrecoverable).

My editor is dynamically created following a mouse-click on its parent, and destroyed on return, esc, or focus-lost. It’s these events which don’t get called if I’ve previously clicked on some other component. So my editor stays visible - uneditable, and undismissable.

Perhaps worth noting that Wayland is installed as the default in Ubuntu and Fedora, for almost two years now.

I’m seeing the exact behavior as @pintsized. Is there a workaround or fix on the horizon? Running latest JUCE, current Ubuntu.

ComboBoxes also do not work with Wayland. They lose the focus before the user can select an item.