WaylandBackend becomes a KWin Singleton

The backend gets created by Workspace, but only if the environment
variable WAYLAND_DISPLAY is set.

Because of that the egl wayland backend does no longer create the
backend, but uses the already created one.
icc-effect-5.14.5
Martin Gräßlin 2013-06-17 10:28:31 +02:00
parent baf477ac00
commit 0f09f00210
5 changed files with 39 additions and 8 deletions

View File

@ -40,15 +40,19 @@ EglWaylandBackend::EglWaylandBackend()
, OpenGLBackend()
, m_context(EGL_NO_CONTEXT)
, m_bufferAge(0)
, m_wayland(new Wayland::WaylandBackend)
, m_wayland(Wayland::WaylandBackend::self())
, m_overlay(NULL)
{
if (!m_wayland) {
setFailed("Wayland Backend has not been created");
return;
}
qDebug() << "Connected to Wayland display?" << (m_wayland->display() ? "yes" : "no" );
if (!m_wayland->display()) {
setFailed("Could not connect to Wayland compositor");
return;
}
connect(m_wayland.data(), SIGNAL(shellSurfaceSizeChanged(QSize)), SLOT(overlaySizeChanged(QSize)));
connect(m_wayland, SIGNAL(shellSurfaceSizeChanged(QSize)), SLOT(overlaySizeChanged(QSize)));
initializeEgl();
init();
// Egl is always direct rendering

View File

@ -85,7 +85,7 @@ private:
EGLSurface m_surface;
EGLContext m_context;
int m_bufferAge;
QScopedPointer<Wayland::WaylandBackend> m_wayland;
Wayland::WaylandBackend *m_wayland;
wl_egl_window *m_overlay;
QScopedPointer<Shm> m_shm;
friend class EglWaylandTexture;

View File

@ -20,7 +20,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
// own
#include "wayland_backend.h"
// KWin
#include <kwinglobals.h>
#include "cursor.h"
// Qt
#include <QDebug>
@ -338,7 +337,10 @@ X11CursorTracker::X11CursorTracker(wl_pointer *pointer, WaylandBackend *backend,
X11CursorTracker::~X11CursorTracker()
{
Cursor::self()->stopCursorTracking();
if (Cursor::self()) {
// Cursor might have been destroyed before Wayland backend gets destroyed
Cursor::self()->stopCursorTracking();
}
if (m_cursor) {
wl_surface_destroy(m_cursor);
}
@ -519,8 +521,20 @@ void WaylandSeat::resetCursor()
}
}
WaylandBackend::WaylandBackend()
: QObject(NULL)
WaylandBackend *WaylandBackend::s_self = 0;
WaylandBackend *WaylandBackend::create(QObject *parent)
{
Q_ASSERT(!s_self);
const QByteArray display = qgetenv("WAYLAND_DISPLAY");
if (display.isEmpty()) {
return NULL;
}
s_self = new WaylandBackend(parent);
return s_self;
}
WaylandBackend::WaylandBackend(QObject *parent)
: QObject(parent)
, m_display(wl_display_connect(NULL))
, m_registry(wl_display_get_registry(m_display))
, m_compositor(NULL)
@ -562,6 +576,7 @@ WaylandBackend::~WaylandBackend()
wl_display_disconnect(m_display);
}
qDebug() << "Destroyed Wayland display";
s_self = NULL;
}
void WaylandBackend::readEvents()

View File

@ -19,6 +19,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#ifndef KWIN_WAYLAND_BACKEND_H
#define KWIN_WAYLAND_BACKEND_H
// KWin
#include <kwinglobals.h>
// Qt
#include <QHash>
#include <QObject>
@ -126,7 +128,6 @@ class WaylandBackend : public QObject
{
Q_OBJECT
public:
WaylandBackend();
virtual ~WaylandBackend();
wl_display *display();
wl_registry *registry();
@ -159,6 +160,8 @@ private:
QSize m_shellSurfaceSize;
QScopedPointer<WaylandSeat> m_seat;
QScopedPointer<ShmPool> m_shm;
KWIN_SINGLETON(WaylandBackend)
};
inline

View File

@ -58,6 +58,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "unmanaged.h"
#include "useractions.h"
#include "virtualdesktops.h"
#include <config-workspace.h>
#ifdef WAYLAND_FOUND
#include "wayland_backend.h"
#endif
#include "xcbutils.h"
#include "main.h"
// KDE
@ -168,6 +172,11 @@ Workspace::Workspace(bool restore)
// first initialize the extensions
Xcb::Extensions::self();
// start the Wayland Backend - will only be created if WAYLAND_DISPLAY is present
#ifdef WAYLAND_FOUND
Wayland::WaylandBackend::create(this);
#endif
// start the cursor support
Cursor::create(this);