2 * Copyright (c) 2014 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>
30 // keycode-related code
31 #include "ecore_wl_private.h"
35 // keycode-related code
39 const int KEYCODE_BUFFER_SIZE = 5;
41 typedef struct _keycode_map{
43 xkb_keycode_t *keycodes;
47 static void find_keycode( struct xkb_keymap *keymap, xkb_keycode_t key, void *data )
49 keycode_map *found_keycodes = (keycode_map *)data;
50 xkb_keysym_t keysym = found_keycodes->keysym;
52 const xkb_keysym_t *syms_out = NULL;
54 nsyms = xkb_keymap_key_get_syms_by_level(keymap, key, 0, 0, &syms_out);
55 if( nsyms && syms_out )
57 if( *syms_out == keysym )
59 found_keycodes->nkeycodes++;
60 found_keycodes->keycodes = static_cast<xkb_keycode_t*>(realloc( found_keycodes->keycodes, sizeof(int)*found_keycodes->nkeycodes ));
61 found_keycodes->keycodes[found_keycodes->nkeycodes-1] = key;
66 int xkb_keycode_from_keysym( struct xkb_keymap *keymap, xkb_keysym_t keysym, xkb_keycode_t **keycodes )
68 keycode_map found_keycodes = {0,};
69 found_keycodes.keysym = keysym;
70 xkb_keymap_key_for_each( keymap, find_keycode, &found_keycodes );
72 *keycodes = found_keycodes.keycodes;
73 return found_keycodes.nkeycodes;
76 bool keycode_from_keyname( const char* keyname, char* keycode_buffer )
78 xkb_keysym_t keysym = xkb_keysym_from_name( keyname, XKB_KEYSYM_NO_FLAGS );
80 int nkeycodes = 0; // num of keycodes mapping with keysym
81 xkb_keycode_t *keycodes = NULL; // keycodes list
82 nkeycodes = xkb_keycode_from_keysym( ecore_wl_input_get()->xkb.keymap, keysym, &keycodes );
85 snprintf( keycode_buffer, KEYCODE_BUFFER_SIZE, "%d", keycodes[0] );
95 } // unnamed namespace
103 bool GrabKeyTopmost( Window window, Dali::KEY daliKey )
105 return GrabKey( window, daliKey, TOPMOST);
108 bool UngrabKeyTopmost( Window window, Dali::KEY daliKey )
110 return UngrabKey( window, daliKey );
113 bool GrabKey( Window window, Dali::KEY daliKey, KeyGrabMode grabMode )
115 Ecore_Wl_Window_Keygrab_Mode wlGrabMode;
116 if( grabMode == TOPMOST )
118 wlGrabMode = ECORE_WL_WINDOW_KEYGRAB_TOPMOST;
120 else if( grabMode == SHARED )
122 wlGrabMode = ECORE_WL_WINDOW_KEYGRAB_SHARED;
124 else if( grabMode == OVERRIDE_EXCLUSIVE )
126 wlGrabMode = ECORE_WL_WINDOW_KEYGRAB_EXCLUSIVE;
128 else if( grabMode == EXCLUSIVE )
130 wlGrabMode = ECORE_WL_WINDOW_KEYGRAB_OVERRIDE_EXCLUSIVE;
137 // keycode-related code
138 char keycode[KEYCODE_BUFFER_SIZE];
139 if( !keycode_from_keyname( Dali::Internal::Adaptor::KeyLookup::GetKeyName( daliKey ), keycode ) )
141 DALI_LOG_WARNING( "Unable to get keycode from keyname %s.\n", Dali::Internal::Adaptor::KeyLookup::GetKeyName( daliKey ) );
144 return ecore_wl_window_keygrab_set( AnyCast<Ecore_Wl_Window*>( window.GetNativeHandle() ),
146 0, 0, 0, wlGrabMode );
148 // Currently the 2nd parameter of ecore_wl_window_keygrab_set means keycode, but its meaning will be changed to keyname later.
149 // Once changed, we can remove all "keycode-related code" and just uncomment below line and
150 // also can remove following files:
151 // ecore_wl_private.h, tizen-extension-client-protocol.h, tizen-policy-client-protocol.h
153 //return ecore_wl_window_keygrab_set( AnyCast<Ecore_Wl_Window*>( window.GetNativeHandle() ),
154 //Dali::Internal::Adaptor::KeyLookup::GetKeyName( daliKey ),
155 //0, 0, 0, wlGrabMode );
158 bool UngrabKey( Window window, Dali::KEY daliKey )
160 // keycode-related code
161 char keycode[KEYCODE_BUFFER_SIZE];
162 if( !keycode_from_keyname( Dali::Internal::Adaptor::KeyLookup::GetKeyName( daliKey ), keycode ) )
164 DALI_LOG_WARNING( "Unable to get keycode from keyname %s.\n", Dali::Internal::Adaptor::KeyLookup::GetKeyName( daliKey ) );
167 return ecore_wl_window_keygrab_unset( AnyCast<Ecore_Wl_Window*>( window.GetNativeHandle() ),
171 // Currently the 2nd parameter of ecore_wl_window_keygrab_set means keycode, but its meaning will be changed to keyname later.
172 // Once changed, we can remove all "keycode-related code" and just uncomment below line and
173 // also can remove following files:
174 // ecore_wl_private.h, tizen-extension-client-protocol.h, tizen-policy-client-protocol.h
176 //return ecore_wl_window_keygrab_unset( AnyCast<Ecore_Wl_Window*>( window.GetNativeHandle() ),
177 //Dali::Internal::Adaptor::KeyLookup::GetKeyName( daliKey ),
181 } // namespace KeyGrab