1
0
mirror of https://github.com/KDE/latte-dock.git synced 2024-12-24 17:33:50 +03:00

introduce View:SubConfig base view

This commit is contained in:
Michail Vourlakos 2020-07-05 18:26:03 +03:00
parent e31e9323bd
commit 622acc27b9
4 changed files with 409 additions and 1 deletions

View File

@ -2,6 +2,7 @@ set(lattedock-app_SRCS
${lattedock-app_SRCS}
${CMAKE_CURRENT_SOURCE_DIR}/primaryconfigview.cpp
${CMAKE_CURRENT_SOURCE_DIR}/secondaryconfigview.cpp
${CMAKE_CURRENT_SOURCE_DIR}/subconfigview.cpp
${CMAKE_CURRENT_SOURCE_DIR}/viewsettingsfactory.cpp
PARENT_SCOPE
)

View File

@ -85,7 +85,6 @@ public:
PrimaryConfigView(Latte::View *view);
~PrimaryConfigView() override;
void init();
void requestActivate();
Qt::WindowFlags wFlags() const;
@ -153,6 +152,7 @@ private slots:
private:
void setupWaylandIntegration();
void setIsReady(bool ready);
void init();
void initParentView(Latte::View *view);
private:

View File

@ -0,0 +1,293 @@
/*
* Copyright 2020 Michail Vourlakos <mvourlakos@gmail.com>
*
* This file is part of Latte-Dock
*
* Latte-Dock is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* Latte-Dock is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "subconfigview.h"
//local
#include <config-latte.h>
#include "../view.h"
#include "../../lattecorona.h"
#include "../../layouts/manager.h"
#include "../../settings/universalsettings.h"
#include "../../shortcuts/globalshortcuts.h"
#include "../../wm/abstractwindowinterface.h"
// KDE
#include <KLocalizedContext>
#include <KDeclarative/KDeclarative>
#include <KWayland/Client/plasmashell.h>
#include <KWayland/Client/surface.h>
#include <KWindowSystem>
namespace Latte {
namespace ViewPart {
SubConfigView::SubConfigView(Latte::View *view, const QString &title)
: QQuickView(nullptr)
{
m_corona = qobject_cast<Latte::Corona *>(view->containment()->corona());
setupWaylandIntegration();
m_validTitle = title;
setTitle(m_validTitle);
if (KWindowSystem::isPlatformX11()) {
m_corona->wm()->registerIgnoredWindow(winId());
} else {
connect(m_corona->wm(), &WindowSystem::AbstractWindowInterface::latteWindowAdded, this, &SubConfigView::updateWaylandId);
}
setScreen(view->screen());
setIcon(qGuiApp->windowIcon());
m_screenSyncTimer.setSingleShot(true);
m_screenSyncTimer.setInterval(100);
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);
}
SubConfigView::~SubConfigView()
{
qDebug() << validTitle() << " 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 SubConfigView::init()
{
qDebug() << validTitle() << " : initialization started...";
setDefaultAlphaBuffer(true);
setColor(Qt::transparent);
m_corona->dialogShadows()->addWindow(this);
if (m_corona) {
rootContext()->setContextProperty(QStringLiteral("universalSettings"), m_corona->universalSettings());
rootContext()->setContextProperty(QStringLiteral("layoutsManager"), m_corona->layoutsManager());
}
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
}
Qt::WindowFlags SubConfigView::wFlags() const
{
return (flags() | Qt::FramelessWindowHint) & ~Qt::WindowDoesNotAcceptFocus;
}
QString SubConfigView::validTitle() const
{
return m_validTitle;
}
Latte::View *SubConfigView::parentView() const
{
return m_latteView;
}
void SubConfigView::setParentView(Latte::View *view)
{
if (m_latteView == view) {
return;
}
initParentView(view);
}
void SubConfigView::initParentView(Latte::View *view)
{
for (const auto &var : viewconnections) {
QObject::disconnect(var);
}
m_latteView = view;
viewconnections << connect(m_latteView->visibility(), &VisibilityManager::modeChanged, this, &SubConfigView::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<QQuickItem *>(m_latteView->containment()->property("_plasma_graphicObject").value<QObject *>());
rootContext()->setContextProperty(QStringLiteral("plasmoid"), containmentGraphicItem);
rootContext()->setContextProperty(QStringLiteral("latteView"), m_latteView);
updateEnabledBorders();
syncGeometry();
}
void SubConfigView::requestActivate()
{
if (KWindowSystem::isPlatformWayland() && m_shellSurface) {
updateWaylandId();
m_corona->wm()->requestActivate(m_waylandWindowId);
} else {
QQuickView::requestActivate();
}
}
void SubConfigView::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 SubConfigView::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 primary settings surface was created...";
m_shellSurface = interface->createSurface(s, this);
m_corona->wm()->setViewExtraFlags(m_shellSurface, false);
syncGeometry();
}
}
bool SubConfigView::event(QEvent *e)
{
if (e->type() == QEvent::PlatformSurface) {
if (auto pe = dynamic_cast<QPlatformSurfaceEvent *>(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 config window surface was deleted...";
}
break;
}
}
}
return QQuickView::event(e);
}
void SubConfigView::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);
}
}
Plasma::FrameSvg::EnabledBorders SubConfigView::enabledBorders() const
{
return m_enabledBorders;
}
}
}

View File

@ -0,0 +1,114 @@
/*
* Copyright 2020 Michail Vourlakos <mvourlakos@gmail.com>
*
* This file is part of Latte-Dock
*
* Latte-Dock is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* Latte-Dock is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef SUBCONFIGVIEW_H
#define SUBCONFIGVIEW_H
// local
#include "../../wm/windowinfowrap.h"
//Qt
#include <QObject>
#include <QPointer>
#include <QQuickView>
#include <QTimer>
// Plasma
#include <Plasma/FrameSvg>
namespace KWayland {
namespace Client {
class PlasmaShellSurface;
}
}
namespace Latte {
class Corona;
class View;
}
namespace Latte {
namespace ViewPart {
class SubConfigView : public QQuickView
{
Q_OBJECT
Q_PROPERTY(Plasma::FrameSvg::EnabledBorders enabledBorders READ enabledBorders NOTIFY enabledBordersChanged)
public:
SubConfigView(Latte::View *view, const QString &title);
~SubConfigView() override;
void requestActivate();
QString validTitle() const;
Plasma::FrameSvg::EnabledBorders enabledBorders() const;
Latte::View *parentView() const;
void setParentView(Latte::View *view);
public slots:
Q_INVOKABLE virtual void syncGeometry() = 0;
signals:
void enabledBordersChanged();
protected:
void syncSlideEffect();
void init();
void initParentView(Latte::View *view);
virtual void updateEnabledBorders() = 0;
bool event(QEvent *e) override;
Qt::WindowFlags wFlags() const;
private slots:
void updateWaylandId();
protected:
QPointer<Latte::View> m_latteView;
QList<QMetaObject::Connection> connections;
QList<QMetaObject::Connection> viewconnections;
Latte::Corona *m_corona{nullptr};
private:
void setupWaylandIntegration();
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};
};
}
}
#endif //SUBCONFIGVIEW_H