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.
18 #include "input-listeners.h"
25 #include "input-interface.h"
42 * Pointer events callbacks. See wl_pointer_listener in wayland-client-protocol.h for a description
45 void PointerEnter( void* data,
52 InputInterface* input = static_cast< InputInterface* >( data );
53 Seat* seat = input->GetSeat( pointer );
55 float x = static_cast<float>( wl_fixed_to_double(surfaceX) );
56 float y = static_cast<float>( wl_fixed_to_double(surfaceY) );
58 seat->SetPointerPosition( Vector2(x, y) ); // record last pointer position
60 input->PointerEnter( seat, serial, surface, x, y );
63 void PointerLeave( void* data,
68 InputInterface* input = static_cast< InputInterface* >( data );
69 Seat* seat = input->GetSeat( pointer );
71 input->PointerLeave( seat, serial, surface );
74 void PointerMotion( void* data,
76 unsigned int timestamp,
80 InputInterface* input = static_cast< InputInterface* >( data );
81 Seat* seat = input->GetSeat( pointer );
83 float x = static_cast<float>( wl_fixed_to_double( surfaceX) );
84 float y = static_cast<float>( wl_fixed_to_double( surfaceY) );
86 seat->SetPointerPosition( Vector2(x, y) ); // record last pointer position
88 input->PointerMotion( seat, timestamp, x, y );
91 void PointerButton( void* data,
94 unsigned int timestamp,
98 InputInterface* input = static_cast< InputInterface* >( data );
99 Seat* seat = input->GetSeat( pointer );
101 input->PointerButton( seat, serial, timestamp, button, state );
105 void PointerAxis( void* data,
107 unsigned int timestamp,
111 InputInterface* input = static_cast< InputInterface* >( data );
112 Seat* seat = input->GetSeat( pointer );
114 float length = static_cast<float>( wl_fixed_to_double( value ) );
116 input->PointerAxis( seat, timestamp, axis, length);
121 * Key event callbacks. See wl_keyboard_listener wayland-client-protocol.h for a description
124 void KeyboardKeymap( void* data,
125 WlKeyboard* keyboard,
130 InputInterface* input = static_cast< InputInterface* >( data );
131 Seat* seat = input->GetSeat( keyboard );
133 input->KeyboardKeymap( seat, format, fd, size );
137 void KeyFocusEnter( void* data,
138 WlKeyboard* keyboard,
143 InputInterface* input = static_cast< InputInterface* >( data );
144 Seat* seat = input->GetSeat( keyboard );
146 input->KeyFocusEnter( seat, serial, surface, keys );
149 void KeyFocusLeave( void* data,
150 WlKeyboard* keyboard,
154 InputInterface* input = static_cast< InputInterface* >( data );
155 Seat* seat = input->GetSeat( keyboard );
157 input->KeyFocusLeave( seat, serial, surface );
160 void KeyEvent( void* data,
161 WlKeyboard* keyboard,
163 unsigned int timestamp,
164 unsigned int keycode,
167 InputInterface* input = static_cast< InputInterface* >( data );
168 Seat* seat = input->GetSeat( keyboard );
170 input->KeyEvent( seat, serial, timestamp, keycode, state );
173 void KeyModifiers( void* data, WlKeyboard* keyboard,
175 unsigned int depressed,
176 unsigned int latched,
180 InputInterface* input = static_cast< InputInterface* >( data );
181 Seat* seat = input->GetSeat( keyboard );
183 input->KeyModifiers( seat, serial, depressed, latched, locked, group );
188 void KeyRepeatInfo( void* data,
189 WlKeyboard* keyboard,
193 InputInterface* input = static_cast< InputInterface* >( data );
194 Seat* seat = input->GetSeat( keyboard );
196 input->KeyRepeatInfo( seat, rate, delay );
202 * Touch event callbacks See wl_touch_listener wayland-client-protocol.h for a description
205 void TouchDown( void* data,
208 unsigned int timestamp,
214 InputInterface* input = static_cast< InputInterface* >( data );
215 Seat* seat = input->GetSeat( touch );
217 float x = static_cast<float>( wl_fixed_to_double( surfaceX) );
218 float y = static_cast<float>( wl_fixed_to_double( surfaceY) );
221 input->TouchDown( seat, serial, timestamp, surface, touchId, x, y );
224 void TouchUp( void* data,
227 unsigned int timestamp,
230 InputInterface* input = static_cast< InputInterface* >( data );
231 Seat* seat = input->GetSeat( touch );
233 input->TouchUp( seat, serial, timestamp, touchId );
236 void TouchMotion( void* data,
238 unsigned int timestamp,
243 InputInterface* input = static_cast< InputInterface* >( data );
244 Seat* seat = input->GetSeat( touch );
246 float x = static_cast<float>( wl_fixed_to_double( surfaceX) );
247 float y = static_cast<float>( wl_fixed_to_double( surfaceY) );
249 input->TouchMotion( seat, timestamp, touchId, x, y );
252 void TouchFrame( void* data, WlTouch* touch )
254 InputInterface* input = static_cast< InputInterface* >( data );
255 Seat* seat = input->GetSeat( touch );
257 input->TouchFrame( seat );
260 void TouchCancel( void* data, WlTouch* touch )
262 InputInterface* input = static_cast< InputInterface* >( data );
263 Seat* seat = input->GetSeat( touch );
265 input->TouchCancel( seat );
269 * pointer listener interface ( wl_pointer_listener )
271 const WlPointerListener PointerListener =
281 * Keyboard listener interface ( wl_keyboard_listener )
283 const WlKeyboardListener KeyboardListener =
294 * Touch listener interface ( wl_touch_listener )
296 const WlTouchListener TouchListener =
306 * @brief emitted whenever a seat gains or loses the pointer, keyboard or touch capabilities.
307 * @param[in] data user data
308 * @param[in] seatInterface seat interface
309 * @param[in] caps enum containing the complete set of capabilities this seat has.
311 void SeatHandleCapabilities( void* data, WlSeat* seatInterface, unsigned int caps)
314 InputInterface* input = static_cast< InputInterface* >( data );
315 Seat* seat = input->GetSeat( seatInterface );
318 // go through either adding or removing pointer/keyboard/touch interfaces
319 // most devices are hot plug so this function may be called many times
320 // a single keyboard/ pointer / touch interface handles multiple devices
321 // e.g. if you plug in 2 mouses, you will still only get a single pointer_interface
323 if( caps & WL_SEAT_CAPABILITY_POINTER )
325 // at least one pointer available
326 seat->SetPointerInterface( Seat::INTERFACE_AVAILABLE );
330 // all pointer devices removed, or never connected
331 seat->SetPointerInterface( Seat::INTERFACE_NOT_AVAILABLE );
334 if( caps & WL_SEAT_CAPABILITY_KEYBOARD )
336 // at least one keyboard available
337 seat->SetKeyboardInterface( Seat::INTERFACE_AVAILABLE );
341 // all keyboard devices removed, or never connected
342 seat->SetKeyboardInterface( Seat::INTERFACE_NOT_AVAILABLE );
345 if( caps & WL_SEAT_CAPABILITY_TOUCH )
347 // new touch device found
348 seat->SetTouchInterface( Seat::INTERFACE_AVAILABLE );
352 // all touch devices removed, or never connected
353 seat->SetTouchInterface( Seat::INTERFACE_NOT_AVAILABLE );
358 void SeatName(void* data, WlSeat* seatInterface, const char* name)
360 InputInterface* input = static_cast< InputInterface* >( data );
361 Seat* seat = input->GetSeat( seatInterface );
362 seat->SetName( name );
365 const WlSeatListener SeatListener =
367 SeatHandleCapabilities, //emitted whenever a seat gains or loses the pointer, keyboard or touch capabilities.
368 SeatName, // used to help identify seat in multi-seat configurations
371 } // unnamed namespace
377 const WlSeatListener* GetSeatListener()
379 return &SeatListener;
382 const WlPointerListener* GetPointerListener()
384 return &PointerListener;
387 const WlTouchListener* GetTouchListener()
389 return &TouchListener;
392 const WlKeyboardListener* GetKeyboardListener()
394 return &KeyboardListener;