Add windowsystem plugin for KWin's qpa

Summary:
KWindowSystem provides a plugin interface to have platform specific
implementations. So far KWin relied on the implementation in
KWayland-integration repository.

This is something I find unsuited, for the following reasons:
 * any test in KWin for functionality set through the plugin would fail
 * it's not clear what's going on where
 * in worst case some code could deadlock
 * KWin shouldn't use KWindowSystem and only a small subset is allowed
to be used

The last point needs some further explanation. KWin internally does not
and cannot use KWindowSystem. KWindowSystem (especially KWindowInfo) is
exposing information which KWin sets. It's more than weird if KWin asks
KWindowSystem for the state of a window it set itself. On X11 it's just
slow, on Wayland it can result in roundtrips to KWin itself which is
dangerous.

But due to using Plasma components we have a few areas where we use
KWindowSystem. E.g. a Plasma::Dialog sets a window type, the slide in
direction, blur and background contrast. This we want to support and
need to support. Other API elements we do not want, like for examples
the available windows. KWin internal windows either have direct access
to KWin or a scripting interface exposed providing (limited) access -
there is just no need to have this in KWindowSystem.

To make it more clear what KWin supports as API of KWindowSystem for
internal windows this change implements a stripped down version of the
kwayland-integration plugin. The main difference is that it does not use
KWayland at all, but a QWindow internal side channel.

To support this EffectWindow provides an accessor for internalWindow and
the three already mentioned effects are adjusted to read from the
internal QWindow and it's dynamic properties.

This change is a first step for a further refactoring. I plan to split
the internal window out of ShellClient into a dedicated class. I think
there are nowadays too many special cases. If it moves out there is the
question whether we really want to use Wayland for the internal windows
or whether this is just historic ballast (after all we used to use
qwayland for that in the beginning).

As the change could introduce regressions I'm targetting 5.16.

Test Plan:
new test case for window type, manual testing using Alt+Tab
for the effects integration. Sliding popups, blur and contrast worked fine.

Reviewers: #kwin

Subscribers: kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D18228
This commit is contained in:
Martin Flöser 2019-01-13 17:50:32 +01:00
parent ef510b4e76
commit 02a0561016
23 changed files with 1015 additions and 4 deletions

View file

@ -20,6 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "kwin_wayland_test.h" #include "kwin_wayland_test.h"
#include "platform.h" #include "platform.h"
#include "cursor.h" #include "cursor.h"
#include "effects.h"
#include "shell_client.h" #include "shell_client.h"
#include "screens.h" #include "screens.h"
#include "wayland_server.h" #include "wayland_server.h"
@ -32,6 +33,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <KWayland/Client/surface.h> #include <KWayland/Client/surface.h>
#include <KWayland/Client/seat.h> #include <KWayland/Client/seat.h>
#include <KWayland/Client/shell.h> #include <KWayland/Client/shell.h>
#include <KWindowSystem>
#include <KWayland/Server/surface_interface.h> #include <KWayland/Server/surface_interface.h>
@ -39,6 +41,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
using namespace KWayland::Client; using namespace KWayland::Client;
Q_DECLARE_METATYPE(NET::WindowType);
namespace KWin namespace KWin
{ {
@ -67,6 +71,11 @@ private Q_SLOTS:
void testModifierScroll(); void testModifierScroll();
void testPopup(); void testPopup();
void testScale(); void testScale();
void testWindowType_data();
void testWindowType();
void testChangeWindowType_data();
void testChangeWindowType();
void testEffectWindow();
}; };
class HelperWindow : public QRasterWindow class HelperWindow : public QRasterWindow
@ -712,6 +721,98 @@ void InternalWindowTest::testScale()
QMetaObject::invokeMethod(kwinApp()->platform(), "setVirtualOutputs", Qt::DirectConnection, Q_ARG(int, 2)); QMetaObject::invokeMethod(kwinApp()->platform(), "setVirtualOutputs", Qt::DirectConnection, Q_ARG(int, 2));
} }
void InternalWindowTest::testWindowType_data()
{
QTest::addColumn<NET::WindowType>("windowType");
QTest::newRow("normal") << NET::Normal;
QTest::newRow("desktop") << NET::Desktop;
QTest::newRow("Dock") << NET::Dock;
QTest::newRow("Toolbar") << NET::Toolbar;
QTest::newRow("Menu") << NET::Menu;
QTest::newRow("Dialog") << NET::Dialog;
QTest::newRow("Utility") << NET::Utility;
QTest::newRow("Splash") << NET::Splash;
QTest::newRow("DropdownMenu") << NET::DropdownMenu;
QTest::newRow("PopupMenu") << NET::PopupMenu;
QTest::newRow("Tooltip") << NET::Tooltip;
QTest::newRow("Notification") << NET::Notification;
QTest::newRow("ComboBox") << NET::ComboBox;
QTest::newRow("OnScreenDisplay") << NET::OnScreenDisplay;
}
void InternalWindowTest::testWindowType()
{
QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded);
QVERIFY(clientAddedSpy.isValid());
HelperWindow win;
win.setGeometry(0, 0, 100, 100);
QFETCH(NET::WindowType, windowType);
KWindowSystem::setType(win.winId(), windowType);
win.show();
QVERIFY(clientAddedSpy.wait());
QTRY_COMPARE(clientAddedSpy.count(), 1);
auto internalClient = clientAddedSpy.first().first().value<ShellClient*>();
QVERIFY(internalClient);
QCOMPARE(internalClient->windowType(), windowType);
}
void InternalWindowTest::testChangeWindowType_data()
{
QTest::addColumn<NET::WindowType>("windowType");
QTest::newRow("desktop") << NET::Desktop;
QTest::newRow("Dock") << NET::Dock;
QTest::newRow("Toolbar") << NET::Toolbar;
QTest::newRow("Menu") << NET::Menu;
QTest::newRow("Dialog") << NET::Dialog;
QTest::newRow("Utility") << NET::Utility;
QTest::newRow("Splash") << NET::Splash;
QTest::newRow("DropdownMenu") << NET::DropdownMenu;
QTest::newRow("PopupMenu") << NET::PopupMenu;
QTest::newRow("Tooltip") << NET::Tooltip;
QTest::newRow("Notification") << NET::Notification;
QTest::newRow("ComboBox") << NET::ComboBox;
QTest::newRow("OnScreenDisplay") << NET::OnScreenDisplay;
}
void InternalWindowTest::testChangeWindowType()
{
QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded);
QVERIFY(clientAddedSpy.isValid());
HelperWindow win;
win.setGeometry(0, 0, 100, 100);
win.show();
QVERIFY(clientAddedSpy.wait());
QTRY_COMPARE(clientAddedSpy.count(), 1);
auto internalClient = clientAddedSpy.first().first().value<ShellClient*>();
QVERIFY(internalClient);
QCOMPARE(internalClient->windowType(), NET::Normal);
QFETCH(NET::WindowType, windowType);
KWindowSystem::setType(win.winId(), windowType);
QTRY_COMPARE(internalClient->windowType(), windowType);
KWindowSystem::setType(win.winId(), NET::Normal);
QTRY_COMPARE(internalClient->windowType(), NET::Normal);
}
void InternalWindowTest::testEffectWindow()
{
QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded);
QVERIFY(clientAddedSpy.isValid());
HelperWindow win;
win.setGeometry(0, 0, 100, 100);
win.show();
QVERIFY(clientAddedSpy.wait());
auto internalClient = clientAddedSpy.first().first().value<ShellClient*>();
QVERIFY(internalClient);
QVERIFY(internalClient->effectWindow());
QCOMPARE(internalClient->effectWindow()->internalWindow(), &win);
QCOMPARE(effects->findWindow(&win), internalClient->effectWindow());
QCOMPARE(effects->findWindow(&win)->internalWindow(), &win);
}
} }

