Re: Event callbacks for ordinary forms - how?

Steve Lamont (spl@szechuan.ucsd.edu)
Thu, 26 Dec 96 09:30:55 PST

To subscribers of the xforms list from spl@szechuan.ucsd.edu (Steve Lamont) :

> Steve> You might consider registering a signal callback and firing a SIGALRM
> Steve> at some appropriate interval. See the Appendix section A.6 (Signals)
> Steve> for more detail.
>
> How does this solve my problem of finding out whether the program is iconified
> or not?

Sorry. I thought you were more interested in knowing the elapsed
time.

As far as I'm able to determine, you can find out whether your window
has been iconified only indirectly, by checking the map state.

If you're using a signal callback to check your elapsed time, you can
check the map state of the window as follows:

FD_try *fd_try;

[...]

fd_try = create_form_try();

[...]

fl_add_signal_callback( SIGALRM, alarm_trap, ( void *) fd_try );
alarm( 1 );

[...]

void alarm_trap( int signal, void *data )

{

FD_try *fd_try = ( FD_try *) data;
XWindowAttributes attributes;

XGetWindowAttributes( fl_get_display(), fd_try->try->window,
&attributes );

if ( attributes.map_state == IsUnmapped )
/* Do your iconified stuff */
else
/* Do your non-iconified stuff */

alarm( 1 );

}

You can also catch the UnmapNotify event by registering a raw
callback:

fl_show_form(fd_try->try,FL_PLACE_CENTER,FL_FULLBORDER,"try");
fl_register_raw_callback( fd_try->try, FL_ALL_EVENT, event_trap );

[...]

int event_trap( FL_FORM *form, void *event )

{

XEvent *xevent = ( XEvent *) event;

if ( xevent->type == UnmapNotify )
/* Do your iconified stuff */
else if ( xevent->type == MapNotify )
/* Do your non-iconified stuff */

return 0; /* Let XForms process it if it wants to */

}

spl