Skip to content

Commit

Permalink
for #363 - working Windows implementation
Browse files Browse the repository at this point in the history
* uses older gtk_status_icon calls
* saves a copy for sequent calls (updates) which matches the
  linux GNotification behavior.
  • Loading branch information
Cecil committed Aug 5, 2017
1 parent b1291c8 commit f44fe03
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Tests/systray/note.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
ctr = 0;
button "Notify" do
ctr += 1
systray title: "Notify Test", message: "message ##{ctr}"
systray title: "Notify Test", message: "message ##{ctr}", icon: "#{DIR}/static/shoes-icon.png"
end
end
end
8 changes: 7 additions & 1 deletion shoes/native/gtk.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,19 @@ void shoes_native_init() {
#if !defined(RUBY_HTTP) && !defined(SHOES_GTK_WIN32)
curl_global_init(CURL_GLOBAL_ALL);
#endif
#ifndef SHOES_GTK_WIN32
/* try using gtk_application_new() instead of gtk_init
*/
int status;
char *empty = NULL;
shoes_GtkApp = gtk_application_new ("org.gnome.example", G_APPLICATION_FLAGS_NONE);
shoes_GApp = (G_APPLICATION (shoes_GtkApp));
g_signal_connect (shoes_GtkApp, "activate", G_CALLBACK (shoes_gtk_app_activate), NULL);
status = g_application_run (G_APPLICATION (shoes_GtkApp), 0, NULL);
status = g_application_run (G_APPLICATION (shoes_GtkApp), 0, &empty);
//gtk_init(NULL, NULL);
#else
gtk_init(NULL, NULL);
#endif
}

void shoes_native_cleanup(shoes_world_t *world) {
Expand Down
23 changes: 18 additions & 5 deletions shoes/native/gtk/gtksystray.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,27 @@
#include "shoes/types/native.h"
#include "shoes/internal.h"
#include "shoes/native/gtk/gtksystray.h"

// This doesn't work so don't worry about purity
// This may not work so don't worry about purity yet
extern GApplication *shoes_GApp;
#ifndef SHOES_GTK_WIN32
void shoes_native_systray(char *title, char *message, char *path) {
GApplication *gapp = g_application_get_default();
GNotification *note;
note = g_notification_new (title);
g_notification_set_body (note, message);
// GFile *iconf = g_file_new_for_path (const char *path);
// GIcon *icon = g_file_icon_new (iconf);
g_application_send_notification (gapp, "Shoes", note);
GFile *iconf = g_file_new_for_path (path);
GIcon *icon = g_file_icon_new (iconf);
g_notification_set_icon(note, icon);
g_application_send_notification (shoes_GApp, "Shoes", note);
}
#else
// try older gtk_status_icon for Windows to see what happens
static GtkStatusIcon *stsicon = NULL;
void shoes_native_systray(char *title, char *message, char *path) {
if (stsicon == NULL) {
stsicon = gtk_status_icon_new_from_file(path);
}
gtk_status_icon_set_title(stsicon, title);
gtk_status_icon_set_tooltip_text(stsicon, message);
}
#endif

0 comments on commit f44fe03

Please sign in to comment.