[vlc-commits] [Git][videolan/vlc][master] 3 commits: qt: expose type of compositor through its interface

Jean-Baptiste Kempf gitlab at videolan.org
Thu May 13 09:02:26 UTC 2021



Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC


Commits:
d118f1d0 by Prince Gupta at 2021-05-13T08:43:49+00:00
qt: expose type of compositor through its interface

- - - - -
a787392b by Prince Gupta at 2021-05-13T08:43:49+00:00
qt: move CSD handling to interface_window_handler

only interface_window_handler knows correct root window

fixes CSD settings not updating and aero snap not working with
win7 compositor

- - - - -
c6b19955 by Prince Gupta at 2021-05-13T08:43:49+00:00
qt: show shadows with CSD on windows

closes #25565

- - - - -


16 changed files:

- modules/gui/qt/dialogs/preferences/simple_preferences.cpp
- modules/gui/qt/maininterface/compositor.hpp
- modules/gui/qt/maininterface/compositor_dcomp.cpp
- modules/gui/qt/maininterface/compositor_dcomp.hpp
- modules/gui/qt/maininterface/compositor_dummy.cpp
- modules/gui/qt/maininterface/compositor_dummy.hpp
- modules/gui/qt/maininterface/compositor_win7.cpp
- modules/gui/qt/maininterface/compositor_win7.hpp
- modules/gui/qt/maininterface/interface_window_handler.cpp
- modules/gui/qt/maininterface/interface_window_handler.hpp
- modules/gui/qt/maininterface/main_interface.cpp
- modules/gui/qt/maininterface/main_interface.hpp
- modules/gui/qt/maininterface/main_interface_win32.cpp
- modules/gui/qt/maininterface/main_interface_win32.hpp
- modules/gui/qt/qt.cpp
- modules/gui/qt/qt.hpp


Changes:

=====================================
modules/gui/qt/dialogs/preferences/simple_preferences.cpp
=====================================
@@ -844,7 +844,7 @@ SPrefsPanel::SPrefsPanel( intf_thread_t *_p_intf, QWidget *_parent,
             QObject::connect( ui.intfScaleFactorSpinBox, QOverload<int>::of(&QSpinBox::valueChanged)
                               , p_intf->p_sys->p_mi , updateIntfUserScaleFactorFromControls );
 
-#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
+#if QT_CLIENT_SIDE_DECORATION_AVAILABLE
             CONFIG_BOOL( "qt-titlebar", titleBarCheckBox );
 #else
             ui.titleBarCheckBox->hide();


=====================================
modules/gui/qt/maininterface/compositor.hpp
=====================================
@@ -34,6 +34,12 @@ namespace vlc {
 
 class Compositor {
 public:
+    enum Type
+    {
+        DummyCompositor,
+        Win7Compositor,
+        DirectCompositionCompositor
+    };
 
     virtual ~Compositor() = default;
 
@@ -42,6 +48,8 @@ public:
 
     virtual bool setupVoutWindow(vout_window_t *p_wnd) = 0;
 
+    virtual Type type() const = 0;
+
     //factory
     static Compositor* createCompositor(intf_thread_t *p_intf);
 };


=====================================
modules/gui/qt/maininterface/compositor_dcomp.cpp
=====================================
@@ -326,4 +326,9 @@ bool CompositorDirectComposition::setupVoutWindow(vout_window_t *p_wnd)
     return true;
 }
 
+Compositor::Type CompositorDirectComposition::type() const
+{
+    return Compositor::DirectCompositionCompositor;
+}
+
 }


=====================================
modules/gui/qt/maininterface/compositor_dcomp.hpp
=====================================
@@ -52,6 +52,8 @@ public:
 
     bool setupVoutWindow(vout_window_t *p_wnd) override;
 
+    Type type() const override;
+
 private slots:
     void onSurfacePositionChanged(QPointF position);
 


