DO NOT REPLY TO THIS MESSAGE.  INSTEAD, POST ANY RESPONSES TO THE LINK BELOW.

[STR New]

Link: http://www.fltk.org/str.php?L2575
Version: 1.3-current


Currently, when a window is more than half way off all monitors in any
direction and fullscreen is called on it, it moves to the default monitor
instead of the monitor it is on. (there are also some quirks in X11 which
make it take up all the monitors when doing this). This is because the
fullscreen function looks for the monitor which holds the centre point of
the window instead of the monitor which intersects the most with the
window.

I have fixed this by adding a third screen_xywh which determines which
screen a rectangle intersects the most with and using it in fullscreen().
This new function should also be helpful for people using the library.


Link: http://www.fltk.org/str.php?L2575
Version: 1.3-current
Index: src/Fl_Window_fullscreen.cxx
===================================================================
--- src/Fl_Window_fullscreen.cxx        (revision 8471)
+++ src/Fl_Window_fullscreen.cxx        (working copy)
@@ -58,7 +58,7 @@
 #else
 # error unsupported platform
 #endif
-}
+}    
 
 void Fl_Window::fullscreen() {
 #ifndef WIN32
@@ -68,13 +68,14 @@
 #endif
 #if defined(__APPLE__) || defined(WIN32) || defined(USE_X11)
   int sx, sy, sw, sh;
-  Fl::screen_xywh(sx, sy, sw, sh, x()+w()/2, y()+h()/2);
+  Fl::screen_xywh(sx, sy, sw, sh, x(), y(), w(), h());
   // if we are on the main screen, we will leave the system menu bar 
unobstructed
   if (Fl::x()>=sx && Fl::y()>=sy && Fl::x()+Fl::w()<=sx+sw && 
Fl::y()+Fl::h()<=sy+sh) {
     sx = Fl::x(); sy = Fl::y(); 
     sw = Fl::w(); sh = Fl::h();
   }
   if (x()==sx) x(sx+1); // make sure that we actually execute the resize
+  resize(0, 0, w(), h()); // work around some quirks in X11
   resize(sx, sy, sw, sh);
 #else
   if (!x()) x(1); // make sure that we actually execute the resize
Index: src/screen_xywh.cxx
===================================================================
--- src/screen_xywh.cxx (revision 8471)
+++ src/screen_xywh.cxx (working copy)
@@ -284,8 +284,51 @@
   H = Fl::h();
 }
 
+inline int max(int a, int b) {
+  return (a > b) ? (a) : (b);
+}
 
+inline int min(int a, int b) {
+  return (a < b) ? (a) : (b);
+}
+
+inline int intersection(int x1, int y1, int w1, int h1,
+                        int x2, int y2, int w2, int h2) {
+  if(x1+w1 < x2 || x2+w2 < x1 || y1+h1 < y2 || y2+h2 < y1)
+    return 0;
+  int int_left = max(x1, x2);
+  int int_right = min(x1+w1, x2+w2);
+  int int_top = max(y1, y2);
+  int int_bottom = min(y1+h1, y2+h2);
+  return (int_right - int_left) * (int_bottom - int_top);
+}
+
 /**
+  Gets the screen bounding rect for the screen
+  which intersects the most with the rectangle
+  defined by \p mx, \p my, \p mw, \p mh.
+  \param[out]  X,Y,W,H the corresponding screen bounding box
+  \param[in] mx, my, mw, mh the rectangle to search for intersection with
+  \see void screen_xywh(int &X, int &Y, int &W, int &H, int n)
+  */
+void Fl::screen_xywh(int &X, int &Y, int &W, int &H, int mx, int my, int mw, 
int mh) {
+  int best_screen = 0;
+  int best_intersection = 0;
+  for(int i = 0; i < Fl::screen_count(); i++) {
+    int sx, sy, sw, sh;
+    Fl::screen_xywh(sx, sy, sw, sh, i);
+    int sintersection = intersection(mx, my, mw, mh, sx, sy, sw, sh);
+    if(sintersection > best_intersection) {
+      best_screen = i;
+      best_intersection = sintersection;
+    }
+  }
+  screen_xywh(X, Y, W, H, best_screen);
+}
+  
+
+
+/**
  Gets the screen resolution in dots-per-inch for the given screen. 
  \param[out]  h, v  horizontal and vertical resolution
  \param[in]   n     the screen number (0 to Fl::screen_count() - 1)
Index: FL/Fl.H
===================================================================
--- FL/Fl.H     (revision 8471)
+++ FL/Fl.H     (working copy)
@@ -784,7 +784,8 @@
     screen_xywh(X, Y, W, H, e_x_root, e_y_root);
   }
   static void screen_xywh(int &X, int &Y, int &W, int &H, int mx, int my);
-  static void screen_xywh(int &X, int &Y, int &W, int &H, int n);  
+  static void screen_xywh(int &X, int &Y, int &W, int &H, int n); 
+  static void screen_xywh(int &X, int &Y, int &W, int &H, int mx, int my, int 
mw, int mh);
   static void screen_dpi(float &h, float &v, int n=0);
 
   /**   @} */
_______________________________________________
fltk-bugs mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-bugs

Reply via email to