1 #include "e_devicemgr_private.h"
2 #include "e_input_intern.h"
4 static void _e_devicemgr_block_client_cb_destroy(struct wl_listener *l, void *data);
7 _e_devicemgr_block_client_remove(struct wl_client *client)
9 struct wl_listener *destroy_listener = NULL;
10 Eina_List *dev_list, *l;
11 E_Input_Device *device_data;
12 Eina_Bool res = EINA_TRUE;
14 if (client != e_devicemgr->block.client) return;
16 e_devicemgr->block.devtype = 0x0;
17 if (e_devicemgr->block.duration_timer)
19 ecore_timer_del(e_devicemgr->block.duration_timer);
20 e_devicemgr->block.duration_timer = NULL;
22 e_devicemgr->block.client = NULL;
23 destroy_listener = wl_client_get_destroy_listener(client, _e_devicemgr_block_client_cb_destroy);
26 wl_list_remove(&destroy_listener->link);
27 E_FREE(destroy_listener);
30 dev_list = (Eina_List *)e_input_devices_get();
31 EINA_LIST_FOREACH(dev_list, l, device_data)
33 res = e_input_device_unblock(device_data, client);
34 if (!res) DMWRN("Failed to request unblock client: %p", client);
39 _e_devicemgr_block_timer(void *data)
41 struct wl_resource *resource = (struct wl_resource *)data;
42 struct wl_client *client = wl_resource_get_client(resource);
44 if ((e_devicemgr->block.client) && (e_devicemgr->block.client != client))
46 return ECORE_CALLBACK_CANCEL;
49 _e_devicemgr_block_client_remove(client);
50 e_devicemgr_wl_block_send_expired(resource);
52 return ECORE_CALLBACK_CANCEL;
56 _e_devicemgr_block_client_cb_destroy(struct wl_listener *l, void *data)
58 struct wl_client *client = (struct wl_client *)data;
60 if (!e_devicemgr->block.client) return;
62 wl_list_remove(&l->link);
65 _e_devicemgr_block_client_remove(client);
69 _e_devicemgr_block_client_add(struct wl_client *client, struct wl_resource *resource, uint32_t clas, uint32_t duration)
71 struct wl_listener *destroy_listener = NULL;
72 double milli_duration = (double)(duration) / 1000.0;
73 unsigned int block_type = 0x0;
74 Eina_List *dev_list, *l;
75 E_Input_Device *device_data;
76 Eina_Bool res = EINA_TRUE;
78 /* Last request of block can renew timer time */
79 if (e_devicemgr->block.duration_timer)
80 ecore_timer_del(e_devicemgr->block.duration_timer);
81 e_devicemgr->block.duration_timer = ecore_timer_add(milli_duration, _e_devicemgr_block_timer, resource);
83 e_devicemgr->block.devtype |= clas;
85 if (e_devicemgr->block.client) return;
86 e_devicemgr->block.client = client;
88 destroy_listener = E_NEW(struct wl_listener, 1);
89 EINA_SAFETY_ON_NULL_GOTO(destroy_listener, failed);
90 destroy_listener->notify = _e_devicemgr_block_client_cb_destroy;
91 wl_client_add_destroy_listener(client, destroy_listener);
93 if (e_devicemgr->block.devtype & TIZEN_INPUT_DEVICE_MANAGER_CLAS_MOUSE)
95 block_type |= E_INPUT_SEAT_POINTER;
97 if (e_devicemgr->block.devtype & TIZEN_INPUT_DEVICE_MANAGER_CLAS_KEYBOARD)
99 block_type |= E_INPUT_SEAT_KEYBOARD;
101 if (e_devicemgr->block.devtype & TIZEN_INPUT_DEVICE_MANAGER_CLAS_TOUCHSCREEN)
103 block_type |= E_INPUT_SEAT_TOUCH;
106 dev_list = (Eina_List *)e_input_devices_get();
107 EINA_LIST_FOREACH(dev_list, l, device_data)
109 res = e_input_device_block(device_data, block_type, client);
110 if (!res) DMWRN("Failed to request block block_type: 0x%x, client: %p", block_type, client);
116 ecore_timer_del(e_devicemgr->block.duration_timer);
117 e_devicemgr->block.duration_timer = NULL;
118 e_devicemgr->block.client = NULL;
122 e_devicemgr_block_add(struct wl_client *client, struct wl_resource *resource, uint32_t clas, uint32_t duration)
124 uint32_t all_class = TIZEN_INPUT_DEVICE_MANAGER_CLAS_MOUSE |
125 TIZEN_INPUT_DEVICE_MANAGER_CLAS_KEYBOARD |
126 TIZEN_INPUT_DEVICE_MANAGER_CLAS_TOUCHSCREEN;
128 if ((e_devicemgr->block.client) && (e_devicemgr->block.client != client))
130 return TIZEN_INPUT_DEVICE_MANAGER_ERROR_BLOCKED_ALREADY;
132 if (!(clas & all_class))
134 return TIZEN_INPUT_DEVICE_MANAGER_ERROR_INVALID_CLASS;
137 _e_devicemgr_block_client_add(client, resource, clas, duration);
139 /* TODO: Release pressed button or key */
141 return TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE;
145 e_devicemgr_block_remove(struct wl_client *client)
147 if ((e_devicemgr->block.client) && (e_devicemgr->block.client != client))
149 return TIZEN_INPUT_DEVICE_MANAGER_ERROR_BLOCKED_ALREADY;
152 _e_devicemgr_block_client_remove(client);
154 return TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE;
158 _e_devicemgr_block_timer_internal(void *data)
160 Eina_List *dev_list, *l;
161 E_Input_Device *device_data;
164 e_devicemgr->block.internal_devtype = 0x0;
165 e_devicemgr->block.internal_duration_timer = NULL;
167 if (!e_devicemgr->block.internal_cb_func) return ECORE_CALLBACK_CANCEL;
169 //Call expiration cb for internal block
170 e_devicemgr->block.internal_cb_func(e_devicemgr->block.internal_cb_data);
172 e_devicemgr->block.internal_cb_func = NULL;
173 e_devicemgr->block.internal_cb_data = NULL;
175 dev_list = (Eina_List *)e_input_devices_get();
176 EINA_LIST_FOREACH(dev_list, l, device_data)
178 res = e_input_device_unblock(device_data, E_INPUT_REQUEST_SERVER);
179 if (!res) DMWRN("Failed to request unblock by server");
182 return ECORE_CALLBACK_DONE;
188 e_devicemgr_block_add_internal(uint32_t clas, uint32_t duration, E_Devicemgr_Block_Expire_Cb cb_func, void *cb_data)
190 uint32_t all_class = TIZEN_INPUT_DEVICE_MANAGER_CLAS_MOUSE |
191 TIZEN_INPUT_DEVICE_MANAGER_CLAS_KEYBOARD |
192 TIZEN_INPUT_DEVICE_MANAGER_CLAS_TOUCHSCREEN;
193 unsigned int block_type = 0x0;
194 Eina_List *dev_list, *l;
195 E_Input_Device *device_data;
198 if (!(clas & all_class)) return EINA_FALSE;
200 if (e_devicemgr->block.internal_duration_timer)
201 ecore_timer_del(e_devicemgr->block.internal_duration_timer);
202 e_devicemgr->block.internal_duration_timer = ecore_timer_add(duration / 1000.0, _e_devicemgr_block_timer_internal, NULL);
204 e_devicemgr->block.internal_devtype |= clas;
206 e_devicemgr->block.internal_cb_func = cb_func;
207 e_devicemgr->block.internal_cb_data = cb_data;
209 if (e_devicemgr->block.internal_devtype & TIZEN_INPUT_DEVICE_MANAGER_CLAS_MOUSE)
211 block_type |= E_INPUT_SEAT_POINTER;
213 if (e_devicemgr->block.internal_devtype & TIZEN_INPUT_DEVICE_MANAGER_CLAS_KEYBOARD)
215 block_type |= E_INPUT_SEAT_KEYBOARD;
217 if (e_devicemgr->block.internal_devtype & TIZEN_INPUT_DEVICE_MANAGER_CLAS_TOUCHSCREEN)
219 block_type |= E_INPUT_SEAT_TOUCH;
222 dev_list = (Eina_List *)e_input_devices_get();
223 EINA_LIST_FOREACH(dev_list, l, device_data)
225 res = e_input_device_block(device_data, block_type, E_INPUT_REQUEST_SERVER);
226 if (!res) DMWRN("Failed to request block block_type: 0x%x by server", block_type);
233 e_devicemgr_block_remove_internal(E_Devicemgr_Block_Expire_Cb cb_func, void *cb_data)
235 Eina_List *dev_list, *l;
236 E_Input_Device *device_data;
239 if ((e_devicemgr->block.internal_cb_func != cb_func) ||
240 (e_devicemgr->block.internal_cb_data != cb_data)) return EINA_FALSE;
242 e_devicemgr->block.internal_devtype = 0x0;
243 if (e_devicemgr->block.internal_duration_timer)
245 ecore_timer_del(e_devicemgr->block.internal_duration_timer);
246 e_devicemgr->block.internal_duration_timer = NULL;
249 e_devicemgr->block.internal_cb_func = NULL;
250 e_devicemgr->block.internal_cb_data = NULL;
252 dev_list = (Eina_List *)e_input_devices_get();
253 EINA_LIST_FOREACH(dev_list, l, device_data)
255 res = e_input_device_unblock(device_data, E_INPUT_REQUEST_SERVER);
256 if (!res) DMWRN("Failed to request unblock by server");