Merge "Build and package Layer Management service binaries." into tizen
[profile/ivi/layer-management.git] / LayerManagerPlugins / Renderers / Graphic / include / WindowSystems / WaylandInputDevice.h
1 /***************************************************************************
2  *
3  * Copyright 2010, 2011 BMW Car IT GmbH
4  * Copyright (C) 2011 DENSO CORPORATION and Robert Bosch Car Multimedia Gmbh
5  *
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *        http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  *
20  * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
21  * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
22  * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
23  * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
24  * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
25  * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
26  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
27  *
28  ****************************************************************************/
29 #ifndef _WAYLANDINPUTDEVICE_H_
30 #define _WAYLANDINPUTDEVICE_H_
31 #include <wayland-server.h>
32 #include "Log.h"
33 #include "config.h"
34 #include "InputManager.h"
35
36 //////////////////////////////////////////////////////////////////////////////
37 class WaylandInputDevice
38 {
39 // Properties
40 private:
41     struct wl_display* m_wlDisplay;
42     struct wl_seat*    m_wlSeat;
43     bool               m_hasPointer;
44     bool               m_hasKeyboard;
45     bool               m_hasTouch;
46     int                m_nTp;
47
48     struct wl_surface*  m_wlTouchFocus;
49     struct wl_listener  m_wlTouchFocusListener;
50     struct wl_resource* m_wlTouchFocusResource;
51     struct wl_listener  m_wlTouchFocusResourceListener;
52
53     struct
54     {
55         struct wl_pointer*  wlPointer;
56         struct wl_keyboard* wlKeyboard;
57         struct wl_touch*    wlTouch;
58     } m_deviceInterfaces;
59
60 // Methods
61 public:
62     WaylandInputDevice(wl_display *display);
63     virtual ~WaylandInputDevice();
64
65     void initPointerDevice();
66     void initKeyboardDevice();
67     void initTouchDevice();
68
69     struct wl_display* display();
70     struct wl_seat* seat();
71     bool hasPointer() const;
72     bool hasKeyboard() const;
73     bool hasTouch() const;
74
75     struct wl_pointer  *pointerDevice();
76     struct wl_keyboard *keyboardDevice();
77     struct wl_touch    *touchDevice();
78     const struct wl_pointer  *pointerDevice() const;
79     const struct wl_keyboard *keyboardDevice() const;
80     const struct wl_touch    *touchDevice() const;
81
82     void sendMousePressEvent(const Point& globalPos, const Point& localPos,
83                                 uint32_t button, uint32_t time);
84     void sendMouseReleaseEvent(const Point& globalPos, const Point& localPos,
85                                 uint32_t button, uint32_t time);
86     void sendMouseMotionEvent(struct wl_surface *surface,
87                                 const Point& globalPos, const Point& localPos, uint32_t time);
88
89     void sendKeyPressEvent(struct wl_surface *surface, uint32_t time, uint32_t code);
90     void sendKeyReleaseEvent(struct wl_surface *surface, uint32_t time, uint32_t code);
91     void setKeyboardFocus(struct wl_surface *surface);
92
93     void sendTouchPointEvent(struct wl_surface *surface, uint32_t time,
94                                 int touchId, int touchState, const Point& touchPos);
95     void sendTouchFrameEvent();
96     void sendTouchCancelEvent();
97
98     void sendModifiers(uint32_t serial);
99
100 private:
101     void releaseDevices();
102     void cleanupDataDeviceForClient(struct wl_client *client, bool destroyDev);
103
104     void setMouseFocus(struct wl_surface *surface,
105                         const Point& globalPos,
106                         const Point& localPos);
107     void sendMouseMotionEvent(const Point& globalPos,
108                                 const Point& localPos,
109                                 uint32_t time);
110
111     void setTouchFocus(struct wl_surface *surface);
112
113     const static struct wl_seat_interface m_seatInterface;
114
115     static void bindInputDevice(struct wl_client *client,
116                                 void *data,
117                                 uint32_t version,
118                                 uint32_t id);
119     static void destroyResource(struct wl_resource *resource);
120     static void destroyDeviceResource(struct wl_resource *resource);
121
122     static void getPointer(struct wl_client *client,
123                             struct wl_resource *resource,
124                             uint32_t id);
125     static void getKeyboard(struct wl_client *client,
126                             struct wl_resource *resource,
127                             uint32_t id);
128     static void getTouch(struct wl_client *client,
129                             struct wl_resource *resource,
130                             uint32_t id);
131 };
132
133 inline struct wl_display* WaylandInputDevice::display()
134 {
135     return m_wlDisplay;
136 }
137
138 inline struct wl_seat* WaylandInputDevice::seat()
139 {
140     return m_wlSeat;
141 }
142
143 inline bool WaylandInputDevice::hasPointer() const
144 {
145     return m_hasPointer;
146 }
147
148 inline bool WaylandInputDevice::hasKeyboard() const
149 {
150     return m_hasKeyboard;
151 }
152
153 inline bool WaylandInputDevice::hasTouch() const
154 {
155     return m_hasTouch;
156 }
157
158 inline struct wl_pointer* WaylandInputDevice::pointerDevice()
159 {
160     return m_deviceInterfaces.wlPointer;
161 }
162
163 inline struct wl_keyboard* WaylandInputDevice::keyboardDevice()
164 {
165     return m_deviceInterfaces.wlKeyboard;
166 }
167
168 inline struct wl_touch* WaylandInputDevice::touchDevice()
169 {
170     return m_deviceInterfaces.wlTouch;
171 }
172
173 inline const struct wl_pointer* WaylandInputDevice::pointerDevice() const
174 {
175     return m_deviceInterfaces.wlPointer;
176 }
177
178 inline const struct wl_keyboard* WaylandInputDevice::keyboardDevice() const
179 {
180     return m_deviceInterfaces.wlKeyboard;
181 }
182
183 inline const struct wl_touch* WaylandInputDevice::touchDevice() const
184 {
185     return m_deviceInterfaces.wlTouch;
186 }
187
188 #endif /* _WAYLANDINPUTDEVICE_H_ */