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.
22 #include <Ecore_Wayland.h>
23 #include <dali/integration-api/debug.h>
39 bool GrabKeyTopmost( Window window, Dali::KEY daliKey )
41 return GrabKey( window, daliKey, TOPMOST);
44 bool UngrabKeyTopmost( Window window, Dali::KEY daliKey )
46 return UngrabKey( window, daliKey );
49 bool GrabKey( Window window, Dali::KEY daliKey, KeyGrabMode grabMode )
51 Ecore_Wl_Window_Keygrab_Mode wlGrabMode;
52 if( grabMode == TOPMOST )
54 wlGrabMode = ECORE_WL_WINDOW_KEYGRAB_TOPMOST;
56 else if( grabMode == SHARED )
58 wlGrabMode = ECORE_WL_WINDOW_KEYGRAB_SHARED;
60 else if( grabMode == OVERRIDE_EXCLUSIVE )
62 wlGrabMode = ECORE_WL_WINDOW_KEYGRAB_EXCLUSIVE;
64 else if( grabMode == EXCLUSIVE )
66 wlGrabMode = ECORE_WL_WINDOW_KEYGRAB_OVERRIDE_EXCLUSIVE;
73 return ecore_wl_window_keygrab_set( AnyCast<Ecore_Wl_Window*>( window.GetNativeHandle() ),
74 Dali::Internal::Adaptor::KeyLookup::GetKeyName( daliKey ),
75 0, 0, 0, wlGrabMode );
78 bool UngrabKey( Window window, Dali::KEY daliKey )
80 return ecore_wl_window_keygrab_unset( AnyCast<Ecore_Wl_Window*>( window.GetNativeHandle() ),
81 Dali::Internal::Adaptor::KeyLookup::GetKeyName( daliKey ),
85 Dali::Vector<bool> GrabKeyList( Window window, const Dali::Vector<Dali::KEY>& daliKeyVector, const Dali::Vector<KeyGrabMode>& grabModeVector)
87 Dali::Vector<bool> resultVector;
88 Eina_List *keyList = NULL, *grabList = NULL, *l = NULL, *m = NULL;
89 void *listData = NULL, *data = NULL;
90 Dali::Vector<Dali::KEY>::SizeType keyCount = daliKeyVector.Count();
91 Dali::Vector<KeyGrabMode>::SizeType keyGrabModeCount = grabModeVector.Count();
94 if(keyCount != keyGrabModeCount || keyCount == 0)
99 for( Dali::Vector<float>::SizeType index = 0; index < keyCount; ++index )
101 Ecore_Wl_Window_Keygrab_Info *info = (Ecore_Wl_Window_Keygrab_Info*)malloc(sizeof(Ecore_Wl_Window_Keygrab_Info));
102 info->key = (char*)Dali::Internal::Adaptor::KeyLookup::GetKeyName( daliKeyVector[index] );
104 switch(grabModeVector[index])
107 info->mode = ECORE_WL_WINDOW_KEYGRAB_TOPMOST;
110 info->mode = ECORE_WL_WINDOW_KEYGRAB_SHARED;
112 case OVERRIDE_EXCLUSIVE:
113 info->mode = ECORE_WL_WINDOW_KEYGRAB_EXCLUSIVE;
116 info->mode = ECORE_WL_WINDOW_KEYGRAB_OVERRIDE_EXCLUSIVE;
119 info->mode = ECORE_WL_WINDOW_KEYGRAB_UNKNOWN;
123 keyList = eina_list_append(keyList, info);
126 grabList = ecore_wl_window_keygrab_list_set(AnyCast<Ecore_Wl_Window*>( window.GetNativeHandle() ), keyList);
128 for( Dali::Vector<float>::SizeType index = 0; index < keyCount; ++index )
130 resultVector.PushBack(true);
133 if( grabList != NULL)
135 EINA_LIST_FOREACH(grabList, m, data)
137 Dali::Vector<float>::SizeType index = 0;
138 EINA_LIST_FOREACH(keyList, l, listData)
140 if(strcmp((char*)data, ((Ecore_Wl_Window_Keygrab_Info*)listData)->key) == 0)
141 resultVector[index] = false;
148 eina_list_free(keyList);
149 eina_list_free(grabList);
155 Dali::Vector<bool> UngrabKeyList( Window window, const Dali::Vector<Dali::KEY>& daliKeyVector )
157 Dali::Vector<bool> resultVector;
158 Eina_List *keyList = NULL, *ungrabList = NULL, *l = NULL, *m = NULL;
159 void *listData = NULL, *data = NULL;
160 Dali::Vector<Dali::KEY>::SizeType keyCount = daliKeyVector.Count();
168 for( Dali::Vector<float>::SizeType index = 0; index < keyCount; ++index )
170 Ecore_Wl_Window_Keygrab_Info *info = (Ecore_Wl_Window_Keygrab_Info*)malloc(sizeof(Ecore_Wl_Window_Keygrab_Info));
171 info->key = (char*)Dali::Internal::Adaptor::KeyLookup::GetKeyName( daliKeyVector[index] );
172 keyList = eina_list_append(keyList, info);
175 ungrabList = ecore_wl_window_keygrab_list_unset(AnyCast<Ecore_Wl_Window*>( window.GetNativeHandle() ), keyList);
177 for( Dali::Vector<float>::SizeType index = 0; index < keyCount; ++index )
179 resultVector.PushBack(true);
182 if( ungrabList != NULL)
184 EINA_LIST_FOREACH(ungrabList, m, data)
186 Dali::Vector<float>::SizeType index = 0;
187 EINA_LIST_FOREACH(keyList, l, listData)
189 if(strcmp((char*)data, ((Ecore_Wl_Window_Keygrab_Info*)listData)->key) == 0)
190 resultVector[index] = false;
197 eina_list_free(keyList);
198 eina_list_free(ungrabList);
204 } // namespace KeyGrab