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"
33 const unsigned int POINTER_DEVICE_ID = 2;
34 const unsigned int TOUCH_DEVICE_ID = 3;
36 } // unnamed namespace
38 InputManager::InputManager()
39 :mWindowEventInterface( NULL )
43 InputManager::~InputManager()
45 for( Dali::Vector< Seat* >::Iterator iter = mSeats.Begin(); iter != mSeats.End() ; ++iter )
52 void InputManager::AssignWindowEventInterface( WindowEventInterface* eventInterface)
54 mWindowEventInterface = eventInterface;
58 void InputManager::PointerEnter( Seat* seat, unsigned int serial, WlSurface* surface, float x, float y )
60 if( mWindowEventInterface )
62 mWindowEventInterface->WindowFocusIn();
66 void InputManager::PointerLeave( Seat* seat, unsigned int serial, WlSurface* surface )
68 if( mWindowEventInterface )
70 mWindowEventInterface->WindowFocusOut();
75 void InputManager::PointerMotion( Seat* seat, unsigned int timestamp, float x, float y )
77 if( mWindowEventInterface )
79 TouchPoint point ( POINTER_DEVICE_ID, TouchPoint::Motion, x , y);
80 mWindowEventInterface->TouchEvent( point, timestamp );
84 void InputManager::PointerButton( Seat* seat, unsigned int serial, unsigned int timestamp, unsigned int button, unsigned int state )
86 // think about handling multiple pointer button states, if DALi starts to support them
87 if( mWindowEventInterface )
89 const Dali::Vector2& pointer( seat->GetLastPointerPosition() );
91 TouchPoint point ( POINTER_DEVICE_ID, TouchPoint::Up, pointer.x, pointer.y );
94 point.state = TouchPoint::Down;
96 mWindowEventInterface->TouchEvent( point, timestamp );
100 void InputManager::PointerAxis( Seat* seat, unsigned int timestamp, unsigned int axis, float value )
103 if( mWindowEventInterface )
105 WheelEvent wheelEvent( WheelEvent::MOUSE_WHEEL,
107 static_cast< int >( seat->GetDepressedKeyboardModifiers() ),
108 seat->GetLastPointerPosition(),
112 mWindowEventInterface->WheelEvent( wheelEvent );
116 void InputManager::KeyboardKeymap( Seat* seat, unsigned int format, int fd, unsigned int size )
118 seat->KeyboardKeymap( format, fd, size );
121 void InputManager::KeyFocusEnter( Seat* seat, unsigned int serial, WlSurface* surface, WlArray* keys )
126 void InputManager::KeyFocusLeave( Seat* seat, unsigned int serial, WlSurface* surface )
131 void InputManager::KeyEvent( Seat* seat, unsigned int serial, unsigned int timestamp, unsigned int keycode, unsigned int state )
133 Dali::KeyEvent keyEvent = seat->GetDALiKeyEvent( serial, timestamp, keycode, state );
135 mWindowEventInterface->KeyEvent( keyEvent);
140 void InputManager::KeyModifiers( Seat* seat,
142 unsigned int depressed,
143 unsigned int latched,
147 seat->SetDepressedKeyboardModifiers( depressed );
150 void InputManager::KeyRepeatInfo( Seat* seat, int32_t rate, int32_t delay)
152 if(( rate >= 0 ) && ( delay >= 0))
154 seat->SetKeyRepeatInfo( static_cast< unsigned int >( rate) , static_cast< unsigned int >(delay ));
158 void InputManager::TouchDown( Seat* seat, unsigned int serial, unsigned int timestamp, WlSurface* surface, int touchId, float x, float y)
160 // think about handling multiple pointer button states, if DALi starts to support them
161 if( mWindowEventInterface )
163 const Dali::Vector2& pointer( seat->GetLastPointerPosition() );
165 TouchPoint point ( touchId, TouchPoint::Down, pointer.x, pointer.y );
166 mWindowEventInterface->TouchEvent( point, timestamp );
171 void InputManager::TouchUp( Seat* seat, unsigned int serial, unsigned int timestamp, int touchId )
173 if( mWindowEventInterface )
175 const Dali::Vector2& pointer( seat->GetLastPointerPosition() );
177 TouchPoint point ( touchId, TouchPoint::Up, pointer.x, pointer.y );
178 mWindowEventInterface->TouchEvent( point, timestamp );
182 void InputManager::TouchMotion( Seat* seat, unsigned int timestamp, int touchId, float x, float y )
184 if( mWindowEventInterface )
186 const Dali::Vector2& pointer( seat->GetLastPointerPosition() );
188 TouchPoint point ( touchId, TouchPoint::Motion, pointer.x, pointer.y );
189 mWindowEventInterface->TouchEvent( point, timestamp );
193 void InputManager::TouchFrame( Seat* seat )
198 void InputManager::TouchCancel( Seat* seat )
200 if( mWindowEventInterface )
202 const Dali::Vector2& pointer( seat->GetLastPointerPosition() );
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 );
211 Seat* InputManager::GetSeat( const WlKeyboard* keyboard )
213 for( Dali::Vector< Seat *>::Iterator iter = mSeats.Begin(); iter != mSeats.End() ; ++iter )
215 if( (*iter)->GetKeyboardInterface() == keyboard )
223 Seat* InputManager::GetSeat( const WlPointer* pointer )
225 for( Dali::Vector< Seat *>::Iterator iter = mSeats.Begin(); iter != mSeats.End() ; ++iter )
227 if( (*iter)->GetPointerInterface() == pointer )
235 Seat* InputManager::GetSeat( const WlTouch* touch )
237 for( Dali::Vector< Seat* >::Iterator iter = mSeats.Begin(); iter != mSeats.End() ; ++iter )
239 if( (*iter)->GetTouchInterface() == touch )
247 Seat* InputManager::GetSeat( const WlSeat* seat)
249 for( Dali::Vector< Seat* >::Iterator iter = mSeats.Begin(); iter != mSeats.End() ; ++iter )
251 if( (*iter)->GetSeatInterface() == seat )
259 void InputManager::AddSeat( Seat* seat )
261 mSeats.PushBack( seat );