wayfire icon indicating copy to clipboard operation
wayfire copied to clipboard

Support keyboard input for xdg-popups of layer-shell views

Open spl237 opened this issue 2 years ago • 1 comments

Describe the bug All menus should always get keyboard focus - there should only ever be one menu on the screen at any one time, and if one is shown, keystrokes should go to it. This does not happen in some cases under Wayfire.

To Reproduce Add the following test widget to wf-panel:

test.cpp

#include <glibmm.h>
#include "test.hpp"

void WayfireTest::command (const char *cmd)
{
    if (!g_strcmp0 (cmd, "menu")) button_pressed ();
}

void WayfireTest::button_pressed (void)
{
    menu->show_all ();
    menu->popup_at_widget (&(*plugin), Gdk::GRAVITY_SOUTH_WEST, Gdk::GRAVITY_NORTH_WEST, nullptr);
}

void WayfireTest::init (Gtk::HBox *container)
{
    plugin = std::make_unique <Gtk::Button> ();
    container->pack_start (*plugin, false, false);
    
    menu = std::make_unique <Gtk::Menu> ();
    item = std::make_unique <Gtk::MenuItem> ("Item", false);
    item2 = std::make_unique <Gtk::MenuItem> ("Item2", false);
    menu->append (*item);
    menu->append (*item2);

    plugin->signal_clicked().connect (sigc::mem_fun (*this, &WayfireTest::button_pressed));
    plugin->set_label ("Test");
    plugin->show_all ();
}

WayfireTest::~WayfireTest()
{
}

test.hpp

#ifndef WIDGETS_TEST_HPP
#define WIDGETS_TEST_HPP

#include "../widget.hpp"
#include <gtkmm/button.h>
#include <gtkmm/menu.h>
#include <gtkmm/menuitem.h>

class WayfireTest : public WayfireWidget
{
    std::unique_ptr <Gtk::Button> plugin;
    std::unique_ptr <Gtk::Menu> menu;
    std::unique_ptr <Gtk::MenuItem> item;
    std::unique_ptr <Gtk::MenuItem> item2;

  public:
    void init (Gtk::HBox *container) override;
    void button_pressed (void);
    void command (const char *cmd) override;
    virtual ~WayfireTest ();
};

#endif

Build and include the plugin in the panel config. Run the panel.

Click the "Test" button to open the menu. Use the up and down arrow keys when the menu is on screen - they should move the menu highlight, but they have no effect.

This can be fixed by including gtk_layer_set_keyboard_mode (window->gobj(), GTK_LAYER_SHELL_KEYBOARD_MODE_ON_DEMAND); in the create_window function in panel.cpp, but this does not completely fix the problem.

If that line is included, then if the menu is opened with the mouse, then the menu does now get keyboard focus and can be navigated with the arrow keys. But if the menu is opened without using the mouse - I am using a DBus message sent from wayfire in response to a keyboard shortcut which then triggers the command handler in the plugin - then the menu opens but still does not have keyboard focus, because it is the action of clicking on a panel button with the mouse which requests keyboard focus.

The only way I have been able to get this situation to work is to modify the way the menu is opened so that before the menu opens, the panel is given exclusive keyboard focus, the menu then opens, and a handler is attached to the menu so that when it closes the exclusive keyboard focus on the panel is relinquished, which really cannot be the right thing to do!

As I understand it, there are no circumstances when a menu should not have keyboard focus, so I think Wayfire itself should ensure that this is the case whenever a menu is opened.

Wayfire version 0.7.5 from Debian bookworm

spl237 avatar Apr 27 '23 15:04 spl237

As I understand it, there are no circumstances when a menu should not have keyboard focus, so I think Wayfire itself should ensure that this is the case whenever a menu is opened.

As far as I understand xdg-popups, you are supposed to start a keyboard grab when the menu opens. Since wlroots handles that, I think that it will work, no matter what Wayfire does.

ammen99 avatar Jun 02 '23 06:06 ammen99

I can repro with lxqt-panel and wayfire-git. Which is weird but at least we know it is a Wayfire bug.

ammen99 avatar Mar 01 '24 19:03 ammen99

Coinicidentally, this was recently raised against labwc - https://github.com/labwc/labwc/issues/1572

So it has the same problem.

spl237 avatar Mar 01 '24 19:03 spl237

In fact ;)

Only kwin_wayland and Hyprland are not affected, gonna open an issue at sway.

stefonarch avatar Mar 01 '24 21:03 stefonarch

PR #2277 seems to fix the problem for me, can someone confirm?

ammen99 avatar Mar 27 '24 12:03 ammen99