Create screen edge through the Platform

Removes a diversion between X11 and Wayland. The base class Platform
creates an instance of class Edge with plugin implementations being
able to create a different type.

The X11StandalonePlugin does that and creates a WindowBasedEdge. For
this the implementation of WindowBasedEdge is moved from screenedges
into the plugin.

Unfortunately an ifdef is needed to make the screenedge test still
work as expected. This should be improved in future, e.g. have a good
way to load the platform plugin from the tests.

Reviewers: #plasma

Subscribers: plasma-devel

Projects: #plasma

Differential Revision: https://phabricator.kde.org/D1419
This commit is contained in:
Martin Gräßlin 2016-04-15 13:47:56 +02:00
parent 736ad55e37
commit e73a86d420
12 changed files with 244 additions and 156 deletions

View file

@ -28,7 +28,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
namespace KWin
{
class Atoms
class KWIN_EXPORT Atoms
{
public:
Atoms();
@ -82,7 +82,7 @@ private:
};
extern Atoms* atoms;
extern KWIN_EXPORT Atoms* atoms;
} // namespace

View file

@ -276,6 +276,7 @@ set( testScreenEdges_SRCS
../screenedge.cpp
../virtualdesktops.cpp
../xcbutils.cpp # init of extensions
../plugins/platforms/x11/standalone/edge.cpp
)
kconfig_add_kcfg_files(testScreenEdges_SRCS ../settings.kcfgc)
qt5_add_dbus_interface( testScreenEdges_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/../org.freedesktop.ScreenSaver.xml screenlocker_interface)

View file

