[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kwin] /: Move NonComposited Outline into the X11 standalone platform
From:       Martin_Flöser <null () kde ! org>
Date:       2017-09-01 15:11:26
Message-ID: E1dnnbS-0007Tn-Qg () code ! kde ! org
[Download RAW message or body]

Git commit a3dc2ad5a26eb036dc18b77f2e35f26d9837fda1 by Martin Flöser.
Committed on 01/09/2017 at 15:07.
Pushed by graesslin into branch 'master'.

Move NonComposited Outline into the X11 standalone platform

Summary:
Creating the OutlineVisual is moved into the Platform API. The default
implementation creates the composited OutlineVisual. The X11 standalone
platform overrides it and creates the non composited outline in case no
compositing is used.

Test Plan:
Run kwin_x11 with KWIN_COMPOSE=N and KWIN_COMPOSE=X,
non composited outline and composited outline loaded

Reviewers: #kwin, #plasma

Subscribers: plasma-devel, kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D7450

M  +4    -129  outline.cpp
M  +4    -32   outline.h
M  +9    -0    platform.cpp
M  +8    -0    platform.h
M  +1    -0    plugins/platforms/x11/standalone/CMakeLists.txt
C  +2    -163  plugins/platforms/x11/standalone/non_composited_outline.cpp [from: \
outline.cpp - 062% similarity] A  +59   -0    \
plugins/platforms/x11/standalone/non_composited_outline.h     [License: GPL (v2)] M  \
+10   -0    plugins/platforms/x11/standalone/x11_platform.cpp M  +1    -0    \
plugins/platforms/x11/standalone/x11_platform.h

https://commits.kde.org/kwin/a3dc2ad5a26eb036dc18b77f2e35f26d9837fda1

diff --git a/outline.cpp b/outline.cpp
index 5ad303bb1..69a8a5462 100644
--- a/outline.cpp
+++ b/outline.cpp
@@ -22,10 +22,10 @@ along with this program.  If not, see \
<http://www.gnu.org/licenses/>.  #include "outline.h"
 // KWin
 #include "composite.h"
+#include "main.h"
+#include "platform.h"
 #include "scripting/scripting.h"
-// KWin libs
-#include <kwinxrenderutils.h>
-#include "workspace.h"
+#include "utils.h"
 // Frameworks
 #include <KConfigGroup>
 // Qt
@@ -35,8 +35,6 @@ along with this program.  If not, see \
<http://www.gnu.org/licenses/>.  #include <QQmlEngine>
 #include <QQuickWindow>
 #include <QStandardPaths>
-// xcb
-#include <xcb/render.h>
 
 namespace KWin {
 
@@ -122,11 +120,7 @@ void Outline::createHelper()
     if (!m_visual.isNull()) {
         return;
     }
-    if (Compositor::compositing()) {
-        m_visual.reset(new CompositedOutlineVisual(this));
-    } else {
-        m_visual.reset(new NonCompositedOutlineVisual(this));
-    }
+    m_visual.reset(kwinApp()->platform()->createOutline(this));
 }
 
 void Outline::compositingChanged()
@@ -189,123 +183,4 @@ void CompositedOutlineVisual::show()
     }
 }
 
