JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
Inintial import
[now-playing-d.git] / now-playing-d.c
diff --git a/now-playing-d.c b/now-playing-d.c
new file mode 100644 (file)
index 0000000..7b2ec06
--- /dev/null
@@ -0,0 +1,79 @@
+/* now-playing-d.c
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include <stdio.h>
+#include <gtk/gtk.h>
+#include "eggtrayicon.h"
+
+
+char buf[1000];
+char* playing[2] = {&buf[0], &buf[500]};
+int playing_i = 0;
+
+
+// this gets called regularly by gtk
+static gboolean
+ticker(GtkWidget *widget) {
+       FILE * fd;
+       int len;
+
+       if (widget->window == NULL) {
+               return FALSE;
+       }
+
+       fd = fopen(TMP_FILE, "r");
+       if(fd == NULL) {
+               return TRUE;
+       }
+       len = fread(playing[playing_i], 1, 499, fd);
+       fclose(fd);
+       playing[playing_i][len] = 0;
+
+       if(strcmp(playing[playing_i], playing[1 - playing_i])) {
+               gtk_label_set_text(GTK_LABEL(widget), playing[playing_i]);
+       }
+
+       playing_i = 1 - playing_i;
+
+       // gtk_widget_queue_draw(widget);
+       return TRUE;
+}
+
+
+int
+main(int argc, char *argv[]) {
+       GtkWidget *label;
+       EggTrayIcon *egg;
+
+       // initialize GTK
+       gtk_set_locale();
+       gtk_init(&argc, &argv);
+
+       // make the widget
+       label = gtk_label_new("initializing...");
+       egg = egg_tray_icon_new("what's this string do?");
+       // nest and display the widget
+       gtk_container_add(GTK_CONTAINER(egg), label);
+       gtk_widget_show_all(GTK_WIDGET(egg));
+
+       // initialize and start ticker
+       playing[0][0] = 0;
+       playing[1][0] = 0;
+       g_timeout_add(1000, (GSourceFunc) ticker, (gpointer) label);
+
+       gtk_main();
+}