[kwin_wayland] Add SeatInterface to server module
So far the Seat interface is provided together with pointer and keyboard. As always touch is not yet implemented. The pointer interface is still lacking the set cursor callback. Keyboard on the other hand is complete. Both Keyboard and Pointer have the concept of a focused surface and only to the bound interface belonging to the same client as the focused surface events are sent. The change comes with a set of new auto tests also verifying the client side which wasn't possible before as we couldn't fake events.icc-effect-5.14.5
parent
106b540d91
commit
5852a4c069
|
@ -10,6 +10,7 @@ set( testWaylandConnectionThread_SRCS
|
|||
${KWIN_SOURCE_DIR}/wayland_server/compositor_interface.cpp
|
||||
${KWIN_SOURCE_DIR}/wayland_server/display.cpp
|
||||
${KWIN_SOURCE_DIR}/wayland_server/output_interface.cpp
|
||||
${KWIN_SOURCE_DIR}/wayland_server/seat_interface.cpp
|
||||
${KWIN_SOURCE_DIR}/wayland_server/shell_interface.cpp
|
||||
${KWIN_SOURCE_DIR}/wayland_server/surface_interface.cpp
|
||||
)
|
||||
|
@ -65,6 +66,7 @@ set( testWaylandOutput_SRCS
|
|||
${KWIN_SOURCE_DIR}/wayland_server/compositor_interface.cpp
|
||||
${KWIN_SOURCE_DIR}/wayland_server/display.cpp
|
||||
${KWIN_SOURCE_DIR}/wayland_server/output_interface.cpp
|
||||
${KWIN_SOURCE_DIR}/wayland_server/seat_interface.cpp
|
||||
${KWIN_SOURCE_DIR}/wayland_server/shell_interface.cpp
|
||||
${KWIN_SOURCE_DIR}/wayland_server/surface_interface.cpp
|
||||
)
|
||||
|
@ -90,6 +92,7 @@ set( testWaylandShell_SRCS
|
|||
${KWIN_SOURCE_DIR}/wayland_server/compositor_interface.cpp
|
||||
${KWIN_SOURCE_DIR}/wayland_server/display.cpp
|
||||
${KWIN_SOURCE_DIR}/wayland_server/output_interface.cpp
|
||||
${KWIN_SOURCE_DIR}/wayland_server/seat_interface.cpp
|
||||
${KWIN_SOURCE_DIR}/wayland_server/shell_interface.cpp
|
||||
${KWIN_SOURCE_DIR}/wayland_server/surface_interface.cpp
|
||||
)
|
||||
|
@ -116,6 +119,7 @@ set( testWaylandSurface_SRCS
|
|||
${KWIN_SOURCE_DIR}/wayland_server/compositor_interface.cpp
|
||||
${KWIN_SOURCE_DIR}/wayland_server/display.cpp
|
||||
${KWIN_SOURCE_DIR}/wayland_server/output_interface.cpp
|
||||
${KWIN_SOURCE_DIR}/wayland_server/seat_interface.cpp
|
||||
${KWIN_SOURCE_DIR}/wayland_server/shell_interface.cpp
|
||||
${KWIN_SOURCE_DIR}/wayland_server/surface_interface.cpp
|
||||
)
|
||||
|
@ -124,3 +128,33 @@ add_dependencies(testWaylandSurface wayland-client-fullscreen-shell)
|
|||
target_link_libraries( testWaylandSurface Qt5::Test Qt5::Gui Wayland::Client Wayland::Server)
|
||||
add_test(kwin-testWaylandSurface testWaylandSurface)
|
||||
ecm_mark_as_test(testWaylandSurface)
|
||||
|
||||
########################################################
|
||||
# Test WaylandSeat
|
||||
########################################################
|
||||
set( testWaylandSeat_SRCS
|
||||
test_wayland_seat.cpp
|
||||
${KWIN_SOURCE_DIR}/wayland_client/buffer.cpp
|
||||
${KWIN_SOURCE_DIR}/wayland_client/compositor.cpp
|
||||
${KWIN_SOURCE_DIR}/wayland_client/connection_thread.cpp
|
||||
${KWIN_SOURCE_DIR}/wayland_client/registry.cpp
|
||||
${KWIN_SOURCE_DIR}/wayland_client/fullscreen_shell.cpp
|
||||
${KWIN_SOURCE_DIR}/wayland_client/keyboard.cpp
|
||||
${KWIN_SOURCE_DIR}/wayland_client/pointer.cpp
|
||||
${KWIN_SOURCE_DIR}/wayland_client/seat.cpp
|
||||
${KWIN_SOURCE_DIR}/wayland_client/shm_pool.cpp
|
||||
${KWIN_SOURCE_DIR}/wayland_client/surface.cpp
|
||||
${CMAKE_BINARY_DIR}/wayland_protocols/wayland-client-fullscreen-shell.c
|
||||
${KWIN_SOURCE_DIR}/wayland_server/buffer_interface.cpp
|
||||
${KWIN_SOURCE_DIR}/wayland_server/compositor_interface.cpp
|
||||
${KWIN_SOURCE_DIR}/wayland_server/display.cpp
|
||||
${KWIN_SOURCE_DIR}/wayland_server/output_interface.cpp
|
||||
${KWIN_SOURCE_DIR}/wayland_server/seat_interface.cpp
|
||||
${KWIN_SOURCE_DIR}/wayland_server/shell_interface.cpp
|
||||
${KWIN_SOURCE_DIR}/wayland_server/surface_interface.cpp
|
||||
)
|
||||
add_executable(testWaylandSeat ${testWaylandSeat_SRCS})
|
||||
add_dependencies(testWaylandSeat wayland-client-fullscreen-shell)
|
||||
target_link_libraries( testWaylandSeat Qt5::Test Qt5::Gui Wayland::Client Wayland::Server)
|
||||
add_test(kwin-testWaylandSeat testWaylandSeat)
|
||||
ecm_mark_as_test(testWaylandSeat)
|
||||
|
|
|
@ -0,0 +1,499 @@
|
|||
/********************************************************************
|
||||
KWin - the KDE window manager
|
||||
This file is part of the KDE project.
|
||||
|
||||
Copyright (C) 2014 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/>.
|
||||
*********************************************************************/
|
||||
// Qt
|
||||
#include <QtTest/QtTest>
|
||||
// KWin
|
||||
#include "../../wayland_client/compositor.h"
|
||||
#include "../../wayland_client/connection_thread.h"
|
||||
#include "../../wayland_client/keyboard.h"
|
||||
#include "../../wayland_client/pointer.h"
|
||||
#include "../../wayland_client/surface.h"
|
||||
#include "../../wayland_client/registry.h"
|
||||
#include "../../wayland_client/seat.h"
|
||||
#include "../../wayland_client/shm_pool.h"
|
||||
#include "../../wayland_server/buffer_interface.h"
|
||||
#include "../../wayland_server/compositor_interface.h"
|
||||
#include "../../wayland_server/display.h"
|
||||
#include "../../wayland_server/seat_interface.h"
|
||||
#include "../../wayland_server/surface_interface.h"
|
||||
// Wayland
|
||||
#include <wayland-client-protocol.h>
|
||||
|
||||
#include <linux/input.h>
|
||||
|
||||
class TestWaylandSeat : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit TestWaylandSeat(QObject *parent = nullptr);
|
||||
private Q_SLOTS:
|
||||
void init();
|
||||
void cleanup();
|
||||
|
||||
void testName();
|
||||
void testCapabilities_data();
|
||||
void testCapabilities();
|
||||
void testPointer();
|
||||
void testKeyboard();
|
||||
// TODO: add test for keymap
|
||||
|
||||
private:
|
||||
KWin::WaylandServer::Display *m_display;
|
||||
KWin::WaylandServer::CompositorInterface *m_compositorInterface;
|
||||
KWin::WaylandServer::SeatInterface *m_seatInterface;
|
||||
KWin::Wayland::ConnectionThread *m_connection;
|
||||
KWin::Wayland::Compositor *m_compositor;
|
||||
KWin::Wayland::Seat *m_seat;
|
||||
QThread *m_thread;
|
||||
};
|
||||
|
||||
static const QString s_socketName = QStringLiteral("kwin-test-wayland-seat-0");
|
||||
|
||||
TestWaylandSeat::TestWaylandSeat(QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_display(nullptr)
|
||||
, m_compositorInterface(nullptr)
|
||||
, m_seatInterface(nullptr)
|
||||
, m_connection(nullptr)
|
||||
, m_compositor(nullptr)
|
||||
, m_seat(nullptr)
|
||||
, m_thread(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
void TestWaylandSeat::init()
|
||||
{
|
||||
using namespace KWin::WaylandServer;
|
||||
delete m_display;
|
||||
m_display = new Display(this);
|
||||
m_display->setSocketName(s_socketName);
|
||||
m_display->start();
|
||||
QVERIFY(m_display->isRunning());
|
||||
|
||||
m_compositorInterface = m_display->createCompositor(m_display);
|
||||
QVERIFY(m_compositorInterface);
|
||||
m_compositorInterface->create();
|
||||
QVERIFY(m_compositorInterface->isValid());
|
||||
|
||||
// setup connection
|
||||
m_connection = new KWin::Wayland::ConnectionThread;
|
||||
QSignalSpy connectedSpy(m_connection, SIGNAL(connected()));
|
||||
m_connection->setSocketName(s_socketName);
|
||||
|
||||
m_thread = new QThread(this);
|
||||
m_connection->moveToThread(m_thread);
|
||||
m_thread->start();
|
||||
|
||||
connect(QCoreApplication::eventDispatcher(), &QAbstractEventDispatcher::aboutToBlock, m_connection,
|
||||
[this]() {
|
||||
if (m_connection->display()) {
|
||||
wl_display_flush(m_connection->display());
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
m_connection->initConnection();
|
||||
QVERIFY(connectedSpy.wait());
|
||||
// TODO: we should destroy the queue
|
||||
wl_event_queue *queue = wl_display_create_queue(m_connection->display());
|
||||
connect(m_connection, &KWin::Wayland::ConnectionThread::eventsRead, this,
|
||||
[this, queue]() {
|
||||
wl_display_dispatch_queue_pending(m_connection->display(), queue);
|
||||
wl_display_flush(m_connection->display());
|
||||
},
|
||||
Qt::QueuedConnection);
|
||||
|
||||
KWin::Wayland::Registry registry;
|
||||
QSignalSpy compositorSpy(®istry, SIGNAL(compositorAnnounced(quint32,quint32)));
|
||||
QSignalSpy seatSpy(®istry, SIGNAL(seatAnnounced(quint32,quint32)));
|
||||
registry.create(m_connection->display());
|
||||
QVERIFY(registry.isValid());
|
||||
registry.setup();
|
||||
wl_proxy_set_queue((wl_proxy*)registry.registry(), queue);
|
||||
QVERIFY(compositorSpy.wait());
|
||||
|
||||
m_seatInterface = m_display->createSeat();
|
||||
QVERIFY(m_seatInterface);
|
||||
m_seatInterface->setName(QStringLiteral("seat0"));
|
||||
m_seatInterface->create();
|
||||
QVERIFY(m_seatInterface->isValid());
|
||||
QVERIFY(seatSpy.wait());
|
||||
|
||||
m_compositor = new KWin::Wayland::Compositor(this);
|
||||
m_compositor->setup(registry.bindCompositor(compositorSpy.first().first().value<quint32>(), compositorSpy.first().last().value<quint32>()));
|
||||
QVERIFY(m_compositor->isValid());
|
||||
|
||||
m_seat = new KWin::Wayland::Seat(this);
|
||||
QSignalSpy nameSpy(m_seat, SIGNAL(nameChanged(QString)));
|
||||
m_seat->setup(registry.bindSeat(seatSpy.first().first().value<quint32>(), seatSpy.first().last().value<quint32>()));
|
||||
QVERIFY(nameSpy.wait());
|
||||
}
|
||||
|
||||
void TestWaylandSeat::cleanup()
|
||||
{
|
||||
if (m_seat) {
|
||||
delete m_seat;
|
||||
m_seat = nullptr;
|
||||
}
|
||||
if (m_compositor) {
|
||||
delete m_compositor;
|
||||
m_compositor = nullptr;
|
||||
}
|
||||
if (m_thread) {
|
||||
m_thread->quit();
|
||||
m_thread->wait();
|
||||
delete m_thread;
|
||||
m_thread = nullptr;
|
||||
}
|
||||
delete m_connection;
|
||||
m_connection = nullptr;
|
||||
|
||||
delete m_compositorInterface;
|
||||
m_compositorInterface = nullptr;
|
||||
|
||||
delete m_seatInterface;
|
||||
m_seatInterface = nullptr;
|
||||
|
||||
delete m_display;
|
||||
m_display = nullptr;
|
||||
}
|
||||
|
||||
void TestWaylandSeat::testName()
|
||||
{
|
||||
// no name set yet
|
||||
QCOMPARE(m_seat->name(), QStringLiteral("seat0"));
|
||||
|
||||
QSignalSpy spy(m_seat, SIGNAL(nameChanged(QString)));
|
||||
QVERIFY(spy.isValid());
|
||||
|
||||
const QString name = QStringLiteral("foobar");
|
||||
m_seatInterface->setName(name);
|
||||
QVERIFY(spy.wait());
|
||||
QCOMPARE(m_seat->name(), name);
|
||||
QCOMPARE(spy.count(), 1);
|
||||
QCOMPARE(spy.first().first().toString(), name);
|
||||
}
|
||||
|
||||
void TestWaylandSeat::testCapabilities_data()
|
||||
{
|
||||
QTest::addColumn<bool>("pointer");
|
||||
QTest::addColumn<bool>("keyboard");
|
||||
QTest::addColumn<bool>("touch");
|
||||
|
||||
QTest::newRow("none") << false << false << false;
|
||||
QTest::newRow("pointer") << true << false << false;
|
||||
QTest::newRow("keyboard") << false << true << false;
|
||||
QTest::newRow("touch") << false << false << true;
|
||||
QTest::newRow("pointer/keyboard") << true << true << false;
|
||||
QTest::newRow("pointer/touch") << true << false << true;
|
||||
QTest::newRow("keyboard/touch") << false << true << true;
|
||||
QTest::newRow("all") << true << true << true;
|
||||
}
|
||||
|
||||
void TestWaylandSeat::testCapabilities()
|
||||
{
|
||||
QVERIFY(!m_seat->hasPointer());
|
||||
QVERIFY(!m_seat->hasKeyboard());
|
||||
QVERIFY(!m_seat->hasTouch());
|
||||
|
||||
QFETCH(bool, pointer);
|
||||
QFETCH(bool, keyboard);
|
||||
QFETCH(bool, touch);
|
||||
|
||||
QSignalSpy pointerSpy(m_seat, SIGNAL(hasPointerChanged(bool)));
|
||||
QVERIFY(pointerSpy.isValid());
|
||||
QSignalSpy keyboardSpy(m_seat, SIGNAL(hasKeyboardChanged(bool)));
|
||||
QVERIFY(keyboardSpy.isValid());
|
||||
QSignalSpy touchSpy(m_seat, SIGNAL(hasTouchChanged(bool)));
|
||||
QVERIFY(touchSpy.isValid());
|
||||
|
||||
m_seatInterface->setHasPointer(pointer);
|
||||
m_seatInterface->setHasKeyboard(keyboard);
|
||||
m_seatInterface->setHasTouch(touch);
|
||||
|
||||
// do processing
|
||||
QCOMPARE(pointerSpy.wait(1000), pointer);
|
||||
QCOMPARE(pointerSpy.isEmpty(), !pointer);
|
||||
if (!pointerSpy.isEmpty()) {
|
||||
QCOMPARE(pointerSpy.first().first().toBool(), pointer);
|
||||
}
|
||||
|
||||
if (keyboardSpy.isEmpty()) {
|
||||
QCOMPARE(keyboardSpy.wait(1000), keyboard);
|
||||
}
|
||||
QCOMPARE(keyboardSpy.isEmpty(), !keyboard);
|
||||
if (!keyboardSpy.isEmpty()) {
|
||||
QCOMPARE(keyboardSpy.first().first().toBool(), keyboard);
|
||||
}
|
||||
|
||||
if (touchSpy.isEmpty()) {
|
||||
QCOMPARE(touchSpy.wait(1000), touch);
|
||||
}
|
||||
QCOMPARE(touchSpy.isEmpty(), !touch);
|
||||
if (!touchSpy.isEmpty()) {
|
||||
QCOMPARE(touchSpy.first().first().toBool(), touch);
|
||||
}
|
||||
|
||||
QCOMPARE(m_seat->hasPointer(), pointer);
|
||||
QCOMPARE(m_seat->hasKeyboard(), keyboard);
|
||||
QCOMPARE(m_seat->hasTouch(), touch);
|
||||
}
|
||||
|
||||
void TestWaylandSeat::testPointer()
|
||||
{
|
||||
using namespace KWin::Wayland;
|
||||
using namespace KWin::WaylandServer;
|
||||
|
||||
QSignalSpy pointerSpy(m_seat, SIGNAL(hasPointerChanged(bool)));
|
||||
QVERIFY(pointerSpy.isValid());
|
||||
m_seatInterface->setHasPointer(true);
|
||||
QVERIFY(pointerSpy.wait());
|
||||
|
||||
QSignalSpy surfaceCreatedSpy(m_compositorInterface, SIGNAL(surfaceCreated(KWin::WaylandServer::SurfaceInterface*)));
|
||||
QVERIFY(surfaceCreatedSpy.isValid());
|
||||
Surface *s = m_compositor->createSurface(m_compositor);
|
||||
QVERIFY(surfaceCreatedSpy.wait());
|
||||
SurfaceInterface *serverSurface = surfaceCreatedSpy.first().first().value<KWin::WaylandServer::SurfaceInterface*>();
|
||||
QVERIFY(serverSurface);
|
||||
|
||||
PointerInterface *serverPointer = m_seatInterface->pointer();
|
||||
serverPointer->setGlobalPos(QPoint(20, 18));
|
||||
serverPointer->setFocusedSurface(serverSurface, QPoint(10, 15));
|
||||
// no pointer yet - won't be set
|
||||
QVERIFY(!serverPointer->focusedSurface());
|
||||
|
||||
Pointer *p = m_seat->createPointer(m_seat);
|
||||
wl_display_flush(m_connection->display());
|
||||
QTest::qWait(100);
|
||||
|
||||
QSignalSpy enteredSpy(p, SIGNAL(entered(quint32,QPointF)));
|
||||
QVERIFY(enteredSpy.isValid());
|
||||
|
||||
QSignalSpy leftSpy(p, SIGNAL(left(quint32)));
|
||||
QVERIFY(leftSpy.isValid());
|
||||
|
||||
QSignalSpy motionSpy(p, SIGNAL(motion(QPointF,quint32)));
|
||||
QVERIFY(motionSpy.isValid());
|
||||
|
||||
QSignalSpy axisSpy(p, SIGNAL(axisChanged(quint32,KWin::Wayland::Pointer::Axis,qreal)));
|
||||
QVERIFY(axisSpy.isValid());
|
||||
|
||||
QSignalSpy buttonSpy(p, SIGNAL(buttonStateChanged(quint32,quint32,quint32,KWin::Wayland::Pointer::ButtonState)));
|
||||
QVERIFY(buttonSpy.isValid());
|
||||
|
||||
serverPointer->setFocusedSurface(serverSurface, QPoint(10, 15));
|
||||
QCOMPARE(serverPointer->focusedSurface(), serverSurface);
|
||||
QVERIFY(enteredSpy.wait());
|
||||
QCOMPARE(enteredSpy.first().first().value<quint32>(), m_display->serial());
|
||||
QCOMPARE(enteredSpy.first().last().toPoint(), QPoint(10, 3));
|
||||
|
||||
// test motion
|
||||
serverPointer->updateTimestamp(1);
|
||||
serverPointer->setGlobalPos(QPoint(10, 16));
|
||||
QVERIFY(motionSpy.wait());
|
||||
QCOMPARE(motionSpy.first().first().toPoint(), QPoint(0, 1));
|
||||
QCOMPARE(motionSpy.first().last().value<quint32>(), quint32(1));
|
||||
|
||||
// test axis
|
||||
serverPointer->updateTimestamp(2);
|
||||
serverPointer->axis(Qt::Horizontal, 10);
|
||||
QVERIFY(axisSpy.wait());
|
||||
serverPointer->updateTimestamp(3);
|
||||
serverPointer->axis(Qt::Vertical, 20);
|
||||
QVERIFY(axisSpy.wait());
|
||||
QCOMPARE(axisSpy.first().at(0).value<quint32>(), quint32(2));
|
||||
QCOMPARE(axisSpy.first().at(1).value<Pointer::Axis>(), Pointer::Axis::Horizontal);
|
||||
QCOMPARE(axisSpy.first().at(2).value<qreal>(), qreal(10));
|
||||
|
||||
QCOMPARE(axisSpy.last().at(0).value<quint32>(), quint32(3));
|
||||
QCOMPARE(axisSpy.last().at(1).value<Pointer::Axis>(), Pointer::Axis::Vertical);
|
||||
QCOMPARE(axisSpy.last().at(2).value<qreal>(), qreal(20));
|
||||
|
||||
// test button
|
||||
serverPointer->updateTimestamp(4);
|
||||
serverPointer->buttonPressed(1);
|
||||
QVERIFY(buttonSpy.wait());
|
||||
QCOMPARE(buttonSpy.at(0).at(0).value<quint32>(), m_display->serial());
|
||||
serverPointer->updateTimestamp(5);
|
||||
serverPointer->buttonPressed(2);
|
||||
QVERIFY(buttonSpy.wait());
|
||||
QCOMPARE(buttonSpy.at(1).at(0).value<quint32>(), m_display->serial());
|
||||
serverPointer->updateTimestamp(6);
|
||||
serverPointer->buttonReleased(2);
|
||||
QVERIFY(buttonSpy.wait());
|
||||
QCOMPARE(buttonSpy.at(2).at(0).value<quint32>(), m_display->serial());
|
||||
serverPointer->updateTimestamp(7);
|
||||
serverPointer->buttonReleased(1);
|
||||
QVERIFY(buttonSpy.wait());
|
||||
QCOMPARE(buttonSpy.count(), 4);
|
||||
|
||||
// timestamp
|
||||
QCOMPARE(buttonSpy.at(0).at(1).value<quint32>(), quint32(4));
|
||||
// button
|
||||
QCOMPARE(buttonSpy.at(0).at(2).value<quint32>(), quint32(1));
|
||||
QCOMPARE(buttonSpy.at(0).at(3).value<KWin::Wayland::Pointer::ButtonState>(), KWin::Wayland::Pointer::ButtonState::Pressed);
|
||||
|
||||
// timestamp
|
||||
QCOMPARE(buttonSpy.at(1).at(1).value<quint32>(), quint32(5));
|
||||
// button
|
||||
QCOMPARE(buttonSpy.at(1).at(2).value<quint32>(), quint32(2));
|
||||
QCOMPARE(buttonSpy.at(1).at(3).value<KWin::Wayland::Pointer::ButtonState>(), KWin::Wayland::Pointer::ButtonState::Pressed);
|
||||
|
||||
QCOMPARE(buttonSpy.at(2).at(0).value<quint32>(), serverPointer->buttonSerial(2));
|
||||
// timestamp
|
||||
QCOMPARE(buttonSpy.at(2).at(1).value<quint32>(), quint32(6));
|
||||
// button
|
||||
QCOMPARE(buttonSpy.at(2).at(2).value<quint32>(), quint32(2));
|
||||
QCOMPARE(buttonSpy.at(2).at(3).value<KWin::Wayland::Pointer::ButtonState>(), KWin::Wayland::Pointer::ButtonState::Released);
|
||||
|
||||
QCOMPARE(buttonSpy.at(3).at(0).value<quint32>(), serverPointer->buttonSerial(1));
|
||||
// timestamp
|
||||
QCOMPARE(buttonSpy.at(3).at(1).value<quint32>(), quint32(7));
|
||||
// button
|
||||
QCOMPARE(buttonSpy.at(3).at(2).value<quint32>(), quint32(1));
|
||||
QCOMPARE(buttonSpy.at(3).at(3).value<KWin::Wayland::Pointer::ButtonState>(), KWin::Wayland::Pointer::ButtonState::Released);
|
||||
|
||||
// leave the surface
|
||||
serverPointer->setFocusedSurface(nullptr);
|
||||
QVERIFY(leftSpy.wait());
|
||||
QCOMPARE(leftSpy.first().first().value<quint32>(), m_display->serial());
|
||||
|
||||
// enter it again
|
||||
serverPointer->setFocusedSurface(serverSurface, QPoint(0, 0));
|
||||
QVERIFY(enteredSpy.wait());
|
||||
|
||||
delete s;
|
||||
wl_display_flush(m_connection->display());
|
||||
QTest::qWait(100);
|
||||
QVERIFY(!serverPointer->focusedSurface());
|
||||
}
|
||||
|
||||
void TestWaylandSeat::testKeyboard()
|
||||
{
|
||||
using namespace KWin::Wayland;
|
||||
using namespace KWin::WaylandServer;
|
||||
|
||||
QSignalSpy keyboardSpy(m_seat, SIGNAL(hasKeyboardChanged(bool)));
|
||||
QVERIFY(keyboardSpy.isValid());
|
||||
m_seatInterface->setHasKeyboard(true);
|
||||
QVERIFY(keyboardSpy.wait());
|
||||
|
||||
// create the surface
|
||||
QSignalSpy surfaceCreatedSpy(m_compositorInterface, SIGNAL(surfaceCreated(KWin::WaylandServer::SurfaceInterface*)));
|
||||
QVERIFY(surfaceCreatedSpy.isValid());
|
||||
Surface *s = m_compositor->createSurface(m_compositor);
|
||||
QVERIFY(surfaceCreatedSpy.wait());
|
||||
SurfaceInterface *serverSurface = surfaceCreatedSpy.first().first().value<KWin::WaylandServer::SurfaceInterface*>();
|
||||
QVERIFY(serverSurface);
|
||||
|
||||
KeyboardInterface *serverKeyboard = m_seatInterface->keyboard();
|
||||
|
||||
serverKeyboard->setFocusedSurface(serverSurface);
|
||||
// no pointer yet - won't be set
|
||||
QVERIFY(!serverKeyboard->focusedSurface());
|
||||
|
||||
Keyboard *keyboard = m_seat->createKeyboard();
|
||||
QVERIFY(keyboard->isValid());
|
||||
wl_display_flush(m_connection->display());
|
||||
QTest::qWait(100);
|
||||
|
||||
serverKeyboard->updateTimestamp(1);
|
||||
serverKeyboard->keyPressed(KEY_K);
|
||||
serverKeyboard->updateTimestamp(2);
|
||||
serverKeyboard->keyPressed(KEY_D);
|
||||
serverKeyboard->updateTimestamp(3);
|
||||
serverKeyboard->keyPressed(KEY_E);
|
||||
|
||||
QSignalSpy modifierSpy(keyboard, SIGNAL(modifiersChanged(quint32,quint32,quint32,quint32)));
|
||||
QVERIFY(modifierSpy.isValid());
|
||||
|
||||
// TODO: add a signalspy for enter
|
||||
serverKeyboard->setFocusedSurface(serverSurface);
|
||||
QCOMPARE(serverKeyboard->focusedSurface(), serverSurface);
|
||||
|
||||
// we get the modifiers sent after the enter
|
||||
QVERIFY(modifierSpy.wait());
|
||||
QCOMPARE(modifierSpy.count(), 1);
|
||||
QCOMPARE(modifierSpy.first().at(0).value<quint32>(), quint32(0));
|
||||
QCOMPARE(modifierSpy.first().at(1).value<quint32>(), quint32(0));
|
||||
QCOMPARE(modifierSpy.first().at(2).value<quint32>(), quint32(0));
|
||||
QCOMPARE(modifierSpy.first().at(3).value<quint32>(), quint32(0));
|
||||
|
||||
QSignalSpy keyChangedSpy(keyboard, SIGNAL(keyChanged(quint32,KWin::Wayland::Keyboard::KeyState,quint32)));
|
||||
QVERIFY(keyChangedSpy.isValid());
|
||||
|
||||
serverKeyboard->updateTimestamp(4);
|
||||
serverKeyboard->keyReleased(KEY_E);
|
||||
QVERIFY(keyChangedSpy.wait());
|
||||
serverKeyboard->updateTimestamp(5);
|
||||
serverKeyboard->keyReleased(KEY_D);
|
||||
QVERIFY(keyChangedSpy.wait());
|
||||
serverKeyboard->updateTimestamp(6);
|
||||
serverKeyboard->keyReleased(KEY_K);
|
||||
QVERIFY(keyChangedSpy.wait());
|
||||
serverKeyboard->updateTimestamp(7);
|
||||
serverKeyboard->keyPressed(KEY_F1);
|
||||
QVERIFY(keyChangedSpy.wait());
|
||||
serverKeyboard->updateTimestamp(8);
|
||||
serverKeyboard->keyReleased(KEY_F1);
|
||||
QVERIFY(keyChangedSpy.wait());
|
||||
|
||||
QCOMPARE(keyChangedSpy.count(), 5);
|
||||
QCOMPARE(keyChangedSpy.at(0).at(0).value<quint32>(), quint32(KEY_E));
|
||||
QCOMPARE(keyChangedSpy.at(0).at(1).value<Keyboard::KeyState>(), Keyboard::KeyState::Released);
|
||||
QCOMPARE(keyChangedSpy.at(0).at(2).value<quint32>(), quint32(4));
|
||||
QCOMPARE(keyChangedSpy.at(1).at(0).value<quint32>(), quint32(KEY_D));
|
||||
QCOMPARE(keyChangedSpy.at(1).at(1).value<Keyboard::KeyState>(), Keyboard::KeyState::Released);
|
||||
QCOMPARE(keyChangedSpy.at(1).at(2).value<quint32>(), quint32(5));
|
||||
QCOMPARE(keyChangedSpy.at(2).at(0).value<quint32>(), quint32(KEY_K));
|
||||
QCOMPARE(keyChangedSpy.at(2).at(1).value<Keyboard::KeyState>(), Keyboard::KeyState::Released);
|
||||
QCOMPARE(keyChangedSpy.at(2).at(2).value<quint32>(), quint32(6));
|
||||
QCOMPARE(keyChangedSpy.at(3).at(0).value<quint32>(), quint32(KEY_F1));
|
||||
QCOMPARE(keyChangedSpy.at(3).at(1).value<Keyboard::KeyState>(), Keyboard::KeyState::Pressed);
|
||||
QCOMPARE(keyChangedSpy.at(3).at(2).value<quint32>(), quint32(7));
|
||||
QCOMPARE(keyChangedSpy.at(4).at(0).value<quint32>(), quint32(KEY_F1));
|
||||
QCOMPARE(keyChangedSpy.at(4).at(1).value<Keyboard::KeyState>(), Keyboard::KeyState::Released);
|
||||
QCOMPARE(keyChangedSpy.at(4).at(2).value<quint32>(), quint32(8));
|
||||
|
||||
serverKeyboard->updateModifiers(1, 2, 3, 4);
|
||||
QVERIFY(modifierSpy.wait());
|
||||
QCOMPARE(modifierSpy.count(), 2);
|
||||
QCOMPARE(modifierSpy.last().at(0).value<quint32>(), quint32(1));
|
||||
QCOMPARE(modifierSpy.last().at(1).value<quint32>(), quint32(2));
|
||||
QCOMPARE(modifierSpy.last().at(2).value<quint32>(), quint32(3));
|
||||
QCOMPARE(modifierSpy.last().at(3).value<quint32>(), quint32(4));
|
||||
|
||||
// TODO: add a test for leave signal
|
||||
serverKeyboard->setFocusedSurface(nullptr);
|
||||
QVERIFY(!serverKeyboard->focusedSurface());
|
||||
|
||||
// enter it again
|
||||
serverKeyboard->setFocusedSurface(serverSurface);
|
||||
QVERIFY(modifierSpy.wait());
|
||||
QCOMPARE(serverKeyboard->focusedSurface(), serverSurface);
|
||||
|
||||
delete s;
|
||||
wl_display_flush(m_connection->display());
|
||||
QTest::qWait(100);
|
||||
QVERIFY(!serverKeyboard->focusedSurface());
|
||||
}
|
||||
|
||||
QTEST_MAIN(TestWaylandSeat)
|
||||
#include "test_wayland_seat.moc"
|
|
@ -7,6 +7,7 @@ set( testWaylandServerDisplay_SRCS
|
|||
${KWIN_SOURCE_DIR}/wayland_server/compositor_interface.cpp
|
||||
${KWIN_SOURCE_DIR}/wayland_server/display.cpp
|
||||
${KWIN_SOURCE_DIR}/wayland_server/output_interface.cpp
|
||||
${KWIN_SOURCE_DIR}/wayland_server/seat_interface.cpp
|
||||
${KWIN_SOURCE_DIR}/wayland_server/shell_interface.cpp
|
||||
${KWIN_SOURCE_DIR}/wayland_server/surface_interface.cpp
|
||||
)
|
||||
|
@ -14,3 +15,21 @@ add_executable(testWaylandServerDisplay ${testWaylandServerDisplay_SRCS})
|
|||
target_link_libraries( testWaylandServerDisplay Qt5::Test Qt5::Gui Wayland::Server)
|
||||
add_test(kwin-testWaylandServerDisplay testWaylandServerDisplay)
|
||||
ecm_mark_as_test(testWaylandServerDisplay)
|
||||
|
||||
########################################################
|
||||
# Test WaylandServerSeat
|
||||
########################################################
|
||||
set( testWaylandServerSeat_SRCS
|
||||
test_seat.cpp
|
||||
${KWIN_SOURCE_DIR}/wayland_server/buffer_interface.cpp
|
||||
${KWIN_SOURCE_DIR}/wayland_server/compositor_interface.cpp
|
||||
${KWIN_SOURCE_DIR}/wayland_server/display.cpp
|
||||
${KWIN_SOURCE_DIR}/wayland_server/output_interface.cpp
|
||||
${KWIN_SOURCE_DIR}/wayland_server/seat_interface.cpp
|
||||
${KWIN_SOURCE_DIR}/wayland_server/shell_interface.cpp
|
||||
${KWIN_SOURCE_DIR}/wayland_server/surface_interface.cpp
|
||||
)
|
||||
add_executable(testWaylandServerSeat ${testWaylandServerSeat_SRCS})
|
||||
target_link_libraries( testWaylandServerSeat Qt5::Test Qt5::Gui Wayland::Server)
|
||||
add_test(kwin-testWaylandServerSeat testWaylandServerSeat)
|
||||
ecm_mark_as_test(testWaylandServerSeat)
|
||||
|
|
|
@ -0,0 +1,161 @@
|
|||
/********************************************************************
|
||||
KWin - the KDE window manager
|
||||
This file is part of the KDE project.
|
||||
|
||||
Copyright (C) 2014 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/>.
|
||||
*********************************************************************/
|
||||
// Qt
|
||||
#include <QtTest/QtTest>
|
||||
// WaylandServer
|
||||
#include "../../wayland_server/display.h"
|
||||
#include "../../wayland_server/seat_interface.h"
|
||||
|
||||
using namespace KWin::WaylandServer;
|
||||
|
||||
|
||||
class TestWaylandServerSeat : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
private Q_SLOTS:
|
||||
void testCapabilities();
|
||||
void testName();
|
||||
void testPointerButton();
|
||||
void testPointerPos();
|
||||
};
|
||||
|
||||
static const QString s_socketName = QStringLiteral("kwin-wayland-server-seat-test-0");
|
||||
|
||||
void TestWaylandServerSeat::testCapabilities()
|
||||
{
|
||||
Display display;
|
||||
display.setSocketName(s_socketName);
|
||||
display.start();
|
||||
SeatInterface *seat = display.createSeat();
|
||||
QVERIFY(!seat->hasKeyboard());
|
||||
QVERIFY(!seat->hasPointer());
|
||||
QVERIFY(!seat->hasTouch());
|
||||
|
||||
QSignalSpy keyboardSpy(seat, SIGNAL(hasKeyboardChanged(bool)));
|
||||
QVERIFY(keyboardSpy.isValid());
|
||||
seat->setHasKeyboard(true);
|
||||
QCOMPARE(keyboardSpy.count(), 1);
|
||||
QVERIFY(keyboardSpy.last().first().toBool());
|
||||
QVERIFY(seat->hasKeyboard());
|
||||
seat->setHasKeyboard(false);
|
||||
QCOMPARE(keyboardSpy.count(), 2);
|
||||
QVERIFY(!keyboardSpy.last().first().toBool());
|
||||
QVERIFY(!seat->hasKeyboard());
|
||||
seat->setHasKeyboard(false);
|
||||
QCOMPARE(keyboardSpy.count(), 2);
|
||||
|
||||
QSignalSpy pointerSpy(seat, SIGNAL(hasPointerChanged(bool)));
|
||||
QVERIFY(pointerSpy.isValid());
|
||||
seat->setHasPointer(true);
|
||||
QCOMPARE(pointerSpy.count(), 1);
|
||||
QVERIFY(pointerSpy.last().first().toBool());
|
||||
QVERIFY(seat->hasPointer());
|
||||
seat->setHasPointer(false);
|
||||
QCOMPARE(pointerSpy.count(), 2);
|
||||
QVERIFY(!pointerSpy.last().first().toBool());
|
||||
QVERIFY(!seat->hasPointer());
|
||||
seat->setHasPointer(false);
|
||||
QCOMPARE(pointerSpy.count(), 2);
|
||||
|
||||
QSignalSpy touchSpy(seat, SIGNAL(hasTouchChanged(bool)));
|
||||
QVERIFY(touchSpy.isValid());
|
||||
seat->setHasTouch(true);
|
||||
QCOMPARE(touchSpy.count(), 1);
|
||||
QVERIFY(touchSpy.last().first().toBool());
|
||||
QVERIFY(seat->hasTouch());
|
||||
seat->setHasTouch(false);
|
||||
QCOMPARE(touchSpy.count(), 2);
|
||||
QVERIFY(!touchSpy.last().first().toBool());
|
||||
QVERIFY(!seat->hasTouch());
|
||||
seat->setHasTouch(false);
|
||||
QCOMPARE(touchSpy.count(), 2);
|
||||
}
|
||||
|
||||
void TestWaylandServerSeat::testName()
|
||||
{
|
||||
Display display;
|
||||
display.setSocketName(s_socketName);
|
||||
display.start();
|
||||
SeatInterface *seat = display.createSeat();
|
||||
QCOMPARE(seat->name(), QString());
|
||||
|
||||
QSignalSpy nameSpy(seat, SIGNAL(nameChanged(QString)));
|
||||
QVERIFY(nameSpy.isValid());
|
||||
const QString name = QStringLiteral("foobar");
|
||||
seat->setName(name);
|
||||
QCOMPARE(seat->name(), name);
|
||||
QCOMPARE(nameSpy.count(), 1);
|
||||
QCOMPARE(nameSpy.first().first().toString(), name);
|
||||
seat->setName(name);
|
||||
QCOMPARE(nameSpy.count(), 1);
|
||||
}
|
||||
|
||||
void TestWaylandServerSeat::testPointerButton()
|
||||
{
|
||||
Display display;
|
||||
display.setSocketName(s_socketName);
|
||||
display.start();
|
||||
SeatInterface *seat = display.createSeat();
|
||||
PointerInterface *pointer = seat->pointer();
|
||||
|
||||
// no button pressed yet, should be released and no serial
|
||||
QVERIFY(!pointer->isButtonPressed(0));
|
||||
QVERIFY(!pointer->isButtonPressed(1));
|
||||
QCOMPARE(pointer->buttonSerial(0), quint32(0));
|
||||
QCOMPARE(pointer->buttonSerial(1), quint32(0));
|
||||
|
||||
// mark the button as pressed
|
||||
pointer->buttonPressed(0);
|
||||
QVERIFY(pointer->isButtonPressed(0));
|
||||
QCOMPARE(pointer->buttonSerial(0), display.serial());
|
||||
|
||||
// other button should still be unpressed
|
||||
QVERIFY(!pointer->isButtonPressed(1));
|
||||
QCOMPARE(pointer->buttonSerial(1), quint32(0));
|
||||
|
||||
// release it again
|
||||
pointer->buttonReleased(0);
|
||||
QVERIFY(!pointer->isButtonPressed(0));
|
||||
QCOMPARE(pointer->buttonSerial(0), display.serial());
|
||||
}
|
||||
|
||||
void TestWaylandServerSeat::testPointerPos()
|
||||
{
|
||||
Display display;
|
||||
display.setSocketName(s_socketName);
|
||||
display.start();
|
||||
SeatInterface *seat = display.createSeat();
|
||||
PointerInterface *pointer = seat->pointer();
|
||||
QSignalSpy posSpy(pointer, SIGNAL(globalPosChanged(QPoint)));
|
||||
QVERIFY(posSpy.isValid());
|
||||
|
||||
QCOMPARE(pointer->globalPos(), QPoint());
|
||||
|
||||
pointer->setGlobalPos(QPoint(10, 15));
|
||||
QCOMPARE(pointer->globalPos(), QPoint(10, 15));
|
||||
QCOMPARE(posSpy.count(), 1);
|
||||
QCOMPARE(posSpy.first().first().toPoint(), QPoint(10, 15));
|
||||
|
||||
pointer->setGlobalPos(QPoint(10, 15));
|
||||
QCOMPARE(posSpy.count(), 1);
|
||||
}
|
||||
|
||||
QTEST_MAIN(TestWaylandServerSeat)
|
||||
#include "test_seat.moc"
|
|
@ -20,6 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
#include "display.h"
|
||||
#include "compositor_interface.h"
|
||||
#include "output_interface.h"
|
||||
#include "seat_interface.h"
|
||||
#include "shell_interface.h"
|
||||
|
||||
#include <QCoreApplication>
|
||||
|
@ -139,6 +140,13 @@ ShellInterface *Display::createShell(QObject *parent)
|
|||
return shell;
|
||||
}
|
||||
|
||||
SeatInterface *Display::createSeat(QObject *parent)
|
||||
{
|
||||
SeatInterface *seat = new SeatInterface(this, parent);
|
||||
connect(this, &Display::aboutToTerminate, seat, [this,seat] { delete seat; });
|
||||
return seat;
|
||||
}
|
||||
|
||||
void Display::createShm()
|
||||
{
|
||||
Q_ASSERT(m_running);
|
||||
|
|
|
@ -33,6 +33,7 @@ namespace WaylandServer
|
|||
|
||||
class CompositorInterface;
|
||||
class OutputInterface;
|
||||
class SeatInterface;
|
||||
class ShellInterface;
|
||||
|
||||
class Display : public QObject
|
||||
|
@ -72,6 +73,7 @@ public:
|
|||
CompositorInterface *createCompositor(QObject *parent = nullptr);
|
||||
void createShm();
|
||||
ShellInterface *createShell(QObject *parent = nullptr);
|
||||
SeatInterface *createSeat(QObject *parent = nullptr);
|
||||
|
||||
Q_SIGNALS:
|
||||
void socketNameChanged(const QString&);
|
||||
|
|
|
@ -0,0 +1,601 @@
|
|||
/********************************************************************
|
||||
KWin - the KDE window manager
|
||||
This file is part of the KDE project.
|
||||
|
||||
Copyright (C) 2014 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 "seat_interface.h"
|
||||
#include "display.h"
|
||||
#include "surface_interface.h"
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
namespace KWin
|
||||
{
|
||||
|
||||
namespace WaylandServer
|
||||
{
|
||||
|
||||
static const quint32 s_version = 3;
|
||||
|
||||
const struct wl_seat_interface SeatInterface::s_interface = {
|
||||
SeatInterface::getPointerCallback,
|
||||
SeatInterface::getKeyboardCallback,
|
||||
SeatInterface::getTouchCallback
|
||||
};
|
||||
|
||||
SeatInterface::SeatInterface(Display *display, QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_display(display)
|
||||
, m_seat(nullptr)
|
||||
, m_name()
|
||||
, m_pointer(false)
|
||||
, m_keyboard(false)
|
||||
, m_touch(false)
|
||||
, m_pointerInterface(new PointerInterface(display, this))
|
||||
, m_keyboardInterface(new KeyboardInterface(display, this))
|
||||
{
|
||||
connect(this, &SeatInterface::nameChanged, this,
|
||||
[this] {
|
||||
for (auto it = m_resources.constBegin(); it != m_resources.constEnd(); ++it) {
|
||||
sendName(*it);
|
||||
}
|
||||
}
|
||||
);
|
||||
auto sendCapabilitiesAll = [this] {
|
||||
for (auto it = m_resources.constBegin(); it != m_resources.constEnd(); ++it) {
|
||||
sendCapabilities(*it);
|
||||
}
|
||||
};
|
||||
connect(this, &SeatInterface::hasPointerChanged, this, sendCapabilitiesAll);
|
||||
connect(this, &SeatInterface::hasKeyboardChanged, this, sendCapabilitiesAll);
|
||||
connect(this, &SeatInterface::hasTouchChanged, this, sendCapabilitiesAll);
|
||||
}
|
||||
|
||||
SeatInterface::~SeatInterface()
|
||||
{
|
||||
destroy();
|
||||
}
|
||||
|
||||
void SeatInterface::create()
|
||||
{
|
||||
Q_ASSERT(!m_seat);
|
||||
m_seat = wl_global_create(*m_display, &wl_seat_interface, s_version, this, &SeatInterface::bind);
|
||||
}
|
||||
|
||||
void SeatInterface::destroy()
|
||||
{
|
||||
while (!m_resources.isEmpty()) {
|
||||
wl_resource_destroy(m_resources.takeLast());
|
||||
}
|
||||
if (m_seat) {
|
||||
wl_global_destroy(m_seat);
|
||||
m_seat = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void SeatInterface::bind(wl_client *client, void *data, uint32_t version, uint32_t id)
|
||||
{
|
||||
reinterpret_cast<SeatInterface*>(data)->bind(client, version, id);
|
||||
}
|
||||
|
||||
void SeatInterface::bind(wl_client *client, uint32_t version, uint32_t id)
|
||||
{
|
||||
wl_resource *r = wl_resource_create(client, &wl_seat_interface, qMin(s_version, version), id);
|
||||
if (!r) {
|
||||
wl_client_post_no_memory(client);
|
||||
return;
|
||||
}
|
||||
m_resources << r;
|
||||
|
||||
wl_resource_set_implementation(r, &SeatInterface::s_interface, this, SeatInterface::unbind);
|
||||
|
||||
sendCapabilities(r);
|
||||
sendName(r);
|
||||
}
|
||||
|
||||
void SeatInterface::unbind(wl_resource *r)
|
||||
{
|
||||
SeatInterface::cast(r)->m_resources.removeAll(r);
|
||||
}
|
||||
|
||||
void SeatInterface::sendName(wl_resource *r)
|
||||
{
|
||||
if (wl_resource_get_version(r) < WL_SEAT_NAME_SINCE_VERSION) {
|
||||
return;
|
||||
}
|
||||
wl_seat_send_name(r, m_name.toUtf8().constData());
|
||||
}
|
||||
|
||||
void SeatInterface::sendCapabilities(wl_resource *r)
|
||||
{
|
||||
uint32_t capabilities = 0;
|
||||
if (m_pointer) {
|
||||
capabilities |= WL_SEAT_CAPABILITY_POINTER;
|
||||
}
|
||||
if (m_keyboard) {
|
||||
capabilities |= WL_SEAT_CAPABILITY_KEYBOARD;
|
||||
}
|
||||
if (m_touch) {
|
||||
capabilities |= WL_SEAT_CAPABILITY_TOUCH;
|
||||
}
|
||||
wl_seat_send_capabilities(r, capabilities);
|
||||
}
|
||||
|
||||
SeatInterface *SeatInterface::cast(wl_resource *r)
|
||||
{
|
||||
return reinterpret_cast<SeatInterface*>(wl_resource_get_user_data(r));
|
||||
}
|
||||
|
||||
void SeatInterface::setHasKeyboard(bool has)
|
||||
{
|
||||
if (m_keyboard == has) {
|
||||
return;
|
||||
}
|
||||
m_keyboard = has;
|
||||
emit hasKeyboardChanged(m_keyboard);
|
||||
}
|
||||
|
||||
void SeatInterface::setHasPointer(bool has)
|
||||
{
|
||||
if (m_pointer == has) {
|
||||
return;
|
||||
}
|
||||
m_pointer = has;
|
||||
emit hasPointerChanged(m_pointer);
|
||||
}
|
||||
|
||||
void SeatInterface::setHasTouch(bool has)
|
||||
{
|
||||
if (m_touch == has) {
|
||||
return;
|
||||
}
|
||||
m_touch = has;
|
||||
emit hasTouchChanged(m_touch);
|
||||
}
|
||||
|
||||
void SeatInterface::setName(const QString &name)
|
||||
{
|
||||
if (m_name == name) {
|
||||
return;
|
||||
}
|
||||
m_name = name;
|
||||
emit nameChanged(m_name);
|
||||
}
|
||||
|
||||
void SeatInterface::getPointerCallback(wl_client *client, wl_resource *resource, uint32_t id)
|
||||
{
|
||||
SeatInterface::cast(resource)->m_pointerInterface->createInterface(client, resource, id);
|
||||
}
|
||||
|
||||
void SeatInterface::getKeyboardCallback(wl_client *client, wl_resource *resource, uint32_t id)
|
||||
{
|
||||
SeatInterface::cast(resource)->m_keyboardInterface->createInterfae(client, resource, id);
|
||||
}
|
||||
|
||||
void SeatInterface::getTouchCallback(wl_client *client, wl_resource *resource, uint32_t id)
|
||||
{
|
||||
Q_UNUSED(client)
|
||||
Q_UNUSED(resource)
|
||||
Q_UNUSED(id)
|
||||
}
|
||||
|
||||
/****************************************
|
||||
* PointerInterface
|
||||
***************************************/
|
||||
|
||||
const struct wl_pointer_interface PointerInterface::s_interface = {
|
||||
PointerInterface::setCursorCallback,
|
||||
PointerInterface::releaseCallback
|
||||
};
|
||||
|
||||
PointerInterface::PointerInterface(Display *display, SeatInterface *parent)
|
||||
: QObject(parent)
|
||||
, m_display(display)
|
||||
, m_seat(parent)
|
||||
, m_eventTime(0)
|
||||
{
|
||||
}
|
||||
|
||||
PointerInterface::~PointerInterface()
|
||||
{
|
||||
while (!m_resources.isEmpty()) {
|
||||
ResourceData data = m_resources.takeLast();
|
||||
wl_resource_destroy(data.pointer);
|
||||
}
|
||||
}
|
||||
|
||||
void PointerInterface::createInterface(wl_client *client, wl_resource *parentResource, uint32_t id)
|
||||
{
|
||||
wl_resource *p = wl_resource_create(client, &wl_pointer_interface, wl_resource_get_version(parentResource), id);
|
||||
if (!p) {
|
||||
wl_resource_post_no_memory(parentResource);
|
||||
return;
|
||||
}
|
||||
ResourceData data;
|
||||
data.client = client;
|
||||
data.pointer = p;
|
||||
m_resources << data;
|
||||
|
||||
wl_resource_set_implementation(p, &PointerInterface::s_interface, this, PointerInterface::unbind);
|
||||
}
|
||||
|
||||
wl_resource *PointerInterface::pointerForSurface(SurfaceInterface *surface) const
|
||||
{
|
||||
if (!surface) {
|
||||
return nullptr;
|
||||
}
|
||||
for (auto it = m_resources.constBegin(); it != m_resources.constEnd(); ++it) {
|
||||
if ((*it).client == surface->client()) {
|
||||
return (*it).pointer;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void PointerInterface::setFocusedSurface(SurfaceInterface *surface, const QPoint &surfacePosition)
|
||||
{
|
||||
const quint32 serial = m_display->nextSerial();
|
||||
if (m_focusedSurface.surface && m_focusedSurface.pointer) {
|
||||
wl_pointer_send_leave(m_focusedSurface.pointer, serial, m_focusedSurface.surface->surface());
|
||||
disconnect(m_focusedSurface.surface, &QObject::destroyed, this, &PointerInterface::surfaceDeleted);
|
||||
}
|
||||
m_focusedSurface.pointer = pointerForSurface(surface);
|
||||
if (!m_focusedSurface.pointer) {
|
||||
m_focusedSurface = FocusedSurface();
|
||||
return;
|
||||
}
|
||||
m_focusedSurface.surface = surface;
|
||||
m_focusedSurface.offset = surfacePosition;
|
||||
m_focusedSurface.serial = serial;
|
||||
connect(m_focusedSurface.surface, &QObject::destroyed, this, &PointerInterface::surfaceDeleted);
|
||||
|
||||
const QPoint pos = m_globalPos - surfacePosition;
|
||||
wl_pointer_send_enter(m_focusedSurface.pointer, m_focusedSurface.serial,
|
||||
m_focusedSurface.surface->surface(),
|
||||
wl_fixed_from_int(pos.x()), wl_fixed_from_int(pos.y()));
|
||||
}
|
||||
|
||||
void PointerInterface::surfaceDeleted()
|
||||
{
|
||||
m_focusedSurface = FocusedSurface();
|
||||
}
|
||||
|
||||
void PointerInterface::setFocusedSurfacePosition(const QPoint &surfacePosition)
|
||||
{
|
||||
if (!m_focusedSurface.surface) {
|
||||
return;
|
||||
}
|
||||
m_focusedSurface.offset = surfacePosition;
|
||||
}
|
||||
|
||||
void PointerInterface::setGlobalPos(const QPoint &pos)
|
||||
{
|
||||
if (m_globalPos == pos) {
|
||||
return;
|
||||
}
|
||||
m_globalPos = pos;
|
||||
if (m_focusedSurface.surface && m_focusedSurface.pointer) {
|
||||
const QPoint pos = m_globalPos - m_focusedSurface.offset;
|
||||
wl_pointer_send_motion(m_focusedSurface.pointer, m_eventTime,
|
||||
wl_fixed_from_int(pos.x()), wl_fixed_from_int(pos.y()));
|
||||
}
|
||||
emit globalPosChanged(m_globalPos);
|
||||
}
|
||||
|
||||
void PointerInterface::updateTimestamp(quint32 time)
|
||||
{
|
||||
m_eventTime = time;
|
||||
}
|
||||
|
||||
void PointerInterface::buttonPressed(quint32 button)
|
||||
{
|
||||
const quint32 serial = m_display->nextSerial();
|
||||
updateButtonSerial(button, serial);
|
||||
updateButtonState(button, ButtonState::Pressed);
|
||||
if (!m_focusedSurface.surface || !m_focusedSurface.pointer) {
|
||||
return;
|
||||
}
|
||||
wl_pointer_send_button(m_focusedSurface.pointer, serial, m_eventTime, button, WL_POINTER_BUTTON_STATE_PRESSED);
|
||||
}
|
||||
|
||||
void PointerInterface::buttonReleased(quint32 button)
|
||||
{
|
||||
const quint32 serial = m_display->nextSerial();
|
||||
updateButtonSerial(button, serial);
|
||||
updateButtonState(button, ButtonState::Released);
|
||||
if (!m_focusedSurface.surface || !m_focusedSurface.pointer) {
|
||||
return;
|
||||
}
|
||||
wl_pointer_send_button(m_focusedSurface.pointer, serial, m_eventTime, button, WL_POINTER_BUTTON_STATE_RELEASED);
|
||||
}
|
||||
|
||||
void PointerInterface::updateButtonSerial(quint32 button, quint32 serial)
|
||||
{
|
||||
auto it = m_buttonSerials.find(button);
|
||||
if (it == m_buttonSerials.end()) {
|
||||
m_buttonSerials.insert(button, serial);
|
||||
return;
|
||||
}
|
||||
it.value() = serial;
|
||||
}
|
||||
|
||||
quint32 PointerInterface::buttonSerial(quint32 button) const
|
||||
{
|
||||
auto it = m_buttonSerials.constFind(button);
|
||||
if (it == m_buttonSerials.constEnd()) {
|
||||
return 0;
|
||||
}
|
||||
return it.value();
|
||||
}
|
||||
|
||||
void PointerInterface::updateButtonState(quint32 button, PointerInterface::ButtonState state)
|
||||
{
|
||||
auto it = m_buttonStates.find(button);
|
||||
if (it == m_buttonStates.end()) {
|
||||
m_buttonStates.insert(button, state);
|
||||
return;
|
||||
}
|
||||
it.value() = state;
|
||||
}
|
||||
|
||||
bool PointerInterface::isButtonPressed(quint32 button) const
|
||||
{
|
||||
auto it = m_buttonStates.constFind(button);
|
||||
if (it == m_buttonStates.constEnd()) {
|
||||
return false;
|
||||
}
|
||||
return it.value() == ButtonState::Pressed ? true : false;
|
||||
}
|
||||
|
||||
void PointerInterface::axis(Qt::Orientation orientation, quint32 delta)
|
||||
{
|
||||
if (!m_focusedSurface.surface || !m_focusedSurface.pointer) {
|
||||
return;
|
||||
}
|
||||
wl_pointer_send_axis(m_focusedSurface.pointer, m_eventTime,
|
||||
(orientation == Qt::Vertical) ? WL_POINTER_AXIS_VERTICAL_SCROLL : WL_POINTER_AXIS_HORIZONTAL_SCROLL,
|
||||
wl_fixed_from_int(delta));
|
||||
}
|
||||
|
||||
void PointerInterface::unbind(wl_resource *resource)
|
||||
{
|
||||
PointerInterface *p = PointerInterface::cast(resource);
|
||||
auto it = std::find_if(p->m_resources.begin(), p->m_resources.end(),
|
||||
[resource](const ResourceData &data) {
|
||||
return data.pointer == resource;
|
||||
}
|
||||
);
|
||||
if (it == p->m_resources.end()) {
|
||||
return;
|
||||
}
|
||||
if ((*it).pointer == p->m_focusedSurface.pointer) {
|
||||
disconnect(p->m_focusedSurface.surface, &QObject::destroyed, p, &PointerInterface::surfaceDeleted);
|
||||
p->m_focusedSurface = FocusedSurface();
|
||||
}
|
||||
p->m_resources.erase(it);
|
||||
}
|
||||
|
||||
void PointerInterface::setCursorCallback(wl_client *client, wl_resource *resource, uint32_t serial,
|
||||
wl_resource *surface, int32_t hotspot_x, int32_t hotspot_y)
|
||||
{
|
||||
Q_UNUSED(client)
|
||||
Q_UNUSED(resource)
|
||||
Q_UNUSED(serial)
|
||||
Q_UNUSED(surface)
|
||||
Q_UNUSED(hotspot_x)
|
||||
Q_UNUSED(hotspot_y)
|
||||
// TODO: implement
|
||||
}
|
||||
|
||||
void PointerInterface::releaseCallback(wl_client *client, wl_resource *resource)
|
||||
{
|
||||
Q_UNUSED(client)
|
||||
unbind(resource);
|
||||
}
|
||||
|
||||
/****************************************
|
||||
* KeyboardInterface
|
||||
***************************************/
|
||||
|
||||
const struct wl_keyboard_interface KeyboardInterface::s_interface {
|
||||
KeyboardInterface::releaseCallback
|
||||
};
|
||||
|
||||
KeyboardInterface::KeyboardInterface(Display *display, SeatInterface *parent)
|
||||
: QObject(parent)
|
||||
, m_display(display)
|
||||
, m_seat(parent)
|
||||
, m_eventTime(0)
|
||||
{
|
||||
}
|
||||
|
||||
KeyboardInterface::~KeyboardInterface()
|
||||
{
|
||||
while (!m_resources.isEmpty()) {
|
||||
ResourceData data = m_resources.takeLast();
|
||||
wl_resource_destroy(data.keyboard);
|
||||
}
|
||||
}
|
||||
|
||||
void KeyboardInterface::createInterfae(wl_client *client, wl_resource *parentResource, uint32_t id)
|
||||
{
|
||||
wl_resource *k = wl_resource_create(client, &wl_keyboard_interface, wl_resource_get_version(parentResource), id);
|
||||
if (!k) {
|
||||
wl_resource_post_no_memory(parentResource);
|
||||
return;
|
||||
}
|
||||
ResourceData data;
|
||||
data.client = client;
|
||||
data.keyboard = k;
|
||||
m_resources << data;
|
||||
|
||||
wl_resource_set_implementation(k, &KeyboardInterface::s_interface, this, KeyboardInterface::unbind);
|
||||
|
||||
sendKeymap(k);
|
||||
}
|
||||
|
||||
void KeyboardInterface::unbind(wl_resource *resource)
|
||||
{
|
||||
KeyboardInterface *k = KeyboardInterface::cast(resource);
|
||||
auto it = std::find_if(k->m_resources.begin(), k->m_resources.end(),
|
||||
[resource](const ResourceData &data) {
|
||||
return data.keyboard == resource;
|
||||
}
|
||||
);
|
||||
if (it == k->m_resources.end()) {
|
||||
return;
|
||||
}
|
||||
if ((*it).keyboard == k->m_focusedSurface.keyboard) {
|
||||
disconnect(k->m_focusedSurface.surface, &QObject::destroyed, k, &KeyboardInterface::surfaceDeleted);
|
||||
k->m_focusedSurface = FocusedSurface();
|
||||
}
|
||||
k->m_resources.erase(it);
|
||||
}
|
||||
|
||||
void KeyboardInterface::surfaceDeleted()
|
||||
{
|
||||
m_focusedSurface = FocusedSurface();
|
||||
}
|
||||
|
||||
void KeyboardInterface::releaseCallback(wl_client *client, wl_resource *resource)
|
||||
{
|
||||
Q_UNUSED(client)
|
||||
unbind(resource);
|
||||
}
|
||||
|
||||
void KeyboardInterface::setKeymap(int fd, quint32 size)
|
||||
{
|
||||
m_keymap.xkbcommonCompatible = true;
|
||||
m_keymap.fd = fd;
|
||||
m_keymap.size = size;
|
||||
sendKeymapToAll();
|
||||
}
|
||||
|
||||
void KeyboardInterface::sendKeymap(wl_resource *r)
|
||||
{
|
||||
if (m_keymap.xkbcommonCompatible) {
|
||||
wl_keyboard_send_keymap(r,
|
||||
WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1,
|
||||
m_keymap.fd,
|
||||
m_keymap.size);
|
||||
} else {
|
||||
int nullFd = open("/dev/null", O_RDONLY);
|
||||
wl_keyboard_send_keymap(r, WL_KEYBOARD_KEYMAP_FORMAT_NO_KEYMAP, nullFd, 0);
|
||||
close(nullFd);
|
||||
}
|
||||
}
|
||||
|
||||
void KeyboardInterface::sendKeymapToAll()
|
||||
{
|
||||
for (auto it = m_resources.constBegin(); it != m_resources.constEnd(); ++it) {
|
||||
sendKeymap((*it).keyboard);
|
||||
}
|
||||
}
|
||||
|
||||
void KeyboardInterface::sendModifiers(wl_resource* r)
|
||||
{
|
||||
wl_keyboard_send_modifiers(r, m_display->nextSerial(), m_modifiers.depressed, m_modifiers.latched, m_modifiers.locked, m_modifiers.group);
|
||||
}
|
||||
|
||||
void KeyboardInterface::setFocusedSurface(SurfaceInterface *surface)
|
||||
{
|
||||
const quint32 serial = m_display->nextSerial();
|
||||
if (m_focusedSurface.surface && m_focusedSurface.keyboard) {
|
||||
wl_keyboard_send_leave(m_focusedSurface.keyboard, serial, m_focusedSurface.surface->surface());
|
||||
disconnect(m_focusedSurface.surface, &QObject::destroyed, this, &KeyboardInterface::surfaceDeleted);
|
||||
}
|
||||
m_focusedSurface.keyboard = keyboardForSurface(surface);
|
||||
if (!m_focusedSurface.keyboard) {
|
||||
m_focusedSurface = FocusedSurface();
|
||||
return;
|
||||
}
|
||||
m_focusedSurface.surface = surface;
|
||||
connect(m_focusedSurface.surface, &QObject::destroyed, this, &KeyboardInterface::surfaceDeleted);
|
||||
|
||||
wl_array keys;
|
||||
wl_array_init(&keys);
|
||||
for (auto it = m_keyStates.constBegin(); it != m_keyStates.constEnd(); ++it) {
|
||||
if (it.value() == KeyState::Pressed) {
|
||||
continue;
|
||||
}
|
||||
uint32_t *k = reinterpret_cast<uint32_t*>(wl_array_add(&keys, sizeof(uint32_t)));
|
||||
*k = it.key();
|
||||
}
|
||||
wl_keyboard_send_enter(m_focusedSurface.keyboard, serial, m_focusedSurface.surface->surface(), &keys);
|
||||
wl_array_release(&keys);
|
||||
|
||||
sendModifiers(m_focusedSurface.keyboard);
|
||||
}
|
||||
|
||||
wl_resource *KeyboardInterface::keyboardForSurface(SurfaceInterface *surface) const
|
||||
{
|
||||
if (!surface) {
|
||||
return nullptr;
|
||||
}
|
||||
for (auto it = m_resources.constBegin(); it != m_resources.constEnd(); ++it) {
|
||||
if ((*it).client == surface->client()) {
|
||||
return (*it).keyboard;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void KeyboardInterface::keyPressed(quint32 key)
|
||||
{
|
||||
updateKey(key, KeyState::Pressed);
|
||||
if (m_focusedSurface.surface && m_focusedSurface.keyboard) {
|
||||
wl_keyboard_send_key(m_focusedSurface.keyboard, m_display->nextSerial(), m_eventTime, key, WL_KEYBOARD_KEY_STATE_PRESSED);
|
||||
}
|
||||
}
|
||||
|
||||
void KeyboardInterface::keyReleased(quint32 key)
|
||||
{
|
||||
updateKey(key, KeyState::Released);
|
||||
if (m_focusedSurface.surface && m_focusedSurface.keyboard) {
|
||||
wl_keyboard_send_key(m_focusedSurface.keyboard, m_display->nextSerial(), m_eventTime, key, WL_KEYBOARD_KEY_STATE_RELEASED);
|
||||
}
|
||||
}
|
||||
|
||||
void KeyboardInterface::updateKey(quint32 key, KeyboardInterface::KeyState state)
|
||||
{
|
||||
auto it = m_keyStates.find(key);
|
||||
if (it == m_keyStates.end()) {
|
||||
m_keyStates.insert(key, state);
|
||||
return;
|
||||
}
|
||||
it.value() = state;
|
||||
}
|
||||
|
||||
void KeyboardInterface::updateTimestamp(quint32 time)
|
||||
{
|
||||
m_eventTime = time;
|
||||
}
|
||||
|
||||
void KeyboardInterface::updateModifiers(quint32 depressed, quint32 latched, quint32 locked, quint32 group)
|
||||
{
|
||||
m_modifiers.depressed = depressed;
|
||||
m_modifiers.latched = latched;
|
||||
m_modifiers.locked = locked;
|
||||
m_modifiers.group = group;
|
||||
if (m_focusedSurface.surface && m_focusedSurface.keyboard) {
|
||||
sendModifiers(m_focusedSurface.keyboard);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,266 @@
|
|||
/********************************************************************
|
||||
KWin - the KDE window manager
|
||||
This file is part of the KDE project.
|
||||
|
||||
Copyright (C) 2014 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_SERVER_SEAT_INTERFACE_H
|
||||
#define KWIN_WAYLAND_SERVER_SEAT_INTERFACE_H
|
||||
|
||||
#include <QHash>
|
||||
#include <QObject>
|
||||
#include <QPoint>
|
||||
|
||||
#include <wayland-server.h>
|
||||
|
||||
namespace KWin
|
||||
{
|
||||
namespace WaylandServer
|
||||
{
|
||||
|
||||
class Display;
|
||||
class KeyboardInterface;
|
||||
class PointerInterface;
|
||||
class SurfaceInterface;
|
||||
|
||||
class SeatInterface : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
|
||||
Q_PROPERTY(bool pointer READ hasPointer WRITE setHasPointer NOTIFY hasPointerChanged)
|
||||
Q_PROPERTY(bool keyboard READ hasKeyboard WRITE setHasKeyboard NOTIFY hasKeyboardChanged)
|
||||
Q_PROPERTY(bool tourch READ hasTouch WRITE setHasTouch NOTIFY hasTouchChanged)
|
||||
public:
|
||||
virtual ~SeatInterface();
|
||||
|
||||
void create();
|
||||
void destroy();
|
||||
bool isValid() const {
|
||||
return m_seat != nullptr;
|
||||
}
|
||||
|
||||
const QString &name() const {
|
||||
return m_name;
|
||||
}
|
||||
bool hasPointer() const {
|
||||
return m_pointer;
|
||||
}
|
||||
bool hasKeyboard() const {
|
||||
return m_keyboard;
|
||||
}
|
||||
bool hasTouch() const {
|
||||
return m_touch;
|
||||
}
|
||||
PointerInterface *pointer() {
|
||||
return m_pointerInterface;
|
||||
}
|
||||
KeyboardInterface *keyboard() {
|
||||
return m_keyboardInterface;
|
||||
}
|
||||
|
||||
void setName(const QString &name);
|
||||
void setHasPointer(bool has);
|
||||
void setHasKeyboard(bool has);
|
||||
void setHasTouch(bool has);
|
||||
|
||||
Q_SIGNALS:
|
||||
void nameChanged(const QString&);
|
||||
void hasPointerChanged(bool);
|
||||
void hasKeyboardChanged(bool);
|
||||
void hasTouchChanged(bool);
|
||||
|
||||
private:
|
||||
friend class Display;
|
||||
explicit SeatInterface(Display *display, QObject *parent);
|
||||
|
||||
static void bind(wl_client *client, void *data, uint32_t version, uint32_t id);
|
||||
static void unbind(wl_resource *r);
|
||||
|
||||
// interface
|
||||
static void getPointerCallback(wl_client *client, wl_resource *resource, uint32_t id);
|
||||
static void getKeyboardCallback(wl_client *client, wl_resource *resource, uint32_t id);
|
||||
static void getTouchCallback(wl_client *client, wl_resource *resource, uint32_t id);
|
||||
|
||||
static SeatInterface *cast(wl_resource *r);
|
||||
void bind(wl_client *client, uint32_t version, uint32_t id);
|
||||
void sendCapabilities(wl_resource *r);
|
||||
void sendName(wl_resource *r);
|
||||
|
||||
Display *m_display;
|
||||
wl_global *m_seat;
|
||||
QString m_name;
|
||||
bool m_pointer;
|
||||
bool m_keyboard;
|
||||
bool m_touch;
|
||||
QList<wl_resource*> m_resources;
|
||||
PointerInterface *m_pointerInterface;
|
||||
KeyboardInterface *m_keyboardInterface;
|
||||
static const struct wl_seat_interface s_interface;
|
||||
};
|
||||
|
||||
class PointerInterface : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QPoint globalPos READ globalPos WRITE setGlobalPos NOTIFY globalPosChanged)
|
||||
public:
|
||||
virtual ~PointerInterface();
|
||||
|
||||
void createInterface(wl_client *client, wl_resource *parentResource, uint32_t id);
|
||||
|
||||
void updateTimestamp(quint32 time);
|
||||
void setGlobalPos(const QPoint &pos);
|
||||
const QPoint &globalPos() const {
|
||||
return m_globalPos;
|
||||
}
|
||||
void buttonPressed(quint32 button);
|
||||
void buttonReleased(quint32 button);
|
||||
bool isButtonPressed(quint32 button) const;
|
||||
quint32 buttonSerial(quint32 button) const;
|
||||
void axis(Qt::Orientation orientation, quint32 delta);
|
||||
|
||||
void setFocusedSurface(SurfaceInterface *surface, const QPoint &surfacePosition = QPoint());
|
||||
void setFocusedSurfacePosition(const QPoint &surfacePosition);
|
||||
SurfaceInterface *focusedSurface() const {
|
||||
return m_focusedSurface.surface;
|
||||
}
|
||||
const QPoint &focusedSurfacePosition() const {
|
||||
return m_focusedSurface.offset;
|
||||
}
|
||||
|
||||
Q_SIGNALS:
|
||||
void globalPosChanged(const QPoint &pos);
|
||||
|
||||
private:
|
||||
friend class SeatInterface;
|
||||
explicit PointerInterface(Display *display, SeatInterface *parent);
|
||||
wl_resource *pointerForSurface(SurfaceInterface *surface) const;
|
||||
void surfaceDeleted();
|
||||
void updateButtonSerial(quint32 button, quint32 serial);
|
||||
enum class ButtonState {
|
||||
Released,
|
||||
Pressed
|
||||
};
|
||||
void updateButtonState(quint32 button, ButtonState state);
|
||||
|
||||
static PointerInterface *cast(wl_resource *resource) {
|
||||
return reinterpret_cast<PointerInterface*>(wl_resource_get_user_data(resource));
|
||||
}
|
||||
|
||||
static void unbind(wl_resource *resource);
|
||||
// interface
|
||||
static void setCursorCallback(wl_client *client, wl_resource *resource, uint32_t serial,
|
||||
wl_resource *surface, int32_t hotspot_x, int32_t hotspot_y);
|
||||
// since version 3
|
||||
static void releaseCallback(wl_client *client, wl_resource *resource);
|
||||
|
||||
Display *m_display;
|
||||
SeatInterface *m_seat;
|
||||
struct ResourceData {
|
||||
wl_client *client = nullptr;
|
||||
wl_resource *pointer = nullptr;
|
||||
};
|
||||
QList<ResourceData> m_resources;
|
||||
quint32 m_eventTime;
|
||||
QPoint m_globalPos;
|
||||
struct FocusedSurface {
|
||||
SurfaceInterface *surface = nullptr;
|
||||
QPoint offset = QPoint();
|
||||
wl_resource *pointer = nullptr;
|
||||
quint32 serial = 0;
|
||||
};
|
||||
FocusedSurface m_focusedSurface;
|
||||
QHash<quint32, quint32> m_buttonSerials;
|
||||
QHash<quint32, ButtonState> m_buttonStates;
|
||||
|
||||
static const struct wl_pointer_interface s_interface;
|
||||
};
|
||||
|
||||
class KeyboardInterface : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
virtual ~KeyboardInterface();
|
||||
|
||||
void createInterfae(wl_client *client, wl_resource *parentResource, uint32_t id);
|
||||
|
||||
void updateTimestamp(quint32 time);
|
||||
void setKeymap(int fd, quint32 size);
|
||||
void keyPressed(quint32 key);
|
||||
void keyReleased(quint32 key);
|
||||
void updateModifiers(quint32 depressed, quint32 latched, quint32 locked, quint32 group);
|
||||
|
||||
void setFocusedSurface(SurfaceInterface *surface);
|
||||
SurfaceInterface *focusedSurface() const {
|
||||
return m_focusedSurface.surface;
|
||||
}
|
||||
|
||||
private:
|
||||
friend class SeatInterface;
|
||||
explicit KeyboardInterface(Display *display, SeatInterface *parent);
|
||||
void surfaceDeleted();
|
||||
wl_resource *keyboardForSurface(SurfaceInterface *surface) const;
|
||||
void sendKeymap(wl_resource *r);
|
||||
void sendKeymapToAll();
|
||||
void sendModifiers(wl_resource *r);
|
||||
enum class KeyState {
|
||||
Released,
|
||||
Pressed
|
||||
};
|
||||
void updateKey(quint32 key, KeyState state);
|
||||
|
||||
static KeyboardInterface *cast(wl_resource *resource) {
|
||||
return reinterpret_cast<KeyboardInterface*>(wl_resource_get_user_data(resource));
|
||||
}
|
||||
|
||||
static void unbind(wl_resource *resource);
|
||||
// since version 3
|
||||
static void releaseCallback(wl_client *client, wl_resource *resource);
|
||||
|
||||
Display *m_display;
|
||||
SeatInterface *m_seat;
|
||||
struct ResourceData {
|
||||
wl_client *client = nullptr;
|
||||
wl_resource *keyboard = nullptr;
|
||||
};
|
||||
QList<ResourceData> m_resources;
|
||||
struct Keymap {
|
||||
int fd = -1;
|
||||
quint32 size = 0;
|
||||
bool xkbcommonCompatible = false;
|
||||
};
|
||||
Keymap m_keymap;
|
||||
struct Modifiers {
|
||||
quint32 depressed = 0;
|
||||
quint32 latched = 0;
|
||||
quint32 locked = 0;
|
||||
quint32 group = 0;
|
||||
};
|
||||
Modifiers m_modifiers;
|
||||
struct FocusedSurface {
|
||||
SurfaceInterface *surface = nullptr;
|
||||
wl_resource *keyboard = nullptr;
|
||||
};
|
||||
FocusedSurface m_focusedSurface;
|
||||
QHash<quint32, KeyState> m_keyStates;
|
||||
quint32 m_eventTime;
|
||||
|
||||
static const struct wl_keyboard_interface s_interface;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue