From 7aee0fbca150b47c697781f418b8bb5cb49e6c44 Mon Sep 17 00:00:00 2001 From: Michail Vourlakos Date: Mon, 6 Jul 2020 01:34:11 +0300 Subject: [PATCH] upgrade secconfigview to subconfigview class --- app/view/settings/primaryconfigview.cpp | 1 - app/view/settings/secondaryconfigview.cpp | 237 +--------------------- app/view/settings/secondaryconfigview.h | 44 +--- app/view/settings/subconfigview.cpp | 3 - app/view/settings/subconfigview.h | 15 +- 5 files changed, 18 insertions(+), 282 deletions(-) diff --git a/app/view/settings/primaryconfigview.cpp b/app/view/settings/primaryconfigview.cpp index 864acfaa8..ed2fa4314 100644 --- a/app/view/settings/primaryconfigview.cpp +++ b/app/view/settings/primaryconfigview.cpp @@ -204,7 +204,6 @@ void PrimaryConfigView::showSecondaryWindow() { if (!m_secConfigView) { m_secConfigView = new SecondaryConfigView(m_latteView, this); - m_secConfigView->init(); } else if (m_secConfigView && !m_secConfigView->isVisible()){ m_secConfigView->show(); } diff --git a/app/view/settings/secondaryconfigview.cpp b/app/view/settings/secondaryconfigview.cpp index 3c9f98595..6695cab8d 100644 --- a/app/view/settings/secondaryconfigview.cpp +++ b/app/view/settings/secondaryconfigview.cpp @@ -48,31 +48,9 @@ namespace Latte { namespace ViewPart { SecondaryConfigView::SecondaryConfigView(Latte::View *view, PrimaryConfigView *parent) - : QQuickView(nullptr), + : SubConfigView(view, QString("#secondaryconfigview#")), m_parent(parent) { - m_corona = qobject_cast(view->containment()->corona()); - - setupWaylandIntegration(); - - setTitle(validTitle()); - - if (KWindowSystem::isPlatformX11()) { - m_corona->wm()->registerIgnoredWindow(winId()); - } else { - connect(m_corona->wm(), &WindowSystem::AbstractWindowInterface::latteWindowAdded, this, &SecondaryConfigView::updateWaylandId); - } - - setResizeMode(QQuickView::SizeViewToRootObject); - setScreen(view->screen()); - - if (view && view->containment()) { - setIcon(qGuiApp->windowIcon()); - } - - m_screenSyncTimer.setSingleShot(true); - m_screenSyncTimer.setInterval(100); - connect(this, &QQuickView::widthChanged, this, &SecondaryConfigView::updateEffects); connect(this, &QQuickView::heightChanged, this, &SecondaryConfigView::updateEffects); @@ -84,65 +62,15 @@ SecondaryConfigView::SecondaryConfigView(Latte::View *view, PrimaryConfigView *p connections << connect(m_parent, &PrimaryConfigView::availableScreenGeometryChanged, this, &SecondaryConfigView::syncGeometry); - connections << connect(&m_screenSyncTimer, &QTimer::timeout, this, [this]() { - setScreen(m_latteView->screen()); - setFlags(wFlags()); - - if (KWindowSystem::isPlatformX11()) { - m_corona->wm()->setViewExtraFlags(this, false, Latte::Types::NormalWindow); - } - - syncGeometry(); - syncSlideEffect(); - }); - - m_thicknessSyncTimer.setSingleShot(true); - m_thicknessSyncTimer.setInterval(200); - connections << connect(&m_thicknessSyncTimer, &QTimer::timeout, this, [this]() { - syncGeometry(); - }); - - setParentView(view); init(); } -SecondaryConfigView::~SecondaryConfigView() -{ - qDebug() << "SecDockConfigView deleting ..."; - - m_corona->dialogShadows()->removeWindow(this); - - m_corona->wm()->unregisterIgnoredWindow(KWindowSystem::isPlatformX11() ? winId() : m_waylandWindowId); - - for (const auto &var : connections) { - QObject::disconnect(var); - } - - for (const auto &var : viewconnections) { - QObject::disconnect(var); - } -} - void SecondaryConfigView::init() { - qDebug() << "dock secondary config view : initialization started..."; - - setDefaultAlphaBuffer(true); - setColor(Qt::transparent); - m_corona->dialogShadows()->addWindow(this); + SubConfigView::init(); rootContext()->setContextProperty(QStringLiteral("viewConfig"), this); - KDeclarative::KDeclarative kdeclarative; - kdeclarative.setDeclarativeEngine(engine()); - kdeclarative.setTranslationDomain(QStringLiteral("latte-dock")); -#if KF5_VERSION_MINOR >= 45 - kdeclarative.setupContext(); - kdeclarative.setupEngine(engine()); -#else - kdeclarative.setupBindings(); -#endif - QByteArray tempFilePath = "lattedocksecondaryconfigurationui"; updateEnabledBorders(); @@ -159,52 +87,14 @@ void SecondaryConfigView::init() qDebug() << "dock secondary config view : initialization ended..."; } -inline Qt::WindowFlags SecondaryConfigView::wFlags() const -{ - return (flags() | Qt::FramelessWindowHint /*| Qt::WindowStaysOnTopHint*/) & ~Qt::WindowDoesNotAcceptFocus; -} - -QString SecondaryConfigView::validTitle() const -{ - return QString("#secondaryconfigview#"); -} - QRect SecondaryConfigView::geometryWhenVisible() const { return m_geometryWhenVisible; } -Latte::View *SecondaryConfigView::parentView() const -{ - return m_latteView; -} - -void SecondaryConfigView::setParentView(Latte::View *view) -{ - if (m_latteView == view) { - return; - } - - initParentView(view); -} - void SecondaryConfigView::initParentView(Latte::View *view) { - for (const auto &var : viewconnections) { - QObject::disconnect(var); - } - - m_latteView = view; - - viewconnections << connect(m_latteView->visibility(), &VisibilityManager::modeChanged, this, &SecondaryConfigView::syncGeometry); - viewconnections << connect(m_latteView, &Latte::View::normalThicknessChanged, [&]() { - m_thicknessSyncTimer.start(); - }); - - //! Assign app interfaces in be accessible through containment graphic item - QQuickItem *containmentGraphicItem = qobject_cast(m_latteView->containment()->property("_plasma_graphicObject").value()); - rootContext()->setContextProperty(QStringLiteral("plasmoid"), containmentGraphicItem); - rootContext()->setContextProperty(QStringLiteral("latteView"), m_latteView); + SubConfigView::initParentView(view); updateEnabledBorders(); syncGeometry(); @@ -214,16 +104,6 @@ void SecondaryConfigView::initParentView(Latte::View *view) } } -void SecondaryConfigView::requestActivate() -{ - if (KWindowSystem::isPlatformWayland() && m_shellSurface) { - updateWaylandId(); - m_corona->wm()->requestActivate(m_waylandWindowId); - } else { - QQuickView::requestActivate(); - } -} - void SecondaryConfigView::syncGeometry() { if (!m_latteView || !m_latteView->layout() || !m_latteView->containment() || !m_parent || !rootObject()) { @@ -351,39 +231,6 @@ void SecondaryConfigView::updateViewMask() m_latteView->effects()->setSubtractedMaskRegion(validTitle(), area); } -void SecondaryConfigView::syncSlideEffect() -{ - if (!m_latteView || !m_latteView->containment()) { - return; - } - - auto slideLocation = WindowSystem::AbstractWindowInterface::Slide::None; - - switch (m_latteView->containment()->location()) { - case Plasma::Types::TopEdge: - slideLocation = WindowSystem::AbstractWindowInterface::Slide::Top; - break; - - case Plasma::Types::RightEdge: - slideLocation = WindowSystem::AbstractWindowInterface::Slide::Right; - break; - - case Plasma::Types::BottomEdge: - slideLocation = WindowSystem::AbstractWindowInterface::Slide::Bottom; - break; - - case Plasma::Types::LeftEdge: - slideLocation = WindowSystem::AbstractWindowInterface::Slide::Left; - break; - - default: - qDebug() << staticMetaObject.className() << "wrong location"; - break; - } - - m_corona->wm()->slideWindow(*this, slideLocation); -} - void SecondaryConfigView::showEvent(QShowEvent *ev) { QQuickWindow::showEvent(ev); @@ -424,65 +271,6 @@ void SecondaryConfigView::focusOutEvent(QFocusEvent *ev) } } -void SecondaryConfigView::setupWaylandIntegration() -{ - if (m_shellSurface || !KWindowSystem::isPlatformWayland() || !m_latteView || !m_latteView->containment()) { - // already setup - return; - } - - if (m_corona) { - using namespace KWayland::Client; - PlasmaShell *interface = m_corona->waylandCoronaInterface(); - - if (!interface) { - return; - } - - Surface *s = Surface::fromWindow(this); - - if (!s) { - return; - } - - qDebug() << "wayland secondary settings surface was created..."; - - m_shellSurface = interface->createSurface(s, this); - m_corona->wm()->setViewExtraFlags(m_shellSurface, false); - - syncGeometry(); - } -} - -bool SecondaryConfigView::event(QEvent *e) -{ - if (e->type() == QEvent::PlatformSurface) { - if (auto pe = dynamic_cast(e)) { - switch (pe->surfaceEventType()) { - case QPlatformSurfaceEvent::SurfaceCreated: - - if (m_shellSurface) { - break; - } - - setupWaylandIntegration(); - break; - - case QPlatformSurfaceEvent::SurfaceAboutToBeDestroyed: - if (m_shellSurface) { - delete m_shellSurface; - m_shellSurface = nullptr; - qDebug() << "WAYLAND secondary config window surface was deleted..."; - } - - break; - } - } - } - - return QQuickView::event(e); -} - void SecondaryConfigView::hideConfigWindow() { m_latteView->effects()->removeSubtractedMaskRegion(validTitle()); @@ -495,20 +283,6 @@ void SecondaryConfigView::hideConfigWindow() } } -void SecondaryConfigView::updateWaylandId() -{ - Latte::WindowSystem::WindowId newId = m_corona->wm()->winIdFor("latte-dock", validTitle()); - - if (m_waylandWindowId != newId) { - if (!m_waylandWindowId.isNull()) { - m_corona->wm()->unregisterIgnoredWindow(m_waylandWindowId); - } - - m_waylandWindowId = newId; - m_corona->wm()->registerIgnoredWindow(m_waylandWindowId); - } -} - void SecondaryConfigView::updateEffects() { //! Don't apply any effect before the wayland surface is created under wayland @@ -552,11 +326,6 @@ void SecondaryConfigView::updateEffects() } //!BEGIN borders -Plasma::FrameSvg::EnabledBorders SecondaryConfigView::enabledBorders() const -{ - return m_enabledBorders; -} - void SecondaryConfigView::updateEnabledBorders() { if (!this->screen()) { diff --git a/app/view/settings/secondaryconfigview.h b/app/view/settings/secondaryconfigview.h index 1b7ce3d12..e60568971 100644 --- a/app/view/settings/secondaryconfigview.h +++ b/app/view/settings/secondaryconfigview.h @@ -22,6 +22,7 @@ // local #include +#include "subconfigview.h" #include "../../wm/windowinfowrap.h" //Qt @@ -62,72 +63,41 @@ class PrimaryConfigView; namespace Latte { namespace ViewPart { -class SecondaryConfigView : public QQuickView +class SecondaryConfigView : public SubConfigView { Q_OBJECT - Q_PROPERTY(Plasma::FrameSvg::EnabledBorders enabledBorders READ enabledBorders NOTIFY enabledBordersChanged) - public: SecondaryConfigView(Latte::View *view, PrimaryConfigView *parent); - ~SecondaryConfigView() override; - - void init(); - void requestActivate(); - Qt::WindowFlags wFlags() const; QRect geometryWhenVisible() const; - QString validTitle() const; - - Plasma::FrameSvg::EnabledBorders enabledBorders() const; - - Latte::View *parentView() const; - void setParentView(Latte::View *view); - public slots: + Q_INVOKABLE void syncGeometry() override; Q_INVOKABLE void hideConfigWindow(); - Q_INVOKABLE void syncGeometry(); Q_INVOKABLE void updateEffects(); signals: - void enabledBordersChanged(); void showSignal(); protected: void showEvent(QShowEvent *ev) override; void focusOutEvent(QFocusEvent *ev) override; - bool event(QEvent *e) override; - void syncSlideEffect(); + void init() override; + void initParentView(Latte::View *view) override; + void updateEnabledBorders() override; -private slots: - void updateEnabledBorders(); - void updateWaylandId(); +private slots: void updateViewMask(); private: - void initParentView(Latte::View *view); - -private: - void setupWaylandIntegration(); - QRect m_geometryWhenVisible; - QPointer m_latteView; QPointer m_parent; - QTimer m_screenSyncTimer; - QTimer m_thicknessSyncTimer; - QList connections; - QList viewconnections; - Plasma::FrameSvg::EnabledBorders m_enabledBorders{Plasma::FrameSvg::AllBorders}; //only for the mask on disabled compositing, not to actually paint Plasma::FrameSvg *m_background{nullptr}; - - Latte::Corona *m_corona{nullptr}; - Latte::WindowSystem::WindowId m_waylandWindowId; - KWayland::Client::PlasmaShellSurface *m_shellSurface{nullptr}; }; } diff --git a/app/view/settings/subconfigview.cpp b/app/view/settings/subconfigview.cpp index 9c13c3a75..f0bd9695c 100644 --- a/app/view/settings/subconfigview.cpp +++ b/app/view/settings/subconfigview.cpp @@ -163,9 +163,6 @@ void SubConfigView::initParentView(Latte::View *view) QQuickItem *containmentGraphicItem = qobject_cast(m_latteView->containment()->property("_plasma_graphicObject").value()); rootContext()->setContextProperty(QStringLiteral("plasmoid"), containmentGraphicItem); rootContext()->setContextProperty(QStringLiteral("latteView"), m_latteView); - - updateEnabledBorders(); - syncGeometry(); } void SubConfigView::requestActivate() diff --git a/app/view/settings/subconfigview.h b/app/view/settings/subconfigview.h index 20797a956..98239dddf 100644 --- a/app/view/settings/subconfigview.h +++ b/app/view/settings/subconfigview.h @@ -66,7 +66,7 @@ public: void setParentView(Latte::View *view); public slots: - Q_INVOKABLE virtual void syncGeometry() = 0; + virtual void syncGeometry() = 0; signals: void enabledBordersChanged(); @@ -74,8 +74,8 @@ signals: protected: void syncSlideEffect(); - void init(); - void initParentView(Latte::View *view); + virtual void init(); + virtual void initParentView(Latte::View *view); virtual void updateEnabledBorders() = 0; bool event(QEvent *e) override; @@ -86,12 +86,17 @@ private slots: void updateWaylandId(); protected: + QTimer m_screenSyncTimer; + QPointer m_latteView; QList connections; QList viewconnections; + Plasma::FrameSvg::EnabledBorders m_enabledBorders{Plasma::FrameSvg::AllBorders}; + Latte::Corona *m_corona{nullptr}; + KWayland::Client::PlasmaShellSurface *m_shellSurface{nullptr}; private: void setupWaylandIntegration(); @@ -99,13 +104,9 @@ private: private: QString m_validTitle; - QTimer m_screenSyncTimer; QTimer m_thicknessSyncTimer; - Plasma::FrameSvg::EnabledBorders m_enabledBorders{Plasma::FrameSvg::AllBorders}; - Latte::WindowSystem::WindowId m_waylandWindowId; - KWayland::Client::PlasmaShellSurface *m_shellSurface{nullptr}; }; }