Adding option to hide status icon on MacOS. See #95

This commit is contained in:
Federico Terzi 2020-04-15 19:09:13 +02:00
parent 72f34b401b
commit 4adedbae43
5 changed files with 23 additions and 12 deletions

View File

@ -24,16 +24,18 @@
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// Setup status icon
myStatusItem = [[[NSStatusBar systemStatusBar] statusItemWithLength:NSSquareStatusItemLength] retain];
if (show_icon) {
myStatusItem = [[[NSStatusBar systemStatusBar] statusItemWithLength:NSSquareStatusItemLength] retain];
NSString *nsIconPath = [NSString stringWithUTF8String:icon_path];
NSImage *statusImage = [[NSImage alloc] initWithContentsOfFile:nsIconPath];
[statusImage setTemplate:YES];
NSString *nsIconPath = [NSString stringWithUTF8String:icon_path];
NSImage *statusImage = [[NSImage alloc] initWithContentsOfFile:nsIconPath];
[statusImage setTemplate:YES];
[myStatusItem.button setImage:statusImage];
[myStatusItem setHighlightMode:YES];
[myStatusItem.button setAction:@selector(statusIconClick:)];
[myStatusItem.button setTarget:self];
[myStatusItem.button setImage:statusImage];
[myStatusItem setHighlightMode:YES];
[myStatusItem.button setAction:@selector(statusIconClick:)];
[myStatusItem.button setTarget:self];
}
// Setup key listener
[NSEvent addGlobalMonitorForEventsMatchingMask:(NSEventMaskKeyDown | NSEventMaskFlagsChanged | NSEventMaskLeftMouseDown | NSEventMaskRightMouseDown)

View File

@ -26,11 +26,12 @@ extern "C" {
extern void * context_instance;
extern char * icon_path;
extern int32_t show_icon;
/*
* Initialize the AppDelegate and check for accessibility permissions
*/
int32_t initialize(void * context, const char * icon_path);
int32_t initialize(void * context, const char * icon_path, int32_t show_icon);
/*
* Start the event loop indefinitely. Blocking call.

View File

@ -33,15 +33,17 @@ extern "C" {
void * context_instance;
char * icon_path;
int32_t show_icon;
AppDelegate * delegate_ptr;
KeypressCallback keypress_callback;
IconClickCallback icon_click_callback;
ContextMenuClickCallback context_menu_click_callback;
int32_t initialize(void * context, const char * _icon_path) {
int32_t initialize(void * context, const char * _icon_path, int32_t _show_icon) {
context_instance = context;
icon_path = strdup(_icon_path);
show_icon = _show_icon;
AppDelegate *delegate = [[AppDelegate alloc] init];
delegate_ptr = delegate;

View File

@ -29,7 +29,7 @@ pub struct MacMenuItem {
#[allow(improper_ctypes)]
#[link(name="macbridge", kind="static")]
extern {
pub fn initialize(s: *const c_void, icon_path: *const c_char);
pub fn initialize(s: *const c_void, icon_path: *const c_char, show_icon: i32);
pub fn eventloop();
pub fn headless_eventloop();

View File

@ -83,7 +83,13 @@ impl MacContext {
register_context_menu_click_callback(context_menu_click_callback);
let status_icon_path = CString::new(status_icon_target.to_str().unwrap_or_default()).unwrap_or_default();
initialize(context_ptr, status_icon_path.as_ptr());
let show_icon = if config.show_icon {
1
}else{
0
};
initialize(context_ptr, status_icon_path.as_ptr(), show_icon);
}
context