2 #include "e_devicemgr_private.h"
3 #include "e_input_intern.h"
5 static void _e_devicemgr_block_client_cb_destroy(struct wl_listener *l, void *data);
8 _e_devicemgr_block_client_remove(struct wl_client *client)
10 struct wl_listener *destroy_listener = NULL;
11 Eina_List *dev_list, *l;
12 E_Input_Device *device_data;
13 Eina_Bool res = EINA_TRUE;
15 if (client != e_devicemgr->block.client) return;
17 e_devicemgr->block.devtype = 0x0;
18 if (e_devicemgr->block.duration_timer)
20 ecore_timer_del(e_devicemgr->block.duration_timer);
21 e_devicemgr->block.duration_timer = NULL;
23 e_devicemgr->block.client = NULL;
24 destroy_listener = wl_client_get_destroy_listener(client, _e_devicemgr_block_client_cb_destroy);
27 wl_list_remove(&destroy_listener->link);
28 E_FREE(destroy_listener);
31 dev_list = (Eina_List *)e_input_devices_get();
32 EINA_LIST_FOREACH(dev_list, l, device_data)
34 res = e_input_device_unblock(device_data, client);
35 if (!res) DMWRN("Failed to request unblock client: %p", client);
40 _e_devicemgr_block_timer(void *data)
42 struct wl_resource *resource = (struct wl_resource *)data;
43 struct wl_client *client = wl_resource_get_client(resource);
45 if ((e_devicemgr->block.client) && (e_devicemgr->block.client != client))
47 return ECORE_CALLBACK_CANCEL;
50 _e_devicemgr_block_client_remove(client);
51 e_devicemgr_wl_block_send_expired(resource);
53 return ECORE_CALLBACK_CANCEL;
57 _e_devicemgr_block_client_cb_destroy(struct wl_listener *l, void *data)
59 struct wl_client *client = (struct wl_client *)data;
61 if (!e_devicemgr->block.client) return;
63 wl_list_remove(&l->link);
66 _e_devicemgr_block_client_remove(client);
70 _e_devicemgr_block_client_add(struct wl_client *client, struct wl_resource *resource, uint32_t clas, uint32_t duration)
72 struct wl_listener *destroy_listener = NULL;
73 double milli_duration = (double)(duration) / 1000.0;
74 unsigned int block_type = 0x0;
75 Eina_List *dev_list, *l;
76 E_Input_Device *device_data;
77 Eina_Bool res = EINA_TRUE;
79 /* Last request of block can renew timer time */
80 if (e_devicemgr->block.duration_timer)
81 ecore_timer_del(e_devicemgr->block.duration_timer);
82 e_devicemgr->block.duration_timer = ecore_timer_add(milli_duration, _e_devicemgr_block_timer, resource);
84 e_devicemgr->block.devtype |= clas;
86 if (e_devicemgr->block.client) return;
87 e_devicemgr->block.client = client;
89 destroy_listener = E_NEW(struct wl_listener, 1);
90 EINA_SAFETY_ON_NULL_GOTO(destroy_listener, failed);
91 destroy_listener->notify = _e_devicemgr_block_client_cb_destroy;
92 wl_client_add_destroy_listener(client, destroy_listener);
94 if (e_devicemgr->block.devtype & TIZEN_INPUT_DEVICE_MANAGER_CLAS_MOUSE)
96 block_type |= E_INPUT_SEAT_POINTER;
98 if (e_devicemgr->block.devtype & TIZEN_INPUT_DEVICE_MANAGER_CLAS_KEYBOARD)
100 block_type |= E_INPUT_SEAT_KEYBOARD;
102 if (e_devicemgr->block.devtype & TIZEN_INPUT_DEVICE_MANAGER_CLAS_TOUCHSCREEN)
104 block_type |= E_INPUT_SEAT_TOUCH;
107 dev_list = (Eina_List *)e_input_devices_get();
108 EINA_LIST_FOREACH(dev_list, l, device_data)
110 res = e_input_device_block(device_data, block_type, client);
111 if (!res) DMWRN("Failed to request block block_type: 0x%x, client: %p", block_type, client);
117 ecore_timer_del(e_devicemgr->block.duration_timer);
118 e_devicemgr->block.duration_timer = NULL;
119 e_devicemgr->block.client = NULL;
123 e_devicemgr_block_add(struct wl_client *client, struct wl_resource *resource, uint32_t clas, uint32_t duration)
125 uint32_t all_class = TIZEN_INPUT_DEVICE_MANAGER_CLAS_MOUSE |
126 TIZEN_INPUT_DEVICE_MANAGER_CLAS_KEYBOARD |
127 TIZEN_INPUT_DEVICE_MANAGER_CLAS_TOUCHSCREEN;
129 if ((e_devicemgr->block.client) && (e_devicemgr->block.client != client))
131 return TIZEN_INPUT_DEVICE_MANAGER_ERROR_BLOCKED_ALREADY;
133 if (!(clas & all_class))
135 return TIZEN_INPUT_DEVICE_MANAGER_ERROR_INVALID_CLASS;
138 _e_devicemgr_block_client_add(client, resource, clas, duration);
140 /* TODO: Release pressed button or key */
142 return TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE;
146 e_devicemgr_block_remove(struct wl_client *client)
148 if ((e_devicemgr->block.client) && (e_devicemgr->block.client != client))
150 return TIZEN_INPUT_DEVICE_MANAGER_ERROR_BLOCKED_ALREADY;
153 _e_devicemgr_block_client_remove(client);
155 return TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE;
159 _e_devicemgr_block_timer_internal(void *data)
161 Eina_List *dev_list, *l;
162 E_Input_Device *device_data;
165 e_devicemgr->block.internal_devtype = 0x0;
166 e_devicemgr->block.internal_duration_timer = NULL;
168 if (!e_devicemgr->block.internal_cb_func) return ECORE_CALLBACK_CANCEL;
170 //Call expiration cb for internal block
171 e_devicemgr->block.internal_cb_func(e_devicemgr->block.internal_cb_data);
173 e_devicemgr->block.internal_cb_func = NULL;
174 e_devicemgr->block.internal_cb_data = NULL;
176 dev_list = (Eina_List *)e_input_devices_get();
177 EINA_LIST_FOREACH(dev_list, l, device_data)
179 res = e_input_device_unblock(device_data, E_INPUT_REQUEST_SERVER);
180 if (!res) DMWRN("Failed to request unblock by server");
183 return ECORE_CALLBACK_DONE;
189 e_devicemgr_block_add_internal(uint32_t clas, uint32_t duration, E_Devicemgr_Block_Expire_Cb cb_func, void *cb_data)
191 uint32_t all_class = TIZEN_INPUT_DEVICE_MANAGER_CLAS_MOUSE |
192 TIZEN_INPUT_DEVICE_MANAGER_CLAS_KEYBOARD |
193 TIZEN_INPUT_DEVICE_MANAGER_CLAS_TOUCHSCREEN;
194 unsigned int block_type = 0x0;
195 Eina_List *dev_list, *l;
196 E_Input_Device *device_data;
199 if (!(clas & all_class)) return EINA_FALSE;
201 if (e_devicemgr->block.internal_duration_timer)
202 ecore_timer_del(e_devicemgr->block.internal_duration_timer);
203 e_devicemgr->block.internal_duration_timer = ecore_timer_add(duration / 1000.0, _e_devicemgr_block_timer_internal, NULL);
205 e_devicemgr->block.internal_devtype |= clas;
207 e_devicemgr->block.internal_cb_func = cb_func;
208 e_devicemgr->block.internal_cb_data = cb_data;
210 if (e_devicemgr->block.internal_devtype & TIZEN_INPUT_DEVICE_MANAGER_CLAS_MOUSE)
212 block_type |= E_INPUT_SEAT_POINTER;
214 if (e_devicemgr->block.internal_devtype & TIZEN_INPUT_DEVICE_MANAGER_CLAS_KEYBOARD)
216 block_type |= E_INPUT_SEAT_KEYBOARD;
218 if (e_devicemgr->block.internal_devtype & TIZEN_INPUT_DEVICE_MANAGER_CLAS_TOUCHSCREEN)
220 block_type |= E_INPUT_SEAT_TOUCH;
223 dev_list = (Eina_List *)e_input_devices_get();
224 EINA_LIST_FOREACH(dev_list, l, device_data)
226 res = e_input_device_block(device_data, block_type, E_INPUT_REQUEST_SERVER);
227 if (!res) DMWRN("Failed to request block block_type: 0x%x by server", block_type);
234 e_devicemgr_block_remove_internal(E_Devicemgr_Block_Expire_Cb cb_func, void *cb_data)
236 Eina_List *dev_list, *l;
237 E_Input_Device *device_data;
240 if ((e_devicemgr->block.internal_cb_func != cb_func) ||
241 (e_devicemgr->block.internal_cb_data != cb_data)) return EINA_FALSE;
243 e_devicemgr->block.internal_devtype = 0x0;
244 if (e_devicemgr->block.internal_duration_timer)
246 ecore_timer_del(e_devicemgr->block.internal_duration_timer);
247 e_devicemgr->block.internal_duration_timer = NULL;
250 e_devicemgr->block.internal_cb_func = NULL;
251 e_devicemgr->block.internal_cb_data = NULL;
253 dev_list = (Eina_List *)e_input_devices_get();
254 EINA_LIST_FOREACH(dev_list, l, device_data)
256 res = e_input_device_unblock(device_data, E_INPUT_REQUEST_SERVER);
257 if (!res) DMWRN("Failed to request unblock by server");