Skip to content

Commit

Permalink
Add SetStatusIcon
Browse files Browse the repository at this point in the history
  • Loading branch information
tmc committed Dec 29, 2017
1 parent a78e9bf commit 5171e9d
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 9 deletions.
23 changes: 15 additions & 8 deletions platform/darwin/tray.m
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
#import <Cocoa/Cocoa.h>

NSMenu * appMenu;
NSStatusItem * appStatusItem;
char * clipboardString;

extern void tray_callback(int itemId);
extern BOOL tray_enabled(int itemId);
extern void notification_callback();
extern struct image invert_png_image(struct image img);

void set_status_item_icon(struct image img);

@interface ManageHandler : NSObject<NSUserNotificationCenterDelegate>
- (void)manage:(id)sender;
- (BOOL)validateMenuItem:(NSMenuItem *)menuItem;
Expand Down Expand Up @@ -112,6 +115,16 @@ int init(const char * title, struct image img) {
[self userNotificationCenter: nil didActivateNotification: launchNotification];
}*/

appStatusItem = [[[NSStatusBar systemStatusBar] statusItemWithLength:NSSquareStatusItemLength] retain];
[appStatusItem setMenu:appMenu];
[appStatusItem setHighlightMode:YES];
[appStatusItem setToolTip:[NSString stringWithUTF8String:title]];
set_status_item_icon(img);

return 0;
}

void set_status_item_icon(struct image img) {
NSSize iconSize = NSMakeSize(16, 16);
NSImage * icon = [[NSImage alloc] initWithSize:iconSize];
NSData * iconData = [NSData dataWithBytes:img.bytes length:img.length];
Expand All @@ -123,14 +136,8 @@ int init(const char * title, struct image img) {
NSData * icon2Data = [NSData dataWithBytes:img.bytes length:img.length];
[icon2 addRepresentation:[NSBitmapImageRep imageRepWithData:icon2Data]];

NSStatusItem * statusItem = [[[NSStatusBar systemStatusBar] statusItemWithLength:NSSquareStatusItemLength] retain];
[statusItem setMenu:appMenu];
[statusItem setImage:icon];
[statusItem setAlternateImage:icon2];
[statusItem setHighlightMode:YES];
[statusItem setToolTip:[NSString stringWithUTF8String:title]];

return 0;
[appStatusItem setImage:icon];
[appStatusItem setAlternateImage:icon2];
}

void set_clipboard_string(const char * string) {
Expand Down
3 changes: 3 additions & 0 deletions platform/linux/tray.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ void display_notification(int id, const char* title, const char* body, struct im
// TODO: Implement.
void clear_menu_items() {}

// TODO: Implement.
void set_status_item_icon(struct image img) {}

// TODO: Implement.
struct clipboard_content get_clipboard_content()
{
Expand Down
4 changes: 4 additions & 0 deletions platform/windows/tray.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,3 +225,7 @@ struct clipboard_content get_clipboard_content() {
void display_notification(int notificationId, const char * title, const char * body, struct image img, double timeout) {
// TODO: Implement.
}

// TODO: Implement.
void set_status_item_icon(struct image img) {}

7 changes: 7 additions & 0 deletions trayhost.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ func Initialize(title string, imageData []byte, items []MenuItem) {
}
}

// SetStatusIcon replaces the icon image data.
func SetStatusIcon(imageData []byte) {
img, freeImg := create_image(Image{Kind: "png", Bytes: imageData})
defer freeImg()
C.set_status_item_icon(img)
}

// EnterLoop enters main loop.
func EnterLoop() {
C.native_loop()
Expand Down
5 changes: 4 additions & 1 deletion trayhost_exports.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@ func invertPngImage(imageData []byte) []byte {
panic(err)
}

invertImageNrgba(m.(*image.NRGBA))
switch m.(type) {
case *image.NRGBA:
invertImageNrgba(m.(*image.NRGBA))
}

var buf bytes.Buffer
err = png.Encode(&buf, m)
Expand Down

0 comments on commit 5171e9d

Please sign in to comment.