-NonCompositedOutlineVisual::NonCompositedOutlineVisual(Outline *outline)
-    : OutlineVisual(outline)
-    , m_initialized(false)
-{
-}
-
-NonCompositedOutlineVisual::~NonCompositedOutlineVisual()
-{
-}
-
-void NonCompositedOutlineVisual::show()
-{
-    if (!m_initialized) {
-        const QRect geo(0, 0, 1, 1);
-        const uint32_t values[] = {true};
-        // TODO: use template variant
-        m_leftOutline.create(geo, XCB_CW_OVERRIDE_REDIRECT, values);
-        m_rightOutline.create(geo, XCB_CW_OVERRIDE_REDIRECT, values);
-        m_topOutline.create(geo, XCB_CW_OVERRIDE_REDIRECT, values);
-        m_bottomOutline.create(geo, XCB_CW_OVERRIDE_REDIRECT, values);
-        m_initialized   = true;
-    }
-
-    const int defaultDepth = Xcb::defaultDepth();
-
-    const QRect &outlineGeometry = 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;
-    const uint16_t horizontalWidth = outlineGeometry.width();
-    const uint horizontalHeight = 5;
-    m_leftOutline.setGeometry(outlineGeometry.x(), outlineGeometry.y() + 5, \
                verticalWidth, verticalHeight);
-    m_rightOutline.setGeometry(outlineGeometry.x() + outlineGeometry.width() - 5, \
                outlineGeometry.y() + 5, verticalWidth, verticalHeight);
-    m_topOutline.setGeometry(outlineGeometry.x(), outlineGeometry.y(), \
                horizontalWidth, horizontalHeight);
-    m_bottomOutline.setGeometry(outlineGeometry.x(), outlineGeometry.y() + \
                outlineGeometry.height() - 5, horizontalWidth, horizontalHeight);
-
-    const xcb_render_color_t white = {0xffff, 0xffff, 0xffff, 0xffff};
-    QColor qGray(Qt::gray);
-    const xcb_render_color_t gray = {
-        uint16_t(0xffff * qGray.redF()),
-        uint16_t(0xffff * qGray.greenF()),
-        uint16_t(0xffff * qGray.blueF()),
-        0xffff
-    };
-    const xcb_render_color_t black = {0, 0, 0, 0xffff};
-    {
-        xcb_pixmap_t xpix = xcb_generate_id(connection());
-        xcb_create_pixmap(connection(), defaultDepth, xpix, rootWindow(), \
                verticalWidth, verticalHeight);
-        XRenderPicture pic(xpix, defaultDepth);
-
-        xcb_rectangle_t rect = {0, 0, 5, verticalHeight};
-        xcb_render_fill_rectangles(connection(), XCB_RENDER_PICT_OP_SRC, pic, white, \
                1, &rect);
-        rect.x = 1;
-        rect.width = 3;
-        xcb_render_fill_rectangles(connection(), XCB_RENDER_PICT_OP_SRC, pic, gray, \
                1, &rect);
-        rect.x = 2;
-        rect.width = 1;
-        xcb_render_fill_rectangles(connection(), XCB_RENDER_PICT_OP_SRC, pic, black, \
                1, &rect);
-
-        m_leftOutline.setBackgroundPixmap(xpix);
-        m_rightOutline.setBackgroundPixmap(xpix);
-        // According to the XSetWindowBackgroundPixmap documentation the pixmap can \
                be freed.
-        xcb_free_pixmap(connection(), xpix);
-    }
-    {
-        xcb_pixmap_t xpix = xcb_generate_id(connection());
-        xcb_create_pixmap(connection(), defaultDepth, xpix, rootWindow(), \
                horizontalWidth, horizontalHeight);
-        XRenderPicture pic(xpix, defaultDepth);
-
-        xcb_rectangle_t rect = {0, 0, horizontalWidth, horizontalHeight};
-        xcb_render_fill_rectangles(connection(), XCB_RENDER_PICT_OP_SRC, pic, white, \
                1, &rect);
-        xcb_rectangle_t grayRects[] = {
-            {1, 1, uint16_t(horizontalWidth -2), 3},
-            {1, 4, 3, 1},
-            {int16_t(horizontalWidth - 4), 4, 3, 1}
-        };
-        xcb_render_fill_rectangles(connection(), XCB_RENDER_PICT_OP_SRC, pic, gray, \
                3, grayRects);
-        xcb_rectangle_t blackRects[] = {
-            {2, 2, uint16_t(horizontalWidth -4), 1},
-            {2, 3, 1, 2},
-            {int16_t(horizontalWidth - 3), 3, 1, 2}
-        };
-        xcb_render_fill_rectangles(connection(), XCB_RENDER_PICT_OP_SRC, pic, black, \
                3, blackRects);
-        m_topOutline.setBackgroundPixmap(xpix);
-        // According to the XSetWindowBackgroundPixmap documentation the pixmap can \
                be freed.
-        xcb_free_pixmap(connection(), xpix);
-    }
-    {
-        xcb_pixmap_t xpix = xcb_generate_id(connection());
-        xcb_create_pixmap(connection(), defaultDepth, xpix, rootWindow(), \
                outlineGeometry.width(), 5);
-        XRenderPicture pic(xpix, defaultDepth);
-
-        xcb_rectangle_t rect = {0, 0, horizontalWidth, horizontalHeight};
-        xcb_render_fill_rectangles(connection(), XCB_RENDER_PICT_OP_SRC, pic, white, \
                1, &rect);
-        xcb_rectangle_t grayRects[] = {
-            {1, 1, uint16_t(horizontalWidth -2), 3},
-            {1, 0, 3, 1},
-            {int16_t(horizontalWidth - 4), 0, 3, 1}
-        };
-        xcb_render_fill_rectangles(connection(), XCB_RENDER_PICT_OP_SRC, pic, gray, \
                3, grayRects);
-        xcb_rectangle_t blackRects[] = {
-            {2, 2, uint16_t(horizontalWidth -4), 1},
-            {2, 0, 1, 2},
-            {int16_t(horizontalWidth - 3), 0, 1, 2}
-        };
-        xcb_render_fill_rectangles(connection(), XCB_RENDER_PICT_OP_SRC, pic, black, \
                3, blackRects);
-        m_bottomOutline.setBackgroundPixmap(xpix);
-        // According to the XSetWindowBackgroundPixmap documentation the pixmap can \
                be freed.
-        xcb_free_pixmap(connection(), xpix);
-    }
-    forEachWindow(&Xcb::Window::clear);
-    forEachWindow(&Xcb::Window::map);
-}
-
-void NonCompositedOutlineVisual::hide()
-{
-    forEachWindow(&Xcb::Window::unmap);
-}
-
 } // namespace
