Skip to content
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

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

Closed
spl237 opened this issue Apr 27, 2023 · 5 comments · Fixed by #2277
Closed

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

spl237 opened this issue Apr 27, 2023 · 5 comments · Fixed by #2277
Labels
Milestone

Comments

@spl237
Copy link

spl237 commented Apr 27, 2023

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 spl237 added the bug label Apr 27, 2023
@ammen99
Copy link
Member

ammen99 commented Jun 2, 2023

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 ammen99 changed the title Popup menus do not always get keyboard focus Support keyboard input for xdg-popups of layer-shell views Aug 4, 2023
@ammen99 ammen99 added this to the 0.9 milestone Mar 1, 2024
@ammen99
Copy link
Member

ammen99 commented Mar 1, 2024

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

@spl237
Copy link
Author

spl237 commented Mar 1, 2024

Coinicidentally, this was recently raised against labwc - labwc/labwc#1572

So it has the same problem.

@stefonarch
Copy link

In fact ;)

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

@ammen99
Copy link
Member

ammen99 commented Mar 27, 2024

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

@ammen99 ammen99 mentioned this issue Mar 27, 2024
ammen99 added a commit that referenced this issue Mar 27, 2024
ammen99 added a commit that referenced this issue Apr 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants