Commit 9a0fd940 authored by Martin Flöser's avatar Martin Flöser

Introduce AbstractBackend as base class for Wayland and X11Windowed backend

The AbstractBackend registers itself in the WaylandServer allowing
external users to easily get to the backend and not needing to test
manually which backend is used.
parent dae8eed3
......@@ -421,6 +421,7 @@ endif()
if(HAVE_WAYLAND)
set(kwin_KDEINIT_SRCS
${kwin_KDEINIT_SRCS}
abstract_backend.cpp
screens_wayland.cpp
screens_x11windowed.cpp
wayland_backend.cpp
......
/********************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 2015 Martin Gräßlin <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) 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 "abstract_backend.h"
#include "wayland_server.h"
namespace KWin
{
AbstractBackend::AbstractBackend(QObject *parent)
: QObject(parent)
{
WaylandServer::self()->installBackend(this);
}
AbstractBackend::~AbstractBackend()
{
WaylandServer::self()->uninstallBackend(this);
}
void AbstractBackend::installCursorFromServer()
{
}
void AbstractBackend::installCursorImage(Qt::CursorShape shape)
{
Q_UNUSED(shape)
}
}
/********************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 2015 Martin Gräßlin <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) 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_ABSTRACT_BACKEND_H
#define KWIN_ABSTRACT_BACKEND_H
#include <QObject>
namespace KWin
{
class AbstractBackend : public QObject
{
Q_OBJECT
public:
virtual ~AbstractBackend();
virtual void installCursorFromServer();
virtual void installCursorImage(Qt::CursorShape shape);
protected:
explicit AbstractBackend(QObject *parent = nullptr);
};
}
#endif
......@@ -56,7 +56,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "composite.h"
#include "xcbutils.h"
#if HAVE_WAYLAND
#include "wayland_backend.h"
#include "abstract_backend.h"
#include "wayland_server.h"
#endif
#include "decorations/decorationbridge.h"
......@@ -673,7 +674,7 @@ void EffectsHandlerImpl::startMouseInterception(Effect *effect, Qt::CursorShape
}
if (kwinApp()->operationMode() != Application::OperationModeX11) {
#if HAVE_WAYLAND
if (Wayland::WaylandBackend *w = Wayland::WaylandBackend::self()) {
if (AbstractBackend *w = waylandServer()->backend()) {
w->installCursorImage(shape);
}
#endif
......@@ -1171,8 +1172,10 @@ void EffectsHandlerImpl::defineCursor(Qt::CursorShape shape)
{
if (!m_mouseInterceptionWindow.isValid()) {
#if HAVE_WAYLAND
if (Wayland::WaylandBackend *w = Wayland::WaylandBackend::self()) {
w->installCursorImage(shape);
if (waylandServer()) {
if (AbstractBackend *w = waylandServer()->backend()) {
w->installCursorImage(shape);
}
}
#endif
return;
......
......@@ -33,9 +33,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "libinput/connection.h"
#endif
#if HAVE_WAYLAND
#include "wayland_backend.h"
#include "abstract_backend.h"
#include "wayland_server.h"
#include "x11windowed_backend.h"
#include <KWayland/Server/seat_interface.h>
#endif
// Qt
......@@ -256,25 +255,6 @@ static KWayland::Server::SeatInterface *findSeat()
}
#endif
template <typename T>
static
void disconnectSeat(KWayland::Server::SeatInterface *seat)
{
if (T *w = T::self()) {
QObject::disconnect(seat->focusedPointer()->cursor(), &KWayland::Server::Cursor::changed, w, &T::installCursorFromServer);
}
}
template <typename T>
static
void connectSeat(KWayland::Server::SeatInterface *seat)
{
if (T *w = T::self()) {
w->installCursorFromServer();
QObject::connect(seat->focusedPointer()->cursor(), &KWayland::Server::Cursor::changed, w, &T::installCursorFromServer);
}
}
void InputRedirection::updatePointerWindow()
{
// TODO: handle pointer grab aka popups
......@@ -288,14 +268,17 @@ void InputRedirection::updatePointerWindow()
// disconnect old surface
if (oldWindow) {
disconnect(oldWindow.data(), &Toplevel::geometryChanged, this, &InputRedirection::updateFocusedPointerPosition);
disconnectSeat<Wayland::WaylandBackend>(seat);
disconnectSeat<X11WindowedBackend>(seat);
if (AbstractBackend *b = waylandServer()->backend()) {
disconnect(seat->focusedPointer()->cursor(), &KWayland::Server::Cursor::changed, b, &AbstractBackend::installCursorFromServer);
}
}
if (t && t->surface()) {
seat->setFocusedPointerSurface(t->surface(), t->pos());
connect(t, &Toplevel::geometryChanged, this, &InputRedirection::updateFocusedPointerPosition);
connectSeat<Wayland::WaylandBackend>(seat);
connectSeat<X11WindowedBackend>(seat);
if (AbstractBackend *b = waylandServer()->backend()) {
b->installCursorFromServer();
connect(seat->focusedPointer()->cursor(), &KWayland::Server::Cursor::changed, b, &AbstractBackend::installCursorFromServer);
}
} else {
seat->setFocusedPointerSurface(nullptr);
t = nullptr;
......
......@@ -354,7 +354,7 @@ WaylandBackend *WaylandBackend::create(QObject *parent)
}
WaylandBackend::WaylandBackend(QObject *parent)
: QObject(parent)
: AbstractBackend(parent)
, m_display(nullptr)
, m_eventQueue(new EventQueue(this))
, m_registry(new Registry(this))
......
......@@ -20,6 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef KWIN_WAYLAND_BACKEND_H
#define KWIN_WAYLAND_BACKEND_H
// KWin
#include "abstract_backend.h"
#include <kwinglobals.h>
// Qt
#include <QHash>
......@@ -141,7 +142,7 @@ private:
* It creates the connection to the Wayland Compositor, sets up the registry and creates
* the Wayland surface and its shell mapping.
*/
class KWIN_EXPORT WaylandBackend : public QObject
class KWIN_EXPORT WaylandBackend : public AbstractBackend
{
Q_OBJECT
public:
......@@ -154,8 +155,8 @@ public:
KWayland::Client::Surface *surface() const;
QSize shellSurfaceSize() const;
void installCursorImage(Qt::CursorShape shape);
void installCursorFromServer();
void installCursorImage(Qt::CursorShape shape) override;
void installCursorFromServer() override;
protected:
void connectNotify(const QMetaMethod &signal) override;
......
......@@ -113,4 +113,16 @@ int WaylandServer::createQtConnection()
return sx[1];
}
void WaylandServer::installBackend(AbstractBackend *backend)
{
Q_ASSERT(!m_backend);
m_backend = backend;
}
void WaylandServer::uninstallBackend(AbstractBackend *backend)
{
Q_ASSERT(m_backend == backend);
m_backend = nullptr;
}
}
......@@ -40,6 +40,8 @@ class OutputInterface;
namespace KWin
{
class AbstractBackend;
class KWIN_EXPORT WaylandServer : public QObject
{
Q_OBJECT
......@@ -61,6 +63,12 @@ public:
return m_shell;
}
AbstractBackend *backend() const {
return m_backend;
}
void installBackend(AbstractBackend *backend);
void uninstallBackend(AbstractBackend *backend);
/**
* @returns file descriptor for Xwayland to connect to.
**/
......@@ -78,6 +86,7 @@ private:
KWayland::Server::ShellInterface *m_shell = nullptr;
KWayland::Server::ClientConnection *m_xwaylandConnection = nullptr;
KWayland::Server::ClientConnection *m_qtConnection = nullptr;
AbstractBackend *m_backend = nullptr;
KWIN_SINGLETON(WaylandServer)
};
......
......@@ -51,7 +51,7 @@ X11WindowedBackend *X11WindowedBackend::create(const QString &display, const QSi
}
X11WindowedBackend::X11WindowedBackend(const QString &display, const QSize &size, QObject *parent)
: QObject(parent)
: AbstractBackend(parent)
, m_size(size)
{
int screen = 0;
......
......@@ -19,6 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#ifndef KWIN_X11WINDOWED_BACKEND_H
#define KWIN_X11WINDOWED_BACKEND_H
#include "abstract_backend.h"
#include <kwin_export.h>
......@@ -33,7 +34,7 @@ typedef struct _XDisplay Display;
namespace KWin
{
class KWIN_EXPORT X11WindowedBackend : public QObject
class KWIN_EXPORT X11WindowedBackend : public AbstractBackend
{
Q_OBJECT
Q_PROPERTY(QSize size READ size NOTIFY sizeChanged)
......@@ -62,7 +63,7 @@ public:
return m_size;
}
void installCursorFromServer();
void installCursorFromServer() override;
static X11WindowedBackend *self();
static X11WindowedBackend *create(const QString &display, const QSize &size, QObject *parent);
......
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