2020-08-02 22:22:19 +00:00
|
|
|
/*
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
2011-04-28 09:16:27 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-FileCopyrightText: 2011 Arthur Arlt <a.arlt@stud.uni-heidelberg.de>
|
|
|
|
SPDX-FileCopyrightText: 2013 Martin Gräßlin <mgraesslin@kde.org>
|
2011-04-28 09:16:27 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2013-01-28 13:17:12 +00:00
|
|
|
// own
|
2011-04-28 09:16:27 +00:00
|
|
|
#include "outline.h"
|
2013-01-28 13:17:12 +00:00
|
|
|
// KWin
|
2013-04-24 07:50:04 +00:00
|
|
|
#include "composite.h"
|
2017-08-21 09:59:52 +00:00
|
|
|
#include "main.h"
|
|
|
|
#include "platform.h"
|
2014-02-27 14:25:03 +00:00
|
|
|
#include "scripting/scripting.h"
|
2022-01-18 08:35:52 +00:00
|
|
|
#include "utils/common.h"
|
2016-01-29 08:50:52 +00:00
|
|
|
// Frameworks
|
|
|
|
#include <KConfigGroup>
|
2013-04-24 07:50:04 +00:00
|
|
|
// Qt
|
2014-02-27 14:25:03 +00:00
|
|
|
#include <QDebug>
|
|
|
|
#include <QQmlComponent>
|
|
|
|
#include <QQmlContext>
|
|
|
|
#include <QQmlEngine>
|
|
|
|
#include <QQuickWindow>
|
|
|
|
#include <QStandardPaths>
|
2011-04-28 09:16:27 +00:00
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
namespace KWin
|
|
|
|
{
|
2011-04-28 09:16:27 +00:00
|
|
|
|
2013-04-25 06:14:34 +00:00
|
|
|
KWIN_SINGLETON_FACTORY(Outline)
|
|
|
|
|
2013-04-24 07:50:04 +00:00
|
|
|
Outline::Outline(QObject *parent)
|
|
|
|
: QObject(parent)
|
2012-01-31 13:34:04 +00:00
|
|
|
, m_active(false)
|
2011-04-28 09:16:27 +00:00
|
|
|
{
|
2020-09-23 18:39:59 +00:00
|
|
|
connect(Compositor::self(), &Compositor::compositingToggled, this, &Outline::compositingChanged);
|
2011-04-28 09:16:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Outline::~Outline()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void Outline::show()
|
|
|
|
{
|
2013-04-24 07:50:04 +00:00
|
|
|
if (m_visual.isNull()) {
|
|
|
|
createHelper();
|
2011-04-28 11:46:32 +00:00
|
|
|
}
|
2013-04-24 07:50:04 +00:00
|
|
|
if (m_visual.isNull()) {
|
|
|
|
// something went wrong
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_visual->show();
|
2017-04-25 14:38:52 +00:00
|
|
|
m_active = true;
|
2021-06-08 07:02:14 +00:00
|
|
|
Q_EMIT activeChanged();
|
2011-04-28 09:16:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Outline::hide()
|
|
|
|
{
|
2012-01-31 13:34:04 +00:00
|
|
|
if (!m_active) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_active = false;
|
2021-06-08 07:02:14 +00:00
|
|
|
Q_EMIT activeChanged();
|
2013-04-24 07:50:04 +00:00
|
|
|
if (m_visual.isNull()) {
|
|
|
|
return;
|
2011-04-28 11:46:32 +00:00
|
|
|
}
|
2013-04-24 07:50:04 +00:00
|
|
|
m_visual->hide();
|
2011-04-28 09:16:27 +00:00
|
|
|
}
|
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
void Outline::show(const QRect &outlineGeometry)
|
2017-04-25 14:38:52 +00:00
|
|
|
{
|
|
|
|
show(outlineGeometry, QRect());
|
|
|
|
}
|
|
|
|
|
|
|
|
void Outline::show(const QRect &outlineGeometry, const QRect &visualParentGeometry)
|
2011-04-28 09:16:27 +00:00
|
|
|
{
|
|
|
|
setGeometry(outlineGeometry);
|
2017-04-25 14:38:52 +00:00
|
|
|
setVisualParentGeometry(visualParentGeometry);
|
2011-04-28 09:16:27 +00:00
|
|
|
show();
|
|
|
|
}
|
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
void Outline::setGeometry(const QRect &outlineGeometry)
|
2011-04-28 09:16:27 +00:00
|
|
|
{
|
2014-02-27 14:25:03 +00:00
|
|
|
if (m_outlineGeometry == outlineGeometry) {
|
|
|
|
return;
|
|
|
|
}
|
2011-04-28 09:16:27 +00:00
|
|
|
m_outlineGeometry = outlineGeometry;
|
2021-06-08 07:02:14 +00:00
|
|
|
Q_EMIT geometryChanged();
|
|
|
|
Q_EMIT unifiedGeometryChanged();
|
2017-04-25 14:38:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Outline::setVisualParentGeometry(const QRect &visualParentGeometry)
|
|
|
|
{
|
|
|
|
if (m_visualParentGeometry == visualParentGeometry) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_visualParentGeometry = visualParentGeometry;
|
2021-06-08 07:02:14 +00:00
|
|
|
Q_EMIT visualParentGeometryChanged();
|
|
|
|
Q_EMIT unifiedGeometryChanged();
|
2017-04-25 14:38:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QRect Outline::unifiedGeometry() const
|
|
|
|
{
|
|
|
|
return m_outlineGeometry | m_visualParentGeometry;
|
2011-04-28 09:16:27 +00:00
|
|
|
}
|
|
|
|
|
2013-04-24 07:50:04 +00:00
|
|
|
void Outline::createHelper()
|
|
|
|
{
|
|
|
|
if (!m_visual.isNull()) {
|
|
|
|
return;
|
|
|
|
}
|
2017-08-21 09:59:52 +00:00
|
|
|
m_visual.reset(kwinApp()->platform()->createOutline(this));
|
2013-04-24 07:50:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Outline::compositingChanged()
|
|
|
|
{
|
|
|
|
m_visual.reset();
|
|
|
|
if (m_active) {
|
|
|
|
show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
OutlineVisual::OutlineVisual(Outline *outline)
|
|
|
|
: m_outline(outline)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
OutlineVisual::~OutlineVisual()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
CompositedOutlineVisual::CompositedOutlineVisual(Outline *outline)
|
2014-02-27 14:25:03 +00:00
|
|
|
: OutlineVisual(outline)
|
|
|
|
, m_qmlContext()
|
|
|
|
, m_qmlComponent()
|
2014-05-30 13:54:24 +00:00
|
|
|
, m_mainItem()
|
2013-04-24 07:50:04 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
CompositedOutlineVisual::~CompositedOutlineVisual()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void CompositedOutlineVisual::hide()
|
|
|
|
{
|
2022-03-23 10:13:38 +00:00
|
|
|
if (QQuickWindow *w = qobject_cast<QQuickWindow *>(m_mainItem.data())) {
|
2014-02-27 14:25:03 +00:00
|
|
|
w->hide();
|
|
|
|
w->destroy();
|
|
|
|
}
|
2013-04-24 07:50:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CompositedOutlineVisual::show()
|
|
|
|
{
|
2014-02-27 14:25:03 +00:00
|
|
|
if (m_qmlContext.isNull()) {
|
|
|
|
m_qmlContext.reset(new QQmlContext(Scripting::self()->qmlEngine()));
|
|
|
|
m_qmlContext->setContextProperty(QStringLiteral("outline"), outline());
|
|
|
|
}
|
|
|
|
if (m_qmlComponent.isNull()) {
|
|
|
|
m_qmlComponent.reset(new QQmlComponent(Scripting::self()->qmlEngine()));
|
2016-01-29 08:50:52 +00:00
|
|
|
const QString fileName = QStandardPaths::locate(QStandardPaths::GenericDataLocation,
|
2022-03-23 10:13:38 +00:00
|
|
|
kwinApp()->config()->group(QStringLiteral("Outline")).readEntry("QmlPath", QStringLiteral(KWIN_NAME "/outline/plasma/outline.qml")));
|
2014-02-27 14:25:03 +00:00
|
|
|
if (fileName.isEmpty()) {
|
2014-12-05 10:42:15 +00:00
|
|
|
qCDebug(KWIN_CORE) << "Could not locate outline.qml";
|
2014-02-27 14:25:03 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_qmlComponent->loadUrl(QUrl::fromLocalFile(fileName));
|
|
|
|
if (m_qmlComponent->isError()) {
|
2014-12-05 10:42:15 +00:00
|
|
|
qCDebug(KWIN_CORE) << "Component failed to load: " << m_qmlComponent->errors();
|
2014-02-27 14:25:03 +00:00
|
|
|
} else {
|
2014-05-30 13:54:24 +00:00
|
|
|
m_mainItem.reset(m_qmlComponent->create(m_qmlContext.data()));
|
2014-02-27 14:25:03 +00:00
|
|
|
}
|
2019-03-19 14:01:29 +00:00
|
|
|
if (auto w = qobject_cast<QQuickWindow *>(m_mainItem.data())) {
|
|
|
|
w->setProperty("__kwin_outline", true);
|
|
|
|
}
|
2013-04-25 07:40:13 +00:00
|
|
|
}
|
2013-04-24 07:50:04 +00:00
|
|
|
}
|
|
|
|
|
2011-04-28 09:16:27 +00:00
|
|
|
} // namespace
|