1 /****************************************************************************
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
6 ** This file is part of the test suite of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
40 ****************************************************************************/
42 #include "mockcompositor.h"
43 #include "mocksurface.h"
47 void Compositor::destroyInputResource(wl_resource *resource)
49 Compositor *compositor = static_cast<Compositor *>(resource->data);
50 wl_keyboard *keyboard = &compositor->m_keyboard;
51 wl_pointer *pointer = &compositor->m_pointer;
53 if (keyboard->focus_resource == resource)
54 keyboard->focus_resource = 0;
55 if (pointer->focus_resource == resource)
56 pointer->focus_resource = 0;
58 wl_list_remove(&resource->link);
63 static void destroyInputDevice(wl_resource *resource)
65 wl_list_remove(&resource->link);
69 void pointer_attach(wl_client *client,
70 wl_resource *device_resource,
72 wl_resource *buffer_resource, int32_t x, int32_t y)
75 Q_UNUSED(device_resource);
77 Q_UNUSED(buffer_resource);
78 Q_UNUSED(QPoint(x, y));
81 void Compositor::get_pointer(wl_client *client,
82 wl_resource *resource,
85 static const struct wl_pointer_interface pointer_interface = {
88 Compositor *compositor = static_cast<Compositor *>(resource->data);
89 wl_pointer *pointer = &compositor->m_pointer;
90 wl_resource *clientResource = wl_client_add_object(client,
91 &wl_pointer_interface,
95 wl_list_insert(&pointer->resource_list, &clientResource->link);
96 clientResource->destroy = destroyInputDevice;
99 void Compositor::get_keyboard(wl_client *client,
100 wl_resource *resource,
103 Compositor *compositor = static_cast<Compositor *>(resource->data);
104 wl_keyboard *keyboard = &compositor->m_keyboard;
105 wl_resource *clientResource = wl_client_add_object(client,
106 &wl_keyboard_interface,
110 wl_list_insert(&keyboard->resource_list, &clientResource->link);
111 clientResource->destroy = destroyInputDevice;
114 void Compositor::get_touch(wl_client *client,
115 wl_resource *resource,
123 void Compositor::bindSeat(wl_client *client, void *compositorData, uint32_t version, uint32_t id)
125 static const struct wl_seat_interface seatInterface = {
132 wl_resource *resource = wl_client_add_object(client, &wl_seat_interface, &seatInterface, id, compositorData);
133 resource->destroy = destroyInputResource;
135 Compositor *compositor = static_cast<Compositor *>(compositorData);
136 wl_list_insert(&compositor->m_seat.base_resource_list, &resource->link);
138 wl_seat_send_capabilities(resource, WL_SEAT_CAPABILITY_POINTER | WL_SEAT_CAPABILITY_KEYBOARD);
141 static wl_surface *resolveSurface(const QVariant &v)
143 QSharedPointer<MockSurface> mockSurface = v.value<QSharedPointer<MockSurface> >();
144 Surface *surface = mockSurface ? mockSurface->handle() : 0;
145 return surface ? surface->handle() : 0;
148 void Compositor::setKeyboardFocus(void *data, const QList<QVariant> ¶meters)
150 Compositor *compositor = static_cast<Compositor *>(data);
151 wl_keyboard_set_focus(&compositor->m_keyboard, resolveSurface(parameters.first()));
154 void Compositor::sendMousePress(void *data, const QList<QVariant> ¶meters)
156 Compositor *compositor = static_cast<Compositor *>(data);
157 wl_surface *surface = resolveSurface(parameters.first());
161 QPoint pos = parameters.last().toPoint();
162 wl_pointer_set_focus(&compositor->m_pointer, surface,
163 wl_fixed_from_int(pos.x()), wl_fixed_from_int(pos.y()));
164 wl_pointer_send_motion(compositor->m_pointer.focus_resource, compositor->time(),
165 wl_fixed_from_double(pos.x()), wl_fixed_from_double(pos.y()));
166 wl_pointer_send_button(compositor->m_pointer.focus_resource,
167 compositor->nextSerial(), compositor->time(), 0x110, 1);
170 void Compositor::sendMouseRelease(void *data, const QList<QVariant> ¶meters)
172 Compositor *compositor = static_cast<Compositor *>(data);
173 wl_surface *surface = resolveSurface(parameters.first());
177 wl_pointer_send_button(compositor->m_pointer.focus_resource,
178 compositor->nextSerial(), compositor->time(), 0x110, 0);
181 void Compositor::sendKeyPress(void *data, const QList<QVariant> ¶meters)
183 Compositor *compositor = static_cast<Compositor *>(data);
184 wl_surface *surface = resolveSurface(parameters.first());
188 wl_keyboard_send_key(compositor->m_keyboard.focus_resource,
189 compositor->nextSerial(), compositor->time(), parameters.last().toUInt() - 8, 1);
192 void Compositor::sendKeyRelease(void *data, const QList<QVariant> ¶meters)
194 Compositor *compositor = static_cast<Compositor *>(data);
195 wl_surface *surface = resolveSurface(parameters.first());
199 wl_keyboard_send_key(compositor->m_keyboard.focus_resource,
200 compositor->nextSerial(), compositor->time(), parameters.last().toUInt() - 8, 0);