Commit 3c56bd97 authored by Xaver Hugl's avatar Xaver Hugl
Browse files

refactor Outline and move its singleton into Workspace

parent f8516c1b
......@@ -42,7 +42,7 @@ void NonCompositedOutlineVisual::show()
const int defaultDepth = Xcb::defaultDepth();
const QRect &outlineGeometry = outline()->geometry();
const QRect &outlineGeometry = m_outline->geometry();
// left/right parts are between top/bottom, they don't reach as far as the corners
const uint16_t verticalWidth = 5;
const uint16_t verticalHeight = outlineGeometry.height() - 10;
......
......@@ -28,25 +28,20 @@
namespace KWin
{
KWIN_SINGLETON_FACTORY(Outline)
Outline::Outline(QObject *parent)
: QObject(parent)
, m_active(false)
Outline::Outline()
: m_active(false)
{
connect(Compositor::self(), &Compositor::compositingToggled, this, &Outline::compositingChanged);
}
Outline::~Outline()
{
}
Outline::~Outline() = default;
void Outline::show()
{
if (m_visual.isNull()) {
if (!m_visual) {
createHelper();
}
if (m_visual.isNull()) {
if (!m_visual) {
// something went wrong
return;
}
......@@ -62,7 +57,7 @@ void Outline::hide()
}
m_active = false;
Q_EMIT activeChanged();
if (m_visual.isNull()) {
if (!m_visual) {
return;
}
m_visual->hide();
......@@ -107,7 +102,7 @@ QRect Outline::unifiedGeometry() const
void Outline::createHelper()
{
if (!m_visual.isNull()) {
if (m_visual) {
return;
}
m_visual.reset(kwinApp()->platform()->createOutline(this));
......@@ -121,6 +116,21 @@ void Outline::compositingChanged()
}
}
const QRect &Outline::geometry() const
{
return m_outlineGeometry;
}
const QRect &Outline::visualParentGeometry() const
{
return m_visualParentGeometry;
}
bool Outline::isActive() const
{
return m_active;
}
OutlineVisual::OutlineVisual(Outline *outline)
: m_outline(outline)
{
......@@ -144,7 +154,7 @@ CompositedOutlineVisual::~CompositedOutlineVisual()
void CompositedOutlineVisual::hide()
{
if (QQuickWindow *w = qobject_cast<QQuickWindow *>(m_mainItem.data())) {
if (QQuickWindow *w = qobject_cast<QQuickWindow *>(m_mainItem.get())) {
w->hide();
w->destroy();
}
......@@ -152,12 +162,12 @@ void CompositedOutlineVisual::hide()
void CompositedOutlineVisual::show()
{
if (m_qmlContext.isNull()) {
m_qmlContext.reset(new QQmlContext(Scripting::self()->qmlEngine()));
m_qmlContext->setContextProperty(QStringLiteral("outline"), outline());
if (!m_qmlContext) {
m_qmlContext = std::make_unique<QQmlContext>(Scripting::self()->qmlEngine());
m_qmlContext->setContextProperty(QStringLiteral("outline"), m_outline);
}
if (m_qmlComponent.isNull()) {
m_qmlComponent.reset(new QQmlComponent(Scripting::self()->qmlEngine()));
if (!m_qmlComponent) {
m_qmlComponent = std::make_unique<QQmlComponent>(Scripting::self()->qmlEngine());
const QString fileName = QStandardPaths::locate(QStandardPaths::GenericDataLocation,
kwinApp()->config()->group(QStringLiteral("Outline")).readEntry("QmlPath", QStringLiteral(KWIN_NAME "/outline/plasma/outline.qml")));
if (fileName.isEmpty()) {
......@@ -168,9 +178,9 @@ void CompositedOutlineVisual::show()
if (m_qmlComponent->isError()) {
qCDebug(KWIN_CORE) << "Component failed to load: " << m_qmlComponent->errors();
} else {
m_mainItem.reset(m_qmlComponent->create(m_qmlContext.data()));
m_mainItem.reset(m_qmlComponent->create(m_qmlContext.get()));
}
if (auto w = qobject_cast<QQuickWindow *>(m_mainItem.data())) {
if (auto w = qobject_cast<QQuickWindow *>(m_mainItem.get())) {
w->setProperty("__kwin_outline", true);
}
}
......
......@@ -12,6 +12,7 @@
#include <QObject>
#include <QRect>
#include <kwinglobals.h>
#include <memory>
#include <kwin_export.h>
......@@ -33,7 +34,7 @@ class OutlineVisual;
* @author Arthur Arlt
* @since 4.7
*/
class Outline : public QObject
class KWIN_EXPORT Outline : public QObject
{
Q_OBJECT
Q_PROPERTY(QRect geometry READ geometry NOTIFY geometryChanged)
......@@ -41,6 +42,7 @@ class Outline : public QObject
Q_PROPERTY(QRect unifiedGeometry READ unifiedGeometry NOTIFY unifiedGeometryChanged)
Q_PROPERTY(bool active READ isActive NOTIFY activeChanged)
public:
explicit Outline();
~Outline() override;
/**
......@@ -110,11 +112,10 @@ Q_SIGNALS:
private:
void createHelper();
QScopedPointer<OutlineVisual> m_visual;
std::unique_ptr<OutlineVisual> m_visual;
QRect m_outlineGeometry;
QRect m_visualParentGeometry;
bool m_active;
KWIN_SINGLETON(Outline)
};
class KWIN_EXPORT OutlineVisual
......@@ -126,11 +127,7 @@ public:
virtual void hide() = 0;
protected:
Outline *outline();
const Outline *outline() const;
private:
Outline *m_outline;
Outline *const m_outline;
};
class CompositedOutlineVisual : public OutlineVisual
......@@ -142,41 +139,10 @@ public:
void hide() override;
private:
QScopedPointer<QQmlContext> m_qmlContext;
QScopedPointer<QQmlComponent> m_qmlComponent;
QScopedPointer<QObject> m_mainItem;
std::unique_ptr<QQmlContext> m_qmlContext;
std::unique_ptr<QQmlComponent> m_qmlComponent;
std::unique_ptr<QObject> m_mainItem;
};
inline bool Outline::isActive() const
{
return m_active;
}
inline const QRect &Outline::geometry() const
{
return m_outlineGeometry;
}
inline const QRect &Outline::visualParentGeometry() const
{
return m_visualParentGeometry;
}
inline Outline *OutlineVisual::outline()
{
return m_outline;
}
inline const Outline *OutlineVisual::outline() const
{
return m_outline;
}
inline Outline *outline()
{
return Outline::self();
}
}
#endif
......@@ -368,17 +368,17 @@ void WorkspaceWrapper::setupClientConnections(Window *client)
void WorkspaceWrapper::showOutline(const QRect &geometry)
{
outline()->show(geometry);
workspace()->outline()->show(geometry);
}
void WorkspaceWrapper::showOutline(int x, int y, int width, int height)
{
outline()->show(QRect(x, y, width, height));
workspace()->outline()->show(QRect(x, y, width, height));
}
void WorkspaceWrapper::hideOutline()
{
outline()->hide();
workspace()->outline()->hide();
}
X11Window *WorkspaceWrapper::getClient(qulonglong windowId)
......
......@@ -2788,7 +2788,7 @@ void Window::leaveInteractiveMoveResize()
ScreenEdges::self()->reserveDesktopSwitching(false, Qt::Vertical | Qt::Horizontal);
}
if (isElectricBorderMaximizing()) {
outline()->hide();
workspace()->outline()->hide();
elevate(false);
}
}
......@@ -3687,9 +3687,9 @@ void Window::setElectricBorderMaximizing(bool maximizing)
{
m_electricMaximizing = maximizing;
if (maximizing) {
outline()->show(quickTileGeometry(electricBorderMode(), Cursors::self()->mouse()->pos()).toRect(), moveResizeGeometry().toRect());
workspace()->outline()->show(quickTileGeometry(electricBorderMode(), Cursors::self()->mouse()->pos()).toRect(), moveResizeGeometry().toRect());
} else {
outline()->hide();
workspace()->outline()->hide();
}
elevate(maximizing);
}
......
......@@ -181,7 +181,7 @@ Workspace::Workspace()
connect(this, &Workspace::configChanged, m_decorationBridge.get(), &Decoration::DecorationBridge::reconfigure);
new DBusInterface(this);
Outline::create(this);
m_outline = std::make_unique<Outline>();
initShortcuts();
......@@ -2842,6 +2842,11 @@ Decoration::DecorationBridge *Workspace::decorationBridge() const
return m_decorationBridge.get();
}
Outline *Workspace::outline() const
{
return m_outline.get();
}
#if KWIN_BUILD_ACTIVITIES
Activities *Workspace::activities() const
{
......
......@@ -62,6 +62,7 @@ class X11EventFilter;
class FocusChain;
class ApplicationMenu;
enum class Predicate;
class Outline;
#if KWIN_BUILD_ACTIVITIES
class Activities;
#endif
......@@ -436,6 +437,7 @@ public:
FocusChain *focusChain() const;
ApplicationMenu *applicationMenu() const;
Decoration::DecorationBridge *decorationBridge() const;
Outline *outline() const;
#if KWIN_BUILD_ACTIVITIES
Activities *activities() const;
#endif
......@@ -710,6 +712,7 @@ private:
std::unique_ptr<FocusChain> m_focusChain;
std::unique_ptr<ApplicationMenu> m_applicationMenu;
std::unique_ptr<Decoration::DecorationBridge> m_decorationBridge;
std::unique_ptr<Outline> m_outline;
#if KWIN_BUILD_ACTIVITIES
std::unique_ptr<Activities> m_activities;
#endif
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment