Merge "Pause adaptor when the window is hidden" into devel/master
[platform/core/uifw/dali-adaptor.git] / adaptors / x11 / key-grab-x.cpp
1 /*
2  * Copyright (c) 2016 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_X.h>
23 #include <utilX.h>
24
25 // INTERNAL INCLUDES
26 #include <window.h>
27 #include <key-impl.h>
28 #include <ecore-x-types.h>
29
30 namespace Dali
31 {
32
33 namespace KeyGrab
34 {
35
36 bool GrabKeyTopmost( Window window, Dali::KEY daliKey )
37 {
38   return GrabKey( window, daliKey, TOPMOST);
39 }
40
41 bool UngrabKeyTopmost( Window window, Dali::KEY daliKey )
42 {
43   return UngrabKey( window, daliKey );
44 }
45
46 bool GrabKey( Window window, Dali::KEY daliKey, KeyGrabMode grabMode )
47 {
48   int xGrabMode;
49   if( grabMode == TOPMOST )
50   {
51     xGrabMode = TOP_POSITION_GRAB;
52   }
53   else if( grabMode == SHARED )
54   {
55     xGrabMode = SHARED_GRAB;
56   }
57   else if( grabMode == OVERRIDE_EXCLUSIVE )
58   {
59     xGrabMode = OR_EXCLUSIVE_GRAB;
60   }
61   else if( grabMode == EXCLUSIVE )
62   {
63     xGrabMode = EXCLUSIVE_GRAB;
64   }
65   else
66   {
67     return false;
68   }
69
70   int ret = utilx_grab_key ( static_cast<Display*>( ecore_x_display_get() ),
71                              static_cast<XWindow>( AnyCast<Ecore_X_Window>( window.GetNativeHandle() ) ),
72                              Dali::Internal::Adaptor::KeyLookup::GetKeyName( daliKey ), xGrabMode );
73   return ret==0;
74 }
75
76 bool UngrabKey( Window window, Dali::KEY daliKey )
77 {
78   int ret = utilx_ungrab_key ( static_cast<Display*>( ecore_x_display_get() ),
79                                static_cast<XWindow>( AnyCast<Ecore_X_Window>( window.GetNativeHandle() ) ),
80                                Dali::Internal::Adaptor::KeyLookup::GetKeyName( daliKey ) );
81   return ret==0;
82 }
83
84 } // namespace KeyGrab
85
86 } // namespace Dali
87
88