diff --git a/outline.h b/outline.h
index 3771cd789..982c97f11 100644
--- a/outline.h
+++ b/outline.h
@@ -20,10 +20,11 @@ along with this program.  If not, see \
<http://www.gnu.org/licenses/>.  
 #ifndef KWIN_OUTLINE_H
 #define KWIN_OUTLINE_H
-#include "xcbutils.h"
 #include <kwinglobals.h>
 #include <QRect>
-#include <QWidget>
+#include <QObject>
+
+#include <kwin_export.h>
 
 class QQmlContext;
 class QQmlComponent;
@@ -125,7 +126,7 @@ private:
     KWIN_SINGLETON(Outline)
 };
 
-class OutlineVisual
+class KWIN_EXPORT OutlineVisual
 {
 public:
     OutlineVisual(Outline *outline);
@@ -152,25 +153,6 @@ private:
     QScopedPointer<QObject> m_mainItem;
 };
 
-class NonCompositedOutlineVisual : public OutlineVisual
-{
-public:
-    NonCompositedOutlineVisual(Outline *outline);
-    virtual ~NonCompositedOutlineVisual();
-    virtual void show();
-    virtual void hide();
-
-private:
-    // TODO: variadic template arguments for adding method arguments
-    template <typename T>
-    void forEachWindow(T method);
-    bool m_initialized;
-    Xcb::Window m_topOutline;
-    Xcb::Window m_rightOutline;
-    Xcb::Window m_bottomOutline;
-    Xcb::Window m_leftOutline;
-};
-
 inline
 bool Outline::isActive() const
 {
@@ -201,16 +183,6 @@ const Outline *OutlineVisual::outline() const
     return m_outline;
 }
 
-template <typename T>
-inline
-void NonCompositedOutlineVisual::forEachWindow(T method)
-{
-    (m_topOutline.*method)();
-    (m_rightOutline.*method)();
-    (m_bottomOutline.*method)();
-    (m_leftOutline.*method)();
-}
-
 inline
 Outline *outline()
 {
diff --git a/platform.cpp b/platform.cpp
index 8472b56cd..d9ac03206 100644
--- a/platform.cpp
+++ b/platform.cpp
@@ -24,6 +24,7 @@ along with this program.  If not, see \
<http://www.gnu.org/licenses/>.  #include "cursor.h"
 #include "input.h"
 #include "overlaywindow.h"
+#include "outline.h"
 #include "pointer_input.h"
 #include "scene_opengl.h"
 #include "screenedge.h"
@@ -470,4 +471,12 @@ void Platform::updateXTime()
 {
 }
 
+OutlineVisual *Platform::createOutline(Outline *outline)
+{
+    if (Compositor::compositing()) {
+       return new CompositedOutlineVisual(outline);
+    }
+    return nullptr;
+}
+
 }
diff --git a/platform.h b/platform.h
index 1d56933c4..80b5072a1 100644
--- a/platform.h
+++ b/platform.h
@@ -42,6 +42,8 @@ namespace KWin
 class Edge;
 class OverlayWindow;
 class OpenGLBackend;
+class Outline;
+class OutlineVisual;
 class QPainterBackend;
 class Screens;
 class ScreenEdges;
@@ -317,6 +319,12 @@ public:
      **/
     virtual void updateXTime();
 
+    /**
+     * Creates the OutlineVisual for the given @p outline.
+     * Default implementation creates an OutlineVisual suited for composited usage.
+     **/
+    virtual OutlineVisual *createOutline(Outline *outline);
+
 public Q_SLOTS:
     void pointerMotion(const QPointF &position, quint32 time);
     void pointerButtonPressed(quint32 button, quint32 time);
