diff --git a/window_unix.c b/window_unix.c index ba9b7ef6..c4ec6d4c 100644 --- a/window_unix.c +++ b/window_unix.c @@ -8,6 +8,21 @@ struct uiWindow { void *onClosingData; }; +static gboolean onClosing(GtkWidget *win, GdkEvent *e, gpointer data) +{ + uiWindow *w = (uiWindow *) data; + + // return exact values just in case + if ((*(w->onClosing))(w, w->onClosingData)) + return FALSE; + return TRUE; +} + +static int defaultOnClosing(uiWindow *w, void *data) +{ + return 1; +} + static void onDestroy(GtkWidget *widget, gpointer data) { uiWindow *w = (uiWindow *) data; @@ -23,9 +38,11 @@ uiWindow *uiNewWindow(char *title, int width, int height) w->widget = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_title(GTK_WINDOW(w->widget), title); gtk_window_resize(GTK_WINDOW(w->widget), width, height); + g_signal_connect(w->widget, "delete-event", G_CALLBACK(onClosing), w); g_signal_connect(w->widget, "destroy", G_CALLBACK(onDestroy), w); w->container = newContainer(); gtk_container_add(GTK_CONTAINER(w->widget), w->container); + w->onClosing = defaultOnClosing; return w; } @@ -59,21 +76,10 @@ void uiWindowHide(uiWindow *w) gtk_widget_hide(w->widget); } -static gboolean onClosing(GtkWidget *win, GdkEvent *e, gpointer data) -{ - uiWindow *w = (uiWindow *) data; - - // return exact values just in case - if ((*(w->onClosing))(w, w->onClosingData)) - return FALSE; - return TRUE; -} - void uiWindowOnClosing(uiWindow *w, int (*f)(uiWindow *, void *), void *data) { w->onClosing = f; w->onClosingData = data; - g_signal_connect(w->widget, "delete-event", G_CALLBACK(onClosing), w); } void uiWindowSetChild(uiWindow *w, uiControl *c) diff --git a/window_windows.c b/window_windows.c index 20fbbd9b..00d8c1ae 100644 --- a/window_windows.c +++ b/window_windows.c @@ -96,7 +96,6 @@ uiWindow *uiNewWindow(char *title, int width, int height) WCHAR *wtitle; w = uiNew(uiWindow); - // TODO move other cases of default events here relative w->onClosing = defaultOnClosing; adjust.left = 0;