2 #include <wayland-server.h>
3 #include <input-method-server-protocol.h>
7 #include <libds/seat.h>
8 #include <libds-tizen/input_method.h>
10 #define INPUT_METHOD_VERSION 1
12 struct ds_tizen_input_method;
14 struct ds_tizen_input_method_context {
15 struct wl_resource *resource;
16 struct ds_tizen_input_method *input_method;
19 struct wl_signal destroy;
20 struct wl_signal commit_string;
21 struct wl_signal preedit_string;
22 struct wl_signal preedit_styling;
23 struct wl_signal preedit_cursor;
24 struct wl_signal delete_surrounding_text;
25 struct wl_signal cursor_position;
26 struct wl_signal modifiers_map;
27 struct wl_signal keysym;
28 struct wl_signal grab_keyboard;
30 struct wl_signal modifiers;
31 struct wl_signal language;
32 struct wl_signal text_direction;
36 struct ds_tizen_input_method {
37 struct wl_global *global;
38 struct wl_resource *resource;
39 struct ds_tizen_input_method_context *context;
41 struct wl_listener destroy;
44 struct wl_signal destroy;
48 struct ds_tizen_input_method_manager {
49 struct wl_global *global;
50 struct wl_resource *resource;
52 struct wl_listener destroy;
55 struct wl_signal destroy;
56 struct wl_signal set_transient_for;
60 static const struct zwp_input_method_context_v1_interface context_impl;
61 static const struct zwp_input_method_manager_v1_interface input_method_mgr_impl;
64 ds_tizen_input_method_manager_add_destroy_listener(
65 struct ds_tizen_input_method_manager *im_mgr, struct wl_listener *listener)
67 wl_signal_add(&im_mgr->events.destroy, listener);
71 ds_tizen_input_method_manager_add_set_transient_for_listener(
72 struct ds_tizen_input_method_manager *im_mgr, struct wl_listener *listener)
74 wl_signal_add(&im_mgr->events.set_transient_for, listener);
78 input_method_mgr_handle_display_destroy(struct wl_listener *listener, void *data)
80 struct ds_tizen_input_method_manager *input_method_mgr;
82 input_method_mgr = wl_container_of(listener, input_method_mgr, destroy);
84 ds_inf("Global destroy: input_method_mgr(%p)", input_method_mgr);
86 wl_signal_emit(&input_method_mgr->events.destroy, input_method_mgr);
87 wl_list_remove(&input_method_mgr->destroy.link);
89 wl_global_destroy(input_method_mgr->global);
90 free(input_method_mgr);
94 input_method_mgr_handle_set_transient_for(struct wl_client *wl_client,
95 struct wl_resource *resource, uint32_t parent_pid, uint32_t child_pid)
97 struct ds_tizen_input_method_manager_event_set_transient_for ds_event;
98 struct ds_tizen_input_method_manager *input_method_mgr;
100 input_method_mgr = wl_resource_get_user_data(resource);
102 ds_inf("input_method_mgr_handle_set_transient_for() parent:%u, child:%u",
103 parent_pid, child_pid);
105 ds_event.im_mgr = input_method_mgr;
106 ds_event.pid_parent = parent_pid;
107 ds_event.pid_child = child_pid;
108 wl_signal_emit(&input_method_mgr->events.set_transient_for, &ds_event);
111 static const struct zwp_input_method_manager_v1_interface input_method_mgr_impl =
113 .set_transient_for = input_method_mgr_handle_set_transient_for,
117 input_method_mgr_bind(struct wl_client *wl_client, void *data,
118 uint32_t version, uint32_t id)
120 struct ds_tizen_input_method_manager *input_method_mgr = data;
122 ds_inf("input_method_mgr. client binds. (client:%p)", wl_client);
124 input_method_mgr->resource = wl_resource_create(wl_client,
125 &zwp_input_method_manager_v1_interface,
127 if (input_method_mgr->resource == NULL) {
128 ds_err("input_method_mgr. wl_resource_create() failed.");
129 wl_client_post_no_memory(wl_client);
132 wl_resource_set_implementation(input_method_mgr->resource, &input_method_mgr_impl,
133 input_method_mgr, NULL);
136 WL_EXPORT struct ds_tizen_input_method_manager *
137 ds_tizen_input_method_manager_create(struct wl_display *display)
139 struct ds_tizen_input_method_manager *input_method_mgr;
141 input_method_mgr = calloc(1, sizeof *input_method_mgr);
142 if (input_method_mgr == NULL) {
143 ds_err("calloc() failed. ds_tizen_input_method_manager");
147 input_method_mgr->global = wl_global_create(display,
148 &zwp_input_method_manager_v1_interface, INPUT_METHOD_VERSION, input_method_mgr, input_method_mgr_bind);
149 if (!input_method_mgr->global) {
150 free(input_method_mgr);
154 wl_signal_init(&input_method_mgr->events.destroy);
155 wl_signal_init(&input_method_mgr->events.set_transient_for);
157 input_method_mgr->destroy.notify = input_method_mgr_handle_display_destroy;
158 wl_display_add_destroy_listener(display, &input_method_mgr->destroy);
160 ds_inf("Global create: zwp_input_method_manager_v1. input_method_mgr(%p)", input_method_mgr);
162 return input_method_mgr;
166 ds_tizen_input_method_add_destroy_listener(
167 struct ds_tizen_input_method *im, struct wl_listener *listener)
169 wl_signal_add(&im->events.destroy, listener);
173 ds_tizen_input_method_send_activate(struct ds_tizen_input_method *im,
174 struct ds_tizen_input_method_context *context)
176 if (!im || !context) return;
178 ds_inf("ds_tizen_input_method_send_activate");
179 zwp_input_method_v1_send_activate(im->resource, context->resource);
183 ds_tizen_input_method_send_deactivate(struct ds_tizen_input_method *im,
184 struct ds_tizen_input_method_context *context)
186 if (!im || !context) return;
188 ds_inf("ds_tizen_input_method_send_deactivate");
189 zwp_input_method_v1_send_deactivate(im->resource, context->resource);
193 context_destroy(struct ds_tizen_input_method_context *context)
195 ds_inf("input_method_context(%p) destroy", context);
197 wl_signal_emit(&context->events.destroy, context);
203 input_method_context_client_handle_destroy(struct wl_resource *resource)
205 struct ds_tizen_input_method_context *context = wl_resource_get_user_data(resource);
206 struct ds_tizen_input_method *input_method;
208 ds_inf("input_method_context_client_handle_destroy");
210 input_method = context->input_method;
211 input_method->context = NULL;
213 context_destroy(context);
216 WL_EXPORT struct ds_tizen_input_method_context *
217 ds_tizen_input_method_create_context(struct ds_tizen_input_method *input_method)
219 struct ds_tizen_input_method_context *context;
220 struct wl_resource *binding;
222 ds_inf("ds_tizen_input_method_create_context");
223 context = calloc(1, sizeof *context);
227 binding = input_method->resource;
228 if (!binding) return NULL;
229 context->resource = wl_resource_create(wl_resource_get_client(binding),
230 &zwp_input_method_context_v1_interface, INPUT_METHOD_VERSION, 0);
231 if (context->resource == NULL) {
232 ds_err("context. wl_resource_create() failed.");
235 wl_resource_set_implementation(context->resource, &context_impl,
236 context, input_method_context_client_handle_destroy);
238 wl_signal_init(&context->events.destroy);
239 wl_signal_init(&context->events.commit_string);
240 wl_signal_init(&context->events.preedit_string);
241 wl_signal_init(&context->events.preedit_styling);
242 wl_signal_init(&context->events.preedit_cursor);
243 wl_signal_init(&context->events.delete_surrounding_text);
244 wl_signal_init(&context->events.cursor_position);
245 wl_signal_init(&context->events.modifiers_map);
246 wl_signal_init(&context->events.keysym);
247 wl_signal_init(&context->events.grab_keyboard);
248 wl_signal_init(&context->events.key);
249 wl_signal_init(&context->events.modifiers);
250 wl_signal_init(&context->events.language);
251 wl_signal_init(&context->events.text_direction);
253 ds_tizen_input_method_send_activate(input_method, context);
255 input_method->context = context;
256 context->input_method = input_method;
262 ds_tizen_input_method_context_add_destroy_listener(
263 struct ds_tizen_input_method_context *context, struct wl_listener *listener)
265 wl_signal_add(&context->events.destroy, listener);
269 ds_tizen_input_method_context_add_commit_string_listener(
270 struct ds_tizen_input_method_context *context, struct wl_listener *listener)
272 wl_signal_add(&context->events.commit_string, listener);
276 ds_tizen_input_method_context_add_preedit_string_listener(
277 struct ds_tizen_input_method_context *context, struct wl_listener *listener)
279 wl_signal_add(&context->events.preedit_string, listener);
283 ds_tizen_input_method_context_add_preedit_styling_listener(
284 struct ds_tizen_input_method_context *context, struct wl_listener *listener)
286 wl_signal_add(&context->events.preedit_styling, listener);
290 ds_tizen_input_method_context_add_preedit_cursor_listener(
291 struct ds_tizen_input_method_context *context, struct wl_listener *listener)
293 wl_signal_add(&context->events.preedit_cursor, listener);
297 ds_tizen_input_method_context_add_delete_surrounding_text_listener(
298 struct ds_tizen_input_method_context *context, struct wl_listener *listener)
300 wl_signal_add(&context->events.delete_surrounding_text, listener);
304 ds_tizen_input_method_context_add_cursor_position_listener(
305 struct ds_tizen_input_method_context *context, struct wl_listener *listener)
307 wl_signal_add(&context->events.cursor_position, listener);
311 ds_tizen_input_method_context_add_modifiers_map_listener(
312 struct ds_tizen_input_method_context *context, struct wl_listener *listener)
314 wl_signal_add(&context->events.modifiers_map, listener);
318 ds_tizen_input_method_context_add_keysym_listener(
319 struct ds_tizen_input_method_context *context, struct wl_listener *listener)
321 wl_signal_add(&context->events.keysym, listener);
325 ds_tizen_input_method_context_add_grab_keyboard_listener(
326 struct ds_tizen_input_method_context *context, struct wl_listener *listener)
328 wl_signal_add(&context->events.grab_keyboard, listener);
332 ds_tizen_input_method_context_add_key_listener(
333 struct ds_tizen_input_method_context *context, struct wl_listener *listener)
335 wl_signal_add(&context->events.key, listener);
339 ds_tizen_input_method_context_add_modifiers_listener(
340 struct ds_tizen_input_method_context *context, struct wl_listener *listener)
342 wl_signal_add(&context->events.modifiers, listener);
346 ds_tizen_input_method_context_add_language_listener(
347 struct ds_tizen_input_method_context *context, struct wl_listener *listener)
349 wl_signal_add(&context->events.language, listener);
353 ds_tizen_input_method_context_add_text_direction_listener(
354 struct ds_tizen_input_method_context *context, struct wl_listener *listener)
356 wl_signal_add(&context->events.text_direction, listener);
360 ds_tizen_input_method_context_send_surrounding_text(struct ds_tizen_input_method_context *context,
361 const char *text, uint32_t cursor, uint32_t anchor)
363 if (!context || !context->resource) return;
365 ds_inf("ds_tizen_input_method_context_send_surrounding_text");
366 zwp_input_method_context_v1_send_surrounding_text(context->resource, text, cursor, anchor);
370 ds_tizen_input_method_context_send_reset(
371 struct ds_tizen_input_method_context *context)
373 if (!context || !context->resource) return;
375 ds_inf("ds_tizen_input_method_context_send_reset");
376 zwp_input_method_context_v1_send_reset(context->resource);
380 ds_tizen_input_method_context_send_content_type(
381 struct ds_tizen_input_method_context *context, uint32_t hint, uint32_t purpose)
383 if (!context || !context->resource) return;
385 ds_inf("ds_tizen_input_method_context_send_content_type");
386 zwp_input_method_context_v1_send_content_type(context->resource, hint, purpose);
390 ds_tizen_input_method_context_send_invoke_action(
391 struct ds_tizen_input_method_context *context, uint32_t button, uint32_t index)
393 if (!context || !context->resource) return;
395 ds_inf("ds_tizen_input_method_context_send_invoke_action");
396 zwp_input_method_context_v1_send_invoke_action(context->resource, button, index);
400 ds_tizen_input_method_context_send_commit_state(
401 struct ds_tizen_input_method_context *context, uint32_t serial)
403 if (!context || !context->resource) return;
405 ds_inf("ds_tizen_input_method_context_send_commit_state");
406 zwp_input_method_context_v1_send_commit_state(context->resource, serial);
410 ds_tizen_input_method_context_send_preferred_language(
411 struct ds_tizen_input_method_context *context, const char *language)
413 if (!context || !context->resource) return;
415 ds_inf("ds_tizen_input_method_context_send_preferred_language");
416 zwp_input_method_context_v1_send_preferred_language(context->resource, language);
420 context_handle_destroy(struct wl_client *client, struct wl_resource *resource)
422 ds_inf("context_handle_destroy");
423 wl_resource_destroy(resource);
427 context_handle_commit_string(struct wl_client *client,
428 struct wl_resource *resource, uint32_t serial, const char *text)
430 struct ds_tizen_input_method_context *context = wl_resource_get_user_data(resource);
431 struct ds_tizen_input_method_context_event_commit_string ds_event;
433 ds_inf("context_handle_commit_string");
434 ds_event.im_context = context;
435 ds_event.serial = serial;
436 ds_event.text = text;
438 wl_signal_emit(&context->events.commit_string, &ds_event);
442 context_handle_preedit_string(struct wl_client *client,
443 struct wl_resource *resource, uint32_t serial, const char *text,
446 struct ds_tizen_input_method_context *context = wl_resource_get_user_data(resource);
447 struct ds_tizen_input_method_context_event_preedit_string ds_event;
449 ds_inf("context_handle_preedit_string() serial:%u, text:%s, commit:%s",
450 serial, text, commit);
452 ds_event.im_context = context;
453 ds_event.serial = serial;
454 ds_event.text = text;
455 ds_event.commit = commit;
457 wl_signal_emit(&context->events.preedit_string, &ds_event);
461 context_handle_preedit_styling(struct wl_client *client,
462 struct wl_resource *resource, uint32_t index, uint32_t length,
465 struct ds_tizen_input_method_context *context = wl_resource_get_user_data(resource);
466 struct ds_tizen_input_method_context_event_preedit_styling ds_event;
468 ds_inf("context_handle_preedit_styling() index:%u, length:%u, style:%u",
469 index, length, style);
471 ds_event.im_context = context;
472 ds_event.index = index;
473 ds_event.length = length;
474 ds_event.style = style;
476 wl_signal_emit(&context->events.preedit_styling, &ds_event);
480 context_handle_preedit_cursor(struct wl_client *client,
481 struct wl_resource *resource, int32_t index)
483 struct ds_tizen_input_method_context *context = wl_resource_get_user_data(resource);
484 struct ds_tizen_input_method_context_event_preedit_cursor ds_event;
486 ds_inf("context_handle_preedit_cursor() cursor:%d", index);
488 ds_event.im_context = context;
489 ds_event.index = index;
490 wl_signal_emit(&context->events.preedit_styling, &ds_event);
494 context_handle_delete_surrounding_text(struct wl_client *client,
495 struct wl_resource *resource, int32_t index, uint32_t length)
497 struct ds_tizen_input_method_context *context = wl_resource_get_user_data(resource);
498 struct ds_tizen_input_method_context_event_delete_surrounding_text ds_event;
500 ds_inf("context_handle_delete_surrounding_text() index:%d, length:%u", index, length);
502 ds_event.im_context = context;
503 ds_event.index = index;
504 ds_event.length = length;
505 wl_signal_emit(&context->events.delete_surrounding_text, &ds_event);
509 context_handle_cursor_position(struct wl_client *client,
510 struct wl_resource *resource, int32_t index, int32_t anchor)
512 struct ds_tizen_input_method_context *context = wl_resource_get_user_data(resource);
513 struct ds_tizen_input_method_context_event_cursor_position ds_event;
515 ds_inf("context_handle_cursor_position() index:%d anchor:%d", index, anchor);
517 ds_event.im_context = context;
518 ds_event.index = index;
519 ds_event.anchor = anchor;
520 wl_signal_emit(&context->events.cursor_position, &ds_event);
524 context_handle_modifiers_map(struct wl_client *client,
525 struct wl_resource *resource, struct wl_array *map)
527 struct ds_tizen_input_method_context *context = wl_resource_get_user_data(resource);
528 struct ds_tizen_input_method_context_event_modifiers_map ds_event;
530 ds_inf("context_handle_modifiers_map() map(%p)", map);
532 ds_event.im_context = context;
534 wl_signal_emit(&context->events.modifiers_map, &ds_event);
538 context_handle_keysym(struct wl_client *client, struct wl_resource *resource,
539 uint32_t serial, uint32_t time, uint32_t sym,
540 uint32_t state, uint32_t modifiers)
542 struct ds_tizen_input_method_context *context = wl_resource_get_user_data(resource);
543 struct ds_tizen_input_method_context_event_keysym ds_event;
545 ds_inf("context_handle_keysym() serial(%u), time(%u), sym(%u), state(%u), modifiers(%u)",
546 serial, time, sym, state, modifiers);
548 ds_event.im_context = context;
549 ds_event.serial = serial;
550 ds_event.time = time;
552 ds_event.state = state;
553 ds_event.modifiers = modifiers;
554 wl_signal_emit(&context->events.keysym, &ds_event);
558 context_handle_grab_keyboard(struct wl_client *client,
559 struct wl_resource *resource, uint32_t id)
561 ds_inf("context_handle_grab_keyboard() nothing done");
566 context_handle_key(struct wl_client *client, struct wl_resource *resource,
567 uint32_t serial, uint32_t time, uint32_t key, uint32_t state_w)
569 ds_inf("context_handle_key() nothing done");
574 context_handle_modifiers(struct wl_client *client,
575 struct wl_resource *resource, uint32_t serial, uint32_t mods_depressed,
576 uint32_t mods_latched, uint32_t mods_locked, uint32_t group)
578 ds_inf("context_handle_modifiers() nothing done");
583 context_handle_language(struct wl_client *client,
584 struct wl_resource *resource, uint32_t serial, const char *language)
586 struct ds_tizen_input_method_context *context = wl_resource_get_user_data(resource);
587 struct ds_tizen_input_method_context_event_language ds_event;
589 ds_inf("context_handle_language() serial(%u) language(%s)", serial, language);
591 ds_event.im_context = context;
592 ds_event.serial = serial;
593 ds_event.language = language;
594 wl_signal_emit(&context->events.language, &ds_event);
598 context_handle_text_direction(struct wl_client *client,
599 struct wl_resource *resource, uint32_t serial, uint32_t direction)
601 struct ds_tizen_input_method_context *context = wl_resource_get_user_data(resource);
602 struct ds_tizen_input_method_context_event_text_direction ds_event;
604 ds_inf("context_handle_text_direction() serial(%u) direction(%u)", serial, direction);
606 ds_event.im_context = context;
607 ds_event.serial = serial;
608 ds_event.direction = direction;
609 wl_signal_emit(&context->events.text_direction, &ds_event);
612 static const struct zwp_input_method_context_v1_interface context_impl = {
613 .destroy = context_handle_destroy,
614 .commit_string = context_handle_commit_string,
615 .preedit_string = context_handle_preedit_string,
616 .preedit_styling = context_handle_preedit_styling,
617 .preedit_cursor = context_handle_preedit_cursor,
618 .delete_surrounding_text = context_handle_delete_surrounding_text,
619 .cursor_position = context_handle_cursor_position,
620 .modifiers_map = context_handle_modifiers_map,
621 .keysym = context_handle_keysym,
622 .grab_keyboard = context_handle_grab_keyboard,
623 .key = context_handle_key,
624 .modifiers = context_handle_modifiers,
625 .language = context_handle_language,
626 .text_direction = context_handle_text_direction,
628 .selection_region = NULL,
629 .private_command = NULL,
630 .update_input_panel_data = NULL,
631 .hide_input_panel = NULL,
632 .get_selection_text = NULL,
633 .get_surrounding_text = NULL,
634 .filter_key_event_done = NULL,
635 .update_ise_geometry = NULL,
636 .recapture_string = NULL,
637 .input_panel_event = NULL,
638 .commit_content = NULL,
639 .update_candidate_state = NULL,
640 .reshow_input_panel = NULL,
641 .set_floating_panel = NULL,
642 .set_floating_drag_enabled = NULL,
646 input_method_handle_display_destroy(struct wl_listener *listener, void *data)
648 struct ds_tizen_input_method *input_method;
650 input_method = wl_container_of(listener, input_method, destroy);
652 ds_inf("Global destroy: input_method(%p)", input_method);
654 if (input_method->context)
655 context_destroy(input_method->context);
657 wl_signal_emit(&input_method->events.destroy, input_method);
658 wl_list_remove(&input_method->destroy.link);
660 wl_global_destroy(input_method->global);
665 input_method_bind(struct wl_client *wl_client, void *data,
666 uint32_t version, uint32_t id)
668 struct ds_tizen_input_method *input_method = data;
670 ds_inf("input_method. client binds. (client:%p)", wl_client);
672 input_method->resource = wl_resource_create(wl_client,
673 &zwp_input_method_v1_interface,
675 if (input_method->resource == NULL) {
676 ds_err("input_method. wl_resource_create() failed.");
677 wl_client_post_no_memory(wl_client);
680 wl_resource_set_implementation(input_method->resource, NULL,
684 WL_EXPORT struct ds_tizen_input_method *
685 ds_tizen_input_method_create(struct wl_display *display)
687 struct ds_tizen_input_method *input_method;
689 input_method = calloc(1, sizeof *input_method);
690 if (input_method == NULL) {
691 ds_err("calloc() failed. ds_tizen_input_method");
695 input_method->global = wl_global_create(display,
696 &zwp_input_method_v1_interface, INPUT_METHOD_VERSION, input_method, input_method_bind);
697 if (!input_method->global) {
702 wl_signal_init(&input_method->events.destroy);
704 input_method->destroy.notify = input_method_handle_display_destroy;
705 wl_display_add_destroy_listener(display, &input_method->destroy);
707 ds_inf("Global create: zwp_input_method_v1. input_method(%p)", input_method);