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

Allow to hook application window events #405

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

dajoha
Copy link

@dajoha dajoha commented Mar 29, 2024

This can be useful to handle application-level global shortcuts.

In the same time I improved the keyboard_handler example, in order to demonstrate the "global shortcut" capability.

EDIT: merged master and removed edits for the the keyboard_handler example

@dominikwilkowski
Copy link
Contributor

I curious how this is different to what we have now?
We have global shortcuts implemented like this: https://github.com/dominikwilkowski/vault/blob/main/src/main.rs#L256-L290 and it seems to work?

@dajoha
Copy link
Author

dajoha commented Jul 15, 2024

Hello @dominikwilkowski , sorry for late response.

  1. The main reason to propose this MR is that for now, for any Linux target, global shortcuts do not work (or you must first click on an empty zone in the UI to get focus, which is unacceptable). The reason is quite simple: the main view (the one given to Application::new().window(|| {})) is wrapped internally by floem, in order to handle context menus. Maybe a better solution would be to remove this wrap for Linux targets, but I don't know if it's possible.
  2. The 2nd reason is that sometimes, depending on the app you are writing, you may want the keyboard events to be handled at first by the application itself, not by the focused element; for example, for now, focused text editors will catch every keyboard event, and there is no way to quit with Ctrl-Q if you set this shortcut globally.

To summarize, as developpers we should have full control over this important aspect, but I'm certainly not enough involved to propose the best solution.

Btw as you can see, this MR is outdated, but I made a different version here where I moved the hook from Application to WindowHandle, (which allows to use the computed values for the key modifiers). I will take the time to update it soon with this new version.

@dominikwilkowski
Copy link
Contributor

I see. This is linux specific then? Good to know. We should check our implementation to work on linux too then :)

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