Can XtAppNextEvent/XtDispatchEvent be called from a callback? - Motif

This is a discussion on Can XtAppNextEvent/XtDispatchEvent be called from a callback? - Motif ; With Motif prior to 2.0, can one call XtAppNextEvent and XtDispatchEvent from inside a callback ? Goal: in a callback that has a CPU intensive loop, I'd like to check for events every second and if there is an event, ...

+ Reply to Thread
Results 1 to 6 of 6

Thread: Can XtAppNextEvent/XtDispatchEvent be called from a callback?

  1. Can XtAppNextEvent/XtDispatchEvent be called from a callback?

    With Motif prior to 2.0, can one call XtAppNextEvent and XtDispatchEvent
    from inside a callback ?

    Goal: in a callback that has a CPU intensive loop, I'd like to check for
    events every second and if there is an event, dispatch it from within
    the callback. (for instance a STOP button would call another callback
    that would set a global flag telling the first callback to stop the loop).

    This simplies may things instead of having to use the WorcProc which
    requires full context saving and restoring for every iteration of that
    procedure for instance).

  2. Re: Can XtAppNextEvent/XtDispatchEvent be called from a callback?


    JF Mezei wrote:
    > With Motif prior to 2.0, can one call XtAppNextEvent and

    XtDispatchEvent
    > from inside a callback ?
    >
    > Goal: in a callback that has a CPU intensive loop, I'd like to check

    for
    > events every second and if there is an event, dispatch it from within
    > the callback. (for instance a STOP button would call another callback
    > that would set a global flag telling the first callback to stop the

    loop).
    >
    > This simplies may things instead of having to use the WorcProc which
    > requires full context saving and restoring for every iteration of

    that
    > procedure for instance).



  3. Re: Can XtAppNextEvent/XtDispatchEvent be called from a callback?

    > Goal: in a callback that has a CPU intensive loop, I'd like to check for
    > events every second and if there is an event, dispatch it from within
    > the callback. (for instance a STOP button would call another callback
    > that would set a global flag telling the first callback to stop the loop).
    >
    > This simplies may things instead of having to use the WorcProc which
    > requires full context saving and restoring for every iteration of that
    > procedure for instance).


    Exactly how do you expect to get a callback without running the event loop
    first?

    The answer is: you can't.

    For what you want to do you have to simply make a call to a routine often
    enough in your code that checks the current time. When a second has expired
    from the last call that checked events, that routine checks for and dispatches
    events.

    Be careful, though, since you don't want to block waiting for events!

    Also, beware of reentrancy problems.

    -Pete Zakel
    (phz@seeheader.nospam)

    "To be sure of hitting the target, shoot first and, whatever you hit,
    call it the target."

  4. Re: Can XtAppNextEvent/XtDispatchEvent be called from a callback?

    Pete nospam Zakel wrote:
    > For what you want to do you have to simply make a call to a routine often
    > enough in your code that checks the current time. When a second has expired
    > from the last call that checked events, that routine checks for and dispatches
    > events.


    My question is whether , from within a callback (which is called by
    XtDispatchEvent), I can call XtDisplatchEvent to process events that
    arrive while the original callback is still executing.

  5. Re: Can XtAppNextEvent/XtDispatchEvent be called from a callback?

    JF Mezei wrote:
    > Pete nospam Zakel wrote:
    >
    >>For what you want to do you have to simply make a call to a routine often
    >>enough in your code that checks the current time. When a second has expired
    >>from the last call that checked events, that routine checks for and dispatches
    >>events.

    >
    >
    > My question is whether , from within a callback (which is called by
    > XtDispatchEvent), I can call XtDisplatchEvent to process events that
    > arrive while the original callback is still executing.


    Basically, yes. What you may *not* do is choose what events you
    dispatch, you have to process them all. This is what I do for dialogs:

    (1) In the activation callback for the widget which is supposed to
    'popup' the dialog, I load the dialog (like changing some labels),
    manage it, then call this function:

    (2)

    void
    hpMotifDialogLoop(Widget dlg)
    {
    XtAppContext app_context;
    app_context = XtWidgetToApplicationContext(dlg);
    while (XtIsManaged(dlg)) {
    XEvent event;
    if (test_some_global_error_flag()) {
    modally_show_error_message(dlg, ...);
    /* Simulate cancel */
    XtCallCallbacks(dlg, XmNcancelCallback, NULL);
    return;
    }
    XtAppNextEvent(app_context, &event);
    hpMotifFixKeyboardLocks(dlg, &event);
    XtDispatchEvent(&event);
    }
    }

    Cheers,
    --
    Michel Bardiaux
    Peaktime Belgium S.A. Bd. du Souverain, 191 B-1160 Bruxelles
    Tel : +32 2 790.29.41

  6. Re: Can XtAppNextEvent/XtDispatchEvent be called from a callback?

    Michel Bardiaux wrote:
    > Basically, yes. What you may *not* do is choose what events you
    > dispatch, you have to process them all. This is what I do for dialogs:


    Merci !

    It greatly helps to be able to popup some dialog to ask for missing
    information and then continue the original callback with the information
    already obtained rather than having to store that information in a queue
    and hope the callback gets called again once the dialog is over.

+ Reply to Thread