2 * Copyright © 2012-2021 Collabora, Ltd.
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sublicense, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial
14 * portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 #include "ivi-compositor.h"
38 #include <linux/input.h>
40 #include <libweston/backend-drm.h>
41 #include <libweston/backend-wayland.h>
42 #ifdef HAVE_BACKEND_RDP
43 #include <libweston/backend-rdp.h>
45 #ifdef HAVE_BACKEND_HEADLESS
46 #include <libweston/backend-headless.h>
48 #ifdef HAVE_BACKEND_X11
49 #include <libweston/backend-x11.h>
51 #include <libweston/libweston.h>
52 #include <libweston/windowed-output-api.h>
53 #include <libweston/config-parser.h>
54 #include <libweston/weston-log.h>
57 #include "shared/os-compatibility.h"
58 #include "shared/helpers.h"
60 #include "agl-shell-server-protocol.h"
66 static int cached_tm_mday = -1;
67 static struct weston_log_scope *log_scope;
69 struct ivi_compositor *
70 to_ivi_compositor(struct weston_compositor *ec)
72 return weston_compositor_get_user_data(ec);
75 static struct ivi_output_config *
76 ivi_init_parsed_options(struct weston_compositor *compositor)
78 struct ivi_compositor *ivi = to_ivi_compositor(compositor);
79 struct ivi_output_config *config;
81 config = zalloc(sizeof *config);
88 config->transform = UINT32_MAX;
90 ivi->parsed_options = config;
98 sigint_helper(int sig)
104 ivi_layout_save(struct ivi_compositor *ivi, struct ivi_output *output)
106 struct ivi_output *new_output;
107 ivi->need_ivi_output_relayout = true;
109 new_output = zalloc(sizeof(*new_output));
111 new_output->ivi = ivi;
112 new_output->background = output->background;
114 new_output->top = output->top;
115 new_output->bottom = output->bottom;
116 new_output->left = output->left;
117 new_output->right = output->right;
119 new_output->active = output->active;
120 new_output->previous_active = output->previous_active;
121 new_output->name = strdup(output->name);
123 new_output->app_ids = strdup(output->app_ids);
125 new_output->area = output->area;
126 new_output->area_saved = output->area_saved;
127 new_output->area_activation = output->area_activation;
129 weston_log("saving output layout for output %s\n", new_output->name);
131 wl_list_insert(&ivi->saved_outputs, &new_output->link);
135 ivi_layout_restore(struct ivi_compositor *ivi, struct ivi_output *n_output)
137 struct ivi_output *output = NULL;
138 struct ivi_output *iter_output;
140 if (!ivi->need_ivi_output_relayout)
143 ivi->need_ivi_output_relayout = false;
145 wl_list_for_each(iter_output, &ivi->saved_outputs, link) {
146 if (strcmp(n_output->name, iter_output->name) == 0) {
147 output = iter_output;
155 weston_log("restoring output layout for output %s\n", output->name);
156 n_output->background = output->background;
158 n_output->top = output->top;
159 n_output->bottom = output->bottom;
160 n_output->left = output->left;
161 n_output->right = output->right;
163 n_output->active = output->active;
164 n_output->previous_active = output->previous_active;
166 n_output->app_ids = strdup(output->app_ids);
168 n_output->area = output->area;
169 n_output->area_saved = output->area_saved;
170 n_output->area_activation = output->area_activation;
172 free(output->app_ids);
174 wl_list_remove(&output->link);
179 ivi_layout_destroy_saved_outputs(struct ivi_compositor *ivi)
181 struct ivi_output *output, *output_next;
183 wl_list_for_each_safe(output, output_next, &ivi->saved_outputs, link) {
184 free(output->app_ids);
187 wl_list_remove(&output->link);
193 handle_output_destroy(struct wl_listener *listener, void *data)
195 struct ivi_output *output;
197 output = wl_container_of(listener, output, output_destroy);
198 assert(output->output == data);
200 if (output->fullscreen_view.fs &&
201 output->fullscreen_view.fs->view) {
202 weston_surface_destroy(output->fullscreen_view.fs->view->surface);
203 output->fullscreen_view.fs->view = NULL;
206 ivi_layout_save(output->ivi, output);
208 output->output = NULL;
209 wl_list_remove(&output->output_destroy.link);
213 to_ivi_output(struct weston_output *o)
215 struct wl_listener *listener;
216 struct ivi_output *output;
218 listener = weston_output_get_destroy_listener(o, handle_output_destroy);
219 output = wl_container_of(listener, output, output_destroy);
225 ivi_output_configure_app_id(struct ivi_output *ivi_output)
227 if (ivi_output->config) {
228 if (ivi_output->app_ids != NULL)
231 weston_config_section_get_string(ivi_output->config,
233 &ivi_output->app_ids,
236 if (ivi_output->app_ids == NULL)
239 weston_log("Will place app_id %s on output %s\n",
240 ivi_output->app_ids, ivi_output->name);
244 static struct ivi_output *
245 ivi_ensure_output(struct ivi_compositor *ivi, char *name,
246 struct weston_config_section *config,
247 struct weston_head *head)
249 struct ivi_output *output = NULL;
250 wl_list_for_each(output, &ivi->outputs, link) {
251 if (strcmp(output->name, name) == 0) {
257 output = zalloc(sizeof *output);
265 output->config = config;
267 if (ivi->simple_output_configure) {
269 weston_compositor_create_output_with_head(ivi->compositor,
271 if (!output->output) {
277 int ret = ivi->simple_output_configure(output->output);
279 weston_log("Configuring output \"%s\" failed.\n",
280 weston_head_get_name(head));
281 weston_output_destroy(output->output);
282 ivi->init_failed = true;
286 if (weston_output_enable(output->output) < 0) {
287 weston_log("Enabling output \"%s\" failed.\n",
288 weston_head_get_name(head));
289 weston_output_destroy(output->output);
290 ivi->init_failed = true;
296 weston_compositor_create_output(ivi->compositor, name);
297 if (!output->output) {
304 output->output_destroy.notify = handle_output_destroy;
305 weston_output_add_destroy_listener(output->output,
306 &output->output_destroy);
308 wl_list_insert(&ivi->outputs, &output->link);
309 ivi_output_configure_app_id(output);
314 count_heads(struct weston_output *output)
316 struct weston_head *iter = NULL;
319 while ((iter = weston_output_iterate_heads(output, iter)))
326 handle_head_destroy(struct wl_listener *listener, void *data)
328 struct weston_head *head = data;
329 struct weston_output *output;
331 wl_list_remove(&listener->link);
334 output = weston_head_get_output(head);
336 /* On shutdown path, the output might be already gone. */
340 /* We're the last head */
341 if (count_heads(output) <= 1)
342 weston_output_destroy(output);
346 add_head_destroyed_listener(struct weston_head *head)
348 /* We already have a destroy listener */
349 if (weston_head_get_destroy_listener(head, handle_head_destroy))
352 struct wl_listener *listener = zalloc(sizeof *listener);
356 listener->notify = handle_head_destroy;
357 weston_head_add_destroy_listener(head, listener);
361 drm_configure_output(struct ivi_output *output)
363 struct ivi_compositor *ivi = output->ivi;
364 struct weston_config_section *section = output->config;
365 enum weston_drm_backend_output_mode mode =
366 WESTON_DRM_BACKEND_OUTPUT_PREFERRED;
367 char *modeline = NULL;
368 char *gbm_format = NULL;
373 weston_config_section_get_string(section, "mode", &m, "preferred");
375 /* This should have been handled earlier */
376 assert(strcmp(m, "off") != 0);
378 if (ivi->cmdline.use_current_mode || strcmp(m, "current") == 0) {
379 mode = WESTON_DRM_BACKEND_OUTPUT_CURRENT;
380 } else if (strcmp(m, "preferred") != 0) {
386 weston_config_section_get_string(section, "gbm-format",
389 weston_config_section_get_string(section, "seat", &seat, "");
392 if (ivi->drm_api->set_mode(output->output, mode, modeline) < 0) {
393 weston_log("Cannot configure output using weston_drm_output_api.\n");
399 ivi->drm_api->set_gbm_format(output->output, gbm_format);
402 ivi->drm_api->set_seat(output->output, seat);
408 #define WINDOWED_DEFAULT_WIDTH 1024
409 #define WINDOWED_DEFAULT_HEIGHT 768
412 windowed_configure_output(struct ivi_output *output)
414 struct ivi_compositor *ivi = output->ivi;
415 struct weston_config_section *section = output->config;
416 int width = WINDOWED_DEFAULT_WIDTH;
417 int height = WINDOWED_DEFAULT_HEIGHT;
422 weston_config_section_get_string(section, "mode", &mode, NULL);
423 if (!mode || sscanf(mode, "%dx%d", &width, &height) != 2) {
424 weston_log("Invalid mode for output %s. Using defaults.\n",
426 width = WINDOWED_DEFAULT_WIDTH;
427 height = WINDOWED_DEFAULT_HEIGHT;
432 if (ivi->cmdline.width)
433 width = ivi->cmdline.width;
434 if (ivi->cmdline.height)
435 height = ivi->cmdline.height;
436 if (ivi->cmdline.scale)
437 weston_output_set_scale(output->output, ivi->cmdline.scale);
439 if (ivi->window_api->output_set_size(output->output, width, height) < 0) {
440 weston_log("Cannot configure output '%s' using weston_windowed_output_api.\n",
445 weston_log("Configured windowed_output_api to %dx%d\n", width, height);
451 parse_transform(const char *transform, uint32_t *out)
453 static const struct { const char *name; uint32_t token; } transforms[] = {
454 { "normal", WL_OUTPUT_TRANSFORM_NORMAL },
455 { "rotate-90", WL_OUTPUT_TRANSFORM_90 },
456 { "rotate-180", WL_OUTPUT_TRANSFORM_180 },
457 { "rotate-270", WL_OUTPUT_TRANSFORM_270 },
458 { "flipped", WL_OUTPUT_TRANSFORM_FLIPPED },
459 { "flipped-rotate-90", WL_OUTPUT_TRANSFORM_FLIPPED_90 },
460 { "flipped-rotate-180", WL_OUTPUT_TRANSFORM_FLIPPED_180 },
461 { "flipped-rotate-270", WL_OUTPUT_TRANSFORM_FLIPPED_270 },
464 for (size_t i = 0; i < ARRAY_LENGTH(transforms); i++)
465 if (strcmp(transforms[i].name, transform) == 0) {
466 *out = transforms[i].token;
470 *out = WL_OUTPUT_TRANSFORM_NORMAL;
475 parse_activation_area(const char *geometry, struct ivi_output *output)
478 unsigned width, height, x, y;
480 n = sscanf(geometry, "%ux%u+%u,%u", &width, &height, &x, &y);
484 output->area_activation.width = width;
485 output->area_activation.height = height;
486 output->area_activation.x = x;
487 output->area_activation.y = y;
492 configure_output(struct ivi_output *output)
494 struct ivi_compositor *ivi = output->ivi;
495 struct weston_config_section *section = output->config;
497 uint32_t transform = WL_OUTPUT_TRANSFORM_NORMAL;
500 * This can happen with the wayland backend with 'sprawl'. The config
501 * is hard-coded, so we don't need to do anything.
503 if (!ivi->drm_api && !ivi->window_api)
509 weston_config_section_get_int(section, "scale", &scale, 1);
510 weston_config_section_get_string(section, "transform", &t, "normal");
511 if (parse_transform(t, &transform) < 0)
512 weston_log("Invalid transform \"%s\" for output %s\n",
514 weston_config_section_get_string(section, "activation-area", &t, "");
515 if (parse_activation_area(t, output) < 0)
516 weston_log("Invalid activation-area \"%s\" for output %s\n",
521 weston_output_set_scale(output->output, scale);
522 weston_output_set_transform(output->output, transform);
525 return drm_configure_output(output);
527 return windowed_configure_output(output);
531 * Reorgainizes the output's add array into two sections.
532 * add[0..ret-1] are the heads that failed to get attached.
533 * add[ret..add_len] are the heads that were successfully attached.
535 * The order between elements in each section is stable.
538 try_attach_heads(struct ivi_output *output)
542 for (size_t i = 0; i < output->add_len; ++i) {
543 if (weston_output_attach_head(output->output, output->add[i]) < 0) {
544 struct weston_head *tmp = output->add[i];
545 memmove(&output->add[fail_len + 1], output->add[fail_len],
546 sizeof output->add[0] * (i - fail_len));
547 output->add[fail_len++] = tmp;
554 * Like try_attach_heads, this reorganizes the output's add array into a failed
555 * and successful section.
556 * i is the number of heads that already failed the previous step.
559 try_enable_output(struct ivi_output *output, size_t i)
561 for (; i < output->add_len; ++i) {
562 struct weston_head *head;
564 if (weston_output_enable(output->output) == 0)
567 head = output->add[output->add_len - 1];
568 memmove(&output->add[i + 1], &output->add[i],
569 sizeof output->add[0] * (output->add_len - i));
570 output->add[i] = head;
572 weston_head_detach(head);
579 try_attach_enable_heads(struct ivi_output *output)
582 assert(!output->output->enabled);
584 fail_len = try_attach_heads(output);
586 if (configure_output(output) < 0)
589 fail_len = try_enable_output(output, fail_len);
591 /* All heads failed to be attached */
592 if (fail_len == output->add_len)
595 /* For each successful head attached */
596 for (size_t i = fail_len; i < output->add_len; ++i)
597 add_head_destroyed_listener(output->add[i]);
599 ivi_layout_restore(output->ivi, output);
601 output->add_len = fail_len;
606 process_output(struct ivi_output *output)
608 if (output->output->enabled) {
609 output->add_len = try_attach_heads(output);
610 return output->add_len == 0 ? 0 : -1;
613 return try_attach_enable_heads(output);
617 head_disable(struct ivi_compositor *ivi, struct weston_head *head)
619 struct weston_output *output;
620 struct ivi_output *ivi_output;
621 struct wl_listener *listener;
623 output = weston_head_get_output(head);
626 listener = weston_output_get_destroy_listener(output,
627 handle_output_destroy);
630 ivi_output = wl_container_of(listener, ivi_output, output_destroy);
631 assert(ivi_output->output == output);
633 weston_head_detach(head);
634 if (count_heads(ivi_output->output) == 0) {
635 if (ivi_output->output) {
636 /* ivi_output->output destruction may be deferred in
637 * some cases (see drm_output_destroy()), so we need to
638 * forcibly trigger the destruction callback now, or
639 * otherwise would later access data that we are about
642 struct weston_output *save = ivi_output->output;
644 handle_output_destroy(&ivi_output->output_destroy, save);
645 weston_output_destroy(save);
648 wl_list_remove(&ivi_output->link);
649 free(ivi_output->app_ids);
653 static struct weston_config_section *
654 find_controlling_output_config(struct weston_config *config,
657 struct weston_config_section *section;
661 same_as = strdup(name);
663 section = weston_config_get_section(config, "output",
665 if (!section && depth > 0)
666 weston_log("Configuration error: output section reffered"
667 "to by same-as=%s not found.\n", same_as);
674 weston_log("Configuration error: same-as nested too "
675 "deep for output '%s'.\n", name);
679 weston_config_section_get_string(section, "same-as",
687 head_prepare_enable(struct ivi_compositor *ivi, struct weston_head *head)
689 const char *name = weston_head_get_name(head);
690 struct weston_config_section *section;
691 struct ivi_output *output;
692 char *output_name = NULL;
695 section = find_controlling_output_config(ivi->config, name);
699 weston_config_section_get_string(section, "mode", &mode, NULL);
700 if (mode && strcmp(mode, "off") == 0) {
706 weston_config_section_get_string(section, "name",
709 output_name = strdup(name);
715 output = ivi_ensure_output(ivi, output_name, section, head);
719 if (output->add_len >= ARRAY_LENGTH(output->add))
722 output->add[output->add_len++] = head;
726 heads_changed(struct wl_listener *listener, void *arg)
728 struct weston_compositor *compositor = arg;
729 struct weston_head *head = NULL;
730 struct ivi_compositor *ivi = to_ivi_compositor(compositor);
731 struct ivi_output *output;
733 while ((head = weston_compositor_iterate_heads(ivi->compositor, head))) {
734 bool connected = weston_head_is_connected(head);
735 bool enabled = weston_head_is_enabled(head);
736 bool changed = weston_head_is_device_changed(head);
737 bool non_desktop = weston_head_is_non_desktop(head);
739 if (connected && !enabled && !non_desktop)
740 head_prepare_enable(ivi, head);
741 else if (!connected && enabled)
742 head_disable(ivi, head);
743 else if (enabled && changed)
744 weston_log("Detected a monitor change on head '%s', "
745 "not bothering to do anything about it.\n",
746 weston_head_get_name(head));
748 weston_head_reset_device_changed(head);
751 wl_list_for_each(output, &ivi->outputs, link) {
752 if (output->add_len == 0)
755 if (process_output(output) < 0) {
757 ivi->init_failed = true;
764 drm_backend_remoted_output_configure(struct weston_output *output,
765 struct weston_config_section *section,
767 const struct weston_remoting_api *api)
769 char *gbm_format = NULL;
772 char *pipeline = NULL;
775 uint32_t transform = WL_OUTPUT_TRANSFORM_NORMAL;
778 ret = api->set_mode(output, modeline);
780 weston_log("Cannot configure an output \"%s\" using "
781 "weston_remoting_api. Invalid mode\n",
786 weston_config_section_get_int(section, "scale", &scale, 1);
787 weston_output_set_scale(output, scale);
789 weston_config_section_get_string(section, "transform", &trans, "normal");
790 if (parse_transform(trans, &transform) < 0) {
791 weston_log("Invalid transform \"%s\" for output %s\n",
792 trans, output->name);
794 weston_output_set_transform(output, transform);
796 weston_config_section_get_string(section, "gbm-format",
798 api->set_gbm_format(output, gbm_format);
801 weston_config_section_get_string(section, "seat", &seat, "");
803 api->set_seat(output, seat);
806 weston_config_section_get_string(section, "gst-pipeline", &pipeline,
809 api->set_gst_pipeline(output, pipeline);
814 weston_config_section_get_string(section, "host", &host, NULL);
815 weston_config_section_get_int(section, "port", &port, 0);
816 if (!host || port <= 0 || 65533 < port) {
817 weston_log("Cannot configure an output \"%s\". "
818 "Need to specify gst-pipeline or "
819 "host and port (1-65533).\n", output->name);
821 api->set_host(output, host);
823 api->set_port(output, port);
830 remote_output_init(struct ivi_output *ivi_output,
831 struct weston_compositor *compositor,
832 struct weston_config_section *section,
833 const struct weston_remoting_api *api)
835 char *output_name, *modeline = NULL;
838 weston_config_section_get_string(section, "name", &output_name, NULL);
842 weston_config_section_get_string(section, "mode", &modeline, "off");
843 if (strcmp(modeline, "off") == 0)
846 ivi_output->output = api->create_output(compositor, output_name);
847 if (!ivi_output->output) {
848 weston_log("Cannot create remoted output \"%s\".\n",
853 ret = drm_backend_remoted_output_configure(ivi_output->output, section,
856 weston_log("Cannot configure remoted output \"%s\".\n",
861 if ((ret = weston_output_enable(ivi_output->output)) < 0) {
862 weston_log("Enabling remoted output \"%s\" failed.\n",
869 weston_log("remoted output '%s' enabled\n", ivi_output->output->name);
876 if (ivi_output->output)
877 weston_output_destroy(ivi_output->output);
883 ivi_enable_remote_outputs(struct ivi_compositor *ivi)
885 struct weston_config_section *remote_section = NULL;
886 const char *section_name;
887 struct weston_config *config = ivi->config;
889 while (weston_config_next_section(config, &remote_section, §ion_name)) {
890 if (strcmp(section_name, "remote-output"))
893 struct ivi_output *ivi_output = NULL;
894 bool output_found = false;
897 weston_config_section_get_string(remote_section,
898 "name", &_name, NULL);
899 wl_list_for_each(ivi_output, &ivi->outputs, link) {
900 if (!strcmp(ivi_output->name, _name)) {
911 ivi_output = zalloc(sizeof(*ivi_output));
917 ivi_output->ivi = ivi;
918 ivi_output->name = _name;
919 ivi_output->config = remote_section;
920 ivi_output->type = OUTPUT_REMOTE;
922 if (remote_output_init(ivi_output, ivi->compositor,
923 remote_section, ivi->remoting_api)) {
924 free(ivi_output->name);
929 ivi_output->output_destroy.notify = handle_output_destroy;
930 weston_output_add_destroy_listener(ivi_output->output,
931 &ivi_output->output_destroy);
933 wl_list_insert(&ivi->outputs, &ivi_output->link);
934 ivi_output_configure_app_id(ivi_output);
939 load_remoting_plugin(struct ivi_compositor *ivi, struct weston_config *config)
941 struct weston_compositor *compositor = ivi->compositor;
942 int (*module_init)(struct weston_compositor *wc);
944 module_init = weston_load_module("remoting-plugin.so",
945 "weston_module_init");
949 if (module_init(compositor) < 0)
952 ivi->remoting_api = weston_remoting_get_api(compositor);
953 if (!ivi->remoting_api)
959 load_remoting_plugin(struct weston_compositor *compositor, struct weston_config *config)
966 load_drm_backend(struct ivi_compositor *ivi, int *argc, char *argv[])
968 struct weston_drm_backend_config config = {
970 .struct_version = WESTON_DRM_BACKEND_CONFIG_VERSION,
971 .struct_size = sizeof config,
974 struct weston_config_section *section;
975 int use_current_mode = 0;
978 bool without_input = false;
981 const struct weston_option options[] = {
982 { WESTON_OPTION_STRING, "seat", 0, &config.seat_id },
983 { WESTON_OPTION_STRING, "drm-device", 0, &config.specific_device },
984 { WESTON_OPTION_BOOLEAN, "current-mode", 0, &use_current_mode },
985 { WESTON_OPTION_BOOLEAN, "use-pixman", 0, &use_pixman },
986 { WESTON_OPTION_BOOLEAN, "continue-without-input", false, &without_input }
989 parse_options(options, ARRAY_LENGTH(options), argc, argv);
990 config.use_pixman = use_pixman;
991 ivi->cmdline.use_current_mode = use_current_mode;
993 section = weston_config_get_section(ivi->config, "core", NULL, NULL);
994 weston_config_section_get_string(section, "gbm-format",
995 &config.gbm_format, NULL);
996 weston_config_section_get_uint(section, "pageflip-timeout",
997 &config.pageflip_timeout, 0);
998 weston_config_section_get_bool(section, "pixman-shadow", &use_shadow, 1);
999 config.use_pixman_shadow = use_shadow;
1002 ivi->compositor->require_input = !without_input;
1004 ret = weston_compositor_load_backend(ivi->compositor, WESTON_BACKEND_DRM,
1009 ivi->drm_api = weston_drm_output_get_api(ivi->compositor);
1010 if (!ivi->drm_api) {
1011 weston_log("Cannot use drm output api.\n");
1016 load_remoting_plugin(ivi, ivi->config);
1019 free(config.gbm_format);
1020 free(config.seat_id);
1025 windowed_parse_common_options(struct ivi_compositor *ivi, int *argc, char *argv[],
1026 bool *use_pixman, bool *fullscreen, int *output_count)
1028 struct weston_config_section *section;
1032 const struct weston_option options[] = {
1033 { WESTON_OPTION_INTEGER, "width", 0, &ivi->cmdline.width },
1034 { WESTON_OPTION_INTEGER, "height", 0, &ivi->cmdline.height },
1035 { WESTON_OPTION_INTEGER, "scale", 0, &ivi->cmdline.scale },
1036 { WESTON_OPTION_BOOLEAN, "use-pixman", 0, &pixman },
1037 { WESTON_OPTION_BOOLEAN, "fullscreen", 0, &fs },
1038 { WESTON_OPTION_INTEGER, "output-count", 0, output_count },
1041 section = weston_config_get_section(ivi->config, "core", NULL, NULL);
1042 weston_config_section_get_bool(section, "use-pixman", &pixman, 0);
1045 parse_options(options, ARRAY_LENGTH(options), argc, argv);
1046 *use_pixman = pixman;
1051 windowed_create_outputs(struct ivi_compositor *ivi, int output_count,
1052 const char *match_prefix, const char *name_prefix)
1054 struct weston_config_section *section = NULL;
1055 const char *section_name;
1056 char *default_output = NULL;
1058 size_t match_len = strlen(match_prefix);
1060 while (weston_config_next_section(ivi->config, §ion, §ion_name)) {
1063 if (i >= output_count)
1066 if (strcmp(section_name, "output") != 0)
1069 weston_config_section_get_string(section, "name", &output_name, NULL);
1070 if (output_name == NULL)
1072 if (strncmp(output_name, match_prefix, match_len) != 0) {
1077 if (ivi->window_api->create_head(ivi->compositor, output_name) < 0) {
1086 for (; i < output_count; ++i) {
1087 if (asprintf(&default_output, "%s%d", name_prefix, i) < 0)
1090 if (ivi->window_api->create_head(ivi->compositor, default_output) < 0) {
1091 free(default_output);
1095 free(default_output);
1102 load_wayland_backend(struct ivi_compositor *ivi, int *argc, char *argv[])
1104 struct weston_wayland_backend_config config = {
1106 .struct_version = WESTON_WAYLAND_BACKEND_CONFIG_VERSION,
1107 .struct_size = sizeof config,
1110 struct weston_config_section *section;
1115 const struct weston_option options[] = {
1116 { WESTON_OPTION_STRING, "display", 0, &config.display_name },
1117 { WESTON_OPTION_STRING, "sprawl", 0, &sprawl },
1120 windowed_parse_common_options(ivi, argc, argv, &config.use_pixman,
1121 &config.fullscreen, &output_count);
1123 parse_options(options, ARRAY_LENGTH(options), argc, argv);
1124 config.sprawl = sprawl;
1126 section = weston_config_get_section(ivi->config, "shell", NULL, NULL);
1127 weston_config_section_get_string(section, "cursor-theme",
1128 &config.cursor_theme, NULL);
1129 weston_config_section_get_int(section, "cursor-size",
1130 &config.cursor_size, 32);
1132 ret = weston_compositor_load_backend(ivi->compositor, WESTON_BACKEND_WAYLAND,
1135 free(config.cursor_theme);
1136 free(config.display_name);
1141 ivi->window_api = weston_windowed_output_get_api(ivi->compositor);
1144 * We will just assume if load_backend() finished cleanly and
1145 * windowed_output_api is not present that wayland backend is started
1146 * with --sprawl or runs on fullscreen-shell. In this case, all values
1147 * are hardcoded, so nothing can be configured; simply create and
1150 if (ivi->window_api == NULL)
1153 return windowed_create_outputs(ivi, output_count, "WL", "wayland");
1156 #ifdef HAVE_BACKEND_X11
1158 load_x11_backend(struct ivi_compositor *ivi, int *argc, char *argv[])
1160 struct weston_x11_backend_config config = {
1162 .struct_version = WESTON_X11_BACKEND_CONFIG_VERSION,
1163 .struct_size = sizeof config,
1170 const struct weston_option options[] = {
1171 { WESTON_OPTION_BOOLEAN, "no-input", 0, &no_input },
1174 windowed_parse_common_options(ivi, argc, argv, &config.use_pixman,
1175 &config.fullscreen, &output_count);
1177 parse_options(options, ARRAY_LENGTH(options), argc, argv);
1178 config.no_input = no_input;
1180 ret = weston_compositor_load_backend(ivi->compositor, WESTON_BACKEND_X11,
1186 ivi->window_api = weston_windowed_output_get_api(ivi->compositor);
1187 if (!ivi->window_api) {
1188 weston_log("Cannot use weston_windowed_output_api.\n");
1192 return windowed_create_outputs(ivi, output_count, "X", "screen");
1196 load_x11_backend(struct ivi_compositor *ivi, int *argc, char *argv[])
1202 #ifdef HAVE_BACKEND_HEADLESS
1204 load_headless_backend(struct ivi_compositor *ivi, int *argc, char **argv)
1206 struct weston_headless_backend_config config = {};
1214 struct weston_compositor *c = ivi->compositor;
1216 const struct weston_option options[] = {
1217 { WESTON_OPTION_BOOLEAN, "use-pixman", 0, &use_pixman },
1218 { WESTON_OPTION_BOOLEAN, "use-gl", 0, &use_gl },
1221 windowed_parse_common_options(ivi, argc, argv, &use_pixman,
1222 &fullscreen, &output_count);
1224 parse_options(options, ARRAY_LENGTH(options), argc, argv);
1225 config.use_pixman = use_pixman;
1226 config.use_gl = use_gl;
1228 config.base.struct_version = WESTON_HEADLESS_BACKEND_CONFIG_VERSION;
1229 config.base.struct_size = sizeof(struct weston_headless_backend_config);
1231 /* load the actual headless-backend and configure it */
1232 ret = weston_compositor_load_backend(c, WESTON_BACKEND_HEADLESS,
1237 ivi->window_api = weston_windowed_output_get_api(c);
1238 if (!ivi->window_api) {
1239 weston_log("Cannot use weston_windowed_output_api.\n");
1243 if (ivi->window_api->create_head(c, "headless") < 0) {
1244 weston_log("Cannot create headless back-end\n");
1252 load_headless_backend(struct ivi_compositor *ivi, int *argc, char **argv)
1258 #ifdef HAVE_BACKEND_RDP
1260 weston_rdp_backend_config_init(struct weston_rdp_backend_config *config)
1262 config->base.struct_version = WESTON_RDP_BACKEND_CONFIG_VERSION;
1263 config->base.struct_size = sizeof(struct weston_rdp_backend_config);
1265 config->bind_address = NULL;
1266 config->port = 3389;
1267 config->rdp_key = NULL;
1268 config->server_cert = NULL;
1269 config->server_key = NULL;
1270 config->env_socket = 0;
1271 config->no_clients_resize = 1;
1272 config->force_no_compression = 0;
1276 rdp_backend_output_configure(struct weston_output *output)
1278 struct ivi_compositor *ivi = to_ivi_compositor(output->compositor);
1279 struct ivi_output_config *parsed_options = ivi->parsed_options;
1280 const struct weston_rdp_output_api *api =
1281 weston_rdp_output_get_api(output->compositor);
1285 assert(parsed_options);
1288 weston_log("Cannot use weston_rdp_output_api.\n");
1292 if (parsed_options->width)
1293 width = parsed_options->width;
1295 if (parsed_options->height)
1296 height = parsed_options->height;
1298 weston_output_set_scale(output, 1);
1299 weston_output_set_transform(output, WL_OUTPUT_TRANSFORM_NORMAL);
1301 if (api->output_set_size(output, width, height) < 0) {
1302 weston_log("Cannot configure output \"%s\" using weston_rdp_output_api.\n",
1311 load_rdp_backend(struct ivi_compositor *ivi, int *argc, char **argv)
1313 struct weston_rdp_backend_config config = {};
1316 struct ivi_output_config *parsed_options = ivi_init_parsed_options(ivi->compositor);
1317 if (!parsed_options)
1320 weston_rdp_backend_config_init(&config);
1322 const struct weston_option rdp_options[] = {
1323 { WESTON_OPTION_BOOLEAN, "env-socket", 0, &config.env_socket },
1324 { WESTON_OPTION_INTEGER, "width", 0, &parsed_options->width },
1325 { WESTON_OPTION_INTEGER, "height", 0, &parsed_options->height },
1326 { WESTON_OPTION_STRING, "address", 0, &config.bind_address },
1327 { WESTON_OPTION_INTEGER, "port", 0, &config.port },
1328 { WESTON_OPTION_BOOLEAN, "no-clients-resize", 0, &config.no_clients_resize },
1329 { WESTON_OPTION_STRING, "rdp4-key", 0, &config.rdp_key },
1330 { WESTON_OPTION_STRING, "rdp-tls-cert", 0, &config.server_cert },
1331 { WESTON_OPTION_STRING, "rdp-tls-key", 0, &config.server_key },
1332 { WESTON_OPTION_BOOLEAN, "force-no-compression", 0, &config.force_no_compression },
1335 parse_options(rdp_options, ARRAY_LENGTH(rdp_options), argc, argv);
1337 ivi->simple_output_configure = rdp_backend_output_configure;
1338 ret = weston_compositor_load_backend(ivi->compositor, WESTON_BACKEND_RDP, &config.base);
1340 free(config.bind_address);
1341 free(config.rdp_key);
1342 free(config.server_cert);
1343 free(config.server_key);
1349 load_rdp_backend(struct ivi_compositor *ivi, int *argc, char **argv)
1357 load_backend(struct ivi_compositor *ivi, const char *backend,
1358 int *argc, char *argv[])
1360 if (strcmp(backend, "drm-backend.so") == 0) {
1361 return load_drm_backend(ivi, argc, argv);
1362 } else if (strcmp(backend, "wayland-backend.so") == 0) {
1363 return load_wayland_backend(ivi, argc, argv);
1364 } else if (strcmp(backend, "x11-backend.so") == 0) {
1365 return load_x11_backend(ivi, argc, argv);
1366 } else if (strcmp(backend, "headless-backend.so") == 0) {
1367 return load_headless_backend(ivi, argc, argv);
1368 } else if (strcmp(backend, "rdp-backend.so") == 0) {
1369 return load_rdp_backend(ivi, argc, argv);
1372 weston_log("fatal: unknown backend '%s'.\n", backend);
1377 load_modules(struct ivi_compositor *ivi, const char *modules,
1378 int *argc, char *argv[], bool *xwayland)
1380 const char *p, *end;
1382 int (*module_init)(struct weston_compositor *wc, int argc, char *argv[]);
1384 if (modules == NULL)
1389 end = strchrnul(p, ',');
1390 snprintf(buffer, sizeof buffer, "%.*s", (int) (end - p), p);
1392 if (strstr(buffer, "xwayland.so")) {
1394 } else if (strstr(buffer, "systemd-notify.so")) {
1395 weston_log("systemd-notify plug-in already loaded!\n");
1397 module_init = weston_load_module(buffer, "wet_module_init");
1401 if (module_init(ivi->compositor, *argc, argv) < 0)
1416 choose_default_backend(void)
1418 char *backend = NULL;
1420 if (getenv("WAYLAND_DISPLAY") || getenv("WAYLAND_SOCKET"))
1421 backend = strdup("wayland-backend.so");
1422 else if (getenv("DISPLAY"))
1423 backend = strdup("x11-backend.so");
1425 backend = strdup("drm-backend.so");
1431 compositor_init_config(struct ivi_compositor *ivi)
1433 struct xkb_rule_names xkb_names;
1434 struct weston_config_section *section;
1435 struct weston_compositor *compositor = ivi->compositor;
1436 struct weston_config *config = ivi->config;
1441 /* agl-compositor.ini [keyboard] */
1442 section = weston_config_get_section(config, "keyboard", NULL, NULL);
1443 weston_config_section_get_string(section, "keymap_rules",
1444 (char **) &xkb_names.rules, NULL);
1445 weston_config_section_get_string(section, "keymap_model",
1446 (char **) &xkb_names.model, NULL);
1447 weston_config_section_get_string(section, "keymap_layout",
1448 (char **) &xkb_names.layout, NULL);
1449 weston_config_section_get_string(section, "keymap_variant",
1450 (char **) &xkb_names.variant, NULL);
1451 weston_config_section_get_string(section, "keymap_options",
1452 (char **) &xkb_names.options, NULL);
1454 if (weston_compositor_set_xkb_rule_names(compositor, &xkb_names) < 0)
1457 weston_config_section_get_int(section, "repeat-rate",
1458 &compositor->kb_repeat_rate, 40);
1459 weston_config_section_get_int(section, "repeat-delay",
1460 &compositor->kb_repeat_delay, 400);
1462 weston_config_section_get_bool(section, "vt-switching",
1463 &vt_switching, false);
1464 compositor->vt_switching = vt_switching;
1466 /* agl-compositor.ini [core] */
1467 section = weston_config_get_section(config, "core", NULL, NULL);
1469 weston_config_section_get_bool(section, "disable-cursor",
1470 &ivi->disable_cursor, false);
1471 weston_config_section_get_bool(section, "activate-by-default",
1472 &ivi->activate_by_default, true);
1474 weston_config_section_get_bool(section, "require-input", &require_input, true);
1475 compositor->require_input = require_input;
1477 weston_config_section_get_int(section, "repaint-window", &repaint_msec,
1478 compositor->repaint_msec);
1479 if (repaint_msec < -10 || repaint_msec > 1000) {
1480 weston_log("Invalid repaint_window value in config: %d\n",
1483 compositor->repaint_msec = repaint_msec;
1485 weston_log("Output repaint window is %d ms maximum.\n",
1486 compositor->repaint_msec);
1491 struct ivi_surface *
1492 to_ivi_surface(struct weston_surface *surface)
1494 struct weston_desktop_surface *dsurface;
1496 dsurface = weston_surface_get_desktop_surface(surface);
1500 return weston_desktop_surface_get_user_data(dsurface);
1504 activate_binding(struct weston_seat *seat,
1505 struct weston_view *focus_view, uint32_t flags)
1507 struct weston_surface *focus_surface;
1508 struct weston_surface *main_surface;
1509 struct ivi_surface *ivi_surface;
1510 struct ivi_shell_seat *ivi_seat = get_ivi_shell_seat(seat);
1515 focus_surface = focus_view->surface;
1516 main_surface = weston_surface_get_main_surface(focus_surface);
1518 ivi_surface = to_ivi_surface(main_surface);
1523 ivi_shell_activate_surface(ivi_surface, ivi_seat, flags);
1527 click_to_activate_binding(struct weston_pointer *pointer,
1528 const struct timespec *time,
1529 uint32_t button, void *data)
1531 if (pointer->grab != &pointer->default_grab)
1533 if (pointer->focus == NULL)
1536 activate_binding(pointer->seat, pointer->focus,
1537 WESTON_ACTIVATE_FLAG_CLICKED);
1541 touch_to_activate_binding(struct weston_touch *touch,
1542 const struct timespec *time,
1545 if (touch->grab != &touch->default_grab)
1547 if (touch->focus == NULL)
1550 activate_binding(touch->seat, touch->focus,
1551 WESTON_ACTIVATE_FLAG_NONE);
1555 add_bindings(struct weston_compositor *compositor)
1557 weston_compositor_add_button_binding(compositor, BTN_LEFT, 0,
1558 click_to_activate_binding,
1560 weston_compositor_add_button_binding(compositor, BTN_RIGHT, 0,
1561 click_to_activate_binding,
1563 weston_compositor_add_touch_binding(compositor, 0,
1564 touch_to_activate_binding,
1569 create_listening_socket(struct wl_display *display, const char *socket_name)
1572 if (wl_display_add_socket(display, socket_name)) {
1573 weston_log("fatal: failed to add socket: %s\n",
1578 socket_name = wl_display_add_socket_auto(display);
1580 weston_log("fatal: failed to add socket: %s\n",
1586 setenv("WAYLAND_DISPLAY", socket_name, 1);
1592 global_filter(const struct wl_client *client, const struct wl_global *global,
1599 load_config(struct weston_config **config, bool no_config,
1600 const char *config_file)
1602 const char *file = "agl-compositor.ini";
1603 const char *full_path;
1609 *config = weston_config_parse(file);
1612 full_path = weston_config_get_full_path(*config);
1614 weston_log("Using config file '%s'.\n", full_path);
1615 setenv(WESTON_CONFIG_FILE_ENV_VAR, full_path, 1);
1620 if (config_file && !no_config) {
1621 weston_log("fatal: error opening or reading config file '%s'.\n",
1627 weston_log("Starting with no config file.\n");
1628 setenv(WESTON_CONFIG_FILE_ENV_VAR, "", 1);
1633 static FILE *logfile;
1636 log_timestamp(char *buf, size_t len)
1639 struct tm *brokendown_time;
1643 gettimeofday(&tv, NULL);
1645 brokendown_time = localtime(&tv.tv_sec);
1646 if (brokendown_time == NULL) {
1647 snprintf(buf, len, "%s", "[(NULL)localtime] ");
1651 memset(datestr, 0, sizeof(datestr));
1652 if (brokendown_time->tm_mday != cached_tm_mday) {
1653 strftime(datestr, sizeof(datestr), "Date: %Y-%m-%d %Z\n",
1655 cached_tm_mday = brokendown_time->tm_mday;
1658 strftime(timestr, sizeof(timestr), "%H:%M:%S", brokendown_time);
1659 /* if datestr is empty it prints only timestr*/
1660 snprintf(buf, len, "%s[%s.%03li]", datestr,
1661 timestr, (tv.tv_usec / 1000));
1667 custom_handler(const char *fmt, va_list arg)
1671 weston_log_scope_printf(log_scope, "%s libwayland: ",
1672 log_timestamp(timestr, sizeof(timestr)));
1673 weston_log_scope_vprintf(log_scope, fmt, arg);
1677 log_file_open(const char *filename)
1679 wl_log_set_handler_server(custom_handler);
1682 logfile = fopen(filename, "a");
1687 os_fd_set_cloexec(fileno(logfile));
1688 setvbuf(logfile, NULL, _IOLBF, 256);
1693 log_file_close(void)
1695 if (logfile && logfile != stderr)
1701 vlog(const char *fmt, va_list ap)
1703 const char *oom = "Out of memory";
1708 if (weston_log_scope_is_enabled(log_scope)) {
1710 char *xlog_timestamp = log_timestamp(timestr, sizeof(timestr));
1711 len_va = vasprintf(&str, fmt, ap);
1713 len = weston_log_scope_printf(log_scope, "%s %s",
1714 xlog_timestamp, str);
1717 len = weston_log_scope_printf(log_scope, "%s %s",
1718 xlog_timestamp, oom);
1727 vlog_continue(const char *fmt, va_list ap)
1729 return weston_log_scope_vprintf(log_scope, fmt, ap);
1733 on_term_signal(int signo, void *data)
1735 struct wl_display *display = data;
1737 weston_log("caught signal %d\n", signo);
1738 wl_display_terminate(display);
1744 handle_exit(struct weston_compositor *compositor)
1746 wl_display_terminate(compositor->wl_display);
1750 usage(int error_code)
1752 FILE *out = error_code == EXIT_SUCCESS ? stdout : stderr;
1754 "Usage: agl-compositor [OPTIONS]\n"
1756 "This is " PACKAGE_STRING ", the reference compositor for\n"
1757 "Automotive Grade Linux. " PACKAGE_STRING " supports multiple "
1758 "backends,\nand depending on which backend is in use different "
1759 "options will be accepted.\n"
1763 " --version\t\tPrint agl-compositor version\n"
1764 " -B, --backend=MODULE\tBackend module, one of\n"
1765 "\t\t\t\tdrm-backend.so\n"
1766 "\t\t\t\twayland-backend.so\n"
1767 "\t\t\t\tx11-backend.so\n"
1768 "\t\t\t\theadless-backend.so\n"
1769 " -S, --socket=NAME\tName of socket to listen on\n"
1770 " --log=FILE\t\tLog to the given file\n"
1771 " -c, --config=FILE\tConfig file to load, defaults to agl-compositor.ini\n"
1772 " --no-config\t\tDo not read agl-compositor.ini\n"
1773 " --debug\t\tEnable debug extension(s)\n"
1774 " -h, --help\t\tThis help message\n"
1780 copy_command_line(int argc, char * const argv[])
1787 fp = open_memstream(&str, &size);
1791 fprintf(fp, "%s", argv[0]);
1792 for (i = 1; i < argc; i++)
1793 fprintf(fp, " %s", argv[i]);
1799 #if !defined(BUILD_XWAYLAND)
1801 wet_load_xwayland(struct weston_compositor *comp)
1803 weston_log("Attempted to load xwayland library but compositor "
1804 "was *not* built with xwayland support!\n");
1810 weston_log_setup_scopes(struct weston_log_context *log_ctx,
1811 struct weston_log_subscriber *subscriber,
1817 char *tokenize = strdup(names);
1818 char *token = strtok(tokenize, ",");
1820 weston_log_subscribe(log_ctx, subscriber, token);
1821 token = strtok(NULL, ",");
1827 weston_log_subscribe_to_scopes(struct weston_log_context *log_ctx,
1828 struct weston_log_subscriber *logger,
1829 const char *debug_scopes)
1831 if (logger && debug_scopes)
1832 weston_log_setup_scopes(log_ctx, logger, debug_scopes);
1834 weston_log_subscribe(log_ctx, logger, "log");
1838 int wet_main(int argc, char *argv[], const struct weston_testsuite_data *test_data)
1840 struct ivi_compositor ivi = { 0 };
1842 struct wl_display *display = NULL;
1843 struct wl_event_loop *loop;
1844 struct wl_event_source *signals[3] = { 0 };
1845 struct weston_config_section *section;
1846 /* Command line options */
1847 char *backend = NULL;
1848 char *socket_name = NULL;
1850 char *modules = NULL;
1851 char *option_modules = NULL;
1852 char *debug_scopes = NULL;
1857 bool list_debug_scopes = false;
1858 char *config_file = NULL;
1859 struct weston_log_context *log_ctx = NULL;
1860 struct weston_log_subscriber *logger;
1861 int ret = EXIT_FAILURE;
1862 bool xwayland = false;
1863 struct sigaction action;
1865 const struct weston_option core_options[] = {
1866 { WESTON_OPTION_STRING, "backend", 'B', &backend },
1867 { WESTON_OPTION_STRING, "socket", 'S', &socket_name },
1868 { WESTON_OPTION_STRING, "log", 0, &log },
1869 { WESTON_OPTION_BOOLEAN, "help", 'h', &help },
1870 { WESTON_OPTION_BOOLEAN, "version", 0, &version },
1871 { WESTON_OPTION_BOOLEAN, "no-config", 0, &no_config },
1872 { WESTON_OPTION_BOOLEAN, "debug", 0, &debug },
1873 { WESTON_OPTION_STRING, "config", 'c', &config_file },
1874 { WESTON_OPTION_STRING, "modules", 0, &option_modules },
1875 { WESTON_OPTION_STRING, "debug-scopes", 'l', &debug_scopes },
1876 { WESTON_OPTION_STRING, "list-debug-scopes", 'L', &list_debug_scopes },
1879 wl_list_init(&ivi.outputs);
1880 wl_list_init(&ivi.saved_outputs);
1881 wl_list_init(&ivi.surfaces);
1882 wl_list_init(&ivi.pending_surfaces);
1883 wl_list_init(&ivi.popup_pending_apps);
1884 wl_list_init(&ivi.fullscreen_pending_apps);
1885 wl_list_init(&ivi.split_pending_apps);
1886 wl_list_init(&ivi.remote_pending_apps);
1887 wl_list_init(&ivi.desktop_clients);
1888 wl_list_init(&ivi.child_process_list);
1889 wl_list_init(&ivi.pending_apps);
1891 /* Prevent any clients we spawn getting our stdin */
1892 os_fd_set_cloexec(STDIN_FILENO);
1894 cmdline = copy_command_line(argc, argv);
1895 parse_options(core_options, ARRAY_LENGTH(core_options), &argc, argv);
1898 usage(EXIT_SUCCESS);
1901 printf(PACKAGE_STRING "\n");
1906 log_ctx = weston_log_ctx_create();
1908 fprintf(stderr, "Failed to initialize weston debug framework.\n");
1912 log_scope = weston_log_ctx_add_log_scope(log_ctx, "log",
1913 "agl-compositor log\n",
1917 weston_log_set_handler(vlog, vlog_continue);
1919 logger = weston_log_subscriber_create_log(logfile);
1920 weston_log_subscribe_to_scopes(log_ctx, logger, debug_scopes);
1922 weston_log("Command line: %s\n", cmdline);
1925 if (load_config(&ivi.config, no_config, config_file) < 0)
1927 section = weston_config_get_section(ivi.config, "core", NULL, NULL);
1929 weston_config_section_get_string(section, "backend", &backend,
1932 backend = choose_default_backend();
1935 display = wl_display_create();
1936 loop = wl_display_get_event_loop(display);
1938 wl_display_set_global_filter(display,
1939 global_filter, &ivi);
1941 /* Register signal handlers so we shut down cleanly */
1943 signals[0] = wl_event_loop_add_signal(loop, SIGTERM, on_term_signal,
1945 signals[1] = wl_event_loop_add_signal(loop, SIGUSR2, on_term_signal,
1947 signals[2] = wl_event_loop_add_signal(loop, SIGCHLD, sigchld_handler,
1950 /* When debugging the compositor, if use wl_event_loop_add_signal() to
1951 * catch SIGINT, the debugger can't catch it, and attempting to stop
1952 * the compositor from within the debugger results in weston exiting
1955 * Instead, use the sigaction() function, which sets up the signal in a
1956 * way that gdb can successfully catch, but have the handler for SIGINT
1957 * send SIGUSR2 (xwayland uses SIGUSR1), which we catch via
1958 * wl_event_loop_add_signal().
1960 action.sa_handler = sigint_helper;
1961 sigemptyset(&action.sa_mask);
1962 action.sa_flags = 0;
1963 sigaction(SIGINT, &action, NULL);
1965 for (size_t i = 0; i < ARRAY_LENGTH(signals); ++i)
1969 ivi.compositor = weston_compositor_create(display, log_ctx, &ivi, test_data);
1970 if (!ivi.compositor) {
1971 weston_log("fatal: failed to create compositor.\n");
1975 if (compositor_init_config(&ivi) < 0)
1976 goto error_compositor;
1978 if (load_backend(&ivi, backend, &argc, argv) < 0) {
1979 weston_log("fatal: failed to create compositor backend.\n");
1980 goto error_compositor;
1983 ivi.heads_changed.notify = heads_changed;
1984 weston_compositor_add_heads_changed_listener(ivi.compositor,
1985 &ivi.heads_changed);
1987 weston_compositor_flush_heads_changed(ivi.compositor);
1988 if (ivi_desktop_init(&ivi) < 0)
1989 goto error_compositor;
1991 ivi_seat_init(&ivi);
1993 /* load additional modules */
1994 weston_config_section_get_string(section, "modules", &modules, "");
1995 if (load_modules(&ivi, modules, &argc, argv, &xwayland) < 0)
1996 goto error_compositor;
1998 if (load_modules(&ivi, option_modules, &argc, argv, &xwayland) < 0)
1999 goto error_compositor;
2002 weston_config_section_get_bool(section, "xwayland", &xwayland,
2006 if (ivi_shell_init(&ivi) < 0)
2007 goto error_compositor;
2010 if (wet_load_xwayland(ivi.compositor) < 0)
2011 goto error_compositor;
2014 if (ivi_policy_init(&ivi) < 0)
2015 goto error_compositor;
2018 if (list_debug_scopes) {
2019 struct weston_log_scope *nscope = NULL;
2021 weston_log("Printing available debug scopes:\n");
2023 while ((nscope = weston_log_scopes_iterate(log_ctx, nscope))) {
2024 weston_log("\tscope name: %s, desc: %s",
2025 weston_log_scope_get_name(nscope),
2026 weston_log_scope_get_description(nscope));
2031 goto error_compositor;
2034 add_bindings(ivi.compositor);
2036 if (ivi.remoting_api)
2037 ivi_enable_remote_outputs(&ivi);
2039 if (create_listening_socket(display, socket_name) < 0)
2040 goto error_compositor;
2042 ivi_shell_init_black_fs(&ivi);
2044 ivi.compositor->exit = handle_exit;
2046 weston_compositor_wake(ivi.compositor);
2048 ivi_shell_create_global(&ivi);
2050 ivi_launch_shell_client(&ivi, "shell-client",
2051 &ivi.shell_client.client);
2052 ivi_launch_shell_client(&ivi, "shell-client-ext",
2053 &ivi.shell_client_ext.client);
2056 ivi_screenshooter_create(&ivi);
2057 ivi_agl_systemd_notify(&ivi);
2059 wl_display_run(display);
2061 ret = ivi.compositor->exit_code;
2063 wl_display_destroy_clients(display);
2071 weston_compositor_destroy(ivi.compositor);
2073 weston_log_scope_destroy(log_scope);
2076 weston_log_subscriber_destroy(logger);
2077 weston_log_ctx_destroy(log_ctx);
2079 ivi_policy_destroy(ivi.policy);
2082 for (size_t i = 0; i < ARRAY_LENGTH(signals); ++i)
2084 wl_event_source_remove(signals[i]);
2086 wl_display_destroy(display);
2090 weston_config_destroy(ivi.config);
2096 free(option_modules);