diff --git a/platform/darwin/tray.m b/platform/darwin/tray.m index c4112df..1c141d5 100644 --- a/platform/darwin/tray.m +++ b/platform/darwin/tray.m @@ -82,6 +82,9 @@ void native_loop() { [NSApp run]; } +void external_main_loop() { +} + void exit_loop() { // Clear all notifications. [[NSUserNotificationCenter defaultUserNotificationCenter] removeAllDeliveredNotifications]; diff --git a/platform/linux/tray.c b/platform/linux/tray.c index 4e9f286..ea2faab 100644 --- a/platform/linux/tray.c +++ b/platform/linux/tray.c @@ -9,6 +9,7 @@ #include #include #include +#include static const char *icon = NULL; static size_t iconSize = 0; @@ -29,6 +30,14 @@ void _tray_callback(GtkMenuItem *item, gpointer user_data) // TODO: Implement. void display_notification(int id, const char* title, const char* body, struct image imageData, double duration) { + char app_name[32]; + snprintf(app_name, sizeof(app_name), "%08x", id); + notify_init(app_name); + NotifyNotification* n = notify_notification_new (title, + body, + 0); + notify_notification_set_timeout(n, (int)(1000*duration)); // milliseconds + notify_notification_show(n, 0); } // TODO: Implement. @@ -98,7 +107,8 @@ void create_indicator(void *handle) static void tray_icon_on_menu(GtkStatusIcon *status_icon, guint button, guint activate_time, gpointer user_data) { - gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, 0, gtk_get_current_event_time()); + // gtk_menu_popup_at_widget(GTK_MENU(menu), NULL, GDK_GRAVITY_SOUTH_EAST, NULL, gtk_get_current_event_time()); + gtk_menu_popup_at_pointer(GTK_MENU(menu), NULL); } void create_status_icon() @@ -137,9 +147,13 @@ void init(const char* title, struct image imageData) } } +void external_main_loop() { + gtk_widget_show_all(menu); +} + void native_loop() { - gtk_widget_show_all(menu); + external_main_loop(); gtk_main (); } @@ -149,4 +163,5 @@ void exit_loop() } + #endif // NATIVE_C diff --git a/platform/windows/tray.c b/platform/windows/tray.c index 104728a..fb587ee 100644 --- a/platform/windows/tray.c +++ b/platform/windows/tray.c @@ -43,6 +43,10 @@ void clear_menu_items() } } +void external_main_loop () +{ +} + void native_loop() { MSG msg; diff --git a/trayhost.go b/trayhost.go index 928be1a..b00625f 100644 --- a/trayhost.go +++ b/trayhost.go @@ -9,8 +9,8 @@ import ( #cgo darwin CFLAGS: -DDARWIN -x objective-c #cgo darwin LDFLAGS: -framework Cocoa -#cgo linux pkg-config: gtk+-2.0 -#cgo linux CFLAGS: -DLINUX -I/usr/include/libappindicator-0.1 +#cgo linux pkg-config: gtk+-3.0 appindicator3-0.1 libnotify +#cgo linux CFLAGS: -DLINUX -Wno-deprecated-declarations #cgo linux LDFLAGS: -ldl #cgo windows CFLAGS: -DWIN32 @@ -66,6 +66,11 @@ func Exit() { C.exit_loop() } +// init widget for running in other gtk_main loop +func InitWidget() { + C.external_main_loop() +} + // SeparatorMenuItem creates a separator MenuItem. func SeparatorMenuItem() MenuItem { return MenuItem{Title: ""} }