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

Any way to swallow all keys while the modal is up? #66

Open
futuro opened this issue Sep 14, 2020 · 5 comments
Open

Any way to swallow all keys while the modal is up? #66

futuro opened this issue Sep 14, 2020 · 5 comments
Assignees

Comments

@futuro
Copy link

futuro commented Sep 14, 2020

Hi!

Thanks for making spacehammer!

I've been wondering if there's a way to eat all keys while the modal is up (after I press the LEADER key). Sometimes I press a non-mapped key, and that gets passed through to the window in focus instead of doing something in the modal; is it currently possible to make all pressed keys go to spacehammer?

Thank you!
Evan

@jaidetree
Copy link
Collaborator

I've been thinking about how this could be tackled. Currently, it would require replacing some of the core functions in modal.fnl to change how modal bindings are handled. Today an idea came to mind linked above to create an advising system that makes it trivial to register functions that can be then replaced or modified by say filtering args, filtering return values, wrapping it, or replacing it directly.

This provides an accessible means to achieve this functionality without pushing something like this on unexpected users.

My current thoughts would be to using the proposed advising systems to override the modal bindings to also run the hs.eventtap system to handle keys. Anything that doesn't match a binding in the current menu will be ignored until an action is pressed or ESC.

@agzam
Copy link
Owner

agzam commented Sep 30, 2020

@futuro Unfortunately, It cannot be done easily, see: Hammerspoon/hammerspoon#1505. We had an open issue here long time ago see #1, and we decided to close it. Until Hammerspoon gets native support for this, I think it's not even worth tackling.

@jaidetree
Copy link
Collaborator

@agzam

Second idea is to create an eventtap in the modal:entered function which traps keyDown and keyUp events and dismisses them (I think by returning false, but check the documentation for hs.eventtap.new to be sure). Not sure if you'll need to add a check in the eventtap callback to exempt the specific keys that you do want to go through or not -- can't remember which gets priority within the Hammerspoon application. In the exited function make sure to disable the eventap. Down side, potentially harder to code especially if your unfamiliar with eventtaps.

That is the solution I had in mind. With the previous version of Spacehammer that would be a nightmare since the bindings were defined at runtime through code that was locally scoped to the modal API. Now they're defined statically in our config.fnl file making the more difficult part of knowing what is and is not a valid key significantly simpler than it was before.

It may not be easy but I'm down for trying it, I had prototyped something like that for a more modal vim mode.

(fn log-key
  [event]
  (let [key-code (: event :getKeyCode)
        flags (: event :getFlags)
        key-char (. hs.keycodes.map key-code)]
    (values false {})))

(let [types hs.eventtap.event.types
      tap (hs.eventtap.new [types.keyDown]
                           log-key)]
  (: tap :start))

@futuro
Copy link
Author

futuro commented Oct 30, 2020

I don't know if I understand lua/fennel/hammerspoon well enough to be much help in building this, but please let me know if I can help test!

@jaidetree jaidetree self-assigned this Sep 16, 2021
@jaidetree
Copy link
Collaborator

With advice being merged that gives me a flexible entrypoint to explore this without introducing a controversial change. Will give this a shot in the next week or two.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants