Compositor memory leak fixes
[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 QPoint &localPos, const QPoint &globalPos)
59 {
60     d->sendMousePressEvent(button,localPos,globalPos);
61 }
62
63 void WaylandInputDevice::sendMouseReleaseEvent(Qt::MouseButton button, const QPoint &localPos, const QPoint &globalPos)
64 {
65     d->sendMouseReleaseEvent(button,localPos,globalPos);
66 }
67
68 void WaylandInputDevice::sendMouseMoveEvent(const QPoint &localPos, const QPoint &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 QPoint &localPos, const QPoint &globalPos)
77 {
78     Wayland::Surface *wlsurface = surface? surface->handle():0;
79     d->sendMouseMoveEvent(wlsurface,localPos,globalPos);
80 }
81
82 void WaylandInputDevice::sendKeyPressEvent(uint code)
83 {
84     d->sendKeyPressEvent(code);
85 }
86
87 void WaylandInputDevice::sendKeyReleaseEvent(uint code)
88 {
89     d->sendKeyReleaseEvent(code);
90 }
91
92 void WaylandInputDevice::sendTouchPointEvent(int id, int x, int y, Qt::TouchPointState state)
93 {
94     d->sendTouchPointEvent(id,x,y,state);
95 }
96
97 void WaylandInputDevice::sendTouchFrameEvent()
98 {
99     d->sendTouchFrameEvent();
100 }
101
102 void WaylandInputDevice::sendTouchCancelEvent()
103 {
104     d->sendTouchCancelEvent();
105 }
106
107 void WaylandInputDevice::sendFullTouchEvent(QTouchEvent *event)
108 {
109     d->sendFullTouchEvent(event);
110 }
111
112 WaylandSurface *WaylandInputDevice::keyboardFocus() const
113 {
114     Wayland::Surface *wlsurface = d->keyboardFocus();
115     if (wlsurface)
116         return  wlsurface->waylandSurface();
117     return 0;
118 }
119
120 void WaylandInputDevice::setKeyboardFocus(WaylandSurface *surface)
121 {
122     Wayland::Surface *wlsurface = surface?surface->handle():0;
123     d->setKeyboardFocus(wlsurface);
124 }
125
126 WaylandSurface *WaylandInputDevice::mouseFocus() const
127 {
128     Wayland::Surface *wlsurface = d->mouseFocus();
129     if (wlsurface)
130         return  wlsurface->waylandSurface();
131     return 0;
132 }
133
134 void WaylandInputDevice::setMouseFocus(WaylandSurface *surface, const QPoint &localPos, const QPoint &globalPos)
135 {
136     Wayland::Surface *wlsurface = surface?surface->handle():0;
137     d->setMouseFocus(wlsurface,localPos,globalPos);
138 }
139
140 WaylandCompositor *WaylandInputDevice::compositor() const
141 {
142     return d->compositor()->waylandCompositor();
143 }
144
145 Wayland::InputDevice *WaylandInputDevice::handle() const
146 {
147     return d;
148 }
149
150