@ -94,11 +94,6 @@ void updateXTime()
{
}
Application::OperationMode Application::operationMode() const
{
return OperationModeX11;
}
class TestObject : public QObject
{
Q_OBJECT

View file

@ -25,6 +25,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "input.h"
#include "pointer_input.h"
#include "scene_opengl.h"
#include "screenedge.h"
#include "wayland_server.h"
namespace KWin
@ -65,6 +66,11 @@ QPainterBackend *Platform::createQPainterBackend()
return nullptr;
}
Edge *Platform::createScreenEdge(ScreenEdges *edges)
{
return new Edge(edges);
}
void Platform::configurationChangeRequested(KWayland::Server::OutputConfigurationInterface *config)
{
Q_UNUSED(config)

View file

@ -34,9 +34,11 @@ namespace KWayland {
namespace KWin
{
class Edge;
class OpenGLBackend;
class QPainterBackend;
class Screens;
class ScreenEdges;
class WaylandCursorTheme;
class KWIN_EXPORT Platform : public QObject
@ -49,6 +51,11 @@ public:
virtual Screens *createScreens(QObject *parent = nullptr);
virtual OpenGLBackend *createOpenGLBackend();
virtual QPainterBackend *createQPainterBackend();
/**
* Allows the platform to create a platform specific screen edge.
* The default implementation creates a Edge.
**/
virtual Edge *createScreenEdge(ScreenEdges *parent);
virtual void warpPointer(const QPointF &globalPos);
/**
* Whether our Compositing EGL display allows a surface less context

View file

@ -1,4 +1,5 @@
set(X11PLATFORM_SOURCES
edge.cpp
logging.cpp
x11_platform.cpp
screens_xrandr.cpp

View file

@ -0,0 +1,131 @@
/********************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 2011 Arthur Arlt <a.arlt@stud.uni-heidelberg.de>
Copyright (C) 2013 Martin Gräßlin <mgraesslin@kde.org>
Since the functionality provided in this class has been moved from
class Workspace, it is not clear who exactly has written the code.
The list below contains the copyright holders of the class Workspace.
Copyright (C) 1999, 2000 Matthias Ettrich <ettrich@kde.org>
Copyright (C) 2003 Lubos Lunak <l.lunak@kde.org>
Copyright (C) 2009 Lucas Murray <lmurray@undefinedfire.com>
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/>.
*********************************************************************/
#include "edge.h"
#include "atoms.h"
#include "cursor.h"
namespace KWin
{
WindowBasedEdge::WindowBasedEdge(ScreenEdges *parent)
: Edge(parent)
, m_window(XCB_WINDOW_NONE)
, m_approachWindow(XCB_WINDOW_NONE)
{
}
WindowBasedEdge::~WindowBasedEdge()
{
}
void WindowBasedEdge::activate()
{
createWindow();
createApproachWindow();
doUpdateBlocking();
}
void WindowBasedEdge::deactivate()
{
m_window.reset();
m_approachWindow.reset();
}
void WindowBasedEdge::createWindow()
{
if (m_window.isValid()) {
return;
}
const uint32_t mask = XCB_CW_OVERRIDE_REDIRECT | XCB_CW_EVENT_MASK;
const uint32_t values[] = {
true,
XCB_EVENT_MASK_ENTER_WINDOW | XCB_EVENT_MASK_LEAVE_WINDOW | XCB_EVENT_MASK_POINTER_MOTION
};
m_window.create(geometry(), XCB_WINDOW_CLASS_INPUT_ONLY, mask, values);
m_window.map();
// Set XdndAware on the windows, so that DND enter events are received (#86998)
xcb_atom_t version = 4; // XDND version
xcb_change_property(connection(), XCB_PROP_MODE_REPLACE, m_window,
atoms->xdnd_aware, XCB_ATOM_ATOM, 32, 1, (unsigned char*)(&version));
}
void WindowBasedEdge::createApproachWindow()
{
if (m_approachWindow.isValid()) {
return;
}
if (!approachGeometry().isValid()) {
return;
}
const uint32_t mask = XCB_CW_OVERRIDE_REDIRECT | XCB_CW_EVENT_MASK;
const uint32_t values[] = {
true,
XCB_EVENT_MASK_ENTER_WINDOW | XCB_EVENT_MASK_LEAVE_WINDOW | XCB_EVENT_MASK_POINTER_MOTION
};
m_approachWindow.create(approachGeometry(), XCB_WINDOW_CLASS_INPUT_ONLY, mask, values);
m_approachWindow.map();
}
void WindowBasedEdge::doGeometryUpdate()
{
m_window.setGeometry(geometry());
m_approachWindow.setGeometry(approachGeometry());
}
void WindowBasedEdge::doStartApproaching()
{
m_approachWindow.unmap();
Cursor *cursor = Cursor::self();
connect(cursor, SIGNAL(posChanged(QPoint)), SLOT(updateApproaching(QPoint)));
cursor->startMousePolling();
}
void WindowBasedEdge::doStopApproaching()
{
Cursor *cursor = Cursor::self();
disconnect(cursor, SIGNAL(posChanged(QPoint)), this, SLOT(updateApproaching(QPoint)));
cursor->stopMousePolling();
m_approachWindow.map();
}
void WindowBasedEdge::doUpdateBlocking()
{
if (!isReserved()) {
return;
}
if (isBlocked()) {
m_window.unmap();
m_approachWindow.unmap();
} else {
m_window.map();
m_approachWindow.map();
}
}
}

View file

@ -0,0 +1,78 @@
/********************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 2011 Arthur Arlt <a.arlt@stud.uni-heidelberg.de>
Copyright (C) 2013 Martin Gräßlin <mgraesslin@kde.org>
Since the functionality provided in this class has been moved from
class Workspace, it is not clear who exactly has written the code.
The list below contains the copyright holders of the class Workspace.
Copyright (C) 1999, 2000 Matthias Ettrich <ettrich@kde.org>
Copyright (C) 2003 Lubos Lunak <l.lunak@kde.org>
Copyright (C) 2009 Lucas Murray <lmurray@undefinedfire.com>
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_EDGE_H
#define KWIN_EDGE_H
#include "screenedge.h"
#include "xcbutils.h"
namespace KWin
{
class WindowBasedEdge : public Edge
{
Q_OBJECT
public:
explicit WindowBasedEdge(ScreenEdges *parent);
virtual ~WindowBasedEdge();
quint32 window() const override;
/**
* The approach window is a special window to notice when get close to the screen border but
* not yet triggering the border.
**/
quint32 approachWindow() const override;
protected:
virtual void doGeometryUpdate();
virtual void activate();
virtual void deactivate();
virtual void doStartApproaching();
virtual void doStopApproaching();
virtual void doUpdateBlocking();
private:
void createWindow();
void createApproachWindow();
Xcb::Window m_window;
Xcb::Window m_approachWindow;
};
inline quint32 WindowBasedEdge::window() const
{
return m_window;
}
inline quint32 WindowBasedEdge::approachWindow() const
{
return m_approachWindow;
}
}
#endif

View file

@ -18,6 +18,7 @@ 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 "x11_platform.h"
#include "edge.h"
#include <kwinconfig.h>
#if HAVE_EPOXY_GLX
#include "glxbackend.h"
@ -68,4 +69,9 @@ OpenGLBackend *X11StandalonePlatform::createOpenGLBackend()
}
}
Edge *X11StandalonePlatform::createScreenEdge(ScreenEdges *edges)
{
return new WindowBasedEdge(edges);
}
}

View file

@ -40,6 +40,7 @@ public:
Screens *createScreens(QObject *parent = nullptr) override;
OpenGLBackend *createOpenGLBackend() override;
Edge *createScreenEdge(ScreenEdges *parent) override;
};

View file

@ -34,10 +34,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <client.h>
#include "cursor.h"
#include "main.h"
#include "platform.h"
#include "screens.h"
#include "utils.h"
#include <workspace.h>
#include "virtualdesktops.h"
#ifdef KWIN_UNIT_TEST
#include "plugins/platforms/x11/standalone/edge.h"
#endif
// DBus generated
#include "screenlocker_interface.h"
// frameworks
@ -497,104 +501,6 @@ quint32 Edge::approachWindow() const
return 0;
}
/**********************************************************
* ScreenEdges
*********************************************************/
WindowBasedEdge::WindowBasedEdge(ScreenEdges *parent)
: Edge(parent)
, m_window(XCB_WINDOW_NONE)
, m_approachWindow(XCB_WINDOW_NONE)
{
}
WindowBasedEdge::~WindowBasedEdge()
{
}
void WindowBasedEdge::activate()
{
createWindow();
createApproachWindow();
doUpdateBlocking();
}
void WindowBasedEdge::deactivate()
{
m_window.reset();
m_approachWindow.reset();
}
void WindowBasedEdge::createWindow()
{
if (m_window.isValid()) {
return;
}
const uint32_t mask = XCB_CW_OVERRIDE_REDIRECT | XCB_CW_EVENT_MASK;
const uint32_t values[] = {
true,
XCB_EVENT_MASK_ENTER_WINDOW | XCB_EVENT_MASK_LEAVE_WINDOW | XCB_EVENT_MASK_POINTER_MOTION
};
m_window.create(geometry(), XCB_WINDOW_CLASS_INPUT_ONLY, mask, values);
m_window.map();
// Set XdndAware on the windows, so that DND enter events are received (#86998)
xcb_atom_t version = 4; // XDND version
xcb_change_property(connection(), XCB_PROP_MODE_REPLACE, m_window,
atoms->xdnd_aware, XCB_ATOM_ATOM, 32, 1, (unsigned char*)(&version));
}
void WindowBasedEdge::createApproachWindow()
{
if (m_approachWindow.isValid()) {
return;
}
if (!approachGeometry().isValid()) {
return;
}
const uint32_t mask = XCB_CW_OVERRIDE_REDIRECT | XCB_CW_EVENT_MASK;
const uint32_t values[] = {
true,
XCB_EVENT_MASK_ENTER_WINDOW | XCB_EVENT_MASK_LEAVE_WINDOW | XCB_EVENT_MASK_POINTER_MOTION
};
m_approachWindow.create(approachGeometry(), XCB_WINDOW_CLASS_INPUT_ONLY, mask, values);
m_approachWindow.map();
}
void WindowBasedEdge::doGeometryUpdate()
{
m_window.setGeometry(geometry());
m_approachWindow.setGeometry(approachGeometry());
}
void WindowBasedEdge::doStartApproaching()
{
m_approachWindow.unmap();
Cursor *cursor = Cursor::self();
connect(cursor, SIGNAL(posChanged(QPoint)), SLOT(updateApproaching(QPoint)));
cursor->startMousePolling();
}
void WindowBasedEdge::doStopApproaching()
{
Cursor *cursor = Cursor::self();
disconnect(cursor, SIGNAL(posChanged(QPoint)), this, SLOT(updateApproaching(QPoint)));
cursor->stopMousePolling();
m_approachWindow.map();
}
void WindowBasedEdge::doUpdateBlocking()
{
if (!isReserved()) {
return;
}
if (isBlocked()) {
m_window.unmap();
m_approachWindow.unmap();
} else {
m_window.map();
m_approachWindow.map();
}
}
/**********************************************************
* ScreenEdges
*********************************************************/
@ -947,12 +853,11 @@ void ScreenEdges::createHorizontalEdge(ElectricBorder border, const QRect &scree
Edge *ScreenEdges::createEdge(ElectricBorder border, int x, int y, int width, int height, bool createAction)
{
Edge *edge;
if (kwinApp()->operationMode() == Application::OperationModeX11) {
edge = new WindowBasedEdge(this);
} else {
edge = new Edge(this);
}
#ifdef KWIN_UNIT_TEST
Edge *edge = new WindowBasedEdge(this);
#else
Edge *edge = kwinApp()->platform()->createScreenEdge(this);
#endif
edge->setBorder(border);
edge->setGeometry(QRect(x, y, width, height));
if (createAction) {

View file

@ -31,13 +31,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define KWIN_SCREENEDGE_H
// KWin
#include "kwinglobals.h"
#include "xcbutils.h"
// KDE includes
#include <KSharedConfig>
// Qt
#include <QObject>
#include <QVector>
#include <QDateTime>
#include <QRect>
class QMouseEvent;
@ -46,7 +46,7 @@ namespace KWin {
class Client;
class ScreenEdges;
class Edge : public QObject
class KWIN_EXPORT Edge : public QObject
{
Q_OBJECT
public:
@ -132,35 +132,6 @@ private:
Client *m_client;
};
class WindowBasedEdge : public Edge
{
Q_OBJECT
public:
explicit WindowBasedEdge(ScreenEdges *parent);
virtual ~WindowBasedEdge();
quint32 window() const override;
/**
* The approach window is a special window to notice when get close to the screen border but
* not yet triggering the border.
**/
quint32 approachWindow() const override;
protected:
virtual void doGeometryUpdate();
virtual void activate();
virtual void deactivate();
virtual void doStartApproaching();
virtual void doStopApproaching();
virtual void doUpdateBlocking();
private:
void createWindow();
void createApproachWindow();
Xcb::Window m_window;
Xcb::Window m_approachWindow;
};
/**
* @short Class for controlling screen edges.
*
@ -496,20 +467,6 @@ inline bool Edge::isApproaching() const
return m_approaching;
}
/**********************************************************
* Inlines WindowBasedEdge
*********************************************************/
inline quint32 WindowBasedEdge::window() const
{
return m_window;
}
inline quint32 WindowBasedEdge::approachWindow() const
{
return m_approachWindow;
}
/**********************************************************
* Inlines ScreenEdges
*********************************************************/