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

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

Merged
merged 6 commits into from
Jul 27, 2023

Conversation

trinitronx
Copy link
Contributor

Change

  • Add a -k flag to set the GTK layer shell keyboard focus mode
    • Modes supported are:
      • exclusive / e (Default)
      • on-demand / o
    • Note: none mode does not seem to make sense for this app, because it disables keyboard input completely.

Rationale / Background:

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
Copy link
Owner

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

@trinitronx
Copy link
Contributor Author

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
Copy link
Owner

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
Copy link
Owner

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
Copy link
Contributor Author

trinitronx commented Jul 27, 2023

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:

  • 1.9-dev-dc634c4a: Pre-release build from git sources.
    • This includes the patch to enable the On-Demand mode.
    • Behavior:
      • Keyboard focus is able to follow mouse movement non-exclusively
      • Use cases enabled:
        • Opening nwg-drawer on a separate monitor / output, moving mouse to the second display to multi-task / copy text to clipboard / etc... Then coming back to nwg-drawer window and pasting in text, opening an app, etc...
          (I tested this via HEADLESS-1 output + wayvnc too!)
        • GTK Inspector workflow (for theming, GTK debug, etc...)
          • Enable GTK Inspector:

            gsettings set org.gtk.Settings.Debug enable-inspector-keybinding true
            
          • Open nwg-drawer on a separate output (e.g. HEADLESS-1 or another display)

          • If using HEADLESS-1, run wayvnc, connect to it with a VNC Client (e.g. Remmina)

          • Press the keyboard shortcut to launch GTK Inspector: Ctrl+Shift+d

          • Move window to another output, make them floating so you can use GTK Inspector while viewing nwg-wrapper in the VNC window.

          • Now keyboard focus follows your mouse, and GTK Inspector is actually usable! (Note: This was not possible before on sway v1.8.1 with Exclusive keyboard mode)

  • 1.8.1-1: Manjaro / Arch stable package release
    • This does not yet include the patch to enable On-Demand mode.
    • Therefore, both Exclusive & On-Demand behave the same
    • Behavior: Exclusive mode is the only behavior, no matter the setting.
      • Focus is placed on nwg-wrapper however it is launched (hotkey, rofi, mouse click on .desktop, etc...)
      • Focus does not follow the mouse. It's locked exclusively to the window.
      • Focus initialized on nwg-wrapper window: This makes keyboard power-users happy! Also good UI/UX for ease of use in general.

@trinitronx
Copy link
Contributor Author

trinitronx commented Jul 27, 2023

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! 🎉

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
Copy link
Owner

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
Copy link
Contributor Author

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 😉

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
Copy link
Owner

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. 🎉 As a hobbyist programmer, I have up to 4 hours a day (night!) for coding.

@nwg-piotr nwg-piotr merged commit 58ea8ea into nwg-piotr:main Jul 27, 2023
@trinitronx trinitronx deleted the add-keyboard-mode-flag branch July 28, 2023 14:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants