2 * Copyright (c) 2016 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 <pepper-dali/internal/input-impl.h>
22 #include <pepper-dali/internal/compositor-impl.h>
25 #include <dali/integration-api/debug.h>
26 #include <pepper-input-backend.h>
27 #include <Ecore_Input.h>
41 #if defined(DEBUG_ENABLED)
42 Integration::Log::Filter* gPepperInputLogging = Integration::Log::Filter::New( Debug::Verbose, false, "LOG_PEPPER_INPUT" );
45 } // unnamed namespace
47 InputPtr Input::New( Pepper::Compositor compositor )
49 InputPtr impl = new Input();
51 // Second-phase init of the implementation
52 impl->Initialize( compositor );
69 for( std::vector<Ecore_Event_Handler*>::iterator iter = mEcoreEventHandler.begin(), endIter = mEcoreEventHandler.end(); iter != endIter; ++iter )
71 ecore_event_handler_del( *iter );
74 pepper_xkb_destroy( mXkb );
77 pepper_seat_remove_input_device( mSeat, mDevice );
78 pepper_input_device_destroy( mDevice );
80 pepper_seat_destroy( mSeat );
83 void Input::Initialize( Pepper::Compositor& compositor )
85 const char *defaultName = "seat0";
87 mSeat = pepper_compositor_add_seat( static_cast< pepper_compositor_t* >( Pepper::GetImplementation( compositor ).GetCompositorHandle() ), defaultName );
90 DALI_LOG_INFO( gPepperInputLogging, Debug::General, "pepper_compositor_add_seat is failed\n" );
94 /* create and add devices. */
95 mDevice = pepper_input_device_create( static_cast< pepper_compositor_t* >( Pepper::GetImplementation( compositor ).GetCompositorHandle() ),
96 WL_SEAT_CAPABILITY_KEYBOARD | WL_SEAT_CAPABILITY_TOUCH, NULL, NULL );
97 // mDevice = pepper_input_device_create( static_cast< pepper_compositor_t* >( Pepper::GetImplementation( compositor ).GetCompositorHandle() ),
98 // ( WL_SEAT_CAPABILITY_POINTER | WL_SEAT_CAPABILITY_KEYBOARD | WL_SEAT_CAPABILITY_TOUCH ), NULL, NULL );
101 DALI_LOG_INFO( gPepperInputLogging, Debug::General, "pepper_input_device_create is failed\n" );
102 pepper_seat_destroy( mSeat );
106 pepper_seat_add_input_device( mSeat, mDevice );
108 /* get device resource from seat */
109 mPointer = pepper_seat_get_pointer( mSeat );
110 mKeyboard = pepper_seat_get_keyboard( mSeat );
111 mTouch = pepper_seat_get_touch( mSeat );
113 mCompositor = compositor;
114 mXkb = pepper_xkb_create( );
117 DALI_LOG_INFO( gPepperInputLogging, Debug::General, "failed to create pepper xkb\n");
121 pepper_xkb_keyboard_set_keymap( mXkb, mKeyboard, NULL);
123 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_KEY_DOWN, EcoreEventKeyDown, this ) );
124 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_KEY_UP, EcoreEventKeyUp, this ) );
126 DALI_LOG_INFO( gPepperInputLogging, Debug::Verbose, "Input::Initialize: success\n" );
129 Eina_Bool Input::EcoreEventKeyDown( void* data, int type, void* event )
131 Input* input = static_cast< Input* >( data );
133 Ecore_Event_Key *keyEvent = static_cast< Ecore_Event_Key* >( event );
136 if( !( view = pepper_keyboard_get_focus( input->mKeyboard ) ) )
138 return ECORE_CALLBACK_RENEW;
141 keycode = (keyEvent->keycode - 8);
143 pepper_keyboard_send_key( input->mKeyboard, view, keyEvent->timestamp, keycode, WL_KEYBOARD_KEY_STATE_PRESSED );
145 return ECORE_CALLBACK_RENEW;
148 Eina_Bool Input::EcoreEventKeyUp( void* data, int type, void* event )
150 Input* input = static_cast< Input* >( data );
152 Ecore_Event_Key *keyEvent = static_cast< Ecore_Event_Key* >( event );
155 if( !( view = pepper_keyboard_get_focus( input->mKeyboard ) ) )
157 return ECORE_CALLBACK_RENEW;
160 keycode = (keyEvent->keycode - 8);
162 pepper_keyboard_send_key( input->mKeyboard, view, keyEvent->timestamp, keycode, WL_KEYBOARD_KEY_STATE_RELEASED );
164 return ECORE_CALLBACK_RENEW;
167 pepper_pointer_t* Input::GetPointer()
172 pepper_keyboard_t* Input::GetKeyboard()
177 pepper_touch_t* Input::GetTouch()
182 } // namespace Internal
184 } // namespace Pepper