X-Git-Url: https://jasonwoof.com/gitweb/?p=now-playing-d.git;a=blobdiff_plain;f=now-playing-d.c;fp=now-playing-d.c;h=7b2ec063a409eb5a98700f06e15a326e5887f8de;hp=0000000000000000000000000000000000000000;hb=c1b9cf2a3e8e380738402381c585f9e282cbc39f;hpb=353f205d1b74d10acc4749605dd2234c2d852a76 diff --git a/now-playing-d.c b/now-playing-d.c new file mode 100644 index 0000000..7b2ec06 --- /dev/null +++ b/now-playing-d.c @@ -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 . + * + */ + +#include +#include +#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(); +}