[vlc-commits] [Git][videolan/vlc][master] 2 commits: qml: fix maximize button state check

Felix Paul Kühne (@fkuehne) gitlab at videolan.org
Sat Jun 25 16:31:54 UTC 2022



Felix Paul Kühne pushed to branch master at VideoLAN / VLC


Commits:
5208df51 by Pierre Lamot at 2022-06-25T16:13:40+00:00
qml: fix maximize button state check

Window state is not an mask, there is not reason to check it with '&'

Second test was always failing

- - - - -
5ebdaa84 by Pierre Lamot at 2022-06-25T16:13:40+00:00
qt: pass and act on the main widget in InterfaceWindowHandler when available

changing directly the window visibility on the QWindow doesn't allways work as
expected on X11. pass and use the QMainWidget in this case

- - - - -


11 changed files:

- modules/gui/qt/maininterface/compositor.cpp
- modules/gui/qt/maininterface/compositor.hpp
- modules/gui/qt/maininterface/compositor_dcomp.cpp
- modules/gui/qt/maininterface/compositor_dummy.cpp
- modules/gui/qt/maininterface/compositor_win7.cpp
- modules/gui/qt/maininterface/compositor_x11.cpp
- modules/gui/qt/maininterface/interface_window_handler.cpp
- modules/gui/qt/maininterface/interface_window_handler.hpp
- modules/gui/qt/maininterface/mainctx_win32.cpp
- modules/gui/qt/maininterface/mainctx_win32.hpp
- modules/gui/qt/widgets/qml/CSDWindowButtonSet.qml


Changes:

=====================================
modules/gui/qt/maininterface/compositor.cpp
=====================================
@@ -235,7 +235,7 @@ void CompositorVideo::commonWindowDisable()
 }
 
 
