1 #include "e_devicemgr_private.h"
2 #include "e_input_intern.h"
3 #include "e_comp_wl_intern.h"
5 static void _e_devicemgr_keyboard_grab_client_cb_destroy(struct wl_listener *l, void *data);
8 e_devicemgr_keyboard_grab_subtype_is_grabbed(Ecore_Device_Subclass subclas)
10 if ((subclas == ECORE_DEVICE_SUBCLASS_NONE) &&
11 (e_devicemgr->keyboard_grab.subtype & TIZEN_INPUT_DEVICE_MANAGER_SUBCLAS_NONE))
14 if ((subclas == ECORE_DEVICE_SUBCLASS_REMOCON) &&
15 (e_devicemgr->keyboard_grab.subtype & TIZEN_INPUT_DEVICE_MANAGER_SUBCLAS_REMOCON))
18 if ((subclas == ECORE_DEVICE_SUBCLASS_VIRTUAL_KEYBOARD) &&
19 (e_devicemgr->keyboard_grab.subtype & TIZEN_INPUT_DEVICE_MANAGER_SUBCLAS_VIRTUAL_KEYBOARD))
22 DMWRN("Keyboard Grab. device subclas(%d) is not grabbed", subclas);
27 _e_devicemgr_keyboard_grab_key_handler(uint32_t keycode, uint32_t state,
28 uint32_t timestamp, void *dev)
30 DMINF("key(%d-%s) event is delivered to grab ec(%p)",
31 keycode, state ? "Pressed" : "Released", e_devicemgr->keyboard_grab.ec);
33 if (!e_comp_wl_key_send(e_devicemgr->keyboard_grab.ec, keycode, state ? EINA_TRUE : EINA_FALSE,
36 DMERR("Could not send keyboard_grab_key to client(%p)", e_devicemgr->keyboard_grab.client);
39 e_input_flush_keyboard_share_events();
43 _e_devicemgr_keyboard_grab_client_remove(struct wl_client *client)
45 struct wl_listener *destroy_listener = NULL;
47 if (client != e_devicemgr->keyboard_grab.client)
50 e_devicemgr->keyboard_grab.subtype = 0x0;
51 e_devicemgr->keyboard_grab.client = NULL;
52 e_devicemgr->keyboard_grab.ec = NULL;
54 if (!e_input_keyboard_grab_key_handler_set(NULL))
56 DMERR("ERROR! Could not set keyboard_grab key handler to NULL!");
60 destroy_listener = wl_client_get_destroy_listener(client, _e_devicemgr_keyboard_grab_client_cb_destroy);
63 wl_list_remove(&destroy_listener->link);
64 E_FREE(destroy_listener);
71 _e_devicemgr_keyboard_grab_client_cb_destroy(struct wl_listener *l, void *data)
73 struct wl_client *client = (struct wl_client *)data;
75 if (!e_devicemgr->keyboard_grab.client) return;
77 wl_list_remove(&l->link);
80 _e_devicemgr_keyboard_grab_client_remove(client);
84 _e_devicemgr_keyboard_grab_client_add(struct wl_client *client, E_Client *ec, uint32_t subclas)
86 struct wl_listener *destroy_listener = NULL;
88 e_devicemgr->keyboard_grab.subtype |= subclas;
90 if (e_devicemgr->keyboard_grab.client == client)
93 e_devicemgr->keyboard_grab.client = client;
94 e_devicemgr->keyboard_grab.ec = ec;
96 if (!e_input_keyboard_grab_key_handler_set(_e_devicemgr_keyboard_grab_key_handler))
98 DMERR("ERROR! Could not set keyboard_grab key handler to func!");
102 destroy_listener = E_NEW(struct wl_listener, 1);
103 EINA_SAFETY_ON_NULL_GOTO(destroy_listener, failed);
104 destroy_listener->notify = _e_devicemgr_keyboard_grab_client_cb_destroy;
105 wl_client_add_destroy_listener(client, destroy_listener);
110 e_devicemgr->keyboard_grab.client = NULL;
111 e_devicemgr->keyboard_grab.ec = NULL;
112 e_devicemgr->keyboard_grab.subtype = 0x0;
118 e_devicemgr_keyboard_grab(struct wl_client *client, struct wl_resource *surface, uint32_t subclas)
120 int ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE;
122 uint32_t all_subclass = TIZEN_INPUT_DEVICE_MANAGER_SUBCLAS_NONE |
123 TIZEN_INPUT_DEVICE_MANAGER_SUBCLAS_REMOCON |
124 TIZEN_INPUT_DEVICE_MANAGER_SUBCLAS_VIRTUAL_KEYBOARD;
126 if ((e_devicemgr->keyboard_grab.client) && (e_devicemgr->keyboard_grab.client != client))
128 return TIZEN_INPUT_DEVICE_MANAGER_ERROR_NOT_ALLOWED;
130 if (!(subclas & all_subclass))
132 return TIZEN_INPUT_DEVICE_MANAGER_ERROR_INVALID_CLASS;
135 ec = e_client_from_surface_resource(surface);
137 return TIZEN_INPUT_DEVICE_MANAGER_ERROR_INVALID_SURFACE;
139 if (!_e_devicemgr_keyboard_grab_client_add(client, ec, subclas))
140 ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NOT_ALLOWED;
146 e_devicemgr_keyboard_ungrab(struct wl_client *client, struct wl_resource *surface)
148 int ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE;
151 if ((e_devicemgr->keyboard_grab.client) && (e_devicemgr->keyboard_grab.client != client))
153 return TIZEN_INPUT_DEVICE_MANAGER_ERROR_NOT_ALLOWED;
156 ec = e_client_from_surface_resource(surface);
158 return TIZEN_INPUT_DEVICE_MANAGER_ERROR_INVALID_SURFACE;
160 if (!_e_devicemgr_keyboard_grab_client_remove(client))
161 ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NOT_ALLOWED;