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>
36 const unsigned int POINTER_DEVICE_ID = 2;
37 const unsigned int TOUCH_DEVICE_ID = 3;
39 } // unnamed namespace
41 InputManager::InputManager()
42 :mWindowEventInterface( NULL )
46 InputManager::~InputManager()
48 for( Dali::Vector< Seat* >::Iterator iter = mSeats.Begin(); iter != mSeats.End() ; ++iter )
55 void InputManager::AssignWindowEventInterface( WindowEventInterface* eventInterface)
57 mWindowEventInterface = eventInterface;
60 void InputManager::AddSeatListener( Dali::WlSeat* seatInterface )
62 Seat* seat = new Seat( this, seatInterface );
66 // listen to seat events
67 wl_seat_add_listener( seatInterface, Wayland::GetSeatListener(), this );
70 void InputManager::PointerEnter( Seat* seat, unsigned int serial, WlSurface* surface, float x, float y )
72 if( mWindowEventInterface )
74 mWindowEventInterface->WindowFocusIn();
78 void InputManager::PointerLeave( Seat* seat, unsigned int serial, WlSurface* surface )
80 if( mWindowEventInterface )
82 mWindowEventInterface->WindowFocusOut();
87 void InputManager::PointerMotion( Seat* seat, unsigned int timestamp, float x, float y )
89 if( mWindowEventInterface )
91 TouchPoint point ( POINTER_DEVICE_ID, TouchPoint::Motion, x , y);
92 mWindowEventInterface->TouchEvent( point, timestamp );
96 void InputManager::PointerButton( Seat* seat, unsigned int serial, unsigned int timestamp, unsigned int button, unsigned int state )
98 // think about handling multiple pointer button states, if DALi starts to support them
99 if( mWindowEventInterface )
101 const Dali::Vector2& pointer( seat->GetLastPointerPosition() );
103 TouchPoint point ( POINTER_DEVICE_ID, TouchPoint::Up, pointer.x, pointer.y );
106 point.state = TouchPoint::Down;
108 mWindowEventInterface->TouchEvent( point, timestamp );
112 void InputManager::PointerAxis( Seat* seat, unsigned int timestamp, unsigned int axis, float value )
115 if( mWindowEventInterface )
117 WheelEvent wheelEvent( WheelEvent::MOUSE_WHEEL,
119 static_cast< int >( seat->GetDepressedKeyboardModifiers() ),
120 seat->GetLastPointerPosition(),
124 mWindowEventInterface->WheelEvent( wheelEvent );
128 void InputManager::KeyboardKeymap( Seat* seat, unsigned int format, int fd, unsigned int size )
130 seat->KeyboardKeymap( format, fd, size );
133 void InputManager::KeyFocusEnter( Seat* seat, unsigned int serial, WlSurface* surface, WlArray* keys )
138 void InputManager::KeyFocusLeave( Seat* seat, unsigned int serial, WlSurface* surface )
143 void InputManager::KeyEvent( Seat* seat, unsigned int serial, unsigned int timestamp, unsigned int keycode, unsigned int state )
145 Dali::KeyEvent keyEvent = seat->GetDALiKeyEvent( serial, timestamp, keycode, state );
147 mWindowEventInterface->KeyEvent( keyEvent);
152 void InputManager::KeyModifiers( Seat* seat,
154 unsigned int depressed,
155 unsigned int latched,
159 seat->SetDepressedKeyboardModifiers( depressed );
162 void InputManager::KeyRepeatInfo( Seat* seat, int32_t rate, int32_t delay)
164 if(( rate >= 0 ) && ( delay >= 0))
166 seat->SetKeyRepeatInfo( static_cast< unsigned int >( rate) , static_cast< unsigned int >(delay ));
170 void InputManager::TouchDown( Seat* seat, unsigned int serial, unsigned int timestamp, WlSurface* surface, int touchId, float x, float y)
172 // think about handling multiple pointer button states, if DALi starts to support them
173 if( mWindowEventInterface )
175 const Dali::Vector2& pointer( seat->GetLastPointerPosition() );
177 TouchPoint point ( touchId, TouchPoint::Down, pointer.x, pointer.y );
178 mWindowEventInterface->TouchEvent( point, timestamp );
183 void InputManager::TouchUp( Seat* seat, unsigned int serial, unsigned int timestamp, int touchId )
185 if( mWindowEventInterface )
187 const Dali::Vector2& pointer( seat->GetLastPointerPosition() );
189 TouchPoint point ( touchId, TouchPoint::Up, pointer.x, pointer.y );
190 mWindowEventInterface->TouchEvent( point, timestamp );
194 void InputManager::TouchMotion( Seat* seat, unsigned int timestamp, int touchId, float x, float y )
196 if( mWindowEventInterface )
198 const Dali::Vector2& pointer( seat->GetLastPointerPosition() );
200 TouchPoint point ( touchId, TouchPoint::Motion, pointer.x, pointer.y );
201 mWindowEventInterface->TouchEvent( point, timestamp );
205 void InputManager::TouchFrame( Seat* seat )
210 void InputManager::TouchCancel( Seat* seat )
212 if( mWindowEventInterface )
214 const Dali::Vector2& pointer( seat->GetLastPointerPosition() );
216 // it looks like DALi just checks the first touch point for interruption
217 // so touchId can be zero
218 TouchPoint point ( 0, TouchPoint::Interrupted, pointer.x, pointer.y );
219 mWindowEventInterface->TouchEvent( point, 0 );
223 Seat* InputManager::GetSeat( const WlKeyboard* keyboard )
225 for( Dali::Vector< Seat *>::Iterator iter = mSeats.Begin(); iter != mSeats.End() ; ++iter )
227 if( (*iter)->GetKeyboardInterface() == keyboard )
235 Seat* InputManager::GetSeat( const WlPointer* pointer )
237 for( Dali::Vector< Seat *>::Iterator iter = mSeats.Begin(); iter != mSeats.End() ; ++iter )
239 if( (*iter)->GetPointerInterface() == pointer )
247 Seat* InputManager::GetSeat( const WlTouch* touch )
249 for( Dali::Vector< Seat* >::Iterator iter = mSeats.Begin(); iter != mSeats.End() ; ++iter )
251 if( (*iter)->GetTouchInterface() == touch )
259 Seat* InputManager::GetSeat( const WlSeat* seat)
261 for( Dali::Vector< Seat* >::Iterator iter = mSeats.Begin(); iter != mSeats.End() ; ++iter )
263 if( (*iter)->GetSeatInterface() == seat )
271 void InputManager::AddSeat( Seat* seat )
273 mSeats.PushBack( seat );