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

Using ⌥ in hotkeys? #5

Closed
9mm opened this issue Sep 27, 2023 · 4 comments
Closed

Using ⌥ in hotkeys? #5

9mm opened this issue Sep 27, 2023 · 4 comments

Comments

@9mm
Copy link

9mm commented Sep 27, 2023

Hey, I'm looking to do a "Hide others" hotkey which is usually ⌥+⌘+H

I see command looks like its already added

            menu.add(MenuItemWrapper::new("Hide Neovide", "h", None));
            menu.add(MenuItemWrapper::new("Hide Others", "", None));

Is there a way I can use this specific key?

@madsmtm
Copy link
Owner

madsmtm commented Sep 27, 2023

General note on stability/readyness: I wouldn't recommend this crate to anyone yet.

I think we need to, on macOS at least, set keyEquivalentModifierMask to the desired modifiers.

This can be done if you use icrate directly, something like menuitem.setKeyEquivalentModifierMask(NSEventModifierFlagOption | NSEventModifierFlagCommand), though that is currently unimplemented in menubar.

@9mm
Copy link
Author

9mm commented Oct 1, 2023

Hey, thanks for letting me know. Just as a precursor to what I'm about to say, I'm new to rust (I've written 5 lines total) and I'm trying to help the Neovide project implement a native OSX menu. They use winit, and the default winit menu is preventing certain hotkeys from being captured (like ⌘-Q quit on OSX).

So far I have disabled the default winit menu, and now I'm setting off to rebuild the menu using this crate and so far it seems to work pretty good, aside form overwriting the actual hotkey combinations.

I think for the use case of Neovide, it can be a very simple menu. Essentially I want to re-create About, Hide (⌘-H), Hide Others (⌥+⌘+H), Quit (⌘+Q), and a window menu with Minimize (⌘+M) (plus other default window hotkeys, like "Full Screen" with ⌃+⌘+F). More could be added later.

So if you do not recommend this library (yet), can you roughly outline the steps I might take to do something like this above, as if i were a golden retriever? I checked out icrate and it looks like native OSX <-> rust bindings, although I don't know objective C. I could figure it out perhaps if there were examples somewhere of using it to create a menu (like I did with the code examples for menubar, they were extremely helpful). Or even a point in the right direction of what crate (this, objc2, icrate, or otherwise) which might best accomplish this goal

Thank you for any help, if you feel like it, although of course no obligation. Thanks!!

@madsmtm
Copy link
Owner

madsmtm commented Oct 1, 2023

If you only want macOS support, then you should use icrate (which is still somewhat unstable, but at least less so than this crate). If you want multiplatform support, then you probably have to write your menu code separately for each platform currently.

Generally

I think the best code examples would probably be to find Objective-C examples on how to programmatically create and configure menus in AppKit (probably loads out there, haven't really checked).

Once you've found code to do that, you could port it to using icrate, once you understand how the latter works - I am in the process of writing a tutorial on that, but I keep getting caught up in other things.

Concretely

menubar fairly precisely follows AppKit's API, e.g. MenuItemWrapper is basically just NSMenuItem with convenience functions; so I think if you check out the source code for menubar::appkit, and convert all your uses of MenuItemWrapper to NSMenuItem (and so on), then you'll have something functional at the end.

Another example can be found in winit's own menu code; that still uses manual definitions of NSMenu and NSMenuItem (because I haven't updated it yet), but I think it should be possible to convert from that to icrate.

I hope that helps!

@9mm
Copy link
Author

9mm commented Oct 1, 2023

Cool, thank you! I appreciate it. This gives me a great direction.

@9mm 9mm mentioned this issue Oct 3, 2023
12 tasks
@9mm 9mm closed this as completed Oct 4, 2023
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

No branches or pull requests

2 participants