Tried to see if we can fix up uiMainSteps() to not need parameters after all. Now to actually apply it.

This commit is contained in:
Pietro Gagliardi 2016-06-17 09:16:30 -04:00
parent 99545e8775
commit cc4c5f7bd5
3 changed files with 24 additions and 30 deletions

View File

@ -39,12 +39,6 @@ uiTab *mainTab;
uiBox *(*newhbox)(void); uiBox *(*newhbox)(void);
uiBox *(*newvbox)(void); uiBox *(*newvbox)(void);
static void stepsLoop(void *data)
{
while (uiMainStep(1))
;
}
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
uiInitOptions o; uiInitOptions o;
@ -167,8 +161,11 @@ int main(int argc, char *argv[])
uiControlShow(uiControl(w)); uiControlShow(uiControl(w));
if (!steps) if (!steps)
uiMain(); uiMain();
else else {
uiMainSteps(stepsLoop, NULL); uiMainSteps(NULL, NULL);
while (uiMainStep(1))
;
}
printf("after uiMain()\n"); printf("after uiMain()\n");
uiUninit(); uiUninit();
printf("after uiUninit()\n"); printf("after uiUninit()\n");

View File

@ -29,33 +29,25 @@ void uiFreeInitError(const char *err)
g_free((gpointer) err); g_free((gpointer) err);
} }
static gboolean (*iteration)(gboolean) = NULL;
void uiMain(void) void uiMain(void)
{ {
iteration = gtk_main_iteration_do;
gtk_main(); gtk_main();
} }
struct mainStepsData { static gboolean stepsQuit = FALSE;
void (*f)(void *);
void *data;
};
static gboolean mainSteps(gpointer data) static gboolean stepsIteration(gboolean block)
{ {
struct mainStepsData *d = (struct mainStepsData *) data; gtk_main_iteration_do(block);
return stepsQuit;
(*(d->f))(d->data);
// TODO call gtk_main_quit() here again?
return FALSE;
} }
void uiMainSteps(void (*f)(void *), void *data) void uiMainSteps(void (*f)(void *), void *data)
{ {
struct mainStepsData d; iteration = stepsIteration;
d.f = f;
d.data = data;
gdk_threads_add_idle(mainSteps, &d);
gtk_main();
} }
int uiMainStep(int wait) int uiMainStep(int wait)
@ -65,7 +57,7 @@ int uiMainStep(int wait)
block = FALSE; block = FALSE;
if (wait) if (wait)
block = TRUE; 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+) // 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 // we'll do it by using an idle callback
static gboolean quit(gpointer data) static gboolean quit(gpointer data)
{ {
gtk_main_quit(); if (iteration == stepsIteration)
stepsQuit = TRUE;
else
gtk_main_quit();
return FALSE; return FALSE;
} }

View File

@ -161,8 +161,8 @@ void uiWindowSetPosition(uiWindow *w, int x, int y)
// we need to wait for a configure-event // we need to wait for a configure-event
// thanks to hergertme in irc.gimp.net/#gtk+ // thanks to hergertme in irc.gimp.net/#gtk+
while (w->changingPosition) while (w->changingPosition)
if (gtk_main_iteration() != FALSE) if (!uiMainStep(1))
break; // stop early if gtk_main_quit() called break; // stop early if uiQuit() called
} }
void uiWindowCenter(uiWindow *w) void uiWindowCenter(uiWindow *w)
@ -186,6 +186,7 @@ void uiWindowCenter(uiWindow *w)
uiWindowSetPosition(w, x, y); uiWindowSetPosition(w, x, y);
} }
// TODO this and size changed get set during uiWindowDestroy
void uiWindowOnPositionChanged(uiWindow *w, void (*f)(uiWindow *, void *), void *data) void uiWindowOnPositionChanged(uiWindow *w, void (*f)(uiWindow *, void *), void *data)
{ {
w->onPositionChanged = f; 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 what happens if the size is already the current one?
// TODO a spurious size-allocate gets sent after this function returns // 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) void uiWindowSetContentSize(uiWindow *w, int width, int height)
{ {
w->changingSize = TRUE; w->changingSize = TRUE;
gtk_widget_set_size_request(w->childHolderWidget, width, height); gtk_widget_set_size_request(w->childHolderWidget, width, height);
while (w->changingSize) while (w->changingSize)
if (gtk_main_iteration() != FALSE) if (!uiMainStep(1))
break; // stop early if gtk_main_quit() called break; // stop early if uiQuit() called
gtk_widget_set_size_request(w->childHolderWidget, -1, -1); gtk_widget_set_size_request(w->childHolderWidget, -1, -1);
} }