wmww / gtk-layer-shell

A library to create panels and other desktop components for Wayland using the Layer Shell protocol
GNU General Public License v3.0
319 stars 16 forks source link

Initially setting keyboard focus for a layer which can then be lost #162

Closed spl237 closed 1 year ago

spl237 commented 1 year ago

As I understand it, there are three different keyboard interactivity options for a layer. NONE means the layer never has keyboard focus. EXCLUSIVE means that the layer has keyboard focus and can never lose it, meaning no other layers can have focus while that layer is open. And ON_DEMAND means that layer does not have focus, but gets it if it is clicked.

None of these, unfortunately, do quite what I need...

I have a text search window which is opened when the user starts to type when in a menu; the text search window immediately replaces the menu. So this window needs to have keyboard focus at the moment it opens, so the user can continue to type and keystrokes continue to go to the new window.

However, this window also needs to behave like a menu, in that if the user clicks outside the window, I want that to be detected as a focus-out event and for the window to then close.

If I set focus for this window to NONE, it does not receive keystrokes and can never do so - so that doesn't work.

If I set focus to EXCLUSIVE, it does receive keystrokes, but can never lose focus, so I cannot close it by clicking outside.

If I set focus to ON_DEMAND, the window will close if clicked outside, and can have keyboard focus, but only if the user stops typing, clicks in the new window to give it keyboard focus, and then carries on typing, which is really not good from a usability perspective.

What I need is either a fourth state, something like RELEASABLE, whereby a layer initially has keyboard focus but non-exclusively, so it can lose it when clicked away, or alternatively a way to create a layer as ON_DEMAND, and then to programmatically ensure that it has keyboard focus when it is opened without the user needing to click on it.

Are either of these possible, either with or without code changes?

Many thanks in advance.

Consolatis commented 1 year ago

Just thinking out loud, couldn't you use EXCLUSIVE when creating the window and then switch to ON_DEMAND once its mapped?

spl237 commented 1 year ago

Already tried that! Doesn't work - as soon as you switch to ON_DEMAND, the window loses focus.

ErikReider commented 1 year ago

as soon as you switch to ON_DEMAND, the window loses focus.

That sounds more like a WM issue if I'm not mistaken

wmww commented 1 year ago

Yeah, unfortunately it sounds like there's nothing a client can do about this behavior with the protocol as it currently is.

Consolatis commented 1 year ago

as soon as you switch to ON_DEMAND, the window loses focus.

That sounds more like a WM issue if I'm not mistaken

Yes, that doesn't sound right. The only case I can imagine is when another layershell client in the TOP/OVERLAY layers has EXCLUSIVE set as well. Then the focus should likely switch to that client once we lose our EXCLUSIVE flag. What compositor are you using?

spl237 commented 1 year ago

Wayfire. But I have had quite a few focus problems, particularly with opening menus off the panel - in order to give those keyboard focus, I have had to do a fairly arcane workaround - so it looks as if this may just be something that isn't handled well in Wayfire.

Tamaranch commented 1 year ago

Yes, Wayfire <= 0.7.5 does not support on-demand mode iirc: see https://github.com/wmww/gtk-layer-shell/issues/141#issuecomment-1343278392

spl237 commented 1 year ago

Hmmm. That's odd, because I am using 0.7.5, and I am sure I have got on-demand mode working in some circumstances. I'm going to do some more digging about in this today and try to get to the bottom of it.