View file

@ -184,6 +184,9 @@ void TestShellClient::testMapUnmapMap()
QVERIFY(client->property("moveable").toBool()); QVERIFY(client->property("moveable").toBool());
QVERIFY(client->property("moveableAcrossScreens").toBool()); QVERIFY(client->property("moveableAcrossScreens").toBool());
QVERIFY(client->property("resizeable").toBool()); QVERIFY(client->property("resizeable").toBool());
QCOMPARE(client->isInternal(), false);
QVERIFY(client->effectWindow());
QVERIFY(!client->effectWindow()->internalWindow());
QCOMPARE(client->internalId().isNull(), false); QCOMPARE(client->internalId().isNull(), false);
const auto uuid = client->internalId(); const auto uuid = client->internalId();
QUuid deletedUuid; QUuid deletedUuid;

View file

@ -134,6 +134,9 @@ public:
KWin::EffectWindow *findWindow(KWayland::Server::SurfaceInterface *) const override { KWin::EffectWindow *findWindow(KWayland::Server::SurfaceInterface *) const override {
return nullptr; return nullptr;
} }
KWin::EffectWindow *findWindow(QWindow *w) const override {
return nullptr;
}
void *getProxy(QString) override { void *getProxy(QString) override {
return nullptr; return nullptr;
} }

View file

@ -59,6 +59,9 @@ public:
void closeWindow() override; void closeWindow() override;
void referencePreviousWindowPixmap() override {} void referencePreviousWindowPixmap() override {}
void unreferencePreviousWindowPixmap() override {} void unreferencePreviousWindowPixmap() override {}
QWindow *internalWindow() const override {
return nullptr;
}
bool isDeleted() const override { bool isDeleted() const override {
return false; return false;
} }

View file

