Commit 8cedb797 authored by David Edmundson's avatar David Edmundson

Port DesktopGrid QtQuickWindow to EffectQuickView

Summary:
Lots of red, does the same thing in a simplified way avoiding creating a
real window and having to hack round it.

Test Plan: Click add and remove, remove button disables appropriately

Reviewers: #kwin, zzag

Reviewed By: #kwin, zzag

Subscribers: meven, zzag, kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D26381
parent 996e8401
......@@ -36,10 +36,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <QMouseEvent>
#include <QTimer>
#include <QVector2D>
#include <QQmlContext>
#include <QQmlEngine>
#include <QQuickItem>
#include <QMatrix4x4>
#include <QQuickItem>
#include <QQmlContext>
#include <KWayland/Server/surface_interface.h>
#include <cmath>
......@@ -102,9 +102,6 @@ DesktopGridEffect::DesktopGridEffect()
DesktopGridEffect::~DesktopGridEffect()
{
foreach (DesktopButtonsView *view, m_desktopButtonsViews)
view->deleteLater();
m_desktopButtonsViews.clear();
}
void DesktopGridEffect::reconfigure(ReconfigureFlags)
......@@ -194,19 +191,9 @@ void DesktopGridEffect::paintScreen(int mask, const QRegion &region, ScreenPaint
}
// paint the add desktop button
foreach (DesktopButtonsView *view, m_desktopButtonsViews) {
if (!view->effectWindow) {
EffectWindow *viewWindow = effects->findWindow(view->winId());
if (viewWindow) {
viewWindow->setData(WindowForceBlurRole, QVariant(true));
view->effectWindow = viewWindow;
}
}
if (view->effectWindow) {
WindowPaintData d(view->effectWindow);
d.multiplyOpacity(timeline.currentValue());
effects->drawWindow(view->effectWindow, PAINT_WINDOW_TRANSLUCENT, infiniteRegion(), d);
}
for (EffectQuickScene *view : m_desktopButtons) {
view->rootItem()->setOpacity(timeline.currentValue());
effects->renderEffectQuickView(view);
}
if (isUsingPresentWindows() && windowMove && wasWindowMove) {
......@@ -313,14 +300,6 @@ void DesktopGridEffect::paintWindow(EffectWindow* w, int mask, QRegion region, W
(sourceDesktop != highlightedDesktop && highlightedDesktop == paintingDesktop))) {
return; // will be painted on top of all other windows
}
foreach (DesktopButtonsView *view, m_desktopButtonsViews) {
if (view->effectWindow == w) {
if (!activated && timeline.currentValue() < 0.05) {
view->hide();
}
return; // will be painted on top of all other windows
}
}
qreal xScale = data.xScale();
qreal yScale = data.yScale();
......@@ -444,12 +423,6 @@ void DesktopGridEffect::slotWindowDeleted(EffectWindow* w)
{
if (w == windowMove)
windowMove = nullptr;
foreach (DesktopButtonsView *view, m_desktopButtonsViews) {
if (view->effectWindow && view->effectWindow == w) {
view->effectWindow = nullptr;
break;
}
}
if (isUsingPresentWindows()) {
for (QList<WindowMotionManager>::iterator it = m_managers.begin(),
end = m_managers.end(); it != end; ++it) {
......@@ -482,11 +455,9 @@ void DesktopGridEffect::windowInputMouseEvent(QEvent* e)
return;
QMouseEvent* me = static_cast< QMouseEvent* >(e);
if (!(wasWindowMove || wasDesktopMove)) {
foreach (DesktopButtonsView *view, m_desktopButtonsViews) {
if (view->geometry().contains(me->pos())) {
const QPoint widgetPos = view->mapFromGlobal(me->pos());
QMouseEvent event(me->type(), widgetPos, me->pos(), me->button(), me->buttons(), me->modifiers());
view->windowInputMouseEvent(&event);
for (EffectQuickScene *view : m_desktopButtons) {
view->forwardMouseEvent(me);
if (e->isAccepted()) {
return;
}
}
......@@ -1060,7 +1031,7 @@ void DesktopGridEffect::setActive(bool active)
[this] {
if (activated)
return;
foreach (DesktopButtonsView *view, m_desktopButtonsViews) {
for (EffectQuickScene *view : m_desktopButtons) {
view->hide();
}
}
......@@ -1125,33 +1096,46 @@ void DesktopGridEffect::setup()
}
}
}
bool enableAdd = effects->numberOfDesktops() < 20;
bool enableRemove = effects->numberOfDesktops() > 1;
QVector<DesktopButtonsView*>::iterator it = m_desktopButtonsViews.begin();
auto it = m_desktopButtons.begin();
const int n = DesktopGridConfig::showAddRemove() ? effects->numScreens() : 0;
for (int i = 0; i < n; ++i) {
DesktopButtonsView *view;
if (it == m_desktopButtonsViews.end()) {
view = new DesktopButtonsView();
m_desktopButtonsViews.append(view);
it = m_desktopButtonsViews.end(); // changed through insert!
connect(view, &DesktopButtonsView::addDesktop, this, &DesktopGridEffect::slotAddDesktop);
connect(view, &DesktopButtonsView::removeDesktop, this, &DesktopGridEffect::slotRemoveDesktop);
EffectQuickScene *view;
QSize size;
if (it == m_desktopButtons.end()) {
view = new EffectQuickScene(this);
connect(view, &EffectQuickView::repaintNeeded, this, []() {
effects->addRepaintFull();
});
view->rootContext()->setContextProperty("effects", effects);
view->setSource(QUrl(QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("kwin/effects/desktopgrid/main.qml"))));
QQuickItem *rootItem = view->rootItem();
if (!rootItem) {
delete view;
continue;
}
m_desktopButtons.append(view);
it = m_desktopButtons.end(); // changed through insert!
size = QSize(rootItem->implicitWidth(), rootItem->implicitHeight());
} else {
view = *it;
++it;
size = view->size();
}
view->setAddDesktopEnabled(enableAdd);
view->setRemoveDesktopEnabled(enableRemove);
const QRect screenRect = effects->clientArea(FullScreenArea, i, 1);
view->show(); // pseudo show must happen before geometry changes
view->setPosition(screenRect.right() - border/3 - view->width(),
screenRect.bottom() - border/3 - view->height());
const QPoint position(screenRect.right() - border/3 - size.width(),
screenRect.bottom() - border/3 - size.height());
view->setGeometry(QRect(position, size));
}
while (it != m_desktopButtonsViews.end()) {
while (it != m_desktopButtons.end()) {
(*it)->deleteLater();
it = m_desktopButtonsViews.erase(it);
it = m_desktopButtons.erase(it);
}
}
......@@ -1297,12 +1281,6 @@ void DesktopGridEffect::slotNumberDesktopsChanged(uint old)
if (!activated)
return;
const uint desktop = effects->numberOfDesktops();
bool enableAdd = desktop < 20;
bool enableRemove = desktop > 1;
foreach (DesktopButtonsView *view, m_desktopButtonsViews) {
view->setAddDesktopEnabled(enableAdd);
view->setRemoveDesktopEnabled(enableRemove);
}
if (old < desktop)
desktopsAdded(old);
else
......@@ -1443,76 +1421,5 @@ bool DesktopGridEffect::isRelevantWithPresentWindows(EffectWindow *w) const
return true;
}
/************************************************
* DesktopButtonView
************************************************/
DesktopButtonsView::DesktopButtonsView(QWindow *parent)
: QQuickView(parent)
, effectWindow(nullptr)
, m_visible(false)
, m_posIsValid(false)
{
setFlags(Qt::X11BypassWindowManagerHint | Qt::FramelessWindowHint);
setColor(Qt::transparent);
rootContext()->setContextProperty(QStringLiteral("add"), QVariant(true));
rootContext()->setContextProperty(QStringLiteral("remove"), QVariant(true));
setSource(QUrl(QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("kwin/effects/desktopgrid/main.qml"))));
if (QObject *item = rootObject()->findChild<QObject*>(QStringLiteral("addButton"))) {
connect(item, SIGNAL(clicked()), SIGNAL(addDesktop()));
}
if (QObject *item = rootObject()->findChild<QObject*>(QStringLiteral("removeButton"))) {
connect(item, SIGNAL(clicked()), SIGNAL(removeDesktop()));
}
}
void DesktopButtonsView::windowInputMouseEvent(QMouseEvent *e)
{
if (e->type() == QEvent::MouseMove) {
mouseMoveEvent(e);
} else if (e->type() == QEvent::MouseButtonPress) {
mousePressEvent(e);
} else if (e->type() == QEvent::MouseButtonDblClick) {
mouseDoubleClickEvent(e);
} else if (e->type() == QEvent::MouseButtonRelease) {
mouseReleaseEvent(e);
}
}
void DesktopButtonsView::setAddDesktopEnabled(bool enable)
{
rootContext()->setContextProperty(QStringLiteral("add"), QVariant(enable));
}
void DesktopButtonsView::setRemoveDesktopEnabled(bool enable)
{
rootContext()->setContextProperty(QStringLiteral("remove"), QVariant(enable));
}
bool DesktopButtonsView::isVisible() const
{
return m_visible;
}
void DesktopButtonsView::show()
{
if (!m_visible && m_posIsValid) {
setPosition(m_pos);
m_posIsValid = false;
}
m_visible = true;
QQuickView::show();
}
void DesktopButtonsView::hide()
{
if (!m_posIsValid) {
m_pos = position();
m_posIsValid = true;
setPosition(-width(), -height());
}
m_visible = false;
}
} // namespace
......@@ -25,35 +25,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <kwineffects.h>
#include <QObject>
#include <QTimeLine>
#include <QQuickView>
#include "kwineffectquickview.h"
namespace KWin
{
class PresentWindowsEffectProxy;
class DesktopButtonsView : public QQuickView
{
Q_OBJECT
public:
explicit DesktopButtonsView(QWindow *parent = nullptr);
void windowInputMouseEvent(QMouseEvent* e);
void setAddDesktopEnabled(bool enable);
void setRemoveDesktopEnabled(bool enable);
bool isVisible() const;
void show();
void hide();
public:
EffectWindow *effectWindow;
Q_SIGNALS:
void addDesktop();
void removeDesktop();
private:
bool m_visible;
QPoint m_pos;
bool m_posIsValid;
};
class DesktopGridEffect
: public Effect
{
......@@ -182,7 +161,7 @@ private:
QRect m_windowMoveGeometry;
QPoint m_windowMoveStartPoint;
QVector<DesktopButtonsView*> m_desktopButtonsViews;
QVector<EffectQuickScene*> m_desktopButtons;
QAction *m_activateAction;
......
......@@ -18,32 +18,20 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
import QtQuick 2.0
import org.kde.plasma.components 2.0 as Plasma
import QtQuick.Layouts 1.2
import org.kde.plasma.components 3.0 as Plasma
Item {
width: childrenRect.width
height: childrenRect.height
Plasma.ButtonRow {
exclusive: false
width: childrenRect.width
height: childrenRect.height
Plasma.Button {
id: removeButton
objectName: "removeButton"
enabled: remove
width: height
font.bold: true
font.pointSize: 20
text: "-"
}
Plasma.Button {
id: addButton
objectName: "addButton"
enabled: add
font.bold: true
font.pointSize: 20
width: height
text: "+"
}
RowLayout {
Plasma.Button {
objectName: "removeButton"
enabled: effects.desktops > 1
icon.name: "list-remove"
onClicked: effects.desktops--
}
Plasma.Button {
objectName: "addButton"
enabled: effects.desktops < 20
icon.name: "list-add"
onClicked: effects.desktops++
}
}
......@@ -346,12 +346,14 @@ EffectQuickScene::EffectQuickScene(QObject *parent)
: EffectQuickView(parent)
, d(new EffectQuickScene::Private)
{
d->qmlObject = new KDeclarative::QmlObjectSharedEngine(this);
}
EffectQuickScene::EffectQuickScene(QObject *parent, EffectQuickView::ExportMode exportMode)
: EffectQuickView(parent, exportMode)
, d(new EffectQuickScene::Private)
{
d->qmlObject = new KDeclarative::QmlObjectSharedEngine(this);
}
EffectQuickScene::~EffectQuickScene()
......@@ -360,9 +362,6 @@ EffectQuickScene::~EffectQuickScene()
void EffectQuickScene::setSource(const QUrl &source)
{
if (!d->qmlObject) {
d->qmlObject = new KDeclarative::QmlObjectSharedEngine(this);
}
d->qmlObject->setSource(source);
QQuickItem *item = rootItem();
......
Markdown is supported
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