BEWARE, quite a LONG POST below!

>
> On 12 May 2007, at 10:10, Ivan Chernyavsky wrote:
>
> > Hello all,
> >
> > I need to start my application with FLTK-generated main window
> > maximized on screen (taking all display area except the linux/
> > windows toolbar). Is there a standard way to achieve this platform-
> > independently?
> >
> > Acceptable alternative of course would be to create the window non-
> > maximized (i.e. with fixed w() and h()) and then make it maximized.
> > I just can't get this working the same way on Linux and Windows.
>
> Easiest way is probably to call Fl::screen_xywh(...) sometime before
> you show your main window and use the values that returns to create
> your main window the right size and in the right place.
>
>

(That's the original author again.)

Some time passed since I gave up on this problem lately,
but now it seems I solved it with a kind of dirty hack.

I'm using FLTK 2 so I replaced screen_xywh with
fltk::Monitor stuff, and got the following code in my window
constructor:

fltk::Monitor monitor = fltk::Monitor::all();
fltk::Rectangle bord;
borders(&bord);

resize(-bord.x(),
       -bord.y(),
       monitor.work.w() - bord.w(),
       monitor.work.h() - bord.h());

And this seem to work on KDE! Because it seems that when
the window is resized exactly to fill the screen
(except the taskbar), KDE remembers its initial size and
changes its state to maximized ("maximize" button changes
to "minimize" and pressing it resizes the window to the initial
specified size (e.g. in Window(x, y, w, h)).

I don't have a system with Gnome currently at hands so can't test it.
On FVWM, since it does not support a usual idea of "maximizing",
I got my window resized nearly to fill the whole screen, which
in fact is what it should do.

However, on Windoze that didn't worked as I want. The window was
resized to fill the whole screen except the taskbar --- yes,
but the original (minimized) size of it was lost. So, window was
still in minimized state and pressing maximize-minimize was only
making it flick a little.

This made me to introduce some OS-specific code. I had to include
<fltk/win32.h> under #ifdef _WIN32 ... #endif and

    ShowWindow(fltk::xid(this), SW_MAXIMIZE);

just after my window->show(). It seemed to work, because for a
split second I saw maximized window appear on the screen and then
minimize to "constructor" size. So I had to somehow call ShowWindow()
_after_ fltk::run() has taken control.

And here is the most dirty part of all. In fact, I would like to ask
all of you if what I did is safe enough.

I've put the ShowWindow() from above into layout() method of
my window as follows:

void G3dWindow::layout()
{

#ifdef _WIN32 // maximization hack for Windows
    if (shown() && ! already_maximized)
    {
        ShowWindow(fltk::xid(this), SW_MAXIMIZE);
        already_maximized = true;
    }
#endif // def _WIN32

    fltk::Window::layout();
}

and also introduced a boolean field already_maximized which
is false just after window is created, so that my ShowWindow()
would be called exactly once on initial layout and after that
the user will have full control over window size. And it works.

Sorry for long post and thanks for your attention,
   Ivan

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

Reply via email to