Author: manolo
Date: 2011-03-12 13:36:21 -0800 (Sat, 12 Mar 2011)
New Revision: 8515
Log:
Fix STR #2575: use the screen that intersects most of the window when made 
fullscreen.

Modified:
   branches/branch-1.3/FL/Fl.H
   branches/branch-1.3/src/Fl_Window_fullscreen.cxx
   branches/branch-1.3/src/screen_xywh.cxx

Modified: branches/branch-1.3/FL/Fl.H
===================================================================
--- branches/branch-1.3/FL/Fl.H 2011-03-11 00:14:29 UTC (rev 8514)
+++ branches/branch-1.3/FL/Fl.H 2011-03-12 21:36:21 UTC (rev 8515)
@@ -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);
 
   /**   @} */

Modified: branches/branch-1.3/src/Fl_Window_fullscreen.cxx
===================================================================
--- branches/branch-1.3/src/Fl_Window_fullscreen.cxx    2011-03-11 00:14:29 UTC 
(rev 8514)
+++ branches/branch-1.3/src/Fl_Window_fullscreen.cxx    2011-03-12 21:36:21 UTC 
(rev 8515)
@@ -68,13 +68,16 @@
 #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
+#if defined(USE_X11)
+  resize(0, 0, w(), h()); // work around some quirks in X11
+#endif
   resize(sx, sy, sw, sh);
 #else
   if (!x()) x(1); // make sure that we actually execute the resize

Modified: branches/branch-1.3/src/screen_xywh.cxx
===================================================================
--- branches/branch-1.3/src/screen_xywh.cxx     2011-03-11 00:14:29 UTC (rev 
8514)
+++ branches/branch-1.3/src/screen_xywh.cxx     2011-03-12 21:36:21 UTC (rev 
8515)
@@ -284,8 +284,43 @@
   H = Fl::h();
 }
 
+static inline float fl_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 = x1 > x2 ? x1 : x2;
+  int int_right = x1+w1 > x2+w2 ? x2+w2 : x1+w1;
+  int int_top = y1 > y2 ? y1 : y2;
+  int int_bottom = y1+h1 > y2+h2 ? y2+h2 : y1+h1;
+  return (float)(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;
+  float 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);
+    float sintersection = fl_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)

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

Reply via email to