#line 6 "flash.c-nw"
#include <config.h>
#include <Xm/Xm.h>
#include "w3a.h"
#include "globals.e"

static XtIntervalId flash_id = NULL;
static Pixel fg, bg;


static void flash_cb(XtPointer client_data, XtIntervalId *id)
{
    Pixel h;
    h = fg; fg = bg; bg = h;
    XtVaSetValues(flash, XmNforeground, fg, XmNbackground, bg, NULL);
    XFlush(XtDisplay(flash));
    flash_id = XtAppAddTimeOut(app_context, 500, flash_cb, flash);
}

EXPORT void start_flashing_light(void)
{
    if (XtIsRealized(flash)) XtMapWidget(flash);
    XtVaGetValues(flash, XmNforeground, &fg, XmNbackground, &bg, NULL);
    flash_id = XtAppAddTimeOut(app_context, 500, flash_cb, flash);
}

EXPORT void stop_flashing_light(void)
{
    if (flash_id) XtRemoveTimeOut(flash_id);
    if (XtIsRealized(flash)) XtUnmapWidget(flash);
}