Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

some linux support #21

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions platform/darwin/tray.m
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ void native_loop() {
[NSApp run];
}

void external_main_loop() {
}

void exit_loop() {
// Clear all notifications.
[[NSUserNotificationCenter defaultUserNotificationCenter] removeAllDeliveredNotifications];
Expand Down
19 changes: 17 additions & 2 deletions platform/linux/tray.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <string.h>
#include <libappindicator/app-indicator.h>
#include <libnotify/notify.h>

static const char *icon = NULL;
static size_t iconSize = 0;
Expand All @@ -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.
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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 ();
}

Expand All @@ -149,4 +163,5 @@ void exit_loop()
}



#endif // NATIVE_C
4 changes: 4 additions & 0 deletions platform/windows/tray.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ void clear_menu_items()
}
}

void external_main_loop ()
{
}

void native_loop()
{
MSG msg;
Expand Down
9 changes: 7 additions & 2 deletions trayhost.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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: ""} }

Expand Down