1 #include "tinyds-tdm.h"
5 struct tinyds_server *server;
6 struct ds_output *ds_output;
7 struct ds_allocator *allocator;
8 #ifdef USE_TDM_BUFFER_QUEUE
9 struct tinyds_renderer renderer;
10 struct ds_tdm_buffer_queue *buffer_queue;
11 struct wl_listener buffer_queue_acquirable;
13 struct ds_swapchain *swapchain;
15 struct ds_buffer *front_buffer;
17 struct wl_listener output_destroy;
18 struct wl_listener output_frame;
22 struct wl_event_source *idle_commit;
27 struct ds_tdm_output_hwc *hwc;
28 struct ds_tdm_output_hwc_window *bg_hwc_window;
32 struct ds_tdm_output_hwc_window *cursor_hwc_window;
38 struct ds_input_device *dev;
39 struct tinyds_server *server;
41 struct tinyds_view *focused_view;
43 struct wl_listener destroy;
44 struct wl_listener motion; //relative
45 struct wl_listener button;
46 struct wl_listener frame;
47 struct wl_list link; //tinyds_server::pointers
50 struct tinyds_keyboard
52 struct ds_input_device *dev;
53 struct tinyds_server *server;
55 struct wl_listener destroy;
56 struct wl_listener key;
57 struct wl_list link; //tinyds_server::keyboards
62 struct ds_input_device *dev;
63 struct tinyds_server *server;
65 struct wl_listener destroy;
66 struct wl_listener down;
67 struct wl_listener up;
68 struct wl_listener motion;
71 struct tinyds_text_input {
72 struct ds_tizen_text_input *input;
73 struct ds_tizen_text_input_manager *text_input_mgr;
75 struct tinyds_server *server;
76 struct ds_surface *surface;
78 struct wl_list input_methods;
80 struct wl_listener mgr_destroy;
81 struct wl_listener new_text_input;
83 struct wl_listener destroy;
84 struct wl_listener text_input_activate;
85 struct wl_listener text_input_deactivate;
86 struct wl_listener text_input_reset;
87 struct wl_listener text_input_set_content_type;
88 struct wl_listener text_input_invoke_action;
89 struct wl_listener text_input_commit_state;
90 struct wl_listener text_input_set_preferred_language;
93 struct tinyds_input_method {
94 struct ds_tizen_input_method *input_method;
95 struct ds_tizen_input_method_manager *input_method_mgr;
97 struct tinyds_server *server;
98 struct tinyds_text_input *input;
99 struct tinyds_input_method_context *context;
103 struct wl_listener destroy;
104 struct wl_listener mgr_destroy;
107 struct tinyds_input_method_context {
108 struct ds_tizen_input_method_context *context;
110 struct tinyds_server *server;
111 struct tinyds_text_input *input;
112 struct tinyds_input_method *input_method;
114 struct wl_listener destroy;
116 struct wl_listener im_context_commit_string;
117 struct wl_listener im_context_preedit_string;
118 struct wl_listener im_context_preedit_styling;
119 struct wl_listener im_context_preedit_cursor;
120 struct wl_listener im_context_delete_surrounding_text;
121 struct wl_listener im_context_cursor_position;
122 struct wl_listener im_context_modifiers_map;
123 struct wl_listener im_context_keysym;
124 struct wl_listener im_context_grab_keyboard;
125 struct wl_listener im_context_key;
126 struct wl_listener im_context_modifiers;
127 struct wl_listener im_context_language;
128 struct wl_listener im_context_text_direction;
131 struct tinyds_server tinyds;
133 static bool init_server(struct tinyds_server *server, struct wl_display *display);
134 static int server_dispatch_stdin(int fd, uint32_t mask, void *data);
135 static void output_handle_destroy(struct wl_listener *listener, void *data);
136 static void output_handle_frame(struct wl_listener *listener, void *data);
137 static void draw_server_with_damage(struct tinyds_server *server);
138 static void draw_output(struct tinyds_output *output);
139 static void output_swap_buffer(struct tinyds_output *output,
140 struct ds_buffer *buffer);
141 static void view_send_frame_done(struct tinyds_view *view);
142 static void output_hwc_init(struct tinyds_output *output);
143 static void output_schedule_commit(struct tinyds_output *output);
144 static void output_commit(struct tinyds_output *output);
145 #ifdef USE_TDM_BUFFER_QUEUE
146 static void output_buffer_queue_init(struct tinyds_output *output);
147 static void output_renderer_init(struct tinyds_output *output);
148 static void output_draw_with_renderer(struct tinyds_output *output);
150 static void output_swapchain_init(struct tinyds_output *output,
151 int width, int height, uint32_t format);
152 static void output_draw_with_swapchain(struct tinyds_output *output);
153 static void draw_view(struct tinyds_view *view, pixman_image_t *dst_image);
155 static void server_add_keyboard(struct tinyds_server *server,
156 struct ds_input_device *dev);
157 static void server_add_pointer(struct tinyds_server *server,
158 struct ds_input_device *dev);
159 static void server_add_touch(struct tinyds_server *server,
160 struct ds_input_device *dev);
161 static bool add_new_text_input(struct tinyds_server *server);
162 static bool add_new_input_method(struct tinyds_server *server);
163 static bool add_new_input_method_context(
164 struct tinyds_input_method *input_method,
165 struct tinyds_text_input *text_input);
167 static void text_input_mgr_handle_destroy(struct wl_listener *listener,
168 void *data TINYDS_UNUSED);
169 static void text_input_mgr_handle_new_text_input(struct wl_listener *listener,
170 void *data TINYDS_UNUSED);
172 static void input_method_mgr_handle_destroy(struct wl_listener *listener,
173 void *data TINYDS_UNUSED);
175 static void input_method_handle_destroy(struct wl_listener *listener,
176 void *data TINYDS_UNUSED);
181 struct tinyds_server *server = &tinyds;
182 struct wl_display *display;
183 struct wl_event_loop *loop;
187 ds_log_init(DS_INF, NULL);
189 display = wl_display_create();
192 res = init_server(server, display);
195 socket = wl_display_add_socket_auto(display);
198 ds_backend_start(server->backend);
199 ds_backend_start(server->input_backend);
201 setenv("WAYLAND_DISPLAY", socket, true);
203 ds_inf("Running Wayland compositor on WAYLAND_DISPLAY=%s", socket);
205 loop = wl_display_get_event_loop(display);
206 server->stdin_source = wl_event_loop_add_fd(loop, STDIN_FILENO,
207 WL_EVENT_READABLE, server_dispatch_stdin, server);
209 wl_display_run(display);
211 protocol_trace_enable(false);
212 protocol_trace_fini();
214 wl_display_destroy_clients(display);
215 wl_display_destroy(display);
221 view_populate_pid(struct tinyds_view *view)
223 struct ds_surface *surface;
224 struct wl_client *client = NULL;
227 surface = ds_xdg_surface_get_surface(view->xdg_surface);
231 client = wl_resource_get_client(ds_surface_get_wl_resource(surface));
235 wl_client_get_credentials(client, &pid, NULL, NULL);
238 ds_inf("view pid(%u)", pid);
240 view->effect_type = tinyds_launch_get_effect_type(
241 view->server->launch, pid);
242 tinyds_launch_unset_effect_type(view->server->launch, pid);
244 ds_inf("view effect_type(%d)", view->effect_type);
248 view_handle_xdg_surface_map(struct wl_listener *listener,
249 void *data TINYDS_UNUSED)
251 struct tinyds_view *view;
252 struct ds_keyboard *keyboard;
253 struct tinyds_keyboard *kbd;
255 view = wl_container_of(listener, view, xdg_surface_map);
258 view_populate_pid(view);
260 wl_list_for_each(kbd, &view->server->keyboards, link) {
261 keyboard = ds_input_device_get_keyboard(kbd->dev);
262 if (keyboard != NULL) {
263 ds_seat_keyboard_notify_enter(view->server->seat,
264 ds_xdg_surface_get_surface(view->xdg_surface),
265 keyboard->keycodes, keyboard->num_keycodes,
266 &keyboard->modifiers);
273 view_handle_xdg_surface_unmap(struct wl_listener *listener,
274 void *data TINYDS_UNUSED)
276 struct tinyds_view *view;
278 view = wl_container_of(listener, view, xdg_surface_unmap);
279 view->mapped = false;
283 view_handle_xdg_surface_destroy(struct wl_listener *listener,
284 void *data TINYDS_UNUSED)
286 struct tinyds_view *view;
288 view = wl_container_of(listener, view, xdg_surface_destroy);
290 draw_server_with_damage(view->server);
292 ds_tdm_output_hwc_window_destroy(view->hwc_window);
294 wl_list_remove(&view->xdg_surface_destroy.link);
295 wl_list_remove(&view->xdg_surface_map.link);
296 wl_list_remove(&view->xdg_surface_unmap.link);
297 wl_list_remove(&view->surface_commit.link);
298 wl_list_remove(&view->link);
303 view_handle_surface_commit(struct wl_listener *listener,
304 void *data TINYDS_UNUSED)
306 struct tinyds_view *view;
308 view = wl_container_of(listener, view, surface_commit);
309 draw_server_with_damage(view->server);
313 server_new_xdg_surface(struct wl_listener *listener, void *data)
315 static unsigned int seedx = 1;
316 static unsigned int seedy = 43210;
317 struct tinyds_server *server;
318 struct tinyds_view *view;
319 struct ds_xdg_surface *xdg_surface;
321 server = wl_container_of(listener, server, new_xdg_surface);
324 ds_inf("New xdg_surface(%p)", (void *)xdg_surface);
326 view = calloc(1, sizeof *view);
329 view->server = server;
330 view->xdg_surface = xdg_surface;
332 view->xdg_surface_map.notify = view_handle_xdg_surface_map;
333 ds_xdg_surface_add_map_listener(xdg_surface,
334 &view->xdg_surface_map);
336 view->xdg_surface_unmap.notify = view_handle_xdg_surface_unmap;
337 ds_xdg_surface_add_unmap_listener(xdg_surface,
338 &view->xdg_surface_unmap);
340 view->xdg_surface_destroy.notify = view_handle_xdg_surface_destroy;
341 ds_xdg_surface_add_destroy_listener(xdg_surface,
342 &view->xdg_surface_destroy);
344 view->surface_commit.notify = view_handle_surface_commit;
345 ds_surface_add_commit_listener(
346 ds_xdg_surface_get_surface(xdg_surface),
347 &view->surface_commit);
349 view->x = rand_r(&seedx) % 1000;
350 view->y = rand_r(&seedy) % 500;
352 view->hwc_window = ds_tdm_output_hwc_window_create(server->output->hwc);
353 assert(view->hwc_window);
355 wl_list_insert(server->views.prev, &view->link);
358 view->effect_type = -1;
360 ds_inf("view at (%d, %d)", view->x, view->y);
364 backend_handle_new_output(struct wl_listener *listener, void *data)
366 struct tinyds_server *server;
367 struct tinyds_output *output;
368 struct ds_output *ds_output;
369 const struct ds_output_mode *mode;
370 struct ds_tdm_box src_box;
372 server = wl_container_of(listener, server, new_output);
375 ds_inf("New output(%p)", ds_output);
380 mode = ds_output_get_preferred_mode(ds_output);
381 ds_output_set_mode(ds_output, mode);
383 output = calloc(1, sizeof *output);
387 output->server = server;
388 output->ds_output = ds_output;
389 output->width = mode->width;
390 output->height = mode->height;
391 output->damaged = true;
392 output->committable = true;
394 output_hwc_init(output);
396 #ifdef USE_TDM_BUFFER_QUEUE
397 output_buffer_queue_init(output);
398 output_renderer_init(output);
400 output_swapchain_init(output, mode->width, mode->height,
401 DRM_FORMAT_XRGB8888);
404 output->bg_hwc_window = ds_tdm_output_hwc_window_create(output->hwc);
405 assert(output->bg_hwc_window);
409 src_box.width = output->width;
410 src_box.height = output->height;
412 ds_tdm_output_hwc_window_set_src_box(output->bg_hwc_window, &src_box);
413 ds_tdm_output_hwc_window_set_position(output->bg_hwc_window, 0, 0);
414 ds_tdm_output_hwc_window_set_dest_size(output->bg_hwc_window, output->width, output->height);
415 ds_tdm_output_hwc_window_set_transform(output->bg_hwc_window, WL_OUTPUT_TRANSFORM_NORMAL);
418 output->cursor_enabled = false;
421 output->output_destroy.notify = output_handle_destroy;
422 ds_output_add_destroy_listener(ds_output, &output->output_destroy);
424 output->output_frame.notify = output_handle_frame;
425 ds_output_add_frame_listener(ds_output, &output->output_frame);
427 tinyds_input_devicemgr_set_output_size(server->input_devicemgr, (uint32_t)output->width, (uint32_t)output->height);
429 server->output = output;
430 server->output_x = (double)(output->width) / 2;
431 server->output_y = (double)(output->height) / 2;
433 output_schedule_commit(output);
437 backend_handle_new_input(struct wl_listener *listener, void *data)
439 struct tinyds_server *server;
440 struct ds_input_device *dev = data;
441 enum ds_input_device_type dev_type;
443 server = wl_container_of(listener, server, new_input);
445 dev_type = ds_input_device_get_type(dev);
448 case DS_INPUT_DEVICE_KEYBOARD:
449 server_add_keyboard(server, dev);
450 server->seat_caps |= WL_SEAT_CAPABILITY_KEYBOARD;
452 case DS_INPUT_DEVICE_TOUCH:
453 server_add_touch(server, dev);
454 server->seat_caps |= WL_SEAT_CAPABILITY_TOUCH;
456 case DS_INPUT_DEVICE_POINTER:
457 server_add_pointer(server, dev);
458 server->seat_caps |= WL_SEAT_CAPABILITY_POINTER;
461 ds_err("Unknown type(%d) of ds_input_device", dev_type);
465 ds_seat_set_capabilities(server->seat, server->seat_caps);
469 dpms_free_func(void *data)
471 struct tinyds_server *server = (struct tinyds_server *)data;
477 policy_free_func(void *data)
479 struct tinyds_server *server = (struct tinyds_server *)data;
481 server->policy = NULL;
485 launch_free_func(void *data)
487 struct tinyds_server *server = (struct tinyds_server *)data;
489 server->launch = NULL;
493 input_devicemgr_free_func(void *data)
495 struct tinyds_server *server = (struct tinyds_server *)data;
497 server->input_devicemgr = NULL;
501 init_server(struct tinyds_server *server, struct wl_display *display)
503 server->display = display;
505 wl_list_init(&server->views);
507 if (wl_display_init_shm(display) != 0)
510 server->backend = ds_tdm_backend_create(display);
511 if (!server->backend)
514 server->input_backend = ds_libinput_backend_create(display);
515 if (!server->input_backend) {
516 ds_backend_destroy(server->backend);
520 server->new_output.notify = backend_handle_new_output;
521 ds_backend_add_new_output_listener(server->backend,
522 &server->new_output);
524 wl_list_init(&server->keyboards);
525 wl_list_init(&server->pointers);
526 server->new_input.notify = backend_handle_new_input;
527 ds_backend_add_new_input_listener(server->input_backend, &server->new_input);
529 server->compositor = ds_compositor_create(display);
530 if (!server->compositor)
533 server->tbm_server = ds_tbm_server_create(display);
534 if (!server->tbm_server)
537 server->xdg_shell = ds_xdg_shell_create(display);
538 if (!server->xdg_shell)
541 server->new_xdg_surface.notify = server_new_xdg_surface;
542 ds_xdg_shell_add_new_surface_listener(server->xdg_shell,
543 &server->new_xdg_surface);
545 server->dpms = tinyds_dpms_init(server->display, dpms_free_func, (void *)server);
549 server->policy = tinyds_policy_init(server->display, policy_free_func, (void *)server);
553 server->launch = tinyds_launch_init(server->display, launch_free_func, (void *)server);
557 server->seat = ds_seat_create(display, "seat0" /* arbitrary name */);
560 server->seat_caps = 0;
562 server->input_devicemgr = tinyds_input_devicemgr_init(server->input_backend,
563 server->seat, input_devicemgr_free_func, (void *)server);
564 if (!server->input_devicemgr)
567 if (!add_new_text_input(server))
570 if (!add_new_input_method(server))
573 if (protocol_trace_init(display))
574 protocol_trace_enable(true);
579 ds_backend_destroy(server->backend);
580 ds_backend_destroy(server->input_backend);
586 output_handle_destroy(struct wl_listener *listener, void *data TINYDS_UNUSED)
588 struct tinyds_output *output =
589 wl_container_of(listener, output, output_destroy);
591 if (output->bg_hwc_window)
592 ds_tdm_output_hwc_window_destroy(output->bg_hwc_window);
594 wl_list_remove(&output->output_destroy.link);
595 wl_list_remove(&output->output_frame.link);
597 if (output->front_buffer)
598 ds_buffer_unlock(output->front_buffer);
600 #ifdef USE_TDM_BUFFER_QUEUE
601 fini_renderer(&output->renderer);
603 if (output->swapchain)
604 ds_swapchain_destroy(output->swapchain);
606 if (output->allocator)
607 ds_allocator_destroy(output->allocator);
610 wl_display_terminate(output->server->display);
612 output->server->output = NULL;
618 output_commit(struct tinyds_output *output)
620 uint32_t num_changed = 0;
621 uint32_t num_windows = 0, current_num_windows = 0;
622 struct ds_tdm_output_hwc_window **composited_hwc_windows = NULL;
623 struct ds_tdm_output_hwc_window **changed_hwc_windows = NULL;
624 enum ds_tdm_output_hwc_window_composition composition;
625 struct tinyds_view *view;
627 bool need_target = false;
628 bool fully_obscured = false;
629 struct ds_buffer *ds_buffer;
630 struct ds_tdm_box src_box;
633 if (!output->committable)
636 if (!output->damaged && !output->target_updated)
639 wl_list_for_each_reverse(view, &output->server->views, link) {
640 if (!view->hwc_window)
643 ds_buffer = ds_surface_get_buffer(
644 ds_xdg_surface_get_surface(view->xdg_surface));
653 ds_buffer_get_size(ds_buffer, &w, &h);
655 if ((output->width <= w) && (output->height <= h))
656 fully_obscured = true;
659 if (fully_obscured) {
660 ds_tdm_output_hwc_window_set_composition(output->bg_hwc_window,
661 DS_TDM_OUTPUT_HWC_WINDOW_COMPOSITION_NONE);
663 ds_tdm_output_hwc_window_set_composition(output->bg_hwc_window,
664 DS_TDM_OUTPUT_HWC_WINDOW_COMPOSITION_CLIENT);
670 if (output->cursor_hwc_window) {
673 src_box.width = CURSOR_W;
674 src_box.height = CURSOR_H;
676 ds_tdm_output_hwc_window_set_src_box(output->cursor_hwc_window, &src_box);
677 ds_tdm_output_hwc_window_set_position(output->cursor_hwc_window, output->server->output_x, output->server->output_y);
678 ds_tdm_output_hwc_window_set_dest_size(output->cursor_hwc_window, CURSOR_W, CURSOR_H);
679 ds_tdm_output_hwc_window_set_transform(output->cursor_hwc_window, WL_OUTPUT_TRANSFORM_NORMAL);
681 ds_tdm_output_hwc_window_set_composition(output->cursor_hwc_window,
682 DS_TDM_OUTPUT_HWC_WINDOW_COMPOSITION_CLIENT);
689 composited_hwc_windows = calloc(num_windows, sizeof *composited_hwc_windows);
690 if (!composited_hwc_windows)
693 wl_list_for_each_reverse(view, &output->server->views, link) {
694 if (!view->hwc_window)
697 ds_buffer = ds_surface_get_buffer(
698 ds_xdg_surface_get_surface(view->xdg_surface));
702 ds_tdm_output_hwc_window_set_buffer(view->hwc_window, ds_buffer);
704 ds_buffer_get_size(ds_buffer, &w, &h);
711 ds_tdm_output_hwc_window_set_src_box(view->hwc_window, &src_box);
712 ds_tdm_output_hwc_window_set_position(view->hwc_window, view->x, view->y);
713 ds_tdm_output_hwc_window_set_dest_size(view->hwc_window, w, h);
714 ds_tdm_output_hwc_window_set_transform(view->hwc_window, WL_OUTPUT_TRANSFORM_NORMAL);
718 ds_tdm_output_hwc_window_set_composition(view->hwc_window,
719 DS_TDM_OUTPUT_HWC_WINDOW_COMPOSITION_CLIENT);
721 ds_tdm_output_hwc_window_set_composition(view->hwc_window,
722 DS_TDM_OUTPUT_HWC_WINDOW_COMPOSITION_DEVICE);
724 composited_hwc_windows[current_num_windows] = view->hwc_window;
725 current_num_windows++;
727 ds_tdm_output_hwc_window_set_composition(view->hwc_window,
728 DS_TDM_OUTPUT_HWC_WINDOW_COMPOSITION_NONE);
732 if (!fully_obscured) {
733 composited_hwc_windows[current_num_windows] = output->bg_hwc_window;
734 current_num_windows++;
738 if (output->cursor_hwc_window) {
739 composited_hwc_windows[current_num_windows] = output->cursor_hwc_window;
740 current_num_windows++;
745 if (!ds_tdm_output_hwc_validate(output->hwc, composited_hwc_windows,
746 num_windows, &num_changed)) {
747 free(composited_hwc_windows);
748 ds_err("Could not hwc validate");
752 if (composited_hwc_windows)
753 free(composited_hwc_windows);
755 if (num_changed > 0) {
756 changed_hwc_windows = calloc(num_windows, sizeof *changed_hwc_windows);
757 if (!changed_hwc_windows)
760 if (!ds_tdm_output_hwc_get_changed_composition(output->hwc, &num_changed,
761 changed_hwc_windows)) {
762 free(changed_hwc_windows);
763 ds_err("Could not get chaged composition");
767 for (i = 0; i < num_changed; i++) {
768 composition = ds_tdm_output_hwc_window_get_composition(changed_hwc_windows[i]);
769 if (composition == DS_TDM_OUTPUT_HWC_WINDOW_COMPOSITION_CLIENT) {
776 if (changed_hwc_windows)
777 free(changed_hwc_windows);
779 if (need_target && output->damaged)
782 #ifdef USE_TDM_BUFFER_QUEUE
783 struct ds_buffer *buffer;
785 buffer = ds_tdm_buffer_queue_acquire(output->buffer_queue);
787 if (!ds_tdm_output_hwc_set_client_target_buffer(output->hwc, buffer)) {
788 ds_err("Could not set hwc client target buffer");
792 output_swap_buffer(output, buffer);
796 if (!ds_tdm_output_hwc_accept_validation(output->hwc)) {
797 ds_err("Could not hwc accept validateion");
801 ds_output_commit(output->ds_output);
803 output->committable = false;
804 output->damaged = false;
805 output->target_updated = false;
807 wl_list_for_each(view, &output->server->views, link) {
808 enum ds_tdm_output_hwc_window_composition composition;
813 composition = ds_tdm_output_hwc_window_get_composition(view->hwc_window);
814 if ((composition == DS_TDM_OUTPUT_HWC_WINDOW_COMPOSITION_DEVICE) ||
815 (composition == DS_TDM_OUTPUT_HWC_WINDOW_COMPOSITION_VIDEO) ||
816 (composition == DS_TDM_OUTPUT_HWC_WINDOW_COMPOSITION_CURSOR))
817 view_send_frame_done(view);
820 ds_dbg("output:%p commit", output);
824 output_handle_frame(struct wl_listener *listener, void *data TINYDS_UNUSED)
826 struct tinyds_output *output =
827 wl_container_of(listener, output, output_frame);
829 ds_dbg("output:%p handle frame", output);
831 output->committable = true;
833 output_commit(output);
837 draw_server_with_damage(struct tinyds_server *server)
839 server->output->damaged = true;
840 output_schedule_commit(server->output);
844 output_hwc_init(struct tinyds_output *output)
846 struct ds_tdm_output *tdm_output;
848 tdm_output = ds_tdm_output_from_output(output->ds_output);
851 output->hwc = ds_tdm_output_get_hwc(tdm_output);
854 ds_tdm_output_hwc_set_enabled(output->hwc, true);
857 #ifdef USE_TDM_BUFFER_QUEUE
859 output_handle_buffer_queue_acquirable(struct wl_listener *listener,
860 void *data TINYDS_UNUSED)
862 struct tinyds_output *output;
864 output = wl_container_of(listener, output, buffer_queue_acquirable);
866 output->target_updated = true;
867 output_schedule_commit(output);
871 output_buffer_queue_init(struct tinyds_output *output)
873 struct ds_tdm_output *tdm_output;
875 tdm_output = ds_tdm_output_from_output(output->ds_output);
878 output->buffer_queue = ds_tdm_output_get_buffer_queue(tdm_output);
879 assert(output->buffer_queue);
881 output->buffer_queue_acquirable.notify =
882 output_handle_buffer_queue_acquirable;
883 ds_tdm_buffer_queue_add_acquirable_listener(output->buffer_queue,
884 &output->buffer_queue_acquirable);
888 output_renderer_init(struct tinyds_output *output)
890 init_renderer(&output->renderer);
892 renderer_set_surface_queue(&output->renderer,
893 ds_tdm_buffer_queue_get_native_queue(output->buffer_queue));
895 renderer_set_bg_color(&output->renderer, 80, 80, 80);
899 output_draw_with_renderer(struct tinyds_output *output)
901 struct tinyds_view *view;
903 ds_dbg(">> BEGIN UPDATE TEXTURES");
905 wl_list_for_each(view, &output->server->views, link) {
906 struct ds_buffer *ds_buffer;
907 struct ds_tbm_client_buffer *tbm_buffer;
908 tbm_surface_h surface;
909 enum ds_tdm_output_hwc_window_composition composition;
914 composition = ds_tdm_output_hwc_window_get_composition(view->hwc_window);
915 if ((composition == DS_TDM_OUTPUT_HWC_WINDOW_COMPOSITION_DEVICE) ||
916 (composition == DS_TDM_OUTPUT_HWC_WINDOW_COMPOSITION_VIDEO) ||
917 (composition == DS_TDM_OUTPUT_HWC_WINDOW_COMPOSITION_CURSOR))
920 ds_buffer = ds_surface_get_buffer(
921 ds_xdg_surface_get_surface(view->xdg_surface));
925 tbm_buffer = ds_tbm_client_buffer_from_buffer(ds_buffer);
929 surface = ds_tbm_client_buffer_get_tbm_surface(tbm_buffer);
933 renderer_add_texture(&output->renderer, surface, view->x, view->y);
935 view_send_frame_done(view);
938 ds_dbg("<< END UPDATE TEXTURES");
940 renderer_draw(&output->renderer);
944 output_swapchain_init(struct tinyds_output *output,
945 int width, int height, uint32_t format)
948 output->allocator = ds_tbm_allocator_create();
949 assert(output->allocator);
951 output->swapchain = ds_swapchain_create(output->allocator,
952 width, height, format);
953 assert(output->swapchain);
957 output_draw_with_swapchain(struct tinyds_output *output)
959 struct tinyds_view *view;
960 struct ds_buffer *output_buffer;
961 pixman_image_t *output_image;
962 enum ds_tdm_output_hwc_window_composition composition;
964 output_buffer = ds_swapchain_acquire(output->swapchain, NULL);
968 output_image = pixman_image_from_buffer(output_buffer,
969 DS_BUFFER_DATA_PTR_ACCESS_WRITE);
971 ds_buffer_unlock(output_buffer);
975 pixman_image_fill_color(output_image, 80, 80, 80);
977 wl_list_for_each(view, &output->server->views, link) {
981 composition = ds_tdm_output_hwc_window_get_composition(view->hwc_window);
982 if ((composition == DS_TDM_OUTPUT_HWC_WINDOW_COMPOSITION_DEVICE) ||
983 (composition == DS_TDM_OUTPUT_HWC_WINDOW_COMPOSITION_VIDEO) ||
984 (composition == DS_TDM_OUTPUT_HWC_WINDOW_COMPOSITION_CURSOR))
987 draw_view(view, output_image);
989 pixman_image_unref(output_image);
991 if (!ds_tdm_output_hwc_set_client_target_buffer(output->hwc, output_buffer)) {
992 ds_err("Could not set hwc client target buffer");
993 ds_buffer_unlock(output_buffer);
997 output_swap_buffer(output, output_buffer);
1001 draw_view(struct tinyds_view *view, pixman_image_t *dst_image)
1003 struct ds_buffer *buffer;
1004 pixman_image_t *src_image;
1006 buffer = ds_surface_get_buffer(
1007 ds_xdg_surface_get_surface(view->xdg_surface));
1011 src_image = pixman_image_from_buffer(buffer,
1012 DS_BUFFER_DATA_PTR_ACCESS_READ);
1013 pixman_image_composite32(PIXMAN_OP_OVER,
1019 pixman_image_get_width(src_image),
1020 pixman_image_get_height(src_image));
1021 pixman_image_unref(src_image);
1023 view_send_frame_done(view);
1028 draw_output(struct tinyds_output *output)
1030 #ifdef USE_TDM_BUFFER_QUEUE
1031 output_draw_with_renderer(output);
1033 output_draw_with_swapchain(output);
1036 ds_dbg("output:%p draw", output);
1040 output_swap_buffer(struct tinyds_output *output, struct ds_buffer *buffer)
1042 ds_output_attach_buffer(output->ds_output, buffer);
1044 if (output->front_buffer)
1045 ds_buffer_unlock(output->front_buffer);
1046 output->front_buffer = buffer;
1050 view_send_frame_done(struct tinyds_view *view)
1052 struct timespec now;
1053 clock_gettime(CLOCK_MONOTONIC, &now);
1054 ds_surface_send_frame_done(ds_xdg_surface_get_surface(view->xdg_surface),
1059 server_dispatch_stdin(int fd, uint32_t mask, void *data)
1061 struct tinyds_server *server = data;
1063 wl_display_terminate(server->display);
1069 keyboard_handle_device_destroy(struct wl_listener *listener, void *data)
1071 struct tinyds_keyboard *kbd;
1073 kbd = wl_container_of(listener, kbd, destroy);
1075 ds_inf("Keyboard(%p) destroyed", kbd);
1077 wl_list_remove(&kbd->destroy.link);
1078 wl_list_remove(&kbd->key.link);
1079 wl_list_remove(&kbd->link);
1085 server_handle_keybinding(struct tinyds_server *server, xkb_keysym_t sym)
1088 case XKB_KEY_BackSpace:
1089 wl_display_terminate(server->display);
1099 keyboard_handle_key(struct wl_listener *listener, void *data)
1101 struct tinyds_keyboard *kbd;
1102 struct ds_event_keyboard_key *event = data;
1103 struct ds_keyboard *ds_keyboard;
1104 struct xkb_state *xkb_state;
1105 const xkb_keysym_t *syms;
1107 bool handled = false;
1109 kbd = wl_container_of(listener, kbd, key);
1111 ds_inf("Keyboard(%p) event key: keycode(%d), state(%d), time_msec(%d), "
1112 "update_state(%d)", kbd->dev,
1113 event->keycode, event->state, event->time_msec,
1114 event->update_state);
1116 ds_keyboard = ds_input_device_get_keyboard(kbd->dev);
1118 if (event->state == WL_KEYBOARD_KEY_STATE_PRESSED) {
1119 xkb_state = ds_keyboard_get_xkb_state(ds_keyboard);
1121 nsyms = xkb_state_key_get_syms(xkb_state, event->keycode + 8,
1123 for (int i = 0; i < nsyms; i++) {
1124 handled = server_handle_keybinding(kbd->server, syms[i]);
1130 ds_seat_keyboard_notify_key(kbd->server->seat, event->time_msec,
1131 event->keycode, event->state);
1136 server_add_keyboard(struct tinyds_server *server, struct ds_input_device *dev)
1138 struct tinyds_keyboard *kbd;
1139 struct xkb_context *context;
1140 struct xkb_keymap *keymap;
1142 kbd = calloc(1, sizeof *kbd);
1146 kbd->server = server;
1148 context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
1152 keymap = xkb_keymap_new_from_names(context, NULL,
1153 XKB_KEYMAP_COMPILE_NO_FLAGS);
1156 ds_err("Failed to compile keymap");
1157 xkb_context_unref(context);
1161 ds_keyboard_set_keymap(ds_input_device_get_keyboard(dev), keymap);
1163 xkb_keymap_unref(keymap);
1164 xkb_context_unref(context);
1166 kbd->destroy.notify = keyboard_handle_device_destroy;
1167 ds_input_device_add_destroy_listener(dev, &kbd->destroy);
1169 kbd->key.notify = keyboard_handle_key;
1170 ds_keyboard_add_key_listener(ds_input_device_get_keyboard(dev), &kbd->key);
1172 wl_list_insert(&server->keyboards, &kbd->link);
1174 ds_inf("Keyboard(%p) added", kbd);
1182 struct tinyds_view *
1183 tinyds_server_view_at(struct tinyds_server *server, double lx, double ly,
1184 double *sx, double *sy)
1186 struct tinyds_view *view;
1187 struct ds_surface *surface;
1188 struct ds_buffer *buffer;
1189 int x, y, w = 0, h = 0;
1191 wl_list_for_each(view, &server->views, link) {
1192 surface = ds_xdg_surface_get_surface(view->xdg_surface);
1193 buffer = ds_surface_get_buffer(surface);
1194 ds_buffer_get_size(buffer, &w, &h);
1199 if (lx >= x && lx <= x + w && ly >= y && ly <= y + h) {
1211 touch_handle_device_destroy(struct wl_listener *listener, void *data)
1213 struct tinyds_touch *touch;
1215 touch = wl_container_of(listener, touch, destroy);
1217 ds_inf("Touch(%p) destroyed", touch);
1219 wl_list_remove(&touch->destroy.link);
1220 wl_list_remove(&touch->down.link);
1221 wl_list_remove(&touch->up.link);
1222 wl_list_remove(&touch->motion.link);
1228 touch_handle_down(struct wl_listener *listener, void *data)
1230 struct ds_event_touch_down *event = data;
1231 struct tinyds_touch *touch;
1232 struct tinyds_view *view;
1233 struct tinyds_server *server;
1234 double sx = 0.f, sy = 0.f;
1236 touch = wl_container_of(listener, touch, down);
1238 server = touch->server;
1239 server->output_x = event->x * server->output->width;
1240 server->output_y = event->y * server->output->height;
1242 ds_inf("Touch(%p) event down: id(%d) x %.3f y %.3f output_x %.1f output_y %.1f",
1243 touch->dev, event->id, event->x, event->y, server->output_x, server->output_y);
1245 view = tinyds_server_view_at(server, server->output_x, server->output_y, &sx, &sy);
1248 ds_seat_touch_notify_down(touch->server->seat, ds_xdg_surface_get_surface(view->xdg_surface),
1249 event->time_msec, event->id, sx, sy);
1253 if (server->output && server->output->cursor_enabled) {
1254 renderer_cursor_update(&server->output->renderer, server->output_x, server->output_y);
1255 draw_server_with_damage(server);
1261 touch_handle_up(struct wl_listener *listener, void *data)
1263 struct ds_event_touch_up *event = data;
1264 struct tinyds_touch *touch;
1266 touch = wl_container_of(listener, touch, up);
1268 ds_inf("Touch(%p) event up: id(%d) time_msec(%d)",
1269 touch->dev, event->id, event->time_msec);
1271 ds_seat_touch_notify_up(touch->server->seat, event->time_msec, event->id);
1275 touch_handle_motion(struct wl_listener *listener, void *data)
1277 struct ds_event_touch_motion *event = data;
1278 struct tinyds_touch *touch;
1279 struct tinyds_view *view;
1280 struct tinyds_server *server;
1281 double sx = 0.f, sy = 0.f;
1283 touch = wl_container_of(listener, touch, motion);
1285 server = touch->server;
1286 server->output_x = event->x * server->output->width;
1287 server->output_y = event->y * server->output->height;
1289 ds_inf("Touch(%p) event motion: id(%d) x %.3f y %.3f output_x %.1f output_y %.1f",
1290 touch->dev, event->id, event->x, event->y, server->output_x, server->output_y);
1292 view = tinyds_server_view_at(server, server->output_x, server->output_y, &sx, &sy);
1295 ds_seat_touch_notify_motion(server->seat, event->time_msec,
1300 if (server->output && server->output->cursor_enabled) {
1301 renderer_cursor_update(&server->output->renderer, server->output_x, server->output_y);
1302 draw_server_with_damage(server);
1308 server_add_touch(struct tinyds_server *server, struct ds_input_device *dev)
1310 struct tinyds_touch *touch;
1312 touch = calloc(1, sizeof *touch);
1316 touch->server = server;
1318 touch->destroy.notify = touch_handle_device_destroy;
1319 ds_input_device_add_destroy_listener(dev, &touch->destroy);
1321 touch->down.notify = touch_handle_down;
1322 ds_touch_add_down_listener(ds_input_device_get_touch(dev), &touch->down);
1324 touch->up.notify = touch_handle_up;
1325 ds_touch_add_up_listener(ds_input_device_get_touch(dev), &touch->up);
1327 touch->motion.notify = touch_handle_motion;
1328 ds_touch_add_motion_listener(ds_input_device_get_touch(dev), &touch->motion);
1330 ds_inf("Touch(%p) added", touch);
1334 pointer_handle_device_destroy(struct wl_listener *listener, void *data)
1336 struct tinyds_pointer *pointer;
1337 struct tinyds_server *server;
1339 pointer = wl_container_of(listener, pointer, destroy);
1341 ds_inf("Pointer(%p) destroyed", pointer);
1343 wl_list_remove(&pointer->destroy.link);
1344 wl_list_remove(&pointer->motion.link);
1345 wl_list_remove(&pointer->button.link);
1346 wl_list_remove(&pointer->frame.link);
1347 wl_list_remove(&pointer->link);
1350 server = pointer->server;
1351 if (server->output && wl_list_empty(&server->pointers))
1353 server->output->cursor_enabled = false;
1354 renderer_cursor_destroy(&server->output->renderer);
1356 if (server->output->cursor_hwc_window)
1358 ds_tdm_output_hwc_window_destroy(server->output->cursor_hwc_window);
1359 server->output->cursor_hwc_window = NULL;
1361 draw_server_with_damage(server);
1369 pointer_handle_motion(struct wl_listener *listener, void *data)
1371 struct tinyds_pointer *pointer;
1372 struct ds_event_pointer_motion *event = data;
1373 struct tinyds_view *view;
1374 struct tinyds_server *server;
1378 pointer = wl_container_of(listener, pointer, motion);
1380 server = pointer->server;
1381 if (server->output) {
1382 ow = server->output->width;
1383 oh = server->output->height;
1386 if (server->output_x + event->delta_x >= ow)
1387 server->output_x = ow;
1388 else if(server->output_x + event->delta_x <= 0.f)
1389 server->output_x = 0.f;
1391 server->output_x = server->output_x + event->delta_x ;
1392 if (server->output_y + event->delta_y >= oh)
1393 server->output_y = oh;
1394 else if(server->output_y + event->delta_y <= 0.f)
1395 server->output_y = 0.f;
1397 server->output_y = server->output_y + event->delta_y ;
1399 ds_inf("Pointer(%p) motion: (delta_x %.1f delta_y %.1f) output_x %.1f output_y %.1f",
1400 pointer, event->delta_x, event->delta_y, server->output_x, server->output_y);
1402 view = tinyds_server_view_at(pointer->server, server->output_x, server->output_y, &sx, &sy);
1404 if (pointer->focused_view != view) {
1405 if (pointer->focused_view) {
1406 ds_inf("Clear pointer focus from view(%p)", pointer->focused_view);
1407 ds_seat_pointer_notify_clear_focus(pointer->server->seat);
1408 pointer->focused_view = NULL;
1412 ds_inf("Set pointer focus to view(%p)", view);
1413 ds_seat_pointer_notify_enter(pointer->server->seat,
1414 ds_xdg_surface_get_surface(view->xdg_surface), sx, sy);
1415 pointer->focused_view = view;
1420 ds_seat_pointer_notify_motion(pointer->server->seat,
1421 event->time_msec, sx, sy);
1425 if (server->output && server->output->cursor_enabled) {
1426 renderer_cursor_update(&server->output->renderer, server->output_x, server->output_y);
1427 draw_server_with_damage(server);
1433 pointer_handle_button(struct wl_listener *listener, void *data)
1435 struct tinyds_pointer *pointer;
1436 struct ds_event_pointer_button *event = data;
1438 pointer = wl_container_of(listener, pointer, button);
1440 ds_inf("Pointer(%p) button(%d): state(%s) time(%d)",
1441 pointer, event->button,
1442 (event->state == DS_BUTTON_PRESSED) ? "Pressed" : "Released",
1445 ds_seat_pointer_notify_button(pointer->server->seat, event->time_msec, event->button, event->state);
1449 pointer_handle_frame(struct wl_listener *listener, void *data)
1451 struct tinyds_pointer *pointer;
1453 pointer = wl_container_of(listener, pointer, frame);
1455 ds_inf("Pointer(%p) frame", pointer);
1456 ds_seat_pointer_notify_frame(pointer->server->seat);
1460 server_add_pointer(struct tinyds_server *server, struct ds_input_device *dev)
1462 struct tinyds_pointer *pointer;
1464 pointer = calloc(1, sizeof *pointer);
1468 pointer->server = server;
1470 pointer->destroy.notify = pointer_handle_device_destroy;
1471 ds_input_device_add_destroy_listener(dev, &pointer->destroy);
1473 pointer->motion.notify = pointer_handle_motion;
1474 ds_pointer_add_motion_listener(ds_input_device_get_pointer(dev),
1477 pointer->button.notify = pointer_handle_button;
1478 ds_pointer_add_button_listener(ds_input_device_get_pointer(dev),
1481 pointer->frame.notify = pointer_handle_frame;
1482 ds_pointer_add_frame_listener(ds_input_device_get_pointer(dev),
1485 pointer->focused_view = NULL;
1488 if (server->output && wl_list_empty(&server->pointers)) {
1489 server->output_x = (double)(server->output->width) / 2;
1490 server->output_y = (double)(server->output->height) / 2;
1492 server->output->cursor_enabled = true;
1493 renderer_cursor_create(&server->output->renderer, 255, 0, 0, CURSOR_W, CURSOR_H);
1494 renderer_cursor_update(&server->output->renderer, server->output_x, server->output_y);
1496 server->output->cursor_hwc_window = ds_tdm_output_hwc_window_create(server->output->hwc);
1497 assert(server->output->cursor_hwc_window);
1498 draw_server_with_damage(server);
1502 wl_list_insert(&server->pointers, &pointer->link);
1504 ds_inf("Pointer(%p) added", pointer);
1508 output_schedule_commit_handle_idle_timer(void *data)
1510 struct tinyds_output *output = data;
1511 output->idle_commit = NULL;
1513 output_commit(output);
1517 output_schedule_commit(struct tinyds_output *output)
1519 if (output->idle_commit)
1522 struct wl_event_loop *ev = wl_display_get_event_loop(output->server->display);
1523 output->idle_commit =
1524 wl_event_loop_add_idle(ev, output_schedule_commit_handle_idle_timer, output);
1528 text_input_mgr_handle_destroy(struct wl_listener *listener, void *data)
1530 struct tinyds_text_input *text_input;
1531 struct tinyds_server *server;
1533 ds_inf("text_input_mgr_handle_destroy");
1534 text_input = wl_container_of(listener, text_input, mgr_destroy);
1536 wl_list_remove(&text_input->mgr_destroy.link);
1537 wl_list_remove(&text_input->new_text_input.link);
1539 server = text_input->server;
1540 server->text_input = NULL;
1544 text_input_handle_destroy(struct wl_listener *listener, void *data)
1546 struct tinyds_text_input *text_input;
1548 ds_inf("text_input_handle_destroy");
1550 text_input = wl_container_of(listener, text_input, destroy);
1552 wl_list_remove(&text_input->destroy.link);
1553 wl_list_remove(&text_input->text_input_activate.link);
1554 wl_list_remove(&text_input->text_input_deactivate.link);
1555 wl_list_remove(&text_input->text_input_reset.link);
1556 wl_list_remove(&text_input->text_input_set_content_type.link);
1557 wl_list_remove(&text_input->text_input_invoke_action.link);
1558 wl_list_remove(&text_input->text_input_commit_state.link);
1559 wl_list_remove(&text_input->text_input_set_preferred_language.link);
1565 text_input_handle_activate(struct wl_listener *listener, void *data)
1567 struct tinyds_text_input *text_input;
1568 struct tinyds_input_method *input_method;
1569 struct ds_tizen_text_input_event_activate *event = data;
1571 text_input = wl_container_of(listener, text_input, text_input_activate);
1573 input_method = text_input->server->input_method;
1575 ds_inf("text_input_handle_activate. text_input(%p) seat(%p) surface(%p) text_input(%p)",
1576 text_input, event->seat, event->surface, event->text_input);
1578 if (input_method->input == text_input)
1580 if (input_method->input)
1581 ;//deactivate_input_method(server->input_method);
1582 input_method->input = text_input;
1583 wl_list_insert(&text_input->input_methods, &input_method->link);
1585 text_input->surface = event->surface;
1587 if (!add_new_input_method_context(input_method, text_input))
1590 // ds_tizen_input_method_send_set_text_input_id();
1594 text_input_handle_deactivate(struct wl_listener *listener, void *data)
1596 struct tinyds_text_input *text_input;
1597 struct tinyds_input_method *input_method, *tmp;
1598 struct ds_tizen_text_input_event_deactivate *event = data;
1600 text_input = wl_container_of(listener, text_input, text_input_deactivate);
1601 ds_inf("text_input_handle_deactivate. text_input(%p) seat(%p) text_input(%p)",
1602 text_input, event->seat, event->text_input);
1604 wl_list_for_each_safe(input_method, tmp, &text_input->input_methods, link) {
1605 if (!input_method->input_method || !input_method->context->context) continue;
1606 ds_tizen_input_method_send_deactivate(input_method->input_method, input_method->context->context);
1607 input_method->input = NULL;
1608 input_method->context = NULL;
1609 wl_list_remove(&input_method->link);
1612 text_input->surface = NULL;
1613 // ds_tizen_input_method_send_close_connection();
1617 text_input_handle_reset(struct wl_listener *listener, void *data)
1619 struct tinyds_text_input *text_input;
1620 struct tinyds_input_method *input_method;
1622 text_input = wl_container_of(listener, text_input, text_input_reset);
1624 ds_inf("text_input_handle_reset. text_input(%p)", text_input);
1626 wl_list_for_each(input_method, &text_input->input_methods, link) {
1627 if (!input_method->context || !input_method->context->context) continue;
1628 ds_tizen_input_method_context_send_reset(input_method->context->context);
1633 text_input_handle_set_content_type(struct wl_listener *listener, void *data)
1635 struct tinyds_text_input *text_input;
1636 struct ds_tizen_text_input_event_set_content_type *event = data;
1637 struct tinyds_input_method *input_method;
1639 text_input = wl_container_of(listener, text_input, text_input_set_content_type);
1641 ds_inf("text_input_handle_content_type. text_input(%p) hint(%u) purpose(%u)",
1642 text_input, event->hint, event->purpose);
1644 wl_list_for_each(input_method, &text_input->input_methods, link) {
1645 if (!input_method->context || !input_method->context->context) continue;
1646 ds_tizen_input_method_context_send_content_type(input_method->context->context,
1647 event->hint, event->purpose);
1652 text_input_handle_invoke_action(struct wl_listener *listener, void *data)
1654 struct tinyds_text_input *text_input;
1655 struct ds_tizen_text_input_event_invoke_action *event = data;
1656 struct tinyds_input_method *input_method;
1658 text_input = wl_container_of(listener, text_input, text_input_invoke_action);
1660 ds_inf("text_input_handle_invoke_action. text_input(%p) button(%u) index(%u)",
1661 text_input, event->button, event->index);
1663 wl_list_for_each(input_method, &text_input->input_methods, link) {
1664 if (!input_method->context || !input_method->context->context) continue;
1665 ds_tizen_input_method_context_send_invoke_action(input_method->context->context,
1666 event->button, event->index);
1671 text_input_handle_commit_state(struct wl_listener *listener, void *data)
1673 struct tinyds_text_input *text_input;
1674 struct ds_tizen_text_input_event_commit_state *event = data;
1675 struct tinyds_input_method *input_method;
1677 text_input = wl_container_of(listener, text_input, text_input_commit_state);
1679 ds_inf("text_input_handle_commit_state. text_input(%p) serial(%u)",
1680 text_input, event->serial);
1682 wl_list_for_each(input_method, &text_input->input_methods, link) {
1683 if (!input_method->context || !input_method->context->context) continue;
1684 ds_tizen_input_method_context_send_commit_state(input_method->context->context,
1690 text_input_handle_set_preferred_language(struct wl_listener *listener, void *data)
1692 struct tinyds_text_input *text_input;
1693 struct ds_tizen_text_input_event_set_preferred_language *event = data;
1694 struct tinyds_input_method *input_method;
1696 text_input = wl_container_of(listener, text_input, text_input_set_preferred_language);
1698 ds_inf("text_input_handle_set_preferred_language. text_input(%p) language(%s)",
1699 text_input, event->language);
1701 wl_list_for_each(input_method, &text_input->input_methods, link) {
1702 if (!input_method->context || !input_method->context->context) continue;
1703 ds_tizen_input_method_context_send_preferred_language(input_method->context->context,
1709 text_input_mgr_handle_new_text_input(struct wl_listener *listener, void *data)
1711 struct tinyds_text_input *text_input;
1712 struct ds_tizen_text_input *input = data;
1714 text_input = wl_container_of(listener, text_input, new_text_input);
1716 ds_inf("text_input_mgr_handle_new_text_input");
1718 text_input->input = input;
1720 text_input->destroy.notify = text_input_handle_destroy;
1721 ds_tizen_text_input_add_destroy_listener(text_input->input,
1722 &text_input->destroy);
1724 text_input->text_input_activate.notify = text_input_handle_activate;
1725 ds_tizen_text_input_add_activate_listener(text_input->input,
1726 &text_input->text_input_activate);
1728 text_input->text_input_deactivate.notify = text_input_handle_deactivate;
1729 ds_tizen_text_input_add_deactivate_listener(text_input->input,
1730 &text_input->text_input_deactivate);
1732 text_input->text_input_reset.notify = text_input_handle_reset;
1733 ds_tizen_text_input_add_reset_listener(text_input->input,
1734 &text_input->text_input_reset);
1736 text_input->text_input_set_content_type.notify = text_input_handle_set_content_type;
1737 ds_tizen_text_input_add_set_content_type_listener(text_input->input,
1738 &text_input->text_input_set_content_type);
1740 text_input->text_input_invoke_action.notify = text_input_handle_invoke_action;
1741 ds_tizen_text_input_add_invoke_action_listener(text_input->input,
1742 &text_input->text_input_invoke_action);
1744 text_input->text_input_commit_state.notify = text_input_handle_commit_state;
1745 ds_tizen_text_input_add_commit_state_listener(text_input->input,
1746 &text_input->text_input_commit_state);
1748 text_input->text_input_set_preferred_language.notify = text_input_handle_set_preferred_language;
1749 ds_tizen_text_input_add_set_preferred_language_listener(text_input->input,
1750 &text_input->text_input_set_preferred_language);
1754 input_method_mgr_handle_destroy(struct wl_listener *listener, void *data)
1756 struct tinyds_input_method *input_method;
1758 ds_inf("input_method_mgr_handle_destroy");
1760 input_method = wl_container_of(listener, input_method, mgr_destroy);
1762 wl_list_remove(&input_method->mgr_destroy.link);
1766 input_method_handle_destroy(struct wl_listener *listener, void *data)
1768 struct tinyds_input_method *input_method;
1769 struct tinyds_server *server;
1771 ds_inf("input_method_handle_destroy");
1773 input_method = wl_container_of(listener, input_method, destroy);
1775 wl_list_remove(&input_method->destroy.link);
1777 server = input_method->server;
1778 server->input_method = NULL;
1784 context_handle_destroy(struct wl_listener *listener, void *data)
1786 struct tinyds_input_method_context *context;
1787 struct tinyds_server *server;
1789 ds_inf("context_handle_destroy");
1791 context = wl_container_of(listener, context, destroy);
1793 wl_list_remove(&context->destroy.link);
1795 wl_list_remove(&context->im_context_commit_string.link);
1796 wl_list_remove(&context->im_context_preedit_string.link);
1797 wl_list_remove(&context->im_context_preedit_styling.link);
1798 wl_list_remove(&context->im_context_preedit_cursor.link);
1799 wl_list_remove(&context->im_context_delete_surrounding_text.link);
1800 wl_list_remove(&context->im_context_cursor_position.link);
1801 wl_list_remove(&context->im_context_modifiers_map.link);
1802 wl_list_remove(&context->im_context_keysym.link);
1803 wl_list_remove(&context->im_context_grab_keyboard.link);
1804 wl_list_remove(&context->im_context_key.link);
1805 wl_list_remove(&context->im_context_modifiers.link);
1806 wl_list_remove(&context->im_context_language.link);
1807 wl_list_remove(&context->im_context_text_direction.link);
1809 server = context->server;
1810 server->input_method->context = NULL;
1816 context_handle_commit_string(struct wl_listener *listener, void *data)
1818 struct tinyds_text_input *text_input;
1819 struct tinyds_input_method_context *context;
1820 struct ds_tizen_input_method_context_event_commit_string *event = data;
1822 context = wl_container_of(listener, context, im_context_commit_string);
1823 text_input = context->server->text_input;
1825 ds_inf("context_handle_commit_string. text_input(%p) serial(%u) text(%s)",
1826 text_input, event->serial, event->text);
1828 ds_tizen_text_input_send_commit_string(text_input->input, event->serial, event->text);
1832 context_handle_preedit_string(struct wl_listener *listener, void *data)
1834 struct tinyds_input_method_context *context;
1835 struct tinyds_text_input *text_input;
1836 struct ds_tizen_input_method_context_event_preedit_string *event = data;
1838 context = wl_container_of(listener, context, im_context_preedit_string);
1839 text_input = context->server->text_input;
1841 ds_inf("context_handle_preedit_string. text_input(%p) serial(%u) text(%s) commit(%s)",
1842 text_input, event->serial, event->text, event->commit);
1844 ds_tizen_text_input_send_preedit_string(text_input->input, event->serial, event->text, event->commit);
1848 context_handle_preedit_styling(struct wl_listener *listener, void *data)
1850 struct tinyds_input_method_context *context;
1851 struct tinyds_text_input *text_input;
1852 struct ds_tizen_input_method_context_event_preedit_styling *event = data;
1854 context = wl_container_of(listener, context, im_context_preedit_styling);
1855 text_input = context->server->text_input;
1857 ds_inf("context_handle_preedit_styling. text_input(%p) index(%u) length(%u) style(%u)",
1858 text_input, event->index, event->length, event->style);
1860 ds_tizen_text_input_send_preedit_styling(text_input->input, event->index, event->length, event->style);
1864 context_handle_preedit_cursor(struct wl_listener *listener, void *data)
1866 struct tinyds_input_method_context *context;
1867 struct tinyds_text_input *text_input;
1868 struct ds_tizen_input_method_context_event_preedit_cursor *event = data;
1870 context = wl_container_of(listener, context, im_context_preedit_cursor);
1871 text_input = context->server->text_input;
1873 ds_inf("context_handle_preedit_cursor. text_input(%p) index(%u)",
1874 text_input, event->index);
1876 ds_tizen_text_input_send_preedit_cursor(text_input->input, event->index);
1880 context_handle_delete_surrounding_text(struct wl_listener *listener, void *data)
1882 struct tinyds_input_method_context *context;
1883 struct tinyds_text_input *text_input;
1884 struct ds_tizen_input_method_context_event_delete_surrounding_text *event = data;
1886 context = wl_container_of(listener, context, im_context_delete_surrounding_text);
1887 text_input = context->server->text_input;
1889 ds_inf("context_handle_delete_surrounding_text. text_input(%p) index(%d) length(%u)",
1890 text_input, event->index, event->length);
1892 ds_tizen_text_input_send_delete_surrounding_text(text_input->input, event->index, event->length);
1896 context_handle_cursor_position(struct wl_listener *listener, void *data)
1898 struct tinyds_input_method_context *context;
1899 struct tinyds_text_input *text_input;
1900 struct ds_tizen_input_method_context_event_cursor_position *event = data;
1902 context = wl_container_of(listener, context, im_context_cursor_position);
1903 text_input = context->server->text_input;
1905 ds_inf("context_handle_cursor_position. text_input(%p) index(%d) length(%d)",
1906 text_input, event->index, event->anchor);
1908 ds_tizen_text_input_send_cursor_position(text_input->input, event->index, event->anchor);
1912 context_handle_modifiers_map(struct wl_listener *listener, void *data)
1914 struct tinyds_input_method_context *context;
1915 struct tinyds_text_input *text_input;
1916 struct ds_tizen_input_method_context_event_modifiers_map *event = data;
1918 context = wl_container_of(listener, context, im_context_modifiers_map);
1919 text_input = context->server->text_input;
1921 ds_inf("context_handle_modifiers_map. text_input(%p) map(%p)",
1922 text_input, event->map);
1924 ds_tizen_text_input_send_modifiers_map(text_input->input, event->map);
1928 context_handle_keysym(struct wl_listener *listener, void *data)
1930 struct tinyds_input_method_context *context;
1931 struct tinyds_text_input *text_input;
1932 struct ds_tizen_input_method_context_event_keysym *event = data;
1934 context = wl_container_of(listener, context, im_context_keysym);
1935 text_input = context->server->text_input;
1937 ds_inf("context_handle_keysym. text_input(%p) serial(%u) time(%u) sysm(%u) state(%u) modifiers(%u)",
1938 text_input, event->serial, event->time, event->sym, event->state, event->modifiers);
1940 ds_tizen_text_input_send_keysym(text_input->input, event->serial, event->time, event->sym, event->state, event->modifiers);
1944 context_handle_grab_keyboard(struct wl_listener *listener, void *data)
1946 struct tinyds_input_method_context *context;
1947 struct tinyds_text_input *text_input;
1949 context = wl_container_of(listener, context, im_context_grab_keyboard);
1950 text_input = context->server->text_input;
1952 ds_inf("context_handle_grab_keyboard. text_input(%p)",
1959 context_handle_key(struct wl_listener *listener, void *data)
1961 struct tinyds_input_method_context *context;
1962 struct tinyds_text_input *text_input;
1964 context = wl_container_of(listener, context, im_context_key);
1965 text_input = context->server->text_input;
1967 ds_inf("context_handle_key. text_input(%p)",
1974 context_handle_modifiers(struct wl_listener *listener, void *data)
1976 struct tinyds_input_method_context *context;
1977 struct tinyds_text_input *text_input;
1979 context = wl_container_of(listener, context, im_context_modifiers);
1980 text_input = context->server->text_input;
1982 ds_inf("context_handle_modifiers. text_input(%p)",
1989 context_handle_language(struct wl_listener *listener, void *data)
1991 struct tinyds_input_method_context *context;
1992 struct tinyds_text_input *text_input;
1993 struct ds_tizen_input_method_context_event_language *event = data;
1995 context = wl_container_of(listener, context, im_context_language);
1996 text_input = context->server->text_input;
1998 ds_inf("context_handle_language. text_input(%p) serial(%u), language(%s)",
1999 text_input, event->serial, event->language);
2001 ds_tizen_text_input_send_language(text_input->input, event->serial, event->language);
2005 context_handle_text_direction(struct wl_listener *listener, void *data)
2007 struct tinyds_input_method_context *context;
2008 struct tinyds_text_input *text_input;
2009 struct ds_tizen_input_method_context_event_text_direction *event = data;
2011 context = wl_container_of(listener, context, im_context_text_direction);
2012 text_input = context->server->text_input;
2014 ds_inf("context_handle_text_direction. text_input(%p) serial(%u), direction(%u)",
2015 text_input, event->serial, event->direction);
2017 ds_tizen_text_input_send_text_direction(text_input->input, event->serial, event->direction);
2021 add_new_text_input(struct tinyds_server *server)
2023 struct tinyds_text_input *text_input;
2025 text_input = calloc(1, sizeof *text_input);
2029 text_input->text_input_mgr = ds_tizen_text_input_manager_create(server->display);
2030 if (!text_input->text_input_mgr) {
2032 ds_err("Could not create ds_tizen_text_input_manager");
2036 wl_list_init(&text_input->input_methods);
2038 text_input->mgr_destroy.notify = text_input_mgr_handle_destroy;
2039 ds_tizen_text_input_manager_add_destroy_listener(text_input->text_input_mgr,
2040 &text_input->mgr_destroy);
2042 text_input->new_text_input.notify = text_input_mgr_handle_new_text_input;
2043 ds_tizen_text_input_manager_add_new_text_input_listener(text_input->text_input_mgr,
2044 &text_input->new_text_input);
2046 text_input->server = server;
2047 server->text_input = text_input;
2049 ds_inf("Text_Input (%p) added", text_input);
2055 add_new_input_method(struct tinyds_server *server)
2057 struct tinyds_input_method *input_method;
2059 input_method = calloc(1, sizeof *input_method);
2063 input_method->input_method = ds_tizen_input_method_create(server->display);
2064 if (!input_method->input_method) {
2066 ds_err("Could not create ds_tizen_input_method");
2069 input_method->destroy.notify = input_method_handle_destroy;
2070 ds_tizen_input_method_add_destroy_listener(input_method->input_method,
2071 &input_method->destroy);
2073 input_method->input_method_mgr = ds_tizen_input_method_manager_create(server->display);
2074 if (!input_method->input_method_mgr) {
2076 ds_err("Could not create ds_tizen_input_method_manager");
2080 input_method->mgr_destroy.notify = input_method_mgr_handle_destroy;
2081 ds_tizen_input_method_manager_add_destroy_listener(input_method->input_method_mgr,
2082 &input_method->mgr_destroy);
2084 input_method->server = server;
2085 server->input_method = input_method;
2087 ds_inf("Input_Method (%p) added", input_method);
2093 add_new_input_method_context(struct tinyds_input_method *input_method,
2094 struct tinyds_text_input *text_input)
2096 struct tinyds_input_method_context *context;
2098 context = calloc(1, sizeof *context);
2099 if (context == NULL)
2101 ds_err("calloc is failed. tinyds_input_method_context");
2104 input_method->context = context;
2105 context->input_method = input_method;
2106 context->server = input_method->server;
2107 context->input = text_input;
2109 context->context = ds_tizen_input_method_create_context(input_method->input_method);
2110 if (context->context == NULL) {
2111 ds_err("ds_tizen_input_method_create_context() failed.");
2115 context->destroy.notify = context_handle_destroy;
2116 ds_tizen_input_method_context_add_destroy_listener(context->context,
2119 context->im_context_commit_string.notify = context_handle_commit_string;
2120 ds_tizen_input_method_context_add_commit_string_listener(context->context,
2121 &context->im_context_commit_string);
2123 context->im_context_preedit_string.notify = context_handle_preedit_string;
2124 ds_tizen_input_method_context_add_preedit_string_listener(context->context,
2125 &context->im_context_preedit_string);
2127 context->im_context_preedit_styling.notify = context_handle_preedit_styling;
2128 ds_tizen_input_method_context_add_preedit_styling_listener(context->context,
2129 &context->im_context_preedit_styling);
2131 context->im_context_preedit_cursor.notify = context_handle_preedit_cursor;
2132 ds_tizen_input_method_context_add_preedit_cursor_listener(context->context,
2133 &context->im_context_preedit_cursor);
2135 context->im_context_delete_surrounding_text.notify = context_handle_delete_surrounding_text;
2136 ds_tizen_input_method_context_add_delete_surrounding_text_listener(context->context,
2137 &context->im_context_delete_surrounding_text);
2139 context->im_context_cursor_position.notify = context_handle_cursor_position;
2140 ds_tizen_input_method_context_add_cursor_position_listener(context->context,
2141 &context->im_context_cursor_position);
2143 context->im_context_modifiers_map.notify = context_handle_modifiers_map;
2144 ds_tizen_input_method_context_add_modifiers_map_listener(context->context,
2145 &context->im_context_modifiers_map);
2147 context->im_context_keysym.notify = context_handle_keysym;
2148 ds_tizen_input_method_context_add_keysym_listener(context->context,
2149 &context->im_context_keysym);
2151 context->im_context_grab_keyboard.notify = context_handle_grab_keyboard;
2152 ds_tizen_input_method_context_add_grab_keyboard_listener(context->context,
2153 &context->im_context_grab_keyboard);
2155 context->im_context_key.notify = context_handle_key;
2156 ds_tizen_input_method_context_add_key_listener(context->context,
2157 &context->im_context_key);
2159 context->im_context_modifiers.notify = context_handle_modifiers;
2160 ds_tizen_input_method_context_add_modifiers_listener(context->context,
2161 &context->im_context_modifiers);
2163 context->im_context_language.notify = context_handle_language;
2164 ds_tizen_input_method_context_add_language_listener(context->context,
2165 &context->im_context_language);
2167 context->im_context_text_direction.notify = context_handle_text_direction;
2168 ds_tizen_input_method_context_add_text_direction_listener(context->context,
2169 &context->im_context_text_direction);
2174 struct tinyds_view *
2175 tinyds_server_get_focused_view(struct tinyds_server *server)
2177 struct tinyds_view *view = NULL;
2178 struct tinyds_pointer *pointer;
2180 wl_list_for_each(pointer, &server->pointers, link){
2181 if (!pointer->focused_view) continue;
2183 view = pointer->focused_view;
2190 tinyds_server_get_output_size(struct tinyds_server *server,
2191 int *output_w, int *output_h)
2193 *output_w = server->output->width;
2194 *output_h = server->output->height;