nwg-piotr / nwg-drawer

Application drawer for wlroots-based Wayland compositors
MIT License
233 stars 25 forks source link

Add keyboard mode flag to support both: "on-demand" & "exclusive" GTK layer-shell modes #95

Closed trinitronx closed 1 year ago

trinitronx commented 1 year ago

Change

gtk-layer-shell, and Wayland now supports an "On Demand" mode via zwlr_layer_surface_v1::keyboard_interactivity v4 for keyboard focus. The demo app also supports this mode and works well to demonstrate the new zwlr_layer_surface_v1::keyboard_interactivity v4 wayland protocol for the on-demand keyboard focus mode.

Note that for this to behave differently, it requires a newer version of sway than is currently released on most Linux distros, but it will not break anything given the backwards-compatible behavior being exclusive by default. (e.g. without this change: swaywm/sway@913a7679 / swaywm/sway#7587 ... and with on-demand mode set, it still behaves as if exclusive mode was set)

The following PRs have made it into wl-protocols, wlroots, & gtk-layer-shell:

Note: there is also one for wayfire: WayfireWM/wayfire#962

Testing the gtk-layer-shell demo program on Sway 1.8.1 behaves the same. For example: When setting the "On Demand" keyboard mode (--keyboard o) and either "Top" or "Overlay" layers (--layer t or --layer o).

When on these layers, it's impossible to get keyboard focus off of the demo program window without first setting keyboard setting back to "None". While not ideal from a UI/UX perspective, nor from an app developer perspective, it doesn't hurt to have this option in client programs to enable the feature when sway or other window managers adopt the zwlr_layer_surface_v1::keyboard_interactivity v4 protocol.

More information can be found in: swaywm/sway#7499.

nwg-piotr commented 1 year ago

If the exclusive mode is default, wouldn't it be enough to add a boolean argument for the on demand mode?

trinitronx commented 1 year ago

If the exclusive mode is default, wouldn't it be enough to add a boolean argument for the on demand mode?

Yes, now that I think about it again this makes more sense. The reason I went down the path of using a string flag was to support all the enum types supported by GTK layer shell, which included the none type at first.

After testing this out, I realized that none keyboard mode did not make sense from a UI/UX perspective for this app... so I changed it by removing that option and leaving the other two.

Now it can be represented by a simple binary on/off for on-demand vs exclusive modes (unless they add more modes in the future).

nwg-piotr commented 1 year ago

Sorry for delay. I was busy at other projects.

After some deliberation: I think we should just use LAYER_SHELL_KEYBOARD_MODE_ON_DEMAND in main.go line 389, w/o multiplying arguments. I'll check how it behaves tonight.

nwg-piotr commented 1 year ago

On sway 1.8.1 setting keyboard mode layershell.LAYER_SHELL_KEYBOARD_MODE_ON_DEMAND seems to change nothing. On Hyprland for some reason it behaves perfectly well in both ON_DEMAND and EXCLUSIVE mode. I failed installing the current development version of sway, so dunno how it's going to behave there. I suppose that just changing to ON_DEMAND mode should be safe.

trinitronx commented 1 year ago

Sorry for delay. I was busy at other projects.

After some deliberation: I think we should just use LAYER_SHELL_KEYBOARD_MODE_ON_DEMAND in main.go line 389, w/o multiplying arguments. I'll check how it behaves tonight.

I'd caution against making it the default unless also the app will grab focus on opening. In my testing, I could trigger nwg-wrapper with hotkey and had to explicitly focus the app first by moving the mouse. Without a focus event, it detracts from keyboard power-users... who are probably the demographic that window managers like Sway & i3wm appeal to.

I've tested on the following versions of sway:

trinitronx commented 1 year ago

On sway 1.8.1 setting keyboard mode layershell.LAYER_SHELL_KEYBOARD_MODE_ON_DEMAND seems to change nothing.

This was my experience too during testing. It's because the only mode supported for that version was LAYER_SHELL_KEYBOARD_MODE_EXCLUSIVE. New behavior depends on the following change:

On Hyprland for some reason it behaves perfectly well in both ON_DEMAND and EXCLUSIVE mode.

Sounds like it supports the zwlr_layer_surface_v1::keyboard_interactivity v4 protocol too! :tada:

I failed installing the current development version of sway, so dunno how it's going to behave there. I suppose that just changing to ON_DEMAND mode should be safe.

If you'd like to test... I built pre-release Arch packages from the PKGBUILDs on Manjaro. Here is the PKGBUILD testing repo I've been pushing to: gitlab.archlinux.org/trinitronx/nwg-drawer-git. Attaching the .pkg.tar.xz files here...

sway-pre-release-packages.tar.gz

nwg-piotr commented 1 year ago

Alright then. I'll merge it after #96. Sorry for prioritizing my own PR, which is younger, but your PR introduces less changes (in case of conflicts).

trinitronx commented 1 year ago

Alright then. I'll merge it after #96. Sorry for prioritizing my own PR, which is younger, but your PR introduces less changes (in case of conflicts).

No problem, you can prioritize however makes sense... it's your project after all :wink:

FYI: I just uploaded both of the pre-release versions that I was testing to the Releases page @ gitlab.archlinux.org/trinitronx/nwg-drawer-git.

I think the one for nwg-drawer-git that I included in the sway-pre-release-packages.tar.gz above is the older version with flag.String implementation. The newer one with flag.Bool is: 0.3.8.r20_pre.git.4724b52b0da.

The other updated dependencies for sway 1.9-dev-dc634c4a are still in sway-pre-release-packages.tar.gz

nwg-piotr commented 1 year ago

This update is simple enough to need no special testing, for which I have too little time by the way. I'm sure you tested it well enough. I'm a bit in hurry to finish what I'm working on before my holiday starts. :tada: As a hobbyist programmer, I have up to 4 hours a day (night!) for coding.