It seemed that this example code make the problem more clear.

The program will never exit if I press 'a' !

I have to stop the program with 'ESC'. It take me about ten seconds to press 
'ESC' before the program exited.


> Sparkaround wrote:
> > I have tried repeat_time, but the result is the same. And if w.fullscreen() 
> > is called, it is very difficult to stop the program by pressing 'a' or 
> > 'ESC'.
>
>       Sounds like something about the way the code is written
>       is affecting the app's ability to process events, esp.
>       if it affects the window's default ESC handler callback.
>
>       Since I can't replicate the problem, I can't probe it.
>
>       Here's how I might have written the program..
>       curious if it makes a difference in the behavior on your system.
>
>       The key change I made is /not/ to call the Fl::event_key()
>       from within the timer, but from within a handle() method,
>       and only in response to when a keyboard down event occurs.
>
>       I'd offer that this might be 'more correct', as I normally
>       wouldn't do keyboard event processing outside the handle() loop:
>
>
> #include <FL/Fl.H>
> #include <FL/Fl_Widget.H>
> #include <FL/Fl_Double_Window.H>
> #include <FL/fl_draw.H>
>
> #define DELAY 0.001
>
> class Test_Draw: public Fl_Widget {
> public:
>     Test_Draw(int x, int y, int w, int h, char *l=0):Fl_Widget(x,y,w,h,l) {
>     }
>     void draw() {
>         static int d=0;
>         d++;
>         fl_rectf(x(),y(), (int) d%w(), (int)d%h(), d%255,d%255,d%255);
>     }
>     int handle(int e) {
>         switch (e) {
>             case FL_KEYDOWN:
>                 if ( Fl::event_key('a') ) exit(0);
>                 break;
>         }
>         return(Fl_Widget::handle(e));
>     }
> };
>
> Test_Draw *t;
> static void update(void *) {
>     t->redraw();
>     Fl::repeat_timeout(DELAY, update, 0);
> }
>
> int main(int argc, char **argv) {
>     Fl_Double_Window w(200,200,Fl::w()/2, Fl::h()/2);
>     //Fl_Window w(200,200,Fl::w()/2, Fl::h()/2);
>     t = new Test_Draw(0,0,w.w(),w.h());
>     w.end();
>     w.show(argc, argv);
>     Fl::add_timeout(DELAY, update, 0);
>     return(Fl::run());
> }
>
>

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

Reply via email to