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 <dali/integration-api/events/key-event-integ.h>
25 #include <input/input-listeners.h>
26 #include <input/text/text-input-listeners.h>
27 #include <virtual-keyboard.h>
41 const unsigned int POINTER_DEVICE_ID = 2;
42 const unsigned int TOUCH_DEVICE_ID = 3;
44 } // unnamed namespace
46 InputManager::InputManager()
48 mWindowEventInterface( NULL )
52 InputManager::~InputManager()
54 for( Dali::Vector< Seat* >::Iterator iter = mSeats.Begin(); iter != mSeats.End() ; ++iter )
61 void InputManager::AssignWindowEventInterface( WindowEventInterface* eventInterface)
63 mWindowEventInterface = eventInterface;
64 mTextInputManger.AssignWindowEventInterface( mWindowEventInterface );
67 void InputManager::AssignDisplay( WlDisplay* display )
70 mTextInputManger.AssignDisplay( mDisplay );
73 void InputManager::AssignSurface( WlSurface* surface)
75 for( Dali::Vector< Seat* >::Iterator iter = mSeats.Begin(); iter != mSeats.End() ; ++iter )
78 seat->SetSurfaceInterface( surface );
83 void InputManager::AddSeatListener( Dali::WlSeat* seatInterface )
85 Seat* seat = new Seat( this, seatInterface );
88 mTextInputManger.AddSeat( seat );
90 // listen to seat events
91 wl_seat_add_listener( seatInterface, Wayland::GetSeatListener(), this );
95 void InputManager::AddTextInputManager( Dali::WlTextInputManager* textInputManager )
98 for( Dali::Vector< Seat* >::Iterator iter = mSeats.Begin(); iter != mSeats.End() ; ++iter )
100 Seat* seat = (*iter);
102 // Create a text input object for each seat
103 WlTextInput* textInput = wl_text_input_manager_create_text_input( textInputManager );
104 seat->SetTextInputInterface( textInput );
106 wl_text_input_add_listener( textInput, Wayland::GetTextInputListener(), &mTextInputManger );
111 void InputManager::PointerEnter( Seat* seat, unsigned int serial, WlSurface* surface, float x, float y )
113 if( mWindowEventInterface )
115 mWindowEventInterface->WindowFocusIn();
119 void InputManager::PointerLeave( Seat* seat, unsigned int serial, WlSurface* surface )
121 if( mWindowEventInterface )
123 mWindowEventInterface->WindowFocusOut();
128 void InputManager::PointerMotion( Seat* seat, unsigned int timestamp, float x, float y )
130 if( mWindowEventInterface )
132 Integration::Point point;
133 point.SetDeviceId( POINTER_DEVICE_ID );
134 point.SetState( PointState::MOTION );
135 point.SetScreenPosition( Vector2( x , y ) );
136 mWindowEventInterface->TouchEvent( point, timestamp );
140 void InputManager::PointerButton( Seat* seat, unsigned int serial, unsigned int timestamp, unsigned int button, unsigned int state )
142 // think about handling multiple pointer button states, if DALi starts to support them
143 if( mWindowEventInterface )
145 const Dali::Vector2& pointer( seat->GetLastPointerPosition() );
147 Integration::Point point;
148 point.SetDeviceId( POINTER_DEVICE_ID );
149 point.SetScreenPosition( pointer );
153 point.SetState( PointState::DOWN );
157 point.SetState( PointState::UP );
160 mWindowEventInterface->TouchEvent( point, timestamp );
164 void InputManager::PointerAxis( Seat* seat, unsigned int timestamp, unsigned int axis, float value )
167 if( mWindowEventInterface )
169 WheelEvent wheelEvent( WheelEvent::MOUSE_WHEEL,
171 static_cast< int >( seat->GetDepressedKeyboardModifiers() ),
172 seat->GetLastPointerPosition(),
176 mWindowEventInterface->WheelEvent( wheelEvent );
180 void InputManager::KeyboardKeymap( Seat* seat, unsigned int format, int fd, unsigned int size )
182 seat->KeyboardKeymap( format, fd, size );
185 void InputManager::KeyFocusEnter( Seat* seat, unsigned int serial, WlSurface* surface, WlArray* keys )
190 void InputManager::KeyFocusLeave( Seat* seat, unsigned int serial, WlSurface* surface )
195 void InputManager::KeyEvent( Seat* seat, unsigned int serial, unsigned int timestamp, unsigned int keycode, unsigned int state )
197 Integration::KeyEvent keyEvent( seat->GetDALiKeyEvent( serial, timestamp, keycode, state ) );
199 mWindowEventInterface->KeyEvent( keyEvent);
204 void InputManager::KeyModifiers( Seat* seat,
206 unsigned int depressed,
207 unsigned int latched,
211 seat->SetDepressedKeyboardModifiers( depressed );
214 void InputManager::KeyRepeatInfo( Seat* seat, int32_t rate, int32_t delay)
216 if(( rate >= 0 ) && ( delay >= 0))
218 seat->SetKeyRepeatInfo( static_cast< unsigned int >( rate) , static_cast< unsigned int >(delay ));
222 void InputManager::TouchDown( Seat* seat, unsigned int serial, unsigned int timestamp, WlSurface* surface, int touchId, float x, float y)
224 // think about handling multiple pointer button states, if DALi starts to support them
225 if( mWindowEventInterface )
227 const Dali::Vector2& pointer( seat->GetLastPointerPosition() );
229 Integration::Point point;
230 point.SetDeviceId( touchId );
231 point.SetState( PointState::DOWN );
232 point.SetScreenPosition( pointer );
233 mWindowEventInterface->TouchEvent( point, timestamp );
238 void InputManager::TouchUp( Seat* seat, unsigned int serial, unsigned int timestamp, int touchId )
240 if( mWindowEventInterface )
242 const Dali::Vector2& pointer( seat->GetLastPointerPosition() );
244 Integration::Point point;
245 point.SetDeviceId( touchId );
246 point.SetState( PointState::UP );
247 point.SetScreenPosition( pointer );
248 mWindowEventInterface->TouchEvent( point, timestamp );
252 void InputManager::TouchMotion( Seat* seat, unsigned int timestamp, int touchId, float x, float y )
254 if( mWindowEventInterface )
256 const Dali::Vector2& pointer( seat->GetLastPointerPosition() );
258 Integration::Point point;
259 point.SetDeviceId( touchId );
260 point.SetState( PointState::MOTION );
261 point.SetScreenPosition( pointer );
262 mWindowEventInterface->TouchEvent( point, timestamp );
266 void InputManager::TouchFrame( Seat* seat )
271 void InputManager::TouchCancel( Seat* seat )
273 if( mWindowEventInterface )
275 const Dali::Vector2& pointer( seat->GetLastPointerPosition() );
277 // it looks like DALi just checks the first touch point for interruption
278 // so touchId can be zero
279 Integration::Point point;
280 point.SetState( PointState::INTERRUPTED );
281 point.SetScreenPosition( pointer );
282 mWindowEventInterface->TouchEvent( point, 0 );
286 Seat* InputManager::GetSeat( const WlKeyboard* keyboard )
288 for( Dali::Vector< Seat *>::Iterator iter = mSeats.Begin(); iter != mSeats.End() ; ++iter )
290 if( (*iter)->GetKeyboardInterface() == keyboard )
298 Seat* InputManager::GetSeat( const WlPointer* pointer )
300 for( Dali::Vector< Seat *>::Iterator iter = mSeats.Begin(); iter != mSeats.End() ; ++iter )
302 if( (*iter)->GetPointerInterface() == pointer )
310 Seat* InputManager::GetSeat( const WlTouch* touch )
312 for( Dali::Vector< Seat* >::Iterator iter = mSeats.Begin(); iter != mSeats.End() ; ++iter )
314 if( (*iter)->GetTouchInterface() == touch )
322 Seat* InputManager::GetSeat( const WlSeat* seat)
324 for( Dali::Vector< Seat* >::Iterator iter = mSeats.Begin(); iter != mSeats.End() ; ++iter )
326 if( (*iter)->GetSeatInterface() == seat )
334 void InputManager::AddSeat( Seat* seat )
336 mSeats.PushBack( seat );