-bool CompositorVideo::commonGUICreateImpl(QWindow* window, CompositorVideo::Flags flags)
+bool CompositorVideo::commonGUICreateImpl(QWindow* window, QWidget* rootWidget, CompositorVideo::Flags flags)
 {
     assert(m_mainCtx);
 
@@ -253,9 +253,9 @@ bool CompositorVideo::commonGUICreateImpl(QWindow* window, CompositorVideo::Flag
     m_videoWindowHandler->setWindow( window );
 
 #ifdef _WIN32
-    m_interfaceWindowHandler = std::make_unique<InterfaceWindowHandlerWin32>(m_intf, m_mainCtx, window);
+    m_interfaceWindowHandler = std::make_unique<InterfaceWindowHandlerWin32>(m_intf, m_mainCtx, window, rootWidget);
 #else
-    m_interfaceWindowHandler = std::make_unique<InterfaceWindowHandler>(m_intf, m_mainCtx, window);
+    m_interfaceWindowHandler = std::make_unique<InterfaceWindowHandler>(m_intf, m_mainCtx,  window, rootWidget);
 #endif
     m_mainCtx->setHasAcrylicSurface(flags & CompositorVideo::HAS_ACRYLIC);
 
@@ -267,9 +267,9 @@ bool CompositorVideo::commonGUICreateImpl(QWindow* window, CompositorVideo::Flag
     return true;
 }
 
-bool CompositorVideo::commonGUICreate(QWindow* window, QmlUISurface* qmlSurface, CompositorVideo::Flags flags)
+bool CompositorVideo::commonGUICreate(QWindow* window, QWidget* rootWidget, QmlUISurface* qmlSurface, CompositorVideo::Flags flags)
 {
-    bool ret = commonGUICreateImpl(window, flags);
+    bool ret = commonGUICreateImpl(window, rootWidget, flags);
     if (!ret)
         return false;
     ret = m_ui->setup(qmlSurface->engine());
@@ -279,9 +279,9 @@ bool CompositorVideo::commonGUICreate(QWindow* window, QmlUISurface* qmlSurface,
     return true;
 }
 
-bool CompositorVideo::commonGUICreate(QWindow* window, QQuickView* qmlView, CompositorVideo::Flags flags)
+bool CompositorVideo::commonGUICreate(QWindow* window, QWidget* rootWidget, QQuickView* qmlView, CompositorVideo::Flags flags)
 {
-    bool ret = commonGUICreateImpl(window, flags);
+    bool ret = commonGUICreateImpl(window, rootWidget, flags);
     if (!ret)
         return false;
     ret = m_ui->setup(qmlView->engine());


=====================================
modules/gui/qt/maininterface/compositor.hpp
=====================================
@@ -119,13 +119,13 @@ protected:
     void commonWindowDisable();
 
 protected:
-    bool commonGUICreate(QWindow* window, QmlUISurface* , CompositorVideo::Flags flags);
-    bool commonGUICreate(QWindow* window, QQuickView* , CompositorVideo::Flags flags);
+    bool commonGUICreate(QWindow* window, QWidget* rootWidget, QmlUISurface* , CompositorVideo::Flags flags);
+    bool commonGUICreate(QWindow* window, QWidget* rootWidget, QQuickView* , CompositorVideo::Flags flags);
     void commonGUIDestroy();
     void commonIntfDestroy();
 
 private:
-    bool commonGUICreateImpl(QWindow* window, CompositorVideo::Flags flags);
+    bool commonGUICreateImpl(QWindow* window, QWidget* rootWidget, CompositorVideo::Flags flags);
 
 protected slots:
     virtual void onSurfacePositionChanged(const QPointF&) {}


=====================================
modules/gui/qt/maininterface/compositor_dcomp.cpp
=====================================
@@ -270,7 +270,7 @@ bool CompositorDirectComposition::makeMainInterface(MainCtx* mainCtx)
         if (!ret)
             return false;
 
-        ret = commonGUICreate(m_rootWindow, m_uiSurface.get(), CompositorVideo::CAN_SHOW_PIP);
+        ret = commonGUICreate(m_rootWindow, nullptr, m_uiSurface.get(), CompositorVideo::CAN_SHOW_PIP);
         if (!ret)
             return false;
 


=====================================
modules/gui/qt/maininterface/compositor_dummy.cpp
=====================================
@@ -54,7 +54,7 @@ bool CompositorDummy::makeMainInterface(MainCtx* mainCtx)
         m_qmlWidget->setFlag(Qt::FramelessWindowHint);
     m_qmlWidget->setResizeMode(QQuickView::SizeRootObjectToView);
 
-    m_intfWindowHandler = std::make_unique<InterfaceWindowHandler>(m_intf, m_mainCtx, m_qmlWidget.get());
+    m_intfWindowHandler = std::make_unique<InterfaceWindowHandler>(m_intf, m_mainCtx, m_qmlWidget.get(), nullptr);
 
     MainUI* ui = new MainUI(m_intf, m_mainCtx, m_qmlWidget.get(), m_qmlWidget.get());
     ui->setup(m_qmlWidget->engine());


=====================================
modules/gui/qt/maininterface/compositor_win7.cpp
=====================================
@@ -143,7 +143,7 @@ bool CompositorWin7::makeMainInterface(MainCtx* mainCtx)
 
     m_qmlWindowHWND = (HWND)m_qmlView->winId();
 
-    commonGUICreate(m_qmlView.get(), m_qmlView.get(), CompositorVideo::CAN_SHOW_PIP);
+    commonGUICreate(m_qmlView.get(), nullptr, m_qmlView.get(), CompositorVideo::CAN_SHOW_PIP);
 
     return true;
 }


=====================================
modules/gui/qt/maininterface/compositor_x11.cpp
=====================================
@@ -185,7 +185,7 @@ bool CompositorX11::makeMainInterface(MainCtx* mainCtx)
     CompositorVideo::Flags flags = CompositorVideo::CAN_SHOW_PIP;
     if (m_renderWindow->hasAcrylic())
         flags |= CompositorVideo::HAS_ACRYLIC;
-    commonGUICreate(m_interfaceWindow, m_qmlView.get(), flags);
+    commonGUICreate(m_interfaceWindow, m_renderWindow.get(), m_qmlView.get(), flags);
 
     m_renderWindow->setInterfaceWindow(m_qmlView.get());
     m_renderWindow->setVideoWindow(m_videoWidget->windowHandle());


=====================================
modules/gui/qt/maininterface/interface_window_handler.cpp
=====================================
@@ -25,10 +25,11 @@
 #include <QQmlProperty>
 
 
-InterfaceWindowHandler::InterfaceWindowHandler(qt_intf_t *_p_intf, MainCtx* mainCtx, QWindow* window, QObject *parent)
+InterfaceWindowHandler::InterfaceWindowHandler(qt_intf_t *_p_intf, MainCtx* mainCtx, QWindow* window, QWidget* widget, QObject *parent)
     : QObject(parent)
     , p_intf(_p_intf)
     , m_window(window)
+    , m_widget(widget)
     , m_mainCtx(mainCtx)
 {
     assert(m_window);
@@ -96,18 +97,13 @@ InterfaceWindowHandler::InterfaceWindowHandler(qt_intf_t *_p_intf, MainCtx* main
 #endif
 
     connect(m_mainCtx, &MainCtx::requestInterfaceMaximized,
-            m_window, &QWindow::showMaximized);
+            this, &InterfaceWindowHandler::setInterfaceMaximized);
 
     connect(m_mainCtx, &MainCtx::requestInterfaceNormal,
-            m_window, &QWindow::showNormal);
+            this, &InterfaceWindowHandler::setInterfaceNormal);
 
     connect(m_mainCtx, &MainCtx::requestInterfaceMinimized,
-            m_window, [this]()
-    {
-        // taking OR with the current state, we preserve the current state
-        // so with next active request, we restore window in it's pre-minimized state
-        m_window->setWindowStates(m_window->windowStates() | Qt::WindowMinimized);
-    });
+            this, &InterfaceWindowHandler::setInterfaceMinimized);
 
     m_window->installEventFilter(this);
 }
@@ -124,9 +120,18 @@ InterfaceWindowHandler::~InterfaceWindowHandler()
 #if QT_CLIENT_SIDE_DECORATION_AVAILABLE
 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_mainCtx->useClientSideDecoration());
