/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
// INTERNAL INCLUDES
#include <window.h>
#include <key-impl.h>
-#include <iostream>
-
-// keycode-related code
-#include "ecore_wl_private.h"
+#include <iostream>
+#include <string.h>
using namespace std;
-// keycode-related code
-namespace
-{
-
-const int KEYCODE_BUFFER_SIZE = 5;
-
-typedef struct _keycode_map{
- xkb_keysym_t keysym;
- xkb_keycode_t *keycodes;
- int nkeycodes;
-}keycode_map;
-
-static void find_keycode( struct xkb_keymap *keymap, xkb_keycode_t key, void *data )
-{
- keycode_map *found_keycodes = (keycode_map *)data;
- xkb_keysym_t keysym = found_keycodes->keysym;
- int nsyms = 0;
- const xkb_keysym_t *syms_out = NULL;
-
- nsyms = xkb_keymap_key_get_syms_by_level(keymap, key, 0, 0, &syms_out);
- if( nsyms && syms_out )
- {
- if( *syms_out == keysym )
- {
- found_keycodes->nkeycodes++;
- found_keycodes->keycodes = static_cast<xkb_keycode_t*>(realloc( found_keycodes->keycodes, sizeof(int)*found_keycodes->nkeycodes ));
- found_keycodes->keycodes[found_keycodes->nkeycodes-1] = key;
- }
- }
-}
-
-int xkb_keycode_from_keysym( struct xkb_keymap *keymap, xkb_keysym_t keysym, xkb_keycode_t **keycodes )
-{
- keycode_map found_keycodes = {0,};
- found_keycodes.keysym = keysym;
- xkb_keymap_key_for_each( keymap, find_keycode, &found_keycodes );
-
- *keycodes = found_keycodes.keycodes;
- return found_keycodes.nkeycodes;
-}
-
-bool keycode_from_keyname( const char* keyname, char* keycode_buffer )
-{
- xkb_keysym_t keysym = xkb_keysym_from_name( keyname, XKB_KEYSYM_NO_FLAGS );
-
- int nkeycodes = 0; // num of keycodes mapping with keysym
- xkb_keycode_t *keycodes = NULL; // keycodes list
- nkeycodes = xkb_keycode_from_keysym( ecore_wl_input_get()->xkb.keymap, keysym, &keycodes );
- if( nkeycodes > 0)
- {
- snprintf( keycode_buffer, KEYCODE_BUFFER_SIZE, "%d", keycodes[0] );
- return true;
- }
- else
- {
- return false;
- }
- free(keycodes);
-}
-
-} // unnamed namespace
-
namespace Dali
{
return false;
}
- // keycode-related code
- char keycode[KEYCODE_BUFFER_SIZE];
- if( !keycode_from_keyname( Dali::Internal::Adaptor::KeyLookup::GetKeyName( daliKey ), keycode ) )
- {
- DALI_LOG_WARNING( "Unable to get keycode from keyname %s.\n", Dali::Internal::Adaptor::KeyLookup::GetKeyName( daliKey ) );
- return false;
- }
return ecore_wl_window_keygrab_set( AnyCast<Ecore_Wl_Window*>( window.GetNativeHandle() ),
- keycode,
+ Dali::Internal::Adaptor::KeyLookup::GetKeyName( daliKey ),
0, 0, 0, wlGrabMode );
+}
- // Currently the 2nd parameter of ecore_wl_window_keygrab_set means keycode, but its meaning will be changed to keyname later.
- // Once changed, we can remove all "keycode-related code" and just uncomment below line and
- // also can remove following files:
- // ecore_wl_private.h, tizen-extension-client-protocol.h, tizen-policy-client-protocol.h
+bool UngrabKey( Window window, Dali::KEY daliKey )
+{
+ return ecore_wl_window_keygrab_unset( AnyCast<Ecore_Wl_Window*>( window.GetNativeHandle() ),
+ Dali::Internal::Adaptor::KeyLookup::GetKeyName( daliKey ),
+ 0, 0 );
+}
+
+Dali::Vector<bool> GrabKeyList( Window window, const Dali::Vector<Dali::KEY> daliKeyVector, const Dali::Vector<KeyGrabMode> grabModeVector)
+{
+ Dali::Vector<bool> resultVector;
+ Eina_List *keyList = NULL, *grabList = NULL, *l = NULL, *m = NULL;
+ void *listData = NULL, *data = NULL;
+ Dali::Vector<Dali::KEY>::SizeType keyCount = daliKeyVector.Count();
+ Dali::Vector<KeyGrabMode>::SizeType keyGrabModeCount = grabModeVector.Count();
+
+
+ if(keyCount != keyGrabModeCount || keyCount == 0)
+ return resultVector;
+
+ eina_init();
+
+ for( Dali::Vector<float>::SizeType index = 0; index < keyCount; ++index )
+ {
+ Ecore_Wl_Window_Keygrab_Info *info = (Ecore_Wl_Window_Keygrab_Info*)malloc(sizeof(Ecore_Wl_Window_Keygrab_Info));
+ info->key = (char*)Dali::Internal::Adaptor::KeyLookup::GetKeyName( daliKeyVector[index] );
+
+ switch(grabModeVector[index])
+ {
+ case TOPMOST:
+ info->mode = ECORE_WL_WINDOW_KEYGRAB_TOPMOST;
+ break;
+ case SHARED:
+ info->mode = ECORE_WL_WINDOW_KEYGRAB_SHARED;
+ break;
+ case OVERRIDE_EXCLUSIVE:
+ info->mode = ECORE_WL_WINDOW_KEYGRAB_EXCLUSIVE;
+ break;
+ case EXCLUSIVE:
+ info->mode = ECORE_WL_WINDOW_KEYGRAB_OVERRIDE_EXCLUSIVE;
+ break;
+ default:
+ info->mode = ECORE_WL_WINDOW_KEYGRAB_UNKNOWN;
+ break;
+ }
+
+ keyList = eina_list_append(keyList, info);
+ }
+
+ grabList = ecore_wl_window_keygrab_list_set(AnyCast<Ecore_Wl_Window*>( window.GetNativeHandle() ), keyList);
+
+ for( Dali::Vector<float>::SizeType index = 0; index < keyCount; ++index )
+ {
+ resultVector.PushBack(true);
+ }
+
+ if( grabList != NULL)
+ {
+ EINA_LIST_FOREACH(grabList, m, data)
+ {
+ Dali::Vector<float>::SizeType index = 0;
+ EINA_LIST_FOREACH(keyList, l, listData)
+ {
+ if(strcmp((char*)data, ((Ecore_Wl_Window_Keygrab_Info*)listData)->key) == 0)
+ resultVector[index] = false;
+
+ ++index;
+ }
+ }
+ }
- //return ecore_wl_window_keygrab_set( AnyCast<Ecore_Wl_Window*>( window.GetNativeHandle() ),
- //Dali::Internal::Adaptor::KeyLookup::GetKeyName( daliKey ),
- //0, 0, 0, wlGrabMode );
+ eina_list_free(keyList);
+ eina_list_free(grabList);
+ eina_shutdown();
+
+ return resultVector;
}
-bool UngrabKey( Window window, Dali::KEY daliKey )
+Dali::Vector<bool> UngrabKeyList( Window window, const Dali::Vector<Dali::KEY> daliKeyVector )
{
- // keycode-related code
- char keycode[KEYCODE_BUFFER_SIZE];
- if( !keycode_from_keyname( Dali::Internal::Adaptor::KeyLookup::GetKeyName( daliKey ), keycode ) )
+ Dali::Vector<bool> resultVector;
+ Eina_List *keyList = NULL, *ungrabList = NULL, *l = NULL, *m = NULL;
+ void *listData = NULL, *data = NULL;
+ Dali::Vector<Dali::KEY>::SizeType keyCount = daliKeyVector.Count();
+
+
+ if(keyCount == 0)
+ return resultVector;
+
+ eina_init();
+
+ for( Dali::Vector<float>::SizeType index = 0; index < keyCount; ++index )
{
- DALI_LOG_WARNING( "Unable to get keycode from keyname %s.\n", Dali::Internal::Adaptor::KeyLookup::GetKeyName( daliKey ) );
- return false;
+ Ecore_Wl_Window_Keygrab_Info *info = (Ecore_Wl_Window_Keygrab_Info*)malloc(sizeof(Ecore_Wl_Window_Keygrab_Info));
+ info->key = (char*)Dali::Internal::Adaptor::KeyLookup::GetKeyName( daliKeyVector[index] );
+ keyList = eina_list_append(keyList, info);
+ }
+
+ ungrabList = ecore_wl_window_keygrab_list_unset(AnyCast<Ecore_Wl_Window*>( window.GetNativeHandle() ), keyList);
+
+ for( Dali::Vector<float>::SizeType index = 0; index < keyCount; ++index )
+ {
+ resultVector.PushBack(true);
+ }
+
+ if( ungrabList != NULL)
+ {
+ EINA_LIST_FOREACH(ungrabList, m, data)
+ {
+ Dali::Vector<float>::SizeType index = 0;
+ EINA_LIST_FOREACH(keyList, l, listData)
+ {
+ if(strcmp((char*)data, ((Ecore_Wl_Window_Keygrab_Info*)listData)->key) == 0)
+ resultVector[index] = false;
+
+ ++index;
+ }
+ }
}
- return ecore_wl_window_keygrab_unset( AnyCast<Ecore_Wl_Window*>( window.GetNativeHandle() ),
- keycode,
- 0, 0 );
- // Currently the 2nd parameter of ecore_wl_window_keygrab_set means keycode, but its meaning will be changed to keyname later.
- // Once changed, we can remove all "keycode-related code" and just uncomment below line and
- // also can remove following files:
- // ecore_wl_private.h, tizen-extension-client-protocol.h, tizen-policy-client-protocol.h
+ eina_list_free(keyList);
+ eina_list_free(ungrabList);
+ eina_shutdown();
- //return ecore_wl_window_keygrab_unset( AnyCast<Ecore_Wl_Window*>( window.GetNativeHandle() ),
- //Dali::Internal::Adaptor::KeyLookup::GetKeyName( daliKey ),
- //0, 0 );
+ return resultVector;
}
} // namespace KeyGrab