tizen 2.4 release
[framework/uifw/e17-mod-tizen-devicemgr.git] / src / e_mod_main.h
1 #ifndef __E_MOD_MAIN_H__
2 #define __E_MOD_MAIN_H__
3
4 #include "e.h"
5 #include "e_randr.h"
6
7 #include <X11/Xlib.h>
8 #include <X11/Xatom.h>
9 #include <X11/extensions/XInput2.h>
10 #include <X11/extensions/XI2.h>
11 #include <X11/extensions/XIproto.h>
12 #include <X11/extensions/Xrandr.h>
13 #include <X11/extensions/XKB.h>
14
15 #include "scrnconf_devicemgr.h"
16 #include "virt_monitor_devicemgr.h"
17 #include "hib_devicemgr.h"
18 #include "e_mod_scrnconf.h"
19 #include "e_mod_drv.h"
20
21 #ifndef LockMask
22 #define LockMask (1<<1)
23 #define Mod2Mask (1<<4)
24 #endif
25 #define CapsLockMask LockMask
26 #define NumLockMask Mod2Mask
27
28 #ifndef  ECORE_X_RANDR_1_2
29 #define ECORE_X_RANDR_1_2 ((1 << 16) | 2)
30 #endif
31 #ifndef  ECORE_X_RANDR_1_3
32 #define ECORE_X_RANDR_1_3 ((1 << 16) | 3)
33 #endif
34
35 #ifndef  E_RANDR_NO_12
36 #define E_RANDR_NO_12      (!e_randr_screen_info || (e_randr_screen_info->randr_version < ECORE_X_RANDR_1_2) || !e_randr_screen_info->rrvd_info.randr_info_12)
37 #endif
38
39 #ifndef MAX_TOUCH
40 #define MAX_TOUCH 3
41 #endif
42
43 #define INSIDE(x, y, x1, y1, x2, y2)    (x1 <= x && x <= x2 && y1 <= y && y <= y2)
44
45 #define E_PROP_DEVICE_LIST "E_DEVICEMGR_DEVICE_LIST"
46
47 #define XI_PROP_DEVICE_ENABLE "Device Enabled"
48 #define E_PROP_DEVICE_NAME "Device"
49 #define E_PROP_DEVICEMGR_INPUTWIN "DeviceMgr Input Window"
50 #define E_PROP_VIRTUAL_TOUCHPAD_INT "Virtual Touchpad Interaction"
51 #define E_PROP_X_MOUSE_CURSOR_ENABLE "X Mouse Cursor Enable"
52 #define E_PROP_X_MOUSE_EXIST "X Mouse Exist"
53 #define E_PROP_X_EXT_KEYBOARD_EXIST "X External Keyboard Exist"
54 #define E_PROP_HW_KEY_INPUT_STARTED "HW Keyboard Input Started"
55 #define E_PROP_X_EVDEV_AXIS_LABELS "Axis Labels"
56 #define E_PROP_X_EVDEV_BUTTON_LABELS "Button Labels"
57 #define E_PROP_XRROUTPUT "X_RR_PROPERTY_REMOTE_CONTROLLER"
58 #define E_PROP_VIRTUAL_TOUCHPAD "_X_Virtual_Touchpad_"
59 #define E_PROP_TOUCH_INPUT "X_TouchInput"
60 #define E_PROP_VIRTUAL_TOUCHPAD_CONFINE_REGION "Evdev Confine Region"
61 #define E_NEW_MASTER_NAME "New Master"
62 #define E_VIRTUAL_TOUCHPAD_NAME "Virtual Touchpad"
63 #define EVDEVMULTITOUCH_PROP_TRANSFORM "EvdevMultitouch Transform Matrix"
64 #define XATOM_FLOAT "FLOAT"
65 #define E_PROP_EXTERNAL_KEYBOARD_ENABLED "External Keyboard Enabled"
66 #define XI_PROP_REL_MOVE_STATUS "Relative Move Status"
67 #define XI_PROP_REL_MOVE_ACK "Relative Move Acknowledge"
68 #define E_PROP_GAMEMODE_ENABLED "Game Mode Enabled"
69 #define E_PROP_MULTITOUCH_DEVICEID "MultitouchDeviceID"
70 #define E_PROP_PALM_DISABLING_WIN_RUNNING "Palm Disabling Window Running"
71 #define GESTURE_PALM_REJECTION_MODE     "GESTURE_PALM_REJECTION_MODE"
72
73 #define DEVICEMGR_PREFIX "/usr/lib/enlightenment/modules/e17-extra-modules-devicemgr/"
74
75 #ifdef _F_SUPPORT_XTEST_TOUCH_EVENT_
76 #define TOUCH_DEVICE_NAME "Virtual core XTEST touch"
77 #define LEN_TOUCH_DEVICE_NAME 24
78 #define FUNCTION_KEY_DEVICE_NAME "Virtual core XTEST functionkeys"
79 #define LEN_FUNCTION_KEY_DEVICE_NAME 23
80 #endif //_F_SUPPORT_XTEST_TOUCH_EVENT_
81
82 #define GESTURE_WINDOW_STACK_CHANGED "GESTURE_WINDOW_STACK_CHANGED"
83
84 typedef enum _VirtualTouchpad_MsgType
85 {
86    E_VIRTUAL_TOUCHPAD_NEED_TO_INIT,
87    E_VIRTUAL_TOUCHPAD_DO_INIT,
88    E_VIRTUAL_TOUCHPAD_AREA_INFO,
89    E_VIRTUAL_TOUCHPAD_POINTED_WINDOW,
90    E_VIRTUAL_TOUCHPAD_WINDOW,
91    E_VIRTUAL_TOUCHPAD_MT_BEGIN,
92    E_VIRTUAL_TOUCHPAD_MT_END,
93    E_VIRTUAL_TOUCHPAD_MT_MATRIX_SET_DONE,
94    E_VIRTUAL_TOUCHPAD_CONFINE_SET,
95    E_VIRTUAL_TOUCHPAD_CONFINE_UNSET,
96    E_VIRTUAL_TOUCHPAD_SHUTDOWN
97 } VirtualTouchpad_MsgType;
98
99 typedef enum
100 {
101    E_DEVICEMGR_HWKEY= 1,
102    E_DEVICEMGR_KEYBOARD,
103    E_DEVICEMGR_MOUSE,
104    E_DEVICEMGR_TOUCHSCREEN,
105    E_DEVICEMGR_GAMEPAD
106 } DeviceMgrDeviceType;
107
108 typedef struct _DeviceMgr_Device_Info DeviceMgr_Device_Info;
109
110 struct _DeviceMgr_Device_Info
111 {
112    int id;
113    const char *name;
114    DeviceMgrDeviceType type;
115    int master_id;
116    int use;
117 };
118
119 typedef struct _DeviceMgr_
120 {
121    Ecore_X_Display* disp;
122    Ecore_X_Window rootWin;
123    Ecore_X_Window input_window;
124    int num_zones;
125    Eina_List *zones;
126
127    /* scrn conf configuration */
128    Eina_Bool scrnconf_enable;
129    Utilx_Scrnconf_Dispmode default_dispmode;
130    Eina_Bool isPopUpEnabled;
131
132    Eina_Bool xkb_available;
133
134    /* scrn conf preferred size */
135    int hdmi_preferred_w;
136    int hdmi_preferred_h;
137    int virtual_preferred_w;
138    int virtual_preferred_h;
139
140    Ecore_X_Atom atomDeviceEnabled;
141    Ecore_X_Atom atomRROutput;
142    Ecore_X_Atom atomAxisLabels;
143    Ecore_X_Atom atomButtonLabels;
144    Ecore_X_Atom atomXMouseExist;
145    Ecore_X_Atom atomXMouseCursorEnable;
146    Ecore_X_Atom atomXExtKeyboardExist;
147    Ecore_X_Atom atomHWKbdInputStarted;
148    Ecore_X_Atom atomDeviceList;
149    Ecore_X_Atom atomDeviceName;
150    Ecore_X_Atom atomVirtualTouchpadConfineRegion;
151    Ecore_X_Atom atomVirtualTouchpad;
152    Ecore_X_Atom atomTouchInput;
153    Ecore_X_Atom atomInputTransform;
154    Ecore_X_Atom atomFloat;
155    Ecore_X_Atom atomVirtualTouchpadInt;
156    Ecore_X_Atom atomDeviceMgrInputWindow;
157    Ecore_X_Atom atomExKeyboardEnabled;
158    Ecore_X_Atom atomRelativeMoveStatus;
159    Ecore_X_Atom atomRelativeMoveAck;
160    Ecore_X_Atom atomGameModeEnabled;
161    Ecore_X_Atom atomMultitouchDeviceId;
162
163    Ecore_X_Atom atomPalmDisablingWinRunning;
164    Ecore_X_Window palmDisablingWin;
165    Ecore_X_Atom atomPalmRejectionMode;
166
167    /* scrn conf atoms */
168    Ecore_X_Atom atomScrnConfDispModeSet;
169    Ecore_X_Atom atomVirtMonReq;
170    Ecore_X_Atom atomHibReq;
171
172    /* devicemgr config atom */
173    Ecore_X_Atom atomDevMgrCfg;
174
175    /* Notify to gesture driver about window stack change */
176    Ecore_X_Atom atomWindowStackisChanged;
177
178    int num_touchscreen_devices;
179    int num_pointer_devices;
180    int num_keyboard_devices;
181    int num_hwkey_devices;
182    Eina_List *device_list;
183
184    Ecore_Event_Handler *window_property_handler;
185    Ecore_Event_Handler *event_generic_handler;
186    Ecore_Event_Handler *zone_add_handler;
187    Ecore_Event_Handler *zone_del_handler;
188    Ecore_Event_Handler *mouse_in_handler;
189    Ecore_Event_Handler *randr_crtc_handler;
190    Ecore_Event_Handler *randr_output_handler;
191    Ecore_Event_Handler *randr_output_property_handler;
192    Ecore_Event_Handler *client_message_handler;
193    Ecore_Event_Handler *window_destroy_handler;
194    E_Border_Hook *border_move_end_hook;
195    E_Border_Hook *border_resize_end_hook;
196    E_Msg_Handler *e_msg_handler;
197
198    //variables to set XRROutputProperty
199    RROutput output;
200    char rroutput_buf[256];
201    int rroutput_buf_len;
202
203    /* selection */
204    Ecore_X_Atom selection_atom;
205    Ecore_X_Atom selection_type_atom;
206    Eina_Bool selection_ownership;
207    Ecore_X_Window selection_xwin;
208    Ecore_X_Randr_Output selection_output_xid;
209    char selection_prev_owner[256];
210    Ecore_Event_Handler *selection_clear_handler;
211    Ecore_Event_Handler *selection_request_handler;
212    Ecore_Event_Handler *selection_notify_handler;
213    Ecore_Timer *selection_request_timeout;
214
215    //variables related to XI2
216    int xi2_opcode;
217    XIEventMask eventmask;
218
219     //XIMasterPointer id(s)
220    int vcp_id;
221    int vck_id;
222    int vcp_xtest_pointer_id;
223    int vck_xtest_keyboard_id;
224    int new_master_pointer_id;
225    unsigned int cursor_show;
226    int cursor_show_ack;
227    int rel_move_deviceid;
228
229    int virtual_touchpad_id;
230    int virtual_multitouch_id[MAX_TOUCH];
231    int virtual_touchpad_area_info[4];
232    int virtual_touchpad_pointed_window_info[4];
233    int virtual_multitouch_done;
234    int virtual_touchpad_cursor_pos[2];
235
236    Ecore_X_Window virtual_touchpad_window;
237    Ecore_X_Window virtual_touchpad_pointed_window;
238
239    int gamepad_id;
240    int gesture_id;
241    Eina_Bool palm_disabled;
242
243    //input transform matrix
244    float tmatrix[9];
245 } DeviceMgr;
246
247 EAPI extern E_Module_Api e_modapi;
248
249 EAPI void* e_modapi_init (E_Module* m);
250 EAPI int e_modapi_shutdown (E_Module* m);
251 EAPI int e_modapi_save (E_Module* m);
252
253 static int _e_devicemgr_init(void);
254 static void _e_devicemgr_fini(void);
255
256 static int _e_devicemgr_xinput_init(void);
257
258 static int _e_devicemgr_cb_window_property(void *data, int ev_type, void *ev);
259 static int _e_devicemgr_cb_window_destroy(void *data, int ev_type, void *ev);
260 static int _e_devicemgr_cb_event_generic(void *data, int ev_type, void *event);
261 static int _e_devicemgr_cb_zone_add(void *data, int ev_type, void *event);
262 static int _e_devicemgr_cb_zone_del(void *data, int ev_type, void *event);
263 static Eina_Bool _e_devicemgr_cb_mouse_in(void *data, int type, void *event);
264 static void _e_devicemgr_hook_border_move_end(void *data, void *border);
265 static void _e_devicemgr_hook_border_resize_end(void *data, void *border);
266 static Eina_Bool _e_devicemgr_get_zones(void);
267 static E_Zone* _e_devicemgr_get_nth_zone(int index);
268 static void _e_mod_move_e_msg_handler(void *data, const char *name, const char *info, int val, E_Object   *obj, void *msgdata);
269
270 static void _e_devicemgr_update_input_transform_matrix(Eina_Bool reset);
271 static void _e_devicemgr_init_transform_matrix(void);
272 static void _e_devicemgr_init_output(void);
273 static void _e_devicemgr_init_input(void);
274 static int _e_devicemgr_marshalize_string (char* buf, int num, char* srcs[]);
275
276 static int _e_devicemgr_check_device_type(int deviceid, DeviceMgrDeviceType type, const char* devname);
277 static void _e_devicemgr_xi2_device_property_handler(XIPropertyEvent *event);
278 static void _e_devicemgr_xi2_device_changed_handler(XIDeviceChangedEvent *event);
279 static void _e_devicemgr_xi2_device_hierarchy_handler(XIHierarchyEvent *event);
280 static void _e_devicemgr_device_enabled(int id, int type);
281 static void _e_devicemgr_device_disabled(int id, int type);
282 static void _e_devicemgr_master_pointer_added(int id);
283 static void _e_devicemgr_master_pointer_removed(int id);
284 static void _e_devicemgr_slave_switched(int deviceid, int sourceid);
285 static void _e_devicemgr_device_changed(int deviceid, int sourceid);
286 static void _e_devicemgr_enable_mouse_cursor(unsigned int val);
287 static void _e_devicemgr_set_confine_information(int deviceid, E_Zone *zone, Eina_Bool isset, int region[4], Eina_Bool pointer_warp, Eina_Bool confine);
288 static void _e_devicemgr_set_mouse_exist(unsigned int val, int propset);
289 static void _e_devicemgr_set_keyboard_exist(unsigned int val, int is_connected);
290 static void _e_devicemgr_append_prop_touchscreen_device_id(int id);
291 static void _e_devicemgr_remove_prop_touchscreen_device_id(int id);
292
293 static int _e_devicemgr_xkb_init(void);
294 static int _e_devicemgr_get_lockmodifier_mask(void);
295 static int _e_devicemgr_xkb_set_on(unsigned int mask);
296 static int _e_devicemgr_lockmodifier_set(void);
297
298 static Eina_Bool _e_devicemgr_create_master_device(char* master_name);
299 static Eina_Bool _e_devicemgr_remove_master_device(int master_id);
300 static Eina_Bool _e_devicemgr_detach_slave(int slave_id);
301 static Eina_Bool _e_devicemgr_reattach_slave(int slave_id, int master_id);
302 static Eina_Bool _e_devicemgr_virtual_touchpad_helper_enable(Eina_Bool is_enable);
303 static void _e_devicemgr_virtual_multitouch_helper_init(int deviceid);
304 static void _e_devicemgr_virtual_multitouch_helper_fini(void);
305 static void _e_devicemgr_show_device_list(unsigned int val);
306
307 Eina_Bool e_mod_sf_rotation_init(void);
308 Eina_Bool e_mod_sf_rotation_deinit(void);
309 #endif//__E_MOD_MAIN_H__