From 3bfe7aa50cdd8998ee818af9902fbcc0b6540895 Mon Sep 17 00:00:00 2001 From: "Serge A. Zaitsev" Date: Mon, 9 Jan 2017 14:49:57 +0200 Subject: [PATCH] fixed init status on macos, moved tray icon paths to #ifdef block --- example.c | 25 +++++++++++++++---------- tray.h | 2 +- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/example.c b/example.c index 62d6c51..d79e8ef 100644 --- a/example.c +++ b/example.c @@ -3,6 +3,17 @@ #include "tray.h" +#if TRAY_APPINDICATOR +#define TRAY_ICON1 "indicator-messages" +#define TRAY_ICON2 "indicator-messages-new" +#elif TRAY_APPKIT +#define TRAY_ICON1 "icon.png" +#define TRAY_ICON2 "icon.png" +#elif TRAY_WINAPI +#define TRAY_ICON1 "icon.ico" +#define TRAY_ICON2 "icon.ico" +#endif + static struct tray tray; static void toggle_cb(struct tray_menu *item) { @@ -13,10 +24,10 @@ static void toggle_cb(struct tray_menu *item) { static void hello_cb(struct tray_menu *item) { printf("hello cb\n"); - if (strcmp(tray.icon, "indicator-messages") == 0) { - tray.icon = "indicator-messages-new"; + if (strcmp(tray.icon, TRAY_ICON1) == 0) { + tray.icon = TRAY_ICON2; } else { - tray.icon = "indicator-messages"; + tray.icon = TRAY_ICON1; } tray_update(&tray); } @@ -27,6 +38,7 @@ static void quit_cb(struct tray_menu *item) { } static struct tray tray = { + .icon = TRAY_ICON1, .menu = (struct tray_menu[]){{"Hello", 0, 0, hello_cb, NULL}, {"Checked", 0, 1, toggle_cb, NULL}, {"Disabled", 1, 0, NULL, NULL}, @@ -36,13 +48,6 @@ static struct tray tray = { }; int main(int argc, char *argv[]) { -#if TRAY_APPINDICATOR - tray.icon = "indicator-messages-new"; -#elif TRAY_COCOA - tray.icon = "icon.png"; -#elif TRAY_WINAPI - tray.icon = "icon.ico"; -#endif if (tray_init(&tray) < 0) { printf("failed to create tray\n"); return 1; diff --git a/tray.h b/tray.h index aac43f9..458716f 100644 --- a/tray.h +++ b/tray.h @@ -108,7 +108,7 @@ static int tray_init(struct tray *tray) { tray_update(tray); [NSApp activateIgnoringOtherApps:YES]; - return -1; + return 0; } static int tray_loop(int blocking) {