Make test compile with Wayland 1.2
Tests still fail when running like before. Change-Id: I9c0a5e8068fa7af7abc0018e6e9c4f08aa39533b Reviewed-by: Andy Nichols <andy.nichols@digia.com>
This commit is contained in:
parent
02305555ca
commit
13ab2c15d4
@ -20,4 +20,5 @@ SOURCES += tst_client.cpp \
|
|||||||
mocksurface.cpp \
|
mocksurface.cpp \
|
||||||
mockoutput.cpp
|
mockoutput.cpp
|
||||||
HEADERS += mockcompositor.h \
|
HEADERS += mockcompositor.h \
|
||||||
mocksurface.h
|
mockinput.h \
|
||||||
|
mocksurface.h \
|
||||||
|
@ -40,6 +40,7 @@
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include "mockcompositor.h"
|
#include "mockcompositor.h"
|
||||||
|
#include "mockinput.h"
|
||||||
#include "mocksurface.h"
|
#include "mocksurface.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@ -201,29 +202,23 @@ Compositor::Compositor()
|
|||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
wl_seat_init(&m_seat);
|
|
||||||
wl_pointer_init(&m_pointer);
|
|
||||||
wl_seat_set_pointer(&m_seat, &m_pointer);
|
|
||||||
wl_keyboard_init(&m_keyboard);
|
|
||||||
wl_seat_set_keyboard(&m_seat, &m_keyboard);
|
|
||||||
|
|
||||||
wl_display_add_global(m_display, &wl_compositor_interface, this, bindCompositor);
|
wl_display_add_global(m_display, &wl_compositor_interface, this, bindCompositor);
|
||||||
|
|
||||||
wl_display_init_shm(m_display);
|
wl_display_init_shm(m_display);
|
||||||
|
|
||||||
wl_display_add_global(m_display, &wl_seat_interface, this, bindSeat);
|
m_seat.reset(new Seat(this, m_display));
|
||||||
|
m_pointer = m_seat->pointer();
|
||||||
|
m_keyboard = m_seat->keyboard();
|
||||||
|
|
||||||
wl_display_add_global(m_display, &wl_output_interface, this, bindOutput);
|
wl_display_add_global(m_display, &wl_output_interface, this, bindOutput);
|
||||||
wl_display_add_global(m_display, &wl_shell_interface, this, bindShell);
|
wl_display_add_global(m_display, &wl_shell_interface, this, bindShell);
|
||||||
|
|
||||||
|
|
||||||
m_loop = wl_display_get_event_loop(m_display);
|
m_loop = wl_display_get_event_loop(m_display);
|
||||||
m_fd = wl_event_loop_get_fd(m_loop);
|
m_fd = wl_event_loop_get_fd(m_loop);
|
||||||
}
|
}
|
||||||
|
|
||||||
Compositor::~Compositor()
|
Compositor::~Compositor()
|
||||||
{
|
{
|
||||||
wl_pointer_release(&m_pointer);
|
|
||||||
wl_keyboard_release(&m_keyboard);
|
|
||||||
wl_display_destroy(m_display);
|
wl_display_destroy(m_display);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -292,6 +287,10 @@ void Compositor::addSurface(Surface *surface)
|
|||||||
void Compositor::removeSurface(Surface *surface)
|
void Compositor::removeSurface(Surface *surface)
|
||||||
{
|
{
|
||||||
m_surfaces.remove(m_surfaces.indexOf(surface));
|
m_surfaces.remove(m_surfaces.indexOf(surface));
|
||||||
|
if (m_keyboard->focus() == surface)
|
||||||
|
m_keyboard->setFocus(0);
|
||||||
|
if (m_pointer->focus() == surface)
|
||||||
|
m_pointer->setFocus(0, QPoint());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -58,6 +58,9 @@ namespace Impl {
|
|||||||
|
|
||||||
typedef void (**Implementation)(void);
|
typedef void (**Implementation)(void);
|
||||||
|
|
||||||
|
class Keyboard;
|
||||||
|
class Pointer;
|
||||||
|
class Seat;
|
||||||
class Surface;
|
class Surface;
|
||||||
|
|
||||||
class Compositor
|
class Compositor
|
||||||
@ -87,16 +90,9 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
static void bindCompositor(wl_client *client, void *data, uint32_t version, uint32_t id);
|
static void bindCompositor(wl_client *client, void *data, uint32_t version, uint32_t id);
|
||||||
static void bindSeat(wl_client *client, void *data, uint32_t version, uint32_t id);
|
|
||||||
static void bindOutput(wl_client *client, void *data, uint32_t version, uint32_t id);
|
static void bindOutput(wl_client *client, void *data, uint32_t version, uint32_t id);
|
||||||
static void bindShell(wl_client *client, void *data, uint32_t version, uint32_t id);
|
static void bindShell(wl_client *client, void *data, uint32_t version, uint32_t id);
|
||||||
|
|
||||||
static void get_pointer(wl_client *client, wl_resource *resource, uint32_t id);
|
|
||||||
static void get_keyboard(wl_client *client, wl_resource *resource, uint32_t id);
|
|
||||||
static void get_touch(wl_client *client, wl_resource *resource, uint32_t id);
|
|
||||||
|
|
||||||
static void destroyInputResource(wl_resource *resource);
|
|
||||||
|
|
||||||
void initShm();
|
void initShm();
|
||||||
|
|
||||||
void sendOutputGeometry(wl_resource *resource);
|
void sendOutputGeometry(wl_resource *resource);
|
||||||
@ -112,9 +108,9 @@ private:
|
|||||||
wl_list m_outputResources;
|
wl_list m_outputResources;
|
||||||
uint32_t m_time;
|
uint32_t m_time;
|
||||||
|
|
||||||
wl_seat m_seat;
|
QScopedPointer<Seat> m_seat;
|
||||||
wl_pointer m_pointer;
|
Pointer *m_pointer;
|
||||||
wl_keyboard m_keyboard;
|
Keyboard *m_keyboard;
|
||||||
QVector<Surface *> m_surfaces;
|
QVector<Surface *> m_surfaces;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -40,164 +40,192 @@
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include "mockcompositor.h"
|
#include "mockcompositor.h"
|
||||||
|
#include "mockinput.h"
|
||||||
#include "mocksurface.h"
|
#include "mocksurface.h"
|
||||||
|
|
||||||
namespace Impl {
|
namespace Impl {
|
||||||
|
|
||||||
void Compositor::destroyInputResource(wl_resource *resource)
|
static Surface *resolveSurface(const QVariant &v)
|
||||||
{
|
|
||||||
Compositor *compositor = static_cast<Compositor *>(resource->data);
|
|
||||||
wl_keyboard *keyboard = &compositor->m_keyboard;
|
|
||||||
wl_pointer *pointer = &compositor->m_pointer;
|
|
||||||
|
|
||||||
if (keyboard->focus_resource == resource)
|
|
||||||
keyboard->focus_resource = 0;
|
|
||||||
if (pointer->focus_resource == resource)
|
|
||||||
pointer->focus_resource = 0;
|
|
||||||
|
|
||||||
wl_list_remove(&resource->link);
|
|
||||||
|
|
||||||
free(resource);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void destroyInputDevice(wl_resource *resource)
|
|
||||||
{
|
|
||||||
wl_list_remove(&resource->link);
|
|
||||||
free(resource);
|
|
||||||
}
|
|
||||||
|
|
||||||
void pointer_attach(wl_client *client,
|
|
||||||
wl_resource *device_resource,
|
|
||||||
uint32_t time,
|
|
||||||
wl_resource *buffer_resource, int32_t x, int32_t y)
|
|
||||||
{
|
|
||||||
Q_UNUSED(client);
|
|
||||||
Q_UNUSED(device_resource);
|
|
||||||
Q_UNUSED(time);
|
|
||||||
Q_UNUSED(buffer_resource);
|
|
||||||
Q_UNUSED(QPoint(x, y));
|
|
||||||
}
|
|
||||||
|
|
||||||
void Compositor::get_pointer(wl_client *client,
|
|
||||||
wl_resource *resource,
|
|
||||||
uint32_t id)
|
|
||||||
{
|
|
||||||
static const struct wl_pointer_interface pointer_interface = {
|
|
||||||
pointer_attach
|
|
||||||
};
|
|
||||||
Compositor *compositor = static_cast<Compositor *>(resource->data);
|
|
||||||
wl_pointer *pointer = &compositor->m_pointer;
|
|
||||||
wl_resource *clientResource = wl_client_add_object(client,
|
|
||||||
&wl_pointer_interface,
|
|
||||||
&pointer_interface,
|
|
||||||
id,
|
|
||||||
pointer);
|
|
||||||
wl_list_insert(&pointer->resource_list, &clientResource->link);
|
|
||||||
clientResource->destroy = destroyInputDevice;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Compositor::get_keyboard(wl_client *client,
|
|
||||||
wl_resource *resource,
|
|
||||||
uint32_t id)
|
|
||||||
{
|
|
||||||
Compositor *compositor = static_cast<Compositor *>(resource->data);
|
|
||||||
wl_keyboard *keyboard = &compositor->m_keyboard;
|
|
||||||
wl_resource *clientResource = wl_client_add_object(client,
|
|
||||||
&wl_keyboard_interface,
|
|
||||||
0,
|
|
||||||
id,
|
|
||||||
keyboard);
|
|
||||||
wl_list_insert(&keyboard->resource_list, &clientResource->link);
|
|
||||||
clientResource->destroy = destroyInputDevice;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Compositor::get_touch(wl_client *client,
|
|
||||||
wl_resource *resource,
|
|
||||||
uint32_t id)
|
|
||||||
{
|
|
||||||
Q_UNUSED(client);
|
|
||||||
Q_UNUSED(resource);
|
|
||||||
Q_UNUSED(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Compositor::bindSeat(wl_client *client, void *compositorData, uint32_t version, uint32_t id)
|
|
||||||
{
|
|
||||||
static const struct wl_seat_interface seatInterface = {
|
|
||||||
get_pointer,
|
|
||||||
get_keyboard,
|
|
||||||
get_touch
|
|
||||||
};
|
|
||||||
|
|
||||||
Q_UNUSED(version);
|
|
||||||
wl_resource *resource = wl_client_add_object(client, &wl_seat_interface, &seatInterface, id, compositorData);
|
|
||||||
resource->destroy = destroyInputResource;
|
|
||||||
|
|
||||||
Compositor *compositor = static_cast<Compositor *>(compositorData);
|
|
||||||
wl_list_insert(&compositor->m_seat.base_resource_list, &resource->link);
|
|
||||||
|
|
||||||
wl_seat_send_capabilities(resource, WL_SEAT_CAPABILITY_POINTER | WL_SEAT_CAPABILITY_KEYBOARD);
|
|
||||||
}
|
|
||||||
|
|
||||||
static wl_surface *resolveSurface(const QVariant &v)
|
|
||||||
{
|
{
|
||||||
QSharedPointer<MockSurface> mockSurface = v.value<QSharedPointer<MockSurface> >();
|
QSharedPointer<MockSurface> mockSurface = v.value<QSharedPointer<MockSurface> >();
|
||||||
Surface *surface = mockSurface ? mockSurface->handle() : 0;
|
return mockSurface ? mockSurface->handle() : 0;
|
||||||
return surface ? surface->base() : 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Compositor::setKeyboardFocus(void *data, const QList<QVariant> ¶meters)
|
void Compositor::setKeyboardFocus(void *data, const QList<QVariant> ¶meters)
|
||||||
{
|
{
|
||||||
Compositor *compositor = static_cast<Compositor *>(data);
|
Compositor *compositor = static_cast<Compositor *>(data);
|
||||||
wl_keyboard_set_focus(&compositor->m_keyboard, resolveSurface(parameters.first()));
|
compositor->m_keyboard->setFocus(resolveSurface(parameters.first()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Compositor::sendMousePress(void *data, const QList<QVariant> ¶meters)
|
void Compositor::sendMousePress(void *data, const QList<QVariant> ¶meters)
|
||||||
{
|
{
|
||||||
Compositor *compositor = static_cast<Compositor *>(data);
|
Compositor *compositor = static_cast<Compositor *>(data);
|
||||||
wl_surface *surface = resolveSurface(parameters.first());
|
Surface *surface = resolveSurface(parameters.first());
|
||||||
if (!surface)
|
if (!surface)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QPoint pos = parameters.last().toPoint();
|
QPoint pos = parameters.last().toPoint();
|
||||||
wl_pointer_set_focus(&compositor->m_pointer, surface,
|
compositor->m_pointer->setFocus(surface, pos);
|
||||||
wl_fixed_from_int(pos.x()), wl_fixed_from_int(pos.y()));
|
compositor->m_pointer->sendMotion(pos);
|
||||||
wl_pointer_send_motion(compositor->m_pointer.focus_resource, compositor->time(),
|
compositor->m_pointer->sendButton(0x110, 1);
|
||||||
wl_fixed_from_double(pos.x()), wl_fixed_from_double(pos.y()));
|
|
||||||
wl_pointer_send_button(compositor->m_pointer.focus_resource,
|
|
||||||
compositor->nextSerial(), compositor->time(), 0x110, 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Compositor::sendMouseRelease(void *data, const QList<QVariant> ¶meters)
|
void Compositor::sendMouseRelease(void *data, const QList<QVariant> ¶meters)
|
||||||
{
|
{
|
||||||
Compositor *compositor = static_cast<Compositor *>(data);
|
Compositor *compositor = static_cast<Compositor *>(data);
|
||||||
wl_surface *surface = resolveSurface(parameters.first());
|
Surface *surface = resolveSurface(parameters.first());
|
||||||
if (!surface)
|
if (!surface)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
wl_pointer_send_button(compositor->m_pointer.focus_resource,
|
compositor->m_pointer->sendButton(0x110, 0);
|
||||||
compositor->nextSerial(), compositor->time(), 0x110, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Compositor::sendKeyPress(void *data, const QList<QVariant> ¶meters)
|
void Compositor::sendKeyPress(void *data, const QList<QVariant> ¶meters)
|
||||||
{
|
{
|
||||||
Compositor *compositor = static_cast<Compositor *>(data);
|
Compositor *compositor = static_cast<Compositor *>(data);
|
||||||
wl_surface *surface = resolveSurface(parameters.first());
|
Surface *surface = resolveSurface(parameters.first());
|
||||||
if (!surface)
|
if (!surface)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
wl_keyboard_send_key(compositor->m_keyboard.focus_resource,
|
compositor->m_keyboard->sendKey(parameters.last().toUInt() - 8, 1);
|
||||||
compositor->nextSerial(), compositor->time(), parameters.last().toUInt() - 8, 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Compositor::sendKeyRelease(void *data, const QList<QVariant> ¶meters)
|
void Compositor::sendKeyRelease(void *data, const QList<QVariant> ¶meters)
|
||||||
{
|
{
|
||||||
Compositor *compositor = static_cast<Compositor *>(data);
|
Compositor *compositor = static_cast<Compositor *>(data);
|
||||||
wl_surface *surface = resolveSurface(parameters.first());
|
Surface *surface = resolveSurface(parameters.first());
|
||||||
if (!surface)
|
if (!surface)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
wl_keyboard_send_key(compositor->m_keyboard.focus_resource,
|
compositor->m_keyboard->sendKey(parameters.last().toUInt() - 8, 0);
|
||||||
compositor->nextSerial(), compositor->time(), parameters.last().toUInt() - 8, 0);
|
}
|
||||||
|
|
||||||
|
Seat::Seat(Compositor *compositor, struct ::wl_display *display)
|
||||||
|
: wl_seat(display)
|
||||||
|
, m_compositor(compositor)
|
||||||
|
, m_keyboard(new Keyboard(compositor))
|
||||||
|
, m_pointer(new Pointer(compositor))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
Seat::~Seat()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void Seat::seat_bind_resource(Resource *resource)
|
||||||
|
{
|
||||||
|
send_capabilities(resource->handle, capability_keyboard | capability_pointer);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Seat::seat_get_keyboard(Resource *resource, uint32_t id)
|
||||||
|
{
|
||||||
|
m_keyboard->add(resource->client(), id);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Seat::seat_get_pointer(Resource *resource, uint32_t id)
|
||||||
|
{
|
||||||
|
m_pointer->add(resource->client(), id);
|
||||||
|
}
|
||||||
|
|
||||||
|
Keyboard::Keyboard(Compositor *compositor)
|
||||||
|
: wl_keyboard()
|
||||||
|
, m_compositor(compositor)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
Keyboard::~Keyboard()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
static wl_resource *resourceForSurface(wl_list *resourceList, Surface *surface)
|
||||||
|
{
|
||||||
|
if (!surface)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
wl_resource *r;
|
||||||
|
wl_client *surfaceClient = surface->resource()->client();
|
||||||
|
|
||||||
|
wl_list_for_each(r, resourceList, link) {
|
||||||
|
if (r->client == surfaceClient)
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Keyboard::setFocus(Surface *surface)
|
||||||
|
{
|
||||||
|
if (m_focusResource && m_focus != surface) {
|
||||||
|
uint32_t serial = m_compositor->nextSerial();
|
||||||
|
send_leave(m_focusResource->handle, serial, m_focus->resource()->handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct ::wl_resource *r = resourceForSurface(resourceList(), surface);
|
||||||
|
Resource *resource = r ? Resource::fromResource(r) : 0;
|
||||||
|
|
||||||
|
if (resource && (m_focus != surface || m_focusResource != resource)) {
|
||||||
|
uint32_t serial = m_compositor->nextSerial();
|
||||||
|
send_modifiers(resource->handle, serial, 0, 0, 0, 0);
|
||||||
|
send_enter(resource->handle, serial, surface->resource()->handle, QByteArray());
|
||||||
|
}
|
||||||
|
|
||||||
|
m_focusResource = resource;
|
||||||
|
m_focus = surface;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Keyboard::sendKey(uint32_t key, uint32_t state)
|
||||||
|
{
|
||||||
|
if (m_focusResource) {
|
||||||
|
uint32_t serial = m_compositor->nextSerial();
|
||||||
|
send_key(m_focusResource->handle, serial, m_compositor->time(), key, state);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Pointer::Pointer(Compositor *compositor)
|
||||||
|
: wl_pointer()
|
||||||
|
, m_compositor(compositor)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
Pointer::~Pointer()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void Pointer::setFocus(Surface *surface, const QPoint &pos)
|
||||||
|
{
|
||||||
|
if (m_focusResource && m_focus != surface) {
|
||||||
|
uint32_t serial = m_compositor->nextSerial();
|
||||||
|
send_leave(m_focusResource->handle, serial, m_focus->resource()->handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct ::wl_resource *r = resourceForSurface(resourceList(), surface);
|
||||||
|
Resource *resource = r ? Resource::fromResource(r) : 0;
|
||||||
|
|
||||||
|
if (resource && (m_focus != surface || resource != m_focusResource)) {
|
||||||
|
uint32_t serial = m_compositor->nextSerial();
|
||||||
|
send_enter(resource->handle, serial, surface->resource()->handle,
|
||||||
|
wl_fixed_from_int(pos.x()), wl_fixed_from_int(pos.y()));
|
||||||
|
}
|
||||||
|
|
||||||
|
m_focusResource = resource;
|
||||||
|
m_focus = surface;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Pointer::sendMotion(const QPoint &pos)
|
||||||
|
{
|
||||||
|
if (m_focusResource)
|
||||||
|
send_motion(m_focusResource->handle, m_compositor->time(),
|
||||||
|
wl_fixed_from_int(pos.x()), wl_fixed_from_int(pos.y()));
|
||||||
|
}
|
||||||
|
|
||||||
|
void Pointer::sendButton(uint32_t button, uint32_t state)
|
||||||
|
{
|
||||||
|
if (m_focusResource) {
|
||||||
|
uint32_t serial = m_compositor->nextSerial();
|
||||||
|
send_button(m_focusResource->handle, serial, m_compositor->time(),
|
||||||
|
button, state);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
119
tests/auto/wayland/mockinput.h
Normal file
119
tests/auto/wayland/mockinput.h
Normal file
@ -0,0 +1,119 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
|
||||||
|
** Copyright (C) 2013 Klarälvdalens Datakonsult AB (KDAB).
|
||||||
|
** Contact: http://www.qt-project.org/legal
|
||||||
|
**
|
||||||
|
** This file is part of the test suite of the Qt Toolkit.
|
||||||
|
**
|
||||||
|
** $QT_BEGIN_LICENSE:LGPL$
|
||||||
|
** Commercial License Usage
|
||||||
|
** Licensees holding valid commercial Qt licenses may use this file in
|
||||||
|
** accordance with the commercial license agreement provided with the
|
||||||
|
** Software or, alternatively, in accordance with the terms contained in
|
||||||
|
** a written agreement between you and Digia. For licensing terms and
|
||||||
|
** conditions see http://qt.digia.com/licensing. For further information
|
||||||
|
** use the contact form at http://qt.digia.com/contact-us.
|
||||||
|
**
|
||||||
|
** GNU Lesser General Public License Usage
|
||||||
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||||
|
** General Public License version 2.1 as published by the Free Software
|
||||||
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||||
|
** packaging of this file. Please review the following information to
|
||||||
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||||
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||||
|
**
|
||||||
|
** In addition, as a special exception, Digia gives you certain additional
|
||||||
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
||||||
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||||
|
**
|
||||||
|
** GNU General Public License Usage
|
||||||
|
** Alternatively, this file may be used under the terms of the GNU
|
||||||
|
** General Public License version 3.0 as published by the Free Software
|
||||||
|
** Foundation and appearing in the file LICENSE.GPL included in the
|
||||||
|
** packaging of this file. Please review the following information to
|
||||||
|
** ensure the GNU General Public License version 3.0 requirements will be
|
||||||
|
** met: http://www.gnu.org/copyleft/gpl.html.
|
||||||
|
**
|
||||||
|
**
|
||||||
|
** $QT_END_LICENSE$
|
||||||
|
**
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef MOCKINPUT_H
|
||||||
|
#define MOCKINPUT_H
|
||||||
|
|
||||||
|
#include <qglobal.h>
|
||||||
|
|
||||||
|
#include "qwayland-server-wayland.h"
|
||||||
|
|
||||||
|
#include "mockcompositor.h"
|
||||||
|
|
||||||
|
namespace Impl {
|
||||||
|
|
||||||
|
class Keyboard;
|
||||||
|
class Pointer;
|
||||||
|
|
||||||
|
class Seat : public QtWaylandServer::wl_seat
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Seat(Compositor *compositor, struct ::wl_display *display);
|
||||||
|
~Seat();
|
||||||
|
|
||||||
|
Compositor *compositor() const { return m_compositor; }
|
||||||
|
|
||||||
|
Keyboard *keyboard() const { return m_keyboard.data(); }
|
||||||
|
Pointer *pointer() const { return m_pointer.data(); }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void seat_bind_resource(Resource *resource) Q_DECL_OVERRIDE;
|
||||||
|
void seat_get_keyboard(Resource *resource, uint32_t id) Q_DECL_OVERRIDE;
|
||||||
|
void seat_get_pointer(Resource *resource, uint32_t id) Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
|
private:
|
||||||
|
Compositor *m_compositor;
|
||||||
|
|
||||||
|
QScopedPointer<Keyboard> m_keyboard;
|
||||||
|
QScopedPointer<Pointer> m_pointer;
|
||||||
|
};
|
||||||
|
|
||||||
|
class Keyboard : public QtWaylandServer::wl_keyboard
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Keyboard(Compositor *compositor);
|
||||||
|
~Keyboard();
|
||||||
|
|
||||||
|
Surface *focus() const { return m_focus; }
|
||||||
|
void setFocus(Surface *surface);
|
||||||
|
|
||||||
|
void sendKey(uint32_t key, uint32_t state);
|
||||||
|
|
||||||
|
private:
|
||||||
|
Compositor *m_compositor;
|
||||||
|
|
||||||
|
Resource *m_focusResource;
|
||||||
|
Surface *m_focus;
|
||||||
|
};
|
||||||
|
|
||||||
|
class Pointer : public QtWaylandServer::wl_pointer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Pointer(Compositor *compositor);
|
||||||
|
~Pointer();
|
||||||
|
|
||||||
|
Surface *focus() const { return m_focus; }
|
||||||
|
|
||||||
|
void setFocus(Surface *surface, const QPoint &pos);
|
||||||
|
void sendMotion(const QPoint &pos);
|
||||||
|
void sendButton(uint32_t button, uint32_t state);
|
||||||
|
|
||||||
|
private:
|
||||||
|
Compositor *m_compositor;
|
||||||
|
|
||||||
|
Resource *m_focusResource;
|
||||||
|
Surface *m_focus;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // MOCKINPUT_H
|
@ -45,7 +45,7 @@
|
|||||||
namespace Impl {
|
namespace Impl {
|
||||||
|
|
||||||
Surface::Surface(wl_client *client, uint32_t id, Compositor *compositor)
|
Surface::Surface(wl_client *client, uint32_t id, Compositor *compositor)
|
||||||
: QtWaylandServer::wl_surface(client, &base()->resource, id)
|
: QtWaylandServer::wl_surface(client, id)
|
||||||
, m_compositor(compositor)
|
, m_compositor(compositor)
|
||||||
, m_mockSurface(new MockSurface(this))
|
, m_mockSurface(new MockSurface(this))
|
||||||
{
|
{
|
||||||
@ -74,7 +74,7 @@ void Surface::surface_attach(Resource *resource,
|
|||||||
Q_UNUSED(resource);
|
Q_UNUSED(resource);
|
||||||
Q_UNUSED(x);
|
Q_UNUSED(x);
|
||||||
Q_UNUSED(y);
|
Q_UNUSED(y);
|
||||||
m_buffer = buffer ? static_cast<wl_buffer *>(buffer->data) : 0;
|
m_buffer = buffer;
|
||||||
|
|
||||||
if (!buffer)
|
if (!buffer)
|
||||||
m_mockSurface->image = QImage();
|
m_mockSurface->image = QImage();
|
||||||
@ -92,13 +92,21 @@ void Surface::surface_damage(Resource *resource,
|
|||||||
if (!m_buffer)
|
if (!m_buffer)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (wl_buffer_is_shm(m_buffer)) {
|
#if WAYLAND_VERSION_CHECK(1, 2, 0)
|
||||||
int stride = wl_shm_buffer_get_stride(m_buffer);
|
struct ::wl_shm_buffer *shm_buffer = wl_shm_buffer_get(m_buffer);
|
||||||
uint format = wl_shm_buffer_get_format(m_buffer);
|
#else
|
||||||
|
struct ::wl_buffer *shm_buffer = 0;
|
||||||
|
if (wl_buffer_is_shm(static_cast<struct ::wl_buffer*>(m_buffer->data)))
|
||||||
|
shm_buffer = static_cast<struct ::wl_buffer*>(m_buffer->data);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (shm_buffer) {
|
||||||
|
int stride = wl_shm_buffer_get_stride(shm_buffer);
|
||||||
|
uint format = wl_shm_buffer_get_format(shm_buffer);
|
||||||
Q_UNUSED(format);
|
Q_UNUSED(format);
|
||||||
void *data = wl_shm_buffer_get_data(m_buffer);
|
void *data = wl_shm_buffer_get_data(shm_buffer);
|
||||||
const uchar *char_data = static_cast<const uchar *>(data);
|
const uchar *char_data = static_cast<const uchar *>(data);
|
||||||
QImage img(char_data, m_buffer->width, m_buffer->height, stride, QImage::Format_ARGB32_Premultiplied);
|
QImage img(char_data, wl_shm_buffer_get_width(shm_buffer), wl_shm_buffer_get_height(shm_buffer), stride, QImage::Format_ARGB32_Premultiplied);
|
||||||
m_mockSurface->image = img;
|
m_mockSurface->image = img;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,15 +41,13 @@
|
|||||||
|
|
||||||
#include <qglobal.h>
|
#include <qglobal.h>
|
||||||
|
|
||||||
#include <QtCompositor/qwaylandobject.h>
|
|
||||||
|
|
||||||
#include "qwayland-server-wayland.h"
|
#include "qwayland-server-wayland.h"
|
||||||
|
|
||||||
#include "mockcompositor.h"
|
#include "mockcompositor.h"
|
||||||
|
|
||||||
namespace Impl {
|
namespace Impl {
|
||||||
|
|
||||||
class Surface : public QtWayland::Object<struct ::wl_surface>, public QtWaylandServer::wl_surface
|
class Surface : public QtWaylandServer::wl_surface
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Surface(wl_client *client, uint32_t id, Compositor *compositor);
|
Surface(wl_client *client, uint32_t id, Compositor *compositor);
|
||||||
@ -72,7 +70,7 @@ protected:
|
|||||||
uint32_t callback) Q_DECL_OVERRIDE;
|
uint32_t callback) Q_DECL_OVERRIDE;
|
||||||
void surface_commit(Resource *resource) Q_DECL_OVERRIDE;
|
void surface_commit(Resource *resource) Q_DECL_OVERRIDE;
|
||||||
private:
|
private:
|
||||||
wl_buffer *m_buffer;
|
wl_resource *m_buffer;
|
||||||
|
|
||||||
Compositor *m_compositor;
|
Compositor *m_compositor;
|
||||||
QSharedPointer<MockSurface> m_mockSurface;
|
QSharedPointer<MockSurface> m_mockSurface;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user