[vlc-devel] [PATCH] Constrain Qt interface to desktop size on video resize

Mario Speiß 1034-135 at online.de
Sun Jan 6 19:21:26 CET 2013


When hi res video is played, it may happen that VLC window is far larger than
the desktop when resizeStack is called due to video changes.
So before passing the original w/h to resizeStack, it is checked first if the
new window size would reach outside the right/bottom of the desktop. If that
would be the case, new w/h are calculated to not get larger than the area
available.

Calculations are done from the current window position, i.e. if VLC is at the
bottom right of the desktop the resulting window should be rather small
compared to if VLC were at the top left of the desktop.

No moving of the VLC is done, only the w/h for resizeStack are validated.

The corresponding option is added in qt4.cpp.

Regards,
Mario
---
 modules/gui/qt4/main_interface.cpp |   29 +++++++++++++++++++++++++++++
 modules/gui/qt4/qt4.cpp            |    6 ++++++
 2 files changed, 35 insertions(+), 0 deletions(-)

diff --git a/modules/gui/qt4/main_interface.cpp b/modules/gui/qt4/main_interface.cpp
index f479e4e..5fdb82e
--- a/modules/gui/qt4/main_interface.cpp
+++ b/modules/gui/qt4/main_interface.cpp
@@ -710,7 +710,36 @@ void MainInterface::setVideoSize( unsigned int w, unsigned int h )
 void MainInterface::videoSizeChanged( int w, int h )
 {
     if( !playlistWidget || playlistWidget->artContainer->currentWidget() != videoWidget )
+    {
+        /* Calculate the future video widget position-
+           If it exceeds the current screen, rescale it to fit the screen */
+        if( var_InheritBool( p_intf, "qt-constrain-to-screen" ) )
+        {
+            QPoint pt( 0, 0 );
+            pt = stackCentralW->mapToGlobal( pt );
+            QRect rc_video = stackCentralW->rect().translated( pt );
+            QRect rc_frame = frameGeometry();
+            msg_Dbg( p_intf, "videoSizeChanged: video=(%d/%d)x(%d/%d), this=(%d/%d)x(%d/%d)",
+                    rc_video.left(), rc_video.top(), rc_video.width(), rc_video.height(),
+                    rc_frame.left(), rc_frame.top(), rc_frame.width(), rc_frame.height() );
+            QRect rc = QApplication::desktop()->availableGeometry( QApplication::desktop()->screenNumber( videoWidget ) );
+            int pixel_to_right  =  rc.width() - pt.x() - ( rc_frame.right() - rc_video.right() );
+            int pixel_to_bottom = rc.height() - pt.y() - ( rc_frame.bottom() - rc_video.bottom() );
+            float sx = 1, sy = 1;
+            if( w > pixel_to_right )
+                sx = (float)pixel_to_right/(float)w;
+            if( h > pixel_to_bottom )
+                sy=(float)pixel_to_bottom/(float)h;
+            if( sx < 1 || sy < 1 )
+            {
+                if( sx < sy )
+                    w *= sx, h *= sx;
+                else
+                    w *= sy, h *= sy;
+            }
+        }
         resizeStack( w, h );
+    }
 }
 
 void MainInterface::setVideoFullScreen( bool fs )
diff --git a/modules/gui/qt4/qt4.cpp b/modules/gui/qt4/qt4.cpp
index 11ae967..4dcce6c
--- a/modules/gui/qt4/qt4.cpp
+++ b/modules/gui/qt4/qt4.cpp
@@ -181,6 +181,9 @@ static void ShowDialog   ( intf_thread_t *, int, int, intf_dialog_args_t * );
     "This option allows the interface to change its icon on various occasions.")
 
 #define VOLUME_MAX_TEXT N_( "Maximum Volume displayed" )
+#define QT_CONSTRAIN_TO_SCREEN_TEXT N_( "Constrain video widget to the current screen." )
+#define QT_CONSTRAIN_TO_SCREEN_LONGTEXT N_( "Constrain the video widget size to fit "\
+                                            "onto the current desktop." )
 
 static const int i_notification_list[] =
     { NOTIFICATION_NEVER, NOTIFICATION_MINIMIZED, NOTIFICATION_ALWAYS };
@@ -219,6 +222,9 @@ vlc_module_begin ()
     add_float_with_range( "qt-fs-opacity", 0.8, 0.1, 1., OPACITY_FS_TEXT,
                           OPACITY_FS_LONGTEXT, false )
 
+
+    add_bool( "qt-constrain-to-screen", true, QT_CONSTRAIN_TO_SCREEN_TEXT,
+              QT_CONSTRAIN_TO_SCREEN_LONGTEXT, false )
     add_bool( "qt-video-autoresize", true, KEEPSIZE_TEXT,
               KEEPSIZE_LONGTEXT, false )
     add_bool( "qt-name-in-title", true, TITLE_TEXT,
-- 
1.7.5.4




More information about the vlc-devel mailing list