8ca663e3f603d0bdda8cd31c1438ea627da01611
[platform/core/uifw/dali-adaptor.git] / adaptors / wayland / input / input-interface.h
1 #ifndef __DALI_INTERNAL_ADAPTOR_INPUT_INTERFACE_H__
2 #define __DALI_INTERNAL_ADAPTOR_INPUT_INTERFACE_H__
3
4 /*
5  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
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
21 // EXTERNAL INCLUDES
22 #include <wl-types.h>
23
24
25 namespace Dali
26 {
27
28 namespace Internal
29 {
30
31 namespace Adaptor
32 {
33
34 class Seat;
35
36 /**
37  * @brief interface used by the Wayland input listeners to signal an event.
38  *
39  * The events that come from keyboard, pointer and touch devices are from a specific seat.
40  * A single seat can have multiple keyboards, pointers and touch devices connected to it.
41  *
42  * For example you can have a car with 4 seats each with their own touch screen that
43  * are run by a central device with multi-display output.
44  *
45  * Some input events have serial numbers and time stamps.
46  *
47  * Serial numbers description from Wayland documentation:
48  * "To avoid race conditions, input events that are likely to trigger further requests
49  * (such as button presses, key events, pointer motions) carry serial numbers, and requests such as
50  * wl_surface.set_popup require that the serial number of the triggering event is specified."
51  *
52  *  Time stamps description from Wayland documentation:
53  * "Input events also carry timestamps with millisecond granularity.
54  *  Their base is undefined, so they can't be compared against system time
55  *  (as obtained with clock_gettime or gettimeofday). They can be compared
56  *  with each other though, and for instance be used to identify sequences
57  *  of button presses as double or triple clicks."
58  */
59 class InputInterface
60 {
61
62 public: // Pointer events. See wl_pointer_listener in wayland-client-protocol.h for more information.
63
64   /**
65    * @brief Called when a seat's pointer has entered a surface
66    *
67    * When focus enters a surface, the pointer image is
68    * undefined and a client should respond to this event by setting
69    * an appropriate pointer image with the set_cursor request.
70    *
71    * @param[in] seat the seat that produced the event
72    * @param[in] serial  serial number
73    * @param[in] surface surface
74    * @param[in] x x coordinate in surface-relative coordinates ( not screen )
75    * @param[in] y y coordinate in surface-relative coordinates ( not screen )
76    */
77   virtual void PointerEnter( Seat* seat, unsigned int serial, WlSurface* surface, float x, float y) = 0;
78
79   /**
80    * @brief Called when a seat's pointer leaves a surface
81    * @param[in] seat the seat that produced the event
82    * @param[in] serial serial number
83    * @param[in] surface surface
84    *
85    * The leave notification is sent before the enter notification for
86    * the new focus.
87    */
88   virtual void PointerLeave( Seat* seat, unsigned int serial, WlSurface* surface ) = 0;
89
90   /**
91    * @brief pointer motion event
92    *
93    * @param[in] seat the seat that produced the event
94    * @param[in] timestamp timestamp with millisecond granularity
95    * @param[in] x x coordinate in surface-relative coordinates ( not screen )
96    * @param[in] y y coordinate in surface-relative coordinates ( not screen )
97    *
98    */
99   virtual void PointerMotion( Seat* seat, unsigned int timestamp, float x, float y ) = 0;
100
101   /**
102    * @brief pointer click and release events
103    *
104    * @param[in] seat the seat that produced the event
105    * @param[in] serial serial number
106    * @param[in] timestamp timestamp with millisecond granularity
107    * @param[in] button pointer button pressed
108    * @param[in] state button state ( 1 = down, 0 = up)
109    *
110    * The location of the click is given by the last motion or enter
111    * event.
112    */
113   virtual void PointerButton( Seat* seat, unsigned int serial, unsigned int timestamp, unsigned int button, unsigned int state ) = 0;
114
115   /**
116    * @brief Pointer scroll and other axis notifications.
117    *
118    * @param[in] seat the seat that produced the event
119    * @param[in] timestamp timestamp with millisecond granularity
120    * @param[in] axis pointer axis
121    * @param[in] value length of a vector along the specified axis in a coordinate space identical to those of motion event
122   */
123   virtual void PointerAxis( Seat* seat, unsigned int timestamp, unsigned int axis, float value ) = 0;
124
125 public: // Key  events. See wl_keyboard_listener in wayland-client-protocol.h for more information.
126
127   /**
128    * @brief keyboard mapping
129    * Provides a file descriptor which can be memory-mapped to a keyboard mapping description
130    *
131    * @param[in] seat the seat that produced the event
132    * @param[in] format see wl_keyboard_keymap_format
133    * @param[in] fd  file descriptor
134    * @param[in] size size of the memory mapped region in bytes
135   */
136   virtual void KeyboardKeymap( Seat* seat, unsigned int format, int fd, unsigned int size ) = 0;
137
138   /**
139    * @brief The seat's keyboard focus has entered a surface
140    *
141    * @param[in] seat the seat that produced the event
142    * @param[in] serial serial number
143    * @param[in] surface surface
144    * @param[in] keys the currently pressed keys
145    */
146   virtual void KeyFocusEnter( Seat* seat, unsigned int serial, WlSurface* surface, WlArray* keys ) = 0;
147
148   /**
149    * @brief The seat's keyboard focus has left a surface
150    *
151    * The leave notification is sent before the enter notification for the new focus.
152    * @param[in] seat the seat that produced the event
153    * @param[in] serial serial number
154    * @param[in] surface surface
155    */
156   virtual void KeyFocusLeave( Seat* seat, unsigned int serial, WlSurface* surface ) = 0;
157
158   /**
159    * @brief Key has been pressed or released
160    *
161    * @param[in] seat the seat that produced the event
162    * @param[in] serial serial number
163    * @param[in] timestamp timestamp
164    * @param[in] keycode raw hardware key code
165    * @param[in] state
166    */
167   virtual void KeyEvent( Seat* seat, unsigned int serial, unsigned int timestamp, unsigned int keycode, unsigned int state) = 0;
168
169   /**
170    * @brief Key modifier state has changed
171    *
172    * @param[in] seat the seat that produced the event
173    * @param[in] serial serial number
174    * @param[in] depressed modifiers depressed
175    * @param[in] latched modifiers latched
176    * @param[in] locked modifiers locked
177    * @param[in[ group group
178    */
179   virtual void KeyModifiers( Seat* seat,
180                             unsigned int serial,
181                             unsigned int depressed,
182                             unsigned int latched,
183                             unsigned int locked,
184                             unsigned int group) = 0;
185
186
187   /**
188    * @brief Key repeat rate and delay.
189    *
190    * Informs DALi of the keyboard's repeat rate and delay.
191    *
192    * Event sent when wl_keyboard object created, before any key events
193    * If rate == zero, repeating is disabled
194    *
195    * @param[in] seat the seat that produced the event
196    * @param[in] rate rate of repeating keys in characters per second
197    * @param[in] delay delay in milliseconds since key down until repeating starts
198    */
199   virtual void KeyRepeatInfo( Seat* seat, int32_t rate, int32_t delay) = 0;
200
201
202 public: // touch  events. See wl_touch_listener in wayland-client-protocol.h for more information.
203
204   /**
205    * @brief Touch down event on a surface.
206    *
207    * Future events from this touch point will have the same id which is valid
208    * until a touch up event.
209    * @param[in] seat the seat that produced the event
210    * @param[in] serial serial number
211    * @param[in] timestamp timestamp
212    * @param[in] surface surface
213    * @param[in] touchId unique touch id valid until touch is released
214    * @param[in] x coordinate in surface-relative coordinates
215    * @param[in[ y coordinate in surface-relative coordinates
216    */
217   virtual void TouchDown( Seat* seat, unsigned int serial, unsigned int timestamp, WlSurface* surface, int touchId, float x, float y) = 0;
218
219   /**
220    * @brief Touch up event on a surface.
221    *
222    * @param[in] seat the seat that produced the event
223    * @param[in] serial serial number
224    * @param[in] timestamp timestamp with millisecond granularity
225    * @param[in] touchId unique touch id valid until touch is released ( can be re-used for future events)
226    */
227   virtual void TouchUp( Seat* seat, unsigned int serial, unsigned int timestamp, int touchId ) = 0;
228
229   /**
230    * @brief Touch Motion event on a surface.
231    * Events relating to the same touch point can be identified by the touchId
232    *
233    * @param[in] seat the seat that produced the event
234    * @param[in] timestamp timestamp with millisecond granularity
235    * @param[in] touchId unique touch id valid until touch is released ( then can be re-used)
236    * @param[in] x coordinate in surface-relative coordinates
237    * @param[in[ y coordinate in surface-relative coordinates
238    */
239   virtual void TouchMotion( Seat* seat, unsigned int timestamp, int touchId, float x, float y ) = 0;
240
241   /**
242    * @brief  end of touch frame event
243    * Unsure what this means.
244    * @param[in] seat the seat that produced the event
245    */
246   virtual void TouchFrame( Seat* seat ) = 0;
247
248   /**
249    * @brief  Cancel current touch session
250    * If Wayland Compositor decides current touch stream is a global
251    * gesture we have to cancel any touch / gesture detection.
252    *
253    * Touch cancellation applies to all touch points currently active on
254    * our surface. TouchPoint::Interrupted will be sent to dali-core
255    *
256    * @param[in] seat the seat that produced the event
257    */
258   virtual void TouchCancel( Seat* seat ) = 0;
259
260 public: // Helper functions used to find the seat associated with the keyboard/pointer/touch device
261
262   /**
263    * @brief get the seat that contains the keyboard interface
264    * @param[in] keyboard wayland keyboard interface
265    * @return the seat the keyboard belongs to
266    */
267   virtual Seat* GetSeat( const WlKeyboard* keyboard ) = 0;
268
269   /**
270    * @brief get the seat that contains the pointer interface
271    * @param[in] pointer wayland pointer interface
272    * @return the seat the pointer belongs to
273    */
274   virtual Seat* GetSeat( const WlPointer* pointer ) = 0;
275
276   /**
277    * @brief get the seat that contains the touch interface
278    * @param[in] touch wayland touch interface
279    * @return the seat the touch device belongs to
280    */
281   virtual Seat* GetSeat( const WlTouch* touch ) = 0;
282
283   /**
284    * @brief get the seat that contains the wayland seat interface
285    * @param[in] seat wayland seat interface
286    * @return the seat the touch device belongs to
287    */
288   virtual Seat* GetSeat( const WlSeat* seat ) = 0;
289
290 protected:
291
292   /**
293    * @brief Constructor
294    */
295   InputInterface()
296   {
297   }
298
299   /**
300    * @brief destructor
301    */
302   virtual ~InputInterface()
303   {
304   }
305
306   // Undefined copy constructor.
307   InputInterface( const InputInterface& );
308
309   // Undefined assignment operator.
310   InputInterface& operator=( const InputInterface& );
311 };
312
313
314
315 } // Internal
316 } // Adaptor
317 } // Dali
318
319 #endif  //__DALI_INTERNAL_ADAPTOR_INPUT_INTERFACE_H__