2 #include <wayland-server.h>
3 #include <text-server-protocol.h>
7 #include <libds-tizen/text_input.h>
9 #define TEXT_INPUT_VERSION 1
11 struct ds_tizen_text_input {
12 struct wl_resource *resource;
17 struct wl_signal destroy;
18 struct wl_signal activate;
19 struct wl_signal deactivate;
20 struct wl_signal reset;
21 struct wl_signal set_content_type;
22 struct wl_signal invoke_action;
23 struct wl_signal commit_state;
24 struct wl_signal set_preferred_language;
28 struct ds_tizen_text_input_manager {
29 struct wl_global *global;
30 struct wl_list text_inputs;
32 struct wl_listener destroy;
35 struct wl_signal new_text_input;
36 struct wl_signal destroy;
40 static const struct wl_text_input_interface text_input_impl;
41 static const struct wl_text_input_manager_interface text_input_mgr_impl;
44 ds_tizen_text_input_manager_add_destroy_listener(
45 struct ds_tizen_text_input_manager *ti_mgr, struct wl_listener *listener)
47 wl_signal_add(&ti_mgr->events.destroy, listener);
51 ds_tizen_text_input_manager_add_new_text_input_listener(
52 struct ds_tizen_text_input_manager *ti_mgr, struct wl_listener *listener)
54 wl_signal_add(&ti_mgr->events.new_text_input, listener);
58 ds_tizen_text_input_add_destroy_listener(
59 struct ds_tizen_text_input *ti, struct wl_listener *listener)
61 wl_signal_add(&ti->events.destroy, listener);
65 ds_tizen_text_input_add_activate_listener(
66 struct ds_tizen_text_input *ti, struct wl_listener *listener)
68 wl_signal_add(&ti->events.activate, listener);
72 ds_tizen_text_input_add_deactivate_listener(
73 struct ds_tizen_text_input *ti, struct wl_listener *listener)
75 wl_signal_add(&ti->events.deactivate, listener);
79 ds_tizen_text_input_add_reset_listener(
80 struct ds_tizen_text_input *ti, struct wl_listener *listener)
82 wl_signal_add(&ti->events.reset, listener);
86 ds_tizen_text_input_add_set_content_type_listener(
87 struct ds_tizen_text_input *ti, struct wl_listener *listener)
89 wl_signal_add(&ti->events.set_content_type, listener);
93 ds_tizen_text_input_add_set_preferred_language_listener(
94 struct ds_tizen_text_input *ti, struct wl_listener *listener)
96 wl_signal_add(&ti->events.set_preferred_language, listener);
100 ds_tizen_text_input_add_commit_state_listener(
101 struct ds_tizen_text_input *ti, struct wl_listener *listener)
103 wl_signal_add(&ti->events.commit_state, listener);
107 ds_tizen_text_input_add_invoke_action_listener(
108 struct ds_tizen_text_input *ti, struct wl_listener *listener)
110 wl_signal_add(&ti->events.invoke_action, listener);
114 ds_tizen_text_input_send_enter(struct ds_tizen_text_input *ti,
115 struct ds_surface *surface)
117 struct wl_resource *resource;
119 ds_inf("ds_tizen_text_input_send_enter");
120 resource = ds_surface_get_wl_resource(surface);
121 wl_text_input_send_enter(ti->resource, resource);
125 ds_tizen_text_input_send_leave(struct ds_tizen_text_input *ti)
127 ds_inf("ds_tizen_text_input_send_leave");
128 wl_text_input_send_leave(ti->resource);
132 ds_tizen_text_input_send_modifiers_map(struct ds_tizen_text_input *ti,
133 struct wl_array *map)
135 ds_inf("ds_tizen_text_input_send_modifiers_map");
136 wl_text_input_send_modifiers_map(ti->resource, map);
140 ds_tizen_text_input_send_input_panel_state(struct ds_tizen_text_input *ti,
143 ds_inf("ds_tizen_text_input_send_input_panel_state");
144 wl_text_input_send_input_panel_state(ti->resource, state);
148 ds_tizen_text_input_send_preedit_string(struct ds_tizen_text_input *ti,
149 uint32_t serial, const char *text, const char *commit)
151 ds_inf("ds_tizen_text_input_send_preedit_string");
152 wl_text_input_send_preedit_string(ti->resource, serial, text, commit);
156 ds_tizen_text_input_send_preedit_styling(struct ds_tizen_text_input *ti,
157 uint32_t index, uint32_t length, uint32_t style)
159 ds_inf("ds_tizen_text_input_send_preedit_styling");
160 wl_text_input_send_preedit_styling(ti->resource, index, length, style);
164 ds_tizen_text_input_send_preedit_cursor(struct ds_tizen_text_input *ti,
167 ds_inf("ds_tizen_text_input_send_preedit_cursor");
168 wl_text_input_send_preedit_cursor(ti->resource, index);
172 ds_tizen_text_input_send_commit_string(struct ds_tizen_text_input *ti,
173 uint32_t serial, const char *text)
175 ds_inf("ds_tizen_text_input_send_commit_string");
176 wl_text_input_send_commit_string(ti->resource, serial, text);
180 ds_tizen_text_input_send_cursor_position(struct ds_tizen_text_input *ti,
181 int32_t index, int32_t anchor)
183 ds_inf("ds_tizen_text_input_send_cursor_position");
184 wl_text_input_send_cursor_position(ti->resource, index, anchor);
188 ds_tizen_text_input_send_delete_surrounding_text(struct ds_tizen_text_input *ti,
189 int32_t index, uint32_t length)
191 ds_inf("ds_tizen_text_input_send_delete_surrounding_text");
192 wl_text_input_send_delete_surrounding_text(ti->resource, index, length);
196 ds_tizen_text_input_send_keysym(struct ds_tizen_text_input *ti,
197 uint32_t serial, uint32_t time, uint32_t sym, uint32_t state,
200 ds_inf("ds_tizen_text_input_send_keysym");
201 wl_text_input_send_keysym(ti->resource, serial, time, sym, state, modifiers);
205 ds_tizen_text_input_send_language(struct ds_tizen_text_input *ti,
206 uint32_t serial, const char *language)
208 ds_inf("ds_tizen_text_input_send_language");
209 wl_text_input_send_language(ti->resource, serial, language);
213 ds_tizen_text_input_send_text_direction(struct ds_tizen_text_input *ti,
214 uint32_t serial, uint32_t direction)
216 ds_inf("ds_tizen_text_input_send_text_direction");
217 wl_text_input_send_text_direction(ti->resource, serial, direction);
221 text_input_handle_destroy(struct wl_client *client, struct wl_resource *resource)
223 ds_inf("text_input_handle_destroy");
224 wl_resource_destroy(resource);
228 text_input_handle_activate(struct wl_client *client,
229 struct wl_resource *resource, struct wl_resource *seat, struct wl_resource *surface)
231 struct ds_tizen_text_input *text_input = wl_resource_get_user_data(resource);
232 struct ds_tizen_text_input_event_activate ds_event;
233 struct ds_surface *ds_surf;
234 struct ds_seat_client *seat_client;
236 ds_inf("text_input_handle_activate");
237 ds_surf = ds_surface_from_resource(surface);
239 ds_event.text_input = text_input;
240 seat_client = ds_seat_client_from_resource(seat);
242 ds_event.seat = ds_seat_client_get_seat(seat_client);
243 ds_event.surface = ds_surf;
244 wl_signal_emit(&text_input->events.activate, &ds_event);
246 ds_tizen_text_input_send_enter(text_input, ds_surf);
250 text_input_handle_deactivate(struct wl_client *client,
251 struct wl_resource *resource, struct wl_resource *seat)
253 struct ds_tizen_text_input *text_input = wl_resource_get_user_data(resource);
254 struct ds_tizen_text_input_event_deactivate ds_event;
255 struct ds_seat_client *seat_client;
257 ds_inf("text_input_handle_deactivate");
258 ds_event.text_input = text_input;
259 seat_client = ds_seat_client_from_resource(seat);
261 ds_event.seat = ds_seat_client_get_seat(seat_client);
262 wl_signal_emit(&text_input->events.deactivate, &ds_event);
264 ds_tizen_text_input_send_leave(text_input);
268 text_input_handle_show_input_panel(struct wl_client *client,
269 struct wl_resource *resource)
271 ds_inf("text_input_handle_show_input_panel");
275 text_input_handle_hide_input_panel(struct wl_client *client,
276 struct wl_resource *resource)
278 ds_inf("text_input_handle_hide_input_panel");
282 text_input_handle_reset(struct wl_client *client, struct wl_resource *resource)
284 struct ds_tizen_text_input *text_input = wl_resource_get_user_data(resource);
286 ds_inf("text_input_handle_reset");
287 wl_signal_emit(&text_input->events.reset, text_input);
291 text_input_handle_set_content_type(struct wl_client *client,
292 struct wl_resource *resource, uint32_t hint, uint32_t purpose)
294 struct ds_tizen_text_input *text_input = wl_resource_get_user_data(resource);
295 struct ds_tizen_text_input_event_set_content_type ds_event;
297 ds_inf("text_input_handle_set_content_type");
298 ds_event.hint = hint;
299 ds_event.purpose = purpose;
300 ds_event.text_input = text_input;
302 wl_signal_emit(&text_input->events.set_content_type, &ds_event);
306 text_input_handle_set_cursor_rectangle(struct wl_client *client,
307 struct wl_resource *resource, int32_t x, int32_t y,
308 int32_t width, int32_t height)
310 ds_inf("text_input_handle_set_cursor_rectangle");
314 text_input_handle_set_preferred_language(struct wl_client *client,
315 struct wl_resource *resource, const char *language)
317 struct ds_tizen_text_input *text_input = wl_resource_get_user_data(resource);
318 struct ds_tizen_text_input_event_set_preferred_language ds_event;
320 ds_inf("text_input_handle_set_preferred_language");
321 ds_event.language = language;
322 ds_event.text_input = text_input;
324 wl_signal_emit(&text_input->events.set_preferred_language, &ds_event);
328 text_input_handle_commit_state(struct wl_client *client,
329 struct wl_resource *resource, uint32_t serial)
331 struct ds_tizen_text_input *text_input = wl_resource_get_user_data(resource);
332 struct ds_tizen_text_input_event_commit_state ds_event;
334 ds_inf("text_input_handle_invoke_action");
335 ds_event.serial = serial;
336 ds_event.text_input = text_input;
338 wl_signal_emit(&text_input->events.commit_state, &ds_event);
342 text_input_handle_invoke_action(struct wl_client *client,
343 struct wl_resource *resource, uint32_t button, uint32_t index)
345 struct ds_tizen_text_input *text_input = wl_resource_get_user_data(resource);
346 struct ds_tizen_text_input_event_invoke_action ds_event;
348 ds_inf("text_input_handle_invoke_action");
350 ds_event.button = button;
351 ds_event.index = index;
352 ds_event.text_input = text_input;
354 wl_signal_emit(&text_input->events.invoke_action, &ds_event);
357 static const struct wl_text_input_interface text_input_impl = {
358 .destroy = text_input_handle_destroy,
359 .activate = text_input_handle_activate,
360 .deactivate = text_input_handle_deactivate,
361 .show_input_panel = text_input_handle_show_input_panel,
362 .hide_input_panel = text_input_handle_hide_input_panel,
363 .reset = text_input_handle_reset,
364 .set_content_type = text_input_handle_set_content_type,
365 .set_cursor_rectangle = text_input_handle_set_cursor_rectangle,
366 .set_preferred_language = text_input_handle_set_preferred_language,
367 .commit_state = text_input_handle_commit_state,
368 .invoke_action = text_input_handle_invoke_action,
370 .set_return_key_type = NULL,
371 .set_return_key_disabled = NULL,
372 .set_input_panel_data = NULL,
373 .bidi_direction = NULL,
374 .set_cursor_position = NULL,
375 .process_input_device_event = NULL,
376 .filter_key_event = NULL,
377 .get_hide_permission = NULL,
378 .set_capital_mode = NULL,
379 .prediction_hint = NULL,
380 .set_mime_type = NULL,
381 .set_input_panel_position = NULL,
382 .finalize_content = NULL,
383 .prediction_hint_data = NULL,
384 .input_panel_enabled = NULL,
388 text_input_destroy(struct ds_tizen_text_input *text_input)
390 wl_signal_emit(&text_input->events.destroy, text_input);
391 wl_list_remove(&text_input->link);
397 text_input_mgr_handle_display_destroy(struct wl_listener *listener, void *data)
399 struct ds_tizen_text_input_manager *text_input_mgr;
400 struct ds_tizen_text_input *text_input, *tmp;
402 text_input_mgr = wl_container_of(listener, text_input_mgr, destroy);
404 ds_inf("Global destroy: text_input_mgr(%p)", text_input_mgr);
406 wl_signal_emit(&text_input_mgr->events.destroy, text_input_mgr);
407 wl_list_remove(&text_input_mgr->destroy.link);
409 wl_list_for_each_safe(text_input, tmp, &text_input_mgr->text_inputs, link) {
410 text_input_destroy(text_input);
413 wl_global_destroy(text_input_mgr->global);
414 free(text_input_mgr);
418 text_input_client_handle_destroy(struct wl_resource *resource)
420 struct ds_tizen_text_input *text_input;
422 ds_inf("text_input_client_handle_destroy");
424 text_input = wl_resource_get_user_data(resource);
425 text_input_destroy(text_input);
429 text_input_manager_handle_create_text_input(struct wl_client *wl_client,
430 struct wl_resource *resource, uint32_t id)
432 struct ds_tizen_text_input *text_input;
433 struct ds_tizen_text_input_manager *text_input_mgr;
435 ds_inf("text_input_manager_handle_create_text_input");
437 text_input_mgr = wl_resource_get_user_data(resource);
439 text_input = calloc(1, sizeof *text_input);
440 if (text_input == NULL) {
441 ds_err("calloc() failed. ds_tizen_text_input");
445 text_input->resource = wl_resource_create(wl_client,
446 &wl_text_input_interface,
447 TEXT_INPUT_VERSION, id);
448 if (text_input->resource == NULL) {
449 ds_err("text_input. wl_resource_create() failed.");
450 wl_client_post_no_memory(wl_client);
453 wl_resource_set_implementation(text_input->resource, &text_input_impl,
454 text_input, text_input_client_handle_destroy);
456 wl_signal_init(&text_input->events.activate);
457 wl_signal_init(&text_input->events.deactivate);
458 wl_signal_init(&text_input->events.reset);
459 wl_signal_init(&text_input->events.set_content_type);
460 wl_signal_init(&text_input->events.invoke_action);
461 wl_signal_init(&text_input->events.commit_state);
462 wl_signal_init(&text_input->events.set_preferred_language);
463 wl_signal_init(&text_input->events.destroy);
465 wl_list_insert(&text_input_mgr->text_inputs, &text_input->link);
466 wl_signal_emit(&text_input_mgr->events.new_text_input, text_input);
469 static const struct wl_text_input_manager_interface text_input_mgr_impl =
471 .create_text_input = text_input_manager_handle_create_text_input,
475 text_input_mgr_bind(struct wl_client *wl_client, void *data,
476 uint32_t version, uint32_t id)
478 struct ds_tizen_text_input_manager *text_input_mgr = data;
479 struct wl_resource *resource;
481 ds_inf("text_input_mgr. client binds. (client:%p)", wl_client);
483 resource = wl_resource_create(wl_client,
484 &wl_text_input_manager_interface,
486 if (resource == NULL) {
487 ds_err("text_input_mgr. wl_resource_create() failed.");
488 wl_client_post_no_memory(wl_client);
491 wl_resource_set_implementation(resource, &text_input_mgr_impl,
492 text_input_mgr, NULL);
495 WL_EXPORT struct ds_tizen_text_input_manager *
496 ds_tizen_text_input_manager_create(struct wl_display *display)
498 struct ds_tizen_text_input_manager *text_input_mgr;
500 text_input_mgr = calloc(1, sizeof *text_input_mgr);
501 if (text_input_mgr == NULL) {
502 ds_err("calloc() failed. ds_tizen_text_input_manager");
506 text_input_mgr->global = wl_global_create(display,
507 &wl_text_input_manager_interface, TEXT_INPUT_VERSION, text_input_mgr,
508 text_input_mgr_bind);
509 if (!text_input_mgr->global) {
510 free(text_input_mgr);
514 wl_list_init(&text_input_mgr->text_inputs);
516 wl_signal_init(&text_input_mgr->events.new_text_input);
517 wl_signal_init(&text_input_mgr->events.destroy);
520 text_input_mgr->destroy.notify = text_input_mgr_handle_display_destroy;
521 wl_display_add_destroy_listener(display, &text_input_mgr->destroy);
523 ds_inf("Global create: wl_text_input_manager. text_input_mgr(%p)", text_input_mgr);
525 return text_input_mgr;