I describe here the logic flow of window creation:
// this puts in the crect rectangle the desired window position and size
NSRect crect;
crect.origin.x = w->x();
crect.origin.y = main_screen_height - (w->y() + w->h());
crect.size.width=w->w();
crect.size.height=w->h();
// this creates a window asking for a position/size through crect
FLWindow *cw = [[FLWindow alloc] initWithFl_W:w
contentRect:crect
styleMask:winstyle];
...
// this maps the new window to the screen
[cw makeKeyAndOrderFront:nil];
// this gets the actual size of the mapped window
crect = [[cw contentView] frame];
// and puts the actual size in w->w() and w->h()
w->w(int(crect.size.width));
w->h(int(crect.size.height));
// this gets the actual window position
crect = [cw frame];
// and puts the actual position in w->x() and w->y()
w->x(int(crect.origin.x));
w->y(int(main_screen_height - (crect.origin.y + w->h())));
The last statement above reflects the fact that cocoa uses coordinates
that go upward from the main screen bottom whereas FLTK uses
coordinates that go downward from the main screen top.
If the window is not mapped where it was asked, it's because the
window manager took this decision. I'm not sure it's possible
to change that.
Did you try and add a poition() call in your make() function
after the show() statement ? What happens ?
> >> On Mon, Oct 17, 2011 at 4:58 AM, Manolo Gouy wrote:
> >> > Could you, please, try to "restore" a window after having added
> >> > this patch but without overriding show() ?
> >>
> >> Excellent, seems to work!
> >>
> >
> > Thanks. The new code has been committed in r.9134.
>
> Sorry, but I think there's something wrong with this patch. Given the
> following file:
>
> #include <FL/Fl.H>
> #include <FL/Fl_Window.H>
> #include <FL/Fl_Box.H>
>
>
> void
> make(int x, int y, int w, int h, const char *label)
> {
> printf("%s: wanted: %d %d\n", label, x, y);
> Fl_Window *win = new Fl_Window(x, y, w, h, label);
> win->show();
> printf("got: %d %d\n", win->x(), win->y());
> }
>
> int
> main()
> {
> make(2318, 22, 120, 1092, "1");
> make(2920, 22, 86, 310, "2"); // 1800, 854
> make(2440, 22, 71, 195, "3"); // 2440, 854
> make(2543, 23, 374, 767, "4");
> make(2200, 22, 118, 1006, "5");
> Fl::run();
> return 0;
> }
>
>
> The windows marked with comments appear at the (x, y) coordinates in
> the comment, not the requested ones. This might be tricky to
> reproduce because I have a 1680x1050 monitor (macbook built in) with a
> 1600x1200 to the right such that the tops line up. If you don't have
> that setup maybe you can get a repro with different monitors? Or at
> least let me know what I should check out.
>
> I've fiddled with it a bit, but it's still a mystery to me. It's
> definitely dependent on which windows are displayed, if I omit one of
> the correctly placed windows, one of the incorrect ones will show up
> in the requested spot. So there's presumably some persistent state
> messing things up. Also it depends on the geometry of the monitors,
> if I do the same on a vertically rotated external monitor, the
> misplaced windows are misplaced in different place (along the X axis
> instead of the Y axis, if I remember correctly). And if I go set
> position() on those windows they are in the right place.
>
> I've tracked it down to these lines in Fl_cocoa.mm:make():
>
> crect = [[cw contentView] frame];
> w->w(int(crect.size.width));
> w->h(int(crect.size.height));
> crect = [cw frame];
> w->x(int(crect.origin.x));
> w->y(int(main_screen_height - (crect.origin.y + w->h())));
>
> The thing is, I don't understand what crect is supposed to be so I
> don't understand what this is doing. I'll look at the docs for the
> 'frame' message, but maybe you'd understand this more quickly.
>
> Thanks!
>
_______________________________________________
fltk-dev mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-dev