2013-06-17 07:35:45 +00:00
|
|
|
/********************************************************************
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 2013 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/>.
|
|
|
|
*********************************************************************/
|
|
|
|
// own
|
|
|
|
#include "wayland_backend.h"
|
|
|
|
// KWin
|
|
|
|
#include "cursor.h"
|
2013-06-26 08:15:20 +00:00
|
|
|
#include "input.h"
|
2014-08-15 12:16:15 +00:00
|
|
|
#include "main.h"
|
2014-12-05 10:42:15 +00:00
|
|
|
#include "utils.h"
|
2014-09-19 11:59:51 +00:00
|
|
|
#include <KWayland/Client/buffer.h>
|
|
|
|
#include <KWayland/Client/compositor.h>
|
|
|
|
#include <KWayland/Client/connection_thread.h>
|
2014-09-23 11:15:49 +00:00
|
|
|
#include <KWayland/Client/event_queue.h>
|
2014-09-19 11:59:51 +00:00
|
|
|
#include <KWayland/Client/fullscreen_shell.h>
|
|
|
|
#include <KWayland/Client/keyboard.h>
|
|
|
|
#include <KWayland/Client/output.h>
|
|
|
|
#include <KWayland/Client/pointer.h>
|
2014-10-16 14:39:49 +00:00
|
|
|
#include <KWayland/Client/region.h>
|
2014-09-19 11:59:51 +00:00
|
|
|
#include <KWayland/Client/registry.h>
|
|
|
|
#include <KWayland/Client/seat.h>
|
|
|
|
#include <KWayland/Client/shell.h>
|
|
|
|
#include <KWayland/Client/shm_pool.h>
|
2014-10-16 14:39:49 +00:00
|
|
|
#include <KWayland/Client/subcompositor.h>
|
|
|
|
#include <KWayland/Client/subsurface.h>
|
2014-09-19 11:59:51 +00:00
|
|
|
#include <KWayland/Client/surface.h>
|
2013-06-17 07:35:45 +00:00
|
|
|
// Qt
|
2014-08-20 10:00:26 +00:00
|
|
|
#include <QAbstractEventDispatcher>
|
|
|
|
#include <QCoreApplication>
|
2013-06-17 07:35:45 +00:00
|
|
|
#include <QDebug>
|
2015-02-21 08:30:22 +00:00
|
|
|
#include <QMetaMethod>
|
2014-08-13 10:54:02 +00:00
|
|
|
#include <QThread>
|
2013-06-17 07:35:45 +00:00
|
|
|
// xcb
|
|
|
|
#include <xcb/xtest.h>
|
|
|
|
#include <xcb/xfixes.h>
|
|
|
|
// Wayland
|
|
|
|
#include <wayland-client-protocol.h>
|
2013-06-27 07:58:04 +00:00
|
|
|
#include <wayland-cursor.h>
|
2013-06-17 07:35:45 +00:00
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
namespace Wayland
|
|
|
|
{
|
|
|
|
|
2014-09-19 11:59:51 +00:00
|
|
|
using namespace KWayland::Client;
|
|
|
|
|
2013-06-18 09:48:23 +00:00
|
|
|
CursorData::CursorData()
|
|
|
|
: m_valid(init())
|
2013-06-17 07:35:45 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
CursorData::~CursorData()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-06-18 09:48:23 +00:00
|
|
|
bool CursorData::init()
|
2013-06-17 07:35:45 +00:00
|
|
|
{
|
|
|
|
QScopedPointer<xcb_xfixes_get_cursor_image_reply_t, QScopedPointerPodDeleter> cursor(
|
|
|
|
xcb_xfixes_get_cursor_image_reply(connection(),
|
|
|
|
xcb_xfixes_get_cursor_image_unchecked(connection()),
|
|
|
|
NULL));
|
|
|
|
if (cursor.isNull()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
QImage cursorImage((uchar *) xcb_xfixes_get_cursor_image_cursor_image(cursor.data()), cursor->width, cursor->height,
|
|
|
|
QImage::Format_ARGB32_Premultiplied);
|
|
|
|
if (cursorImage.isNull()) {
|
|
|
|
return false;
|
|
|
|
}
|
2013-06-18 09:48:23 +00:00
|
|
|
// the backend for the cursorImage is destroyed once the xcb cursor goes out of scope
|
|
|
|
// because of that we create a copy
|
|
|
|
m_cursor = cursorImage.copy();
|
2013-06-17 07:35:45 +00:00
|
|
|
|
|
|
|
m_hotSpot = QPoint(cursor->xhot, cursor->yhot);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-10-15 12:29:26 +00:00
|
|
|
X11CursorTracker::X11CursorTracker(WaylandBackend *backend, QObject* parent)
|
2013-06-17 07:35:45 +00:00
|
|
|
: QObject(parent)
|
|
|
|
, m_backend(backend)
|
|
|
|
, m_lastX11Cursor(0)
|
|
|
|
{
|
|
|
|
Cursor::self()->startCursorTracking();
|
|
|
|
connect(Cursor::self(), SIGNAL(cursorChanged(uint32_t)), SLOT(cursorChanged(uint32_t)));
|
|
|
|
}
|
|
|
|
|
|
|
|
X11CursorTracker::~X11CursorTracker()
|
|
|
|
{
|
2013-06-17 08:28:31 +00:00
|
|
|
if (Cursor::self()) {
|
|
|
|
// Cursor might have been destroyed before Wayland backend gets destroyed
|
|
|
|
Cursor::self()->stopCursorTracking();
|
|
|
|
}
|
2013-06-17 07:35:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void X11CursorTracker::cursorChanged(uint32_t serial)
|
|
|
|
{
|
|
|
|
if (m_lastX11Cursor == serial) {
|
|
|
|
// not changed;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_lastX11Cursor = serial;
|
|
|
|
QHash<uint32_t, CursorData>::iterator it = m_cursors.find(serial);
|
|
|
|
if (it != m_cursors.end()) {
|
|
|
|
installCursor(it.value());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ShmPool *pool = m_backend->shmPool();
|
2014-08-21 05:54:16 +00:00
|
|
|
if (!pool->isValid()) {
|
2013-06-17 07:35:45 +00:00
|
|
|
return;
|
|
|
|
}
|
2013-06-18 09:48:23 +00:00
|
|
|
CursorData cursor;
|
2013-06-17 07:35:45 +00:00
|
|
|
if (cursor.isValid()) {
|
|
|
|
// TODO: discard unused cursors after some time?
|
|
|
|
m_cursors.insert(serial, cursor);
|
|
|
|
}
|
|
|
|
installCursor(cursor);
|
|
|
|
}
|
|
|
|
|
|
|
|
void X11CursorTracker::installCursor(const CursorData& cursor)
|
|
|
|
{
|
2013-06-18 09:48:23 +00:00
|
|
|
const QImage &cursorImage = cursor.cursor();
|
2014-10-15 12:29:26 +00:00
|
|
|
auto buffer = m_backend->shmPool()->createBuffer(cursorImage);
|
2013-06-18 09:48:23 +00:00
|
|
|
if (!buffer) {
|
|
|
|
return;
|
|
|
|
}
|
2014-10-15 12:29:26 +00:00
|
|
|
emit cursorImageChanged(buffer, cursorImage.size(), cursor.hotSpot());
|
2013-06-17 07:35:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void X11CursorTracker::resetCursor()
|
|
|
|
{
|
|
|
|
QHash<uint32_t, CursorData>::iterator it = m_cursors.find(m_lastX11Cursor);
|
|
|
|
if (it != m_cursors.end()) {
|
|
|
|
installCursor(it.value());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
WaylandSeat::WaylandSeat(wl_seat *seat, WaylandBackend *backend)
|
2013-06-27 07:58:04 +00:00
|
|
|
: QObject(NULL)
|
2014-08-21 09:20:03 +00:00
|
|
|
, m_seat(new Seat(this))
|
2013-06-17 07:35:45 +00:00
|
|
|
, m_pointer(NULL)
|
|
|
|
, m_keyboard(NULL)
|
2013-06-27 06:25:59 +00:00
|
|
|
, m_cursor(NULL)
|
2014-10-16 14:39:49 +00:00
|
|
|
, m_theme(new WaylandCursorTheme(backend, this))
|
2013-06-27 06:25:59 +00:00
|
|
|
, m_enteredSerial(0)
|
2013-06-17 07:35:45 +00:00
|
|
|
, m_backend(backend)
|
2014-10-16 14:39:49 +00:00
|
|
|
, m_installCursor(false)
|
2013-06-17 07:35:45 +00:00
|
|
|
{
|
2014-08-21 09:20:03 +00:00
|
|
|
m_seat->setup(seat);
|
|
|
|
connect(m_seat, &Seat::hasKeyboardChanged, this,
|
|
|
|
[this](bool hasKeyboard) {
|
|
|
|
if (hasKeyboard) {
|
|
|
|
m_keyboard = m_seat->createKeyboard(this);
|
|
|
|
connect(m_keyboard, &Keyboard::keyChanged, this,
|
|
|
|
[this](quint32 key, Keyboard::KeyState state, quint32 time) {
|
|
|
|
auto toState = [state] {
|
|
|
|
switch (state) {
|
|
|
|
case Keyboard::KeyState::Pressed:
|
|
|
|
return InputRedirection::KeyboardKeyPressed;
|
|
|
|
case Keyboard::KeyState::Released:
|
|
|
|
return InputRedirection::KeyboardKeyReleased;
|
|
|
|
}
|
|
|
|
abort();
|
|
|
|
};
|
|
|
|
input()->processKeyboardKey(key, toState(), time);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
connect(m_keyboard, &Keyboard::modifiersChanged, this,
|
|
|
|
[this](quint32 depressed, quint32 latched, quint32 locked, quint32 group) {
|
|
|
|
input()->processKeyboardModifiers(depressed, latched, locked, group);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
connect(m_keyboard, &Keyboard::keymapChanged, this,
|
|
|
|
[this](int fd, quint32 size) {
|
|
|
|
input()->processKeymapChange(fd, size);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
destroyKeyboard();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
connect(m_seat, &Seat::hasPointerChanged, this,
|
|
|
|
[this](bool hasPointer) {
|
|
|
|
if (hasPointer && !m_pointer) {
|
|
|
|
m_pointer = m_seat->createPointer(this);
|
|
|
|
connect(m_pointer, &Pointer::entered, this,
|
|
|
|
[this](quint32 serial) {
|
|
|
|
m_enteredSerial = serial;
|
2014-10-16 14:39:49 +00:00
|
|
|
if (!m_installCursor) {
|
|
|
|
// explicitly hide cursor
|
|
|
|
wl_pointer_set_cursor(*m_pointer, m_enteredSerial, nullptr, 0, 0);
|
|
|
|
}
|
2014-08-21 09:20:03 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
connect(m_pointer, &Pointer::motion, this,
|
|
|
|
[this](const QPointF &relativeToSurface, quint32 time) {
|
|
|
|
input()->processPointerMotion(relativeToSurface.toPoint(), time);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
connect(m_pointer, &Pointer::buttonStateChanged, this,
|
|
|
|
[this](quint32 serial, quint32 time, quint32 button, Pointer::ButtonState state) {
|
|
|
|
Q_UNUSED(serial)
|
|
|
|
auto toState = [state] {
|
|
|
|
switch (state) {
|
|
|
|
case Pointer::ButtonState::Pressed:
|
|
|
|
return InputRedirection::PointerButtonPressed;
|
|
|
|
case Pointer::ButtonState::Released:
|
|
|
|
return InputRedirection::PointerButtonReleased;
|
|
|
|
}
|
|
|
|
abort();
|
|
|
|
};
|
|
|
|
input()->processPointerButton(button, toState(), time);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
connect(m_pointer, &Pointer::axisChanged, this,
|
|
|
|
[this](quint32 time, Pointer::Axis axis, qreal delta) {
|
|
|
|
auto toAxis = [axis] {
|
|
|
|
switch (axis) {
|
|
|
|
case Pointer::Axis::Horizontal:
|
|
|
|
return InputRedirection::PointerAxisHorizontal;
|
|
|
|
case Pointer::Axis::Vertical:
|
|
|
|
return InputRedirection::PointerAxisVertical;
|
|
|
|
}
|
|
|
|
abort();
|
|
|
|
};
|
|
|
|
input()->processPointerAxis(toAxis(), delta, time);
|
|
|
|
}
|
|
|
|
);
|
2014-10-15 12:55:31 +00:00
|
|
|
connect(m_backend->cursorTracker(), &X11CursorTracker::cursorImageChanged, this,
|
2014-10-15 12:29:26 +00:00
|
|
|
[this](Buffer::Ptr image, const QSize &size, const QPoint &hotspot) {
|
|
|
|
if (image.isNull()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
installCursorImage(image.toStrongRef()->buffer(), size, hotspot);
|
|
|
|
}
|
|
|
|
);
|
2014-08-21 09:20:03 +00:00
|
|
|
} else {
|
|
|
|
destroyPointer();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2013-06-17 07:35:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
WaylandSeat::~WaylandSeat()
|
|
|
|
{
|
|
|
|
destroyPointer();
|
|
|
|
destroyKeyboard();
|
|
|
|
}
|
|
|
|
|
|
|
|
void WaylandSeat::destroyPointer()
|
|
|
|
{
|
2014-08-21 09:20:03 +00:00
|
|
|
delete m_pointer;
|
|
|
|
m_pointer = nullptr;
|
2013-06-17 07:35:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void WaylandSeat::destroyKeyboard()
|
|
|
|
{
|
2014-08-21 09:20:03 +00:00
|
|
|
delete m_keyboard;
|
|
|
|
m_keyboard = nullptr;
|
2013-06-17 07:35:45 +00:00
|
|
|
}
|
|
|
|
|
2013-06-27 06:25:59 +00:00
|
|
|
void WaylandSeat::installCursorImage(wl_buffer *image, const QSize &size, const QPoint &hotSpot)
|
|
|
|
{
|
2014-10-16 14:39:49 +00:00
|
|
|
if (!m_installCursor) {
|
|
|
|
return;
|
|
|
|
}
|
2014-08-21 09:20:03 +00:00
|
|
|
if (!m_pointer || !m_pointer->isValid()) {
|
2013-06-27 06:25:59 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!m_cursor) {
|
2014-08-21 06:53:00 +00:00
|
|
|
m_cursor = m_backend->compositor()->createSurface(this);
|
|
|
|
}
|
|
|
|
if (!m_cursor || !m_cursor->isValid()) {
|
|
|
|
return;
|
2013-06-27 06:25:59 +00:00
|
|
|
}
|
2014-08-21 09:20:03 +00:00
|
|
|
wl_pointer_set_cursor(*m_pointer, m_enteredSerial, *m_cursor, hotSpot.x(), hotSpot.y());
|
2014-08-21 06:53:00 +00:00
|
|
|
m_cursor->attachBuffer(image);
|
|
|
|
m_cursor->damage(QRect(QPoint(0,0), size));
|
|
|
|
m_cursor->commit(Surface::CommitFlag::None);
|
2013-06-27 06:25:59 +00:00
|
|
|
}
|
|
|
|
|
2013-06-27 07:58:04 +00:00
|
|
|
void WaylandSeat::installCursorImage(Qt::CursorShape shape)
|
|
|
|
{
|
2014-10-16 14:39:49 +00:00
|
|
|
wl_cursor_image *image = m_theme->get(shape);
|
|
|
|
if (!image) {
|
2013-06-27 07:58:04 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
installCursorImage(wl_cursor_image_get_buffer(image),
|
|
|
|
QSize(image->width, image->height),
|
|
|
|
QPoint(image->hotspot_x, image->hotspot_y));
|
|
|
|
}
|
|
|
|
|
2014-10-16 14:39:49 +00:00
|
|
|
void WaylandSeat::setInstallCursor(bool install)
|
|
|
|
{
|
|
|
|
// TODO: remove, add?
|
|
|
|
m_installCursor = install;
|
|
|
|
}
|
|
|
|
|
|
|
|
WaylandCursorTheme::WaylandCursorTheme(WaylandBackend *backend, QObject *parent)
|
|
|
|
: QObject(parent)
|
|
|
|
, m_theme(nullptr)
|
|
|
|
, m_backend(backend)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
WaylandCursorTheme::~WaylandCursorTheme()
|
|
|
|
{
|
|
|
|
destroyTheme();
|
|
|
|
}
|
|
|
|
|
|
|
|
void WaylandCursorTheme::loadTheme()
|
2013-06-27 07:58:04 +00:00
|
|
|
{
|
|
|
|
Cursor *c = Cursor::self();
|
|
|
|
if (!m_theme) {
|
|
|
|
// so far the theme had not been created, this means we need to start tracking theme changes
|
2014-10-16 14:39:49 +00:00
|
|
|
connect(c, &Cursor::themeChanged, this, &WaylandCursorTheme::loadTheme);
|
2013-06-27 07:58:04 +00:00
|
|
|
} else {
|
|
|
|
destroyTheme();
|
|
|
|
}
|
|
|
|
m_theme = wl_cursor_theme_load(c->themeName().toUtf8().constData(),
|
2015-02-24 13:39:45 +00:00
|
|
|
c->themeSize() ? c->themeSize() : -1, m_backend->shmPool()->shm());
|
2013-06-27 07:58:04 +00:00
|
|
|
}
|
|
|
|
|
2014-10-16 14:39:49 +00:00
|
|
|
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();
|
|
|
|
}
|
2015-01-09 15:02:03 +00:00
|
|
|
if (!m_theme) {
|
|
|
|
// loading cursor failed
|
|
|
|
return nullptr;
|
|
|
|
}
|
2014-10-16 14:39:49 +00:00
|
|
|
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];
|
|
|
|
}
|
|
|
|
|
|
|
|
WaylandCursor::WaylandCursor(Surface *parentSurface, WaylandBackend *backend)
|
|
|
|
: QObject(backend)
|
|
|
|
, m_backend(backend)
|
|
|
|
, m_theme(new WaylandCursorTheme(backend, this))
|
|
|
|
{
|
|
|
|
auto surface = backend->compositor()->createSurface(this);
|
|
|
|
m_subSurface = backend->subCompositor()->createSubSurface(QPointer<Surface>(surface), QPointer<Surface>(parentSurface), this);
|
|
|
|
|
|
|
|
connect(m_backend->cursorTracker(), &X11CursorTracker::cursorImageChanged, this,
|
|
|
|
[this](Buffer::Ptr image, const QSize &size, const QPoint &hotspot) {
|
|
|
|
if (image.isNull()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
setCursorImage(image.toStrongRef()->buffer(), size, hotspot);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
connect(Cursor::self(), &Cursor::posChanged, this,
|
|
|
|
[this](const QPoint &pos) {
|
|
|
|
m_subSurface->setPosition(pos - m_hotSpot);
|
|
|
|
QPointer<Surface> parent = m_subSurface->parentSurface();
|
|
|
|
if (parent.isNull()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
parent->commit(Surface::CommitFlag::None);
|
|
|
|
}
|
|
|
|
);
|
2014-10-17 07:53:42 +00:00
|
|
|
|
|
|
|
// install a default cursor image:
|
|
|
|
setCursorImage(Qt::ArrowCursor);
|
2014-10-16 14:39:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void WaylandCursor::setHotSpot(const QPoint &pos)
|
|
|
|
{
|
|
|
|
if (m_hotSpot == pos) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_hotSpot = pos;
|
|
|
|
emit hotSpotChanged(m_hotSpot);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WaylandCursor::setCursorImage(wl_buffer *image, const QSize &size, const QPoint &hotspot)
|
2013-06-27 07:58:04 +00:00
|
|
|
{
|
2014-10-16 14:39:49 +00:00
|
|
|
QPointer<Surface> cursor = m_subSurface->surface();
|
|
|
|
if (cursor.isNull()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
cursor->attachBuffer(image);
|
|
|
|
cursor->damage(QRect(QPoint(0,0), size));
|
|
|
|
cursor->setInputRegion(m_backend->compositor()->createRegion(QRegion()).get());
|
|
|
|
cursor->commit(Surface::CommitFlag::None);
|
|
|
|
setHotSpot(hotspot);
|
|
|
|
m_subSurface->setPosition(Cursor::pos() - m_hotSpot);
|
|
|
|
QPointer<Surface> parent = m_subSurface->parentSurface();
|
|
|
|
if (parent.isNull()) {
|
|
|
|
return;
|
2013-06-27 07:58:04 +00:00
|
|
|
}
|
2014-10-16 14:39:49 +00:00
|
|
|
parent->commit(Surface::CommitFlag::None);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WaylandCursor::setCursorImage(Qt::CursorShape shape)
|
|
|
|
{
|
|
|
|
wl_cursor_image *image = m_theme->get(shape);
|
|
|
|
if (!image) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
setCursorImage(wl_cursor_image_get_buffer(image),
|
|
|
|
QSize(image->width, image->height),
|
|
|
|
QPoint(image->hotspot_x, image->hotspot_y));
|
2013-06-27 07:58:04 +00:00
|
|
|
}
|
|
|
|
|
2013-06-17 08:28:31 +00:00
|
|
|
WaylandBackend *WaylandBackend::s_self = 0;
|
|
|
|
WaylandBackend *WaylandBackend::create(QObject *parent)
|
|
|
|
{
|
|
|
|
Q_ASSERT(!s_self);
|
|
|
|
s_self = new WaylandBackend(parent);
|
|
|
|
return s_self;
|
|
|
|
}
|
|
|
|
|
|
|
|
WaylandBackend::WaylandBackend(QObject *parent)
|
|
|
|
: QObject(parent)
|
2013-07-03 09:56:05 +00:00
|
|
|
, m_display(nullptr)
|
2014-09-23 11:15:49 +00:00
|
|
|
, m_eventQueue(new EventQueue(this))
|
2014-08-18 12:05:35 +00:00
|
|
|
, m_registry(new Registry(this))
|
2014-08-21 06:53:00 +00:00
|
|
|
, m_compositor(new Compositor(this))
|
2014-08-20 09:27:09 +00:00
|
|
|
, m_shell(new Shell(this))
|
2014-08-21 06:53:00 +00:00
|
|
|
, m_surface(nullptr)
|
2013-06-17 07:35:45 +00:00
|
|
|
, m_shellSurface(NULL)
|
|
|
|
, m_seat()
|
2014-08-21 05:54:16 +00:00
|
|
|
, m_shm(new ShmPool(this))
|
2014-10-15 12:55:31 +00:00
|
|
|
, m_cursorTracker()
|
2014-08-13 10:54:02 +00:00
|
|
|
, m_connectionThreadObject(nullptr)
|
|
|
|
, m_connectionThread(nullptr)
|
2014-08-19 07:31:31 +00:00
|
|
|
, m_fullscreenShell(new FullscreenShell(this))
|
2014-10-16 14:39:49 +00:00
|
|
|
, m_subCompositor(new SubCompositor(this))
|
|
|
|
, m_cursor(nullptr)
|
2013-06-17 07:35:45 +00:00
|
|
|
{
|
2014-08-20 09:27:09 +00:00
|
|
|
connect(this, &WaylandBackend::shellSurfaceSizeChanged, this, &WaylandBackend::checkBackendReady);
|
2014-08-18 12:05:35 +00:00
|
|
|
connect(m_registry, &Registry::compositorAnnounced, this,
|
|
|
|
[this](quint32 name) {
|
2014-08-21 06:53:00 +00:00
|
|
|
m_compositor->setup(m_registry->bindCompositor(name, 1));
|
2014-08-18 12:05:35 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
connect(m_registry, &Registry::shellAnnounced, this,
|
|
|
|
[this](quint32 name) {
|
2014-08-20 09:27:09 +00:00
|
|
|
m_shell->setup(m_registry->bindShell(name, 1));
|
2014-08-18 12:05:35 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
connect(m_registry, &Registry::outputAnnounced, this,
|
|
|
|
[this](quint32 name) {
|
2014-08-21 09:30:56 +00:00
|
|
|
Output *output = new Output(this);
|
|
|
|
output->setup(m_registry->bindOutput(name, 2));
|
|
|
|
m_outputs.append(output);
|
|
|
|
connect(output, &Output::changed, this, &WaylandBackend::outputsChanged);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
connect(m_registry, &Registry::seatAnnounced, this,
|
|
|
|
[this](quint32 name) {
|
2014-08-15 12:16:15 +00:00
|
|
|
if (Application::usesLibinput()) {
|
|
|
|
return;
|
|
|
|
}
|
2014-08-21 09:30:56 +00:00
|
|
|
m_seat.reset(new WaylandSeat(m_registry->bindSeat(name, 2), this));
|
2014-08-18 12:05:35 +00:00
|
|
|
}
|
|
|
|
);
|
2014-08-21 05:54:16 +00:00
|
|
|
connect(m_registry, &Registry::shmAnnounced, this,
|
|
|
|
[this](quint32 name) {
|
|
|
|
m_shm->setup(m_registry->bindShm(name, 1));
|
|
|
|
}
|
|
|
|
);
|
2014-08-19 07:31:31 +00:00
|
|
|
connect(m_registry, &Registry::fullscreenShellAnnounced, this,
|
|
|
|
[this](quint32 name, quint32 version) {
|
|
|
|
m_fullscreenShell->setup(m_registry->bindFullscreenShell(name, version));
|
|
|
|
}
|
|
|
|
);
|
2014-10-16 14:39:49 +00:00
|
|
|
connect(m_registry, &Registry::subCompositorAnnounced, this,
|
|
|
|
[this](quint32 name, quint32 version) {
|
|
|
|
m_subCompositor->setup(m_registry->bindSubCompositor(name, version));
|
|
|
|
}
|
|
|
|
);
|
2014-10-15 10:37:20 +00:00
|
|
|
connect(m_registry, &Registry::interfacesAnnounced, this, &WaylandBackend::createSurface);
|
2013-07-03 09:56:05 +00:00
|
|
|
initConnection();
|
2013-06-17 07:35:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
WaylandBackend::~WaylandBackend()
|
|
|
|
{
|
2013-07-05 09:11:25 +00:00
|
|
|
destroyOutputs();
|
2013-06-17 07:35:45 +00:00
|
|
|
if (m_shellSurface) {
|
2014-08-20 09:27:09 +00:00
|
|
|
m_shellSurface->release();
|
2013-06-17 07:35:45 +00:00
|
|
|
}
|
2014-08-19 07:31:31 +00:00
|
|
|
m_fullscreenShell->release();
|
2014-08-21 06:53:00 +00:00
|
|
|
if (m_surface) {
|
|
|
|
m_surface->release();
|
2013-06-17 07:35:45 +00:00
|
|
|
}
|
2014-08-21 06:53:00 +00:00
|
|
|
m_shell->release();
|
|
|
|
m_compositor->release();
|
2014-08-18 12:05:35 +00:00
|
|
|
m_registry->release();
|
2014-08-13 10:54:02 +00:00
|
|
|
m_seat.reset();
|
2014-08-21 05:54:16 +00:00
|
|
|
m_shm->release();
|
2014-09-23 11:15:49 +00:00
|
|
|
m_eventQueue->release();
|
2014-08-13 10:54:02 +00:00
|
|
|
|
|
|
|
m_connectionThreadObject->deleteLater();
|
|
|
|
m_connectionThread->quit();
|
|
|
|
m_connectionThread->wait();
|
|
|
|
|
2014-12-05 10:42:15 +00:00
|
|
|
qCDebug(KWIN_CORE) << "Destroyed Wayland display";
|
2013-06-17 08:28:31 +00:00
|
|
|
s_self = NULL;
|
2013-06-17 07:35:45 +00:00
|
|
|
}
|
|
|
|
|
2013-07-05 09:11:25 +00:00
|
|
|
void WaylandBackend::destroyOutputs()
|
|
|
|
{
|
|
|
|
qDeleteAll(m_outputs);
|
|
|
|
m_outputs.clear();
|
|
|
|
}
|
|
|
|
|
2013-07-03 09:56:05 +00:00
|
|
|
void WaylandBackend::initConnection()
|
|
|
|
{
|
2014-08-13 10:54:02 +00:00
|
|
|
m_connectionThreadObject = new ConnectionThread(nullptr);
|
|
|
|
connect(m_connectionThreadObject, &ConnectionThread::connected, this,
|
|
|
|
[this]() {
|
|
|
|
// create the event queue for the main gui thread
|
|
|
|
m_display = m_connectionThreadObject->display();
|
2014-09-23 11:15:49 +00:00
|
|
|
m_eventQueue->setup(m_connectionThreadObject);
|
|
|
|
m_registry->setEventQueue(m_eventQueue);
|
2014-08-13 10:54:02 +00:00
|
|
|
// setup registry
|
2014-08-18 12:05:35 +00:00
|
|
|
m_registry->create(m_display);
|
|
|
|
m_registry->setup();
|
2014-10-15 12:55:31 +00:00
|
|
|
m_cursorTracker.reset(new X11CursorTracker(this, this));
|
2014-08-13 10:54:02 +00:00
|
|
|
},
|
|
|
|
Qt::QueuedConnection);
|
|
|
|
connect(m_connectionThreadObject, &ConnectionThread::connectionDied, this,
|
|
|
|
[this]() {
|
2015-02-21 08:30:22 +00:00
|
|
|
m_ready = false;
|
2014-08-13 10:54:02 +00:00
|
|
|
emit systemCompositorDied();
|
2014-10-15 12:55:31 +00:00
|
|
|
m_cursorTracker.reset();
|
2014-08-13 10:54:02 +00:00
|
|
|
m_seat.reset();
|
2014-08-21 05:54:16 +00:00
|
|
|
m_shm->destroy();
|
2014-08-13 10:54:02 +00:00
|
|
|
destroyOutputs();
|
|
|
|
if (m_shellSurface) {
|
2014-08-20 09:27:09 +00:00
|
|
|
m_shellSurface->destroy();
|
|
|
|
delete m_shellSurface;
|
2014-08-13 10:54:02 +00:00
|
|
|
m_shellSurface = nullptr;
|
|
|
|
}
|
2014-08-19 07:31:31 +00:00
|
|
|
m_fullscreenShell->destroy();
|
2014-08-21 06:53:00 +00:00
|
|
|
if (m_surface) {
|
|
|
|
m_surface->destroy();
|
|
|
|
delete m_surface;
|
|
|
|
m_surface = nullptr;
|
|
|
|
}
|
2014-08-13 10:54:02 +00:00
|
|
|
if (m_shell) {
|
2014-08-20 09:27:09 +00:00
|
|
|
m_shell->destroy();
|
2014-08-13 10:54:02 +00:00
|
|
|
}
|
2014-08-21 06:53:00 +00:00
|
|
|
m_compositor->destroy();
|
2014-08-18 12:05:35 +00:00
|
|
|
m_registry->destroy();
|
2014-09-23 11:15:49 +00:00
|
|
|
m_eventQueue->destroy();
|
2014-08-13 10:54:02 +00:00
|
|
|
if (m_display) {
|
|
|
|
m_display = nullptr;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
Qt::QueuedConnection);
|
|
|
|
connect(m_connectionThreadObject, &ConnectionThread::failed, this, &WaylandBackend::connectionFailed, Qt::QueuedConnection);
|
|
|
|
|
|
|
|
m_connectionThread = new QThread(this);
|
|
|
|
m_connectionThreadObject->moveToThread(m_connectionThread);
|
|
|
|
m_connectionThread->start();
|
|
|
|
|
|
|
|
m_connectionThreadObject->initConnection();
|
2013-07-03 09:56:05 +00:00
|
|
|
}
|
|
|
|
|
2013-06-27 07:58:04 +00:00
|
|
|
void WaylandBackend::installCursorImage(Qt::CursorShape shape)
|
|
|
|
{
|
2014-10-16 14:39:49 +00:00
|
|
|
if (!m_seat.isNull() && m_seat->isInstallCursor()) {
|
|
|
|
m_seat->installCursorImage(shape);
|
|
|
|
} else if (m_cursor) {
|
|
|
|
m_cursor->setCursorImage(shape);
|
2013-06-27 07:58:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-17 07:35:45 +00:00
|
|
|
void WaylandBackend::createSurface()
|
|
|
|
{
|
2014-08-21 06:53:00 +00:00
|
|
|
m_surface = m_compositor->createSurface(this);
|
|
|
|
if (!m_surface || !m_surface->isValid()) {
|
2013-06-17 07:35:45 +00:00
|
|
|
qCritical() << "Creating Wayland Surface failed";
|
|
|
|
return;
|
|
|
|
}
|
2014-10-16 14:39:49 +00:00
|
|
|
if (m_subCompositor->isValid()) {
|
|
|
|
// we have a sub compositor - let's use it for mouse cursor
|
|
|
|
m_cursor = new WaylandCursor(m_surface, this);
|
|
|
|
} else {
|
|
|
|
// no sub-compositor - use the seat for setting the cursor image
|
|
|
|
if (m_seat) {
|
|
|
|
m_seat->setInstallCursor(true);
|
|
|
|
}
|
|
|
|
}
|
2014-08-19 07:31:31 +00:00
|
|
|
if (m_fullscreenShell->isValid()) {
|
|
|
|
Output *o = m_outputs.first();
|
2014-08-20 12:06:58 +00:00
|
|
|
m_fullscreenShell->present(m_surface, o);
|
2014-08-19 07:31:31 +00:00
|
|
|
if (o->pixelSize().isValid()) {
|
2014-08-20 09:27:09 +00:00
|
|
|
emit shellSurfaceSizeChanged(o->pixelSize());
|
2014-08-19 07:31:31 +00:00
|
|
|
}
|
|
|
|
connect(o, &Output::changed, this,
|
|
|
|
[this, o]() {
|
|
|
|
if (o->pixelSize().isValid()) {
|
2014-08-20 09:27:09 +00:00
|
|
|
emit shellSurfaceSizeChanged(o->pixelSize());
|
2014-08-19 07:31:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2014-08-20 09:27:09 +00:00
|
|
|
} else if (m_shell->isValid()) {
|
2014-08-19 07:31:31 +00:00
|
|
|
// map the surface as fullscreen
|
2014-08-20 09:27:09 +00:00
|
|
|
m_shellSurface = m_shell->createSurface(m_surface, this);
|
|
|
|
m_shellSurface->setFullscreen();
|
2014-10-15 12:55:31 +00:00
|
|
|
connect(m_shellSurface, &ShellSurface::pinged, m_cursorTracker.data(), &X11CursorTracker::resetCursor);
|
2014-08-20 09:27:09 +00:00
|
|
|
connect(m_shellSurface, &ShellSurface::sizeChanged, this, &WaylandBackend::shellSurfaceSizeChanged);
|
2014-08-19 07:31:31 +00:00
|
|
|
}
|
2013-06-17 07:35:45 +00:00
|
|
|
}
|
|
|
|
|
2014-08-20 09:27:09 +00:00
|
|
|
QSize WaylandBackend::shellSurfaceSize() const
|
|
|
|
{
|
|
|
|
if (m_shellSurface) {
|
|
|
|
return m_shellSurface->size();
|
|
|
|
}
|
|
|
|
if (m_fullscreenShell->isValid()) {
|
|
|
|
return m_outputs.first()->pixelSize();
|
|
|
|
}
|
|
|
|
return QSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
void WaylandBackend::checkBackendReady()
|
|
|
|
{
|
|
|
|
if (!shellSurfaceSize().isValid()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
disconnect(this, &WaylandBackend::shellSurfaceSizeChanged, this, &WaylandBackend::checkBackendReady);
|
2015-02-21 08:30:22 +00:00
|
|
|
m_ready = true;
|
2014-08-20 09:27:09 +00:00
|
|
|
emit backendReady();
|
|
|
|
}
|
|
|
|
|
2015-02-21 08:30:22 +00:00
|
|
|
void WaylandBackend::connectNotify(const QMetaMethod &signal)
|
|
|
|
{
|
|
|
|
if (m_ready && signal == QMetaMethod::fromSignal(&WaylandBackend::backendReady)) {
|
|
|
|
// backend is already ready, let's emit the signal
|
|
|
|
signal.invoke(this, Qt::QueuedConnection);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-17 07:35:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // KWin
|