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 #ifndef MOCKCOMPOSITOR_H
43 #define MOCKCOMPOSITOR_H
47 #include <wayland-server.h>
52 #include <QSharedPointer>
55 #include <QWaitCondition>
59 typedef void (**Implementation)(void);
69 int fileDescriptor() const { return m_fd; }
70 void dispatchEvents(int timeout = 0);
72 uint32_t nextSerial();
73 uint32_t time() { return ++m_time; }
75 static void setOutputGeometry(void *compositor, const QList<QVariant> ¶meters);
77 QVector<Surface *> surfaces() const;
79 void addSurface(Surface *surface);
80 void removeSurface(Surface *surface);
82 static void setKeyboardFocus(void *data, const QList<QVariant> ¶meters);
83 static void sendMousePress(void *data, const QList<QVariant> ¶meters);
84 static void sendMouseRelease(void *data, const QList<QVariant> ¶meters);
85 static void sendKeyPress(void *data, const QList<QVariant> ¶meters);
86 static void sendKeyRelease(void *data, const QList<QVariant> ¶meters);
89 static void bindCompositor(wl_client *client, void *data, uint32_t version, uint32_t id);
90 static void bindSeat(wl_client *client, void *data, uint32_t version, uint32_t id);
91 static void bindOutput(wl_client *client, void *data, uint32_t version, uint32_t id);
92 static void bindShell(wl_client *client, void *data, uint32_t version, uint32_t id);
94 static void get_pointer(wl_client *client, wl_resource *resource, uint32_t id);
95 static void get_keyboard(wl_client *client, wl_resource *resource, uint32_t id);
96 static void get_touch(wl_client *client, wl_resource *resource, uint32_t id);
98 static void destroyInputResource(wl_resource *resource);
102 void sendOutputGeometry(wl_resource *resource);
103 void sendOutputMode(wl_resource *resource);
105 QRect m_outputGeometry;
107 wl_display *m_display;
108 wl_event_loop *m_loop;
112 wl_list m_outputResources;
116 wl_pointer m_pointer;
117 wl_keyboard m_keyboard;
118 QVector<Surface *> m_surfaces;
121 void registerResource(wl_list *list, wl_resource *resource);
128 Impl::Surface *handle() const { return m_surface; }
133 MockSurface(Impl::Surface *surface);
134 friend class Impl::Compositor;
135 friend class Impl::Surface;
137 Impl::Surface *m_surface;
140 Q_DECLARE_METATYPE(QSharedPointer<MockSurface>)
148 void applicationInitialized();
150 int waylandFileDescriptor() const;
151 void processWaylandEvents();
153 void setOutputGeometry(const QRect &rect);
154 void setKeyboardFocus(const QSharedPointer<MockSurface> &surface);
155 void sendMousePress(const QSharedPointer<MockSurface> &surface, const QPoint &pos);
156 void sendMouseRelease(const QSharedPointer<MockSurface> &surface);
157 void sendKeyPress(const QSharedPointer<MockSurface> &surface, uint code);
158 void sendKeyRelease(const QSharedPointer<MockSurface> &surface, uint code);
160 QSharedPointer<MockSurface> surface();
168 typedef void (*Callback)(void *target, const QList<QVariant> ¶meters);
172 QList<QVariant> parameters;
175 static Command makeCommand(Command::Callback callback, void *target);
177 void processCommand(const Command &command);
178 void dispatchCommands();
180 static void *run(void *data);
186 QWaitCondition m_waitCondition;
188 Impl::Compositor *m_compositor;
190 QList<Command> m_commandQueue;