[wayland] Split out WaylandCursorTheme into own header/implementation

It's used by both the WaylandBackend and AbstractBackend. By splitting
it out the AbstractBackend doesn't need to depend on an implementation.
icc-effect-5.14.5
Martin Gräßlin 2015-05-05 13:02:16 +02:00
parent 79b5685b7a
commit 300a576d32
7 changed files with 157 additions and 90 deletions

View File

@ -461,6 +461,12 @@ if(HAVE_WAYLAND)
egl_gbm_backend.cpp
)
endif()
if(HAVE_WAYLAND_CURSOR)
set(kwin_KDEINIT_SRCS
${kwin_KDEINIT_SRCS}
wayland_cursor_theme.cpp
)
endif()
endif()
if(UDEV_FOUND)

View File

@ -23,9 +23,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "cursor.h"
#include "input.h"
#include "wayland_server.h"
#if HAVE_WAYLAND_CURSOR
#include "wayland_backend.h"
#endif
#include "wayland_cursor_theme.h"
// KWayland
#include <KWayland/Client/buffer.h>
#include <KWayland/Client/connection_thread.h>
@ -97,7 +95,7 @@ void AbstractBackend::updateCursorImage(Qt::CursorShape shape)
if (!m_cursorTheme) {
// check whether we can create it
if (waylandServer() && waylandServer()->internalShmPool()) {
m_cursorTheme = new Wayland::WaylandCursorTheme(waylandServer()->internalShmPool(), this);
m_cursorTheme = new WaylandCursorTheme(waylandServer()->internalShmPool(), this);
}
}
if (!m_cursorTheme) {

View File

@ -29,11 +29,7 @@ namespace KWin
class OpenGLBackend;
class QPainterBackend;
class Screens;
namespace Wayland
{
class WaylandCursorTheme;
}
class KWIN_EXPORT AbstractBackend : public QObject
{
@ -101,7 +97,7 @@ private:
QImage image;
QPoint lastRenderedPosition;
} m_cursor;
Wayland::WaylandCursorTheme *m_cursorTheme = nullptr;
WaylandCursorTheme *m_cursorTheme = nullptr;
bool m_handlesOutputs = false;
};

View File

@ -26,6 +26,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "screens_wayland.h"
#include "utils.h"
#include "wayland_server.h"
#if HAVE_WAYLAND_CURSOR
#include "wayland_cursor_theme.h"
#endif
#if HAVE_WAYLAND_EGL
#include "egl_wayland_backend.h"
#endif
@ -276,61 +279,6 @@ void WaylandSeat::setInstallCursor(bool install)
m_installCursor = install;
}
#if HAVE_WAYLAND_CURSOR
WaylandCursorTheme::WaylandCursorTheme(KWayland::Client::ShmPool *shm, QObject *parent)
: QObject(parent)
, m_theme(nullptr)
, m_shm(shm)
{
}
WaylandCursorTheme::~WaylandCursorTheme()
{
destroyTheme();
}
void WaylandCursorTheme::loadTheme()
{
if (!m_shm->isValid()) {
return;
}
Cursor *c = Cursor::self();
if (!m_theme) {
// so far the theme had not been created, this means we need to start tracking theme changes
connect(c, &Cursor::themeChanged, this, &WaylandCursorTheme::loadTheme);
} else {
destroyTheme();
}
m_theme = wl_cursor_theme_load(c->themeName().toUtf8().constData(),
c->themeSize() ? c->themeSize() : -1, m_shm->shm());
}
void WaylandCursorTheme::destroyTheme()
{
if (!m_theme) {
return;
}
wl_cursor_theme_destroy(m_theme);
m_theme = nullptr;
}
wl_cursor_image *WaylandCursorTheme::get(Qt::CursorShape shape)
{
if (!m_theme) {
loadTheme();
}
if (!m_theme) {
// loading cursor failed
return nullptr;
}
wl_cursor *c = wl_cursor_theme_get_cursor(m_theme, Cursor::self()->cursorName(shape).constData());
if (!c || c->image_count <= 0) {
return nullptr;
}
return c->images[0];
}
#endif
WaylandCursor::WaylandCursor(Surface *parentSurface, WaylandBackend *backend)
: QObject(backend)
, m_backend(backend)

View File

