aboutsummaryrefslogtreecommitdiffstats
path: root/systray_darwin.m
diff options
context:
space:
mode:
authorjoesis2018-10-17 03:05:42 -0700
committerGitHub2018-10-17 03:05:42 -0700
commit89b3d9c45cc69f861868cc7f3159eba2b4cdfb22 (patch)
treed44d0e0f1eaba23282d2f15f602aba0941cd33b9 /systray_darwin.m
parent3fd1443dac5c8297999189fe28d5836b2b075b66 (diff)
parent1a665b2c73c12a4cdf5402daef46b1082a822e0d (diff)
downloadsystray-89b3d9c45cc69f861868cc7f3159eba2b4cdfb22.tar.bz2
Merge pull request #65 from jefvel/menu-item-icons
Made it possible to add icons to menu items on Mac
Diffstat (limited to 'systray_darwin.m')
-rw-r--r--systray_darwin.m22
1 files changed, 22 insertions, 0 deletions
diff --git a/systray_darwin.m b/systray_darwin.m
index f1dc7ac..a489bc4 100644
--- a/systray_darwin.m
+++ b/systray_darwin.m
@@ -124,6 +124,19 @@
[menuItem setHidden:TRUE];
}
+- (void)setMenuItemIcon:(NSArray*)imageAndMenuId {
+ NSImage* image = [imageAndMenuId objectAtIndex:0];
+ NSNumber* menuId = [imageAndMenuId objectAtIndex:1];
+
+ NSMenuItem* menuItem;
+ int existedMenuIndex = [menu indexOfItemWithRepresentedObject: menuId];
+ if (existedMenuIndex == -1) {
+ return;
+ }
+ menuItem = [menu itemAtIndex: existedMenuIndex];
+ menuItem.image = image;
+}
+
- (void) show_menu_item:(NSNumber*) menuId
{
NSMenuItem* menuItem;
@@ -163,6 +176,15 @@ void setIcon(const char* iconBytes, int length) {
runInMainThread(@selector(setIcon:), (id)image);
}
+void setMenuItemIcon(const char* iconBytes, int length, int menuId) {
+ NSData* buffer = [NSData dataWithBytes: iconBytes length:length];
+ NSImage *image = [[NSImage alloc] initWithData:buffer];
+ [image setSize:NSMakeSize(16, 16)];
+
+ NSNumber *mId = [NSNumber numberWithInt:menuId];
+ runInMainThread(@selector(setMenuItemIcon:), @[image, (id)mId]);
+}
+
void setTitle(char* ctitle) {
NSString* title = [[NSString alloc] initWithCString:ctitle
encoding:NSUTF8StringEncoding];