2 #include "e_devicemgr_private.h"
3 #include "e_input_intern.h"
4 #include "e_comp_wl_intern.h"
6 static void _e_devicemgr_keyboard_grab_client_cb_destroy(struct wl_listener *l, void *data);
9 e_devicemgr_keyboard_grab_subtype_is_grabbed(Ecore_Device_Subclass subclas)
11 if ((subclas == ECORE_DEVICE_SUBCLASS_NONE) &&
12 (e_devicemgr->keyboard_grab.subtype & TIZEN_INPUT_DEVICE_MANAGER_SUBCLAS_NONE))
15 if ((subclas == ECORE_DEVICE_SUBCLASS_REMOCON) &&
16 (e_devicemgr->keyboard_grab.subtype & TIZEN_INPUT_DEVICE_MANAGER_SUBCLAS_REMOCON))
19 if ((subclas == ECORE_DEVICE_SUBCLASS_VIRTUAL_KEYBOARD) &&
20 (e_devicemgr->keyboard_grab.subtype & TIZEN_INPUT_DEVICE_MANAGER_SUBCLAS_VIRTUAL_KEYBOARD))
23 DMWRN("Keyboard Grab. device subclas(%d) is not grabbed", subclas);
28 _e_devicemgr_keyboard_grab_key_handler(uint32_t keycode, uint32_t state,
29 uint32_t timestamp, void *dev)
31 DMINF("key(%d-%s) event is delivered to grab ec(%p)",
32 keycode, state ? "Pressed" : "Released", e_devicemgr->keyboard_grab.ec);
34 if (!e_comp_wl_key_send(e_devicemgr->keyboard_grab.ec, keycode, state ? EINA_TRUE : EINA_FALSE,
37 DMERR("Could not send keyboard_grab_key to client(%p)", e_devicemgr->keyboard_grab.client);
40 e_input_flush_keyboard_share_events();
44 _e_devicemgr_keyboard_grab_client_remove(struct wl_client *client)
46 struct wl_listener *destroy_listener = NULL;
48 if (client != e_devicemgr->keyboard_grab.client)
51 e_devicemgr->keyboard_grab.subtype = 0x0;
52 e_devicemgr->keyboard_grab.client = NULL;
53 e_devicemgr->keyboard_grab.ec = NULL;
55 if (!e_input_keyboard_grab_key_handler_set(NULL))
57 DMERR("ERROR! Could not set keyboard_grab key handler to NULL!");
61 destroy_listener = wl_client_get_destroy_listener(client, _e_devicemgr_keyboard_grab_client_cb_destroy);
64 wl_list_remove(&destroy_listener->link);
65 E_FREE(destroy_listener);
72 _e_devicemgr_keyboard_grab_client_cb_destroy(struct wl_listener *l, void *data)
74 struct wl_client *client = (struct wl_client *)data;
76 if (!e_devicemgr->keyboard_grab.client) return;
78 wl_list_remove(&l->link);
81 _e_devicemgr_keyboard_grab_client_remove(client);
85 _e_devicemgr_keyboard_grab_client_add(struct wl_client *client, E_Client *ec, uint32_t subclas)
87 struct wl_listener *destroy_listener = NULL;
89 e_devicemgr->keyboard_grab.subtype |= subclas;
91 if (e_devicemgr->keyboard_grab.client == client)
94 e_devicemgr->keyboard_grab.client = client;
95 e_devicemgr->keyboard_grab.ec = ec;
97 if (!e_input_keyboard_grab_key_handler_set(_e_devicemgr_keyboard_grab_key_handler))
99 DMERR("ERROR! Could not set keyboard_grab key handler to func!");
103 destroy_listener = E_NEW(struct wl_listener, 1);
104 EINA_SAFETY_ON_NULL_GOTO(destroy_listener, failed);
105 destroy_listener->notify = _e_devicemgr_keyboard_grab_client_cb_destroy;
106 wl_client_add_destroy_listener(client, destroy_listener);
111 e_devicemgr->keyboard_grab.client = NULL;
112 e_devicemgr->keyboard_grab.ec = NULL;
113 e_devicemgr->keyboard_grab.subtype = 0x0;
119 e_devicemgr_keyboard_grab(struct wl_client *client, struct wl_resource *surface, uint32_t subclas)
121 int ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE;
123 uint32_t all_subclass = TIZEN_INPUT_DEVICE_MANAGER_SUBCLAS_NONE |
124 TIZEN_INPUT_DEVICE_MANAGER_SUBCLAS_REMOCON |
125 TIZEN_INPUT_DEVICE_MANAGER_SUBCLAS_VIRTUAL_KEYBOARD;
127 if ((e_devicemgr->keyboard_grab.client) && (e_devicemgr->keyboard_grab.client != client))
129 return TIZEN_INPUT_DEVICE_MANAGER_ERROR_NOT_ALLOWED;
131 if (!(subclas & all_subclass))
133 return TIZEN_INPUT_DEVICE_MANAGER_ERROR_INVALID_CLASS;
136 ec = e_client_from_surface_resource(surface);
138 return TIZEN_INPUT_DEVICE_MANAGER_ERROR_INVALID_SURFACE;
140 if (!_e_devicemgr_keyboard_grab_client_add(client, ec, subclas))
141 ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NOT_ALLOWED;
147 e_devicemgr_keyboard_ungrab(struct wl_client *client, struct wl_resource *surface)
149 int ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE;
152 if ((e_devicemgr->keyboard_grab.client) && (e_devicemgr->keyboard_grab.client != client))
154 return TIZEN_INPUT_DEVICE_MANAGER_ERROR_NOT_ALLOWED;
157 ec = e_client_from_surface_resource(surface);
159 return TIZEN_INPUT_DEVICE_MANAGER_ERROR_INVALID_SURFACE;
161 if (!_e_devicemgr_keyboard_grab_client_remove(client))
162 ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NOT_ALLOWED;