So I finally figured out how to make an override_redirect window get keyboard focus: it has to grab the keyboard device itself. https://github.com/anko/hudkit/commit/d40cb15eea00588c09e9deacc7af6bfa9cd07001 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.
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
So I finally figured out how to make an
override_redirect
window get keyboard focus: it has to grab the keyboard device itself. https://github.com/anko/hudkit/commit/d40cb15eea00588c09e9deacc7af6bfa9cd07001 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 theexample/
, 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 tokeydown
events.https://user-images.githubusercontent.com/5231746/116835815-66b4d980-abc4-11eb-86fe-8ebf362101ee.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 bynever
: do not ever grab keyboard focus; related JS API does nothingon-hover
: always grab keyboard when clickable part of overlay is hovered; related JS API does nothingon-js
: enable the related JS APIHaven't decided what the default should be yet.