2011-04-28 09:16:27 +00:00
|
|
|
/********************************************************************
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 2011 Arthur Arlt <a.arlt@stud.uni-heidelberg.de>
|
2013-01-28 13:17:12 +00:00
|
|
|
Copyright (C) 2013 Martin Gräßlin <mgraesslin@kde.org>
|
2011-04-28 09:16:27 +00:00
|
|
|
|
|
|
|
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/>.
|
|
|
|
*********************************************************************/
|
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"
|
2014-02-27 14:25:03 +00:00
|
|
|
#include "scripting/scripting.h"
|
2013-01-28 13:17:12 +00:00
|
|
|
// KWin libs
|
|
|
|
#include <kwinxrenderutils.h>
|
2013-04-25 07:40:13 +00:00
|
|
|
#include "workspace.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>
|
2013-01-28 13:17:12 +00:00
|
|
|
// xcb
|
|
|
|
#include <xcb/render.h>
|
2011-04-28 09:16:27 +00:00
|
|
|
|
|
|
|
namespace KWin {
|
|
|
|
|
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
|
|
|
{
|
2013-04-24 07:50:04 +00:00
|
|
|
connect(Compositor::self(), SIGNAL(compositingToggled(bool)), SLOT(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;
|
|
|
|
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;
|
2014-02-27 14:25:03 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Outline::setGeometry(const QRect& outlineGeometry)
|
|
|
|
{
|
2014-02-27 14:25:03 +00:00
|
|
|
if (m_outlineGeometry == outlineGeometry) {
|
|
|
|
return;
|
|
|
|
}
|
2011-04-28 09:16:27 +00:00
|
|
|
m_outlineGeometry = outlineGeometry;
|
2014-02-27 14:25:03 +00:00
|
|
|
emit geometryChanged();
|
2017-04-25 14:38:52 +00:00
|
|
|
emit unifiedGeometryChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Outline::setVisualParentGeometry(const QRect &visualParentGeometry)
|
|
|
|
{
|
|
|
|
if (m_visualParentGeometry == visualParentGeometry) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_visualParentGeometry = visualParentGeometry;
|
|
|
|
emit visualParentGeometryChanged();
|
|
|
|
emit unifiedGeometryChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
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)
|
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()
|
|
|
|
{
|
2014-05-30 13:54:24 +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,
|
|
|
|
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
|
|
|
}
|
2013-04-25 07:40:13 +00:00
|
|
|
}
|
2013-04-24 07:50:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NonCompositedOutlineVisual::NonCompositedOutlineVisual(Outline *outline)
|
|
|
|
: OutlineVisual(outline)
|
|
|
|
, m_initialized(false)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NonCompositedOutlineVisual::~NonCompositedOutlineVisual()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void NonCompositedOutlineVisual::show()
|
2011-04-28 09:16:27 +00:00
|
|
|
{
|
|
|
|
if (!m_initialized) {
|
2013-01-28 13:17:12 +00:00
|
|
|
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;
|
2011-04-28 09:16:27 +00:00
|
|
|
}
|
2011-05-12 16:52:38 +00:00
|
|
|
|
2013-02-11 14:52:36 +00:00
|
|
|
const int defaultDepth = Xcb::defaultDepth();
|
2011-05-12 16:52:38 +00:00
|
|
|
|
2013-04-24 07:50:04 +00:00
|
|
|
const QRect &outlineGeometry = outline()->geometry();
|
|
|
|
// left/right parts are between top/bottom, they don't reach as far as the corners
|
2013-01-28 13:17:12 +00:00
|
|
|
const uint16_t verticalWidth = 5;
|
2013-04-24 07:50:04 +00:00
|
|
|
const uint16_t verticalHeight = outlineGeometry.height() - 10;
|
|
|
|
const uint16_t horizontalWidth = outlineGeometry.width();
|
2013-01-28 13:17:12 +00:00
|
|
|
const uint horizontalHeight = 5;
|
2013-04-24 07:50:04 +00:00
|
|
|
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);
|
2013-01-28 13:17:12 +00:00
|
|
|
|
|
|
|
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};
|
2011-04-28 09:16:27 +00:00
|
|
|
{
|
2013-01-28 13:17:12 +00:00
|
|
|
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);
|
2011-05-12 16:52:38 +00:00
|
|
|
// According to the XSetWindowBackgroundPixmap documentation the pixmap can be freed.
|
2013-01-28 13:17:12 +00:00
|
|
|
xcb_free_pixmap(connection(), xpix);
|
2011-04-28 09:16:27 +00:00
|
|
|
}
|
|
|
|
{
|
2013-01-28 13:17:12 +00:00
|
|
|
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);
|
2011-05-12 16:52:38 +00:00
|
|
|
// According to the XSetWindowBackgroundPixmap documentation the pixmap can be freed.
|
2013-01-28 13:17:12 +00:00
|
|
|
xcb_free_pixmap(connection(), xpix);
|
2011-04-28 09:16:27 +00:00
|
|
|
}
|
|
|
|
{
|
2013-01-28 13:17:12 +00:00
|
|
|
xcb_pixmap_t xpix = xcb_generate_id(connection());
|
2013-04-24 07:50:04 +00:00
|
|
|
xcb_create_pixmap(connection(), defaultDepth, xpix, rootWindow(), outlineGeometry.width(), 5);
|
2013-01-28 13:17:12 +00:00
|
|
|
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);
|
2011-05-12 16:52:38 +00:00
|
|
|
// According to the XSetWindowBackgroundPixmap documentation the pixmap can be freed.
|
2013-01-28 13:17:12 +00:00
|
|
|
xcb_free_pixmap(connection(), xpix);
|
2011-04-28 09:16:27 +00:00
|
|
|
}
|
2013-01-28 13:17:12 +00:00
|
|
|
forEachWindow(&Xcb::Window::clear);
|
|
|
|
forEachWindow(&Xcb::Window::map);
|
2011-04-28 09:16:27 +00:00
|
|
|
}
|
|
|
|
|
2013-04-24 07:50:04 +00:00
|
|
|
void NonCompositedOutlineVisual::hide()
|
|
|
|
{
|
|
|
|
forEachWindow(&Xcb::Window::unmap);
|
|
|
|
}
|
|
|
|
|
2011-04-28 09:16:27 +00:00
|
|
|
} // namespace
|