From: Linus Torvalds Date: Wed, 31 Aug 2011 02:48:00 +0000 (-0700) Subject: Create a gtk window X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=0ca546b31e5527713f11676bc965aa1ed8dac619;p=ext%2Fsubsurface.git Create a gtk window It doesn't *do* anything, but some day it will. Signed-off-by: Linus Torvalds --- diff --git a/Makefile b/Makefile index 675fb50..b69ddb2 100644 --- a/Makefile +++ b/Makefile @@ -2,10 +2,11 @@ CC=gcc CFLAGS=-Wall -Wno-pointer-sign -g parse: main.o parse.o - $(CC) $(LDLAGS) -o parse main.o parse.o `xml2-config --libs` + $(CC) $(LDLAGS) -o parse main.o parse.o `xml2-config --libs` \ + `pkg-config --libs gtk+-2.0` parse.o: parse.c dive.h $(CC) $(CFLAGS) -c `xml2-config --cflags` parse.c main.o: main.c dive.h - $(CC) $(CFLAGS) -c main.c + $(CC) $(CFLAGS) `pkg-config --cflags gtk+-2.0` -c main.c diff --git a/main.c b/main.c index 6da386c..adceca9 100644 --- a/main.c +++ b/main.c @@ -1,6 +1,9 @@ #include #include #include +#include +#include +#include #include "dive.h" @@ -43,13 +46,13 @@ static int sortfn(const void *_a, const void *_b) return 0; } +/* + * This doesn't really report anything at all. We just sort the + * dives, the GUI does the reporting + */ static void report_dives(void) { - int i; - qsort(dive_table.dives, dive_table.nr, sizeof(struct dive *), sortfn); - for (i = 0; i < dive_table.nr; i++) - show_dive(i+1, dive_table.dives[i]); } static void parse_argument(const char *arg) @@ -68,12 +71,28 @@ static void parse_argument(const char *arg) } while (*++p); } +static void on_destroy(GtkWidget* w, gpointer data) +{ + gtk_main_quit(); +} + +static gboolean on_expose(GtkWidget* w, GdkEventExpose* e, gpointer data) +{ + cairo_t* cr; + cr = gdk_cairo_create(w->window); + cairo_destroy(cr); + return FALSE; +} + int main(int argc, char **argv) { int i; + GtkWidget* win; parse_xml_init(); + gtk_init(&argc, &argv); + for (i = 1; i < argc; i++) { const char *a = argv[i]; @@ -83,7 +102,16 @@ int main(int argc, char **argv) } parse_xml_file(a); } + report_dives(); + + win = gtk_window_new(GTK_WINDOW_TOPLEVEL); + g_signal_connect(G_OBJECT(win), "destroy", G_CALLBACK(on_destroy), NULL); + g_signal_connect(G_OBJECT(win), "expose-event", G_CALLBACK(on_expose), NULL); + gtk_widget_set_app_paintable(win, TRUE); + gtk_widget_show_all(win); + + gtk_main(); return 0; }