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 *(*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");

View File

@ -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;
}

View File

@ -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);
}