Skip to content

Commit

Permalink
qt: support CSD shadows in compositor_wayland
Browse files Browse the repository at this point in the history
  • Loading branch information
fuzun authored and fkuehne committed Jun 23, 2024
1 parent 0a47412 commit 062d5ba
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
38 changes: 36 additions & 2 deletions modules/gui/qt/maininterface/compositor_wayland.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
#include <QtGui/qpa/qplatformnativeinterface.h>
#include <QtGui/qpa/qplatformwindow.h>

#ifdef QT_WAYLAND_HAS_CUSTOM_MARGIN_SUPPORT
#include <QtGui/qpa/qplatformwindow_p.h>
#endif

#include <vlc_window.h>
#include <vlc_modules.h>

Expand Down Expand Up @@ -113,8 +117,25 @@ bool CompositorWayland::makeMainInterface(MainCtx* mainCtx)

m_waylandImpl->setupInterface(m_waylandImpl, interfaceSurface, dprForWindow(m_qmlView.get()));

const bool ret = commonGUICreate(m_qmlView.get(), m_qmlView.get(),
CompositorVideo::CAN_SHOW_PIP | CompositorVideo::HAS_ACRYLIC);
CompositorVideo::Flags flags = CompositorVideo::CAN_SHOW_PIP | CompositorVideo::HAS_ACRYLIC;

#ifdef QT_WAYLAND_HAS_CUSTOM_MARGIN_SUPPORT
connect(m_intf->p_mi, &MainCtx::windowExtendedMarginChanged, this, [this](const unsigned margin) {
const auto quickViewPtr = m_qmlView.get();
assert(quickViewPtr);
connect(quickViewPtr, &QWindow::widthChanged, this, &CompositorWayland::adjustQuickWindowMask, Qt::UniqueConnection);
connect(quickViewPtr, &QWindow::heightChanged, this, &CompositorWayland::adjustQuickWindowMask, Qt::UniqueConnection);

const auto waylandWindow = dynamic_cast<QNativeInterface::Private::QWaylandWindow *>(quickViewPtr->handle());
assert(waylandWindow);
const QMargins margins(margin, margin, margin, margin);
waylandWindow->setCustomMargins(margins);
});

flags |= CompositorVideo::HAS_EXTENDED_FRAME;
#endif

const bool ret = commonGUICreate(m_qmlView.get(), m_qmlView.get(), flags);

if (ret)
m_qmlView->show();
Expand Down Expand Up @@ -206,4 +227,17 @@ void CompositorWayland::onSurfaceSizeChanged(const QSizeF& size)
size.height() / nativeDpr);
}

#ifdef QT_WAYLAND_HAS_CUSTOM_MARGIN_SUPPORT
void CompositorWayland::adjustQuickWindowMask()
{
assert(m_intf);
assert(m_intf->p_mi);
unsigned maskMargin = 0;
if (Q_LIKELY(static_cast<unsigned>(m_intf->p_mi->CSDBorderSize()) < m_intf->p_mi->windowExtendedMargin()))
maskMargin = m_intf->p_mi->windowExtendedMargin() - m_intf->p_mi->CSDBorderSize();
const QMargins maskMargins(maskMargin, maskMargin, maskMargin, maskMargin);
m_qmlView->setMask(m_qmlView->geometry().marginsRemoved(maskMargins));
}
#endif

}
8 changes: 7 additions & 1 deletion modules/gui/qt/maininterface/compositor_wayland.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
#include <memory>
#include "compositor.hpp"

#if (QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)) && defined(QT_GUI_PRIVATE)
#define QT_WAYLAND_HAS_CUSTOM_MARGIN_SUPPORT
#endif

class MainCtx;
class QQuickView;
class InterfaceWindowHandler;
Expand Down Expand Up @@ -77,7 +81,9 @@ class CompositorWayland : public CompositorVideo
protected slots:
void onSurfacePositionChanged(const QPointF&) override;
void onSurfaceSizeChanged(const QSizeF&) override;

#ifdef QT_WAYLAND_HAS_CUSTOM_MARGIN_SUPPORT
void adjustQuickWindowMask();
#endif

protected:
std::unique_ptr<QQuickView> m_qmlView;
Expand Down

0 comments on commit 062d5ba

Please sign in to comment.