@ -1086,6 +1086,19 @@ EffectWindow* EffectsHandlerImpl::findWindow(KWayland::Server::SurfaceInterface
return nullptr; return nullptr;
} }
EffectWindow *EffectsHandlerImpl::findWindow(QWindow *w) const
{
if (waylandServer()) {
if (auto c = waylandServer()->findClient(w)) {
return c->effectWindow();
}
}
if (auto u = Workspace::self()->findUnmanaged(w->winId())) {
return u->effectWindow();
}
return nullptr;
}
EffectWindowList EffectsHandlerImpl::stackingOrder() const EffectWindowList EffectsHandlerImpl::stackingOrder() const
{ {
@ -1936,6 +1949,15 @@ EffectWindow* EffectWindowImpl::findModal()
return nullptr; return nullptr;
} }
QWindow *EffectWindowImpl::internalWindow() const
{
auto client = qobject_cast<ShellClient*>(toplevel);
if (!client) {
return nullptr;
}
return client->internalWindow();
}
template <typename T> template <typename T>
EffectWindowList getMainWindows(T *c) EffectWindowList getMainWindows(T *c)
{ {

View file

@ -134,6 +134,7 @@ public:
void stopMousePolling() override; void stopMousePolling() override;
EffectWindow* findWindow(WId id) const override; EffectWindow* findWindow(WId id) const override;
EffectWindow* findWindow(KWayland::Server::SurfaceInterface *surf) const override; EffectWindow* findWindow(KWayland::Server::SurfaceInterface *surf) const override;
EffectWindow *findWindow(QWindow *w) const override;
EffectWindowList stackingOrder() const override; EffectWindowList stackingOrder() const override;
void setElevatedWindow(KWin::EffectWindow* w, bool set) override; void setElevatedWindow(KWin::EffectWindow* w, bool set) override;
@ -474,6 +475,8 @@ public:
void referencePreviousWindowPixmap() override; void referencePreviousWindowPixmap() override;
void unreferencePreviousWindowPixmap() override; void unreferencePreviousWindowPixmap() override;
QWindow *internalWindow() const override;
const Toplevel* window() const; const Toplevel* window() const;
Toplevel* window(); Toplevel* window();

View file

@ -25,6 +25,7 @@
#include <QMatrix4x4> #include <QMatrix4x4>
#include <QLinkedList> #include <QLinkedList>
#include <QWindow>
#include <KWayland/Server/surface_interface.h> #include <KWayland/Server/surface_interface.h>
#include <KWayland/Server/contrast_interface.h> #include <KWayland/Server/contrast_interface.h>
@ -140,6 +141,27 @@ void ContrastEffect::updateContrastRegion(EffectWindow *w)
m_colorMatrices[w] = colorMatrix(surf->contrast()->contrast(), surf->contrast()->intensity(), surf->contrast()->saturation()); m_colorMatrices[w] = colorMatrix(surf->contrast()->contrast(), surf->contrast()->intensity(), surf->contrast()->saturation());
} }
if (auto internal = w->internalWindow()) {
const auto property = internal->property("kwin_background_region");
if (property.isValid()) {
region = property.value<QRegion>();
bool ok = false;
qreal contrast = internal->property("kwin_background_contrast").toReal(&ok);
if (!ok) {
contrast = 1.0;
}
qreal intensity = internal->property("kwin_background_intensity").toReal(&ok);
if (!ok) {
intensity = 1.0;
}
qreal saturation = internal->property("kwin_background_saturation").toReal(&ok);
if (!ok) {
saturation = 1.0;
}
m_colorMatrices[w] = colorMatrix(contrast, intensity, saturation);
}
}
//!value.isNull() full window in X11 case, surf->contrast() //!value.isNull() full window in X11 case, surf->contrast()
//valid, full window in wayland case //valid, full window in wayland case
if (region.isEmpty() && (!value.isNull() || (surf && surf->contrast()))) { if (region.isEmpty() && (!value.isNull() || (surf && surf->contrast()))) {
@ -163,9 +185,31 @@ void ContrastEffect::slotWindowAdded(EffectWindow *w)
} }
}); });
} }
if (auto internal = w->internalWindow()) {
internal->installEventFilter(this);
}
updateContrastRegion(w); updateContrastRegion(w);
} }
bool ContrastEffect::eventFilter(QObject *watched, QEvent *event)
{
auto internal = qobject_cast<QWindow*>(watched);
if (internal && event->type() == QEvent::DynamicPropertyChange) {
QDynamicPropertyChangeEvent *pe = static_cast<QDynamicPropertyChangeEvent*>(event);
if (pe->propertyName() == "kwin_background_region" ||
pe->propertyName() == "kwin_background_contrast" ||
pe->propertyName() == "kwin_background_intensity" ||
pe->propertyName() == "kwin_background_saturation") {
if (auto w = effects->findWindow(internal)) {
updateContrastRegion(w);
}
}
}
return false;
}
void ContrastEffect::slotWindowDeleted(EffectWindow *w) void ContrastEffect::slotWindowDeleted(EffectWindow *w)
{ {
if (m_contrastChangedConnections.contains(w)) { if (m_contrastChangedConnections.contains(w)) {

View file

@ -64,6 +64,8 @@ public:
return 76; return 76;
} }
bool eventFilter(QObject *watched, QEvent *event) override;
public Q_SLOTS: public Q_SLOTS:
void slotWindowAdded(KWin::EffectWindow *w); void slotWindowAdded(KWin::EffectWindow *w);
void slotWindowDeleted(KWin::EffectWindow *w); void slotWindowDeleted(KWin::EffectWindow *w);

View file

@ -29,6 +29,7 @@
#include <QLinkedList> #include <QLinkedList>
#include <QScreen> // for QGuiApplication #include <QScreen> // for QGuiApplication
#include <QTime> #include <QTime>
#include <QWindow>
#include <cmath> // for ceil() #include <cmath> // for ceil()
#include <KWayland/Server/surface_interface.h> #include <KWayland/Server/surface_interface.h>
@ -272,6 +273,13 @@ void BlurEffect::updateBlurRegion(EffectWindow *w) const
region = surf->blur()->region(); region = surf->blur()->region();
} }
if (auto internal = w->internalWindow()) {
const auto property = internal->property("kwin_blur");
if (property.isValid()) {
region = property.value<QRegion>();
}
}
//!value.isNull() full window in X11 case, surf->blur() //!value.isNull() full window in X11 case, surf->blur()
//valid, full window in wayland case //valid, full window in wayland case
if (region.isEmpty() && (!value.isNull() || (surf && surf->blur()))) { if (region.isEmpty() && (!value.isNull() || (surf && surf->blur()))) {
@ -294,6 +302,9 @@ void BlurEffect::slotWindowAdded(EffectWindow *w)
} }
}); });
} }
if (auto internal = w->internalWindow()) {
internal->installEventFilter(this);
}
updateBlurRegion(w); updateBlurRegion(w);
} }
@ -315,6 +326,20 @@ void BlurEffect::slotPropertyNotify(EffectWindow *w, long atom)
} }
} }
bool BlurEffect::eventFilter(QObject *watched, QEvent *event)
{
auto internal = qobject_cast<QWindow*>(watched);
if (internal && event->type() == QEvent::DynamicPropertyChange) {
QDynamicPropertyChangeEvent *pe = static_cast<QDynamicPropertyChangeEvent*>(event);
if (pe->propertyName() == "kwin_blur") {
if (auto w = effects->findWindow(internal)) {
updateBlurRegion(w);
}
}
}
return false;
}
bool BlurEffect::enabledByDefault() bool BlurEffect::enabledByDefault()
{ {
GLPlatform *gl = GLPlatform::instance(); GLPlatform *gl = GLPlatform::instance();

View file

@ -67,6 +67,8 @@ public:
return 75; return 75;
} }
bool eventFilter(QObject *watched, QEvent *event) override;
public Q_SLOTS: public Q_SLOTS:
void slotWindowAdded(KWin::EffectWindow *w); void slotWindowAdded(KWin::EffectWindow *w);
void slotWindowDeleted(KWin::EffectWindow *w); void slotWindowDeleted(KWin::EffectWindow *w);

