Merge "Fix security SVACE issue" into devel/master
[platform/core/uifw/dali-adaptor.git] / adaptors / wayland / input / seat.h
1 #ifndef __DALI_WAYLAND_SEAT_H__
2 #define __DALI_WAYLAND_SEAT_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 <string>
23 #include <xkbcommon/xkbcommon.h>
24 #include <dali/public-api/math/vector2.h>
25 #include <dali/public-api/events/key-event.h>
26
27 // INTERNAL INCLUDES
28 #include <wl-types.h>
29
30
31 namespace Dali
32 {
33
34 namespace Internal
35 {
36
37 namespace Adaptor
38 {
39
40 class InputInterface;
41
42 /**
43  *
44  * A single seat is a group of keyboards, pointers and touch devices.
45  *
46  * For example you can have a car with 4 seats each with their own touch screen that
47  * is run by a central computer with a multi-display output.
48  *
49  * Or you may have two people / two seats in an office sharing the same screen at the same time.
50  *
51  *
52  * There is a single wl_pointer / wl_touch and wl_keyboard interface per seat.
53  * But each interface can have multiple devices. E.g. wl_pointer interface may have 2
54  * mouse pointers attached.
55  *
56  * Input devices can be hot plugged. However wl_pointer / wl_touch and wl_keyboard interface
57  * will only be destroyed when the interface has no devices associated with it.
58  * E.g. if a seat has a single mouse, when you unplug the mouse the interface is deleted.
59  * If a seat has two mice, only when you unplug both mice is the interface deleted.
60  *
61  */
62 class Seat
63 {
64
65 public:
66
67   /**
68    * @brief Seat interface status for a device class ( keyboard, touch, pointer )
69    */
70   enum InterfaceStatus
71   {
72     INTERFACE_AVAILABLE,      ///< Occurs when at least 1 device for this device class is plugged in
73     INTERFACE_NOT_AVAILABLE,  ///< Occurs when all devices for a device class are unplugged (e.g. all mice )
74   };
75
76   /**
77    * @brief constructor
78    * @param[in] inputInterface input interface
79    * @param[in] seatInterface Wayland seat interface
80    */
81   Seat( InputInterface* inputInterface, WlSeat* seatInterface );
82
83   /**
84    * @brief non virtual destructor, not intended as base class
85    */
86   ~Seat();
87
88   /**
89    * @brief set Tizen Wayland Text Input interface
90    * @param[in] textInputManager interface
91    */
92   void SetTextInputInterface( WlTextInput* textInput );
93
94   /**
95    * @brief set the surface
96    * @param[in] surface Wayland surface currently associated with this seat ( for input panel / IMF )
97    */
98   void SetSurfaceInterface( WlSurface* surface );
99
100   /**
101    * @brief Set the pointer interface
102    * @param[in] pointer Wayland pointer interface
103    * @param[in] status of the interface
104    */
105   void SetPointerInterface( InterfaceStatus status );
106
107   /**
108    * @brief Set the touch interface
109    * @param[in] pointer Wayland pointer interface
110    * @param[in] status of the interface
111    */
112   void SetTouchInterface( InterfaceStatus status );
113
114   /**
115    * @brief Set the keyboard interface
116    * @param[in] pointer Wayland pointer interface
117    * @param[in] status of the interface
118    */
119   void SetKeyboardInterface( InterfaceStatus status );
120
121   /**
122    * @brief Get the pointer interface
123    * @return Wayland pointer interface
124    */
125   WlPointer* GetPointerInterface();
126
127   /**
128    * @brief Get the touch interface
129    * @return Wayland touch interface
130    */
131   WlTouch* GetTouchInterface();
132
133   /**
134    * @brief Get the keyboard interface
135    * @return Wayland keyboard interface
136    */
137   WlKeyboard* GetKeyboardInterface();
138
139   /**
140    * @brief Get the keyboard interface
141    * @return Wayland keyboard interface
142    */
143   WlSeat* GetSeatInterface();
144
145   /**
146    * @brief Get the text input interface
147    * @return Wayland text input interface
148    */
149   WlTextInput* GetTextInputInterface();
150
151   /**
152    * @brief Get the surface
153    * @return Wayland surface
154    */
155   WlSurface* GetSurface();
156
157   /**
158    * @brief calls wl_pointer_destroy on the pointer interface
159    */
160   void DestroyPointerInterface();
161
162   /**
163    * @brief calls wl_touch_destroy on the touch interface
164    */
165   void DestroyTouchInterface();
166
167   /**
168    * @brief calls wl_touch_keyboard on the keyboard interface
169    */
170   void DestroyKeyboardInterface();
171
172   /**
173    * @brief place holder store the seat name
174    * Currently we don't store the name as DALi core isn't seat name aware
175    * Need to think about adding Seat name to touch / key events.
176    * @param[in] name seat name
177    */
178   void SetName( const char* name );
179
180   /**
181    * @brief get the seat name
182    * E.g. may return "front-passenger-seat"
183    * @return seat name
184    */
185   const std::string& GetName() const;
186
187   /**
188    * @brief get the last known pointer position
189    * @return pointer position
190    */
191   const Dali::Vector2& GetLastPointerPosition() const;
192
193   /**
194    * @brief set the pointer position
195    * So we need to cache mouse x/y position, for pointer down events which
196    * don't have x,y position attached
197    * @param[in] position pointer position
198    */
199   void SetPointerPosition( Dali::Vector2 position);
200
201   /**
202    * @brief keyboard mapping
203    * Provides a file descriptor which can be memory-mapped to a keyboard mapping description
204    * @param[in] seat the seat that produced the event
205    * @param[in] format see wl_keyboard_keymap_format
206    * @param[in] fd  file descriptor
207    * @param[in] size size of the memory mapped region in bytes
208   */
209   void KeyboardKeymap( unsigned int format, int fd, unsigned int size );
210
211   /**
212    * @brief get current depressed keyboard modifiers (not latched)
213    * @return keyboard modifiers
214    */
215   unsigned int GetDepressedKeyboardModifiers() const ;
216
217   /**
218    * @brief get current depressed keyboard modifiers (not latched)
219    * @param[in] modifiers depressed keyboard modifiers
220    */
221   void SetDepressedKeyboardModifiers( unsigned int modifiers);
222
223   /**
224    * @brief set key repeat rate and delay
225    * @param[in] rate repeat rate in milliseconds
226    * @param[in] delay delay in milliseconds
227    */
228   void SetKeyRepeatInfo( unsigned int rate, unsigned int delay );
229
230
231   /**
232    * @brief Key has been pressed or released.
233    * Used for key events from Tizen Wayland wl_text_input interface.
234    *
235    * @param[in] seat the seat that produced the event
236    * @param[in] timestamp timestamp
237    * @param[in] symbol key symbol
238    * @param[in] state key state
239    * @param[in] modifiers keyboard modifiers
240    * @return Key event
241    */
242
243   Dali::KeyEvent GetDALiKeyEventFromSymbol( unsigned int serial,
244                                         unsigned int timestamp,
245                                         unsigned int symbol,
246                                         unsigned int state,
247                                         unsigned int modifiers );
248
249   /**
250    * @brief Key has been pressed or released. Used
251    *
252    * @param[in] seat the seat that produced the event
253    * @param[in] serial serial number
254    * @param[in] timestamp timestamp
255    * @param[in] keycode raw hardware key code
256    * @param[in] state
257    * @return Key event
258    */
259   KeyEvent GetDALiKeyEvent( unsigned int serial, unsigned int timestamp, unsigned int keycode, unsigned int state  );
260
261
262 private:  // data specific to a single seat
263
264   /**
265    * Keyboard data
266    */
267   struct XkbData
268   {
269     XkbData()
270     :mContext( NULL ),
271      mKeymap( NULL ),
272      mState( NULL ),
273      mControlMask( 0 ),
274      mAltMask( 0 ),
275      mShiftMask( 0 ),
276      mControlDown( 0 ),
277      mShiftDown( 0 ),
278      mAltDown( 0 )
279     {
280
281     }
282     struct xkb_context *mContext;
283     struct xkb_keymap* mKeymap;
284     struct xkb_state* mState;
285     xkb_mod_mask_t mControlMask;
286     xkb_mod_mask_t mAltMask;
287     xkb_mod_mask_t mShiftMask;
288     bool mControlDown:1;
289     bool mShiftDown:1;
290     bool mAltDown:1;
291   };
292
293   XkbData mXkbData;          ///< Keyboard data. Believe this can vary per seat
294   std::string mName;         ///< Seat name
295   WlPointer* mPointer;       ///< Wayland Pointer interface ( for multiple pointers )
296   WlKeyboard* mKeyboard;     ///< Wayland Keyboard interface ( for multiple keyboards )
297   WlTouch* mTouch;           ///< Wayland Touch interface ( for multiple touch devices )
298   WlSeat* mWaylandSeat;      ///< Wayland Seat interface
299   WlTextInput* mTextInput;   ///< Wayland Tizen Text input interface (Virtual Keyboard / IMF)
300   WlSurface* mSurface;       ///< Surface currently used by this seat
301   InputInterface* mInputInterface;  ///< DALi Wayland Input interface
302   Vector2 mPointerPosition; ///< Current pointer X,Y position
303   unsigned int mDepressedKeyboardModifiers; ///< keyboard modifiers
304   unsigned int mKeyRepeatRate;
305   unsigned int mKeyRepeatDelay;
306
307
308 };
309
310 } // Internal
311 } // Adaptor
312 } // Dali
313
314 #endif  //__DALI_WAYLAND_SEAT_H__