> So I noticed that when I save windows on the non-primary screen, quit
> and restore, they wind up on the primary screen.  It looks like on OS
> X, show() will move the window back on to the primary screen.  So I
> overrode show:
>
> void
> BlockViewWindow::show()
> {
>     IRect requested = rect(this);
>     Fl_Double_Window::show();
>     if (rect(this) != requested) {
>         IRect screen;
>         Fl::screen_xywh(screen.x, screen.y, screen.w, screen.h,
>             requested.x, requested.y);
>         if (screen.contains(IPoint(requested.x, requested.y)))
>             this->position(requested.x, requested.y);
>     }
> }
>
> The idea is that if the screen the window wants to be on exists, then
> move it again where it wanted to go.  Otherwise, let it stay where the
> OS put it.  This works ok but does lead to an annoying flicker since I
> have to wait until after show() to move the window.
>
> I poked into Fl_cocoa.mm and the key function seems to be
> Fl_X::make().  There's some fiddling with FORCE_POSITION, but I don't
> think this is quite what I want.  I think it should appear where
> requested if that's on a screen that exists, and otherwise pick some
> reasonable spot on the main screen.
>
> Does this seem like reasonable behaviour for the default show?
>

Could you, please, try to "restore" a window after having added
this patch but without overriding show() ?

Index: src/Fl_cocoa.mm
===================================================================
--- src/Fl_cocoa.mm     (revision 9131)
+++ src/Fl_cocoa.mm     (working copy)
@@ -577,7 +577,21 @@
              contentRect:(NSRect)rect
                styleMask:(NSUInteger)windowStyle
 {
-  self = [super initWithContentRect:rect styleMask:windowStyle 
backing:NSBackingStoreBuffered defer:NO];
+  NSScreen *gd = nil; // gd will point to the screen containing the 
bottom-left of rect
+  NSArray *a = [NSScreen screens];
+  for(NSUInteger i = 0; i < [a count]; i++) {
+    NSRect r = [[a objectAtIndex:i] frame];
+    if (rect.origin.x >= r.origin.x && rect.origin.x <= r.origin.x + 
r.size.width
+        && rect.origin.y >= r.origin.y && rect.origin.y <= r.origin.y + 
r.size.height) {
+      rect.origin.x -= r.origin.x; // express rect relatively to gd's origin
+      rect.origin.y -= r.origin.y;
+      gd = [a objectAtIndex:i];
+      break;
+      }
+  }
+  // attempt to create the window on screen gd
+  self = [super initWithContentRect:rect styleMask:windowStyle 
backing:NSBackingStoreBuffered defer:NO
+         screen:gd];
   if (self) {
     w = flw;
     containsGLsubwindow = NO;

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

Reply via email to