-#include <assert.h>
-#include <stdbool.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <signal.h>
-#include <time.h>
-
-#include <drm_fourcc.h>
-#include <pixman.h>
-#include <wayland-server.h>
-#include <libds/log.h>
-#include <libds/backend.h>
-#include <libds/output.h>
-#include <libds/compositor.h>
-#include <libds/xdg_shell.h>
-#include <libds-tizen/allocator/tbm.h>
-#include <libds-tizen/backend/tdm.h>
-#include <libds/backend/libinput.h>
-#include <libds-tizen/tbm_server.h>
-#include <libds-tizen/dpms.h>
-#include <libds/input_device.h>
-#include <libds/keyboard.h>
-#include <libds/touch.h>
-#include <libds/pointer.h>
-#include <libds/seat.h>
-#include <libds-tizen/input_devicemgr.h>
-#include <xkbcommon/xkbcommon.h>
-#include <libds/interfaces/keyboard.h>
-#include <libds-tizen/launch.h>
-#include <libds-tizen/backend/tdm_output_hwc.h>
-
-#define USE_TDM_BUFFER_QUEUE
-
-#ifdef USE_TDM_BUFFER_QUEUE
-#include "pixman-tbm-helper.h"
-#include "tinyds-tdm-renderer.h"
-#else
-#include <libds/swapchain.h>
-#endif
-
-#include "pixman-helper.h"
-
-#define TINYDS_UNUSED __attribute__((unused))
-struct tinyds_keyboard;
-struct tinyds_pointer;
+#include "tinyds-tdm.h"
struct tinyds_output
{
struct ds_tdm_output_hwc *hwc;
struct ds_tdm_output_hwc_window *bg_hwc_window;
-};
-
-struct tinyds_dpms
-{
- struct ds_tizen_dpms *ds_dpms;
- struct tinyds_server *server;
-
- struct wl_listener destroy;
- struct wl_listener set_dpms;
- struct wl_listener get_dpms;
-};
-struct tinyds_server
-{
- struct ds_tbm_server *tbm_server;
-
- struct wl_display *display;
-
- struct ds_backend *backend;
- struct ds_backend *input_backend;
- struct ds_compositor *compositor;
- struct ds_xdg_shell *xdg_shell;
- struct ds_seat *seat;
- uint32_t seat_caps;
- double output_x, output_y;
- struct ds_tizen_input_devicemgr *devicemgr;
- struct ds_tizen_launch_effect *effect;
- struct ds_tizen_launch_splash *splash;
-
- struct tinyds_output *output;
- struct tinyds_dpms *dpms;
- struct wl_event_source *stdin_source;
-
- struct wl_list views;
-
- struct wl_listener new_output;
- struct wl_listener new_input;
- struct wl_listener new_xdg_surface;
- struct wl_listener devicemgr_destroy;
- struct wl_listener pointer_warp;
- struct wl_listener effect_destroy;
- struct wl_listener effect_type_set;
- struct wl_listener effect_type_unset;
- struct wl_listener new_splash;
- struct wl_listener splash_owner;
-
- struct wl_list keyboards;
- struct wl_list pointers;
+#ifdef USE_CURSOR
+ bool cursor_enabled;
+ struct ds_tdm_output_hwc_window *cursor_hwc_window;
+#endif
};
struct tinyds_view
struct wl_listener motion;
};
+struct tinyds_text_input {
+ struct ds_tizen_text_input *input;
+ struct ds_tizen_text_input_manager *text_input_mgr;
+
+ struct tinyds_server *server;
+ struct ds_surface *surface;
+
+ struct wl_list input_methods;
+
+ struct wl_listener mgr_destroy;
+ struct wl_listener new_text_input;
+
+ struct wl_listener destroy;
+ struct wl_listener text_input_activate;
+ struct wl_listener text_input_deactivate;
+ struct wl_listener text_input_reset;
+ struct wl_listener text_input_set_content_type;
+ struct wl_listener text_input_invoke_action;
+ struct wl_listener text_input_commit_state;
+ struct wl_listener text_input_set_preferred_language;
+};
+
+struct tinyds_input_method {
+ struct ds_tizen_input_method *input_method;
+ struct ds_tizen_input_method_manager *input_method_mgr;
+
+ struct tinyds_server *server;
+ struct tinyds_text_input *input;
+ struct tinyds_input_method_context *context;
+
+ struct wl_list link;
+
+ struct wl_listener destroy;
+ struct wl_listener mgr_destroy;
+};
+
+struct tinyds_input_method_context {
+ struct ds_tizen_input_method_context *context;
+
+ struct tinyds_server *server;
+ struct tinyds_text_input *input;
+ struct tinyds_input_method *input_method;
+
+ struct wl_listener destroy;
+
+ struct wl_listener im_context_commit_string;
+ struct wl_listener im_context_preedit_string;
+ struct wl_listener im_context_preedit_styling;
+ struct wl_listener im_context_preedit_cursor;
+ struct wl_listener im_context_delete_surrounding_text;
+ struct wl_listener im_context_cursor_position;
+ struct wl_listener im_context_modifiers_map;
+ struct wl_listener im_context_keysym;
+ struct wl_listener im_context_grab_keyboard;
+ struct wl_listener im_context_key;
+ struct wl_listener im_context_modifiers;
+ struct wl_listener im_context_language;
+ struct wl_listener im_context_text_direction;
+};
+
struct tinyds_server tinyds;
static bool init_server(struct tinyds_server *server, struct wl_display *display);
static void output_draw_with_swapchain(struct tinyds_output *output);
static void draw_view(struct tinyds_view *view, pixman_image_t *dst_image);
#endif
-static void dpms_handle_destroy(struct wl_listener *listener, void *data);
-static void dpms_handle_set_dpms(struct wl_listener *listener, void *data);
-static void dpms_handle_get_dpms(struct wl_listener *listener, void *data);
static void server_add_keyboard(struct tinyds_server *server,
struct ds_input_device *dev);
static void server_add_pointer(struct tinyds_server *server,
struct ds_input_device *dev);
static void server_add_touch(struct tinyds_server *server,
struct ds_input_device *dev);
-
static struct tinyds_view *
server_view_at(struct tinyds_server *server, double lx, double ly,
double *sx, double *sy);
+static bool add_new_text_input(struct tinyds_server *server);
+static bool add_new_input_method(struct tinyds_server *server);
+static bool add_new_input_method_context(
+ struct tinyds_input_method *input_method,
+ struct tinyds_text_input *text_input);
+
+static void text_input_mgr_handle_destroy(struct wl_listener *listener,
+ void *data TINYDS_UNUSED);
+static void text_input_mgr_handle_new_text_input(struct wl_listener *listener,
+ void *data TINYDS_UNUSED);
+
+static void input_method_mgr_handle_destroy(struct wl_listener *listener,
+ void *data TINYDS_UNUSED);
+
+static void input_method_handle_destroy(struct wl_listener *listener,
+ void *data TINYDS_UNUSED);
+
int
main(void)
{
wl_display_run(display);
+ protocol_trace_enable(false);
+ protocol_trace_fini();
+
wl_display_destroy_clients(display);
wl_display_destroy(display);
{
pid_t pid;
struct wl_client *client = NULL;
- struct ds_surface *surface = ds_xdg_surface_get_surface(view->xdg_surface);
+ struct ds_surface *surface;
+
+ surface = ds_xdg_surface_get_surface(view->xdg_surface);
+ if (!surface)
+ return;
+
+ client = wl_resource_get_client(ds_surface_get_wl_resource(surface));
+ if (!client)
+ return;
- if (surface)
- client = wl_resource_get_client(ds_surface_get_wl_resource(surface));
wl_client_get_credentials(client, &pid, NULL, NULL);
ds_inf("view pid(%u)", pid);
static void
server_new_xdg_surface(struct wl_listener *listener, void *data)
{
+ static unsigned int seedx = 1;
+ static unsigned int seedy = 43210;
struct tinyds_server *server;
struct tinyds_view *view;
struct ds_xdg_surface *xdg_surface;
ds_xdg_surface_get_surface(xdg_surface),
&view->surface_commit);
- view->x = rand() % 1000;
- view->y = rand() % 500;
+ view->x = rand_r(&seedx) % 1000;
+ view->y = rand_r(&seedy) % 500;
view->hwc_window = ds_tdm_output_hwc_window_create(server->output->hwc);
assert(view->hwc_window);
ds_tdm_output_hwc_window_set_dest_size(output->bg_hwc_window, output->width, output->height);
ds_tdm_output_hwc_window_set_transform(output->bg_hwc_window, WL_OUTPUT_TRANSFORM_NORMAL);
+#ifdef USE_CURSOR
+ output->cursor_enabled = false;
+#endif
+
output->output_destroy.notify = output_handle_destroy;
ds_output_add_destroy_listener(ds_output, &output->output_destroy);
ds_tizen_input_devicemgr_set_output_width_height(server->devicemgr, (uint32_t)output->width, (uint32_t)output->height);
server->output = output;
+ server->output_x = (double)(output->width) / 2;
+ server->output_y = (double)(output->height) / 2;
output_schedule_commit(output);
}
-static bool
-add_new_dpms(struct tinyds_server *server)
-{
- struct tinyds_dpms *dpms;
-
- dpms = calloc(1, sizeof *dpms);
- if (!dpms)
- return false;
-
- dpms->ds_dpms = ds_tizen_dpms_create(server->display);
- if (!dpms->ds_dpms) {
- free(dpms);
- ds_err("Could not create ds_tizen_dpms");
- return false;
- }
-
- dpms->destroy.notify = dpms_handle_destroy;
- ds_tizen_dpms_add_destroy_listener(dpms->ds_dpms, &dpms->destroy);
-
- dpms->set_dpms.notify = dpms_handle_set_dpms;
- ds_tizen_dpms_add_set_dpms_listener(dpms->ds_dpms, &dpms->set_dpms);
-
- dpms->get_dpms.notify = dpms_handle_get_dpms;
- ds_tizen_dpms_add_get_dpms_listener(dpms->ds_dpms, &dpms->get_dpms);
-
- server->dpms = dpms;
-
- ds_inf("Dpms (%p) added", dpms);
-
- return true;
-}
-
static void
backend_handle_new_input(struct wl_listener *listener, void *data)
{
&server->splash_owner);
}
+static void
+dpms_free_func(void *data)
+{
+ struct tinyds_server *server = (struct tinyds_server *)data;
+
+ server->dpms = NULL;
+}
+
+static void
+policy_free_func(void *data)
+{
+ struct tinyds_server *server = (struct tinyds_server *)data;
+
+ server->policy = NULL;
+}
+
static bool
init_server(struct tinyds_server *server, struct wl_display *display)
{
ds_xdg_shell_add_new_surface_listener(server->xdg_shell,
&server->new_xdg_surface);
- if (!add_new_dpms(server))
+ server->dpms = tinyds_dpms_init(server->display, dpms_free_func, (void *)server);
+ if (!server->dpms)
+ goto err;
+
+ server->policy = tinyds_policy_init(server->display, policy_free_func, (void *)server);
+ if (!server->policy)
goto err;
server->seat = ds_seat_create(display, "seat0" /* arbitrary name */);
ds_tizen_launch_effect_add_new_splash_listener(server->effect,
&server->new_splash);
+ if (!add_new_text_input(server))
+ goto err;
+
+ if (!add_new_input_method(server))
+ goto err;
+
+ if (protocol_trace_init(display))
+ protocol_trace_enable(true);
+
return true;
err:
need_target = true;
}
+#ifdef USE_CURSOR
+ if (output->cursor_hwc_window) {
+ src_box.x = 0;
+ src_box.y = 0;
+ src_box.width = CURSOR_W;
+ src_box.height = CURSOR_H;
+
+ ds_tdm_output_hwc_window_set_src_box(output->cursor_hwc_window, &src_box);
+ ds_tdm_output_hwc_window_set_position(output->cursor_hwc_window, output->server->output_x, output->server->output_y);
+ ds_tdm_output_hwc_window_set_dest_size(output->cursor_hwc_window, CURSOR_W, CURSOR_H);
+ ds_tdm_output_hwc_window_set_transform(output->cursor_hwc_window, WL_OUTPUT_TRANSFORM_NORMAL);
+
+ ds_tdm_output_hwc_window_set_composition(output->cursor_hwc_window,
+ DS_TDM_OUTPUT_HWC_WINDOW_COMPOSITION_CLIENT);
+ num_windows++;
+ need_target = true;
+ }
+#endif
+
if (num_windows) {
composited_hwc_windows = calloc(num_windows, sizeof *composited_hwc_windows);
if (!composited_hwc_windows)
ds_tdm_output_hwc_window_set_transform(view->hwc_window, WL_OUTPUT_TRANSFORM_NORMAL);
if (view->mapped) {
+#ifdef USE_CURSOR
+ ds_tdm_output_hwc_window_set_composition(view->hwc_window,
+ DS_TDM_OUTPUT_HWC_WINDOW_COMPOSITION_CLIENT);
+#endif
ds_tdm_output_hwc_window_set_composition(view->hwc_window,
DS_TDM_OUTPUT_HWC_WINDOW_COMPOSITION_DEVICE);
composited_hwc_windows[current_num_windows] = output->bg_hwc_window;
current_num_windows++;
}
+
+#ifdef USE_CURSOR
+ if (output->cursor_hwc_window) {
+ composited_hwc_windows[current_num_windows] = output->cursor_hwc_window;
+ current_num_windows++;
+ }
+#endif
}
if (!ds_tdm_output_hwc_validate(output->hwc, composited_hwc_windows,
}
static void
-dpms_handle_destroy(struct wl_listener *listener, void *data)
-{
- struct tinyds_dpms *dpms;
-
- dpms = wl_container_of(listener, dpms, destroy);
-
- ds_inf("Dpms(%p) destroyed", dpms);
-
- wl_list_remove(&dpms->destroy.link);
- wl_list_remove(&dpms->set_dpms.link);
- wl_list_remove(&dpms->get_dpms.link);
-
- free(dpms);
-}
-
-static void
-dpms_handle_set_dpms(struct wl_listener *listener, void *data)
-{
- struct tinyds_dpms *dpms;
- struct ds_tizen_dpms_event *event = data;
-
- dpms = wl_container_of(listener, dpms, set_dpms);
-
- ds_inf("Dpms(%p) set dpms : %d", dpms, event->mode);
-
- //To do
- //set dpms mode to output
- ds_tizen_dpms_send_set_result(dpms->ds_dpms, event->mode,
- DS_TIZEN_DPMS_ERROR_NONE);
-}
-
-static void
-dpms_handle_get_dpms(struct wl_listener *listener, void *data)
-{
- struct tinyds_dpms *dpms;
-
- dpms = wl_container_of(listener, dpms, get_dpms);
-
- ds_inf("Dpms(%p) get dpms", dpms);
-
- //To do
- //get dpms mode from output
- ds_tizen_dpms_send_get_result(dpms->ds_dpms, DS_TIZEN_DPMS_MODE_ON,
- DS_TIZEN_DPMS_ERROR_NONE);
-}
-
-static void
keyboard_handle_device_destroy(struct wl_listener *listener, void *data)
{
struct tinyds_keyboard *kbd;
ds_seat_touch_notify_down(touch->server->seat, ds_xdg_surface_get_surface(view->xdg_surface),
event->time_msec, event->id, sx, sy);
}
+
+#ifdef USE_CURSOR
+ if (server->output && server->output->cursor_enabled) {
+ renderer_cursor_update(&server->output->renderer, server->output_x, server->output_y);
+ draw_server_with_damage(server);
+ }
+#endif
}
static void
ds_seat_touch_notify_motion(server->seat, event->time_msec,
event->id, sx, sy);
}
+
+#ifdef USE_CURSOR
+ if (server->output && server->output->cursor_enabled) {
+ renderer_cursor_update(&server->output->renderer, server->output_x, server->output_y);
+ draw_server_with_damage(server);
+ }
+#endif
}
static void
pointer_handle_device_destroy(struct wl_listener *listener, void *data)
{
struct tinyds_pointer *pointer;
+ struct tinyds_server *server;
pointer = wl_container_of(listener, pointer, destroy);
wl_list_remove(&pointer->frame.link);
wl_list_remove(&pointer->link);
+#ifdef USE_CURSOR
+ server = pointer->server;
+ if (server->output && wl_list_empty(&server->pointers))
+ {
+ server->output->cursor_enabled = false;
+ renderer_cursor_destroy(&server->output->renderer);
+
+ if (server->output->cursor_hwc_window)
+ {
+ ds_tdm_output_hwc_window_destroy(server->output->cursor_hwc_window);
+ server->output->cursor_hwc_window = NULL;
+ }
+ draw_server_with_damage(server);
+ }
+#endif
+
free(pointer);
}
ds_seat_pointer_notify_motion(pointer->server->seat,
event->time_msec, sx, sy);
}
+
+#ifdef USE_CURSOR
+ if (server->output && server->output->cursor_enabled) {
+ renderer_cursor_update(&server->output->renderer, server->output_x, server->output_y);
+ draw_server_with_damage(server);
+ }
+#endif
}
static void
pointer->dev = dev;
pointer->server = server;
- server->output_x = 200;
- server->output_y = 200;
pointer->destroy.notify = pointer_handle_device_destroy;
ds_input_device_add_destroy_listener(dev, &pointer->destroy);
pointer->focused_view = NULL;
+#ifdef USE_CURSOR
+ if (server->output && wl_list_empty(&server->pointers)) {
+ server->output_x = (double)(server->output->width) / 2;
+ server->output_y = (double)(server->output->height) / 2;
+
+ server->output->cursor_enabled = true;
+ renderer_cursor_create(&server->output->renderer, 255, 0, 0, CURSOR_W, CURSOR_H);
+ renderer_cursor_update(&server->output->renderer, server->output_x, server->output_y);
+
+ server->output->cursor_hwc_window = ds_tdm_output_hwc_window_create(server->output->hwc);
+ assert(server->output->cursor_hwc_window);
+ draw_server_with_damage(server);
+ }
+#endif
+
wl_list_insert(&server->pointers, &pointer->link);
ds_inf("Pointer(%p) added", pointer);
}
-
static void
output_schedule_commit_handle_idle_timer(void *data)
{
output->idle_commit =
wl_event_loop_add_idle(ev, output_schedule_commit_handle_idle_timer, output);
}
+
+static void
+text_input_mgr_handle_destroy(struct wl_listener *listener, void *data)
+{
+ struct tinyds_text_input *text_input;
+ struct tinyds_server *server;
+
+ ds_inf("text_input_mgr_handle_destroy");
+ text_input = wl_container_of(listener, text_input, mgr_destroy);
+
+ wl_list_remove(&text_input->mgr_destroy.link);
+ wl_list_remove(&text_input->new_text_input.link);
+
+ server = text_input->server;
+ server->text_input = NULL;
+}
+
+static void
+text_input_handle_destroy(struct wl_listener *listener, void *data)
+{
+ struct tinyds_text_input *text_input;
+
+ ds_inf("text_input_handle_destroy");
+
+ text_input = wl_container_of(listener, text_input, destroy);
+
+ wl_list_remove(&text_input->destroy.link);
+ wl_list_remove(&text_input->text_input_activate.link);
+ wl_list_remove(&text_input->text_input_deactivate.link);
+ wl_list_remove(&text_input->text_input_reset.link);
+ wl_list_remove(&text_input->text_input_set_content_type.link);
+ wl_list_remove(&text_input->text_input_invoke_action.link);
+ wl_list_remove(&text_input->text_input_commit_state.link);
+ wl_list_remove(&text_input->text_input_set_preferred_language.link);
+
+ free(text_input);
+}
+
+static void
+text_input_handle_activate(struct wl_listener *listener, void *data)
+{
+ struct tinyds_text_input *text_input;
+ struct tinyds_input_method *input_method;
+ struct ds_tizen_text_input_event_activate *event = data;
+
+ text_input = wl_container_of(listener, text_input, text_input_activate);
+
+ input_method = text_input->server->input_method;
+
+ ds_inf("text_input_handle_activate. text_input(%p) seat(%p) surface(%p) text_input(%p)",
+ text_input, event->seat, event->surface, event->text_input);
+
+ if (input_method->input == text_input)
+ return;
+ if (input_method->input)
+ ;//deactivate_input_method(server->input_method);
+ input_method->input = text_input;
+ wl_list_insert(&text_input->input_methods, &input_method->link);
+
+ text_input->surface = event->surface;
+
+ if (!add_new_input_method_context(input_method, text_input))
+ return;
+
+ // ds_tizen_input_method_send_set_text_input_id();
+}
+
+static void
+text_input_handle_deactivate(struct wl_listener *listener, void *data)
+{
+ struct tinyds_text_input *text_input;
+ struct tinyds_input_method *input_method, *tmp;
+ struct ds_tizen_text_input_event_deactivate *event = data;
+
+ text_input = wl_container_of(listener, text_input, text_input_deactivate);
+ ds_inf("text_input_handle_deactivate. text_input(%p) seat(%p) text_input(%p)",
+ text_input, event->seat, event->text_input);
+
+ wl_list_for_each_safe(input_method, tmp, &text_input->input_methods, link) {
+ if (!input_method->input_method || !input_method->context->context) continue;
+ ds_tizen_input_method_send_deactivate(input_method->input_method, input_method->context->context);
+ input_method->input = NULL;
+ input_method->context = NULL;
+ wl_list_remove(&input_method->link);
+ }
+
+ text_input->surface = NULL;
+ // ds_tizen_input_method_send_close_connection();
+}
+
+static void
+text_input_handle_reset(struct wl_listener *listener, void *data)
+{
+ struct tinyds_text_input *text_input;
+ struct tinyds_input_method *input_method;
+
+ text_input = wl_container_of(listener, text_input, text_input_reset);
+
+ ds_inf("text_input_handle_reset. text_input(%p)", text_input);
+
+ wl_list_for_each(input_method, &text_input->input_methods, link) {
+ if (!input_method->context || !input_method->context->context) continue;
+ ds_tizen_input_method_context_send_reset(input_method->context->context);
+ }
+}
+
+static void
+text_input_handle_set_content_type(struct wl_listener *listener, void *data)
+{
+ struct tinyds_text_input *text_input;
+ struct ds_tizen_text_input_event_set_content_type *event = data;
+ struct tinyds_input_method *input_method;
+
+ text_input = wl_container_of(listener, text_input, text_input_set_content_type);
+
+ ds_inf("text_input_handle_content_type. text_input(%p) hint(%u) purpose(%u)",
+ text_input, event->hint, event->purpose);
+
+ wl_list_for_each(input_method, &text_input->input_methods, link) {
+ if (!input_method->context || !input_method->context->context) continue;
+ ds_tizen_input_method_context_send_content_type(input_method->context->context,
+ event->hint, event->purpose);
+ }
+}
+
+static void
+text_input_handle_invoke_action(struct wl_listener *listener, void *data)
+{
+ struct tinyds_text_input *text_input;
+ struct ds_tizen_text_input_event_invoke_action *event = data;
+ struct tinyds_input_method *input_method;
+
+ text_input = wl_container_of(listener, text_input, text_input_invoke_action);
+
+ ds_inf("text_input_handle_invoke_action. text_input(%p) button(%u) index(%u)",
+ text_input, event->button, event->index);
+
+ wl_list_for_each(input_method, &text_input->input_methods, link) {
+ if (!input_method->context || !input_method->context->context) continue;
+ ds_tizen_input_method_context_send_invoke_action(input_method->context->context,
+ event->button, event->index);
+ }
+}
+
+static void
+text_input_handle_commit_state(struct wl_listener *listener, void *data)
+{
+ struct tinyds_text_input *text_input;
+ struct ds_tizen_text_input_event_commit_state *event = data;
+ struct tinyds_input_method *input_method;
+
+ text_input = wl_container_of(listener, text_input, text_input_commit_state);
+
+ ds_inf("text_input_handle_commit_state. text_input(%p) serial(%u)",
+ text_input, event->serial);
+
+ wl_list_for_each(input_method, &text_input->input_methods, link) {
+ if (!input_method->context || !input_method->context->context) continue;
+ ds_tizen_input_method_context_send_commit_state(input_method->context->context,
+ event->serial);
+ }
+}
+
+static void
+text_input_handle_set_preferred_language(struct wl_listener *listener, void *data)
+{
+ struct tinyds_text_input *text_input;
+ struct ds_tizen_text_input_event_set_preferred_language *event = data;
+ struct tinyds_input_method *input_method;
+
+ text_input = wl_container_of(listener, text_input, text_input_set_preferred_language);
+
+ ds_inf("text_input_handle_set_preferred_language. text_input(%p) language(%s)",
+ text_input, event->language);
+
+ wl_list_for_each(input_method, &text_input->input_methods, link) {
+ if (!input_method->context || !input_method->context->context) continue;
+ ds_tizen_input_method_context_send_preferred_language(input_method->context->context,
+ event->language);
+ }
+}
+
+static void
+text_input_mgr_handle_new_text_input(struct wl_listener *listener, void *data)
+{
+ struct tinyds_text_input *text_input;
+ struct ds_tizen_text_input *input = data;
+
+ text_input = wl_container_of(listener, text_input, new_text_input);
+
+ ds_inf("text_input_mgr_handle_new_text_input");
+
+ text_input->input = input;
+
+ text_input->destroy.notify = text_input_handle_destroy;
+ ds_tizen_text_input_add_destroy_listener(text_input->input,
+ &text_input->destroy);
+
+ text_input->text_input_activate.notify = text_input_handle_activate;
+ ds_tizen_text_input_add_activate_listener(text_input->input,
+ &text_input->text_input_activate);
+
+ text_input->text_input_deactivate.notify = text_input_handle_deactivate;
+ ds_tizen_text_input_add_deactivate_listener(text_input->input,
+ &text_input->text_input_deactivate);
+
+ text_input->text_input_reset.notify = text_input_handle_reset;
+ ds_tizen_text_input_add_reset_listener(text_input->input,
+ &text_input->text_input_reset);
+
+ text_input->text_input_set_content_type.notify = text_input_handle_set_content_type;
+ ds_tizen_text_input_add_set_content_type_listener(text_input->input,
+ &text_input->text_input_set_content_type);
+
+ text_input->text_input_invoke_action.notify = text_input_handle_invoke_action;
+ ds_tizen_text_input_add_invoke_action_listener(text_input->input,
+ &text_input->text_input_invoke_action);
+
+ text_input->text_input_commit_state.notify = text_input_handle_commit_state;
+ ds_tizen_text_input_add_commit_state_listener(text_input->input,
+ &text_input->text_input_commit_state);
+
+ text_input->text_input_set_preferred_language.notify = text_input_handle_set_preferred_language;
+ ds_tizen_text_input_add_set_preferred_language_listener(text_input->input,
+ &text_input->text_input_set_preferred_language);
+}
+
+static void
+input_method_mgr_handle_destroy(struct wl_listener *listener, void *data)
+{
+ struct tinyds_input_method *input_method;
+
+ ds_inf("input_method_mgr_handle_destroy");
+
+ input_method = wl_container_of(listener, input_method, mgr_destroy);
+
+ wl_list_remove(&input_method->mgr_destroy.link);
+}
+
+static void
+input_method_handle_destroy(struct wl_listener *listener, void *data)
+{
+ struct tinyds_input_method *input_method;
+ struct tinyds_server *server;
+
+ ds_inf("input_method_handle_destroy");
+
+ input_method = wl_container_of(listener, input_method, destroy);
+
+ wl_list_remove(&input_method->destroy.link);
+
+ server = input_method->server;
+ server->input_method = NULL;
+
+ free(input_method);
+}
+
+static void
+context_handle_destroy(struct wl_listener *listener, void *data)
+{
+ struct tinyds_input_method_context *context;
+ struct tinyds_server *server;
+
+ ds_inf("context_handle_destroy");
+
+ context = wl_container_of(listener, context, destroy);
+
+ wl_list_remove(&context->destroy.link);
+
+ wl_list_remove(&context->im_context_commit_string.link);
+ wl_list_remove(&context->im_context_preedit_string.link);
+ wl_list_remove(&context->im_context_preedit_styling.link);
+ wl_list_remove(&context->im_context_preedit_cursor.link);
+ wl_list_remove(&context->im_context_delete_surrounding_text.link);
+ wl_list_remove(&context->im_context_cursor_position.link);
+ wl_list_remove(&context->im_context_modifiers_map.link);
+ wl_list_remove(&context->im_context_keysym.link);
+ wl_list_remove(&context->im_context_grab_keyboard.link);
+ wl_list_remove(&context->im_context_key.link);
+ wl_list_remove(&context->im_context_modifiers.link);
+ wl_list_remove(&context->im_context_language.link);
+ wl_list_remove(&context->im_context_text_direction.link);
+
+ server = context->server;
+ server->input_method->context = NULL;
+
+ free(context);
+}
+
+static void
+context_handle_commit_string(struct wl_listener *listener, void *data)
+{
+ struct tinyds_text_input *text_input;
+ struct tinyds_input_method_context *context;
+ struct ds_tizen_input_method_context_event_commit_string *event = data;
+
+ context = wl_container_of(listener, context, im_context_commit_string);
+ text_input = context->server->text_input;
+
+ ds_inf("context_handle_commit_string. text_input(%p) serial(%u) text(%s)",
+ text_input, event->serial, event->text);
+
+ ds_tizen_text_input_send_commit_string(text_input->input, event->serial, event->text);
+}
+
+static void
+context_handle_preedit_string(struct wl_listener *listener, void *data)
+{
+ struct tinyds_input_method_context *context;
+ struct tinyds_text_input *text_input;
+ struct ds_tizen_input_method_context_event_preedit_string *event = data;
+
+ context = wl_container_of(listener, context, im_context_preedit_string);
+ text_input = context->server->text_input;
+
+ ds_inf("context_handle_preedit_string. text_input(%p) serial(%u) text(%s) commit(%s)",
+ text_input, event->serial, event->text, event->commit);
+
+ ds_tizen_text_input_send_preedit_string(text_input->input, event->serial, event->text, event->commit);
+}
+
+static void
+context_handle_preedit_styling(struct wl_listener *listener, void *data)
+{
+ struct tinyds_input_method_context *context;
+ struct tinyds_text_input *text_input;
+ struct ds_tizen_input_method_context_event_preedit_styling *event = data;
+
+ context = wl_container_of(listener, context, im_context_preedit_styling);
+ text_input = context->server->text_input;
+
+ ds_inf("context_handle_preedit_styling. text_input(%p) index(%u) length(%u) style(%u)",
+ text_input, event->index, event->length, event->style);
+
+ ds_tizen_text_input_send_preedit_styling(text_input->input, event->index, event->length, event->style);
+}
+
+static void
+context_handle_preedit_cursor(struct wl_listener *listener, void *data)
+{
+ struct tinyds_input_method_context *context;
+ struct tinyds_text_input *text_input;
+ struct ds_tizen_input_method_context_event_preedit_cursor *event = data;
+
+ context = wl_container_of(listener, context, im_context_preedit_cursor);
+ text_input = context->server->text_input;
+
+ ds_inf("context_handle_preedit_cursor. text_input(%p) index(%u)",
+ text_input, event->index);
+
+ ds_tizen_text_input_send_preedit_cursor(text_input->input, event->index);
+}
+
+static void
+context_handle_delete_surrounding_text(struct wl_listener *listener, void *data)
+{
+ struct tinyds_input_method_context *context;
+ struct tinyds_text_input *text_input;
+ struct ds_tizen_input_method_context_event_delete_surrounding_text *event = data;
+
+ context = wl_container_of(listener, context, im_context_delete_surrounding_text);
+ text_input = context->server->text_input;
+
+ ds_inf("context_handle_delete_surrounding_text. text_input(%p) index(%d) length(%u)",
+ text_input, event->index, event->length);
+
+ ds_tizen_text_input_send_delete_surrounding_text(text_input->input, event->index, event->length);
+}
+
+static void
+context_handle_cursor_position(struct wl_listener *listener, void *data)
+{
+ struct tinyds_input_method_context *context;
+ struct tinyds_text_input *text_input;
+ struct ds_tizen_input_method_context_event_cursor_position *event = data;
+
+ context = wl_container_of(listener, context, im_context_cursor_position);
+ text_input = context->server->text_input;
+
+ ds_inf("context_handle_cursor_position. text_input(%p) index(%d) length(%d)",
+ text_input, event->index, event->anchor);
+
+ ds_tizen_text_input_send_cursor_position(text_input->input, event->index, event->anchor);
+}
+
+static void
+context_handle_modifiers_map(struct wl_listener *listener, void *data)
+{
+ struct tinyds_input_method_context *context;
+ struct tinyds_text_input *text_input;
+ struct ds_tizen_input_method_context_event_modifiers_map *event = data;
+
+ context = wl_container_of(listener, context, im_context_modifiers_map);
+ text_input = context->server->text_input;
+
+ ds_inf("context_handle_modifiers_map. text_input(%p) map(%p)",
+ text_input, event->map);
+
+ ds_tizen_text_input_send_modifiers_map(text_input->input, event->map);
+}
+
+static void
+context_handle_keysym(struct wl_listener *listener, void *data)
+{
+ struct tinyds_input_method_context *context;
+ struct tinyds_text_input *text_input;
+ struct ds_tizen_input_method_context_event_keysym *event = data;
+
+ context = wl_container_of(listener, context, im_context_keysym);
+ text_input = context->server->text_input;
+
+ ds_inf("context_handle_keysym. text_input(%p) serial(%u) time(%u) sysm(%u) state(%u) modifiers(%u)",
+ text_input, event->serial, event->time, event->sym, event->state, event->modifiers);
+
+ ds_tizen_text_input_send_keysym(text_input->input, event->serial, event->time, event->sym, event->state, event->modifiers);
+}
+
+static void
+context_handle_grab_keyboard(struct wl_listener *listener, void *data)
+{
+ struct tinyds_input_method_context *context;
+ struct tinyds_text_input *text_input;
+
+ context = wl_container_of(listener, context, im_context_grab_keyboard);
+ text_input = context->server->text_input;
+
+ ds_inf("context_handle_grab_keyboard. text_input(%p)",
+ text_input);
+
+ //TODO
+}
+
+static void
+context_handle_key(struct wl_listener *listener, void *data)
+{
+ struct tinyds_input_method_context *context;
+ struct tinyds_text_input *text_input;
+
+ context = wl_container_of(listener, context, im_context_key);
+ text_input = context->server->text_input;
+
+ ds_inf("context_handle_key. text_input(%p)",
+ text_input);
+
+ //TODO
+}
+
+static void
+context_handle_modifiers(struct wl_listener *listener, void *data)
+{
+ struct tinyds_input_method_context *context;
+ struct tinyds_text_input *text_input;
+
+ context = wl_container_of(listener, context, im_context_modifiers);
+ text_input = context->server->text_input;
+
+ ds_inf("context_handle_modifiers. text_input(%p)",
+ text_input);
+
+ //TODO
+}
+
+static void
+context_handle_language(struct wl_listener *listener, void *data)
+{
+ struct tinyds_input_method_context *context;
+ struct tinyds_text_input *text_input;
+ struct ds_tizen_input_method_context_event_language *event = data;
+
+ context = wl_container_of(listener, context, im_context_language);
+ text_input = context->server->text_input;
+
+ ds_inf("context_handle_language. text_input(%p) serial(%u), language(%s)",
+ text_input, event->serial, event->language);
+
+ ds_tizen_text_input_send_language(text_input->input, event->serial, event->language);
+}
+
+static void
+context_handle_text_direction(struct wl_listener *listener, void *data)
+{
+ struct tinyds_input_method_context *context;
+ struct tinyds_text_input *text_input;
+ struct ds_tizen_input_method_context_event_text_direction *event = data;
+
+ context = wl_container_of(listener, context, im_context_text_direction);
+ text_input = context->server->text_input;
+
+ ds_inf("context_handle_text_direction. text_input(%p) serial(%u), direction(%u)",
+ text_input, event->serial, event->direction);
+
+ ds_tizen_text_input_send_text_direction(text_input->input, event->serial, event->direction);
+}
+
+static bool
+add_new_text_input(struct tinyds_server *server)
+{
+ struct tinyds_text_input *text_input;
+
+ text_input = calloc(1, sizeof *text_input);
+ if (!text_input)
+ return false;
+
+ text_input->text_input_mgr = ds_tizen_text_input_manager_create(server->display);
+ if (!text_input->text_input_mgr) {
+ free(text_input);
+ ds_err("Could not create ds_tizen_text_input_manager");
+ return false;
+ }
+
+ wl_list_init(&text_input->input_methods);
+
+ text_input->mgr_destroy.notify = text_input_mgr_handle_destroy;
+ ds_tizen_text_input_manager_add_destroy_listener(text_input->text_input_mgr,
+ &text_input->mgr_destroy);
+
+ text_input->new_text_input.notify = text_input_mgr_handle_new_text_input;
+ ds_tizen_text_input_manager_add_new_text_input_listener(text_input->text_input_mgr,
+ &text_input->new_text_input);
+
+ text_input->server = server;
+ server->text_input = text_input;
+
+ ds_inf("Text_Input (%p) added", text_input);
+
+ return true;
+}
+
+static bool
+add_new_input_method(struct tinyds_server *server)
+{
+ struct tinyds_input_method *input_method;
+
+ input_method = calloc(1, sizeof *input_method);
+ if (!input_method)
+ return false;
+
+ input_method->input_method = ds_tizen_input_method_create(server->display);
+ if (!input_method->input_method) {
+ free(input_method);
+ ds_err("Could not create ds_tizen_input_method");
+ return false;
+ }
+ input_method->destroy.notify = input_method_handle_destroy;
+ ds_tizen_input_method_add_destroy_listener(input_method->input_method,
+ &input_method->destroy);
+
+ input_method->input_method_mgr = ds_tizen_input_method_manager_create(server->display);
+ if (!input_method->input_method_mgr) {
+ free(input_method);
+ ds_err("Could not create ds_tizen_input_method_manager");
+ return false;
+ }
+
+ input_method->mgr_destroy.notify = input_method_mgr_handle_destroy;
+ ds_tizen_input_method_manager_add_destroy_listener(input_method->input_method_mgr,
+ &input_method->mgr_destroy);
+
+ input_method->server = server;
+ server->input_method = input_method;
+
+ ds_inf("Input_Method (%p) added", input_method);
+
+ return true;
+}
+
+static bool
+add_new_input_method_context(struct tinyds_input_method *input_method,
+ struct tinyds_text_input *text_input)
+{
+ struct tinyds_input_method_context *context;
+
+ context = calloc(1, sizeof *context);
+ if (context == NULL)
+ {
+ ds_err("calloc is failed. tinyds_input_method_context");
+ return false;
+ }
+ input_method->context = context;
+ context->input_method = input_method;
+ context->server = input_method->server;
+ context->input = text_input;
+
+ context->context = ds_tizen_input_method_create_context(input_method->input_method);
+ if (context->context == NULL) {
+ ds_err("ds_tizen_input_method_create_context() failed.");
+ return false;
+ }
+
+ context->destroy.notify = context_handle_destroy;
+ ds_tizen_input_method_context_add_destroy_listener(context->context,
+ &context->destroy);
+
+ context->im_context_commit_string.notify = context_handle_commit_string;
+ ds_tizen_input_method_context_add_commit_string_listener(context->context,
+ &context->im_context_commit_string);
+
+ context->im_context_preedit_string.notify = context_handle_preedit_string;
+ ds_tizen_input_method_context_add_preedit_string_listener(context->context,
+ &context->im_context_preedit_string);
+
+ context->im_context_preedit_styling.notify = context_handle_preedit_styling;
+ ds_tizen_input_method_context_add_preedit_styling_listener(context->context,
+ &context->im_context_preedit_styling);
+
+ context->im_context_preedit_cursor.notify = context_handle_preedit_cursor;
+ ds_tizen_input_method_context_add_preedit_cursor_listener(context->context,
+ &context->im_context_preedit_cursor);
+
+ context->im_context_delete_surrounding_text.notify = context_handle_delete_surrounding_text;
+ ds_tizen_input_method_context_add_delete_surrounding_text_listener(context->context,
+ &context->im_context_delete_surrounding_text);
+
+ context->im_context_cursor_position.notify = context_handle_cursor_position;
+ ds_tizen_input_method_context_add_cursor_position_listener(context->context,
+ &context->im_context_cursor_position);
+
+ context->im_context_modifiers_map.notify = context_handle_modifiers_map;
+ ds_tizen_input_method_context_add_modifiers_map_listener(context->context,
+ &context->im_context_modifiers_map);
+
+ context->im_context_keysym.notify = context_handle_keysym;
+ ds_tizen_input_method_context_add_keysym_listener(context->context,
+ &context->im_context_keysym);
+
+ context->im_context_grab_keyboard.notify = context_handle_grab_keyboard;
+ ds_tizen_input_method_context_add_grab_keyboard_listener(context->context,
+ &context->im_context_grab_keyboard);
+
+ context->im_context_key.notify = context_handle_key;
+ ds_tizen_input_method_context_add_key_listener(context->context,
+ &context->im_context_key);
+
+ context->im_context_modifiers.notify = context_handle_modifiers;
+ ds_tizen_input_method_context_add_modifiers_listener(context->context,
+ &context->im_context_modifiers);
+
+ context->im_context_language.notify = context_handle_language;
+ ds_tizen_input_method_context_add_language_listener(context->context,
+ &context->im_context_language);
+
+ context->im_context_text_direction.notify = context_handle_text_direction;
+ ds_tizen_input_method_context_add_text_direction_listener(context->context,
+ &context->im_context_text_direction);
+
+ return true;
+}