Merge "Merge remote-tracking branch 'origin/5.14' into dev"

This commit is contained in:
Qt Forward Merge Bot 2019-08-28 07:37:29 +02:00
commit 70b66cad43
12 changed files with 249 additions and 36 deletions

View File

@ -442,6 +442,21 @@ QWaylandInputDevice::Touch *QWaylandInputDevice::createTouch(QWaylandInputDevice
return new Touch(device);
}
QWaylandInputDevice::Keyboard *QWaylandInputDevice::keyboard() const
{
return mKeyboard;
}
QWaylandInputDevice::Pointer *QWaylandInputDevice::pointer() const
{
return mPointer;
}
QWaylandInputDevice::Touch *QWaylandInputDevice::touch() const
{
return mTouch;
}
void QWaylandInputDevice::handleEndDrag()
{
if (mTouch)
@ -774,8 +789,10 @@ void QWaylandInputDevice::Pointer::pointer_button(uint32_t serial, uint32_t time
void QWaylandInputDevice::Pointer::invalidateFocus()
{
disconnect(mFocus.data(), &QObject::destroyed, this, &Pointer::handleFocusDestroyed);
mFocus = nullptr;
if (mFocus) {
disconnect(mFocus.data(), &QObject::destroyed, this, &Pointer::handleFocusDestroyed);
mFocus = nullptr;
}
mEnterSerial = 0;
}

View File

@ -148,6 +148,10 @@ public:
virtual Pointer *createPointer(QWaylandInputDevice *device);
virtual Touch *createTouch(QWaylandInputDevice *device);
Keyboard *keyboard() const;
Pointer *pointer() const;
Touch *touch() const;
private:
QWaylandDisplay *mQDisplay = nullptr;
struct wl_display *mDisplay = nullptr;
@ -248,6 +252,8 @@ public:
Qt::KeyboardModifiers modifiers() const;
struct ::wl_keyboard *wl_keyboard() { return QtWayland::wl_keyboard::object(); }
private slots:
void handleFocusDestroyed();
void handleFocusLost();
@ -284,6 +290,8 @@ public:
#endif
QWaylandInputDevice *seat() const { return mParent; }
struct ::wl_pointer *wl_pointer() { return QtWayland::wl_pointer::object(); }
protected:
void pointer_enter(uint32_t serial, struct wl_surface *surface,
wl_fixed_t sx, wl_fixed_t sy) override;
@ -377,6 +385,8 @@ public:
bool allTouchPointsReleased();
void releasePoints();
struct ::wl_touch *wl_touch() { return QtWayland::wl_touch::object(); }
QWaylandInputDevice *mParent = nullptr;
QPointer<QWaylandWindow> mFocus;
QList<QWindowSystemInterface::TouchPoint> mTouchPoints;

View File

@ -47,6 +47,7 @@
#include "qwaylanddisplay_p.h"
#include "qwaylandwindowmanagerintegration_p.h"
#include "qwaylandscreen_p.h"
#include "qwaylandinputdevice_p.h"
#include <QtGui/private/qguiapplication_p.h>
#include <QtGui/QScreen>
#include <QtWaylandClient/private/qwaylandclientbufferintegration_p.h>
@ -76,6 +77,27 @@ void *QWaylandNativeInterface::nativeResourceForIntegration(const QByteArray &re
if (lowerCaseResource == "egldisplay" && m_integration->clientBufferIntegration())
return m_integration->clientBufferIntegration()->nativeResource(QWaylandClientBufferIntegration::EglDisplay);
if (lowerCaseResource == "wl_seat")
return m_integration->display()->defaultInputDevice()->wl_seat();
if (lowerCaseResource == "wl_keyboard") {
auto *keyboard = m_integration->display()->defaultInputDevice()->keyboard();
if (keyboard)
return keyboard->wl_keyboard();
return nullptr;
}
if (lowerCaseResource == "wl_pointer") {
auto *pointer = m_integration->display()->defaultInputDevice()->pointer();
if (pointer)
return pointer->wl_pointer();
return nullptr;
}
if (lowerCaseResource == "wl_touch") {
auto *touch = m_integration->display()->defaultInputDevice()->touch();
if (touch)
return touch->wl_touch();
return nullptr;
}
return nullptr;
}

View File

@ -66,7 +66,7 @@ void tst_datadevicev1::initTestCase()
{
QCOMPOSITOR_TRY_VERIFY(pointer());
QCOMPOSITOR_TRY_VERIFY(!pointer()->resourceMap().empty());
QCOMPOSITOR_TRY_COMPARE(pointer()->resourceMap().first()->version(), 4);
QCOMPOSITOR_TRY_COMPARE(pointer()->resourceMap().first()->version(), 5);
QCOMPOSITOR_TRY_VERIFY(keyboard());
@ -104,8 +104,11 @@ void tst_datadevicev1::pasteAscii()
keyboard()->sendEnter(surface); // Need to set keyboard focus according to protocol
pointer()->sendEnter(surface, {32, 32});
pointer()->sendFrame(client);
pointer()->sendButton(client, BTN_LEFT, 1);
pointer()->sendFrame(client);
pointer()->sendButton(client, BTN_LEFT, 0);
pointer()->sendFrame(client);
});
QTRY_COMPARE(window.m_text, "normal ascii");
}
@ -139,8 +142,11 @@ void tst_datadevicev1::pasteUtf8()
keyboard()->sendEnter(surface); // Need to set keyboard focus according to protocol
pointer()->sendEnter(surface, {32, 32});
pointer()->sendFrame(client);
pointer()->sendButton(client, BTN_LEFT, 1);
pointer()->sendFrame(client);
pointer()->sendButton(client, BTN_LEFT, 0);
pointer()->sendFrame(client);
});
QTRY_COMPARE(window.m_text, "face with tears of joy: 😂");
}