=====================================
modules/gui/qt/maininterface/compositor_dummy.cpp
=====================================
@@ -74,4 +74,9 @@ bool CompositorDummy::setupVoutWindow(vout_window_t*)
     return false;
 }
 
+Compositor::Type CompositorDummy::type() const
+{
+    return Compositor::DummyCompositor;
+}
+
 }


=====================================
modules/gui/qt/maininterface/compositor_dummy.hpp
=====================================
@@ -42,6 +42,8 @@ public:
 
     bool setupVoutWindow(vout_window_t *p_wnd) override;
 
+    Type type() const override;
+
 protected:
     intf_thread_t *m_intf;
 


=====================================
modules/gui/qt/maininterface/compositor_win7.cpp
=====================================
@@ -192,8 +192,6 @@ MainInterface* CompositorWin7::makeMainInterface()
     m_qmlView->setColor(QColor(Qt::transparent));
     m_qmlView->setGeometry(m_rootWindow->geometry());
     m_qmlView->setMinimumSize( m_rootWindow->minimumSize() );
-    if (m_rootWindow->useClientSideDecoration())
-        m_qmlView->setFlag(Qt::FramelessWindowHint);
 
     m_qmlView->installEventFilter(this);
     Win7NativeEventFilter* m_nativeEventFilter = new Win7NativeEventFilter(this);
@@ -273,6 +271,12 @@ bool CompositorWin7::setupVoutWindow(vout_window_t *p_wnd)
     return true;
 }
 
+
+Compositor::Type CompositorWin7::type() const
+{
+    return Compositor::Win7Compositor;
+}
+
 bool CompositorWin7::eventFilter(QObject*, QEvent* ev)
 {
     switch (ev->type())


=====================================
modules/gui/qt/maininterface/compositor_win7.hpp
=====================================
@@ -52,6 +52,8 @@ public:
     virtual void destroyMainInterface() override;
     virtual bool setupVoutWindow(vout_window_t*) override;
 
+    Type type() const override;
+
 protected:
     bool eventFilter(QObject *obj, QEvent *ev) override;
 


=====================================
modules/gui/qt/maininterface/interface_window_handler.cpp
=====================================
@@ -75,6 +75,11 @@ InterfaceWindowHandler::InterfaceWindowHandler(intf_thread_t *_p_intf, MainInter
     connect(this, &InterfaceWindowHandler::incrementIntfUserScaleFactor,
             m_mainInterface, &MainInterface::incrementIntfUserScaleFactor);
 
+#if QT_CLIENT_SIDE_DECORATION_AVAILABLE
+    connect( m_mainInterface, &MainInterface::useClientSideDecorationChanged,
+             this, &InterfaceWindowHandler::updateCSDWindowSettings );
+#endif
+
     m_window->installEventFilter(this);
 }
 
@@ -85,7 +90,7 @@ InterfaceWindowHandler::~InterfaceWindowHandler()
     WindowStateHolder::holdFullscreen( m_window,  WindowStateHolder::INTERFACE, false );
 }
 
-#if QT_VERSION >= QT_VERSION_CHECK(5,15,0)
+#if QT_CLIENT_SIDE_DECORATION_AVAILABLE
 bool InterfaceWindowHandler::CSDSetCursor(QMouseEvent* mouseEvent)
 {
     if (!m_mainInterface->useClientSideDecoration())
@@ -137,6 +142,13 @@ bool InterfaceWindowHandler::CSDHandleClick(QMouseEvent* mouseEvent)
     }
     return false;
 }
+
+void InterfaceWindowHandler::updateCSDWindowSettings()
+{
+    m_window->hide(); // some window managers don't like to change frame window hint on visible window
+    m_window->setFlag(Qt::FramelessWindowHint, m_mainInterface->useClientSideDecoration());
+    m_window->show();
+}
 #endif
 
 bool InterfaceWindowHandler::eventFilter(QObject*, QEvent* event)
@@ -206,7 +218,7 @@ bool InterfaceWindowHandler::eventFilter(QObject*, QEvent* event)
         }
         break;
     }
-#if QT_VERSION >= QT_VERSION_CHECK(5,15,0)
+#if QT_CLIENT_SIDE_DECORATION_AVAILABLE
     //Handle CSD edge behaviors
     case QEvent::MouseMove:
     {


=====================================
modules/gui/qt/maininterface/interface_window_handler.hpp
=====================================
@@ -55,9 +55,10 @@ signals:
     void incrementIntfUserScaleFactor(bool increment);
 
 private:
-#if QT_VERSION >= QT_VERSION_CHECK(5,15,0)
+#if QT_CLIENT_SIDE_DECORATION_AVAILABLE
     bool CSDSetCursor(QMouseEvent* mouseEvent);
     bool CSDHandleClick(QMouseEvent* mouseEvent);
+    virtual void updateCSDWindowSettings();
 #endif
 
 protected:


=====================================
modules/gui/qt/maininterface/main_interface.cpp
=====================================
@@ -163,7 +163,7 @@ MainInterface::MainInterface(intf_thread_t *_p_intf , QWidget* parent, Qt::Windo
     /* Should the UI stays on top of other windows */
     b_interfaceOnTop = var_InheritBool( p_intf, "video-on-top" );
 
-#if QT_VERSION >= QT_VERSION_CHECK(5,15,0)
+#if QT_CLIENT_SIDE_DECORATION_AVAILABLE
     m_clientSideDecoration = ! var_InheritBool( p_intf, "qt-titlebar" );
 #endif
     m_hasToolbarMenu = var_InheritBool( p_intf, "qt-menubar" );
@@ -305,12 +305,11 @@ void MainInterface::reloadPrefs()
         emit hasToolbarMenuChanged();
     }
 
-#if QT_VERSION >= QT_VERSION_CHECK(5,15,0)
+#if QT_CLIENT_SIDE_DECORATION_AVAILABLE
     if (m_clientSideDecoration != (! var_InheritBool( p_intf, "qt-titlebar" )))
     {
         m_clientSideDecoration = !m_clientSideDecoration;
         emit useClientSideDecorationChanged();
-        updateClientSideDecorations();
     }
 #endif
 }
@@ -720,13 +719,6 @@ void MainInterface::closeEvent( QCloseEvent *e )
     }
 }
 
-void MainInterface::updateClientSideDecorations()
-{
-    hide(); // some window managers don't like to change frame window hint on visible window
-    setWindowFlag(Qt::FramelessWindowHint, useClientSideDecoration());
-    show();
-}
-
 void MainInterface::setInterfaceFullScreen( bool fs )
 {
     b_interfaceFullScreen = fs;


=====================================
modules/gui/qt/maininterface/main_interface.hpp
=====================================
@@ -226,7 +226,6 @@ protected:
     void dragMoveEvent( QDragMoveEvent * ) Q_DECL_OVERRIDE;
     void dragLeaveEvent( QDragLeaveEvent * ) Q_DECL_OVERRIDE;
     void closeEvent( QCloseEvent *) Q_DECL_OVERRIDE;
-    virtual void updateClientSideDecorations();
 
 protected:
     /* Systray */


=====================================
modules/gui/qt/maininterface/main_interface_win32.cpp
=====================================
@@ -27,6 +27,7 @@
 
 #include "main_interface_win32.hpp"
 
+#include "maininterface/compositor.hpp"
 #include "player/player_controller.hpp"
 #include "playlist/playlist_controller.hpp"
 #include "dialogs/dialogs_provider.hpp"
@@ -39,6 +40,8 @@
 #include <QWindow>
 #include <qpa/qplatformnativeinterface.h>
 
+#include <dwmapi.h>
+
 #define WM_APPCOMMAND 0x0319
 
 #define APPCOMMAND_VOLUME_MUTE            8
@@ -93,6 +96,81 @@ HWND WinId( QWindow *windowHandle )
         return 0;
 }
 
