[vlc-devel] [PATCH] qt: don't auto resize when window is tiled with win7 aero snap

Pierre Lamot pierre at videolabs.io
Tue Oct 31 12:06:32 CET 2017


---
 modules/gui/qt/main_interface.cpp       |  8 ++++----
 modules/gui/qt/main_interface.hpp       |  4 ++--
 modules/gui/qt/main_interface_win32.cpp | 36 +++++++++++++++++++++++++++++++++
 modules/gui/qt/main_interface_win32.hpp |  3 +++
 4 files changed, 45 insertions(+), 6 deletions(-)

diff --git a/modules/gui/qt/main_interface.cpp b/modules/gui/qt/main_interface.cpp
index 3bde9e8968..8389933df8 100644
--- a/modules/gui/qt/main_interface.cpp
+++ b/modules/gui/qt/main_interface.cpp
@@ -403,7 +403,7 @@ void MainInterface::showResumePanel( int64_t _time ) {
         resumePlayback();
     else
     {
-        if( !isFullScreen() && !isMaximized() )
+        if( !isFullScreen() && !isMaximized() && !isSizeForced() )
             resizeWindow( width(), height() + resumePanel->height() );
         resumePanel->setVisible(true);
         resumeTimer->start();
@@ -414,7 +414,7 @@ void MainInterface::hideResumePanel()
 {
     if( resumePanel->isVisible() )
     {
-        if( !isFullScreen() && !isMaximized() )
+        if( !isFullScreen() && !isMaximized() && !isSizeForced() )
             resizeWindow( width(), height() - resumePanel->height() );
         resumePanel->hide();
         resumeTimer->stop();
@@ -1075,7 +1075,7 @@ void MainInterface::setMinimalView( bool b_minimal )
     bool b_statusBarVisible = statusBar()->isVisible();
     bool b_inputCVisible = inputC->isVisible();
 
-    if( !isFullScreen() && !isMaximized() && b_minimal )
+    if( !isFullScreen() && !isMaximized() && b_minimal && !isSizeForced() )
     {
         int i_heightChange = 0;
 
@@ -1097,7 +1097,7 @@ void MainInterface::setMinimalView( bool b_minimal )
     statusBar()->setVisible( !b_minimal && b_statusbarVisible );
     inputC->setVisible( !b_minimal );
 
-    if( !isFullScreen() && !isMaximized() && !b_minimal )
+    if( !isFullScreen() && !isMaximized() && !b_minimal && !isSizeForced() )
     {
         int i_heightChange = 0;
 
diff --git a/modules/gui/qt/main_interface.hpp b/modules/gui/qt/main_interface.hpp
index e986c69bae..75bb3fae30 100644
--- a/modules/gui/qt/main_interface.hpp
+++ b/modules/gui/qt/main_interface.hpp
@@ -109,7 +109,7 @@ protected:
     void wheelEvent( QWheelEvent * ) Q_DECL_OVERRIDE;
     bool eventFilter(QObject *, QEvent *) Q_DECL_OVERRIDE;
     virtual void toggleUpdateSystrayMenuWhenVisible();
-
+    virtual bool isSizeForced() { return false; };
     void resizeWindow(int width, int height);
 
 protected:
@@ -234,7 +234,7 @@ protected slots:
 
     void resizeStack( int w, int h )
     {
-        if( !isFullScreen() && !isMaximized() )
+        if( !isFullScreen() && !isMaximized() && !isSizeForced() )
         {
             if( b_minimalView )
                 resizeWindow( w, h ); /* Oh yes, it shouldn't
diff --git a/modules/gui/qt/main_interface_win32.cpp b/modules/gui/qt/main_interface_win32.cpp
index 637b643d00..1ecc17714c 100644
--- a/modules/gui/qt/main_interface_win32.cpp
+++ b/modules/gui/qt/main_interface_win32.cpp
@@ -349,6 +349,42 @@ void MainInterfaceWin32::toggleUpdateSystrayMenuWhenVisible()
         activateWindow();
 }
 
+bool MainInterfaceWin32::isSizeForced()
+{
+    /*
+     * Detects if window placement is not in its normal position (ex: win7 aero snap)
+     * This function compares the normal position (non snapped) to the current position.
+     * The current position is translated from screen referential to workspace referential
+     * to workspace referential
+     */
+    HWND winHwnd = WinId( this );
+
+    WINDOWPLACEMENT windowPlacement;
+    windowPlacement.length = sizeof( windowPlacement );
+    if ( GetWindowPlacement( winHwnd, &windowPlacement ) == 0 )
+        return false;
+
+    if ( windowPlacement.showCmd != SW_SHOWNORMAL )
+        return false;
+
+    HMONITOR monitor = MonitorFromWindow( winHwnd, MONITOR_DEFAULTTONEAREST );
+
+    MONITORINFO monitorInfo;
+    monitorInfo.cbSize = sizeof( monitorInfo );
+    if ( GetMonitorInfo( monitor, &monitorInfo )  == 0 )
+        return false;
+
+    RECT windowRect;
+    if ( GetWindowRect( winHwnd, &windowRect ) == 0 )
+        return false;
+
+    OffsetRect( &windowRect,
+                monitorInfo.rcWork.left - monitorInfo.rcMonitor.left,
+                monitorInfo.rcWork.top - monitorInfo.rcMonitor.top );
+
+    return EqualRect( &windowPlacement.rcNormalPosition, &windowRect ) == 0;
+}
+
 void MainInterfaceWin32::reloadPrefs()
 {
     p_intf->p_sys->disable_volume_keys = var_InheritBool( p_intf, "qt-disable-volume-keys" );
diff --git a/modules/gui/qt/main_interface_win32.hpp b/modules/gui/qt/main_interface_win32.hpp
index 289d306716..62820a7928 100644
--- a/modules/gui/qt/main_interface_win32.hpp
+++ b/modules/gui/qt/main_interface_win32.hpp
@@ -40,6 +40,9 @@ private:
     virtual bool winEvent( MSG *, long * );
     virtual void toggleUpdateSystrayMenuWhenVisible() Q_DECL_OVERRIDE;
 
+protected:
+    virtual bool isSizeForced() Q_DECL_OVERRIDE;
+
 private:
     HWND WinId( QWidget *);
     void createTaskBarButtons();
-- 
2.14.2



More information about the vlc-devel mailing list