View File

@ -196,8 +196,11 @@ void tst_output::removePrimaryScreen()
exec([&] {
auto *surface = xdgToplevel()->surface();
pointer()->sendEnter(surface, {32, 32});
pointer()->sendFrame(client());
pointer()->sendButton(client(), BTN_LEFT, 1);
pointer()->sendFrame(client());
pointer()->sendButton(client(), BTN_LEFT, 0);
pointer()->sendFrame(client());
});
// Wait to make sure mouse events dont't cause a crash now that the screen has changed

View File

@ -268,7 +268,7 @@ void tst_primaryselectionv1::initTestCase()
{
QCOMPOSITOR_TRY_VERIFY(pointer());
QCOMPOSITOR_TRY_VERIFY(!pointer()->resourceMap().empty());
QCOMPOSITOR_TRY_COMPARE(pointer()->resourceMap().first()->version(), 4);
QCOMPOSITOR_TRY_COMPARE(pointer()->resourceMap().first()->version(), 5);
QCOMPOSITOR_TRY_VERIFY(keyboard());
}
@ -329,8 +329,11 @@ void tst_primaryselectionv1::pasteAscii()
device->sendSelection(offer);
pointer()->sendEnter(surface, {32, 32});
pointer()->sendFrame(client());
pointer()->sendButton(client(), BTN_MIDDLE, 1);
pointer()->sendFrame(client());
pointer()->sendButton(client(), BTN_MIDDLE, 0);
pointer()->sendFrame(client());
});
QTRY_COMPARE(window.m_formats, QStringList{"text/plain"});
QTRY_COMPARE(window.m_text, "normal ascii");
@ -372,8 +375,11 @@ void tst_primaryselectionv1::pasteUtf8()
device->sendSelection(offer);
pointer()->sendEnter(surface, {32, 32});
pointer()->sendFrame(client());
pointer()->sendButton(client(), BTN_MIDDLE, 1);
pointer()->sendFrame(client());
pointer()->sendButton(client(), BTN_MIDDLE, 0);
pointer()->sendFrame(client());
});
QTRY_COMPARE(window.m_formats, QStringList({"text/plain", "text/plain;charset=utf-8"}));
QTRY_COMPARE(window.m_text, "face with tears of joy: 😂");
@ -428,8 +434,11 @@ void tst_primaryselectionv1::copy()
auto *surface = xdgSurface()->m_surface;
keyboard()->sendEnter(surface); // Need to set keyboard focus according to protocol
pointer()->sendEnter(surface, {32, 32});
pointer()->sendFrame(client());
mouseSerials << pointer()->sendButton(client(), BTN_MIDDLE, 1);
pointer()->sendFrame(client());
mouseSerials << pointer()->sendButton(client(), BTN_MIDDLE, 0);
pointer()->sendFrame(client());
});
QCOMPOSITOR_TRY_VERIFY(primarySelectionDevice()->m_selectionSource);
QCOMPOSITOR_TRY_VERIFY(mouseSerials.contains(primarySelectionDevice()->m_serial));

View File