-    m_window->show();
+    if (m_widget)
+    {
+        m_widget->hide(); // some window managers don't like to change frame window hint on visible window
+        m_widget->setWindowFlag(Qt::FramelessWindowHint, m_mainCtx->useClientSideDecoration());
+        m_widget->show();
+    }
+    else
+    {
+        m_window->hide(); // some window managers don't like to change frame window hint on visible window
+        m_window->setFlag(Qt::FramelessWindowHint, m_mainCtx->useClientSideDecoration());
+        m_window->show();
+    }
 }
 #endif
 
@@ -156,7 +161,7 @@ bool InterfaceWindowHandler::eventFilter(QObject*, QEvent* event)
             oldState & Qt::WindowFullScreen &&
             m_maximizedView )
         {
-            m_window->showMaximized();
+            setInterfaceMaximized();
             return false;
         }
 
@@ -277,15 +282,15 @@ void InterfaceWindowHandler::toggleWindowVisibility()
     {
     case QWindow::Hidden:
         /* If hidden, show it */
-        m_window->show();
-        m_window->requestActivate();
+        setInterfaceShown();
+        requestActivate();
         break;
     case QWindow::Minimized:
-        m_window->showNormal();
-        m_window->requestActivate();
+        setInterfaceNormal();
+        requestActivate();
         break;
     default:
-        m_window->hide();
+        setInterfaceHiden();
         break;
     }
 }
