Merge branch 'devel/master(1.1.39)' into tizen
[platform/core/uifw/dali-adaptor.git] / adaptors / x11 / x-events / x-input2.h
1 #ifndef __DALI_INTERNAL_X_INPUT_2_MANAGER_H__
2 #define __DALI_INTERNAL_X_INPUT_2_MANAGER_H__
3
4 /*
5  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <X11/X.h>
23 #include <X11/Xlib.h>
24 #include <X11/extensions/XInput2.h>
25 #include <X11/extensions/XI2.h>
26 #include <dali/public-api/common/dali-vector.h>
27
28 // INTERNAL INCLUDES
29 #include <base/interfaces/window-event-interface.h>
30 #include "x-input2-device.h"
31
32 namespace Dali
33 {
34
35 namespace Internal
36 {
37
38 namespace Adaptor
39 {
40
41 /**
42  *
43  * @brief Used to setup and process XInput2 events.
44  *
45  * For help with debugging, build DALi in debug mode then set the environment variables
46  * export LOG_X_INPUT_EVENTS=2
47  * export LOG_X_INPUT_DEVICES=2
48  */
49 class XInput2
50 {
51
52 public:
53
54   /**
55    * @brief Constructor
56    */
57   XInput2( XID window, Display* display, WindowEventInterface* eventInterface );
58
59   /**
60    * @brief destructor
61    */
62   ~XInput2();
63
64   /**
65    * @brief enumerates input devices using XIQueryDevice then sets up event filtering using XISelectEvents
66    */
67   void Initialize();
68
69   /**
70    * @brief get X the extension id
71    * @return the Id
72    */
73   int GetExtensionId() const;
74
75   /**
76    * @brief process a generic X event
77    * @param[in] cookie X cookie
78    */
79   void ProcessGenericEvent( XGenericEventCookie* cookie );
80
81   /**
82    * @brief process XKeyEvent
83    * @param[in] XKeyEvent key event
84    */
85    void ProcessKeyEvent( XKeyEvent* xKeyEvent );
86
87    /**
88     * @brief process XKeyEvent
89     * @param[in] event x-event
90     */
91    void ProcessClientMessage( XEvent* event );
92
93 private:
94
95   /**
96    * @brief query x input devices
97    */
98   void QueryDevices();
99
100   /**
101    * @brief query multi-touch support
102    */
103   void QueryMultiTouchSupport();
104
105   /**
106    * Uses XISelectEvents to select the events we want to recieve from each input device
107    */
108   void SelectInputEvents();
109
110   /**
111    * @brief checks if we are filtering events from a specific device
112    * @param[in] deviceId device id
113    * @return true if the device is being filtered
114    */
115   bool FilteredDevice( int deviceId ) const;
116
117   /**
118    * @brief Select specific events to be filtered on a device
119    * @param[in] device id
120    * @param[in] filter vector of X input events like XI_ButtonPress
121    */
122   void SelectEvents( int deviceId, const Dali::Vector< unsigned int >& filter );
123
124   /**
125    * @brief checks if the event should be processed
126    * @param[in] deviceEvent device event
127    * @return true if should be processed
128    */
129   bool PreProcessEvent( XIDeviceEvent *deviceEvent ) const;
130
131   /**
132    * @brief creates a DALi key event given a XIDeviceEvent for a key press
133    * @param[in] deviceEvent device event
134    * @param[out] keyEvent DALi key event
135    */
136   void CreateKeyEvent( const XIDeviceEvent* deviceEvent, KeyEvent& keyEvent ) const;
137
138 private:
139
140   Dali::Vector< XInput2Device > mInputDeviceInfo;   ///< list of input devices
141   WindowEventInterface* mEventInterface;            ///< window event interface
142   Display* mDisplay;                                ///< X display
143   XID mWindow;                                      ///< X window
144   int mXI2ExtensionId;                              ///< XI2 extension id
145   bool mMultiTouchSupport:1;                        ///< whether multi-touch is supported
146 };
147
148 } // namespace Adaptor
149 } // namespace Internal
150 } // namespace Dali
151
152 #endif