[vlc-devel] [PATCH v2 2/3] qt: send mouse release events before popping a QMenu to avoid Vout mouse state corruption

Pierre Lamot pierre at videolabs.io
Fri Oct 27 18:29:43 CEST 2017


---
 modules/gui/qt/dialogs_provider.cpp |  5 +++++
 modules/gui/qt/dialogs_provider.hpp |  1 +
 modules/gui/qt/main_interface.cpp   | 25 +++++++++++++++++++++++++
 modules/gui/qt/main_interface.hpp   |  1 +
 4 files changed, 32 insertions(+)

diff --git a/modules/gui/qt/dialogs_provider.cpp b/modules/gui/qt/dialogs_provider.cpp
index ec393b5f4c..252612f153 100644
--- a/modules/gui/qt/dialogs_provider.cpp
+++ b/modules/gui/qt/dialogs_provider.cpp
@@ -188,7 +188,12 @@ void DialogsProvider::customEvent( QEvent *event )
            delete popupMenu; popupMenu = NULL;
            bool show = (de->i_arg != 0);
            if( show )
+           {
+               //popping a QMenu will prenvent mouse releases events to be received,
+               //this ensure the coherency of the vout mouse state.
+               emit releaseMouseEvents();
                popupMenu = VLCMenuBar::PopupMenu( p_intf, show );
+           }
            break;
         }
         case INTF_DIALOG_AUDIOPOPUPMENU:
diff --git a/modules/gui/qt/dialogs_provider.hpp b/modules/gui/qt/dialogs_provider.hpp
index 399ac5322f..4d65c7a599 100644
--- a/modules/gui/qt/dialogs_provider.hpp
+++ b/modules/gui/qt/dialogs_provider.hpp
@@ -184,6 +184,7 @@ private slots:
     void menuUpdateAction( QObject * );
 signals:
     void  toolBarConfUpdated();
+    void releaseMouseEvents();
 };
 
 class DialogEvent : public QEvent
diff --git a/modules/gui/qt/main_interface.cpp b/modules/gui/qt/main_interface.cpp
index c06c26f502..28ec1eac67 100644
--- a/modules/gui/qt/main_interface.cpp
+++ b/modules/gui/qt/main_interface.cpp
@@ -229,6 +229,8 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
     CONNECT( this, askBoss(), this, setBoss() );
     CONNECT( this, askRaise(), this, setRaise() );
 
+
+    connect( THEDP, &DialogsProvider::releaseMouseEvents, this, &MainInterface::voutReleaseMouseEvents ) ;
     /** END of CONNECTS**/
 
 
@@ -1665,6 +1667,29 @@ void MainInterface::setRaise()
     raise();
 }
 
+void MainInterface::voutReleaseMouseEvents()
+{
+    if (videoWidget)
+    {
+        QPoint pos = QCursor::pos();
+        QPoint localpos = videoWidget->mapFromGlobal(pos);
+        int buttons = QApplication::mouseButtons();
+        int i_button = 1;
+        while (buttons != 0)
+        {
+            if ( (buttons & 1) != 0 )
+            {
+                QMouseEvent new_e( QEvent::MouseButtonRelease, localpos,
+                                   (Qt::MouseButton)i_button, (Qt::MouseButton)i_button, Qt::NoModifier );
+                QApplication::sendEvent(videoWidget, &new_e);
+            }
+            buttons >>= 1;
+            i_button <<= 1;
+        }
+
+    }
+}
+
 /*****************************************************************************
  * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
  *  We don't show the menu directly here because we don't want the
diff --git a/modules/gui/qt/main_interface.hpp b/modules/gui/qt/main_interface.hpp
index c0fe178135..e986c69bae 100644
--- a/modules/gui/qt/main_interface.hpp
+++ b/modules/gui/qt/main_interface.hpp
@@ -253,6 +253,7 @@ protected slots:
     void setVideoOnTop( bool );
     void setBoss();
     void setRaise();
+    void voutReleaseMouseEvents();
 
     void showResumePanel( int64_t);
     void hideResumePanel();
-- 
2.14.2



More information about the vlc-devel mailing list