@@ -298,19 +303,19 @@ void InterfaceWindowHandler::setInterfaceVisible(bool visible)
         switch ( m_window->visibility() )
         {
         case QWindow::Hidden:
-            m_window->show();
+            setInterfaceShown();
             break;
         case QWindow::Minimized:
-            m_window->showNormal();
+            setInterfaceNormal();
             break;
         default:
             break;
         }
-        m_window->requestActivate();
+        requestActivate();
     }
     else
     {
-        m_window->hide();
+        setInterfaceHiden();
     }
 }
 
@@ -328,8 +333,11 @@ void InterfaceWindowHandler::setInterfaceFullScreen( bool fs )
 
 void InterfaceWindowHandler::setRaise()
 {
-    m_window->requestActivate();
-    m_window->raise();
+    requestActivate();
+    if (m_widget)
+        m_widget->raise();
+    else
+        m_window->raise();
 }
 
 void InterfaceWindowHandler::setBoss()
@@ -337,14 +345,63 @@ void InterfaceWindowHandler::setBoss()
     THEMPL->pause();
     if( m_mainCtx->getSysTray() )
     {
-        m_window->hide();
+        setInterfaceHiden();
     }
     else
     {
-        m_window->showMinimized();
+        setInterfaceMinimized();
     }
 }
 