+class CSDWin32EventHandler : public QObject, public QAbstractNativeEventFilter
+{
+public:
+    CSDWin32EventHandler(const bool useClientSideDecoration, const bool isWin7Compositor, QWindow *window, QObject *parent)
+        : QObject {parent}
+        , m_useClientSideDecoration {useClientSideDecoration}
+        , m_window {window}
+        , m_isWin7Compositor {isWin7Compositor}
+    {
+        QApplication::instance()->installNativeEventFilter(this);
+        updateCSDSettings();
+    }
+
+    bool nativeEventFilter(const QByteArray &, void *message, long *result) override
+    {
+        MSG* msg = static_cast<MSG*>( message );
+
+        if ( (msg->message == WM_NCCALCSIZE) && (msg->hwnd == WinId(m_window)) )
+        {
+            /* This is used to remove the decoration instead of using FramelessWindowHint because
+             * frameless window don't support areo snapping
+             */
+            if (m_useClientSideDecoration) {
+                *result = WVR_REDRAW;
+                return true;
+            }
+        }
+
+        return false;
+    }
+
+    void setUseClientSideDecoration(bool useClientSideDecoration)
+    {
+        m_useClientSideDecoration = useClientSideDecoration;
+
+        updateCSDSettings();
+    }
+
+private:
+    void updateCSDSettings()
+    {
+        HWND winId = WinId(m_window);
+
+        if (m_isWin7Compositor)
+        {
+            // special case for win7 compositor
+            // removing CSD borders with win7 compositor works with Qt::FramelessWindowHint
+            // but with that the shadows don't work, so manually remove WS_CAPTION style
+            DWORD style = m_nonCSDGwlStyle == 0 ? GetWindowLong(winId, GWL_STYLE) : m_nonCSDGwlStyle;
+            if (m_nonCSDGwlStyle == 0)
+                m_nonCSDGwlStyle = style;
+            if (m_useClientSideDecoration)
+            {
+                style &= ~WS_CAPTION;
+                style |= (WS_MAXIMIZEBOX | WS_THICKFRAME);
+            }
+            SetWindowLong (winId, GWL_STYLE, style);
+        }
+
+        // add back shadows
+        const MARGINS m {0, 0, (m_useClientSideDecoration ? 1 : 0) /* top margin */ , 0};
+        DwmExtendFrameIntoClientArea(winId, &m);
+
+        SetWindowPos(winId, NULL, 0, 0, 0, 0,
+            SWP_FRAMECHANGED | SWP_NOACTIVATE | SWP_NOCOPYBITS |
+            SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOREPOSITION |
+            SWP_NOSENDCHANGING | SWP_NOSIZE | SWP_NOZORDER);
+    }
+
+    DWORD m_nonCSDGwlStyle = 0;
+    bool m_useClientSideDecoration;
+    QWindow *m_window;
+    const bool m_isWin7Compositor;
+};
+
 }
 
 WinTaskbarWidget::WinTaskbarWidget(intf_thread_t *_p_intf, QWindow* windowHandle, QObject* parent)