@ -41,18 +41,11 @@ public:
removeAll<Seat>();
uint capabilities = MockCompositor::Seat::capability_pointer;
uint capabilities = MockCompositor::Seat::capability_pointer | MockCompositor::Seat::capability_touch;
int version = 5;
add<Seat>(capabilities, version);
});
}
Pointer *pointer()
{
auto *seat = get<Seat>();
Q_ASSERT(seat);
return seat->m_pointer;
}
};
class tst_seatv5 : public QObject, private SeatV5Compositor
@ -61,6 +54,8 @@ class tst_seatv5 : public QObject, private SeatV5Compositor
private slots:
void cleanup() { QTRY_VERIFY2(isClean(), qPrintable(dirtyMessage())); }
void bindsToSeat();
// Pointer tests
void createsPointer();
void setsCursorOnEnter();
void usesEnterSerial();
@ -69,6 +64,10 @@ private slots:
void fingerScroll();
void fingerScrollSlow();
void wheelDiscreteScroll();
// Touch tests
void createsTouch();
void singleTap();
};
void tst_seatv5::bindsToSeat()
@ -383,5 +382,70 @@ void tst_seatv5::wheelDiscreteScroll()
}
}
void tst_seatv5::createsTouch()
{
QCOMPOSITOR_TRY_COMPARE(touch()->resourceMap().size(), 1);
QCOMPOSITOR_TRY_COMPARE(touch()->resourceMap().first()->version(), 5);
}
class TouchWindow : public QRasterWindow {
public:
TouchWindow()
{
resize(64, 64);
show();
}
void touchEvent(QTouchEvent *event) override
{
QRasterWindow::touchEvent(event);
m_events.append(Event{event});
}
struct Event // Because I didn't find a convenient way to copy it entirely
{
explicit Event() = default;
explicit Event(const QTouchEvent *event)
: type(event->type())
, touchPointStates(event->touchPointStates())
, touchPoints(event->touchPoints())
{
}
const QEvent::Type type{};
const Qt::TouchPointStates touchPointStates{};
const QList<QTouchEvent::TouchPoint> touchPoints;
};
QVector<Event> m_events;
};
void tst_seatv5::singleTap()
{
TouchWindow window;
QCOMPOSITOR_TRY_VERIFY(xdgSurface() && xdgSurface()->m_committedConfigureSerial);
exec([=] {
auto *t = touch();
auto *c = client();
t->sendDown(xdgToplevel()->surface(), {32, 32}, 1);
t->sendFrame(c);
t->sendUp(c, 1);
t->sendFrame(c);
});
QTRY_VERIFY(!window.m_events.empty());
{
auto e = window.m_events.takeFirst();
QCOMPARE(e.type, QEvent::TouchBegin);
QCOMPARE(e.touchPointStates, Qt::TouchPointState::TouchPointPressed);
QCOMPARE(e.touchPoints.length(), 1);
QCOMPARE(e.touchPoints.first().pos(), QPointF(32-window.frameMargins().left(), 32-window.frameMargins().top()));
}
{
auto e = window.m_events.takeFirst();
QCOMPARE(e.type, QEvent::TouchEnd);
QCOMPARE(e.touchPointStates, Qt::TouchPointState::TouchPointReleased);
QCOMPARE(e.touchPoints.length(), 1);
QCOMPARE(e.touchPoints.first().pos(), QPointF(32-window.frameMargins().left(), 32-window.frameMargins().top()));
}
}
QCOMPOSITOR_TEST_MAIN(tst_seatv5)
#include "tst_seatv5.moc"

View File