+void InterfaceWindowHandler::setInterfaceHiden()
+{
+    if (m_widget)
+        m_widget->hide();
+    else
+        m_window->hide();
+}
+
+void InterfaceWindowHandler::setInterfaceShown()
+{
+    if (m_widget)
+        m_widget->show();
+    else
+        m_window->show();
+}
+
+void InterfaceWindowHandler::setInterfaceMinimized()
+{
+    if (m_widget)
+        m_widget->showMinimized();
+    else
+        m_window->showMinimized();
+}
+
+void InterfaceWindowHandler::setInterfaceMaximized()
+{
+    if (m_widget)
+        m_widget->showMaximized();
+    else
+        m_window->showMaximized();
+}
+
+void InterfaceWindowHandler::setInterfaceNormal()
+{
+    if (m_widget)
+        m_widget->showNormal();
+    else
+        m_window->showNormal();
+}
+
+
+void InterfaceWindowHandler::requestActivate()
+{
+    if (m_widget)
+        m_widget->activateWindow();
+    else
+        m_window->requestActivate();
+}
+
 void InterfaceWindowHandler::setInterfaceAlwaysOnTop( bool on_top )
 {
     WindowStateHolder::holdOnTop(m_window, WindowStateHolder::INTERFACE, on_top);


=====================================
modules/gui/qt/maininterface/interface_window_handler.hpp
=====================================
@@ -28,7 +28,7 @@ class InterfaceWindowHandler : public QObject
 {
     Q_OBJECT
 public:
-    explicit InterfaceWindowHandler(qt_intf_t *_p_intf, MainCtx* mainCtx, QWindow* window, QObject *parent = nullptr);
+    explicit InterfaceWindowHandler(qt_intf_t *_p_intf, MainCtx* mainCtx, QWindow* window, QWidget* widget, QObject *parent = nullptr);
     virtual ~InterfaceWindowHandler();
 
 public slots:
@@ -40,11 +40,17 @@ protected slots:
     virtual void setInterfaceAlwaysOnTop( bool on_top );
     virtual void toggleWindowVisibility();
     virtual void setInterfaceVisible(bool);
-
+    virtual void setInterfaceHiden();
+    virtual void setInterfaceShown();
+    virtual void setInterfaceMinimized();
+    virtual void setInterfaceMaximized();
+    virtual void setInterfaceNormal();
 
     virtual void setRaise();
     virtual void setBoss();
 
+    void requestActivate();
+
     virtual bool eventFilter(QObject*, QEvent* event) override;
 
 signals:
@@ -63,7 +69,11 @@ private:
 
 protected:
     qt_intf_t* p_intf = nullptr;
+    //some compositor uses a Window as the base interface, some uses a widget
+    //when a widget is used, perform window operation on it
     QWindow* m_window = nullptr;
+    QWidget* m_widget = nullptr;
+
     MainCtx* m_mainCtx = nullptr;
 
     bool m_hasPausedWhenMinimized = false;


=====================================
modules/gui/qt/maininterface/mainctx_win32.cpp
=====================================
@@ -505,8 +505,8 @@ void MainCtxWin32::reloadPrefs()
 
 // InterfaceWindowHandlerWin32
 
-InterfaceWindowHandlerWin32::InterfaceWindowHandlerWin32(qt_intf_t *_p_intf, MainCtx* mainCtx, QWindow* window, QObject *parent)
-    : InterfaceWindowHandler(_p_intf, mainCtx, window, parent)
+InterfaceWindowHandlerWin32::InterfaceWindowHandlerWin32(qt_intf_t *_p_intf, MainCtx* mainCtx, QWindow* window, QWidget* widget, QObject *parent)
+    : InterfaceWindowHandler(_p_intf, mainCtx, window, widget, parent)
 
 #if QT_CLIENT_SIDE_DECORATION_AVAILABLE
     , m_CSDWindowEventHandler(new CSDWin32EventHandler(mainCtx->useClientSideDecoration(),
@@ -530,12 +530,12 @@ void InterfaceWindowHandlerWin32::toggleWindowVisibility()
     {
     case QWindow::Hidden:
         /* If hidden, show it */
-        m_window->show();
-        m_window->requestActivate();
+        setInterfaceShown();
+        requestActivate();
         break;
     case QWindow::Minimized:
-        m_window->showNormal();
-        m_window->requestActivate();
+        setInterfaceMinimized();
+        requestActivate();
         break;
     default:
         {
@@ -556,9 +556,9 @@ void InterfaceWindowHandlerWin32::toggleWindowVisibility()
             {
             }
             if( !hwnd || !GetWindowInfo( hwnd, &wi ) || (wi.dwExStyle&WS_EX_TOPMOST) )
-                m_window->hide();
+                setInterfaceHiden();
             else
-                m_window->requestActivate();
+                requestActivate();
         }
         break;
     }


=====================================
modules/gui/qt/maininterface/mainctx_win32.hpp
=====================================
@@ -70,7 +70,7 @@ class InterfaceWindowHandlerWin32 : public InterfaceWindowHandler, public QAbstr
 {
     Q_OBJECT
 public:
-    explicit InterfaceWindowHandlerWin32(qt_intf_t *_p_intf, MainCtx* mainCtx, QWindow* window, QObject *parent = nullptr);
+    explicit InterfaceWindowHandlerWin32(qt_intf_t *_p_intf, MainCtx* mainCtx, QWindow* window, QWidget* widget, QObject *parent = nullptr);
     virtual ~InterfaceWindowHandlerWin32();
     virtual void toggleWindowVisibility() override;
 


=====================================
modules/gui/qt/widgets/qml/CSDWindowButtonSet.qml
=====================================
@@ -40,9 +40,9 @@ Row {
     }
 
     CSDWindowButton {
-        iconTxt: (MainCtx.intfMainWindow.visibility & Window.Maximized)  ? VLCIcons.window_restore :VLCIcons.window_maximize
+        iconTxt: (MainCtx.intfMainWindow.visibility === Window.Maximized)  ? VLCIcons.window_restore :VLCIcons.window_maximize
         onClicked: {
-            if (MainCtx.intfMainWindow & Window.Maximized) {
+            if (MainCtx.intfMainWindow.visibility === Window.Maximized) {
                 MainCtx.requestInterfaceNormal()
             } else {
                 MainCtx.requestInterfaceMaximized()



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/2c872aedbf169b4cf6523f605b73c5ab89b24c11...5ebdaa848b3e6eee4038343e1388a0d6567b10db

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/2c872aedbf169b4cf6523f605b73c5ab89b24c11...5ebdaa848b3e6eee4038343e1388a0d6567b10db
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list