>             Ur's idea seems to work. Can u post a pseudo code so that I
> can
> easily implement becase I never worked on events and handle.
> 

Well, OK, here's the basic idea laid out in code. 

Seems to kind of work - though bearing in mind Albrecht's observations, it may 
not be the right solution, and probably not all that robust.
Perhaps it will get you started in the right direction...


/*****************************************************************************/
//   fltk-config --compile idle-window.cxx

/* Standard headers */
#include <stdlib.h>
#include <stdio.h>

/* Fltk headers */
#include <Fl/Fl.h>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Button.H>
#include <FL/names.h>

#define IDLE_CHECK_TIME 5.0

/*****************************************************************************/
/* This class provides an idle-detecting window */
class idle_win : public Fl_Double_Window {
        int handle(int event);

public:
        idle_win(int w, int h, const char *L);

    unsigned had_events;
};

/*****************************************************************************/
/* Constructor */
idle_win::idle_win(int w, int h, const char *L) : Fl_Double_Window(w,h,L){
    had_events = 0;
} // Constructor

/*****************************************************************************/
int idle_win::handle(int ev) {

        switch(ev) {
        case FL_ENTER:
        case FL_MOVE:
        case FL_LEAVE:
        case FL_PUSH:
        case FL_DRAG:
        case FL_RELEASE:
        // and some other events?
        had_events ++;
                break;

        default:
                break;
        }
//    printf("%6d - %s\n", had_events, fl_eventnames[ev]);fflush(stdout);
        // call the base class event handler
        return Fl_Double_Window::handle(ev);
} // handle

/*****************************************************************************/
// The main window for the demo
static idle_win *main_window = NULL;

/*****************************************************************************/
static void check_for_idle(void *) {
    static unsigned last_check = 0;
    static unsigned ticks = 0;
    static unsigned idle_count = 0;

    ticks++;
    if(last_check == main_window->had_events)
    {
        printf("May be idle %d\n", ticks); fflush(stdout);
        idle_count++;
    }
    else
    {
        idle_count = 0;
        last_check = main_window->had_events;
    }

    // are we idle for too long?
    if(idle_count > 5) // exit now...
    {
        main_window->hide();
    }
        // repeat the delay
        Fl::repeat_timeout(IDLE_CHECK_TIME, check_for_idle);
} // check_for_idle

/*****************************************************************************/
static void do_exit(Fl_Button *, void *v) {
    main_window->hide();
} // do_exit
/*****************************************************************************/
int main (int argc, char **argv) {
        // create the main window
        main_window = new idle_win(600, 600, "Idle Demo");
        main_window->begin();

    Fl_Button *b1 = new Fl_Button(100, 100, 60, 30, "A button");

    Fl_Button *b2 = new Fl_Button(530, 560, 60, 30, "Exit");
    b2->callback((Fl_Callback *)do_exit);
        main_window->end();
        // show the app
        main_window->show(argc, argv);
        // add a timer to detect inactivity
        Fl::add_timeout(IDLE_CHECK_TIME, check_for_idle);
        // start the fltk loop
        return Fl::run();
} // main

/* end of file */

--------------------

















SELEX Galileo Ltd
Registered Office: Sigma House, Christopher Martin Road, Basildon, Essex SS14 
3EL
A company registered in England & Wales.  Company no. 02426132
********************************************************************
This email and any attachments are confidential to the intended
recipient and may also be privileged. If you are not the intended
recipient please delete it from your system and notify the sender.
You should not copy it or use it for any purpose nor disclose or
distribute its contents to any other person.
********************************************************************

_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to