-
-
Couldn't load subscription status.
- Fork 963
Desktop: Mac native menu bar #3301
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
Merged
+458
−45
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
7b1ec73
macos native menu bar
timon-schelling b5ff871
fix nix build
timon-schelling d260abd
Add shortcut symbols to menu
timon-schelling 280ea92
fix fmt
timon-schelling 40a315b
Merge branch 'master' into desktop-mac-native-menu-bar
timon-schelling 9e32d0f
fix vendoring
timon-schelling b11cb5e
cleanup intercept frontend message
timon-schelling 5fbf325
accept into editor message in queue function
timon-schelling ea7e5ce
Merge branch 'master' into desktop-mac-native-menu-bar
timon-schelling File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
Cargo.lock
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
desktop/src/gpu_context.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
desktop/src/persist.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
desktop/src/render/graphics_state.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
desktop/src/window/mac/menu.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| use muda::Menu as MudaMenu; | ||
| use muda::accelerator::Accelerator; | ||
| use muda::{AboutMetadataBuilder, CheckMenuItem, IsMenuItem, MenuEvent, MenuId, MenuItem, MenuItemKind, PredefinedMenuItem, Submenu}; | ||
|
|
||
| use crate::event::{AppEvent, AppEventScheduler}; | ||
| use crate::wrapper::messages::MenuItem as WrapperMenuItem; | ||
|
|
||
| pub(super) struct Menu { | ||
| inner: MudaMenu, | ||
| } | ||
|
|
||
| impl Menu { | ||
| pub(super) fn new(event_scheduler: AppEventScheduler, app_name: &str) -> Self { | ||
| let about = PredefinedMenuItem::about(None, Some(AboutMetadataBuilder::new().name(Some(app_name)).build())); | ||
| let hide = PredefinedMenuItem::hide(None); | ||
| let hide_others = PredefinedMenuItem::hide_others(None); | ||
| let show_all = PredefinedMenuItem::show_all(None); | ||
| let quit = PredefinedMenuItem::quit(None); | ||
| let app_submenu = Submenu::with_items( | ||
| "", | ||
| true, | ||
| &[&about, &PredefinedMenuItem::separator(), &hide, &hide_others, &show_all, &PredefinedMenuItem::separator(), &quit], | ||
| ) | ||
| .unwrap(); | ||
|
|
||
| let menu = MudaMenu::new(); | ||
| menu.prepend(&app_submenu).unwrap(); | ||
|
|
||
| menu.init_for_nsapp(); | ||
|
|
||
| MenuEvent::set_event_handler(Some(move |event: MenuEvent| { | ||
| if let Some(id) = menu_id_to_u64(event.id()) { | ||
| event_scheduler.schedule(AppEvent::MenuEvent { id }); | ||
| } | ||
| })); | ||
|
|
||
| Menu { inner: menu } | ||
| } | ||
|
|
||
| pub(super) fn update(&self, entries: Vec<WrapperMenuItem>) { | ||
| // remove all items except the first (app menu) | ||
| self.inner.items().iter().skip(1).for_each(|item: &muda::MenuItemKind| { | ||
| self.inner.remove(menu_item_kind_to_dyn(item)).unwrap(); | ||
| }); | ||
|
|
||
| let items = menu_items_from_wrapper(entries); | ||
| let items = items.iter().map(|item| menu_item_kind_to_dyn(item)).collect::<Vec<&dyn IsMenuItem>>(); | ||
| self.inner.append_items(items.as_ref()).unwrap(); | ||
| } | ||
| } | ||
|
|
||
| fn menu_items_from_wrapper(entries: Vec<WrapperMenuItem>) -> Vec<MenuItemKind> { | ||
| let mut menu_items: Vec<MenuItemKind> = Vec::new(); | ||
| for entry in entries { | ||
| match entry { | ||
| WrapperMenuItem::Action { id, text, enabled, shortcut } => { | ||
| let id = u64_to_menu_id(id); | ||
| let accelerator = shortcut.map(|s| Accelerator::new(Some(s.modifiers), s.key)); | ||
| let item = MenuItem::with_id(id, text, enabled, accelerator); | ||
| menu_items.push(MenuItemKind::MenuItem(item)); | ||
| } | ||
| WrapperMenuItem::Checkbox { id, text, enabled, shortcut, checked } => { | ||
| let id = u64_to_menu_id(id); | ||
| let accelerator = shortcut.map(|s| Accelerator::new(Some(s.modifiers), s.key)); | ||
| let check = CheckMenuItem::with_id(id, text, enabled, checked, accelerator); | ||
| menu_items.push(MenuItemKind::Check(check)); | ||
| } | ||
| WrapperMenuItem::SubMenu { text: name, items, .. } => { | ||
| let items = menu_items_from_wrapper(items); | ||
| let items = items.iter().map(|item| menu_item_kind_to_dyn(item)).collect::<Vec<&dyn IsMenuItem>>(); | ||
| let submenu = Submenu::with_items(name, true, &items).unwrap(); | ||
| menu_items.push(MenuItemKind::Submenu(submenu)); | ||
| } | ||
| WrapperMenuItem::Separator => { | ||
| let separator = PredefinedMenuItem::separator(); | ||
| menu_items.push(MenuItemKind::Predefined(separator)); | ||
| } | ||
| } | ||
| } | ||
| menu_items | ||
| } | ||
|
|
||
| fn menu_item_kind_to_dyn(item: &MenuItemKind) -> &dyn IsMenuItem { | ||
| match item { | ||
| MenuItemKind::MenuItem(i) => i, | ||
| MenuItemKind::Submenu(i) => i, | ||
| MenuItemKind::Predefined(i) => i, | ||
| MenuItemKind::Check(i) => i, | ||
| MenuItemKind::Icon(i) => i, | ||
| } | ||
| } | ||
|
|
||
| fn u64_to_menu_id(id: u64) -> String { | ||
| format!("{id:08x}") | ||
| } | ||
|
|
||
| fn menu_id_to_u64(id: &MenuId) -> Option<u64> { | ||
| u64::from_str_radix(&id.0, 16).ok() | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.