Revert "[3.0] NativeImageSource with tbm_surface for tizen 3.0 wayland"
[platform/core/uifw/dali-adaptor.git] / adaptors / wayland / input-manager.cpp
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include "input-manager.h"
20
21 namespace Dali
22 {
23
24 namespace Internal
25 {
26
27 namespace Adaptor
28 {
29
30 namespace
31 {
32
33 const unsigned int POINTER_DEVICE_ID = 2;
34 const unsigned int TOUCH_DEVICE_ID = 3;
35
36 } // unnamed namespace
37
38 InputManager::InputManager()
39 :mWindowEventInterface( NULL )
40 {
41
42 }
43 InputManager::~InputManager()
44 {
45   for( Dali::Vector< Seat* >::Iterator iter = mSeats.Begin(); iter != mSeats.End() ; ++iter )
46   {
47     delete (*iter);
48   }
49   mSeats.Clear();
50 }
51
52 void InputManager::AssignWindowEventInterface( WindowEventInterface* eventInterface)
53 {
54   mWindowEventInterface = eventInterface;
55 }
56
57
58 void InputManager::PointerEnter( Seat* seat, unsigned int serial, WlSurface* surface, float x, float y )
59 {
60   if( mWindowEventInterface )
61   {
62     mWindowEventInterface->WindowFocusIn();
63   }
64 }
65
66 void InputManager::PointerLeave( Seat* seat, unsigned int serial, WlSurface* surface )
67 {
68   if( mWindowEventInterface )
69   {
70     mWindowEventInterface->WindowFocusOut();
71   }
72
73 }
74
75 void InputManager::PointerMotion( Seat* seat, unsigned int timestamp, float x, float y )
76 {
77   if( mWindowEventInterface )
78   {
79     TouchPoint point ( POINTER_DEVICE_ID, TouchPoint::Motion, x , y);
80     mWindowEventInterface->TouchEvent( point, timestamp );
81   }
82 }
83
84 void InputManager::PointerButton( Seat* seat, unsigned int serial, unsigned int timestamp, unsigned int button, unsigned int state )
85 {
86   // think about handling multiple pointer button states, if DALi starts to support them
87   if( mWindowEventInterface )
88   {
89     const Dali::Vector2& pointer( seat->GetLastPointerPosition() );
90
91     TouchPoint point ( POINTER_DEVICE_ID, TouchPoint::Up,  pointer.x,  pointer.y );
92     if( state == 1)
93     {
94       point.state = TouchPoint::Down;
95     }
96     mWindowEventInterface->TouchEvent( point, timestamp );
97   }
98 }
99
100 void InputManager::PointerAxis( Seat* seat, unsigned int timestamp, unsigned int axis, float value )
101 {
102
103   if( mWindowEventInterface )
104   {
105     WheelEvent wheelEvent( WheelEvent::MOUSE_WHEEL,
106                            axis,
107                            static_cast< int >( seat->GetDepressedKeyboardModifiers() ),
108                            seat->GetLastPointerPosition(),
109                            value,
110                            timestamp );
111
112     mWindowEventInterface->WheelEvent( wheelEvent );
113   }
114 }
115
116 void InputManager::KeyboardKeymap( Seat* seat, unsigned int format, int fd, unsigned int size )
117 {
118   seat->KeyboardKeymap( format, fd, size );
119 }
120
121 void InputManager::KeyFocusEnter( Seat* seat, unsigned int serial, WlSurface* surface, WlArray* keys )
122 {
123   // ignore for now
124 }
125
126 void InputManager::KeyFocusLeave( Seat* seat, unsigned int serial, WlSurface* surface )
127 {
128   // ignore for now
129 }
130
131 void InputManager::KeyEvent( Seat* seat, unsigned int serial, unsigned int timestamp, unsigned int keycode, unsigned int state )
132 {
133   Dali::KeyEvent keyEvent = seat->GetDALiKeyEvent( serial, timestamp, keycode, state );
134
135   mWindowEventInterface->KeyEvent( keyEvent);
136
137 }
138
139
140 void InputManager::KeyModifiers( Seat* seat,
141                           unsigned int serial,
142                           unsigned int depressed,
143                           unsigned int latched,
144                           unsigned int locked,
145                           unsigned int group )
146 {
147   seat->SetDepressedKeyboardModifiers( depressed );
148 }
149
150 void InputManager::KeyRepeatInfo( Seat* seat, int32_t rate, int32_t delay)
151 {
152   if(( rate >= 0 ) && ( delay >= 0))
153   {
154     seat->SetKeyRepeatInfo( static_cast< unsigned int >( rate) , static_cast< unsigned int >(delay ));
155   }
156 }
157
158 void InputManager::TouchDown( Seat* seat, unsigned int serial, unsigned int timestamp, WlSurface* surface, int touchId, float x, float y)
159 {
160   // think about handling multiple pointer button states, if DALi starts to support them
161   if( mWindowEventInterface )
162   {
163     const Dali::Vector2& pointer( seat->GetLastPointerPosition() );
164
165     TouchPoint point ( touchId, TouchPoint::Down,  pointer.x,  pointer.y );
166     mWindowEventInterface->TouchEvent( point, timestamp );
167   }
168 }
169
170
171 void InputManager::TouchUp( Seat* seat, unsigned int serial, unsigned int timestamp, int touchId )
172 {
173   if( mWindowEventInterface )
174   {
175     const Dali::Vector2& pointer( seat->GetLastPointerPosition() );
176
177     TouchPoint point ( touchId, TouchPoint::Up,  pointer.x,  pointer.y );
178     mWindowEventInterface->TouchEvent( point, timestamp );
179   }
180 }
181
182 void InputManager::TouchMotion( Seat* seat, unsigned int timestamp, int touchId, float x, float y )
183 {
184   if( mWindowEventInterface )
185   {
186     const Dali::Vector2& pointer( seat->GetLastPointerPosition() );
187
188     TouchPoint point ( touchId, TouchPoint::Motion,  pointer.x,  pointer.y );
189     mWindowEventInterface->TouchEvent( point, timestamp );
190   }
191 }
192
193 void InputManager::TouchFrame( Seat* seat )
194 {
195   // un-used
196 }
197
198 void InputManager::TouchCancel( Seat* seat )
199 {
200   if( mWindowEventInterface )
201   {
202     const Dali::Vector2& pointer( seat->GetLastPointerPosition() );
203
204     // it looks like DALi just checks the first touch point for interruption
205     // so touchId can be zero
206     TouchPoint point ( 0, TouchPoint::Interrupted,  pointer.x,  pointer.y );
207     mWindowEventInterface->TouchEvent( point, 0 );
208   }
209 }
210
211 Seat* InputManager::GetSeat( const WlKeyboard* keyboard )
212 {
213   for( Dali::Vector< Seat *>::Iterator iter = mSeats.Begin(); iter != mSeats.End() ; ++iter )
214   {
215     if( (*iter)->GetKeyboardInterface() == keyboard )
216     {
217       return (*iter);
218     }
219   }
220   return NULL;
221 }
222
223 Seat* InputManager::GetSeat( const WlPointer* pointer )
224 {
225   for( Dali::Vector< Seat *>::Iterator iter = mSeats.Begin(); iter != mSeats.End() ; ++iter )
226   {
227     if( (*iter)->GetPointerInterface() == pointer )
228     {
229       return (*iter);
230     }
231   }
232   return NULL;
233 }
234
235 Seat* InputManager::GetSeat( const WlTouch* touch )
236 {
237   for( Dali::Vector< Seat* >::Iterator iter = mSeats.Begin(); iter != mSeats.End() ; ++iter )
238   {
239     if( (*iter)->GetTouchInterface() == touch )
240     {
241       return (*iter);
242     }
243   }
244   return NULL;
245 }
246
247 Seat* InputManager::GetSeat( const WlSeat* seat)
248 {
249   for( Dali::Vector< Seat* >::Iterator iter = mSeats.Begin(); iter != mSeats.End() ; ++iter )
250   {
251     if( (*iter)->GetSeatInterface() == seat )
252     {
253       return (*iter);
254     }
255   }
256   return NULL;
257 }
258
259 void InputManager::AddSeat( Seat* seat )
260 {
261   mSeats.PushBack( seat );
262 }
263
264
265 }
266 }
267 }