diff options
| author | ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> | 2024-05-14 17:46:25 +0200 |
|---|---|---|
| committer | ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> | 2024-05-14 17:46:25 +0200 |
| commit | 79c3db48cf593ccbe64f6c845af0777caebde2a8 (patch) | |
| tree | 42cdb8075c572ae089f3fd596876692ecd4fe978 /src/Fl_MacOS_Sys_Menu_Bar.mm | |
| parent | ea962375255190b5e641783ff193cff06ff616c6 (diff) | |
New member function Fl_Menu_Bar::play_menu(const char *title)
Diffstat (limited to 'src/Fl_MacOS_Sys_Menu_Bar.mm')
| -rw-r--r-- | src/Fl_MacOS_Sys_Menu_Bar.mm | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/Fl_MacOS_Sys_Menu_Bar.mm b/src/Fl_MacOS_Sys_Menu_Bar.mm index d51734729..aa8560966 100644 --- a/src/Fl_MacOS_Sys_Menu_Bar.mm +++ b/src/Fl_MacOS_Sys_Menu_Bar.mm @@ -726,4 +726,36 @@ void fl_mac_set_about(Fl_Callback *cb, void *user_data, int shortcut) { Fl_Sys_Menu_Bar::about(cb, user_data); } + +void Fl_MacOS_Sys_Menu_Bar_Driver::play_menu(const char *menu_name) { + // Use the accessibility interface to programmatically open a menu of the system menubar + char *ts = remove_ampersand(menu_name); + NSString *mac_name = [NSString stringWithUTF8String:ts]; + free(ts); + AXUIElementRef appElement = AXUIElementCreateApplication(getpid()); + AXUIElementRef menuBar; + AXError error = AXUIElementCopyAttributeValue(appElement, kAXMenuBarAttribute, (CFTypeRef *)&menuBar); + if (error) return; + CFIndex count = -1; + error = AXUIElementGetAttributeValueCount(menuBar, kAXChildrenAttribute, &count); + if (error) { CFRelease(menuBar); return; } + NSArray *children = nil; + error = AXUIElementCopyAttributeValues(menuBar, kAXChildrenAttribute, 0, count, (CFArrayRef *)&children); + if (error) { CFRelease(menuBar); return; } + for (id child in children) { + AXUIElementRef element = (AXUIElementRef)child; + id title; + AXError error = AXUIElementCopyAttributeValue(element, kAXTitleAttribute, (CFTypeRef *)&title); + if (!error && [title isEqualToString:mac_name]) { + AXUIElementPerformAction(element, kAXPressAction); + CFRelease(title); + break; + } + CFRelease(title); + } + CFRelease(menuBar); + [children release]; + CFRelease(appElement); +} + #endif /* __APPLE__ */ |
