[vlc-devel] commit: Improve x11 xinerama fullscreen window placement (Ilkka Ollakka )

git version control git at videolan.org
Wed Jun 24 16:09:35 CEST 2009


vlc | branch: 1.0-bugfix | Ilkka Ollakka <ileoo at videolan.org> | Wed Jun 24 16:52:36 2009 +0300| [1d3a963a433dc74e541525c72b324adcbea087e1] | committer: Ilkka Ollakka 

Improve x11 xinerama fullscreen window placement

Select fullscreen display the one that has most of the video-window,
then you get qt4 fullscreencontroller on same display also, and it's
more logical (imo). Algorithm is prettymuch the same as Nigel Tao has
made in his gpl2 project superswitcher, Didn't want to reinvent this
with different variable-names ;)

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=1d3a963a433dc74e541525c72b324adcbea087e1
---

 modules/video_output/x11/xcommon.c |   47 +++++++++++++++++++++++++++++-------
 1 files changed, 38 insertions(+), 9 deletions(-)

diff --git a/modules/video_output/x11/xcommon.c b/modules/video_output/x11/xcommon.c
index 9cd132c..de1c3bf 100644
--- a/modules/video_output/x11/xcommon.c
+++ b/modules/video_output/x11/xcommon.c
@@ -2098,7 +2098,7 @@ static void ToggleFullScreen ( vout_thread_t *p_vout )
         Window parent_win;
         Window child_win;
         XWindowAttributes win_attr;
-        int screen_x,screen_y;
+        int screen_x,screen_y,win_width,win_height;
 
         XGetWindowAttributes(
                 p_vout->p_sys->p_display,
@@ -2121,7 +2121,10 @@ static void ToggleFullScreen ( vout_thread_t *p_vout )
                 &screen_x,&screen_y,
                 &child_win);
 
-        msg_Dbg( p_vout, "X %d/%d Y %d/%d", win_attr.x,screen_x,win_attr.y,screen_y);
+        win_width = p_vout->p_sys->p_win->i_width;
+        win_height = p_vout->p_sys->p_win->i_height;
+        msg_Dbg( p_vout, "X %d/%d Y %d/%d",
+            win_width, screen_x, win_height, screen_y );
         /* screen_x and screen_y are current position */
 
         p_vout->p_sys->b_altfullscreen =
@@ -2239,18 +2242,44 @@ static void ToggleFullScreen ( vout_thread_t *p_vout )
              * otherwise use that screen where window is */
             if( SCREEN >= i_num_screens || SCREEN < 0 )
             {
+                int overlapping=0;
+                int rightmost_left=0;
+                int leftmost_right=0;
+                int bottommost_top=0;
+                int topmost_bottom=0;
+                int best_screen=0;
+                int best_overlapping=0;
+                int dx,dy;
                 msg_Dbg( p_vout, "requested screen number invalid (%d/%d)", SCREEN, i_num_screens );
-#define left screens[SCREEN].x_org
-#define right left + screens[SCREEN].width
+#define left ( screens[SCREEN].x_org )
+#define right ( left + screens[SCREEN].width )
 #define top screens[SCREEN].y_org
-#define bottom top + screens[SCREEN].height
+#define bottom ( top + screens[SCREEN].height )
 
-                 for( SCREEN = i_num_screens-1; SCREEN > 0; SCREEN--)
+                /* Code mostly same as http://superswitcher.googlecode.com/svn/trunk/src/xinerama.c
+                 * by Nigel Tao, as it was pretty clean implemention what's needed here. Checks what display
+                 * contains most of the window, and use that as fullscreen screen instead screen what
+                 * contains videowindows 0.0 */
+                 for( SCREEN = i_num_screens-1; SCREEN >= 0; SCREEN--)
                  {
-                     if( left <= screen_x && screen_x <= right &&
-                             top <= screen_y && screen_y <= bottom )
-                         break;
+                     rightmost_left = __MAX( left, screen_x );
+                     leftmost_right = __MIN( right, screen_x + win_width );
+                     bottommost_top = __MAX( top, screen_y );
+                     topmost_bottom = __MIN( bottom , screen_y + win_height );
+                     dx = leftmost_right - rightmost_left;
+                     dy = topmost_bottom - bottommost_top;
+                     overlapping=0;
+                     if ( dx > 0 && dy > 0 )
+                         overlapping = dx*dy;
+                     if( SCREEN == (i_num_screens-1) ||
+                             overlapping > best_overlapping )
+                     {
+                         best_overlapping = overlapping;
+                         best_screen = SCREEN;
+                     }
                  }
+                 msg_Dbg( p_vout, "setting best screen to %d", best_screen );
+                 SCREEN = best_screen;
 #undef bottom
 #undef top
 #undef right




More information about the vlc-devel mailing list