> Hello,
> Found this thread when looking for info about problems with setting
> focus to a specific window under linux. The example program in this post
> works as described in windows, but in linux my window labeled "window"
> lose focus as soon the "extended window" is shown.
>
> Did anyone find a nice way of solving this focus problem under linux?
>
> I'm using fltk-1.1.x.
>
> Thank you in advance,
> /Daniel

I've had the same experience.  Here's a fix.

class ExtWindow : public Fl_Window {
public:
    ExtWindow(int x, int y, int w, int h, char const* label = 0,
                       Fl_Window* parent = 0)
        : Fl_Window(x, y, w, h, label)
        , parent_(parent)
    {;}
    int handle(int event)
    {
        int r = Fl_Window::handle(event);
        if(parent_) parent_->take_focus();
        return r;
    }
private:
    Fl_Window* parent_;
}

Later, replace
  Fl_Window *ext_win;
with
  ExtWindow *ext_win;
and
  ext_win=new Fl_Window(0,0,300,50,"extended window");
with
  ext_win=new ExtWindow(0,0,300,50,"extended window", win);

HTH,
Stan

>
> michael sephton skrev:
> > Hi, Here is a similar demo program for fltk 1.1x.  You type in an input in 
> > one window, and as soon as you type it pops up another window with an 
> > input, and it retains the focus, and as you continue typing, it updates the 
> > text in the second window.
> >
> > #include <FL/Fl.h>
> > #include <FL/Fl_Window.h>
> > #include <FL/Fl_Input.h>
> > #include <Fl/Fl_Button.h>
> > #include <iostream>
> >
> > Fl_Window *win;
> > Fl_Input *in;
> > Fl_Window *ext_win;
> > Fl_Input *ext_in;
> > Fl_Button *hide_button;
> >
> > void hide_cb(Fl_Widget *w,void *d){
> > if(ext_win->visible())
> > ext_win->hide();
> > }
> >
> > void in_cb(Fl_Widget *w,void *d){
> > if(!ext_win->visible())
> > ext_win->show();
> > ext_in->value(in->value());
> > in->take_focus();
> >
> > }//in_cb
> >
> > int main(void){
> >
> > win=new Fl_Window(0,100,100,30,"window");
> > in=new Fl_Input(0,0,100,30);
> > in->callback(in_cb,0);
> > in->when(FL_WHEN_CHANGED);
> > win->end();
> > win->show();
> > ext_win=new Fl_Window(0,0,300,50,"extended window");
> > ext_in=new Fl_Input(0,0,300,30);
> > hide_button=new Fl_Button(5,35,45,15,"Hide");
> > hide_button->callback(hide_cb);
> > ext_win->end();
> > ext_win->hide();//see comment below
> >
> > return Fl::run();
> > }
> >
> > BTW I noticed that if I don't explicitly hide this window 
> > ext_win->visible() returns 1, even though the window is not shown.. is this 
> > a feature or a bug?
> >
> >
> >> Hi. I have main window which has input in it, and it should as soon as
> >> something is typed in the input box, popup new borderless window (child of
> >> main) with browser in it, with that what is typed in input box added in
> >> browsers.
> >>
> >> When I type the first character in input box, child window with browser in 
> >> it,
> >> which added that character, pops up but focus is not on input anymore, so I
> >> have to click on input and continue typing after which focus stays on 
> >> input.
> >>
> >> But how can I prevent losing focus even that first time (after first typed
> >> character), because it is expected that user should continuously type the
> >> whole word in input box, not first one character and then switch manually 
> >> to
> >> input again and continue typing?
> >>
> >> I'm using FLTK 2.x and piece of code in question is bellow:
> >> --- Begin ---
> >> void MainWindow::cb_wordInput_i() { // callback, called "WHEN_CHANGED"
> >>    // wordInput is fltk::Input
> >>    if (wordInput->size()) {
> >>            browser->add(wordInput->value());
> >>            browserWindow->show();
> >>            wordInput->take_focus(); // I've tried and focus(wordInput)
> >>                                     // also, from <fltk/events.h>
> >>    } else {
> >>            browser->clear();
> >>            browserWindow->hide();
> >>    }
> >> }
> >> --- End ---
> >>
> >> Thanks in advance.
> >>
> >

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

Reply via email to