diff --git a/plugins/platforms/x11/standalone/CMakeLists.txt \
b/plugins/platforms/x11/standalone/CMakeLists.txt index 582af8c04..1f398bc6f 100644
--- a/plugins/platforms/x11/standalone/CMakeLists.txt
+++ b/plugins/platforms/x11/standalone/CMakeLists.txt
@@ -7,6 +7,7 @@ set(X11PLATFORM_SOURCES
     windowselector.cpp
     overlaywindow_x11.cpp
     screenedges_filter.cpp
+    non_composited_outline.cpp
 )
 
 if(X11_Xinput_FOUND)
diff --git a/outline.cpp \
b/plugins/platforms/x11/standalone/non_composited_outline.cpp similarity index 62%
copy from outline.cpp
copy to plugins/platforms/x11/standalone/non_composited_outline.cpp
index 5ad303bb1..dd03bbaee 100644
--- a/outline.cpp
+++ b/plugins/platforms/x11/standalone/non_composited_outline.cpp
@@ -19,175 +19,14 @@ You should have received a copy of the GNU General Public \
License  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *********************************************************************/
 // own
-#include "outline.h"
-// KWin
-#include "composite.h"
-#include "scripting/scripting.h"
+#include "non_composited_outline.h"
 // KWin libs
 #include <kwinxrenderutils.h>
-#include "workspace.h"
-// Frameworks
-#include <KConfigGroup>
-// Qt
-#include <QDebug>
-#include <QQmlComponent>
-#include <QQmlContext>
-#include <QQmlEngine>
-#include <QQuickWindow>
-#include <QStandardPaths>
 // xcb
 #include <xcb/render.h>
 
-namespace KWin {
-
-KWIN_SINGLETON_FACTORY(Outline)
-
-Outline::Outline(QObject *parent)
-    : QObject(parent)
-    , m_active(false)
-{
-    connect(Compositor::self(), SIGNAL(compositingToggled(bool)), \
                SLOT(compositingChanged()));
-}
-
-Outline::~Outline()
-{
-}
-
-void Outline::show()
-{
-    if (m_visual.isNull()) {
-        createHelper();
-    }
-    if (m_visual.isNull()) {
-        // something went wrong
-        return;
-    }
-    m_visual->show();
-    m_active = true;
-    emit activeChanged();
-}
-
-void Outline::hide()
-{
-    if (!m_active) {
-        return;
-    }
-    m_active = false;
-    emit activeChanged();
-    if (m_visual.isNull()) {
-        return;
-    }
-    m_visual->hide();
-}
-
-void Outline::show(const QRect& outlineGeometry)
-{
-    show(outlineGeometry, QRect());
-}
-
-void Outline::show(const QRect &outlineGeometry, const QRect &visualParentGeometry)
-{
-    setGeometry(outlineGeometry);
-    setVisualParentGeometry(visualParentGeometry);
-    show();
-}
-
-void Outline::setGeometry(const QRect& outlineGeometry)
-{
-    if (m_outlineGeometry == outlineGeometry) {
-        return;
-    }
-    m_outlineGeometry = outlineGeometry;
-    emit geometryChanged();
-    emit unifiedGeometryChanged();
-}
-
-void Outline::setVisualParentGeometry(const QRect &visualParentGeometry)
-{
-    if (m_visualParentGeometry == visualParentGeometry) {
-        return;
-    }
-    m_visualParentGeometry = visualParentGeometry;
-    emit visualParentGeometryChanged();
-    emit unifiedGeometryChanged();
-}
-
-QRect Outline::unifiedGeometry() const
+namespace KWin
 {
-    return m_outlineGeometry | m_visualParentGeometry;
-}
-
-void Outline::createHelper()
-{
-    if (!m_visual.isNull()) {
-        return;
-    }
-    if (Compositor::compositing()) {
-        m_visual.reset(new CompositedOutlineVisual(this));
-    } else {
-        m_visual.reset(new NonCompositedOutlineVisual(this));
-    }
-}
-
-void Outline::compositingChanged()
-{
-    m_visual.reset();
-    if (m_active) {
-        show();
-    }
-}
-
-OutlineVisual::OutlineVisual(Outline *outline)
-    : m_outline(outline)
-{
-}
-
-OutlineVisual::~OutlineVisual()
-{
-}
-
-CompositedOutlineVisual::CompositedOutlineVisual(Outline *outline)
-    : OutlineVisual(outline)
-    , m_qmlContext()
-    , m_qmlComponent()
-    , m_mainItem()
-{
-}
-
-CompositedOutlineVisual::~CompositedOutlineVisual()
-{
-}
-
-void CompositedOutlineVisual::hide()
-{
-    if (QQuickWindow *w = qobject_cast<QQuickWindow*>(m_mainItem.data())) {
-        w->hide();
-        w->destroy();
-    }
-}
-
-void CompositedOutlineVisual::show()
-{
-    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()));
-        const QString fileName = \
                QStandardPaths::locate(QStandardPaths::GenericDataLocation,
-                                                 \
kwinApp()->config()->group(QStringLiteral("Outline")).readEntry("QmlPath", \
                QStringLiteral(KWIN_NAME "/outline/plasma/outline.qml")));
