diff --git a/test/main.c b/test/main.c index e69feee7..1ae5ec12 100644 --- a/test/main.c +++ b/test/main.c @@ -39,12 +39,6 @@ uiTab *mainTab; uiBox *(*newhbox)(void); uiBox *(*newvbox)(void); -static void stepsLoop(void *data) -{ - while (uiMainStep(1)) - ; -} - int main(int argc, char *argv[]) { uiInitOptions o; @@ -167,8 +161,11 @@ int main(int argc, char *argv[]) uiControlShow(uiControl(w)); if (!steps) uiMain(); - else - uiMainSteps(stepsLoop, NULL); + else { + uiMainSteps(NULL, NULL); + while (uiMainStep(1)) + ; + } printf("after uiMain()\n"); uiUninit(); printf("after uiUninit()\n"); diff --git a/unix/main.c b/unix/main.c index 59590886..bdd22eeb 100644 --- a/unix/main.c +++ b/unix/main.c @@ -29,33 +29,25 @@ void uiFreeInitError(const char *err) g_free((gpointer) err); } +static gboolean (*iteration)(gboolean) = NULL; + void uiMain(void) { + iteration = gtk_main_iteration_do; gtk_main(); } -struct mainStepsData { - void (*f)(void *); - void *data; -}; +static gboolean stepsQuit = FALSE; -static gboolean mainSteps(gpointer data) +static gboolean stepsIteration(gboolean block) { - struct mainStepsData *d = (struct mainStepsData *) data; - - (*(d->f))(d->data); - // TODO call gtk_main_quit() here again? - return FALSE; + gtk_main_iteration_do(block); + return stepsQuit; } void uiMainSteps(void (*f)(void *), void *data) { - struct mainStepsData d; - - d.f = f; - d.data = data; - gdk_threads_add_idle(mainSteps, &d); - gtk_main(); + iteration = stepsIteration; } int uiMainStep(int wait) @@ -65,7 +57,7 @@ int uiMainStep(int wait) block = FALSE; if (wait) block = TRUE; - return gtk_main_iteration_do(block) == FALSE; + return (*iteration)(block) == FALSE; } // gtk_main_quit() may run immediately, or it may wait for other pending events; "it depends" (thanks mclasen in irc.gimp.net/#gtk+) @@ -73,7 +65,10 @@ int uiMainStep(int wait) // we'll do it by using an idle callback static gboolean quit(gpointer data) { - gtk_main_quit(); + if (iteration == stepsIteration) + stepsQuit = TRUE; + else + gtk_main_quit(); return FALSE; } diff --git a/unix/window.c b/unix/window.c index bd75b9b5..71e47aa9 100644 --- a/unix/window.c +++ b/unix/window.c @@ -161,8 +161,8 @@ void uiWindowSetPosition(uiWindow *w, int x, int y) // we need to wait for a configure-event // thanks to hergertme in irc.gimp.net/#gtk+ while (w->changingPosition) - if (gtk_main_iteration() != FALSE) - break; // stop early if gtk_main_quit() called + if (!uiMainStep(1)) + break; // stop early if uiQuit() called } void uiWindowCenter(uiWindow *w) @@ -186,6 +186,7 @@ void uiWindowCenter(uiWindow *w) uiWindowSetPosition(w, x, y); } +// TODO this and size changed get set during uiWindowDestroy void uiWindowOnPositionChanged(uiWindow *w, void (*f)(uiWindow *, void *), void *data) { w->onPositionChanged = f; @@ -203,13 +204,14 @@ void uiWindowContentSize(uiWindow *w, int *width, int *height) // TODO what happens if the size is already the current one? // TODO a spurious size-allocate gets sent after this function returns +// TODO can't reduce the size this way void uiWindowSetContentSize(uiWindow *w, int width, int height) { w->changingSize = TRUE; gtk_widget_set_size_request(w->childHolderWidget, width, height); while (w->changingSize) - if (gtk_main_iteration() != FALSE) - break; // stop early if gtk_main_quit() called + if (!uiMainStep(1)) + break; // stop early if uiQuit() called gtk_widget_set_size_request(w->childHolderWidget, -1, -1); }