[3.0] Add key grab/ungrab interfaces for Tizen (X11/Wayland)
[platform/core/uifw/dali-adaptor.git] / adaptors / x11 / key-grab-x.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 // CLASS HEADER
19 #include <key-grab.h>
20
21 // EXTERNAL INCLUDES
22 #include <Ecore.h>
23 #include <Ecore_X.h>
24 #include <utilX.h>
25
26 // INTERNAL INCLUDES
27 #include <window.h>
28 #include <key-impl.h>
29 #include <ecore-x-types.h>
30
31 namespace Dali
32 {
33
34 namespace KeyGrab
35 {
36
37 bool GrabKeyTopmost( Window window, Dali::KEY daliKey )
38 {
39   return GrabKey( window, daliKey, TOPMOST);
40 }
41
42 bool UngrabKeyTopmost( Window window, Dali::KEY daliKey )
43 {
44   return UngrabKey( window, daliKey );
45 }
46
47 bool GrabKey( Window window, Dali::KEY daliKey, KeyGrabMode grabMode )
48 {
49   int xGrabMode;
50   if( grabMode == TOPMOST )
51   {
52     xGrabMode = TOP_POSITION_GRAB;
53   }
54   else if( grabMode == SHARED )
55   {
56     xGrabMode = SHARED_GRAB;
57   }
58   else if( grabMode == OVERRIDE_EXCLUSIVE )
59   {
60     xGrabMode = OR_EXCLUSIVE_GRAB;
61   }
62   else if( grabMode == EXCLUSIVE )
63   {
64     xGrabMode = EXCLUSIVE_GRAB;
65   }
66   else
67   {
68     return false;
69   }
70
71   int ret = utilx_grab_key ( static_cast<Display*>( ecore_x_display_get() ),
72                              static_cast<XWindow>( AnyCast<Ecore_X_Window>( window.GetNativeHandle() ) ),
73                              Dali::Internal::Adaptor::KeyLookup::GetKeyName( daliKey ), xGrabMode );
74   return ret==0;
75 }
76
77 bool UngrabKey( Window window, Dali::KEY daliKey )
78 {
79   int ret = utilx_ungrab_key ( static_cast<Display*>( ecore_x_display_get() ),
80                                static_cast<XWindow>( AnyCast<Ecore_X_Window>( window.GetNativeHandle() ) ),
81                                Dali::Internal::Adaptor::KeyLookup::GetKeyName( daliKey ) );
82   return ret==0;
83 }
84
85 } // namespace KeyGrab
86
87 } // namespace Dali
88
89