View file

@ -24,11 +24,16 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <QApplication> #include <QApplication>
#include <QFontMetrics> #include <QFontMetrics>
#include <QWindow>
#include <KWayland/Server/surface_interface.h> #include <KWayland/Server/surface_interface.h>
#include <KWayland/Server/slide_interface.h> #include <KWayland/Server/slide_interface.h>
#include <KWayland/Server/display.h> #include <KWayland/Server/display.h>
#include <KWindowEffects>
Q_DECLARE_METATYPE(KWindowEffects::SlideFromLocation)
namespace KWin namespace KWin
{ {
@ -200,6 +205,11 @@ void SlidingPopupsEffect::slotWindowAdded(EffectWindow *w)
}); });
} }
if (auto internal = w->internalWindow()) {
internal->installEventFilter(this);
setupInternalWindowSlide(w);
}
slideIn(w); slideIn(w);
} }
@ -377,6 +387,62 @@ void SlidingPopupsEffect::slotWaylandSlideOnShowChanged(EffectWindow* w)
} }
} }
void SlidingPopupsEffect::setupInternalWindowSlide(EffectWindow *w)
{
if (!w) {
return;
}
auto internal = w->internalWindow();
if (!internal) {
return;
}
const QVariant slideProperty = internal->property("kwin_slide");
if (!slideProperty.isValid()) {
return;
}
AnimationData &animData = m_animationsData[w];
switch (slideProperty.value<KWindowEffects::SlideFromLocation>()) {
case KWindowEffects::BottomEdge:
animData.location = Location::Bottom;
break;
case KWindowEffects::TopEdge:
animData.location = Location::Top;
break;
case KWindowEffects::RightEdge:
animData.location = Location::Right;
break;
case KWindowEffects::LeftEdge:
animData.location = Location::Left;
break;
default:
return;
}
bool intOk = false;
animData.offset = internal->property("kwin_slide_offset").toInt(&intOk);
if (!intOk) {
animData.offset = -1;
}
animData.slideLength = 0;
animData.slideInDuration = m_slideInDuration;
animData.slideOutDuration = m_slideOutDuration;
setupAnimData(w);
}
bool SlidingPopupsEffect::eventFilter(QObject *watched, QEvent *event)
{
auto internal = qobject_cast<QWindow*>(watched);
if (internal && event->type() == QEvent::DynamicPropertyChange) {
QDynamicPropertyChangeEvent *pe = static_cast<QDynamicPropertyChangeEvent*>(event);
if (pe->propertyName() == "kwin_slide" || pe->propertyName() == "kwin_slide_offset") {
if (auto w = effects->findWindow(internal)) {
setupInternalWindowSlide(w);
}
}
}
return false;
}
void SlidingPopupsEffect::slideIn(EffectWindow *w) void SlidingPopupsEffect::slideIn(EffectWindow *w)
{ {
if (effects->activeFullScreenEffect()) { if (effects->activeFullScreenEffect()) {

View file

@ -53,6 +53,8 @@ public:
int slideInDuration() const; int slideInDuration() const;
int slideOutDuration() const; int slideOutDuration() const;
bool eventFilter(QObject *watched, QEvent *event) override;
private Q_SLOTS: private Q_SLOTS:
void slotWindowAdded(EffectWindow *w); void slotWindowAdded(EffectWindow *w);
void slotWindowDeleted(EffectWindow *w); void slotWindowDeleted(EffectWindow *w);
@ -65,6 +67,7 @@ private Q_SLOTS:
private: private:
void setupAnimData(EffectWindow *w); void setupAnimData(EffectWindow *w);
void setupInternalWindowSlide(EffectWindow *w);
long m_atom; long m_atom;

View file

@ -1078,6 +1078,16 @@ public:
Q_SCRIPTABLE virtual KWin::EffectWindow* findWindow(WId id) const = 0; Q_SCRIPTABLE virtual KWin::EffectWindow* findWindow(WId id) const = 0;
Q_SCRIPTABLE virtual KWin::EffectWindow* findWindow(KWayland::Server::SurfaceInterface *surf) const = 0; Q_SCRIPTABLE virtual KWin::EffectWindow* findWindow(KWayland::Server::SurfaceInterface *surf) const = 0;
/**
* Finds the EffectWindow for the internal window @p w.
* If there is no such window @c null is returned.
*
* On Wayland this returns the internal window. On X11 it returns an Unamanged with the
* window id matching that of the provided window @p w.
*
* @since 5.16
**/
Q_SCRIPTABLE virtual KWin::EffectWindow *findWindow(QWindow *w) const = 0;
virtual EffectWindowList stackingOrder() const = 0; virtual EffectWindowList stackingOrder() const = 0;
// window will be temporarily painted as if being at the top of the stack // window will be temporarily painted as if being at the top of the stack
Q_SCRIPTABLE virtual void setElevatedWindow(KWin::EffectWindow* w, bool set) = 0; Q_SCRIPTABLE virtual void setElevatedWindow(KWin::EffectWindow* w, bool set) = 0;
@ -2041,6 +2051,14 @@ class KWINEFFECTS_EXPORT EffectWindow : public QObject
**/ **/
Q_PROPERTY(bool popupWindow READ isPopupWindow CONSTANT) Q_PROPERTY(bool popupWindow READ isPopupWindow CONSTANT)
/**
* KWin internal window. Specific to Wayland platform.
*
* If the EffectWindow does not reference an internal window, this property is @c null.
* @since 5.16
**/
Q_PROPERTY(QWindow *internalWindow READ internalWindow CONSTANT)
public: public:
/** Flags explaining why painting should be disabled */ /** Flags explaining why painting should be disabled */
enum { enum {
@ -2324,6 +2342,11 @@ public:
**/ **/
virtual bool isPopupWindow() const = 0; virtual bool isPopupWindow() const = 0;
/**
* @since 5.16
**/
virtual QWindow *internalWindow() const = 0;
/** /**
* Can be used to by effects to store arbitrary data in the EffectWindow. * Can be used to by effects to store arbitrary data in the EffectWindow.
* *

View file

@ -3,6 +3,7 @@ add_subdirectory(qpa)
add_subdirectory(idletime) add_subdirectory(idletime)
add_subdirectory(platforms) add_subdirectory(platforms)
add_subdirectory(scenes) add_subdirectory(scenes)
add_subdirectory(windowsystem)
if(KWIN_BUILD_DECORATIONS) if(KWIN_BUILD_DECORATIONS)
add_subdirectory(kdecorations) add_subdirectory(kdecorations)

View file

@ -0,0 +1,19 @@
set(kwindowsystem_plugin_SRCS
plugin.cpp
windoweffects.cpp
windowsystem.cpp
)
add_library(KF5WindowSystemKWinPrivatePlugin MODULE ${kwindowsystem_plugin_SRCS})
set_target_properties(KF5WindowSystemKWinPrivatePlugin PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/kf5/org.kde.kwindowsystem.platforms/")
target_link_libraries(KF5WindowSystemKWinPrivatePlugin
kwin
)
install(
TARGETS
KF5WindowSystemKWinPrivatePlugin
DESTINATION
${PLUGIN_INSTALL_DIR}/kf5/org.kde.kwindowsystem.platforms/
)

View file

@ -0,0 +1,3 @@
{
"platforms": ["wayland-org.kde.kwin.qpa"]
}

View file

@ -0,0 +1,41 @@
/*
* Copyright 2019 Martin Flöser <mgraesslin@kde.org>
*
* 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) version 3 or any later version
* accepted by the membership of KDE e.V. (or its successor approved
* by the membership of KDE e.V.), which shall act as a proxy
* defined in Section 14 of version 3 of the license.
*
* 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/>.
*/
#include "plugin.h"
#include "windowsystem.h"
#include "windoweffects.h"
KWindowSystemKWinPlugin::KWindowSystemKWinPlugin(QObject *parent)
: KWindowSystemPluginInterface(parent)
{
}
KWindowSystemKWinPlugin::~KWindowSystemKWinPlugin()
{
}
KWindowEffectsPrivate *KWindowSystemKWinPlugin::createEffects()
{
return new KWin::WindowEffects();
}
KWindowSystemPrivate *KWindowSystemKWinPlugin::createWindowSystem()
{
return new KWin::WindowSystem();
}

View file

@ -0,0 +1,36 @@
/*
* Copyright 2019 Martin Flöser <mgraesslin@kde.org>
*
* 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) version 3 or any later version
* accepted by the membership of KDE e.V. (or its successor approved
* by the membership of KDE e.V.), which shall act as a proxy
* defined in Section 14 of version 3 of the license.
*
* 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/>.
*/
#pragma once
#include <KWindowSystem/private/kwindowsystemplugininterface_p.h>
class KWindowSystemKWinPlugin : public KWindowSystemPluginInterface
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.kde.kwindowsystem.KWindowSystemPluginInterface" FILE "kwindowsystem.json")
Q_INTERFACES(KWindowSystemPluginInterface)
public:
explicit KWindowSystemKWinPlugin(QObject *parent = nullptr);
~KWindowSystemKWinPlugin() override;
KWindowEffectsPrivate *createEffects() override;
KWindowSystemPrivate *createWindowSystem() override;
};

View file

@ -0,0 +1,150 @@
/*
* Copyright 2019 Martin Flöser <mgraesslin@kde.org>
*
* 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) version 3 or any later version
* accepted by the membership of KDE e.V. (or its successor approved
* by the membership of KDE e.V.), which shall act as a proxy
* defined in Section 14 of version 3 of the license.
*
* 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/>.
*/
#include "windoweffects.h"
#include "effect_builtins.h"
#include "../../effects.h"
#include <QGuiApplication>
#include <QWidget>
#include <QWindow>
Q_DECLARE_METATYPE(KWindowEffects::SlideFromLocation)
namespace KWin
{
WindowEffects::WindowEffects()
: QObject(),
KWindowEffectsPrivate()
{
}
WindowEffects::~WindowEffects()
{}
namespace
{
QWindow *findWindow(WId win)
{
const auto windows = qApp->allWindows();
auto it = std::find_if(windows.begin(), windows.end(), [win] (QWindow *w) { return w->winId() == win; });
if (it == windows.end()) {
return nullptr;
}
return *it;
}
}
bool WindowEffects::isEffectAvailable(KWindowEffects::Effect effect)
{
if (!effects) {
return false;
}
auto e = static_cast<EffectsHandlerImpl*>(effects);
switch (effect) {
case KWindowEffects::BackgroundContrast:
return e->isEffectLoaded(BuiltInEffects::nameForEffect(BuiltInEffect::Contrast));
case KWindowEffects::BlurBehind:
return e->isEffectLoaded(BuiltInEffects::nameForEffect(BuiltInEffect::Blur));
case KWindowEffects::Slide:
return e->isEffectLoaded(BuiltInEffects::nameForEffect(BuiltInEffect::SlidingPopups));
default:
// plugin does not provide integration for other effects
return false;
}
}
void WindowEffects::slideWindow(WId id, KWindowEffects::SlideFromLocation location, int offset)
{
auto w = findWindow(id);
if (!w) {
return;
}
w->setProperty("kwin_slide", QVariant::fromValue(location));
w->setProperty("kwin_slide_offset", offset);
}
void WindowEffects::slideWindow(QWidget *widget, KWindowEffects::SlideFromLocation location)
{
slideWindow(widget->winId(), location, 0);
}
QList<QSize> WindowEffects::windowSizes(const QList<WId> &ids)
{
Q_UNUSED(ids)
return {};
}
void WindowEffects::presentWindows(WId controller, const QList<WId> &ids)
{
Q_UNUSED(controller)
Q_UNUSED(ids)
}
void WindowEffects::presentWindows(WId controller, int desktop)
{
Q_UNUSED(controller)
Q_UNUSED(desktop)
}
void WindowEffects::highlightWindows(WId controller, const QList<WId> &ids)
{
Q_UNUSED(controller)
Q_UNUSED(ids)
}
void WindowEffects::enableBlurBehind(WId window, bool enable, const QRegion &region)
{
auto w = findWindow(window);
if (!w) {
return;
}
if (enable) {
w->setProperty("kwin_blur", region);
} else {
w->setProperty("kwin_blur", {});
}
}
void WindowEffects::enableBackgroundContrast(WId window, bool enable, qreal contrast, qreal intensity, qreal saturation, const QRegion &region)
{
auto w = findWindow(window);
if (!w) {
return;
}
if (enable) {
w->setProperty("kwin_background_region", region);
w->setProperty("kwin_background_contrast", contrast);
w->setProperty("kwin_background_intensity", intensity);
w->setProperty("kwin_background_saturation", saturation);
} else {
w->setProperty("kwin_background_region", {});
w->setProperty("kwin_background_contrast", {});
w->setProperty("kwin_background_intensity", {});
w->setProperty("kwin_background_saturation", {});
}
}
void WindowEffects::markAsDashboard(WId window)
{
Q_UNUSED(window)
}
}

View file

@ -0,0 +1,44 @@
/*
* Copyright 2019 Martin Flöser <mgraesslin@kde.org>
*
* 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) version 3 or any later version
* accepted by the membership of KDE e.V. (or its successor approved
* by the membership of KDE e.V.), which shall act as a proxy
* defined in Section 14 of version 3 of the license.
*
* 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/>.
*/
#pragma once
#include <KWindowSystem/private/kwindoweffects_p.h>
namespace KWin
{
class WindowEffects : public QObject, public KWindowEffectsPrivate
{
public:
WindowEffects();
~WindowEffects() override;
bool isEffectAvailable(KWindowEffects::Effect effect) override;
void slideWindow(WId id, KWindowEffects::SlideFromLocation location, int offset) override;
void slideWindow(QWidget *widget, KWindowEffects::SlideFromLocation location) override;
QList<QSize> windowSizes(const QList<WId> &ids) override;
void presentWindows(WId controller, const QList<WId> &ids) override;
void presentWindows(WId controller, int desktop = NET::OnAllDesktops) override;
void highlightWindows(WId controller, const QList<WId> &ids) override;
void enableBlurBehind(WId window, bool enable = true, const QRegion &region = QRegion()) override;
void enableBackgroundContrast(WId window, bool enable = true, qreal contrast = 1, qreal intensity = 1, qreal saturation = 1, const QRegion &region = QRegion()) override;
void markAsDashboard(WId window) override;
};
}

View file

@ -0,0 +1,328 @@
/*
* Copyright 2019 Martin Flöser <mgraesslin@kde.org>
*
* 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) version 3 or any later version
* accepted by the membership of KDE e.V. (or its successor approved
* by the membership of KDE e.V.), which shall act as a proxy
* defined in Section 14 of version 3 of the license.
*
* 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/>.
*/
#include "windowsystem.h"
#include <KWindowSystem/KWindowSystem>
#include <QGuiApplication>
#include <QWindow>
Q_DECLARE_METATYPE(NET::WindowType)
namespace KWin
{
WindowSystem::WindowSystem()
: QObject()
, KWindowSystemPrivate()
{
}
void WindowSystem::activateWindow(WId win, long int time)
{
Q_UNUSED(win)
Q_UNUSED(time)
// KWin cannot activate own windows
}
void WindowSystem::forceActiveWindow(WId win, long int time)
{
Q_UNUSED(win)
Q_UNUSED(time)
// KWin cannot activate own windows
}
WId WindowSystem::activeWindow()
{
// KWin internal should not use KWindowSystem to find active window
return 0;
}
bool WindowSystem::allowedActionsSupported()
{
return false;
}
void WindowSystem::allowExternalProcessWindowActivation(int pid)
{
Q_UNUSED(pid)
}
bool WindowSystem::compositingActive()
{
// wayland is always composited
return true;
}
void WindowSystem::connectNotify(const QMetaMethod &signal)
{
Q_UNUSED(signal)
}
QPoint WindowSystem::constrainViewportRelativePosition(const QPoint &pos)
{
Q_UNUSED(pos)
return QPoint();
}
int WindowSystem::currentDesktop()
{
// KWin internal should not use KWindowSystem to find current desktop
return 0;
}
void WindowSystem::demandAttention(WId win, bool set)
{
Q_UNUSED(win)
Q_UNUSED(set)
}
QString WindowSystem::desktopName(int desktop)
{
Q_UNUSED(desktop)
return QString();
}
QPoint WindowSystem::desktopToViewport(int desktop, bool absolute)
{
Q_UNUSED(desktop)
Q_UNUSED(absolute)
return QPoint();
}
#ifndef KWINDOWSYSTEM_NO_DEPRECATED
WId WindowSystem::groupLeader(WId window)
{
Q_UNUSED(window)
return 0;
}
#endif
bool WindowSystem::icccmCompliantMappingState()
{
return false;
}
QPixmap WindowSystem::icon(WId win, int width, int height, bool scale, int flags)
{
Q_UNUSED(win)
Q_UNUSED(width)
Q_UNUSED(height)
Q_UNUSED(scale)
Q_UNUSED(flags)
return QPixmap();
}
void WindowSystem::lowerWindow(WId win)
{
Q_UNUSED(win)
}
bool WindowSystem::mapViewport()
{
return false;
}
void WindowSystem::minimizeWindow(WId win)
{
Q_UNUSED(win)
}
void WindowSystem::unminimizeWindow(WId win)
{
Q_UNUSED(win)
}
int WindowSystem::numberOfDesktops()
{
// KWin internal should not use KWindowSystem to find number of desktops
return 1;
}
void WindowSystem::raiseWindow(WId win)
{
Q_UNUSED(win)
}
QString WindowSystem::readNameProperty(WId window, long unsigned int atom)
{
Q_UNUSED(window)
Q_UNUSED(atom)
return QString();
}
void WindowSystem::setBlockingCompositing(WId window, bool active)
{
Q_UNUSED(window)
Q_UNUSED(active)
}
void WindowSystem::setCurrentDesktop(int desktop)
{
Q_UNUSED(desktop)
// KWin internal should not use KWindowSystem to set current desktop
}
void WindowSystem::setDesktopName(int desktop, const QString &name)
{
Q_UNUSED(desktop)
Q_UNUSED(name)
// KWin internal should not use KWindowSystem to set desktop name
}
void WindowSystem::setExtendedStrut(WId win, int left_width, int left_start, int left_end, int right_width, int right_start, int right_end, int top_width, int top_start, int top_end, int bottom_width, int bottom_start, int bottom_end)
{
Q_UNUSED(win)
Q_UNUSED(left_width)
Q_UNUSED(left_start)
Q_UNUSED(left_end)
Q_UNUSED(right_width)
Q_UNUSED(right_start)
Q_UNUSED(right_end)
Q_UNUSED(top_width)
Q_UNUSED(top_start)
Q_UNUSED(top_end)
Q_UNUSED(bottom_width)
Q_UNUSED(bottom_start)
Q_UNUSED(bottom_end)
}
void WindowSystem::setStrut(WId win, int left, int right, int top, int bottom)
{
Q_UNUSED(win)
Q_UNUSED(left)
Q_UNUSED(right)
Q_UNUSED(top)
Q_UNUSED(bottom)
}
void WindowSystem::setIcons(WId win, const QPixmap &icon, const QPixmap &miniIcon)
{
Q_UNUSED(win)
Q_UNUSED(icon)
Q_UNUSED(miniIcon)
}
void WindowSystem::setOnActivities(WId win, const QStringList &activities)
{
Q_UNUSED(win)
Q_UNUSED(activities)
}
void WindowSystem::setOnAllDesktops(WId win, bool b)
{
Q_UNUSED(win)
Q_UNUSED(b)
}
void WindowSystem::setOnDesktop(WId win, int desktop)
{
Q_UNUSED(win)
Q_UNUSED(desktop)
}
void WindowSystem::setShowingDesktop(bool showing)
{
Q_UNUSED(showing)
// KWin should not use KWindowSystem to set showing desktop state
}
void WindowSystem::clearState(WId win, NET::States state)
{
// KWin's windows don't support state
Q_UNUSED(win)
Q_UNUSED(state)
}
void WindowSystem::setState(WId win, NET::States state)
{
// KWin's windows don't support state
Q_UNUSED(win)
Q_UNUSED(state)
}
void WindowSystem::setType(WId win, NET::WindowType windowType)
{
const auto windows = qApp->allWindows();
auto it = std::find_if(windows.begin(), windows.end(), [win] (QWindow *w) { return w->winId() == win; });
if (it == windows.end()) {
return;
}
(*it)->setProperty("kwin_windowType", QVariant::fromValue(windowType));
}
void WindowSystem::setUserTime(WId win, long int time)
{
Q_UNUSED(win)
Q_UNUSED(time)
}
bool WindowSystem::showingDesktop()
{
// KWin should not use KWindowSystem for showing desktop state
return false;
}
QList< WId > WindowSystem::stackingOrder()
{
// KWin should not use KWindowSystem for stacking order
return {};
}
#ifndef KWINDOWSYSTEM_NO_DEPRECATED
WId WindowSystem::transientFor(WId window)
{
Q_UNUSED(window)
return 0;
}
#endif
int WindowSystem::viewportToDesktop(const QPoint &pos)
{
Q_UNUSED(pos)
return 0;
}
int WindowSystem::viewportWindowToDesktop(const QRect &r)
{
Q_UNUSED(r)
return 0;
}
QList< WId > WindowSystem::windows()
{
return {};
}
QRect WindowSystem::workArea(const QList< WId > &excludes, int desktop)
{
Q_UNUSED(excludes)
Q_UNUSED(desktop)
return {};
}
QRect WindowSystem::workArea(int desktop)
{
Q_UNUSED(desktop)
return {};
}
}

View file

@ -0,0 +1,85 @@
/*
* Copyright 2019 Martin Flöser <mgraesslin@kde.org>
*
* 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) version 3 or any later version
* accepted by the membership of KDE e.V. (or its successor approved
* by the membership of KDE e.V.), which shall act as a proxy
* defined in Section 14 of version 3 of the license.
*
* 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/>.
*/
#pragma once
#include <KWindowSystem/private/kwindowsystem_p.h>
#include <QObject>
namespace KWin
{
class WindowSystem : public QObject, public KWindowSystemPrivate
{
Q_OBJECT
public:
WindowSystem();
QList<WId> windows() override;
QList<WId> stackingOrder() override;
WId activeWindow() override;
void activateWindow(WId win, long time) override;
void forceActiveWindow(WId win, long time) override;
void demandAttention(WId win, bool set) override;
bool compositingActive() override;
int currentDesktop() override;
int numberOfDesktops() override;
void setCurrentDesktop(int desktop) override;
void setOnAllDesktops(WId win, bool b) override;
void setOnDesktop(WId win, int desktop) override;
void setOnActivities(WId win, const QStringList &activities) override;
#ifndef KWINDOWSYSTEM_NO_DEPRECATED
WId transientFor(WId window) override;
WId groupLeader(WId window) override;
#endif
QPixmap icon(WId win, int width, int height, bool scale, int flags) override;
void setIcons(WId win, const QPixmap &icon, const QPixmap &miniIcon) override;
void setType(WId win, NET::WindowType windowType) override;
void setState(WId win, NET::States state) override;
void clearState(WId win, NET::States state) override;
void minimizeWindow(WId win) override;
void unminimizeWindow(WId win) override;
void raiseWindow(WId win) override;
void lowerWindow(WId win) override;
bool icccmCompliantMappingState() override;
QRect workArea(int desktop) override;
QRect workArea(const QList<WId> &excludes, int desktop) override;
QString desktopName(int desktop) override;
void setDesktopName(int desktop, const QString &name) override;
bool showingDesktop() override;
void setShowingDesktop(bool showing) override;
void setUserTime(WId win, long time) override;
void setExtendedStrut(WId win, int left_width, int left_start, int left_end,
int right_width, int right_start, int right_end, int top_width, int top_start, int top_end,
int bottom_width, int bottom_start, int bottom_end) override;
void setStrut(WId win, int left, int right, int top, int bottom) override;
bool allowedActionsSupported() override;
QString readNameProperty(WId window, unsigned long atom) override;
void allowExternalProcessWindowActivation(int pid) override;
void setBlockingCompositing(WId window, bool active) override;
bool mapViewport() override;
int viewportToDesktop(const QPoint &pos) override;
int viewportWindowToDesktop(const QRect &r) override;
QPoint desktopToViewport(int desktop, bool absolute) override;
QPoint constrainViewportRelativePosition(const QPoint &pos) override;
void connectNotify(const QMetaMethod &signal) override;
};
}

View file

@ -60,6 +60,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <unistd.h> #include <unistd.h>
#include <signal.h> #include <signal.h>
Q_DECLARE_METATYPE(NET::WindowType)
using namespace KWayland::Server; using namespace KWayland::Server;
static const QByteArray s_skipClosePropertyName = QByteArrayLiteral("KWIN_SKIP_CLOSE_ANIMATION"); static const QByteArray s_skipClosePropertyName = QByteArrayLiteral("KWIN_SKIP_CLOSE_ANIMATION");
@ -1143,11 +1145,9 @@ void ShellClient::findInternalWindow()
connect(m_internalWindow, &QWindow::destroyed, this, [this] { m_internalWindow = nullptr; }); connect(m_internalWindow, &QWindow::destroyed, this, [this] { m_internalWindow = nullptr; });
connect(m_internalWindow, &QWindow::opacityChanged, this, &ShellClient::setOpacity); connect(m_internalWindow, &QWindow::opacityChanged, this, &ShellClient::setOpacity);
// Try reading the window type from the QWindow. PlasmaCore.Dialog provides a dynamic type property const QVariant windowType = m_internalWindow->property("kwin_windowType");
// let's check whether it exists, if it does it's our window type
const QVariant windowType = m_internalWindow->property("type");
if (!windowType.isNull()) { if (!windowType.isNull()) {
m_windowType = static_cast<NET::WindowType>(windowType.toInt()); m_windowType = windowType.value<NET::WindowType>();
} }
setOpacity(m_internalWindow->opacity()); setOpacity(m_internalWindow->opacity());
@ -1505,6 +1505,10 @@ bool ShellClient::eventFilter(QObject *watched, QEvent *event)
if (pe->propertyName() == s_skipClosePropertyName) { if (pe->propertyName() == s_skipClosePropertyName) {
setSkipCloseAnimation(m_internalWindow->property(s_skipClosePropertyName).toBool()); setSkipCloseAnimation(m_internalWindow->property(s_skipClosePropertyName).toBool());
} }
if (pe->propertyName() == "kwin_windowType") {
m_windowType = m_internalWindow->property("kwin_windowType").value<NET::WindowType>();
workspace()->updateClientArea();
}
} }
return false; return false;
} }