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 <dali/public-api/adaptor-framework/key-grab.h>
22 #include <Ecore_Wl2.h>
23 #include <dali/integration-api/debug.h>
26 #include <dali/public-api/adaptor-framework/window.h>
27 #include <dali/internal/input/common/key-impl.h>
40 bool GrabKeyTopmost( Window window, Dali::KEY daliKey )
42 return GrabKey( window, daliKey, TOPMOST);
46 bool UngrabKeyTopmost( Window window, Dali::KEY daliKey )
48 return UngrabKey( window, daliKey );
52 bool GrabKey( Window window, Dali::KEY daliKey, KeyGrabMode grabMode )
54 Ecore_Wl2_Window_Keygrab_Mode wlGrabMode;
55 if( grabMode == TOPMOST )
57 wlGrabMode = ECORE_WL2_WINDOW_KEYGRAB_TOPMOST;
59 else if( grabMode == SHARED )
61 wlGrabMode = ECORE_WL2_WINDOW_KEYGRAB_SHARED;
63 else if( grabMode == OVERRIDE_EXCLUSIVE )
65 wlGrabMode = ECORE_WL2_WINDOW_KEYGRAB_OVERRIDE_EXCLUSIVE;
67 else if( grabMode == EXCLUSIVE )
69 wlGrabMode = ECORE_WL2_WINDOW_KEYGRAB_EXCLUSIVE;
76 return ecore_wl2_window_keygrab_set( AnyCast<Ecore_Wl2_Window*>( window.GetNativeHandle() ),
77 Dali::Internal::Adaptor::KeyLookup::GetKeyName( daliKey ),
78 0, 0, 0, wlGrabMode );
82 bool UngrabKey( Window window, Dali::KEY daliKey )
84 return ecore_wl2_window_keygrab_unset( AnyCast<Ecore_Wl2_Window*>( window.GetNativeHandle() ),
85 Dali::Internal::Adaptor::KeyLookup::GetKeyName( daliKey ),
90 bool GrabKeyList( Window window, const Dali::Vector<Dali::KEY>& daliKeyVector, const Dali::Vector<KeyGrabMode>& grabModeVector, Dali::Vector<bool>& returnVector)
92 const Dali::Vector<bool>::SizeType returnCount = returnVector.Count();
93 const Dali::Vector<Dali::KEY>::SizeType keyCount = daliKeyVector.Count();
94 const Dali::Vector<KeyGrabMode>::SizeType keyGrabModeCount = grabModeVector.Count();
96 if( keyCount != keyGrabModeCount || keyCount != returnCount || keyCount == 0 )
103 Eina_List* keyList = NULL;
105 for( Dali::Vector<float>::SizeType index = 0; index < keyCount; ++index )
107 Ecore_Wl2_Window_Keygrab_Info info;
108 info.key = const_cast<char*>(Dali::Internal::Adaptor::KeyLookup::GetKeyName( daliKeyVector[index] ));
110 switch( grabModeVector[index] )
114 info.mode = ECORE_WL2_WINDOW_KEYGRAB_TOPMOST;
119 info.mode = ECORE_WL2_WINDOW_KEYGRAB_SHARED;
122 case OVERRIDE_EXCLUSIVE:
124 info.mode = ECORE_WL2_WINDOW_KEYGRAB_OVERRIDE_EXCLUSIVE;
129 info.mode = ECORE_WL2_WINDOW_KEYGRAB_EXCLUSIVE;
134 info.mode = ECORE_WL2_WINDOW_KEYGRAB_UNKNOWN;
139 keyList = eina_list_append( keyList, &info );
143 Eina_List* grabList = ecore_wl2_window_keygrab_list_set( AnyCast<Ecore_Wl2_Window*>( window.GetNativeHandle() ), keyList );
145 returnVector.Resize( keyCount, true );
149 void *listData = NULL;
151 if( grabList != NULL )
153 EINA_LIST_FOREACH( grabList, m, data )
155 Dali::Vector<float>::SizeType index = 0;
156 EINA_LIST_FOREACH( keyList, l, listData )
158 if((static_cast<Ecore_Wl2_Window_Keygrab_Info*>(listData))->key == NULL)
160 DALI_LOG_ERROR("input key list has null data!");
164 if( strcmp( static_cast<char*>(data), static_cast<Ecore_Wl2_Window_Keygrab_Info*>(listData)->key ) == 0 )
166 returnVector[index] = false;
173 eina_list_free( keyList );
174 eina_list_free( grabList );
180 bool UngrabKeyList( Window window, const Dali::Vector<Dali::KEY>& daliKeyVector, Dali::Vector<bool>& returnVector)
182 const Dali::Vector<bool>::SizeType returnCount = returnVector.Count();
183 const Dali::Vector<Dali::KEY>::SizeType keyCount = daliKeyVector.Count();
185 if( keyCount != returnCount ||keyCount == 0 )
192 Eina_List* keyList = NULL;
194 for( Dali::Vector<float>::SizeType index = 0; index < keyCount; ++index )
196 Ecore_Wl2_Window_Keygrab_Info info;
197 info.key = const_cast<char*>(Dali::Internal::Adaptor::KeyLookup::GetKeyName( daliKeyVector[index] ));
198 keyList = eina_list_append( keyList, &info );
202 Eina_List* ungrabList = ecore_wl2_window_keygrab_list_unset( AnyCast<Ecore_Wl2_Window*>( window.GetNativeHandle() ), keyList );
204 returnVector.Resize( keyCount, true );
208 void *listData = NULL;
211 if( ungrabList != NULL )
213 EINA_LIST_FOREACH( ungrabList, m, data )
215 Dali::Vector<float>::SizeType index = 0;
216 EINA_LIST_FOREACH( keyList, l, listData )
218 if( strcmp( static_cast<char*>(data), static_cast<Ecore_Wl2_Window_Keygrab_Info*>(listData)->key ) == 0 )
220 returnVector[index] = false;
227 eina_list_free( keyList );
228 eina_list_free( ungrabList );
234 } // namespace KeyGrab