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>
28 #include <xkbcommon/xkbcommon.h>
42 #if defined(DEBUG_ENABLED)
43 Integration::Log::Filter* gPepperInputLogging = Integration::Log::Filter::New( Debug::Verbose, false, "LOG_PEPPER_INPUT" );
46 } // unnamed namespace
48 InputPtr Input::New( Pepper::Compositor compositor )
50 InputPtr impl = new Input();
52 // Second-phase init of the implementation
53 impl->Initialize( compositor );
71 for( std::vector<Ecore_Event_Handler*>::iterator iter = mEcoreEventHandler.begin(), endIter = mEcoreEventHandler.end(); iter != endIter; ++iter )
73 ecore_event_handler_del( *iter );
76 xkb_context_unref( mContext );
78 pepper_seat_remove_input_device( mSeat, mDevice );
79 pepper_input_device_destroy( mDevice );
81 pepper_seat_destroy( mSeat );
84 void Input::Initialize( Pepper::Compositor& compositor )
86 const char *defaultName = "seat0";
88 mSeat = pepper_compositor_add_seat( static_cast< pepper_compositor_t* >( Pepper::GetImplementation( compositor ).GetCompositorHandle() ), defaultName );
91 DALI_LOG_INFO( gPepperInputLogging, Debug::General, "pepper_compositor_add_seat is failed\n" );
95 /* create and add devices. */
96 mDevice = pepper_input_device_create( static_cast< pepper_compositor_t* >( Pepper::GetImplementation( compositor ).GetCompositorHandle() ),
97 WL_SEAT_CAPABILITY_TOUCH, NULL, NULL );
98 // mDevice = pepper_input_device_create( static_cast< pepper_compositor_t* >( Pepper::GetImplementation( compositor ).GetCompositorHandle() ),
99 // ( WL_SEAT_CAPABILITY_POINTER | WL_SEAT_CAPABILITY_KEYBOARD | WL_SEAT_CAPABILITY_TOUCH ), NULL, NULL );
102 DALI_LOG_INFO( gPepperInputLogging, Debug::General, "pepper_input_device_create is failed\n" );
103 pepper_seat_destroy( mSeat );
107 pepper_seat_add_input_device( mSeat, mDevice );
109 /* get device resource from seat */
110 mPointer = pepper_seat_get_pointer( mSeat );
111 mKeyboard = pepper_seat_get_keyboard( mSeat );
112 mTouch = pepper_seat_get_touch( mSeat );
114 mCompositor = compositor;
118 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_KEY_DOWN, EcoreEventKeyDown, this ) );
119 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_KEY_UP, EcoreEventKeyUp, this ) );
121 DALI_LOG_INFO( gPepperInputLogging, Debug::Verbose, "Input::Initialize: success\n" );
124 void Input::SetKeymap()
126 struct xkb_keymap* keymap;
127 struct xkb_context* context;
128 struct xkb_rule_names names;
130 names.rules = "evdev";
131 names.model = "pc105";
133 names.options = NULL;
135 context = xkb_context_new( XKB_CONTEXT_NO_FLAGS );
138 DALI_LOG_INFO( gPepperInputLogging, Debug::General, "failed to create xkb_context\n" );
142 keymap = xkb_map_new_from_names( context, &names, XKB_KEYMAP_COMPILE_NO_FLAGS );
145 DALI_LOG_INFO( gPepperInputLogging, Debug::General, "failed to get keymap\n" );
146 xkb_context_unref( context );
150 pepper_keyboard_set_keymap( mKeyboard, keymap );
151 xkb_map_unref( keymap );
156 Eina_Bool Input::EcoreEventKeyDown( void* data, int type, void* event )
158 Input* input = static_cast< Input* >( data );
160 Ecore_Event_Key *keyEvent = static_cast< Ecore_Event_Key* >( event );
163 if( !( view = pepper_keyboard_get_focus( input->mKeyboard ) ) )
165 return ECORE_CALLBACK_RENEW;
168 keycode = (keyEvent->keycode - 8);
170 pepper_keyboard_send_key( input->mKeyboard, view, keyEvent->timestamp, keycode, WL_KEYBOARD_KEY_STATE_PRESSED );
172 return ECORE_CALLBACK_RENEW;
175 Eina_Bool Input::EcoreEventKeyUp( void* data, int type, void* event )
177 Input* input = static_cast< Input* >( data );
179 Ecore_Event_Key *keyEvent = static_cast< Ecore_Event_Key* >( event );
182 if( !( view = pepper_keyboard_get_focus( input->mKeyboard ) ) )
184 return ECORE_CALLBACK_RENEW;
187 keycode = (keyEvent->keycode - 8);
189 pepper_keyboard_send_key( input->mKeyboard, view, keyEvent->timestamp, keycode, WL_KEYBOARD_KEY_STATE_RELEASED );
191 return ECORE_CALLBACK_RENEW;
194 pepper_pointer_t* Input::GetPointer()
199 pepper_keyboard_t* Input::GetKeyboard()
204 pepper_touch_t* Input::GetTouch()
209 } // namespace Internal
211 } // namespace Pepper