ime: free allocated variables before return statement
[platform/core/uifw/libds-tizen.git] / src / input_method / input_method.c
1 #include <stdlib.h>
2 #include <wayland-server.h>
3 #include <input-method-server-protocol.h>
4 #include <libds/log.h>
5
6 #include "util.h"
7 #include <libds/seat.h>
8 #include <libds-tizen/input_method.h>
9
10 #define INPUT_METHOD_VERSION 1
11
12 struct ds_tizen_input_method;
13
14 struct ds_tizen_input_method_context {
15     struct wl_resource *resource;
16     struct ds_tizen_input_method *input_method;
17
18     struct {
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;
29         struct wl_signal key;
30         struct wl_signal modifiers;
31         struct wl_signal language;
32         struct wl_signal text_direction;
33     } events;
34 };
35
36 struct ds_tizen_input_method {
37     struct wl_global *global;
38     struct wl_resource *resource;
39     struct ds_tizen_input_method_context *context;
40
41     struct wl_listener destroy;
42
43     struct {
44         struct wl_signal destroy;
45     } events;
46 };
47
48 struct ds_tizen_input_method_manager {
49     struct wl_global *global;
50     struct wl_resource *resource;
51
52     struct wl_listener destroy;
53
54     struct {
55         struct wl_signal destroy;
56         struct wl_signal set_transient_for;
57     } events;
58 };
59
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;
62
63 WL_EXPORT void
64 ds_tizen_input_method_manager_add_destroy_listener(
65     struct ds_tizen_input_method_manager *im_mgr, struct wl_listener *listener)
66 {
67     wl_signal_add(&im_mgr->events.destroy, listener);
68 }
69
70 WL_EXPORT void
71 ds_tizen_input_method_manager_add_set_transient_for_listener(
72     struct ds_tizen_input_method_manager *im_mgr, struct wl_listener *listener)
73 {
74     wl_signal_add(&im_mgr->events.set_transient_for, listener);
75 }
76
77 static void
78 input_method_mgr_handle_display_destroy(struct wl_listener *listener, void *data)
79 {
80     struct ds_tizen_input_method_manager *input_method_mgr;
81
82     input_method_mgr = wl_container_of(listener, input_method_mgr, destroy);
83
84     ds_inf("Global destroy: input_method_mgr(%p)", input_method_mgr);
85
86     wl_signal_emit(&input_method_mgr->events.destroy, input_method_mgr);
87     wl_list_remove(&input_method_mgr->destroy.link);
88
89     wl_global_destroy(input_method_mgr->global);
90     free(input_method_mgr);
91 }
92
93 static void
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)
96 {
97     struct ds_tizen_input_method_manager_event_set_transient_for ds_event;
98     struct ds_tizen_input_method_manager *input_method_mgr;
99
100     input_method_mgr = wl_resource_get_user_data(resource);
101
102     ds_inf("input_method_mgr_handle_set_transient_for() parent:%u, child:%u",
103         parent_pid, child_pid);
104
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);
109 }
110
111 static const struct zwp_input_method_manager_v1_interface input_method_mgr_impl =
112 {
113     .set_transient_for = input_method_mgr_handle_set_transient_for,
114 };
115
116 static void
117 input_method_mgr_bind(struct wl_client *wl_client, void *data,
118     uint32_t version, uint32_t id)
119 {
120     struct ds_tizen_input_method_manager *input_method_mgr = data;
121
122     ds_inf("input_method_mgr. client binds. (client:%p)", wl_client);
123
124     input_method_mgr->resource = wl_resource_create(wl_client,
125             &zwp_input_method_manager_v1_interface,
126             version, id);
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);
130         return;
131     }
132     wl_resource_set_implementation(input_method_mgr->resource, &input_method_mgr_impl,
133         input_method_mgr, NULL);
134 }
135
136 WL_EXPORT struct ds_tizen_input_method_manager *
137 ds_tizen_input_method_manager_create(struct wl_display *display)
138 {
139     struct ds_tizen_input_method_manager *input_method_mgr;
140
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");
144         return NULL;
145     }
146
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);
151         return NULL;
152     }
153
154     wl_signal_init(&input_method_mgr->events.destroy);
155     wl_signal_init(&input_method_mgr->events.set_transient_for);
156
157     input_method_mgr->destroy.notify = input_method_mgr_handle_display_destroy;
158     wl_display_add_destroy_listener(display, &input_method_mgr->destroy);
159
160     ds_inf("Global create: zwp_input_method_manager_v1. input_method_mgr(%p)", input_method_mgr);
161
162     return input_method_mgr;
163 }
164
165 WL_EXPORT void
166 ds_tizen_input_method_add_destroy_listener(
167     struct ds_tizen_input_method *im, struct wl_listener *listener)
168 {
169     wl_signal_add(&im->events.destroy, listener);
170 }
171
172 WL_EXPORT void
173 ds_tizen_input_method_send_activate(struct ds_tizen_input_method *im,
174     struct ds_tizen_input_method_context *context)
175 {
176     if (!im || !context) return;
177
178     ds_inf("ds_tizen_input_method_send_activate");
179     zwp_input_method_v1_send_activate(im->resource, context->resource);
180 }
181
182 WL_EXPORT void
183 ds_tizen_input_method_send_deactivate(struct ds_tizen_input_method *im,
184     struct ds_tizen_input_method_context *context)
185 {
186     if (!im || !context) return;
187
188     ds_inf("ds_tizen_input_method_send_deactivate");
189     zwp_input_method_v1_send_deactivate(im->resource, context->resource);
190 }
191
192 static void
193 context_destroy(struct ds_tizen_input_method_context *context)
194 {
195     ds_inf("input_method_context(%p) destroy", context);
196
197     wl_signal_emit(&context->events.destroy, context);
198
199     free(context);
200 }
201
202 static void
203 input_method_context_client_handle_destroy(struct wl_resource *resource)
204 {
205     struct ds_tizen_input_method_context *context = wl_resource_get_user_data(resource);
206     struct ds_tizen_input_method *input_method;
207
208     ds_inf("input_method_context_client_handle_destroy");
209
210     input_method = context->input_method;
211     input_method->context = NULL;
212
213     context_destroy(context);
214 }
215
216 WL_EXPORT struct ds_tizen_input_method_context *
217 ds_tizen_input_method_create_context(struct ds_tizen_input_method *input_method)
218 {
219     struct ds_tizen_input_method_context *context;
220     struct wl_resource *binding;
221
222     ds_inf("ds_tizen_input_method_create_context");
223     context = calloc(1, sizeof *context);
224     if (context == NULL) {
225         ds_err("calloc() failed. ds_tizen_input_method_context");
226         return NULL;
227     }
228
229     binding = input_method->resource;
230     if (!binding) return NULL;
231     context->resource = wl_resource_create(wl_resource_get_client(binding),
232             &zwp_input_method_context_v1_interface, INPUT_METHOD_VERSION, 0);
233     if (context->resource == NULL) {
234         ds_err("context. wl_resource_create() failed.");
235         free(context);
236         return NULL;
237     }
238     wl_resource_set_implementation(context->resource, &context_impl,
239         context, input_method_context_client_handle_destroy);
240
241     wl_signal_init(&context->events.destroy);
242     wl_signal_init(&context->events.commit_string);
243     wl_signal_init(&context->events.preedit_string);
244     wl_signal_init(&context->events.preedit_styling);
245     wl_signal_init(&context->events.preedit_cursor);
246     wl_signal_init(&context->events.delete_surrounding_text);
247     wl_signal_init(&context->events.cursor_position);
248     wl_signal_init(&context->events.modifiers_map);
249     wl_signal_init(&context->events.keysym);
250     wl_signal_init(&context->events.grab_keyboard);
251     wl_signal_init(&context->events.key);
252     wl_signal_init(&context->events.modifiers);
253     wl_signal_init(&context->events.language);
254     wl_signal_init(&context->events.text_direction);
255
256     ds_tizen_input_method_send_activate(input_method, context);
257
258     input_method->context = context;
259     context->input_method = input_method;
260
261     return context;
262 }
263
264 WL_EXPORT void
265 ds_tizen_input_method_context_add_destroy_listener(
266     struct ds_tizen_input_method_context *context, struct wl_listener *listener)
267 {
268     wl_signal_add(&context->events.destroy, listener);
269 }
270
271 WL_EXPORT void
272 ds_tizen_input_method_context_add_commit_string_listener(
273     struct ds_tizen_input_method_context *context, struct wl_listener *listener)
274 {
275     wl_signal_add(&context->events.commit_string, listener);
276 }
277
278 WL_EXPORT void
279 ds_tizen_input_method_context_add_preedit_string_listener(
280     struct ds_tizen_input_method_context *context, struct wl_listener *listener)
281 {
282     wl_signal_add(&context->events.preedit_string, listener);
283 }
284
285 WL_EXPORT void
286 ds_tizen_input_method_context_add_preedit_styling_listener(
287     struct ds_tizen_input_method_context *context, struct wl_listener *listener)
288 {
289     wl_signal_add(&context->events.preedit_styling, listener);
290 }
291
292 WL_EXPORT void
293 ds_tizen_input_method_context_add_preedit_cursor_listener(
294     struct ds_tizen_input_method_context *context, struct wl_listener *listener)
295 {
296     wl_signal_add(&context->events.preedit_cursor, listener);
297 }
298
299 WL_EXPORT void
300 ds_tizen_input_method_context_add_delete_surrounding_text_listener(
301     struct ds_tizen_input_method_context *context, struct wl_listener *listener)
302 {
303     wl_signal_add(&context->events.delete_surrounding_text, listener);
304 }
305
306 WL_EXPORT void
307 ds_tizen_input_method_context_add_cursor_position_listener(
308     struct ds_tizen_input_method_context *context, struct wl_listener *listener)
309 {
310     wl_signal_add(&context->events.cursor_position, listener);
311 }
312
313 WL_EXPORT void
314 ds_tizen_input_method_context_add_modifiers_map_listener(
315     struct ds_tizen_input_method_context *context, struct wl_listener *listener)
316 {
317     wl_signal_add(&context->events.modifiers_map, listener);
318 }
319
320 WL_EXPORT void
321 ds_tizen_input_method_context_add_keysym_listener(
322     struct ds_tizen_input_method_context *context, struct wl_listener *listener)
323 {
324     wl_signal_add(&context->events.keysym, listener);
325 }
326
327 WL_EXPORT void
328 ds_tizen_input_method_context_add_grab_keyboard_listener(
329     struct ds_tizen_input_method_context *context, struct wl_listener *listener)
330 {
331     wl_signal_add(&context->events.grab_keyboard, listener);
332 }
333
334 WL_EXPORT void
335 ds_tizen_input_method_context_add_key_listener(
336     struct ds_tizen_input_method_context *context, struct wl_listener *listener)
337 {
338     wl_signal_add(&context->events.key, listener);
339 }
340
341 WL_EXPORT void
342 ds_tizen_input_method_context_add_modifiers_listener(
343     struct ds_tizen_input_method_context *context, struct wl_listener *listener)
344 {
345     wl_signal_add(&context->events.modifiers, listener);
346 }
347
348 WL_EXPORT void
349 ds_tizen_input_method_context_add_language_listener(
350     struct ds_tizen_input_method_context *context, struct wl_listener *listener)
351 {
352     wl_signal_add(&context->events.language, listener);
353 }
354
355 WL_EXPORT void
356 ds_tizen_input_method_context_add_text_direction_listener(
357     struct ds_tizen_input_method_context *context, struct wl_listener *listener)
358 {
359     wl_signal_add(&context->events.text_direction, listener);
360 }
361
362 WL_EXPORT void
363 ds_tizen_input_method_context_send_surrounding_text(struct ds_tizen_input_method_context *context,
364     const char *text, uint32_t cursor, uint32_t anchor)
365 {
366     if (!context || !context->resource) return;
367
368     ds_inf("ds_tizen_input_method_context_send_surrounding_text");
369     zwp_input_method_context_v1_send_surrounding_text(context->resource, text, cursor, anchor);
370 }
371
372 WL_EXPORT void
373 ds_tizen_input_method_context_send_reset(
374     struct ds_tizen_input_method_context *context)
375 {
376     if (!context || !context->resource) return;
377
378     ds_inf("ds_tizen_input_method_context_send_reset");
379     zwp_input_method_context_v1_send_reset(context->resource);
380 }
381
382 WL_EXPORT void
383 ds_tizen_input_method_context_send_content_type(
384     struct ds_tizen_input_method_context *context, uint32_t hint, uint32_t purpose)
385 {
386     if (!context || !context->resource) return;
387
388     ds_inf("ds_tizen_input_method_context_send_content_type");
389     zwp_input_method_context_v1_send_content_type(context->resource, hint, purpose);
390 }
391
392 WL_EXPORT void
393 ds_tizen_input_method_context_send_invoke_action(
394     struct ds_tizen_input_method_context *context, uint32_t button, uint32_t index)
395 {
396     if (!context || !context->resource) return;
397
398     ds_inf("ds_tizen_input_method_context_send_invoke_action");
399     zwp_input_method_context_v1_send_invoke_action(context->resource, button, index);
400 }
401
402 WL_EXPORT void
403 ds_tizen_input_method_context_send_commit_state(
404     struct ds_tizen_input_method_context *context, uint32_t serial)
405 {
406     if (!context || !context->resource) return;
407
408     ds_inf("ds_tizen_input_method_context_send_commit_state");
409     zwp_input_method_context_v1_send_commit_state(context->resource, serial);
410 }
411
412 WL_EXPORT void
413 ds_tizen_input_method_context_send_preferred_language(
414     struct ds_tizen_input_method_context *context, const char *language)
415 {
416     if (!context || !context->resource) return;
417
418     ds_inf("ds_tizen_input_method_context_send_preferred_language");
419     zwp_input_method_context_v1_send_preferred_language(context->resource, language);
420 }
421
422 static void
423 context_handle_destroy(struct wl_client *client, struct wl_resource *resource)
424 {
425     ds_inf("context_handle_destroy");
426     wl_resource_destroy(resource);
427 }
428
429 static void
430 context_handle_commit_string(struct wl_client *client,
431     struct wl_resource *resource, uint32_t serial, const char *text)
432 {
433     struct ds_tizen_input_method_context *context = wl_resource_get_user_data(resource);
434     struct ds_tizen_input_method_context_event_commit_string ds_event;
435
436     ds_inf("context_handle_commit_string");
437     ds_event.im_context = context;
438     ds_event.serial = serial;
439     ds_event.text = text;
440
441     wl_signal_emit(&context->events.commit_string, &ds_event);
442 }
443
444 static void
445 context_handle_preedit_string(struct wl_client *client,
446     struct wl_resource *resource, uint32_t serial, const char *text,
447     const char *commit)
448 {
449     struct ds_tizen_input_method_context *context = wl_resource_get_user_data(resource);
450     struct ds_tizen_input_method_context_event_preedit_string ds_event;
451
452     ds_inf("context_handle_preedit_string() serial:%u, text:%s, commit:%s",
453         serial, text, commit);
454
455     ds_event.im_context = context;
456     ds_event.serial = serial;
457     ds_event.text = text;
458     ds_event.commit = commit;
459
460     wl_signal_emit(&context->events.preedit_string, &ds_event);
461 }
462
463 static void
464 context_handle_preedit_styling(struct wl_client *client,
465     struct wl_resource *resource, uint32_t index, uint32_t length,
466     uint32_t style)
467 {
468     struct ds_tizen_input_method_context *context = wl_resource_get_user_data(resource);
469     struct ds_tizen_input_method_context_event_preedit_styling ds_event;
470
471     ds_inf("context_handle_preedit_styling() index:%u, length:%u, style:%u",
472         index, length, style);
473
474     ds_event.im_context = context;
475     ds_event.index = index;
476     ds_event.length = length;
477     ds_event.style = style;
478
479     wl_signal_emit(&context->events.preedit_styling, &ds_event);
480 }
481
482 static void
483 context_handle_preedit_cursor(struct wl_client *client,
484     struct wl_resource *resource, int32_t index)
485 {
486     struct ds_tizen_input_method_context *context = wl_resource_get_user_data(resource);
487     struct ds_tizen_input_method_context_event_preedit_cursor ds_event;
488
489     ds_inf("context_handle_preedit_cursor() cursor:%d", index);
490
491     ds_event.im_context = context;
492     ds_event.index = index;
493     wl_signal_emit(&context->events.preedit_styling, &ds_event);
494 }
495
496 static void
497 context_handle_delete_surrounding_text(struct wl_client *client,
498     struct wl_resource *resource, int32_t index, uint32_t length)
499 {
500     struct ds_tizen_input_method_context *context = wl_resource_get_user_data(resource);
501     struct ds_tizen_input_method_context_event_delete_surrounding_text ds_event;
502
503     ds_inf("context_handle_delete_surrounding_text() index:%d, length:%u", index, length);
504
505     ds_event.im_context = context;
506     ds_event.index = index;
507     ds_event.length = length;
508     wl_signal_emit(&context->events.delete_surrounding_text, &ds_event);
509 }
510
511 static void
512 context_handle_cursor_position(struct wl_client *client,
513     struct wl_resource *resource, int32_t index, int32_t anchor)
514 {
515     struct ds_tizen_input_method_context *context = wl_resource_get_user_data(resource);
516     struct ds_tizen_input_method_context_event_cursor_position ds_event;
517
518     ds_inf("context_handle_cursor_position() index:%d anchor:%d", index, anchor);
519
520     ds_event.im_context = context;
521     ds_event.index = index;
522     ds_event.anchor = anchor;
523     wl_signal_emit(&context->events.cursor_position, &ds_event);
524 }
525
526 static void
527 context_handle_modifiers_map(struct wl_client *client,
528     struct wl_resource *resource, struct wl_array *map)
529 {
530     struct ds_tizen_input_method_context *context = wl_resource_get_user_data(resource);
531     struct ds_tizen_input_method_context_event_modifiers_map ds_event;
532
533     ds_inf("context_handle_modifiers_map() map(%p)", map);
534
535     ds_event.im_context = context;
536     ds_event.map = map;
537     wl_signal_emit(&context->events.modifiers_map, &ds_event);
538 }
539
540 static void
541 context_handle_keysym(struct wl_client *client, struct wl_resource *resource,
542     uint32_t serial, uint32_t time, uint32_t sym,
543     uint32_t state, uint32_t modifiers)
544 {
545     struct ds_tizen_input_method_context *context = wl_resource_get_user_data(resource);
546     struct ds_tizen_input_method_context_event_keysym ds_event;
547
548     ds_inf("context_handle_keysym() serial(%u), time(%u), sym(%u), state(%u), modifiers(%u)",
549         serial, time, sym, state, modifiers);
550
551     ds_event.im_context = context;
552     ds_event.serial = serial;
553     ds_event.time = time;
554     ds_event.sym = sym;
555     ds_event.state = state;
556     ds_event.modifiers = modifiers;
557     wl_signal_emit(&context->events.keysym, &ds_event);
558 }
559
560 static void
561 context_handle_grab_keyboard(struct wl_client *client,
562     struct wl_resource *resource, uint32_t id)
563 {
564     ds_inf("context_handle_grab_keyboard() nothing done");
565     //TODO
566 }
567
568 static void
569 context_handle_key(struct wl_client *client, struct wl_resource *resource,
570     uint32_t serial, uint32_t time, uint32_t key, uint32_t state_w)
571 {
572     ds_inf("context_handle_key() nothing done");
573     //TODO
574 }
575
576 static void
577 context_handle_modifiers(struct wl_client *client,
578     struct wl_resource *resource, uint32_t serial, uint32_t mods_depressed,
579     uint32_t mods_latched, uint32_t mods_locked, uint32_t group)
580 {
581     ds_inf("context_handle_modifiers() nothing done");
582     //TODO
583 }
584
585 static void
586 context_handle_language(struct wl_client *client,
587     struct wl_resource *resource, uint32_t serial, const char *language)
588 {
589     struct ds_tizen_input_method_context *context = wl_resource_get_user_data(resource);
590     struct ds_tizen_input_method_context_event_language ds_event;
591
592     ds_inf("context_handle_language() serial(%u) language(%s)", serial, language);
593
594     ds_event.im_context = context;
595     ds_event.serial = serial;
596     ds_event.language = language;
597     wl_signal_emit(&context->events.language, &ds_event);
598 }
599
600 static void
601 context_handle_text_direction(struct wl_client *client,
602     struct wl_resource *resource, uint32_t serial, uint32_t direction)
603 {
604     struct ds_tizen_input_method_context *context = wl_resource_get_user_data(resource);
605     struct ds_tizen_input_method_context_event_text_direction ds_event;
606
607     ds_inf("context_handle_text_direction() serial(%u) direction(%u)", serial, direction);
608
609     ds_event.im_context = context;
610     ds_event.serial = serial;
611     ds_event.direction = direction;
612     wl_signal_emit(&context->events.text_direction, &ds_event);
613 }
614
615 static const struct zwp_input_method_context_v1_interface context_impl = {
616     .destroy = context_handle_destroy,
617     .commit_string = context_handle_commit_string,
618     .preedit_string = context_handle_preedit_string,
619     .preedit_styling = context_handle_preedit_styling,
620     .preedit_cursor = context_handle_preedit_cursor,
621     .delete_surrounding_text = context_handle_delete_surrounding_text,
622     .cursor_position = context_handle_cursor_position,
623     .modifiers_map = context_handle_modifiers_map,
624     .keysym = context_handle_keysym,
625     .grab_keyboard = context_handle_grab_keyboard,
626     .key = context_handle_key,
627     .modifiers = context_handle_modifiers,
628     .language = context_handle_language,
629     .text_direction = context_handle_text_direction,
630     //for tizen_only
631     .selection_region = NULL,
632     .private_command = NULL,
633     .update_input_panel_data = NULL,
634     .hide_input_panel = NULL,
635     .get_selection_text = NULL,
636     .get_surrounding_text = NULL,
637     .filter_key_event_done = NULL,
638     .update_ise_geometry = NULL,
639     .recapture_string = NULL,
640     .input_panel_event = NULL,
641     .commit_content = NULL,
642     .update_candidate_state = NULL,
643     .reshow_input_panel = NULL,
644     .set_floating_panel = NULL,
645     .set_floating_drag_enabled = NULL,
646 };
647
648 static void
649 input_method_handle_display_destroy(struct wl_listener *listener, void *data)
650 {
651     struct ds_tizen_input_method *input_method;
652
653     input_method = wl_container_of(listener, input_method, destroy);
654
655     ds_inf("Global destroy: input_method(%p)", input_method);
656
657     if (input_method->context)
658         context_destroy(input_method->context);
659
660     wl_signal_emit(&input_method->events.destroy, input_method);
661     wl_list_remove(&input_method->destroy.link);
662
663     wl_global_destroy(input_method->global);
664     free(input_method);
665 }
666
667 static void
668 input_method_bind(struct wl_client *wl_client, void *data,
669     uint32_t version, uint32_t id)
670 {
671     struct ds_tizen_input_method *input_method = data;
672
673     ds_inf("input_method. client binds. (client:%p)", wl_client);
674
675     input_method->resource = wl_resource_create(wl_client,
676             &zwp_input_method_v1_interface,
677             version, id);
678     if (input_method->resource == NULL) {
679         ds_err("input_method. wl_resource_create() failed.");
680         wl_client_post_no_memory(wl_client);
681         return;
682     }
683     wl_resource_set_implementation(input_method->resource, NULL,
684         input_method, NULL);
685 }
686
687 WL_EXPORT struct ds_tizen_input_method *
688 ds_tizen_input_method_create(struct wl_display *display)
689 {
690     struct ds_tizen_input_method *input_method;
691
692     input_method = calloc(1, sizeof *input_method);
693     if (input_method == NULL) {
694         ds_err("calloc() failed. ds_tizen_input_method");
695         return NULL;
696     }
697
698     input_method->global = wl_global_create(display,
699         &zwp_input_method_v1_interface, INPUT_METHOD_VERSION, input_method, input_method_bind);
700     if (!input_method->global) {
701         free(input_method);
702         return NULL;
703     }
704
705     wl_signal_init(&input_method->events.destroy);
706
707     input_method->destroy.notify = input_method_handle_display_destroy;
708     wl_display_add_destroy_listener(display, &input_method->destroy);
709
710     ds_inf("Global create: zwp_input_method_v1. input_method(%p)", input_method);
711
712     return input_method;
713 }