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 < (size_t)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) {
811 composition = ds_tdm_output_hwc_window_get_composition(view->hwc_window);
812 if ((composition == DS_TDM_OUTPUT_HWC_WINDOW_COMPOSITION_DEVICE) ||
813 (composition == DS_TDM_OUTPUT_HWC_WINDOW_COMPOSITION_VIDEO) ||
814 (composition == DS_TDM_OUTPUT_HWC_WINDOW_COMPOSITION_CURSOR))
815 view_send_frame_done(view);
818 ds_dbg("output:%p commit", output);
822 output_handle_frame(struct wl_listener *listener, void *data TINYDS_UNUSED)
824 struct tinyds_output *output =
825 wl_container_of(listener, output, output_frame);
827 ds_dbg("output:%p handle frame", output);
829 output->committable = true;
831 output_commit(output);
835 draw_server_with_damage(struct tinyds_server *server)
837 server->output->damaged = true;
838 output_schedule_commit(server->output);
842 output_hwc_init(struct tinyds_output *output)
844 struct ds_tdm_output *tdm_output;
846 tdm_output = ds_tdm_output_from_output(output->ds_output);
849 output->hwc = ds_tdm_output_get_hwc(tdm_output);
852 ds_tdm_output_hwc_set_enabled(output->hwc, true);
855 #ifdef USE_TDM_BUFFER_QUEUE
857 output_handle_buffer_queue_acquirable(struct wl_listener *listener,
858 void *data TINYDS_UNUSED)
860 struct tinyds_output *output;
862 output = wl_container_of(listener, output, buffer_queue_acquirable);
864 output->target_updated = true;
865 output_schedule_commit(output);
869 output_buffer_queue_init(struct tinyds_output *output)
871 struct ds_tdm_output *tdm_output;
873 tdm_output = ds_tdm_output_from_output(output->ds_output);
876 output->buffer_queue = ds_tdm_output_get_buffer_queue(tdm_output);
877 assert(output->buffer_queue);
879 output->buffer_queue_acquirable.notify =
880 output_handle_buffer_queue_acquirable;
881 ds_tdm_buffer_queue_add_acquirable_listener(output->buffer_queue,
882 &output->buffer_queue_acquirable);
886 output_renderer_init(struct tinyds_output *output)
888 init_renderer(&output->renderer);
890 renderer_set_surface_queue(&output->renderer,
891 ds_tdm_buffer_queue_get_native_queue(output->buffer_queue));
893 renderer_set_bg_color(&output->renderer, 80, 80, 80);
897 output_draw_with_renderer(struct tinyds_output *output)
899 struct tinyds_view *view;
901 ds_dbg(">> BEGIN UPDATE TEXTURES");
903 wl_list_for_each(view, &output->server->views, link) {
904 struct ds_buffer *ds_buffer;
905 struct ds_tbm_client_buffer *tbm_buffer;
906 tbm_surface_h surface;
907 enum ds_tdm_output_hwc_window_composition composition;
912 composition = ds_tdm_output_hwc_window_get_composition(view->hwc_window);
913 if ((composition == DS_TDM_OUTPUT_HWC_WINDOW_COMPOSITION_DEVICE) ||
914 (composition == DS_TDM_OUTPUT_HWC_WINDOW_COMPOSITION_VIDEO) ||
915 (composition == DS_TDM_OUTPUT_HWC_WINDOW_COMPOSITION_CURSOR))
918 ds_buffer = ds_surface_get_buffer(
919 ds_xdg_surface_get_surface(view->xdg_surface));
923 tbm_buffer = ds_tbm_client_buffer_from_buffer(ds_buffer);
927 surface = ds_tbm_client_buffer_get_tbm_surface(tbm_buffer);
931 renderer_add_texture(&output->renderer, surface, view->x, view->y);
933 view_send_frame_done(view);
936 ds_dbg("<< END UPDATE TEXTURES");
938 renderer_draw(&output->renderer);
942 output_swapchain_init(struct tinyds_output *output,
943 int width, int height, uint32_t format)
946 output->allocator = ds_tbm_allocator_create();
947 assert(output->allocator);
949 output->swapchain = ds_swapchain_create(output->allocator,
950 width, height, format);
951 assert(output->swapchain);
955 output_draw_with_swapchain(struct tinyds_output *output)
957 struct tinyds_view *view;
958 struct ds_buffer *output_buffer;
959 pixman_image_t *output_image;
960 enum ds_tdm_output_hwc_window_composition composition;
962 output_buffer = ds_swapchain_acquire(output->swapchain, NULL);
966 output_image = pixman_image_from_buffer(output_buffer,
967 DS_BUFFER_DATA_PTR_ACCESS_WRITE);
969 ds_buffer_unlock(output_buffer);
973 pixman_image_fill_color(output_image, 80, 80, 80);
975 wl_list_for_each(view, &output->server->views, link) {
979 composition = ds_tdm_output_hwc_window_get_composition(view->hwc_window);
980 if ((composition == DS_TDM_OUTPUT_HWC_WINDOW_COMPOSITION_DEVICE) ||
981 (composition == DS_TDM_OUTPUT_HWC_WINDOW_COMPOSITION_VIDEO) ||
982 (composition == DS_TDM_OUTPUT_HWC_WINDOW_COMPOSITION_CURSOR))
985 draw_view(view, output_image);
987 pixman_image_unref(output_image);
989 if (!ds_tdm_output_hwc_set_client_target_buffer(output->hwc, output_buffer)) {
990 ds_err("Could not set hwc client target buffer");
991 ds_buffer_unlock(output_buffer);
995 output_swap_buffer(output, output_buffer);
999 draw_view(struct tinyds_view *view, pixman_image_t *dst_image)
1001 struct ds_buffer *buffer;
1002 pixman_image_t *src_image;
1004 buffer = ds_surface_get_buffer(
1005 ds_xdg_surface_get_surface(view->xdg_surface));
1009 src_image = pixman_image_from_buffer(buffer,
1010 DS_BUFFER_DATA_PTR_ACCESS_READ);
1011 pixman_image_composite32(PIXMAN_OP_OVER,
1017 pixman_image_get_width(src_image),
1018 pixman_image_get_height(src_image));
1019 pixman_image_unref(src_image);
1021 view_send_frame_done(view);
1026 draw_output(struct tinyds_output *output)
1028 #ifdef USE_TDM_BUFFER_QUEUE
1029 output_draw_with_renderer(output);
1031 output_draw_with_swapchain(output);
1034 ds_dbg("output:%p draw", output);
1038 output_swap_buffer(struct tinyds_output *output, struct ds_buffer *buffer)
1040 ds_output_attach_buffer(output->ds_output, buffer);
1042 if (output->front_buffer)
1043 ds_buffer_unlock(output->front_buffer);
1044 output->front_buffer = buffer;
1048 view_send_frame_done(struct tinyds_view *view)
1050 struct timespec now;
1051 clock_gettime(CLOCK_MONOTONIC, &now);
1052 ds_surface_send_frame_done(ds_xdg_surface_get_surface(view->xdg_surface),
1057 server_dispatch_stdin(int fd, uint32_t mask, void *data)
1059 struct tinyds_server *server = data;
1061 wl_display_terminate(server->display);
1067 keyboard_handle_device_destroy(struct wl_listener *listener, void *data)
1069 struct tinyds_keyboard *kbd;
1071 kbd = wl_container_of(listener, kbd, destroy);
1073 ds_inf("Keyboard(%p) destroyed", kbd);
1075 wl_list_remove(&kbd->destroy.link);
1076 wl_list_remove(&kbd->key.link);
1077 wl_list_remove(&kbd->link);
1083 server_handle_keybinding(struct tinyds_server *server, xkb_keysym_t sym)
1086 case XKB_KEY_BackSpace:
1087 wl_display_terminate(server->display);
1097 keyboard_handle_key(struct wl_listener *listener, void *data)
1099 struct tinyds_keyboard *kbd;
1100 struct ds_keyboard_event_key *event = data;
1101 struct ds_keyboard *ds_keyboard;
1102 struct xkb_state *xkb_state;
1103 const xkb_keysym_t *syms;
1105 bool handled = false;
1107 kbd = wl_container_of(listener, kbd, key);
1109 ds_inf("Keyboard(%p) event key: keycode(%d), state(%d), time_msec(%d), "
1110 "update_state(%d)", kbd->dev,
1111 event->keycode, event->state, event->time_msec,
1112 event->update_state);
1114 ds_keyboard = ds_input_device_get_keyboard(kbd->dev);
1116 if (event->state == WL_KEYBOARD_KEY_STATE_PRESSED) {
1117 xkb_state = ds_keyboard_get_xkb_state(ds_keyboard);
1119 nsyms = xkb_state_key_get_syms(xkb_state, event->keycode + 8,
1121 for (int i = 0; i < nsyms; i++) {
1122 handled = server_handle_keybinding(kbd->server, syms[i]);
1128 ds_seat_keyboard_notify_key(kbd->server->seat, event->time_msec,
1129 event->keycode, event->state);
1134 server_add_keyboard(struct tinyds_server *server, struct ds_input_device *dev)
1136 struct tinyds_keyboard *kbd;
1137 struct xkb_context *context;
1138 struct xkb_keymap *keymap;
1140 kbd = calloc(1, sizeof *kbd);
1144 kbd->server = server;
1146 context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
1150 keymap = xkb_keymap_new_from_names(context, NULL,
1151 XKB_KEYMAP_COMPILE_NO_FLAGS);
1154 ds_err("Failed to compile keymap");
1155 xkb_context_unref(context);
1159 ds_keyboard_set_keymap(ds_input_device_get_keyboard(dev), keymap);
1161 xkb_keymap_unref(keymap);
1162 xkb_context_unref(context);
1164 kbd->destroy.notify = keyboard_handle_device_destroy;
1165 ds_input_device_add_destroy_listener(dev, &kbd->destroy);
1167 kbd->key.notify = keyboard_handle_key;
1168 ds_keyboard_add_key_listener(ds_input_device_get_keyboard(dev), &kbd->key);
1170 wl_list_insert(&server->keyboards, &kbd->link);
1172 ds_inf("Keyboard(%p) added", kbd);
1180 struct tinyds_view *
1181 tinyds_server_view_at(struct tinyds_server *server, double lx, double ly,
1182 double *sx, double *sy)
1184 struct tinyds_view *view;
1185 struct ds_surface *surface;
1186 struct ds_buffer *buffer;
1187 int x, y, w = 0, h = 0;
1189 wl_list_for_each(view, &server->views, link) {
1190 surface = ds_xdg_surface_get_surface(view->xdg_surface);
1191 buffer = ds_surface_get_buffer(surface);
1192 ds_buffer_get_size(buffer, &w, &h);
1197 if (lx >= x && lx <= x + w && ly >= y && ly <= y + h) {
1209 touch_handle_device_destroy(struct wl_listener *listener, void *data)
1211 struct tinyds_touch *touch;
1213 touch = wl_container_of(listener, touch, destroy);
1215 ds_inf("Touch(%p) destroyed", touch);
1217 wl_list_remove(&touch->destroy.link);
1218 wl_list_remove(&touch->down.link);
1219 wl_list_remove(&touch->up.link);
1220 wl_list_remove(&touch->motion.link);
1226 touch_handle_down(struct wl_listener *listener, void *data)
1228 struct ds_touch_event_down *event = data;
1229 struct tinyds_touch *touch;
1230 struct tinyds_view *view;
1231 struct tinyds_server *server;
1232 double sx = 0.f, sy = 0.f;
1234 touch = wl_container_of(listener, touch, down);
1236 server = touch->server;
1237 if (server->output) {
1238 server->output_x = event->x * server->output->width;
1239 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_touch_event_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_touch_event_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 if (server->output) {
1287 server->output_x = event->x * server->output->width;
1288 server->output_y = event->y * server->output->height;
1291 ds_inf("Touch(%p) event motion: id(%d) x %.3f y %.3f output_x %.1f output_y %.1f",
1292 touch->dev, event->id, event->x, event->y, server->output_x, server->output_y);
1294 view = tinyds_server_view_at(server, server->output_x, server->output_y, &sx, &sy);
1297 ds_seat_touch_notify_motion(server->seat, event->time_msec,
1302 if (server->output && server->output->cursor_enabled) {
1303 renderer_cursor_update(&server->output->renderer, server->output_x, server->output_y);
1304 draw_server_with_damage(server);
1310 server_add_touch(struct tinyds_server *server, struct ds_input_device *dev)
1312 struct tinyds_touch *touch;
1314 touch = calloc(1, sizeof *touch);
1318 touch->server = server;
1320 touch->destroy.notify = touch_handle_device_destroy;
1321 ds_input_device_add_destroy_listener(dev, &touch->destroy);
1323 touch->down.notify = touch_handle_down;
1324 ds_touch_add_down_listener(ds_input_device_get_touch(dev), &touch->down);
1326 touch->up.notify = touch_handle_up;
1327 ds_touch_add_up_listener(ds_input_device_get_touch(dev), &touch->up);
1329 touch->motion.notify = touch_handle_motion;
1330 ds_touch_add_motion_listener(ds_input_device_get_touch(dev), &touch->motion);
1332 ds_inf("Touch(%p) added", touch);
1336 pointer_handle_device_destroy(struct wl_listener *listener, void *data)
1338 struct tinyds_pointer *pointer;
1339 struct tinyds_server *server;
1341 pointer = wl_container_of(listener, pointer, destroy);
1343 ds_inf("Pointer(%p) destroyed", pointer);
1345 wl_list_remove(&pointer->destroy.link);
1346 wl_list_remove(&pointer->motion.link);
1347 wl_list_remove(&pointer->button.link);
1348 wl_list_remove(&pointer->frame.link);
1349 wl_list_remove(&pointer->link);
1352 server = pointer->server;
1353 if (server->output && wl_list_empty(&server->pointers))
1355 server->output->cursor_enabled = false;
1356 renderer_cursor_destroy(&server->output->renderer);
1358 if (server->output->cursor_hwc_window)
1360 ds_tdm_output_hwc_window_destroy(server->output->cursor_hwc_window);
1361 server->output->cursor_hwc_window = NULL;
1363 draw_server_with_damage(server);
1371 pointer_handle_motion(struct wl_listener *listener, void *data)
1373 struct tinyds_pointer *pointer;
1374 struct ds_pointer_event_motion *event = data;
1375 struct tinyds_view *view;
1376 struct tinyds_server *server;
1380 pointer = wl_container_of(listener, pointer, motion);
1382 server = pointer->server;
1383 if (server->output) {
1384 ow = server->output->width;
1385 oh = server->output->height;
1388 if (server->output_x + event->delta_x >= ow)
1389 server->output_x = ow;
1390 else if(server->output_x + event->delta_x <= 0.f)
1391 server->output_x = 0.f;
1393 server->output_x = server->output_x + event->delta_x ;
1394 if (server->output_y + event->delta_y >= oh)
1395 server->output_y = oh;
1396 else if(server->output_y + event->delta_y <= 0.f)
1397 server->output_y = 0.f;
1399 server->output_y = server->output_y + event->delta_y ;
1401 ds_inf("Pointer(%p) motion: (delta_x %.1f delta_y %.1f) output_x %.1f output_y %.1f",
1402 pointer, event->delta_x, event->delta_y, server->output_x, server->output_y);
1404 view = tinyds_server_view_at(pointer->server, server->output_x, server->output_y, &sx, &sy);
1406 if (pointer->focused_view != view) {
1407 if (pointer->focused_view) {
1408 ds_inf("Clear pointer focus from view(%p)", pointer->focused_view);
1409 ds_seat_pointer_notify_clear_focus(pointer->server->seat);
1410 pointer->focused_view = NULL;
1414 ds_inf("Set pointer focus to view(%p)", view);
1415 ds_seat_pointer_notify_enter(pointer->server->seat,
1416 ds_xdg_surface_get_surface(view->xdg_surface), sx, sy);
1417 pointer->focused_view = view;
1422 ds_seat_pointer_notify_motion(pointer->server->seat,
1423 event->time_msec, sx, sy);
1427 if (server->output && server->output->cursor_enabled) {
1428 renderer_cursor_update(&server->output->renderer, server->output_x, server->output_y);
1429 draw_server_with_damage(server);
1435 pointer_handle_button(struct wl_listener *listener, void *data)
1437 struct tinyds_pointer *pointer;
1438 struct ds_pointer_event_button *event = data;
1440 pointer = wl_container_of(listener, pointer, button);
1442 ds_inf("Pointer(%p) button(%d): state(%s) time(%d)",
1443 pointer, event->button,
1444 (event->state == DS_BUTTON_PRESSED) ? "Pressed" : "Released",
1447 ds_seat_pointer_notify_button(pointer->server->seat, event->time_msec, event->button, event->state);
1451 pointer_handle_frame(struct wl_listener *listener, void *data)
1453 struct tinyds_pointer *pointer;
1455 pointer = wl_container_of(listener, pointer, frame);
1457 ds_inf("Pointer(%p) frame", pointer);
1458 ds_seat_pointer_notify_frame(pointer->server->seat);
1462 server_add_pointer(struct tinyds_server *server, struct ds_input_device *dev)
1464 struct tinyds_pointer *pointer;
1466 pointer = calloc(1, sizeof *pointer);
1470 pointer->server = server;
1472 pointer->destroy.notify = pointer_handle_device_destroy;
1473 ds_input_device_add_destroy_listener(dev, &pointer->destroy);
1475 pointer->motion.notify = pointer_handle_motion;
1476 ds_pointer_add_motion_listener(ds_input_device_get_pointer(dev),
1479 pointer->button.notify = pointer_handle_button;
1480 ds_pointer_add_button_listener(ds_input_device_get_pointer(dev),
1483 pointer->frame.notify = pointer_handle_frame;
1484 ds_pointer_add_frame_listener(ds_input_device_get_pointer(dev),
1487 pointer->focused_view = NULL;
1490 if (server->output && wl_list_empty(&server->pointers)) {
1491 server->output_x = (double)(server->output->width) / 2;
1492 server->output_y = (double)(server->output->height) / 2;
1494 server->output->cursor_enabled = true;
1495 renderer_cursor_create(&server->output->renderer, 255, 0, 0, CURSOR_W, CURSOR_H);
1496 renderer_cursor_update(&server->output->renderer, server->output_x, server->output_y);
1498 server->output->cursor_hwc_window = ds_tdm_output_hwc_window_create(server->output->hwc);
1499 assert(server->output->cursor_hwc_window);
1500 draw_server_with_damage(server);
1504 wl_list_insert(&server->pointers, &pointer->link);
1506 ds_inf("Pointer(%p) added", pointer);
1510 output_schedule_commit_handle_idle_timer(void *data)
1512 struct tinyds_output *output = data;
1513 output->idle_commit = NULL;
1515 output_commit(output);
1519 output_schedule_commit(struct tinyds_output *output)
1521 if (output->idle_commit)
1524 struct wl_event_loop *ev = wl_display_get_event_loop(output->server->display);
1525 output->idle_commit =
1526 wl_event_loop_add_idle(ev, output_schedule_commit_handle_idle_timer, output);
1530 text_input_mgr_handle_destroy(struct wl_listener *listener, void *data)
1532 struct tinyds_text_input *text_input;
1533 struct tinyds_server *server;
1535 ds_inf("text_input_mgr_handle_destroy");
1536 text_input = wl_container_of(listener, text_input, mgr_destroy);
1538 wl_list_remove(&text_input->mgr_destroy.link);
1539 wl_list_remove(&text_input->new_text_input.link);
1541 server = text_input->server;
1542 server->text_input = NULL;
1546 text_input_handle_destroy(struct wl_listener *listener, void *data)
1548 struct tinyds_text_input *text_input;
1550 ds_inf("text_input_handle_destroy");
1552 text_input = wl_container_of(listener, text_input, destroy);
1554 wl_list_remove(&text_input->destroy.link);
1555 wl_list_remove(&text_input->text_input_activate.link);
1556 wl_list_remove(&text_input->text_input_deactivate.link);
1557 wl_list_remove(&text_input->text_input_reset.link);
1558 wl_list_remove(&text_input->text_input_set_content_type.link);
1559 wl_list_remove(&text_input->text_input_invoke_action.link);
1560 wl_list_remove(&text_input->text_input_commit_state.link);
1561 wl_list_remove(&text_input->text_input_set_preferred_language.link);
1567 text_input_handle_activate(struct wl_listener *listener, void *data)
1569 struct tinyds_text_input *text_input;
1570 struct tinyds_input_method *input_method;
1571 struct ds_tizen_text_input_event_activate *event = data;
1573 text_input = wl_container_of(listener, text_input, text_input_activate);
1575 input_method = text_input->server->input_method;
1577 ds_inf("text_input_handle_activate. text_input(%p) seat(%p) surface(%p) text_input(%p)",
1578 text_input, event->seat, event->surface, event->text_input);
1580 if (input_method->input == text_input)
1582 if (input_method->input)
1583 ;//deactivate_input_method(server->input_method);
1584 input_method->input = text_input;
1585 wl_list_insert(&text_input->input_methods, &input_method->link);
1587 text_input->surface = event->surface;
1589 if (!add_new_input_method_context(input_method, text_input))
1592 // ds_tizen_input_method_send_set_text_input_id();
1596 text_input_handle_deactivate(struct wl_listener *listener, void *data)
1598 struct tinyds_text_input *text_input;
1599 struct tinyds_input_method *input_method, *tmp;
1600 struct ds_tizen_text_input_event_deactivate *event = data;
1602 text_input = wl_container_of(listener, text_input, text_input_deactivate);
1603 ds_inf("text_input_handle_deactivate. text_input(%p) seat(%p) text_input(%p)",
1604 text_input, event->seat, event->text_input);
1606 wl_list_for_each_safe(input_method, tmp, &text_input->input_methods, link) {
1607 if (!input_method->input_method || !input_method->context->context) continue;
1608 ds_tizen_input_method_send_deactivate(input_method->input_method, input_method->context->context);
1609 input_method->input = NULL;
1610 input_method->context = NULL;
1611 wl_list_remove(&input_method->link);
1614 text_input->surface = NULL;
1615 // ds_tizen_input_method_send_close_connection();
1619 text_input_handle_reset(struct wl_listener *listener, void *data)
1621 struct tinyds_text_input *text_input;
1622 struct tinyds_input_method *input_method;
1624 text_input = wl_container_of(listener, text_input, text_input_reset);
1626 ds_inf("text_input_handle_reset. text_input(%p)", text_input);
1628 wl_list_for_each(input_method, &text_input->input_methods, link) {
1629 if (!input_method->context || !input_method->context->context) continue;
1630 ds_tizen_input_method_context_send_reset(input_method->context->context);
1635 text_input_handle_set_content_type(struct wl_listener *listener, void *data)
1637 struct tinyds_text_input *text_input;
1638 struct ds_tizen_text_input_event_set_content_type *event = data;
1639 struct tinyds_input_method *input_method;
1641 text_input = wl_container_of(listener, text_input, text_input_set_content_type);
1643 ds_inf("text_input_handle_content_type. text_input(%p) hint(%u) purpose(%u)",
1644 text_input, event->hint, event->purpose);
1646 wl_list_for_each(input_method, &text_input->input_methods, link) {
1647 if (!input_method->context || !input_method->context->context) continue;
1648 ds_tizen_input_method_context_send_content_type(input_method->context->context,
1649 event->hint, event->purpose);
1654 text_input_handle_invoke_action(struct wl_listener *listener, void *data)
1656 struct tinyds_text_input *text_input;
1657 struct ds_tizen_text_input_event_invoke_action *event = data;
1658 struct tinyds_input_method *input_method;
1660 text_input = wl_container_of(listener, text_input, text_input_invoke_action);
1662 ds_inf("text_input_handle_invoke_action. text_input(%p) button(%u) index(%u)",
1663 text_input, event->button, event->index);
1665 wl_list_for_each(input_method, &text_input->input_methods, link) {
1666 if (!input_method->context || !input_method->context->context) continue;
1667 ds_tizen_input_method_context_send_invoke_action(input_method->context->context,
1668 event->button, event->index);
1673 text_input_handle_commit_state(struct wl_listener *listener, void *data)
1675 struct tinyds_text_input *text_input;
1676 struct ds_tizen_text_input_event_commit_state *event = data;
1677 struct tinyds_input_method *input_method;
1679 text_input = wl_container_of(listener, text_input, text_input_commit_state);
1681 ds_inf("text_input_handle_commit_state. text_input(%p) serial(%u)",
1682 text_input, event->serial);
1684 wl_list_for_each(input_method, &text_input->input_methods, link) {
1685 if (!input_method->context || !input_method->context->context) continue;
1686 ds_tizen_input_method_context_send_commit_state(input_method->context->context,
1692 text_input_handle_set_preferred_language(struct wl_listener *listener, void *data)
1694 struct tinyds_text_input *text_input;
1695 struct ds_tizen_text_input_event_set_preferred_language *event = data;
1696 struct tinyds_input_method *input_method;
1698 text_input = wl_container_of(listener, text_input, text_input_set_preferred_language);
1700 ds_inf("text_input_handle_set_preferred_language. text_input(%p) language(%s)",
1701 text_input, event->language);
1703 wl_list_for_each(input_method, &text_input->input_methods, link) {
1704 if (!input_method->context || !input_method->context->context) continue;
1705 ds_tizen_input_method_context_send_preferred_language(input_method->context->context,
1711 text_input_mgr_handle_new_text_input(struct wl_listener *listener, void *data)
1713 struct tinyds_text_input *text_input;
1714 struct ds_tizen_text_input *input = data;
1716 text_input = wl_container_of(listener, text_input, new_text_input);
1718 ds_inf("text_input_mgr_handle_new_text_input");
1720 text_input->input = input;
1722 text_input->destroy.notify = text_input_handle_destroy;
1723 ds_tizen_text_input_add_destroy_listener(text_input->input,
1724 &text_input->destroy);
1726 text_input->text_input_activate.notify = text_input_handle_activate;
1727 ds_tizen_text_input_add_activate_listener(text_input->input,
1728 &text_input->text_input_activate);
1730 text_input->text_input_deactivate.notify = text_input_handle_deactivate;
1731 ds_tizen_text_input_add_deactivate_listener(text_input->input,
1732 &text_input->text_input_deactivate);
1734 text_input->text_input_reset.notify = text_input_handle_reset;
1735 ds_tizen_text_input_add_reset_listener(text_input->input,
1736 &text_input->text_input_reset);
1738 text_input->text_input_set_content_type.notify = text_input_handle_set_content_type;
1739 ds_tizen_text_input_add_set_content_type_listener(text_input->input,
1740 &text_input->text_input_set_content_type);
1742 text_input->text_input_invoke_action.notify = text_input_handle_invoke_action;
1743 ds_tizen_text_input_add_invoke_action_listener(text_input->input,
1744 &text_input->text_input_invoke_action);
1746 text_input->text_input_commit_state.notify = text_input_handle_commit_state;
1747 ds_tizen_text_input_add_commit_state_listener(text_input->input,
1748 &text_input->text_input_commit_state);
1750 text_input->text_input_set_preferred_language.notify = text_input_handle_set_preferred_language;
1751 ds_tizen_text_input_add_set_preferred_language_listener(text_input->input,
1752 &text_input->text_input_set_preferred_language);
1756 input_method_mgr_handle_destroy(struct wl_listener *listener, void *data)
1758 struct tinyds_input_method *input_method;
1760 ds_inf("input_method_mgr_handle_destroy");
1762 input_method = wl_container_of(listener, input_method, mgr_destroy);
1764 wl_list_remove(&input_method->mgr_destroy.link);
1768 input_method_handle_destroy(struct wl_listener *listener, void *data)
1770 struct tinyds_input_method *input_method;
1771 struct tinyds_server *server;
1773 ds_inf("input_method_handle_destroy");
1775 input_method = wl_container_of(listener, input_method, destroy);
1777 wl_list_remove(&input_method->destroy.link);
1779 server = input_method->server;
1780 server->input_method = NULL;
1786 context_handle_destroy(struct wl_listener *listener, void *data)
1788 struct tinyds_input_method_context *context;
1789 struct tinyds_server *server;
1791 ds_inf("context_handle_destroy");
1793 context = wl_container_of(listener, context, destroy);
1795 wl_list_remove(&context->destroy.link);
1797 wl_list_remove(&context->im_context_commit_string.link);
1798 wl_list_remove(&context->im_context_preedit_string.link);
1799 wl_list_remove(&context->im_context_preedit_styling.link);
1800 wl_list_remove(&context->im_context_preedit_cursor.link);
1801 wl_list_remove(&context->im_context_delete_surrounding_text.link);
1802 wl_list_remove(&context->im_context_cursor_position.link);
1803 wl_list_remove(&context->im_context_modifiers_map.link);
1804 wl_list_remove(&context->im_context_keysym.link);
1805 wl_list_remove(&context->im_context_grab_keyboard.link);
1806 wl_list_remove(&context->im_context_key.link);
1807 wl_list_remove(&context->im_context_modifiers.link);
1808 wl_list_remove(&context->im_context_language.link);
1809 wl_list_remove(&context->im_context_text_direction.link);
1811 server = context->server;
1812 server->input_method->context = NULL;
1818 context_handle_commit_string(struct wl_listener *listener, void *data)
1820 struct tinyds_text_input *text_input;
1821 struct tinyds_input_method_context *context;
1822 struct ds_tizen_input_method_context_event_commit_string *event = data;
1824 context = wl_container_of(listener, context, im_context_commit_string);
1825 text_input = context->server->text_input;
1827 ds_inf("context_handle_commit_string. text_input(%p) serial(%u) text(%s)",
1828 text_input, event->serial, event->text);
1830 ds_tizen_text_input_send_commit_string(text_input->input, event->serial, event->text);
1834 context_handle_preedit_string(struct wl_listener *listener, void *data)
1836 struct tinyds_input_method_context *context;
1837 struct tinyds_text_input *text_input;
1838 struct ds_tizen_input_method_context_event_preedit_string *event = data;
1840 context = wl_container_of(listener, context, im_context_preedit_string);
1841 text_input = context->server->text_input;
1843 ds_inf("context_handle_preedit_string. text_input(%p) serial(%u) text(%s) commit(%s)",
1844 text_input, event->serial, event->text, event->commit);
1846 ds_tizen_text_input_send_preedit_string(text_input->input, event->serial, event->text, event->commit);
1850 context_handle_preedit_styling(struct wl_listener *listener, void *data)
1852 struct tinyds_input_method_context *context;
1853 struct tinyds_text_input *text_input;
1854 struct ds_tizen_input_method_context_event_preedit_styling *event = data;
1856 context = wl_container_of(listener, context, im_context_preedit_styling);
1857 text_input = context->server->text_input;
1859 ds_inf("context_handle_preedit_styling. text_input(%p) index(%u) length(%u) style(%u)",
1860 text_input, event->index, event->length, event->style);
1862 ds_tizen_text_input_send_preedit_styling(text_input->input, event->index, event->length, event->style);
1866 context_handle_preedit_cursor(struct wl_listener *listener, void *data)
1868 struct tinyds_input_method_context *context;
1869 struct tinyds_text_input *text_input;
1870 struct ds_tizen_input_method_context_event_preedit_cursor *event = data;
1872 context = wl_container_of(listener, context, im_context_preedit_cursor);
1873 text_input = context->server->text_input;
1875 ds_inf("context_handle_preedit_cursor. text_input(%p) index(%u)",
1876 text_input, event->index);
1878 ds_tizen_text_input_send_preedit_cursor(text_input->input, event->index);
1882 context_handle_delete_surrounding_text(struct wl_listener *listener, void *data)
1884 struct tinyds_input_method_context *context;
1885 struct tinyds_text_input *text_input;
1886 struct ds_tizen_input_method_context_event_delete_surrounding_text *event = data;
1888 context = wl_container_of(listener, context, im_context_delete_surrounding_text);
1889 text_input = context->server->text_input;
1891 ds_inf("context_handle_delete_surrounding_text. text_input(%p) index(%d) length(%u)",
1892 text_input, event->index, event->length);
1894 ds_tizen_text_input_send_delete_surrounding_text(text_input->input, event->index, event->length);
1898 context_handle_cursor_position(struct wl_listener *listener, void *data)
1900 struct tinyds_input_method_context *context;
1901 struct tinyds_text_input *text_input;
1902 struct ds_tizen_input_method_context_event_cursor_position *event = data;
1904 context = wl_container_of(listener, context, im_context_cursor_position);
1905 text_input = context->server->text_input;
1907 ds_inf("context_handle_cursor_position. text_input(%p) index(%d) length(%d)",
1908 text_input, event->index, event->anchor);
1910 ds_tizen_text_input_send_cursor_position(text_input->input, event->index, event->anchor);
1914 context_handle_modifiers_map(struct wl_listener *listener, void *data)
1916 struct tinyds_input_method_context *context;
1917 struct tinyds_text_input *text_input;
1918 struct ds_tizen_input_method_context_event_modifiers_map *event = data;
1920 context = wl_container_of(listener, context, im_context_modifiers_map);
1921 text_input = context->server->text_input;
1923 ds_inf("context_handle_modifiers_map. text_input(%p) map(%p)",
1924 text_input, event->map);
1926 ds_tizen_text_input_send_modifiers_map(text_input->input, event->map);
1930 context_handle_keysym(struct wl_listener *listener, void *data)
1932 struct tinyds_input_method_context *context;
1933 struct tinyds_text_input *text_input;
1934 struct ds_tizen_input_method_context_event_keysym *event = data;
1936 context = wl_container_of(listener, context, im_context_keysym);
1937 text_input = context->server->text_input;
1939 ds_inf("context_handle_keysym. text_input(%p) serial(%u) time(%u) sysm(%u) state(%u) modifiers(%u)",
1940 text_input, event->serial, event->time, event->sym, event->state, event->modifiers);
1942 ds_tizen_text_input_send_keysym(text_input->input, event->serial, event->time, event->sym, event->state, event->modifiers);
1946 context_handle_grab_keyboard(struct wl_listener *listener, void *data)
1948 struct tinyds_input_method_context *context;
1949 struct tinyds_text_input *text_input;
1951 context = wl_container_of(listener, context, im_context_grab_keyboard);
1952 text_input = context->server->text_input;
1954 ds_inf("context_handle_grab_keyboard. text_input(%p)",
1961 context_handle_key(struct wl_listener *listener, void *data)
1963 struct tinyds_input_method_context *context;
1964 struct tinyds_text_input *text_input;
1966 context = wl_container_of(listener, context, im_context_key);
1967 text_input = context->server->text_input;
1969 ds_inf("context_handle_key. text_input(%p)",
1976 context_handle_modifiers(struct wl_listener *listener, void *data)
1978 struct tinyds_input_method_context *context;
1979 struct tinyds_text_input *text_input;
1981 context = wl_container_of(listener, context, im_context_modifiers);
1982 text_input = context->server->text_input;
1984 ds_inf("context_handle_modifiers. text_input(%p)",
1991 context_handle_language(struct wl_listener *listener, void *data)
1993 struct tinyds_input_method_context *context;
1994 struct tinyds_text_input *text_input;
1995 struct ds_tizen_input_method_context_event_language *event = data;
1997 context = wl_container_of(listener, context, im_context_language);
1998 text_input = context->server->text_input;
2000 ds_inf("context_handle_language. text_input(%p) serial(%u), language(%s)",
2001 text_input, event->serial, event->language);
2003 ds_tizen_text_input_send_language(text_input->input, event->serial, event->language);
2007 context_handle_text_direction(struct wl_listener *listener, void *data)
2009 struct tinyds_input_method_context *context;
2010 struct tinyds_text_input *text_input;
2011 struct ds_tizen_input_method_context_event_text_direction *event = data;
2013 context = wl_container_of(listener, context, im_context_text_direction);
2014 text_input = context->server->text_input;
2016 ds_inf("context_handle_text_direction. text_input(%p) serial(%u), direction(%u)",
2017 text_input, event->serial, event->direction);
2019 ds_tizen_text_input_send_text_direction(text_input->input, event->serial, event->direction);
2023 add_new_text_input(struct tinyds_server *server)
2025 struct tinyds_text_input *text_input;
2027 text_input = calloc(1, sizeof *text_input);
2031 text_input->text_input_mgr = ds_tizen_text_input_manager_create(server->display);
2032 if (!text_input->text_input_mgr) {
2034 ds_err("Could not create ds_tizen_text_input_manager");
2038 wl_list_init(&text_input->input_methods);
2040 text_input->mgr_destroy.notify = text_input_mgr_handle_destroy;
2041 ds_tizen_text_input_manager_add_destroy_listener(text_input->text_input_mgr,
2042 &text_input->mgr_destroy);
2044 text_input->new_text_input.notify = text_input_mgr_handle_new_text_input;
2045 ds_tizen_text_input_manager_add_new_text_input_listener(text_input->text_input_mgr,
2046 &text_input->new_text_input);
2048 text_input->server = server;
2049 server->text_input = text_input;
2051 ds_inf("Text_Input (%p) added", text_input);
2057 add_new_input_method(struct tinyds_server *server)
2059 struct tinyds_input_method *input_method;
2061 input_method = calloc(1, sizeof *input_method);
2065 input_method->input_method = ds_tizen_input_method_create(server->display);
2066 if (!input_method->input_method) {
2068 ds_err("Could not create ds_tizen_input_method");
2071 input_method->destroy.notify = input_method_handle_destroy;
2072 ds_tizen_input_method_add_destroy_listener(input_method->input_method,
2073 &input_method->destroy);
2075 input_method->input_method_mgr = ds_tizen_input_method_manager_create(server->display);
2076 if (!input_method->input_method_mgr) {
2078 ds_err("Could not create ds_tizen_input_method_manager");
2082 input_method->mgr_destroy.notify = input_method_mgr_handle_destroy;
2083 ds_tizen_input_method_manager_add_destroy_listener(input_method->input_method_mgr,
2084 &input_method->mgr_destroy);
2086 input_method->server = server;
2087 server->input_method = input_method;
2089 ds_inf("Input_Method (%p) added", input_method);
2095 add_new_input_method_context(struct tinyds_input_method *input_method,
2096 struct tinyds_text_input *text_input)
2098 struct tinyds_input_method_context *context;
2100 context = calloc(1, sizeof *context);
2101 if (context == NULL)
2103 ds_err("calloc is failed. tinyds_input_method_context");
2106 input_method->context = context;
2107 context->input_method = input_method;
2108 context->server = input_method->server;
2109 context->input = text_input;
2111 context->context = ds_tizen_input_method_create_context(input_method->input_method);
2112 if (context->context == NULL) {
2113 ds_err("ds_tizen_input_method_create_context() failed.");
2117 context->destroy.notify = context_handle_destroy;
2118 ds_tizen_input_method_context_add_destroy_listener(context->context,
2121 context->im_context_commit_string.notify = context_handle_commit_string;
2122 ds_tizen_input_method_context_add_commit_string_listener(context->context,
2123 &context->im_context_commit_string);
2125 context->im_context_preedit_string.notify = context_handle_preedit_string;
2126 ds_tizen_input_method_context_add_preedit_string_listener(context->context,
2127 &context->im_context_preedit_string);
2129 context->im_context_preedit_styling.notify = context_handle_preedit_styling;
2130 ds_tizen_input_method_context_add_preedit_styling_listener(context->context,
2131 &context->im_context_preedit_styling);
2133 context->im_context_preedit_cursor.notify = context_handle_preedit_cursor;
2134 ds_tizen_input_method_context_add_preedit_cursor_listener(context->context,
2135 &context->im_context_preedit_cursor);
2137 context->im_context_delete_surrounding_text.notify = context_handle_delete_surrounding_text;
2138 ds_tizen_input_method_context_add_delete_surrounding_text_listener(context->context,
2139 &context->im_context_delete_surrounding_text);
2141 context->im_context_cursor_position.notify = context_handle_cursor_position;
2142 ds_tizen_input_method_context_add_cursor_position_listener(context->context,
2143 &context->im_context_cursor_position);
2145 context->im_context_modifiers_map.notify = context_handle_modifiers_map;
2146 ds_tizen_input_method_context_add_modifiers_map_listener(context->context,
2147 &context->im_context_modifiers_map);
2149 context->im_context_keysym.notify = context_handle_keysym;
2150 ds_tizen_input_method_context_add_keysym_listener(context->context,
2151 &context->im_context_keysym);
2153 context->im_context_grab_keyboard.notify = context_handle_grab_keyboard;
2154 ds_tizen_input_method_context_add_grab_keyboard_listener(context->context,
2155 &context->im_context_grab_keyboard);
2157 context->im_context_key.notify = context_handle_key;
2158 ds_tizen_input_method_context_add_key_listener(context->context,
2159 &context->im_context_key);
2161 context->im_context_modifiers.notify = context_handle_modifiers;
2162 ds_tizen_input_method_context_add_modifiers_listener(context->context,
2163 &context->im_context_modifiers);
2165 context->im_context_language.notify = context_handle_language;
2166 ds_tizen_input_method_context_add_language_listener(context->context,
2167 &context->im_context_language);
2169 context->im_context_text_direction.notify = context_handle_text_direction;
2170 ds_tizen_input_method_context_add_text_direction_listener(context->context,
2171 &context->im_context_text_direction);
2176 struct tinyds_view *
2177 tinyds_server_get_focused_view(struct tinyds_server *server)
2179 struct tinyds_view *view = NULL;
2180 struct tinyds_pointer *pointer;
2182 wl_list_for_each(pointer, &server->pointers, link){
2183 if (!pointer->focused_view) continue;
2185 view = pointer->focused_view;
2192 tinyds_server_get_output_size(struct tinyds_server *server,
2193 int *output_w, int *output_h)
2195 *output_w = server->output->width;
2196 *output_h = server->output->height;