-        if (fileName.isEmpty()) {
-            qCDebug(KWIN_CORE) << "Could not locate outline.qml";
-            return;
-        }
-        m_qmlComponent->loadUrl(QUrl::fromLocalFile(fileName));
-        if (m_qmlComponent->isError()) {
-            qCDebug(KWIN_CORE) << "Component failed to load: " << \
                m_qmlComponent->errors();
-        } else {
-            m_mainItem.reset(m_qmlComponent->create(m_qmlContext.data()));
-        }
-    }
-}
 
 NonCompositedOutlineVisual::NonCompositedOutlineVisual(Outline *outline)
     : OutlineVisual(outline)
diff --git a/plugins/platforms/x11/standalone/non_composited_outline.h \
b/plugins/platforms/x11/standalone/non_composited_outline.h new file mode 100644
index 000000000..1744ff96a
--- /dev/null
+++ b/plugins/platforms/x11/standalone/non_composited_outline.h
@@ -0,0 +1,59 @@
+/********************************************************************
+ KWin - the KDE window manager
+ This file is part of the KDE project.
+
+Copyright (C) 2011 Arthur Arlt <a.arlt@stud.uni-heidelberg.de>
+
+This program 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.
+
+This program 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 KWIN_NON_COMPOSITED_OUTLINE_H
+#define KWIN_NON_COMPOSITED_OUTLINE_H
+#include "outline.h"
+#include "xcbutils.h"
+
+namespace KWin
+{
+
+class NonCompositedOutlineVisual : public OutlineVisual
+{
+public:
+    NonCompositedOutlineVisual(Outline *outline);
+    virtual ~NonCompositedOutlineVisual();
+    virtual void show();
+    virtual void hide();
+
+private:
+    // TODO: variadic template arguments for adding method arguments
+    template <typename T>
+    void forEachWindow(T method);
+    bool m_initialized;
+    Xcb::Window m_topOutline;
+    Xcb::Window m_rightOutline;
+    Xcb::Window m_bottomOutline;
+    Xcb::Window m_leftOutline;
+};
+
+template <typename T>
+inline
+void NonCompositedOutlineVisual::forEachWindow(T method)
+{
+    (m_topOutline.*method)();
+    (m_rightOutline.*method)();
+    (m_bottomOutline.*method)();
+    (m_leftOutline.*method)();
+}
+
+}
+
+#endif
diff --git a/plugins/platforms/x11/standalone/x11_platform.cpp \
b/plugins/platforms/x11/standalone/x11_platform.cpp index e52545fee..59bd8dd90 100644
--- a/plugins/platforms/x11/standalone/x11_platform.cpp
+++ b/plugins/platforms/x11/standalone/x11_platform.cpp
@@ -36,6 +36,7 @@ along with this program.  If not, see \
<http://www.gnu.org/licenses/>.  #include "screenedges_filter.h"
 #include "options.h"
 #include "overlaywindow_x11.h"
+#include "non_composited_outline.h"
 
 #include <KConfigGroup>
 #include <KLocalizedString>
@@ -335,5 +336,14 @@ void X11StandalonePlatform::updateXTime()
     kwinApp()->setX11Time(QX11Info::getTimestamp(), \
Application::TimestampUpdate::Always);  }
 
+OutlineVisual *X11StandalonePlatform::createOutline(Outline *outline)
+{
+    // first try composited Outline
+    auto ret = Platform::createOutline(outline);
+    if (!ret) {
+        ret = new NonCompositedOutlineVisual(outline);
+    }
+    return ret;
+}
 
 }
diff --git a/plugins/platforms/x11/standalone/x11_platform.h \
b/plugins/platforms/x11/standalone/x11_platform.h index eb79276f3..9fce72a0a 100644
--- a/plugins/platforms/x11/standalone/x11_platform.h
+++ b/plugins/platforms/x11/standalone/x11_platform.h
@@ -59,6 +59,7 @@ public:
     OverlayWindow *createOverlayWindow() override;
 
     void updateXTime() override;
+    OutlineVisual *createOutline(Outline *outline) override;
 
 protected:
     void doHideCursor() override;


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic