FLTK logo

[fltk.general] Re: Losing keyboard input under user 'spamming' input

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 All Forums  |  Back to fltk.general  ]
 
Previous Message ]New Message | Reply ]Next Message ]

Re: Losing keyboard input under user 'spamming' input rs Sep 23, 2021  
 
It's a nice idea, but I tested it and, whilst it sometime "survives" longer (sometimes it doesn't - indeed sometimes only managing one full "loop" see below) whilst flicking the window on/off, it does eventually lead to the same problem. Basically, its not *just* FL_KEYBOARD events but also FL_KEYUP events that are continuously being generated, so this doesn't sidestep the issue. In an attempt a debugging with std::couts in a few places I get the following:

The code:
#include <FL/Fl.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Menu_Bar.H>
#include <iostream>

static int shown_v;

class my_win : public Fl_Double_Window {

    int handle(int);

    int please_change;
public:
    my_win(int x, int y,int w,int h,const char* L):Fl_Double_Window(x,y,w,h,L), please_change(0) {};
}; // my_win

int my_win::handle (int e){
    int ret = Fl_Double_Window::handle(e);

    if (e == FL_KEYBOARD) {
        std::cout<<"FL_KEYBOARD"<<std::endl;
        if (Fl::event_state() & (FL_ALT)) {
            if (Fl::event_key()=='s') {
                std::cout<<"shortcut"<<std::endl;
                please_change = (-1);
                return 1;
            }
        }
    }
    else if (e == FL_KEYUP) {
        std::cout<<"FL_KEYUP"<<std::endl;
        if (please_change) {
            std::cout<<"please change"<<std::endl;
                if (shown_v) {
                    std::cout<<"hide"<<std::endl;
                    this->hide();
                    shown_v = 0;
                }
                else {
                    std::cout<<"show"<<std::endl;
                    this->show();
                    shown_v = 1;
                }
            please_change = 0;
            return 1;
        }
    }
    return ret;
} // my_win::handle

void toggle_win (Fl_Widget*,void* data) {
    my_win* w = static_cast<my_win*>(data);

    if (shown_v) {
        std::cout<<"hide from main"<<std::endl;
        w->hide();
        shown_v = 0;
    }
    else {
        std::cout<<"show from main"<<std::endl;
        w->show();
        shown_v = 1;
    }
} // toggle_win

int main() {
    shown_v = 0;

    my_win *win2 = new my_win(0.5*Fl::w()-100,0.5*Fl::h()-100,200,200,"Second win");
    win2->end();

    Fl_Double_Window *win = new Fl_Double_Window(0.5*Fl::w()-200,0.5*Fl::h()-200,400,400,"Main Win");
    win->begin();

    Fl_Menu_Item items[] = {
        {"Menu1",0,0,0,FL_SUBMENU,0,0,FL_NORMAL_SIZE,FL_BLACK}, //0
        {"Hide/show second window",FL_ALT+'s',toggle_win,win2,0,0,0,FL_NORMAL_SIZE,FL_BLACK},
        {0,0,0,0,0,0,0,0,0},
        {0,0,0,0,0,0,0,0,0}
    };

    Fl_Menu_Bar *menu = new Fl_Menu_Bar(0, 0, win->w(),25);
    menu->menu(items);
    win->end();
    win->show();

    return Fl::run();
} // main
// end of file




The output from the end of one of the "long" flickering sequences:
...
FL_KEYBOARD
shortcut
FL_KEYUP
please change
hide
show from main
FL_KEYUP
FL_KEYBOARD
shortcut
FL_KEYUP
please change
hide
show from main
FL_KEYUP
FL_KEYBOARD
shortcut
FL_KEYUP
please change
hide
show from main
<----No more output here when keyboard events are no longer delivered to program.

A particulary short output (all of it) can look like

show from main
FL_KEYUP
FL_KEYBOARD
shortcut
FL_KEYUP
please change
hide
show from main
hide from main <---- The fact that this happens might be due to the cout calls, but could vaguely indicate that the window manager simply can't keep up
show from main
<----No more output here when keyboard events are no longer delivered to program.

with the final "show from main" being the last std::cout to be called before it falls over in all cases. The state of the window when this happens is *shown* so I actually think it is the "hide" method that is actually failing. I wonder if the during the failure it fails to hand over the keyboard shortcuts back to the main window, leaving the main window without keyboard input.  (I don't know how the internals actually work here)

Unless there are core FLTK things that can be learnt from this, I wouldn't worry too much about this. I.e. working out why it is doing this might be valuable, but generating workarounds for my use case may not be worth your time - I'll probably just disable the ability to toggle the modal window off/hidden on Linux builds.

My main thought, actually, is that this is rather a symptom of misbehaving event signals - repeated keyup and keydown is not what is actually happening, but those events are being generated.

Thanks,

R.

On Friday, September 24, 2021 at 1:11:22 AM UTC+10 Ian MacArthur wrote:
If it is a window show/hide issue, then breaking the link between the keyboard events and the window events might help?

If so, this might be better?

#include <FL/Fl.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Menu_Bar.H>
#include <iostream>

static int shown_v;

class my_win : public Fl_Double_Window {

    int handle(int);

    int please_change;
public:
    my_win(int x, int y,int w,int h,const char* L):Fl_Double_Window(x,y,w,h,L), please_change(0) {};
}; // my_win

int my_win::handle (int e){
    int ret = Fl_Double_Window::handle(e);
    if (e == FL_KEYBOARD) {
        if (Fl::event_state() & (FL_ALT)) {
            if (Fl::event_key()=='s') {
                please_change = (-1);
                return 1;
            }
        }
    }
    else if (e == FL_KEYUP) {
        if (please_change) {
                if (shown_v) {
                    this->hide();
                    shown_v = 0;
                }
                else {
                    this->show();
                    shown_v = 1;
                }
            please_change = 0;
            return 1;
        }
    }
    return ret;
} // my_win::handle

void toggle_win (Fl_Widget*,void* data) {
    my_win* w = static_cast<my_win*>(data);

    if (shown_v) {
        w->hide();
        shown_v = 0;
    }
    else {
        w->show();
        shown_v = 1;
    }
} // toggle_win

int main() {
    shown_v = 0;

    my_win *win2 = new my_win(0.5*Fl::w()-100,0.5*Fl::h()-100,200,200,"Second win");
    win2->end();

    Fl_Double_Window *win = new Fl_Double_Window(0.5*Fl::w()-200,0.5*Fl::h()-200,400,400,"Main Win");
    win->begin();

    Fl_Menu_Item items[] = {
        {"Menu1",0,0,0,FL_SUBMENU,0,0,FL_NORMAL_SIZE,FL_BLACK}, //0
        {"Hide/show second window",FL_ALT+'s',toggle_win,win2,0,0,0,FL_NORMAL_SIZE,FL_BLACK},
        {0,0,0,0,0,0,0,0,0},
        {0,0,0,0,0,0,0,0,0}
    };

    Fl_Menu_Bar *menu = new Fl_Menu_Bar(0, 0, win->w(),25);
    menu->menu(items);
    win->end();
    win->show();

    return Fl::run();
} // main
// end of file

--
You received this message because you are subscribed to the Google Groups "fltk.general" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fltkgeneral+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/fltkgeneral/6d3bb67a-97c7-4182-a5cd-4d07d61d331an%40googlegroups.com.
Direct Link to Message ]
 
     
Previous Message ]New Message | Reply ]Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2024 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.