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 #12

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft

Support keyboard input #12

wants to merge 1 commit into from

Conversation

anko
Copy link
Owner

@anko anko commented May 3, 2021

So I finally figured out how to make an override_redirect window get keyboard focus: it has to grab the keyboard device itself. d40cb15 is an initial proof of concept that this works. This draft PR is a dumping ground for thoughts and plans on how to proceed, toward something stable enough to release, as if I ever finished anything worthwhile.

If you check out the grab-keyboard branch and run the example/, the leftmost 100 pixels of column on your leftmost monitor should be a clickable area, and when you hover over it, you can also type text, which the webview can react to as you'd expect by listening to keydown events.

Peek.2021-05-03.04-00.mp4

Incidentally, this also makes it possible to type into the Web Inspector also when it is docked to the overlay window.


Bugs to be fixed:

  • Drag-and-drop gets into a broken state when trying to drag selected text out of the overlay's clickable area.

    It would be real smooth if it were possible to drag and drop whatever across the boundary, but if it turns out to be too hard, just cancelling the drag and not breaking is still good enough to release.

  • The window gets erroneously jittery enter/leave events when moving the mouse near the edges of the screen.

    A workaround that seems to work according to brief testing: Just make the window 1 pixel larger in every dimension than the desktop area, and position it so it's indistinguishable. The event jitter only happens on the edge pixel.


Also have to think about the API design of this. My plan so far is to add Hudkit.grabKeyboard()/.ungrabKeyboard() to the JS API, so user code can grab it when appropriate, instead of always. You might for example want some elements to only be clickable, without grabbing keyboard focus when they are hovered, while others should grab keyboard focus.

The command line flag to control this could look like --grab-keyboard followed by

  • never: do not ever grab keyboard focus; related JS API does nothing
  • on-hover: always grab keyboard when clickable part of overlay is hovered; related JS API does nothing
  • on-js: enable the related JS API

Haven't decided what the default should be yet.

Finally figured out how to do this.  This change makes it possible for
the first time for the overlay window to react to keyboard events, and
so it's possible to make any arbitrary interactive web UI with it!

It's pretty neato.

This is a proof of concept!  There are many minor bugs, like
drag-and-drop completely breaks when trying to drag out of the overlay's
clickable area, and enter/leave events jitter when sweeping the mouse
along edges of the screen.  That kind of thing.

Related to #3 and #5, but not global; no events are duplicated here.
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.

1 participant