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"
|
2015-11-30 07:34:52 +00:00
|
|
|
#include <config-kwin.h>
|
2013-06-17 07:35:45 +00:00
|
|
|
// KWin
|
|
|
|
#include "cursor.h"
|
2015-05-05 15:27:03 +00:00
|
|
|
#include "logging.h"
|
2014-08-15 12:16:15 +00:00
|
|
|
#include "main.h"
|
2015-05-05 13:13:36 +00:00
|
|
|
#include "scene_qpainter_wayland_backend.h"
|
2015-11-17 09:43:10 +00:00
|
|
|
#include "screens.h"
|
2015-02-25 08:35:42 +00:00
|
|
|
#include "wayland_server.h"
|
2015-05-05 11:02:16 +00:00
|
|
|
#include "wayland_cursor_theme.h"
|
2015-11-30 07:34:52 +00:00
|
|
|
#if HAVE_WAYLAND_EGL
|
2015-03-27 07:51:56 +00:00
|
|
|
#include "egl_wayland_backend.h"
|
2015-11-30 07:34:52 +00:00
|
|
|
#endif
|
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/keyboard.h>
|
|
|
|
#include <KWayland/Client/pointer.h>
|
2016-11-24 12:51:15 +00:00
|
|
|
#include <KWayland/Client/pointerconstraints.h>
|
2017-03-15 16:56:08 +00:00
|
|
|
#include <KWayland/Client/pointergestures.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>
|
2015-12-17 14:32:41 +00:00
|
|
|
#include <KWayland/Client/server_decoration.h>
|
2014-09-19 11:59:51 +00:00
|
|
|
#include <KWayland/Client/shell.h>
|
|
|
|
#include <KWayland/Client/shm_pool.h>
|
|
|
|
#include <KWayland/Client/surface.h>
|
2015-03-25 13:50:14 +00:00
|
|
|
#include <KWayland/Client/touch.h>
|
2016-07-11 07:59:05 +00:00
|
|
|
#include <KWayland/Client/xdgshell.h>
|
2015-02-27 16:46:41 +00:00
|
|
|
#include <KWayland/Server/buffer_interface.h>
|
2016-11-24 12:51:15 +00:00
|
|
|
#include <KWayland/Server/display.h>
|
2015-02-25 08:35:42 +00:00
|
|
|
#include <KWayland/Server/seat_interface.h>
|
2015-02-27 16:46:41 +00:00
|
|
|
#include <KWayland/Server/surface_interface.h>
|
2016-11-24 12:51:15 +00:00
|
|
|
|
|
|
|
#include <KLocalizedString>
|
2013-06-17 07:35:45 +00:00
|
|
|
// Qt
|
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
|
|
|
// Wayland
|
2013-06-27 07:58:04 +00:00
|
|
|
#include <wayland-cursor.h>
|
2013-06-17 07:35:45 +00:00
|
|
|
|
2016-11-24 12:51:15 +00:00
|
|
|
#include <linux/input.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-17 07:35:45 +00:00
|
|
|
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)
|
2015-03-31 09:22:58 +00:00
|
|
|
, m_touch(nullptr)
|
2013-06-27 06:25:59 +00:00
|
|
|
, m_cursor(NULL)
|
|
|
|
, 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) {
|
2015-05-05 08:44:46 +00:00
|
|
|
switch (state) {
|
|
|
|
case Keyboard::KeyState::Pressed:
|
2016-11-24 12:51:15 +00:00
|
|
|
if (key == KEY_RIGHTCTRL) {
|
|
|
|
m_backend->togglePointerConfinement();
|
|
|
|
}
|
2015-05-05 08:44:46 +00:00
|
|
|
m_backend->keyboardKeyPressed(key, time);
|
|
|
|
break;
|
|
|
|
case Keyboard::KeyState::Released:
|
|
|
|
m_backend->keyboardKeyReleased(key, time);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
Q_UNREACHABLE();
|
|
|
|
}
|
2014-08-21 09:20:03 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
connect(m_keyboard, &Keyboard::modifiersChanged, this,
|
|
|
|
[this](quint32 depressed, quint32 latched, quint32 locked, quint32 group) {
|
2015-05-05 08:44:46 +00:00
|
|
|
m_backend->keyboardModifiers(depressed, latched, locked, group);
|
2014-08-21 09:20:03 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
connect(m_keyboard, &Keyboard::keymapChanged, this,
|
|
|
|
[this](int fd, quint32 size) {
|
2015-05-05 08:44:46 +00:00
|
|
|
m_backend->keymapChange(fd, size);
|
2014-08-21 09:20:03 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
destroyKeyboard();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
connect(m_seat, &Seat::hasPointerChanged, this,
|
|
|
|
[this](bool hasPointer) {
|
|
|
|
if (hasPointer && !m_pointer) {
|
|
|
|
m_pointer = m_seat->createPointer(this);
|
2017-03-15 16:56:08 +00:00
|
|
|
setupPointerGestures();
|
2014-08-21 09:20:03 +00:00
|
|
|
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
|
2015-02-27 16:57:12 +00:00
|
|
|
m_pointer->hideCursor();
|
2014-10-16 14:39:49 +00:00
|
|
|
}
|
2014-08-21 09:20:03 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
connect(m_pointer, &Pointer::motion, this,
|
|
|
|
[this](const QPointF &relativeToSurface, quint32 time) {
|
2015-05-05 08:44:46 +00:00
|
|
|
m_backend->pointerMotion(relativeToSurface, time);
|
2014-08-21 09:20:03 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
connect(m_pointer, &Pointer::buttonStateChanged, this,
|
|
|
|
[this](quint32 serial, quint32 time, quint32 button, Pointer::ButtonState state) {
|
|
|
|
Q_UNUSED(serial)
|
2015-05-05 08:44:46 +00:00
|
|
|
switch (state) {
|
|
|
|
case Pointer::ButtonState::Pressed:
|
|
|
|
m_backend->pointerButtonPressed(button, time);
|
|
|
|
break;
|
|
|
|
case Pointer::ButtonState::Released:
|
|
|
|
m_backend->pointerButtonReleased(button, time);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
Q_UNREACHABLE();
|
|
|
|
}
|
2014-08-21 09:20:03 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
connect(m_pointer, &Pointer::axisChanged, this,
|
|
|
|
[this](quint32 time, Pointer::Axis axis, qreal delta) {
|
2015-05-05 08:44:46 +00:00
|
|
|
switch (axis) {
|
|
|
|
case Pointer::Axis::Horizontal:
|
|
|
|
m_backend->pointerAxisHorizontal(delta, time);
|
|
|
|
break;
|
|
|
|
case Pointer::Axis::Vertical:
|
|
|
|
m_backend->pointerAxisVertical(delta, time);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
Q_UNREACHABLE();
|
|
|
|
}
|
2014-08-21 09:20:03 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
destroyPointer();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2015-03-25 13:50:14 +00:00
|
|
|
connect(m_seat, &Seat::hasTouchChanged,
|
|
|
|
[this] (bool hasTouch) {
|
|
|
|
if (hasTouch && !m_touch) {
|
|
|
|
m_touch = m_seat->createTouch(this);
|
2016-04-07 07:18:10 +00:00
|
|
|
connect(m_touch, &Touch::sequenceCanceled, m_backend, &Platform::touchCancel);
|
|
|
|
connect(m_touch, &Touch::frameEnded, m_backend, &Platform::touchFrame);
|
2015-03-25 13:50:14 +00:00
|
|
|
connect(m_touch, &Touch::sequenceStarted, this,
|
2015-05-05 08:44:46 +00:00
|
|
|
[this] (TouchPoint *tp) {
|
|
|
|
m_backend->touchDown(tp->id(), tp->position(), tp->time());
|
2015-03-25 13:50:14 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
connect(m_touch, &Touch::pointAdded, this,
|
2015-05-05 08:44:46 +00:00
|
|
|
[this] (TouchPoint *tp) {
|
|
|
|
m_backend->touchDown(tp->id(), tp->position(), tp->time());
|
2015-03-25 13:50:14 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
connect(m_touch, &Touch::pointRemoved, this,
|
2015-05-05 08:44:46 +00:00
|
|
|
[this] (TouchPoint *tp) {
|
|
|
|
m_backend->touchUp(tp->id(), tp->time());
|
2015-03-25 13:50:14 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
connect(m_touch, &Touch::pointMoved, this,
|
2015-05-05 08:44:46 +00:00
|
|
|
[this] (TouchPoint *tp) {
|
|
|
|
m_backend->touchMotion(tp->id(), tp->position(), tp->time());
|
2015-03-25 13:50:14 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
destroyTouch();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2015-02-25 08:35:42 +00:00
|
|
|
WaylandServer *server = waylandServer();
|
|
|
|
if (server) {
|
|
|
|
using namespace KWayland::Server;
|
|
|
|
SeatInterface *si = server->seat();
|
|
|
|
connect(m_seat, &Seat::hasKeyboardChanged, si, &SeatInterface::setHasKeyboard);
|
|
|
|
connect(m_seat, &Seat::hasPointerChanged, si, &SeatInterface::setHasPointer);
|
|
|
|
connect(m_seat, &Seat::hasTouchChanged, si, &SeatInterface::setHasTouch);
|
|
|
|
connect(m_seat, &Seat::nameChanged, si, &SeatInterface::setName);
|
|
|
|
}
|
2013-06-17 07:35:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
WaylandSeat::~WaylandSeat()
|
|
|
|
{
|
|
|
|
destroyPointer();
|
|
|
|
destroyKeyboard();
|
2015-03-25 13:50:14 +00:00
|
|
|
destroyTouch();
|
2013-06-17 07:35:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void WaylandSeat::destroyPointer()
|
|
|
|
{
|
2017-03-15 16:56:08 +00:00
|
|
|
delete m_pinchGesture;
|
|
|
|
m_pinchGesture = nullptr;
|
|
|
|
delete m_swipeGesture;
|
|
|
|
m_swipeGesture = nullptr;
|
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
|
|
|
}
|
|
|
|
|
2015-03-25 13:50:14 +00:00
|
|
|
void WaylandSeat::destroyTouch()
|
|
|
|
{
|
|
|
|
delete m_touch;
|
|
|
|
m_touch = nullptr;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
2015-02-27 16:57:12 +00:00
|
|
|
m_pointer->setCursor(m_cursor, hotSpot);
|
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);
|
2016-02-23 11:29:05 +00:00
|
|
|
m_backend->flush();
|
2013-06-27 06:25:59 +00:00
|
|
|
}
|
|
|
|
|
2016-02-23 11:29:05 +00:00
|
|
|
void WaylandSeat::installCursorImage(const QImage &image, const QPoint &hotSpot)
|
2013-06-27 07:58:04 +00:00
|
|
|
{
|
2016-02-23 11:29:05 +00:00
|
|
|
if (image.isNull()) {
|
|
|
|
installCursorImage(nullptr, QSize(), QPoint());
|
2013-06-27 07:58:04 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-02-27 16:46:41 +00:00
|
|
|
installCursorImage(*(m_backend->shmPool()->createBuffer(image).data()), image.size(), hotSpot);
|
|
|
|
}
|
|
|
|
|
2014-10-16 14:39:49 +00:00
|
|
|
void WaylandSeat::setInstallCursor(bool install)
|
|
|
|
{
|
|
|
|
// TODO: remove, add?
|
|
|
|
m_installCursor = install;
|
|
|
|
}
|
|
|
|
|
2017-03-15 16:56:08 +00:00
|
|
|
void WaylandSeat::setupPointerGestures()
|
|
|
|
{
|
|
|
|
if (!m_pointer || !m_gesturesInterface) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (m_pinchGesture || m_swipeGesture) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_pinchGesture = m_gesturesInterface->createPinchGesture(m_pointer, this);
|
|
|
|
m_swipeGesture = m_gesturesInterface->createSwipeGesture(m_pointer, this);
|
|
|
|
connect(m_pinchGesture, &PointerPinchGesture::started, m_backend,
|
|
|
|
[this] (quint32 serial, quint32 time) {
|
|
|
|
Q_UNUSED(serial);
|
|
|
|
m_backend->processPinchGestureBegin(m_pinchGesture->fingerCount(), time);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
connect(m_pinchGesture, &PointerPinchGesture::updated, m_backend,
|
|
|
|
[this] (const QSizeF &delta, qreal scale, qreal rotation, quint32 time) {
|
|
|
|
m_backend->processPinchGestureUpdate(scale, rotation, delta, time);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
connect(m_pinchGesture, &PointerPinchGesture::ended, m_backend,
|
|
|
|
[this] (quint32 serial, quint32 time) {
|
|
|
|
Q_UNUSED(serial)
|
|
|
|
m_backend->processPinchGestureEnd(time);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
connect(m_pinchGesture, &PointerPinchGesture::cancelled, m_backend,
|
|
|
|
[this] (quint32 serial, quint32 time) {
|
|
|
|
Q_UNUSED(serial)
|
|
|
|
m_backend->processPinchGestureCancelled(time);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
connect(m_swipeGesture, &PointerSwipeGesture::started, m_backend,
|
|
|
|
[this] (quint32 serial, quint32 time) {
|
|
|
|
Q_UNUSED(serial)
|
|
|
|
m_backend->processSwipeGestureBegin(m_swipeGesture->fingerCount(), time);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
connect(m_swipeGesture, &PointerSwipeGesture::updated, m_backend, &Platform::processSwipeGestureUpdate);
|
|
|
|
connect(m_swipeGesture, &PointerSwipeGesture::ended, m_backend,
|
|
|
|
[this] (quint32 serial, quint32 time) {
|
|
|
|
Q_UNUSED(serial)
|
|
|
|
m_backend->processSwipeGestureEnd(time);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
connect(m_swipeGesture, &PointerSwipeGesture::cancelled, m_backend,
|
|
|
|
[this] (quint32 serial, quint32 time) {
|
|
|
|
Q_UNUSED(serial)
|
|
|
|
m_backend->processSwipeGestureCancelled(time);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-05-06 07:37:25 +00:00
|
|
|
WaylandBackend::WaylandBackend(QObject *parent)
|
2016-04-07 07:18:10 +00:00
|
|
|
: Platform(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))
|
2017-09-23 18:21:26 +00:00
|
|
|
, m_compositor(new KWayland::Client::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))
|
2015-03-23 11:45:21 +00:00
|
|
|
, m_connectionThreadObject(new ConnectionThread(nullptr))
|
2014-08-13 10:54:02 +00:00
|
|
|
, m_connectionThread(nullptr)
|
2015-05-06 06:32:39 +00:00
|
|
|
{
|
2015-05-06 07:16:36 +00:00
|
|
|
connect(this, &WaylandBackend::connectionFailed, this, &WaylandBackend::initFailed);
|
2015-11-17 09:43:10 +00:00
|
|
|
connect(this, &WaylandBackend::shellSurfaceSizeChanged, this, &WaylandBackend::screenSizeChanged);
|
2015-05-06 06:32:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
WaylandBackend::~WaylandBackend()
|
|
|
|
{
|
2016-11-24 12:51:15 +00:00
|
|
|
if (m_pointerConstraints) {
|
|
|
|
m_pointerConstraints->release();
|
|
|
|
}
|
2016-07-11 07:59:05 +00:00
|
|
|
if (m_xdgShellSurface) {
|
|
|
|
m_xdgShellSurface->release();
|
|
|
|
}
|
2015-05-06 06:32:39 +00:00
|
|
|
if (m_shellSurface) {
|
|
|
|
m_shellSurface->release();
|
|
|
|
}
|
|
|
|
if (m_surface) {
|
|
|
|
m_surface->release();
|
|
|
|
}
|
2016-07-11 07:59:05 +00:00
|
|
|
if (m_xdgShell) {
|
|
|
|
m_xdgShell->release();
|
|
|
|
}
|
2015-05-06 06:32:39 +00:00
|
|
|
m_shell->release();
|
|
|
|
m_compositor->release();
|
|
|
|
m_registry->release();
|
|
|
|
m_seat.reset();
|
|
|
|
m_shm->release();
|
|
|
|
m_eventQueue->release();
|
|
|
|
|
|
|
|
m_connectionThreadObject->deleteLater();
|
|
|
|
m_connectionThread->quit();
|
|
|
|
m_connectionThread->wait();
|
|
|
|
|
|
|
|
qCDebug(KWIN_WAYLAND_BACKEND) << "Destroyed Wayland display";
|
|
|
|
}
|
|
|
|
|
|
|
|
void WaylandBackend::init()
|
2013-06-17 07:35:45 +00:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
);
|
2014-08-21 09:30:56 +00:00
|
|
|
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));
|
|
|
|
}
|
|
|
|
);
|
2016-11-24 12:51:15 +00:00
|
|
|
connect(m_registry, &Registry::pointerConstraintsUnstableV1Announced, this,
|
|
|
|
[this](quint32 name, quint32 version) {
|
|
|
|
if (m_pointerConstraints) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_pointerConstraints = m_registry->createPointerConstraints(name, version, this);
|
|
|
|
updateWindowTitle();
|
|
|
|
}
|
|
|
|
);
|
2014-10-15 10:37:20 +00:00
|
|
|
connect(m_registry, &Registry::interfacesAnnounced, this, &WaylandBackend::createSurface);
|
2017-03-15 16:56:08 +00:00
|
|
|
connect(m_registry, &Registry::interfacesAnnounced, this,
|
|
|
|
[this] {
|
|
|
|
if (!m_seat) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto gi = m_registry->interface(Registry::Interface::PointerGesturesUnstableV1);
|
|
|
|
if (gi.name == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto gesturesInterface = m_registry->createPointerGestures(gi.name, gi.version, m_seat.data());
|
|
|
|
m_seat->installGesturesInterface(gesturesInterface);
|
|
|
|
}
|
|
|
|
);
|
2015-11-17 08:47:46 +00:00
|
|
|
if (!deviceIdentifier().isEmpty()) {
|
|
|
|
m_connectionThreadObject->setSocketName(deviceIdentifier());
|
|
|
|
}
|
2016-02-23 11:29:05 +00:00
|
|
|
connect(this, &WaylandBackend::cursorChanged, this,
|
|
|
|
[this] {
|
|
|
|
if (m_seat.isNull() || !m_seat->isInstallCursor()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_seat->installCursorImage(softwareCursor(), softwareCursorHotspot());
|
|
|
|
markCursorAsRendered();
|
|
|
|
}
|
|
|
|
);
|
2013-07-03 09:56:05 +00:00
|
|
|
initConnection();
|
2013-06-17 07:35:45 +00:00
|
|
|
}
|
|
|
|
|
2013-07-03 09:56:05 +00:00
|
|
|
void WaylandBackend::initConnection()
|
|
|
|
{
|
2014-08-13 10:54:02 +00:00
|
|
|
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-08-13 10:54:02 +00:00
|
|
|
},
|
|
|
|
Qt::QueuedConnection);
|
|
|
|
connect(m_connectionThreadObject, &ConnectionThread::connectionDied, this,
|
|
|
|
[this]() {
|
2015-05-05 17:02:52 +00:00
|
|
|
setReady(false);
|
2014-08-13 10:54:02 +00:00
|
|
|
emit systemCompositorDied();
|
|
|
|
m_seat.reset();
|
2014-08-21 05:54:16 +00:00
|
|
|
m_shm->destroy();
|
2016-07-11 07:59:05 +00:00
|
|
|
if (m_xdgShellSurface) {
|
|
|
|
m_xdgShellSurface->destroy();
|
|
|
|
delete m_xdgShellSurface;
|
|
|
|
m_xdgShellSurface = nullptr;
|
|
|
|
}
|
2014-08-13 10:54:02 +00:00
|
|
|
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-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
|
|
|
}
|
2016-07-11 07:59:05 +00:00
|
|
|
if (m_xdgShell) {
|
|
|
|
m_xdgShell->destroy();
|
|
|
|
}
|
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-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()) {
|
2015-07-31 08:17:43 +00:00
|
|
|
qCCritical(KWIN_WAYLAND_BACKEND) << "Creating Wayland Surface failed";
|
2013-06-17 07:35:45 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-12-17 14:32:41 +00:00
|
|
|
using namespace KWayland::Client;
|
|
|
|
auto iface = m_registry->interface(Registry::Interface::ServerSideDecorationManager);
|
|
|
|
if (iface.name != 0) {
|
|
|
|
auto manager = m_registry->createServerSideDecorationManager(iface.name, iface.version, this);
|
|
|
|
auto decoration = manager->create(m_surface, this);
|
|
|
|
connect(decoration, &ServerSideDecoration::modeChanged, this,
|
|
|
|
[this, decoration] {
|
|
|
|
if (decoration->mode() != ServerSideDecoration::Mode::Server) {
|
|
|
|
decoration->requestMode(ServerSideDecoration::Mode::Server);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2015-11-16 15:07:48 +00:00
|
|
|
if (m_seat) {
|
|
|
|
m_seat->setInstallCursor(true);
|
2014-10-16 14:39:49 +00:00
|
|
|
}
|
2016-07-11 07:59:05 +00:00
|
|
|
// check for xdg shell
|
|
|
|
auto xdgIface = m_registry->interface(Registry::Interface::XdgShellUnstableV5);
|
|
|
|
if (xdgIface.name != 0) {
|
|
|
|
m_xdgShell = m_registry->createXdgShell(xdgIface.name, xdgIface.version, this);
|
|
|
|
if (m_xdgShell && m_xdgShell->isValid()) {
|
|
|
|
m_xdgShellSurface = m_xdgShell->createSurface(m_surface, this);
|
|
|
|
connect(m_xdgShellSurface, &XdgShellSurface::closeRequested, qApp, &QCoreApplication::quit);
|
|
|
|
setupSurface(m_xdgShellSurface);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2015-11-16 15:00:24 +00:00
|
|
|
if (m_shell->isValid()) {
|
2014-08-20 09:27:09 +00:00
|
|
|
m_shellSurface = m_shell->createSurface(m_surface, this);
|
2016-07-11 07:59:05 +00:00
|
|
|
setupSurface(m_shellSurface);
|
2015-11-16 15:14:10 +00:00
|
|
|
m_shellSurface->setToplevel();
|
2014-08-19 07:31:31 +00:00
|
|
|
}
|
2013-06-17 07:35:45 +00:00
|
|
|
}
|
|
|
|
|
2016-07-11 07:59:05 +00:00
|
|
|
template <class T>
|
|
|
|
void WaylandBackend::setupSurface(T *surface)
|
|
|
|
{
|
|
|
|
connect(surface, &T::sizeChanged, this, &WaylandBackend::shellSurfaceSizeChanged);
|
|
|
|
surface->setSize(initialWindowSize());
|
2016-11-24 12:51:15 +00:00
|
|
|
updateWindowTitle();
|
2016-07-11 07:59:05 +00:00
|
|
|
setReady(true);
|
|
|
|
emit screensQueried();
|
|
|
|
}
|
|
|
|
|
2014-08-20 09:27:09 +00:00
|
|
|
QSize WaylandBackend::shellSurfaceSize() const
|
|
|
|
{
|
|
|
|
if (m_shellSurface) {
|
|
|
|
return m_shellSurface->size();
|
|
|
|
}
|
2016-07-11 07:59:05 +00:00
|
|
|
if (m_xdgShellSurface) {
|
|
|
|
return m_xdgShellSurface->size();
|
|
|
|
}
|
2014-08-20 09:27:09 +00:00
|
|
|
return QSize();
|
|
|
|
}
|
|
|
|
|
2015-03-27 06:52:59 +00:00
|
|
|
Screens *WaylandBackend::createScreens(QObject *parent)
|
|
|
|
{
|
2015-11-17 09:43:10 +00:00
|
|
|
return new BasicScreens(this, parent);
|
2015-03-27 06:52:59 +00:00
|
|
|
}
|
|
|
|
|
2015-03-27 07:51:56 +00:00
|
|
|
OpenGLBackend *WaylandBackend::createOpenGLBackend()
|
|
|
|
{
|
2015-11-30 07:34:52 +00:00
|
|
|
#if HAVE_WAYLAND_EGL
|
2015-03-27 07:51:56 +00:00
|
|
|
return new EglWaylandBackend(this);
|
2015-11-30 07:34:52 +00:00
|
|
|
#else
|
|
|
|
return nullptr;
|
|
|
|
#endif
|
2015-03-27 07:51:56 +00:00
|
|
|
}
|
|
|
|
|
2015-03-27 08:05:03 +00:00
|
|
|
QPainterBackend *WaylandBackend::createQPainterBackend()
|
|
|
|
{
|
|
|
|
return new WaylandQPainterBackend(this);
|
|
|
|
}
|
|
|
|
|
2016-02-23 11:29:05 +00:00
|
|
|
void WaylandBackend::flush()
|
|
|
|
{
|
|
|
|
if (m_connectionThreadObject) {
|
|
|
|
m_connectionThreadObject->flush();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-24 12:51:15 +00:00
|
|
|
void WaylandBackend::togglePointerConfinement()
|
|
|
|
{
|
|
|
|
if (!m_pointerConstraints) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!m_seat) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto p = m_seat->pointer();
|
|
|
|
if (!p) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!m_surface) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (m_pointerConfinement && m_isPointerConfined) {
|
|
|
|
delete m_pointerConfinement;
|
|
|
|
m_pointerConfinement = nullptr;
|
|
|
|
m_isPointerConfined = false;
|
|
|
|
updateWindowTitle();
|
|
|
|
flush();
|
|
|
|
return;
|
|
|
|
} else if (m_pointerConfinement) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_pointerConfinement = m_pointerConstraints->confinePointer(m_surface, p, nullptr, PointerConstraints::LifeTime::Persistent, this);
|
|
|
|
connect(m_pointerConfinement, &ConfinedPointer::confined, this,
|
|
|
|
[this] {
|
|
|
|
m_isPointerConfined = true;
|
|
|
|
updateWindowTitle();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
connect(m_pointerConfinement, &ConfinedPointer::unconfined, this,
|
|
|
|
[this] {
|
|
|
|
m_isPointerConfined = false;
|
|
|
|
updateWindowTitle();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
updateWindowTitle();
|
|
|
|
flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
void WaylandBackend::updateWindowTitle()
|
|
|
|
{
|
|
|
|
if (!m_xdgShellSurface) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
QString grab;
|
|
|
|
if (m_isPointerConfined) {
|
|
|
|
grab = i18n("Press right control to ungrab pointer");
|
|
|
|
} else {
|
|
|
|
if (!m_pointerConfinement && m_pointerConstraints) {
|
|
|
|
grab = i18n("Press right control key to grab pointer");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const QString title = i18nc("Title of nested KWin Wayland with Wayland socket identifier as argument",
|
|
|
|
"KDE Wayland Compositor (%1)", waylandServer()->display()->socketName());
|
|
|
|
if (grab.isEmpty()) {
|
|
|
|
m_xdgShellSurface->setTitle(title);
|
|
|
|
} else {
|
|
|
|
m_xdgShellSurface->setTitle(title + QStringLiteral(" - ") + grab);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-15 20:24:49 +00:00
|
|
|
QVector<CompositingType> WaylandBackend::supportedCompositors() const
|
|
|
|
{
|
|
|
|
#if HAVE_WAYLAND_EGL
|
|
|
|
return QVector<CompositingType>{OpenGLCompositing, QPainterCompositing};
|
|
|
|
#else
|
|
|
|
return QVector<CompositingType>{QPainterCompositing};
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-17 07:35:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // KWin
|