2 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include "input-manager.h"
22 #include <input/input-listeners.h>
23 #include <input/text/text-input-listeners.h>
24 #include <virtual-keyboard.h>
38 const unsigned int POINTER_DEVICE_ID = 2;
39 const unsigned int TOUCH_DEVICE_ID = 3;
41 } // unnamed namespace
43 InputManager::InputManager()
45 mWindowEventInterface( NULL )
49 InputManager::~InputManager()
51 for( Dali::Vector< Seat* >::Iterator iter = mSeats.Begin(); iter != mSeats.End() ; ++iter )
58 void InputManager::AssignWindowEventInterface( WindowEventInterface* eventInterface)
60 mWindowEventInterface = eventInterface;
61 mTextInputManger.AssignWindowEventInterface( mWindowEventInterface );
64 void InputManager::AssignDisplay( WlDisplay* display )
67 mTextInputManger.AssignDisplay( mDisplay );
70 void InputManager::AssignSurface( WlSurface* surface)
72 for( Dali::Vector< Seat* >::Iterator iter = mSeats.Begin(); iter != mSeats.End() ; ++iter )
75 seat->SetSurfaceInterface( surface );
80 void InputManager::AddSeatListener( Dali::WlSeat* seatInterface )
82 Seat* seat = new Seat( this, seatInterface );
85 mTextInputManger.AddSeat( seat );
87 // listen to seat events
88 wl_seat_add_listener( seatInterface, Wayland::GetSeatListener(), this );
92 void InputManager::AddTextInputManager( Dali::WlTextInputManager* textInputManager )
95 for( Dali::Vector< Seat* >::Iterator iter = mSeats.Begin(); iter != mSeats.End() ; ++iter )
99 // Create a text input object for each seat
100 WlTextInput* textInput = wl_text_input_manager_create_text_input( textInputManager );
101 seat->SetTextInputInterface( textInput );
103 wl_text_input_add_listener( textInput, Wayland::GetTextInputListener(), &mTextInputManger );
108 void InputManager::PointerEnter( Seat* seat, unsigned int serial, WlSurface* surface, float x, float y )
110 if( mWindowEventInterface )
112 mWindowEventInterface->WindowFocusIn();
116 void InputManager::PointerLeave( Seat* seat, unsigned int serial, WlSurface* surface )
118 if( mWindowEventInterface )
120 mWindowEventInterface->WindowFocusOut();
125 void InputManager::PointerMotion( Seat* seat, unsigned int timestamp, float x, float y )
127 if( mWindowEventInterface )
129 Integration::Point point;
130 point.SetDeviceId( POINTER_DEVICE_ID );
131 point.SetState( PointState::MOTION );
132 point.SetScreenPosition( Vector2( x , y ) );
133 mWindowEventInterface->TouchEvent( point, timestamp );
137 void InputManager::PointerButton( Seat* seat, unsigned int serial, unsigned int timestamp, unsigned int button, unsigned int state )
139 // think about handling multiple pointer button states, if DALi starts to support them
140 if( mWindowEventInterface )
142 const Dali::Vector2& pointer( seat->GetLastPointerPosition() );
144 Integration::Point point;
145 point.SetDeviceId( POINTER_DEVICE_ID );
146 point.SetScreenPosition( pointer );
150 point.SetState( PointState::DOWN );
154 point.SetState( PointState::UP );
157 mWindowEventInterface->TouchEvent( point, timestamp );
161 void InputManager::PointerAxis( Seat* seat, unsigned int timestamp, unsigned int axis, float value )
164 if( mWindowEventInterface )
166 WheelEvent wheelEvent( WheelEvent::MOUSE_WHEEL,
168 static_cast< int >( seat->GetDepressedKeyboardModifiers() ),
169 seat->GetLastPointerPosition(),
173 mWindowEventInterface->WheelEvent( wheelEvent );
177 void InputManager::KeyboardKeymap( Seat* seat, unsigned int format, int fd, unsigned int size )
179 seat->KeyboardKeymap( format, fd, size );
182 void InputManager::KeyFocusEnter( Seat* seat, unsigned int serial, WlSurface* surface, WlArray* keys )
187 void InputManager::KeyFocusLeave( Seat* seat, unsigned int serial, WlSurface* surface )
192 void InputManager::KeyEvent( Seat* seat, unsigned int serial, unsigned int timestamp, unsigned int keycode, unsigned int state )
194 Dali::KeyEvent keyEvent = seat->GetDALiKeyEvent( serial, timestamp, keycode, state );
196 mWindowEventInterface->KeyEvent( keyEvent);
201 void InputManager::KeyModifiers( Seat* seat,
203 unsigned int depressed,
204 unsigned int latched,
208 seat->SetDepressedKeyboardModifiers( depressed );
211 void InputManager::KeyRepeatInfo( Seat* seat, int32_t rate, int32_t delay)
213 if(( rate >= 0 ) && ( delay >= 0))
215 seat->SetKeyRepeatInfo( static_cast< unsigned int >( rate) , static_cast< unsigned int >(delay ));
219 void InputManager::TouchDown( Seat* seat, unsigned int serial, unsigned int timestamp, WlSurface* surface, int touchId, float x, float y)
221 // think about handling multiple pointer button states, if DALi starts to support them
222 if( mWindowEventInterface )
224 const Dali::Vector2& pointer( seat->GetLastPointerPosition() );
226 Integration::Point point;
227 point.SetDeviceId( touchId );
228 point.SetState( PointState::DOWN );
229 point.SetScreenPosition( pointer );
230 mWindowEventInterface->TouchEvent( point, timestamp );
235 void InputManager::TouchUp( Seat* seat, unsigned int serial, unsigned int timestamp, int touchId )
237 if( mWindowEventInterface )
239 const Dali::Vector2& pointer( seat->GetLastPointerPosition() );
241 Integration::Point point;
242 point.SetDeviceId( touchId );
243 point.SetState( PointState::UP );
244 point.SetScreenPosition( pointer );
245 mWindowEventInterface->TouchEvent( point, timestamp );
249 void InputManager::TouchMotion( Seat* seat, unsigned int timestamp, int touchId, float x, float y )
251 if( mWindowEventInterface )
253 const Dali::Vector2& pointer( seat->GetLastPointerPosition() );
255 Integration::Point point;
256 point.SetDeviceId( touchId );
257 point.SetState( PointState::MOTION );
258 point.SetScreenPosition( pointer );
259 mWindowEventInterface->TouchEvent( point, timestamp );
263 void InputManager::TouchFrame( Seat* seat )
268 void InputManager::TouchCancel( Seat* seat )
270 if( mWindowEventInterface )
272 const Dali::Vector2& pointer( seat->GetLastPointerPosition() );
274 // it looks like DALi just checks the first touch point for interruption
275 // so touchId can be zero
276 Integration::Point point;
277 point.SetState( PointState::INTERRUPTED );
278 point.SetScreenPosition( pointer );
279 mWindowEventInterface->TouchEvent( point, 0 );
283 Seat* InputManager::GetSeat( const WlKeyboard* keyboard )
285 for( Dali::Vector< Seat *>::Iterator iter = mSeats.Begin(); iter != mSeats.End() ; ++iter )
287 if( (*iter)->GetKeyboardInterface() == keyboard )
295 Seat* InputManager::GetSeat( const WlPointer* pointer )
297 for( Dali::Vector< Seat *>::Iterator iter = mSeats.Begin(); iter != mSeats.End() ; ++iter )
299 if( (*iter)->GetPointerInterface() == pointer )
307 Seat* InputManager::GetSeat( const WlTouch* touch )
309 for( Dali::Vector< Seat* >::Iterator iter = mSeats.Begin(); iter != mSeats.End() ; ++iter )
311 if( (*iter)->GetTouchInterface() == touch )
319 Seat* InputManager::GetSeat( const WlSeat* seat)
321 for( Dali::Vector< Seat* >::Iterator iter = mSeats.Begin(); iter != mSeats.End() ; ++iter )
323 if( (*iter)->GetSeatInterface() == seat )
331 void InputManager::AddSeat( Seat* seat )
333 mSeats.PushBack( seat );