@ -31,8 +31,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <QSize>
class QTemporaryFile;
struct wl_cursor_image;
struct wl_cursor_theme;
struct wl_buffer;
struct wl_display;
struct wl_event_queue;
@ -64,6 +62,7 @@ class Touch;
namespace KWin
{
class WaylandCursorTheme;
namespace Wayland
{
@ -71,24 +70,6 @@ namespace Wayland
class WaylandBackend;
class WaylandSeat;
#if HAVE_WAYLAND_CURSOR
class WaylandCursorTheme : public QObject
{
Q_OBJECT
public:
explicit WaylandCursorTheme(KWayland::Client::ShmPool *shm, QObject *parent = nullptr);
virtual ~WaylandCursorTheme();
wl_cursor_image *get(Qt::CursorShape shape);
private:
void loadTheme();
void destroyTheme();
wl_cursor_theme *m_theme;
KWayland::Client::ShmPool *m_shm = nullptr;
};
#endif
class WaylandSeat : public QObject
{
Q_OBJECT
@ -112,9 +93,7 @@ private:
KWayland::Client::Keyboard *m_keyboard;
KWayland::Client::Touch *m_touch;
KWayland::Client::Surface *m_cursor;
#if HAVE_WAYLAND_CURSOR
WaylandCursorTheme *m_theme;
#endif
WaylandCursorTheme *m_theme = nullptr;
uint32_t m_enteredSerial;
WaylandBackend *m_backend;
bool m_installCursor;
@ -141,9 +120,7 @@ private:
WaylandBackend *m_backend;
QPoint m_hotSpot;
KWayland::Client::SubSurface *m_subSurface;
#if HAVE_WAYLAND_CURSOR
WaylandCursorTheme *m_theme;
#endif
WaylandCursorTheme *m_theme = nullptr;
};
/**

83
wayland_cursor_theme.cpp Normal file
View File

@ -0,0 +1,83 @@
/********************************************************************
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 "wayland_cursor_theme.h"
#include "cursor.h"
// KWayland
#include <KWayland/Client/shm_pool.h>
// Wayland
#include <wayland-cursor.h>
namespace KWin
{
WaylandCursorTheme::WaylandCursorTheme(KWayland::Client::ShmPool *shm, QObject *parent)
: QObject(parent)
, m_theme(nullptr)
, m_shm(shm)
{
}
WaylandCursorTheme::~WaylandCursorTheme()
{
destroyTheme();
}
void WaylandCursorTheme::loadTheme()
{
if (!m_shm->isValid()) {
return;
}
Cursor *c = Cursor::self();
if (!m_theme) {
// so far the theme had not been created, this means we need to start tracking theme changes
connect(c, &Cursor::themeChanged, this, &WaylandCursorTheme::loadTheme);
} else {
destroyTheme();
}
m_theme = wl_cursor_theme_load(c->themeName().toUtf8().constData(),
c->themeSize() ? c->themeSize() : -1, m_shm->shm());
}
void WaylandCursorTheme::destroyTheme()
{
if (!m_theme) {
return;
}
wl_cursor_theme_destroy(m_theme);
m_theme = nullptr;
}
wl_cursor_image *WaylandCursorTheme::get(Qt::CursorShape shape)
{
if (!m_theme) {
loadTheme();
}
if (!m_theme) {
// loading cursor failed
return nullptr;
}
wl_cursor *c = wl_cursor_theme_get_cursor(m_theme, Cursor::self()->cursorName(shape).constData());
if (!c || c->image_count <= 0) {
return nullptr;
}
return c->images[0];
}
}

59
wayland_cursor_theme.h Normal file
View File

@ -0,0 +1,59 @@
/********************************************************************
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_WAYLAND_CURSOR_THEME_H
#define KWIN_WAYLAND_CURSOR_THEME_H
#include <kwin_export.h>
#include <QObject>
struct wl_cursor_image;
struct wl_cursor_theme;
namespace KWayland
{
namespace Client
{
class ShmPool;
}
}
namespace KWin
{
class KWIN_EXPORT WaylandCursorTheme : public QObject
{
Q_OBJECT
public:
explicit WaylandCursorTheme(KWayland::Client::ShmPool *shm, QObject *parent = nullptr);
virtual ~WaylandCursorTheme();
wl_cursor_image *get(Qt::CursorShape shape);
private:
void loadTheme();
void destroyTheme();
wl_cursor_theme *m_theme;
KWayland::Client::ShmPool *m_shm = nullptr;
};
}
#endif