@@ -340,19 +418,6 @@ bool MainInterfaceWin32::nativeEvent(const QByteArray &eventType, void *message,
     short cmd;
     switch( msg->message )
     {
-#if QT_VERSION >= QT_VERSION_CHECK(5,15,0)
-        case WM_NCCALCSIZE:
-        {
-            /* This is used to remove the decoration instead of using FramelessWindowHint because
-             * frameless window don't support areo snapping
-             */
-            if (useClientSideDecoration()) {
-                *result = 0;
-                return true;
-            }
-            break;
-        }
-#endif
         case WM_APPCOMMAND:
             cmd = GET_APPCOMMAND_LPARAM(msg->lParam);
 
@@ -425,6 +490,13 @@ bool MainInterfaceWin32::nativeEvent(const QByteArray &eventType, void *message,
 
 InterfaceWindowHandlerWin32::InterfaceWindowHandlerWin32(intf_thread_t *_p_intf, MainInterface* mainInterface, QWindow* window, QObject *parent)
     : InterfaceWindowHandler(_p_intf, mainInterface, window, parent)
+
+#if QT_CLIENT_SIDE_DECORATION_AVAILABLE
+    , m_CSDWindowEventHandler(new CSDWin32EventHandler(mainInterface->useClientSideDecoration(),
+                                                       _p_intf->p_sys->p_compositor->type() == vlc::Compositor::Win7Compositor,
+                                                       window, window))
+#endif
+
 {
 }
 
@@ -434,15 +506,6 @@ void MainInterfaceWin32::reloadPrefs()
     MainInterface::reloadPrefs();
 }
 
-void MainInterfaceWin32::updateClientSideDecorations()
-{
-    HWND winId = WinId(windowHandle());
-    SetWindowPos(winId, NULL, 0, 0, 0, 0,
-        SWP_FRAMECHANGED | SWP_NOACTIVATE | SWP_NOCOPYBITS |
-        SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOREPOSITION |
-        SWP_NOSENDCHANGING | SWP_NOSIZE | SWP_NOZORDER);
-}
-
 
 void InterfaceWindowHandlerWin32::toggleWindowVisiblity()
 {
@@ -530,3 +593,10 @@ bool InterfaceWindowHandlerWin32::eventFilter(QObject* obj, QEvent* ev)
 
     return ret;
 }
+
+#if QT_CLIENT_SIDE_DECORATION_AVAILABLE
+void InterfaceWindowHandlerWin32::updateCSDWindowSettings()
+{
+    static_cast<CSDWin32EventHandler *>(m_CSDWindowEventHandler)->setUseClientSideDecoration(m_mainInterface->useClientSideDecoration());
+}
+#endif


=====================================
modules/gui/qt/maininterface/main_interface_win32.hpp
=====================================
@@ -67,9 +67,6 @@ private:
 
 public slots:
     virtual void reloadPrefs() override;
-
-protected:
-    void updateClientSideDecorations() Q_DECL_OVERRIDE;
 };
 
 class InterfaceWindowHandlerWin32 : public InterfaceWindowHandler
@@ -81,6 +78,12 @@ public:
     virtual void toggleWindowVisiblity() override;
 
     virtual bool eventFilter(QObject*, QEvent* event) override;
+
+private:
+#if QT_CLIENT_SIDE_DECORATION_AVAILABLE
+    void updateCSDWindowSettings() override;
+    QObject *m_CSDWindowEventHandler {};
+#endif
 };
 
 #endif // MAIN_INTERFACE_WIN32_HPP


=====================================
modules/gui/qt/qt.cpp
=====================================
@@ -333,7 +333,7 @@ vlc_module_begin ()
               false                                /* advanced mode only */)
 #endif
 
-#if QT_VERSION >= QT_VERSION_CHECK(5,15,0)
+#if QT_CLIENT_SIDE_DECORATION_AVAILABLE
     add_bool( "qt-titlebar",
 #ifdef _WIN32
               false                              /* use CSD by default on windows */,


=====================================
modules/gui/qt/qt.hpp
=====================================
@@ -169,4 +169,6 @@ static inline QString QVLCUserDir( vlc_userdir_t type )
  */
 #define QT_XMAS_JOKE_DAY 354
 
+#define QT_CLIENT_SIDE_DECORATION_AVAILABLE (QT_VERSION >= QT_VERSION_CHECK(5,15,0))
+
 #endif



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/3fca93ef6e2271806093a260f5b672b14fcaef1f...c6b199559b2a52d7d585ee33821b1ed8e5ef5851

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/3fca93ef6e2271806093a260f5b672b14fcaef1f...c6b199559b2a52d7d585ee33821b1ed8e5ef5851
You're receiving this email because of your account on code.videolan.org.




More information about the vlc-commits mailing list