A few fixes to prevent compositor crashes
[profile/ivi/qtwayland.git] / src / compositor / compositor_api / waylandinput.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the Qt Compositor.
7 **
8 ** $QT_BEGIN_LICENSE:BSD$
9 ** You may use this file under the terms of the BSD license as follows:
10 **
11 ** "Redistribution and use in source and binary forms, with or without
12 ** modification, are permitted provided that the following conditions are
13 ** met:
14 **   * Redistributions of source code must retain the above copyright
15 **     notice, this list of conditions and the following disclaimer.
16 **   * Redistributions in binary form must reproduce the above copyright
17 **     notice, this list of conditions and the following disclaimer in
18 **     the documentation and/or other materials provided with the
19 **     distribution.
20 **   * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
21 **     the names of its contributors may be used to endorse or promote
22 **     products derived from this software without specific prior written
23 **     permission.
24 **
25 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
36 **
37 ** $QT_END_LICENSE$
38 **
39 ****************************************************************************/
40
41 #include "waylandinput.h"
42
43 #include "wlinputdevice.h"
44 #include "waylandcompositor.h"
45 #include "wlsurface.h"
46 #include "wlcompositor.h"
47
48 WaylandInputDevice::WaylandInputDevice(WaylandCompositor *compositor)
49     : d(new Wayland::InputDevice(this,compositor->handle()))
50 {
51 }
52
53 WaylandInputDevice::~WaylandInputDevice()
54 {
55     delete d;
56 }
57
58 void WaylandInputDevice::sendMousePressEvent(Qt::MouseButton button, const QPointF &localPos, const QPointF &globalPos)
59 {
60     d->sendMousePressEvent(button,localPos,globalPos);
61 }
62
63 void WaylandInputDevice::sendMouseReleaseEvent(Qt::MouseButton button, const QPointF &localPos, const QPointF &globalPos)
64 {
65     d->sendMouseReleaseEvent(button,localPos,globalPos);
66 }
67
68 void WaylandInputDevice::sendMouseMoveEvent(const QPointF &localPos, const QPointF &globalPos)
69 {
70     d->sendMouseMoveEvent(localPos,globalPos);
71 }
72
73 /** Convenience function that will set the mouse focus to the surface, then send the mouse move event.
74  *  If the mouse focus is the same surface as the surface passed in, then only the move event is sent
75  **/
76 void WaylandInputDevice::sendMouseMoveEvent(WaylandSurface *surface, const QPointF &localPos, const QPointF &globalPos)
77 {
78     Wayland::Surface *wlsurface = surface? surface->handle():0;
79     d->sendMouseMoveEvent(wlsurface,localPos,globalPos);
80 }
81
82 void WaylandInputDevice::sendMouseWheelEvent(Qt::Orientation orientation, int delta)
83 {
84     d->sendMouseWheelEvent(orientation, delta);
85 }
86
87 void WaylandInputDevice::sendKeyPressEvent(uint code)
88 {
89     d->sendKeyPressEvent(code);
90 }
91
92 void WaylandInputDevice::sendKeyReleaseEvent(uint code)
93 {
94     d->sendKeyReleaseEvent(code);
95 }
96
97 void WaylandInputDevice::sendTouchPointEvent(int id, double x, double y, Qt::TouchPointState state)
98 {
99     d->sendTouchPointEvent(id,x,y,state);
100 }
101
102 void WaylandInputDevice::sendTouchFrameEvent()
103 {
104     d->sendTouchFrameEvent();
105 }
106
107 void WaylandInputDevice::sendTouchCancelEvent()
108 {
109     d->sendTouchCancelEvent();
110 }
111
112 void WaylandInputDevice::sendFullTouchEvent(QTouchEvent *event)
113 {
114     d->sendFullTouchEvent(event);
115 }
116
117 void WaylandInputDevice::sendFullKeyEvent(QKeyEvent *event)
118 {
119     d->sendFullKeyEvent(event);
120 }
121
122 WaylandSurface *WaylandInputDevice::keyboardFocus() const
123 {
124     Wayland::Surface *wlsurface = d->keyboardFocus();
125     if (wlsurface)
126         return  wlsurface->waylandSurface();
127     return 0;
128 }
129
130 void WaylandInputDevice::setKeyboardFocus(WaylandSurface *surface)
131 {
132     Wayland::Surface *wlsurface = surface?surface->handle():0;
133     d->setKeyboardFocus(wlsurface);
134 }
135
136 WaylandSurface *WaylandInputDevice::mouseFocus() const
137 {
138     Wayland::Surface *wlsurface = d->mouseFocus();
139     if (wlsurface)
140         return  wlsurface->waylandSurface();
141     return 0;
142 }
143
144 void WaylandInputDevice::setMouseFocus(WaylandSurface *surface, const QPointF &localPos, const QPointF &globalPos)
145 {
146     Wayland::Surface *wlsurface = surface?surface->handle():0;
147     d->setMouseFocus(wlsurface,localPos,globalPos);
148 }
149
150 WaylandCompositor *WaylandInputDevice::compositor() const
151 {
152     return d->compositor()->waylandCompositor();
153 }
154
155 Wayland::InputDevice *WaylandInputDevice::handle() const
156 {
157     return d;
158 }
159
160