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

Pierre Lamot pierre at videolabs.io
Tue Oct 31 18:55:13 CET 2017


---
 modules/gui/qt/main_interface.cpp       |  9 ++++----
 modules/gui/qt/main_interface.hpp       |  4 ++--
 modules/gui/qt/main_interface_win32.cpp | 40 +++++++++++++++++++++++++++++++++
 modules/gui/qt/main_interface_win32.hpp |  3 +++
 4 files changed, 50 insertions(+), 6 deletions(-)

diff --git a/modules/gui/qt/main_interface.cpp b/modules/gui/qt/main_interface.cpp
index 58a0efaf16..fc49683777 100644
--- a/modules/gui/qt/main_interface.cpp
+++ b/modules/gui/qt/main_interface.cpp
@@ -109,6 +109,7 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
     b_hasPausedWhenMinimized = false;
     i_kc_offset          = false;
     b_maximizedView      = false;
+    b_isWindowTiled      = false;
 
     /* Ask for Privacy */
     FirstRun::CheckAndRun( this, p_intf );
@@ -403,7 +404,7 @@ void MainInterface::showResumePanel( int64_t _time ) {
         resumePlayback();
     else
     {
-        if( !isFullScreen() && !isMaximized() )
+        if( !isFullScreen() && !isMaximized() && !b_isWindowTiled )
             resizeWindow( width(), height() + resumePanel->height() );
         resumePanel->setVisible(true);
         resumeTimer->start();
@@ -414,7 +415,7 @@ void MainInterface::hideResumePanel()
 {
     if( resumePanel->isVisible() )
     {
-        if( !isFullScreen() && !isMaximized() )
+        if( !isFullScreen() && !isMaximized() && !b_isWindowTiled )
             resizeWindow( width(), height() - resumePanel->height() );
         resumePanel->hide();
         resumeTimer->stop();
@@ -1078,7 +1079,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 && !b_isWindowTiled )
     {
         int i_heightChange = 0;
 
@@ -1100,7 +1101,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 && !b_isWindowTiled )
     {
         int i_heightChange = 0;
 
diff --git a/modules/gui/qt/main_interface.hpp b/modules/gui/qt/main_interface.hpp
index e986c69bae..fe8a4b61f0 100644
--- a/modules/gui/qt/main_interface.hpp
+++ b/modules/gui/qt/main_interface.hpp
@@ -109,7 +109,6 @@ protected:
     void wheelEvent( QWheelEvent * ) Q_DECL_OVERRIDE;
     bool eventFilter(QObject *, QEvent *) Q_DECL_OVERRIDE;
     virtual void toggleUpdateSystrayMenuWhenVisible();
-
     void resizeWindow(int width, int height);
 
 protected:
@@ -180,6 +179,7 @@ protected:
     bool                 b_interfaceFullScreen;
     bool                 b_pauseOnMinimize;
     bool                 b_maximizedView;
+    bool                 b_isWindowTiled;
 
     /* States */
     bool                 playlistVisible;       ///< Is the playlist visible ?
@@ -234,7 +234,7 @@ protected slots:
 
     void resizeStack( int w, int h )
     {
-        if( !isFullScreen() && !isMaximized() )
+        if( !isFullScreen() && !isMaximized() && !b_isWindowTiled )
         {
             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..ffa46760e8 100644
--- a/modules/gui/qt/main_interface_win32.cpp
+++ b/modules/gui/qt/main_interface_win32.cpp
@@ -349,6 +349,46 @@ void MainInterfaceWin32::toggleUpdateSystrayMenuWhenVisible()
         activateWindow();
 }
 
+
+void MainInterfaceWin32::resizeEvent(QResizeEvent *event)
+{
+    QWidget::resizeEvent(event);
+
+    /*
+     * 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
+     */
+    b_isWindowTiled = false;
+    HWND winHwnd = WinId( this );
+
+    WINDOWPLACEMENT windowPlacement;
+    windowPlacement.length = sizeof( windowPlacement );
+    if ( GetWindowPlacement( winHwnd, &windowPlacement ) == 0 )
+        return;
+
+    if ( windowPlacement.showCmd != SW_SHOWNORMAL )
+        return;
+
+    HMONITOR monitor = MonitorFromWindow( winHwnd, MONITOR_DEFAULTTONEAREST );
+
+    MONITORINFO monitorInfo;
+    monitorInfo.cbSize = sizeof( monitorInfo );
+    if ( GetMonitorInfo( monitor, &monitorInfo )  == 0 )
+        return;
+
+    RECT windowRect;
+    if ( GetWindowRect( winHwnd, &windowRect ) == 0 )
+        return;
+
+    OffsetRect( &windowRect,
+                monitorInfo.rcWork.left - monitorInfo.rcMonitor.left,
+                monitorInfo.rcWork.top - monitorInfo.rcMonitor.top );
+
+    b_isWindowTiled = ( 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..1e456c4c35 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 void resizeEvent( QResizeEvent *event ) Q_DECL_OVERRIDE;
+
 private:
     HWND WinId( QWidget *);
     void createTaskBarButtons();
-- 
2.14.2



More information about the vlc-devel mailing list