@ -191,12 +191,15 @@ Seat::~Seat()
{
qDeleteAll(m_oldPointers);
delete m_pointer;
qDeleteAll(m_oldTouchs);
delete m_touch;
qDeleteAll(m_oldKeyboards);
delete m_keyboard;
}
void Seat::setCapabilities(uint capabilities) {
// TODO: Add support for touch
Q_ASSERT(~capabilities & capability_touch);
m_capabilities = capabilities;
if (m_capabilities & capability_pointer) {
@ -207,6 +210,14 @@ void Seat::setCapabilities(uint capabilities) {
m_pointer = nullptr;
}
if (m_capabilities & capability_touch) {
if (!m_touch)
m_touch = (new Touch(this));
} else if (m_touch) {
m_oldTouchs << m_touch;
m_touch = nullptr;
}
if (m_capabilities & capability_keyboard) {
if (!m_keyboard)
m_keyboard = (new Keyboard(this));
@ -234,9 +245,24 @@ void Seat::seat_get_pointer(Resource *resource, uint32_t id)
m_pointer->add(resource->client(), id, resource->version());
}
void Seat::seat_get_touch(QtWaylandServer::wl_seat::Resource *resource, uint32_t id)
{
if (~m_capabilities & capability_touch) {
qWarning() << "Client requested a wl_touch without the capability being available."
<< "This Could be a race condition when hotunplugging,"
<< "but is most likely a client error";
Touch *touch = new Touch(this);
touch->add(resource->client(), id, resource->version());
// TODO: mark as destroyed
m_oldTouchs << touch;
return;
}
m_touch->add(resource->client(), id, resource->version());
}
void Seat::seat_get_keyboard(QtWaylandServer::wl_seat::Resource *resource, uint32_t id)
{
if (~m_capabilities & capability_pointer) {
if (~m_capabilities & capability_keyboard) {
qWarning() << "Client requested a wl_keyboard without the capability being available."
<< "This Could be a race condition when hotunplugging,"
<< "but is most likely a client error";
@ -371,6 +397,40 @@ void Pointer::pointer_set_cursor(Resource *resource, uint32_t serial, wl_resourc
emit setCursor(serial);
}
uint Touch::sendDown(Surface *surface, const QPointF &position, int id)
{
wl_fixed_t x = wl_fixed_from_double(position.x());
wl_fixed_t y = wl_fixed_from_double(position.y());
uint serial = m_seat->m_compositor->nextSerial();
auto time = m_seat->m_compositor->currentTimeMilliseconds();
wl_client *client = surface->resource()->client();
const auto touchResources = resourceMap().values(client);
for (auto *r : touchResources)
wl_touch::send_down(r->handle, serial, time, surface->resource()->handle, id, x, y);
return serial;
}
uint Touch::sendUp(wl_client *client, int id)
{
uint serial = m_seat->m_compositor->nextSerial();
auto time = m_seat->m_compositor->currentTimeMilliseconds();
const auto touchResources = resourceMap().values(client);
for (auto *r : touchResources)
wl_touch::send_up(r->handle, serial, time, id);
return serial;
}
void Touch::sendFrame(wl_client *client)
{
const auto touchResources = resourceMap().values(client);
for (auto *r : touchResources)
send_frame(r->handle);
}
uint Keyboard::sendEnter(Surface *surface)
{
auto serial = m_seat->m_compositor->nextSerial();

View File

@ -38,6 +38,7 @@ namespace MockCompositor {
class WlCompositor;
class Output;
class Pointer;
class Touch;
class Keyboard;
class CursorRole;
class ShmPool;
@ -236,7 +237,7 @@ class Seat : public Global, public QtWaylandServer::wl_seat
{
Q_OBJECT
public:
explicit Seat(CoreCompositor *compositor, uint capabilities = Seat::capability_pointer | Seat::capability_keyboard, int version = 4);
explicit Seat(CoreCompositor *compositor, uint capabilities = Seat::capability_pointer | Seat::capability_keyboard | Seat::capability_touch, int version = 5);
~Seat() override;
void send_capabilities(Resource *resource, uint capabilities) = delete; // Use wrapper instead
void send_capabilities(uint capabilities) = delete; // Use wrapper instead
@ -247,6 +248,9 @@ public:
Pointer* m_pointer = nullptr;
QVector<Pointer *> m_oldPointers;
Touch* m_touch = nullptr;
QVector<Touch *> m_oldTouchs;
Keyboard* m_keyboard = nullptr;
QVector<Keyboard *> m_oldKeyboards;
@ -259,8 +263,8 @@ protected:
}
void seat_get_pointer(Resource *resource, uint32_t id) override;
void seat_get_touch(Resource *resource, uint32_t id) override;
void seat_get_keyboard(Resource *resource, uint32_t id) override;
// void seat_get_touch(Resource *resource, uint32_t id) override;
// void seat_release(Resource *resource) override;
};
@ -307,6 +311,18 @@ public:
Surface *m_surface = nullptr;
};
class Touch : public QObject, public QtWaylandServer::wl_touch
{
Q_OBJECT
public:
explicit Touch(Seat *seat) : m_seat(seat) {}
uint sendDown(Surface *surface, const QPointF &position, int id);
uint sendUp(wl_client *client, int id);
void sendFrame(wl_client *client);
Seat *m_seat = nullptr;
};
class Keyboard : public QObject, public QtWaylandServer::wl_keyboard
{
Q_OBJECT

View File

@ -41,7 +41,7 @@ DefaultCompositor::DefaultCompositor()
add<SubCompositor>();
auto *output = add<Output>();
output->m_data.physicalSize = output->m_data.mode.physicalSizeForDpi(96);
add<Seat>(Seat::capability_pointer | Seat::capability_keyboard);
add<Seat>(Seat::capability_pointer | Seat::capability_keyboard | Seat::capability_touch);
add<XdgWmBase>();
add<Shm>();
// TODO: other shells, viewporter, xdgoutput etc

View File

@ -60,6 +60,7 @@ public:
XdgToplevel *xdgToplevel(int i = 0) { return get<XdgWmBase>()->toplevel(i); }
XdgPopup *xdgPopup(int i = 0) { return get<XdgWmBase>()->popup(i); }
Pointer *pointer() { auto *seat = get<Seat>(); Q_ASSERT(seat); return seat->m_pointer; }
Touch *touch() { auto *seat = get<Seat>(); Q_ASSERT(seat); return seat->m_touch; }
Surface *cursorSurface() { auto *p = pointer(); return p ? p->cursorSurface() : nullptr; }
Keyboard *keyboard() { auto *seat = get<Seat>(); Q_ASSERT(seat); return seat->m_keyboard; }
uint sendXdgShellPing();

View File

@ -214,12 +214,13 @@ void tst_xdgshell::popup()
uint clickSerial = exec([=] {
auto *surface = xdgToplevel()->surface();
auto *p = pointer();
auto *c = client();
p->sendEnter(surface, {100, 100});
// p->sendFrame(); //TODO: uncomment when we support seat v5
p->sendFrame(c);
uint serial = p->sendButton(client(), BTN_LEFT, Pointer::button_state_pressed);
p->sendButton(client(), BTN_LEFT, Pointer::button_state_released);
p->sendButton(c, BTN_LEFT, Pointer::button_state_released);
return serial;
// p->sendFrame(); //TODO: uncomment when we support seat v5
p->sendFrame(c);
});
QTRY_VERIFY(window.m_popup);
@ -298,13 +299,14 @@ void tst_xdgshell::tooltipOnPopup()
exec([=] {
auto *surface = xdgToplevel()->surface();
auto *p = pointer();
auto *c = client();
p->sendEnter(surface, {100, 100});
// p->sendFrame(); //TODO: uncomment when we support seat v5
p->sendFrame(c);
p->sendButton(client(), BTN_LEFT, Pointer::button_state_pressed);
p->sendButton(client(), BTN_LEFT, Pointer::button_state_released);
// p->sendFrame();
p->sendFrame(c);
p->sendLeave(surface);
// p->sendFrame();
p->sendFrame(c);
});
QCOMPOSITOR_TRY_VERIFY(xdgPopup());
@ -315,11 +317,12 @@ void tst_xdgshell::tooltipOnPopup()
exec([=] {
auto *surface = xdgPopup()->surface();
auto *p = pointer();
auto *c = client();
p->sendEnter(surface, {100, 100});
// p->sendFrame();
p->sendFrame(c);
p->sendButton(client(), BTN_LEFT, Pointer::button_state_pressed);
p->sendButton(client(), BTN_LEFT, Pointer::button_state_released);
// p->sendFrame();
p->sendFrame(c);
});
QCOMPOSITOR_TRY_VERIFY(xdgPopup(1));
@ -380,13 +383,14 @@ void tst_xdgshell::switchPopups()
exec([=] {
auto *surface = xdgToplevel()->surface();
auto *p = pointer();
auto *c = client();
p->sendEnter(surface, {100, 100});
// p->sendFrame(); //TODO: uncomment when we support seat v5
p->sendButton(client(), BTN_LEFT, Pointer::button_state_pressed);
p->sendButton(client(), BTN_LEFT, Pointer::button_state_released);
// p->sendFrame();
p->sendFrame(c);
p->sendButton(c, BTN_LEFT, Pointer::button_state_pressed);
p->sendButton(c, BTN_LEFT, Pointer::button_state_released);
p->sendFrame(c);
p->sendLeave(surface);
// p->sendFrame();
p->sendFrame(c);
});
QCOMPOSITOR_TRY_VERIFY(xdgPopup());
@ -399,11 +403,12 @@ void tst_xdgshell::switchPopups()
exec([=] {
auto *surface = xdgToplevel()->surface();
auto *p = pointer();
auto *c = client();
p->sendEnter(surface, {100, 100});
// p->sendFrame();
p->sendButton(client(), BTN_LEFT, Pointer::button_state_pressed);
p->sendButton(client(), BTN_LEFT, Pointer::button_state_released);
// p->sendFrame();
p->sendFrame(c);
p->sendButton(c, BTN_LEFT, Pointer::button_state_pressed);
p->sendButton(c, BTN_LEFT, Pointer::button_state_released);
p->sendFrame(c);
});
// The client will now hide one popup and then show another