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);
358 text_input_handle_set_return_key_type(struct wl_client *client,
359 struct wl_resource *resource, uint32_t return_key_type)
362 ds_inf("Not Implemented. text_input_handle_set_return_key_type");
366 text_input_handle_set_return_key_disabled(struct wl_client *client,
367 struct wl_resource *resource, uint32_t return_key_disabled)
370 ds_inf("Not Implemented. text_input_handle_set_return_key_disabled");
374 text_input_handle_set_input_panel_data(struct wl_client *client,
375 struct wl_resource *resource, const char *input_panel_data,
376 uint32_t input_panel_length)
379 ds_inf("Not Implemented. text_input_handle_set_input_panel_data");
383 text_input_handle_bidi_direction(struct wl_client *client,
384 struct wl_resource *resource, uint32_t direction)
387 ds_inf("Not Implemented. text_input_handle_bidi_direction");
391 text_input_handle_set_cursor_position(struct wl_client *client,
392 struct wl_resource *resource, uint32_t cursor_position)
395 ds_inf("Not Implemented. text_input_handle_set_cursor_position");
399 text_input_handle_process_input_device_event(struct wl_client *client,
400 struct wl_resource *resource, uint32_t event_type, const char *event_data,
401 uint32_t event_length)
404 ds_inf("Not Implemented. text_input_handle_process_input_device_event");
408 text_input_handle_filter_key_event(struct wl_client *client,
409 struct wl_resource *resource, uint32_t serial, uint32_t time,
410 const char *keyname, uint32_t modifiers, const char *dev_name,
411 uint32_t dev_class, uint32_t dev_subclass, uint32_t keycode)
414 ds_inf("Not Implemented. text_input_handle_filter_key_event");
418 text_input_handle_get_hide_permission(struct wl_client *client,
419 struct wl_resource *resource)
422 ds_inf("Not Implemented. text_input_handle_get_hide_permission");
426 text_input_handle_set_capital_mode(struct wl_client *client,
427 struct wl_resource *resource, uint32_t mode)
430 ds_inf("Not Implemented. text_input_handle_set_capital_mode");
434 text_input_handle_prediction_hint(struct wl_client *client,
435 struct wl_resource *resource, const char *text)
438 ds_inf("Not Implemented. text_input_handle_prediction_hint");
442 text_input_handle_set_mime_type(struct wl_client *client,
443 struct wl_resource *resource, const char *type)
446 ds_inf("Not Implemented. text_input_handle_set_mime_type");
450 text_input_handle_set_input_panel_position(struct wl_client *client,
451 struct wl_resource *resource, uint32_t x, uint32_t y)
454 ds_inf("Not Implemented. text_input_handle_set_input_panel_position");
458 text_input_handle_finalize_content(struct wl_client *client,
459 struct wl_resource *resource, const char *text, uint32_t cursor_position)
462 ds_inf("Not Implemented. text_input_handle_finalize_content");
466 text_input_handle_prediction_hint_data(struct wl_client *client,
467 struct wl_resource *resource, const char *key, const char *value)
470 ds_inf("Not Implemented. text_input_handle_prediction_hint_data");
474 text_input_handle_input_panel_enabled(struct wl_client *client,
475 struct wl_resource *resource, uint32_t enabled)
478 ds_inf("Not Implemented. text_input_handle_input_panel_enabled");
481 static const struct wl_text_input_interface text_input_impl = {
482 .destroy = text_input_handle_destroy,
483 .activate = text_input_handle_activate,
484 .deactivate = text_input_handle_deactivate,
485 .show_input_panel = text_input_handle_show_input_panel,
486 .hide_input_panel = text_input_handle_hide_input_panel,
487 .reset = text_input_handle_reset,
488 .set_content_type = text_input_handle_set_content_type,
489 .set_cursor_rectangle = text_input_handle_set_cursor_rectangle,
490 .set_preferred_language = text_input_handle_set_preferred_language,
491 .commit_state = text_input_handle_commit_state,
492 .invoke_action = text_input_handle_invoke_action,
494 .set_return_key_type = text_input_handle_set_return_key_type,
495 .set_return_key_disabled = text_input_handle_set_return_key_disabled,
496 .set_input_panel_data = text_input_handle_set_input_panel_data,
497 .bidi_direction = text_input_handle_bidi_direction,
498 .set_cursor_position = text_input_handle_set_cursor_position,
499 .process_input_device_event = text_input_handle_process_input_device_event,
500 .filter_key_event = text_input_handle_filter_key_event,
501 .get_hide_permission = text_input_handle_get_hide_permission,
502 .set_capital_mode = text_input_handle_set_capital_mode,
503 .prediction_hint = text_input_handle_prediction_hint,
504 .set_mime_type = text_input_handle_set_mime_type,
505 .set_input_panel_position = text_input_handle_set_input_panel_position,
506 .finalize_content = text_input_handle_finalize_content,
507 .prediction_hint_data = text_input_handle_prediction_hint_data,
508 .input_panel_enabled = text_input_handle_input_panel_enabled,
512 text_input_destroy(struct ds_tizen_text_input *text_input)
514 wl_signal_emit(&text_input->events.destroy, text_input);
515 wl_list_remove(&text_input->link);
521 text_input_mgr_handle_display_destroy(struct wl_listener *listener, void *data)
523 struct ds_tizen_text_input_manager *text_input_mgr;
524 struct ds_tizen_text_input *text_input, *tmp;
526 text_input_mgr = wl_container_of(listener, text_input_mgr, destroy);
528 ds_inf("Global destroy: text_input_mgr(%p)", text_input_mgr);
530 wl_signal_emit(&text_input_mgr->events.destroy, text_input_mgr);
531 wl_list_remove(&text_input_mgr->destroy.link);
533 wl_list_for_each_safe(text_input, tmp, &text_input_mgr->text_inputs, link) {
534 text_input_destroy(text_input);
537 wl_global_destroy(text_input_mgr->global);
538 free(text_input_mgr);
542 text_input_client_handle_destroy(struct wl_resource *resource)
544 struct ds_tizen_text_input *text_input;
546 ds_inf("text_input_client_handle_destroy");
548 text_input = wl_resource_get_user_data(resource);
549 text_input_destroy(text_input);
553 text_input_manager_handle_create_text_input(struct wl_client *wl_client,
554 struct wl_resource *resource, uint32_t id)
556 struct ds_tizen_text_input *text_input;
557 struct ds_tizen_text_input_manager *text_input_mgr;
559 ds_inf("text_input_manager_handle_create_text_input");
561 text_input_mgr = wl_resource_get_user_data(resource);
563 text_input = calloc(1, sizeof *text_input);
564 if (text_input == NULL) {
565 ds_err("calloc() failed. ds_tizen_text_input");
569 text_input->resource = wl_resource_create(wl_client,
570 &wl_text_input_interface,
571 TEXT_INPUT_VERSION, id);
572 if (text_input->resource == NULL) {
573 ds_err("text_input. wl_resource_create() failed.");
574 wl_client_post_no_memory(wl_client);
578 wl_resource_set_implementation(text_input->resource, &text_input_impl,
579 text_input, text_input_client_handle_destroy);
581 wl_signal_init(&text_input->events.activate);
582 wl_signal_init(&text_input->events.deactivate);
583 wl_signal_init(&text_input->events.reset);
584 wl_signal_init(&text_input->events.set_content_type);
585 wl_signal_init(&text_input->events.invoke_action);
586 wl_signal_init(&text_input->events.commit_state);
587 wl_signal_init(&text_input->events.set_preferred_language);
588 wl_signal_init(&text_input->events.destroy);
590 wl_list_insert(&text_input_mgr->text_inputs, &text_input->link);
591 wl_signal_emit(&text_input_mgr->events.new_text_input, text_input);
594 static const struct wl_text_input_manager_interface text_input_mgr_impl =
596 .create_text_input = text_input_manager_handle_create_text_input,
600 text_input_mgr_bind(struct wl_client *wl_client, void *data,
601 uint32_t version, uint32_t id)
603 struct ds_tizen_text_input_manager *text_input_mgr = data;
604 struct wl_resource *resource;
606 ds_inf("text_input_mgr. client binds. (client:%p)", wl_client);
608 resource = wl_resource_create(wl_client,
609 &wl_text_input_manager_interface,
611 if (resource == NULL) {
612 ds_err("text_input_mgr. wl_resource_create() failed.");
613 wl_client_post_no_memory(wl_client);
616 wl_resource_set_implementation(resource, &text_input_mgr_impl,
617 text_input_mgr, NULL);
620 WL_EXPORT struct ds_tizen_text_input_manager *
621 ds_tizen_text_input_manager_create(struct wl_display *display)
623 struct ds_tizen_text_input_manager *text_input_mgr;
625 text_input_mgr = calloc(1, sizeof *text_input_mgr);
626 if (text_input_mgr == NULL) {
627 ds_err("calloc() failed. ds_tizen_text_input_manager");
631 text_input_mgr->global = wl_global_create(display,
632 &wl_text_input_manager_interface, TEXT_INPUT_VERSION, text_input_mgr,
633 text_input_mgr_bind);
634 if (!text_input_mgr->global) {
635 free(text_input_mgr);
639 wl_list_init(&text_input_mgr->text_inputs);
641 wl_signal_init(&text_input_mgr->events.new_text_input);
642 wl_signal_init(&text_input_mgr->events.destroy);
645 text_input_mgr->destroy.notify = text_input_mgr_handle_display_destroy;
646 wl_display_add_destroy_listener(display, &text_input_mgr->destroy);
648 ds_inf("Global create: wl_text_input_manager. text_input_mgr(%p)", text_input_mgr);
650 return text_input_mgr;