2 * Copyright © 2010-2011 Intel Corporation
3 * Copyright © 2008-2011 Kristian Høgsberg
4 * Copyright © 2012-2015 Collabora, Ltd.
5 * Copyright © 2010-2011 Benjamin Franzke
6 * Copyright © 2013 Jason Ekstrand
8 * Permission is hereby granted, free of charge, to any person obtaining
9 * a copy of this software and associated documentation files (the
10 * "Software"), to deal in the Software without restriction, including
11 * without limitation the rights to use, copy, modify, merge, publish,
12 * distribute, sublicense, and/or sell copies of the Software, and to
13 * permit persons to whom the Software is furnished to do so, subject to
14 * the following conditions:
16 * The above copyright notice and this permission notice (including the
17 * next paragraph) shall be included in all copies or substantial
18 * portions of the Software.
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
24 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
25 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
26 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
38 #include <sys/utsname.h>
41 #include <sys/socket.h>
44 #include <linux/limits.h>
47 #define UNW_LOCAL_ONLY
48 #include <libunwind.h>
52 #include "compositor.h"
53 #include "../shared/os-compatibility.h"
54 #include "../shared/helpers.h"
55 #include "../shared/string-helpers.h"
56 #include "git-version.h"
60 #include "compositor-drm.h"
61 #include "compositor-headless.h"
62 #include "compositor-rdp.h"
63 #include "compositor-fbdev.h"
64 #include "compositor-x11.h"
65 #include "compositor-wayland.h"
66 #include "windowed-output-api.h"
68 #define WINDOW_TITLE "Weston Compositor"
70 struct wet_output_config {
77 struct wet_compositor {
78 struct weston_config *config;
79 struct wet_output_config *parsed_options;
80 struct wl_listener pending_output_listener;
83 static FILE *weston_logfile = NULL;
85 static int cached_tm_mday = -1;
87 static int weston_log_timestamp(void)
90 struct tm *brokendown_time;
93 gettimeofday(&tv, NULL);
95 brokendown_time = localtime(&tv.tv_sec);
96 if (brokendown_time == NULL)
97 return fprintf(weston_logfile, "[(NULL)localtime] ");
99 if (brokendown_time->tm_mday != cached_tm_mday) {
100 strftime(string, sizeof string, "%Y-%m-%d %Z", brokendown_time);
101 fprintf(weston_logfile, "Date: %s\n", string);
103 cached_tm_mday = brokendown_time->tm_mday;
106 strftime(string, sizeof string, "%H:%M:%S", brokendown_time);
108 return fprintf(weston_logfile, "[%s.%03li] ", string, tv.tv_usec/1000);
112 custom_handler(const char *fmt, va_list arg)
114 weston_log_timestamp();
115 fprintf(weston_logfile, "libwayland: ");
116 vfprintf(weston_logfile, fmt, arg);
120 weston_log_file_open(const char *filename)
122 wl_log_set_handler_server(custom_handler);
124 if (filename != NULL) {
125 weston_logfile = fopen(filename, "a");
127 os_fd_set_cloexec(fileno(weston_logfile));
130 if (weston_logfile == NULL)
131 weston_logfile = stderr;
133 setvbuf(weston_logfile, NULL, _IOLBF, 256);
137 weston_log_file_close(void)
139 if ((weston_logfile != stderr) && (weston_logfile != NULL))
140 fclose(weston_logfile);
141 weston_logfile = stderr;
145 vlog(const char *fmt, va_list ap)
149 l = weston_log_timestamp();
150 l += vfprintf(weston_logfile, fmt, ap);
156 vlog_continue(const char *fmt, va_list argp)
158 return vfprintf(weston_logfile, fmt, argp);
161 static struct wl_list child_process_list;
162 static struct weston_compositor *segv_compositor;
165 sigchld_handler(int signal_number, void *data)
167 struct weston_process *p;
171 while ((pid = waitpid(-1, &status, WNOHANG)) > 0) {
172 wl_list_for_each(p, &child_process_list, link) {
177 if (&p->link == &child_process_list) {
178 weston_log("unknown child process exited\n");
182 wl_list_remove(&p->link);
183 p->cleanup(p, status);
186 if (pid < 0 && errno != ECHILD)
187 weston_log("waitpid error %m\n");
192 #ifdef HAVE_LIBUNWIND
195 print_backtrace(void)
198 unw_context_t context;
203 const char *filename;
206 pip.unwind_info = NULL;
207 ret = unw_getcontext(&context);
209 weston_log("unw_getcontext: %d\n", ret);
213 ret = unw_init_local(&cursor, &context);
215 weston_log("unw_init_local: %d\n", ret);
219 ret = unw_step(&cursor);
221 ret = unw_get_proc_info(&cursor, &pip);
223 weston_log("unw_get_proc_info: %d\n", ret);
227 ret = unw_get_proc_name(&cursor, procname, 256, &off);
228 if (ret && ret != -UNW_ENOMEM) {
229 if (ret != -UNW_EUNSPEC)
230 weston_log("unw_get_proc_name: %d\n", ret);
235 if (dladdr((void *)(pip.start_ip + off), &dlinfo) && dlinfo.dli_fname &&
237 filename = dlinfo.dli_fname;
241 weston_log("%u: %s (%s%s+0x%x) [%p]\n", i++, filename, procname,
242 ret == -UNW_ENOMEM ? "..." : "", (int)off, (void *)(pip.start_ip + off));
244 ret = unw_step(&cursor);
246 weston_log("unw_step: %d\n", ret);
253 print_backtrace(void)
259 count = backtrace(buffer, ARRAY_LENGTH(buffer));
260 for (i = 0; i < count; i++) {
261 dladdr(buffer[i], &info);
262 weston_log(" [%016lx] %s (%s)\n",
264 info.dli_sname ? info.dli_sname : "--",
272 child_client_exec(int sockfd, const char *path)
278 /* do not give our signal mask to the new process */
279 sigfillset(&allsigs);
280 sigprocmask(SIG_UNBLOCK, &allsigs, NULL);
282 /* Launch clients as the user. Do not lauch clients with wrong euid.*/
283 if (seteuid(getuid()) == -1) {
284 weston_log("compositor: failed seteuid\n");
288 /* SOCK_CLOEXEC closes both ends, so we dup the fd to get a
289 * non-CLOEXEC fd to pass through exec. */
290 clientfd = dup(sockfd);
291 if (clientfd == -1) {
292 weston_log("compositor: dup failed: %m\n");
296 snprintf(s, sizeof s, "%d", clientfd);
297 setenv("WAYLAND_SOCKET", s, 1);
299 if (execl(path, path, NULL) < 0)
300 weston_log("compositor: executing '%s' failed: %m\n",
304 WL_EXPORT struct wl_client *
305 weston_client_launch(struct weston_compositor *compositor,
306 struct weston_process *proc,
308 weston_process_cleanup_func_t cleanup)
312 struct wl_client *client;
314 weston_log("launching '%s'\n", path);
316 if (os_socketpair_cloexec(AF_UNIX, SOCK_STREAM, 0, sv) < 0) {
317 weston_log("weston_client_launch: "
318 "socketpair failed while launching '%s': %m\n",
327 weston_log("weston_client_launch: "
328 "fork failed while launching '%s': %m\n", path);
333 child_client_exec(sv[1], path);
339 client = wl_client_create(compositor->wl_display, sv[0]);
342 weston_log("weston_client_launch: "
343 "wl_client_create failed while launching '%s'.\n",
349 proc->cleanup = cleanup;
350 weston_watch_process(proc);
356 weston_watch_process(struct weston_process *process)
358 wl_list_insert(&child_process_list, &process->link);
361 struct process_info {
362 struct weston_process proc;
367 process_handle_sigchld(struct weston_process *process, int status)
369 struct process_info *pinfo =
370 container_of(process, struct process_info, proc);
373 * There are no guarantees whether this runs before or after
374 * the wl_client destructor.
377 if (WIFEXITED(status)) {
378 weston_log("%s exited with status %d\n", pinfo->path,
379 WEXITSTATUS(status));
380 } else if (WIFSIGNALED(status)) {
381 weston_log("%s died on signal %d\n", pinfo->path,
384 weston_log("%s disappeared\n", pinfo->path);
391 WL_EXPORT struct wl_client *
392 weston_client_start(struct weston_compositor *compositor, const char *path)
394 struct process_info *pinfo;
395 struct wl_client *client;
397 pinfo = zalloc(sizeof *pinfo);
401 pinfo->path = strdup(path);
405 client = weston_client_launch(compositor, &pinfo->proc, path,
406 process_handle_sigchld);
428 weston_log("OS: %s, %s, %s, %s\n", usys.sysname, usys.release,
429 usys.version, usys.machine);
432 static struct wet_compositor *
433 to_wet_compositor(struct weston_compositor *compositor)
435 return weston_compositor_get_user_data(compositor);
439 wet_set_pending_output_handler(struct weston_compositor *ec,
440 wl_notify_func_t handler)
442 struct wet_compositor *compositor = to_wet_compositor(ec);
444 compositor->pending_output_listener.notify = handler;
445 wl_signal_add(&ec->output_pending_signal, &compositor->pending_output_listener);
448 static struct wet_output_config *
449 wet_init_parsed_options(struct weston_compositor *ec)
451 struct wet_compositor *compositor = to_wet_compositor(ec);
452 struct wet_output_config *config;
454 config = zalloc(sizeof *config);
457 perror("out of memory");
464 config->transform = UINT32_MAX;
466 compositor->parsed_options = config;
471 WL_EXPORT struct weston_config *
472 wet_get_config(struct weston_compositor *ec)
474 struct wet_compositor *compositor = to_wet_compositor(ec);
476 return compositor->config;
479 static const char xdg_error_message[] =
480 "fatal: environment variable XDG_RUNTIME_DIR is not set.\n";
482 static const char xdg_wrong_message[] =
483 "fatal: environment variable XDG_RUNTIME_DIR\n"
484 "is set to \"%s\", which is not a directory.\n";
486 static const char xdg_wrong_mode_message[] =
487 "warning: XDG_RUNTIME_DIR \"%s\" is not configured\n"
488 "correctly. Unix access mode must be 0700 (current mode is %o),\n"
489 "and must be owned by the user (current owner is UID %d).\n";
491 static const char xdg_detail_message[] =
492 "Refer to your distribution on how to get it, or\n"
493 "http://www.freedesktop.org/wiki/Specifications/basedir-spec\n"
494 "on how to implement it.\n";
497 verify_xdg_runtime_dir(void)
499 char *dir = getenv("XDG_RUNTIME_DIR");
503 weston_log(xdg_error_message);
504 weston_log_continue(xdg_detail_message);
508 if (stat(dir, &s) || !S_ISDIR(s.st_mode)) {
509 weston_log(xdg_wrong_message, dir);
510 weston_log_continue(xdg_detail_message);
514 if ((s.st_mode & 0777) != 0700 || s.st_uid != getuid()) {
515 weston_log(xdg_wrong_mode_message,
516 dir, s.st_mode & 0777, s.st_uid);
517 weston_log_continue(xdg_detail_message);
522 usage(int error_code)
525 "Usage: weston [OPTIONS]\n\n"
526 "This is weston version " VERSION ", the Wayland reference compositor.\n"
527 "Weston supports multiple backends, and depending on which backend is in use\n"
528 "different options will be accepted.\n\n"
532 " --version\t\tPrint weston version\n"
533 " -B, --backend=MODULE\tBackend module, one of\n"
534 #if defined(BUILD_DRM_COMPOSITOR)
535 "\t\t\t\tdrm-backend.so\n"
537 #if defined(BUILD_FBDEV_COMPOSITOR)
538 "\t\t\t\tfbdev-backend.so\n"
540 #if defined(BUILD_HEADLESS_COMPOSITOR)
541 "\t\t\t\theadless-backend.so\n"
543 #if defined(BUILD_RDP_COMPOSITOR)
544 "\t\t\t\trdp-backend.so\n"
546 #if defined(BUILD_WAYLAND_COMPOSITOR)
547 "\t\t\t\twayland-backend.so\n"
549 #if defined(BUILD_X11_COMPOSITOR)
550 "\t\t\t\tx11-backend.so\n"
552 " --shell=MODULE\tShell module, defaults to desktop-shell.so\n"
553 " -S, --socket=NAME\tName of socket to listen on\n"
554 " -i, --idle-time=SECS\tIdle time in seconds\n"
555 " --modules\t\tLoad the comma-separated list of modules\n"
556 " --log=FILE\t\tLog to the given file\n"
557 " -c, --config=FILE\tConfig file to load, defaults to weston.ini\n"
558 " --no-config\t\tDo not read weston.ini\n"
559 " -h, --help\t\tThis help message\n\n");
561 #if defined(BUILD_DRM_COMPOSITOR)
563 "Options for drm-backend.so:\n\n"
564 " --connector=ID\tBring up only this connector\n"
565 " --seat=SEAT\t\tThe seat that weston should run on\n"
566 " --tty=TTY\t\tThe tty to use\n"
567 " --use-pixman\t\tUse the pixman (CPU) renderer\n"
568 " --current-mode\tPrefer current KMS mode over EDID preferred mode\n\n");
571 #if defined(BUILD_FBDEV_COMPOSITOR)
573 "Options for fbdev-backend.so:\n\n"
574 " --tty=TTY\t\tThe tty to use\n"
575 " --device=DEVICE\tThe framebuffer device to use\n"
579 #if defined(BUILD_HEADLESS_COMPOSITOR)
581 "Options for headless-backend.so:\n\n"
582 " --width=WIDTH\t\tWidth of memory surface\n"
583 " --height=HEIGHT\tHeight of memory surface\n"
584 " --transform=TR\tThe output transformation, TR is one of:\n"
585 "\tnormal 90 180 270 flipped flipped-90 flipped-180 flipped-270\n"
586 " --use-pixman\t\tUse the pixman (CPU) renderer (default: no rendering)\n"
587 " --no-outputs\t\tDo not create any virtual outputs\n"
591 #if defined(BUILD_RDP_COMPOSITOR)
593 "Options for rdp-backend.so:\n\n"
594 " --width=WIDTH\t\tWidth of desktop\n"
595 " --height=HEIGHT\tHeight of desktop\n"
596 " --env-socket\t\tUse socket defined in RDP_FD env variable as peer connection\n"
597 " --address=ADDR\tThe address to bind\n"
598 " --port=PORT\t\tThe port to listen on\n"
599 " --no-clients-resize\tThe RDP peers will be forced to the size of the desktop\n"
600 " --rdp4-key=FILE\tThe file containing the key for RDP4 encryption\n"
601 " --rdp-tls-cert=FILE\tThe file containing the certificate for TLS encryption\n"
602 " --rdp-tls-key=FILE\tThe file containing the private key for TLS encryption\n"
606 #if defined(BUILD_WAYLAND_COMPOSITOR)
608 "Options for wayland-backend.so:\n\n"
609 " --width=WIDTH\t\tWidth of Wayland surface\n"
610 " --height=HEIGHT\tHeight of Wayland surface\n"
611 " --scale=SCALE\t\tScale factor of output\n"
612 " --fullscreen\t\tRun in fullscreen mode\n"
613 " --use-pixman\t\tUse the pixman (CPU) renderer\n"
614 " --output-count=COUNT\tCreate multiple outputs\n"
615 " --sprawl\t\tCreate one fullscreen output for every parent output\n"
616 " --display=DISPLAY\tWayland display to connect to\n\n");
619 #if defined(BUILD_X11_COMPOSITOR)
621 "Options for x11-backend.so:\n\n"
622 " --width=WIDTH\t\tWidth of X window\n"
623 " --height=HEIGHT\tHeight of X window\n"
624 " --scale=SCALE\t\tScale factor of output\n"
625 " --fullscreen\t\tRun in fullscreen mode\n"
626 " --use-pixman\t\tUse the pixman (CPU) renderer\n"
627 " --output-count=COUNT\tCreate multiple outputs\n"
628 " --no-input\t\tDont create input devices\n\n");
634 static int on_term_signal(int signal_number, void *data)
636 struct wl_display *display = data;
638 weston_log("caught signal %d\n", signal_number);
639 wl_display_terminate(display);
645 on_caught_signal(int s, siginfo_t *siginfo, void *context)
647 /* This signal handler will do a best-effort backtrace, and
648 * then call the backend restore function, which will switch
649 * back to the vt we launched from or ungrab X etc and then
650 * raise SIGTRAP. If we run weston under gdb from X or a
651 * different vt, and tell gdb "handle *s* nostop", this
652 * will allow weston to switch back to gdb on crash and then
653 * gdb will catch the crash with SIGTRAP.*/
655 weston_log("caught signal: %d\n", s);
659 segv_compositor->backend->restore(segv_compositor);
667 struct sigaction action;
669 action.sa_flags = SA_SIGINFO | SA_RESETHAND;
670 action.sa_sigaction = on_caught_signal;
671 sigemptyset(&action.sa_mask);
672 sigaction(SIGSEGV, &action, NULL);
673 sigaction(SIGABRT, &action, NULL);
677 clock_name(clockid_t clk_id)
679 static const char *names[] = {
680 [CLOCK_REALTIME] = "CLOCK_REALTIME",
681 [CLOCK_MONOTONIC] = "CLOCK_MONOTONIC",
682 [CLOCK_MONOTONIC_RAW] = "CLOCK_MONOTONIC_RAW",
683 [CLOCK_REALTIME_COARSE] = "CLOCK_REALTIME_COARSE",
684 [CLOCK_MONOTONIC_COARSE] = "CLOCK_MONOTONIC_COARSE",
685 #ifdef CLOCK_BOOTTIME
686 [CLOCK_BOOTTIME] = "CLOCK_BOOTTIME",
690 if (clk_id < 0 || (unsigned)clk_id >= ARRAY_LENGTH(names))
693 return names[clk_id];
696 static const struct {
697 uint32_t bit; /* enum weston_capability */
699 } capability_strings[] = {
700 { WESTON_CAP_ROTATION_ANY, "arbitrary surface rotation:" },
701 { WESTON_CAP_CAPTURE_YFLIP, "screen capture uses y-flip:" },
705 weston_compositor_log_capabilities(struct weston_compositor *compositor)
711 weston_log("Compositor capabilities:\n");
712 for (i = 0; i < ARRAY_LENGTH(capability_strings); i++) {
713 yes = compositor->capabilities & capability_strings[i].bit;
714 weston_log_continue(STAMP_SPACE "%s %s\n",
715 capability_strings[i].desc,
719 weston_log_continue(STAMP_SPACE "presentation clock: %s, id %d\n",
720 clock_name(compositor->presentation_clock),
721 compositor->presentation_clock);
723 if (clock_getres(compositor->presentation_clock, &res) == 0)
724 weston_log_continue(STAMP_SPACE
725 "presentation clock resolution: %d.%09ld s\n",
726 (int)res.tv_sec, res.tv_nsec);
728 weston_log_continue(STAMP_SPACE
729 "presentation clock resolution: N/A\n");
733 handle_primary_client_destroyed(struct wl_listener *listener, void *data)
735 struct wl_client *client = data;
737 weston_log("Primary client died. Closing...\n");
739 wl_display_terminate(wl_client_get_display(client));
743 weston_create_listening_socket(struct wl_display *display, const char *socket_name)
746 if (wl_display_add_socket(display, socket_name)) {
747 weston_log("fatal: failed to add socket: %m\n");
751 socket_name = wl_display_add_socket_auto(display);
753 weston_log("fatal: failed to add socket: %m\n");
758 setenv("WAYLAND_DISPLAY", socket_name, 1);
764 wet_load_module(const char *name, const char *entrypoint)
766 const char *builddir = getenv("WESTON_BUILD_DIR");
773 if (name[0] != '/') {
775 snprintf(path, sizeof path, "%s/.libs/%s", builddir, name);
777 snprintf(path, sizeof path, "%s/%s", MODULEDIR, name);
779 snprintf(path, sizeof path, "%s", name);
782 module = dlopen(path, RTLD_NOW | RTLD_NOLOAD);
784 weston_log("Module '%s' already loaded\n", path);
789 weston_log("Loading module '%s'\n", path);
790 module = dlopen(path, RTLD_NOW);
792 weston_log("Failed to load module: %s\n", dlerror());
796 init = dlsym(module, entrypoint);
798 weston_log("Failed to lookup init function: %s\n", dlerror());
807 load_modules(struct weston_compositor *ec, const char *modules,
808 int *argc, char *argv[])
812 int (*module_init)(struct weston_compositor *ec,
813 int *argc, char *argv[]);
820 end = strchrnul(p, ',');
821 snprintf(buffer, sizeof buffer, "%.*s", (int) (end - p), p);
823 if (strstr(buffer, "xwayland.so")) {
824 if (wet_load_xwayland(ec) < 0)
827 module_init = wet_load_module(buffer, "module_init");
830 if (module_init(ec, argc, argv) < 0)
843 weston_compositor_init_config(struct weston_compositor *ec,
844 struct weston_config *config)
846 struct xkb_rule_names xkb_names;
847 struct weston_config_section *s;
851 s = weston_config_get_section(config, "keyboard", NULL, NULL);
852 weston_config_section_get_string(s, "keymap_rules",
853 (char **) &xkb_names.rules, NULL);
854 weston_config_section_get_string(s, "keymap_model",
855 (char **) &xkb_names.model, NULL);
856 weston_config_section_get_string(s, "keymap_layout",
857 (char **) &xkb_names.layout, NULL);
858 weston_config_section_get_string(s, "keymap_variant",
859 (char **) &xkb_names.variant, NULL);
860 weston_config_section_get_string(s, "keymap_options",
861 (char **) &xkb_names.options, NULL);
863 if (weston_compositor_set_xkb_rule_names(ec, &xkb_names) < 0)
866 weston_config_section_get_int(s, "repeat-rate",
867 &ec->kb_repeat_rate, 40);
868 weston_config_section_get_int(s, "repeat-delay",
869 &ec->kb_repeat_delay, 400);
871 weston_config_section_get_bool(s, "vt-switching",
872 &vt_switching, true);
873 ec->vt_switching = vt_switching;
875 s = weston_config_get_section(config, "core", NULL, NULL);
876 weston_config_section_get_int(s, "repaint-window", &repaint_msec,
878 if (repaint_msec < -10 || repaint_msec > 1000) {
879 weston_log("Invalid repaint_window value in config: %d\n",
882 ec->repaint_msec = repaint_msec;
884 weston_log("Output repaint window is %d ms maximum.\n",
891 weston_choose_default_backend(void)
893 char *backend = NULL;
895 if (getenv("WAYLAND_DISPLAY") || getenv("WAYLAND_SOCKET"))
896 backend = strdup("wayland-backend.so");
897 else if (getenv("DISPLAY"))
898 backend = strdup("x11-backend.so");
900 backend = strdup(WESTON_NATIVE_BACKEND);
905 static const struct { const char *name; uint32_t token; } transforms[] = {
906 { "normal", WL_OUTPUT_TRANSFORM_NORMAL },
907 { "90", WL_OUTPUT_TRANSFORM_90 },
908 { "180", WL_OUTPUT_TRANSFORM_180 },
909 { "270", WL_OUTPUT_TRANSFORM_270 },
910 { "flipped", WL_OUTPUT_TRANSFORM_FLIPPED },
911 { "flipped-90", WL_OUTPUT_TRANSFORM_FLIPPED_90 },
912 { "flipped-180", WL_OUTPUT_TRANSFORM_FLIPPED_180 },
913 { "flipped-270", WL_OUTPUT_TRANSFORM_FLIPPED_270 },
917 weston_parse_transform(const char *transform, uint32_t *out)
921 for (i = 0; i < ARRAY_LENGTH(transforms); i++)
922 if (strcmp(transforms[i].name, transform) == 0) {
923 *out = transforms[i].token;
927 *out = WL_OUTPUT_TRANSFORM_NORMAL;
931 WL_EXPORT const char *
932 weston_transform_to_string(uint32_t output_transform)
936 for (i = 0; i < ARRAY_LENGTH(transforms); i++)
937 if (transforms[i].token == output_transform)
938 return transforms[i].name;
940 return "<illegal value>";
944 load_configuration(struct weston_config **config, int32_t noconfig,
945 const char *config_file)
947 const char *file = "weston.ini";
948 const char *full_path;
956 *config = weston_config_parse(file);
959 full_path = weston_config_get_full_path(*config);
961 weston_log("Using config file '%s'\n", full_path);
962 setenv(WESTON_CONFIG_FILE_ENV_VAR, full_path, 1);
967 if (config_file && noconfig == 0) {
968 weston_log("fatal: error opening or reading config file"
969 " '%s'.\n", config_file);
974 weston_log("Starting with no config file.\n");
975 setenv(WESTON_CONFIG_FILE_ENV_VAR, "", 1);
981 handle_exit(struct weston_compositor *c)
983 wl_display_terminate(c->wl_display);
987 wet_output_set_scale(struct weston_output *output,
988 struct weston_config_section *section,
989 int32_t default_scale,
990 int32_t parsed_scale)
992 int32_t scale = default_scale;
995 weston_config_section_get_int(section, "scale", &scale, default_scale);
998 scale = parsed_scale;
1000 weston_output_set_scale(output, scale);
1003 /* UINT32_MAX is treated as invalid because 0 is a valid
1004 * enumeration value and the parameter is unsigned
1007 wet_output_set_transform(struct weston_output *output,
1008 struct weston_config_section *section,
1009 uint32_t default_transform,
1010 uint32_t parsed_transform)
1013 uint32_t transform = default_transform;
1016 weston_config_section_get_string(section,
1017 "transform", &t, "normal");
1019 if (weston_parse_transform(t, &transform) < 0) {
1020 weston_log("Invalid transform \"%s\" for output %s\n",
1022 transform = default_transform;
1027 if (parsed_transform != UINT32_MAX)
1028 transform = parsed_transform;
1030 weston_output_set_transform(output, transform);
1034 wet_configure_windowed_output_from_config(struct weston_output *output,
1035 struct wet_output_config *defaults)
1037 const struct weston_windowed_output_api *api =
1038 weston_windowed_output_get_api(output->compositor);
1040 struct weston_config *wc = wet_get_config(output->compositor);
1041 struct weston_config_section *section = NULL;
1042 struct wet_compositor *compositor = to_wet_compositor(output->compositor);
1043 struct wet_output_config *parsed_options = compositor->parsed_options;
1044 int width = defaults->width;
1045 int height = defaults->height;
1047 assert(parsed_options);
1050 weston_log("Cannot use weston_windowed_output_api.\n");
1054 section = weston_config_get_section(wc, "output", "name", output->name);
1059 weston_config_section_get_string(section, "mode", &mode, NULL);
1060 if (!mode || sscanf(mode, "%dx%d", &width,
1062 weston_log("Invalid mode for output %s. Using defaults.\n",
1064 width = defaults->width;
1065 height = defaults->height;
1070 if (parsed_options->width)
1071 width = parsed_options->width;
1073 if (parsed_options->height)
1074 height = parsed_options->height;
1076 wet_output_set_scale(output, section, defaults->scale, parsed_options->scale);
1077 wet_output_set_transform(output, section, defaults->transform, parsed_options->transform);
1079 if (api->output_set_size(output, width, height) < 0) {
1080 weston_log("Cannot configure output \"%s\" using weston_windowed_output_api.\n",
1085 weston_output_enable(output);
1091 configure_input_device(struct weston_compositor *compositor,
1092 struct libinput_device *device)
1094 struct weston_config_section *s;
1095 struct weston_config *config = wet_get_config(compositor);
1097 int enable_tap_default;
1099 s = weston_config_get_section(config,
1100 "libinput", NULL, NULL);
1102 if (libinput_device_config_tap_get_finger_count(device) > 0) {
1103 enable_tap_default =
1104 libinput_device_config_tap_get_default_enabled(
1106 weston_config_section_get_bool(s, "enable_tap",
1108 enable_tap_default);
1109 libinput_device_config_tap_set_enabled(device,
1115 drm_backend_output_configure(struct wl_listener *listener, void *data)
1117 struct weston_output *output = data;
1118 struct weston_config *wc = wet_get_config(output->compositor);
1119 struct weston_config_section *section;
1120 const struct weston_drm_output_api *api = weston_drm_output_get_api(output->compositor);
1121 enum weston_drm_backend_output_mode mode =
1122 WESTON_DRM_BACKEND_OUTPUT_PREFERRED;
1125 char *modeline = NULL;
1126 char *gbm_format = NULL;
1130 weston_log("Cannot use weston_drm_output_api.\n");
1134 section = weston_config_get_section(wc, "output", "name", output->name);
1135 weston_config_section_get_string(section, "mode", &s, "preferred");
1137 if (strcmp(s, "off") == 0) {
1138 weston_output_disable(output);
1141 } else if (strcmp(s, "current") == 0) {
1142 mode = WESTON_DRM_BACKEND_OUTPUT_CURRENT;
1143 } else if (strcmp(s, "preferred") != 0) {
1149 if (api->set_mode(output, mode, modeline) < 0) {
1150 weston_log("Cannot configure an output using weston_drm_output_api.\n");
1156 wet_output_set_scale(output, section, 1, 0);
1157 wet_output_set_transform(output, section, WL_OUTPUT_TRANSFORM_NORMAL, UINT32_MAX);
1159 weston_config_section_get_string(section,
1160 "gbm-format", &gbm_format, NULL);
1162 api->set_gbm_format(output, gbm_format);
1165 weston_config_section_get_string(section, "seat", &seat, "");
1167 api->set_seat(output, seat);
1170 weston_output_enable(output);
1174 load_drm_backend(struct weston_compositor *c,
1175 int *argc, char **argv, struct weston_config *wc)
1177 struct weston_drm_backend_config config = {{ 0, }};
1178 struct weston_config_section *section;
1181 const struct weston_option options[] = {
1182 { WESTON_OPTION_INTEGER, "connector", 0, &config.connector },
1183 { WESTON_OPTION_STRING, "seat", 0, &config.seat_id },
1184 { WESTON_OPTION_INTEGER, "tty", 0, &config.tty },
1185 { WESTON_OPTION_BOOLEAN, "current-mode", 0, &config.use_current_mode },
1186 { WESTON_OPTION_BOOLEAN, "use-pixman", 0, &config.use_pixman },
1189 parse_options(options, ARRAY_LENGTH(options), argc, argv);
1191 section = weston_config_get_section(wc, "core", NULL, NULL);
1192 weston_config_section_get_string(section,
1193 "gbm-format", &config.gbm_format,
1196 config.base.struct_version = WESTON_DRM_BACKEND_CONFIG_VERSION;
1197 config.base.struct_size = sizeof(struct weston_drm_backend_config);
1198 config.configure_device = configure_input_device;
1200 ret = weston_compositor_load_backend(c, WESTON_BACKEND_DRM,
1203 wet_set_pending_output_handler(c, drm_backend_output_configure);
1205 free(config.gbm_format);
1206 free(config.seat_id);
1212 headless_backend_output_configure(struct wl_listener *listener, void *data)
1214 struct weston_output *output = data;
1215 struct wet_output_config defaults = {
1219 .transform = WL_OUTPUT_TRANSFORM_NORMAL
1222 if (wet_configure_windowed_output_from_config(output, &defaults) < 0)
1223 weston_log("Cannot configure output \"%s\".\n", output->name);
1227 load_headless_backend(struct weston_compositor *c,
1228 int *argc, char **argv, struct weston_config *wc)
1230 const struct weston_windowed_output_api *api;
1231 struct weston_headless_backend_config config = {{ 0, }};
1234 char *transform = NULL;
1236 struct wet_output_config *parsed_options = wet_init_parsed_options(c);
1237 if (!parsed_options)
1240 const struct weston_option options[] = {
1241 { WESTON_OPTION_INTEGER, "width", 0, &parsed_options->width },
1242 { WESTON_OPTION_INTEGER, "height", 0, &parsed_options->height },
1243 { WESTON_OPTION_BOOLEAN, "use-pixman", 0, &config.use_pixman },
1244 { WESTON_OPTION_STRING, "transform", 0, &transform },
1245 { WESTON_OPTION_BOOLEAN, "no-outputs", 0, &no_outputs },
1248 parse_options(options, ARRAY_LENGTH(options), argc, argv);
1251 if (weston_parse_transform(transform, &parsed_options->transform) < 0) {
1252 weston_log("Invalid transform \"%s\"\n", transform);
1253 parsed_options->transform = UINT32_MAX;
1258 config.base.struct_version = WESTON_HEADLESS_BACKEND_CONFIG_VERSION;
1259 config.base.struct_size = sizeof(struct weston_headless_backend_config);
1261 /* load the actual wayland backend and configure it */
1262 ret = weston_compositor_load_backend(c, WESTON_BACKEND_HEADLESS,
1268 wet_set_pending_output_handler(c, headless_backend_output_configure);
1271 api = weston_windowed_output_get_api(c);
1274 weston_log("Cannot use weston_windowed_output_api.\n");
1278 if (api->output_create(c, "headless") < 0)
1286 rdp_backend_output_configure(struct wl_listener *listener, void *data)
1288 struct weston_output *output = data;
1289 struct wet_compositor *compositor = to_wet_compositor(output->compositor);
1290 struct wet_output_config *parsed_options = compositor->parsed_options;
1291 const struct weston_rdp_output_api *api = weston_rdp_output_get_api(output->compositor);
1295 assert(parsed_options);
1298 weston_log("Cannot use weston_rdp_output_api.\n");
1302 if (parsed_options->width)
1303 width = parsed_options->width;
1305 if (parsed_options->height)
1306 height = parsed_options->height;
1308 weston_output_set_scale(output, 1);
1309 weston_output_set_transform(output, WL_OUTPUT_TRANSFORM_NORMAL);
1311 if (api->output_set_size(output, width, height) < 0) {
1312 weston_log("Cannot configure output \"%s\" using weston_rdp_output_api.\n",
1317 weston_output_enable(output);
1321 weston_rdp_backend_config_init(struct weston_rdp_backend_config *config)
1323 config->base.struct_version = WESTON_RDP_BACKEND_CONFIG_VERSION;
1324 config->base.struct_size = sizeof(struct weston_rdp_backend_config);
1326 config->bind_address = NULL;
1327 config->port = 3389;
1328 config->rdp_key = NULL;
1329 config->server_cert = NULL;
1330 config->server_key = NULL;
1331 config->env_socket = 0;
1332 config->no_clients_resize = 0;
1336 load_rdp_backend(struct weston_compositor *c,
1337 int *argc, char *argv[], struct weston_config *wc)
1339 struct weston_rdp_backend_config config = {{ 0, }};
1342 struct wet_output_config *parsed_options = wet_init_parsed_options(c);
1343 if (!parsed_options)
1346 weston_rdp_backend_config_init(&config);
1348 const struct weston_option rdp_options[] = {
1349 { WESTON_OPTION_BOOLEAN, "env-socket", 0, &config.env_socket },
1350 { WESTON_OPTION_INTEGER, "width", 0, &parsed_options->width },
1351 { WESTON_OPTION_INTEGER, "height", 0, &parsed_options->height },
1352 { WESTON_OPTION_STRING, "address", 0, &config.bind_address },
1353 { WESTON_OPTION_INTEGER, "port", 0, &config.port },
1354 { WESTON_OPTION_BOOLEAN, "no-clients-resize", 0, &config.no_clients_resize },
1355 { WESTON_OPTION_STRING, "rdp4-key", 0, &config.rdp_key },
1356 { WESTON_OPTION_STRING, "rdp-tls-cert", 0, &config.server_cert },
1357 { WESTON_OPTION_STRING, "rdp-tls-key", 0, &config.server_key }
1360 parse_options(rdp_options, ARRAY_LENGTH(rdp_options), argc, argv);
1362 ret = weston_compositor_load_backend(c, WESTON_BACKEND_RDP,
1368 wet_set_pending_output_handler(c, rdp_backend_output_configure);
1371 free(config.bind_address);
1372 free(config.rdp_key);
1373 free(config.server_cert);
1374 free(config.server_key);
1380 fbdev_backend_output_configure(struct wl_listener *listener, void *data)
1382 struct weston_output *output = data;
1383 struct weston_config *wc = wet_get_config(output->compositor);
1384 struct weston_config_section *section;
1386 section = weston_config_get_section(wc, "output", "name", "fbdev");
1388 wet_output_set_transform(output, section, WL_OUTPUT_TRANSFORM_NORMAL, UINT32_MAX);
1389 weston_output_set_scale(output, 1);
1391 weston_output_enable(output);
1395 load_fbdev_backend(struct weston_compositor *c,
1396 int *argc, char **argv, struct weston_config *wc)
1398 struct weston_fbdev_backend_config config = {{ 0, }};
1401 const struct weston_option fbdev_options[] = {
1402 { WESTON_OPTION_INTEGER, "tty", 0, &config.tty },
1403 { WESTON_OPTION_STRING, "device", 0, &config.device },
1406 parse_options(fbdev_options, ARRAY_LENGTH(fbdev_options), argc, argv);
1409 config.device = strdup("/dev/fb0");
1411 config.base.struct_version = WESTON_FBDEV_BACKEND_CONFIG_VERSION;
1412 config.base.struct_size = sizeof(struct weston_fbdev_backend_config);
1413 config.configure_device = configure_input_device;
1415 /* load the actual wayland backend and configure it */
1416 ret = weston_compositor_load_backend(c, WESTON_BACKEND_FBDEV,
1422 wet_set_pending_output_handler(c, fbdev_backend_output_configure);
1425 free(config.device);
1430 x11_backend_output_configure(struct wl_listener *listener, void *data)
1432 struct weston_output *output = data;
1433 struct wet_output_config defaults = {
1437 .transform = WL_OUTPUT_TRANSFORM_NORMAL
1440 if (wet_configure_windowed_output_from_config(output, &defaults) < 0)
1441 weston_log("Cannot configure output \"%s\".\n", output->name);
1445 load_x11_backend(struct weston_compositor *c,
1446 int *argc, char **argv, struct weston_config *wc)
1448 char *default_output;
1449 const struct weston_windowed_output_api *api;
1450 struct weston_x11_backend_config config = {{ 0, }};
1451 struct weston_config_section *section;
1453 int option_count = 1;
1454 int output_count = 0;
1455 char const *section_name;
1458 struct wet_output_config *parsed_options = wet_init_parsed_options(c);
1459 if (!parsed_options)
1462 const struct weston_option options[] = {
1463 { WESTON_OPTION_INTEGER, "width", 0, &parsed_options->width },
1464 { WESTON_OPTION_INTEGER, "height", 0, &parsed_options->height },
1465 { WESTON_OPTION_INTEGER, "scale", 0, &parsed_options->scale },
1466 { WESTON_OPTION_BOOLEAN, "fullscreen", 'f', &config.fullscreen },
1467 { WESTON_OPTION_INTEGER, "output-count", 0, &option_count },
1468 { WESTON_OPTION_BOOLEAN, "no-input", 0, &config.no_input },
1469 { WESTON_OPTION_BOOLEAN, "use-pixman", 0, &config.use_pixman },
1472 parse_options(options, ARRAY_LENGTH(options), argc, argv);
1474 config.base.struct_version = WESTON_X11_BACKEND_CONFIG_VERSION;
1475 config.base.struct_size = sizeof(struct weston_x11_backend_config);
1477 /* load the actual backend and configure it */
1478 ret = weston_compositor_load_backend(c, WESTON_BACKEND_X11,
1484 wet_set_pending_output_handler(c, x11_backend_output_configure);
1486 api = weston_windowed_output_get_api(c);
1489 weston_log("Cannot use weston_windowed_output_api.\n");
1494 while (weston_config_next_section(wc, §ion, §ion_name)) {
1497 if (output_count >= option_count)
1500 if (strcmp(section_name, "output") != 0) {
1504 weston_config_section_get_string(section, "name", &output_name, NULL);
1505 if (output_name == NULL || output_name[0] != 'X') {
1510 if (api->output_create(c, output_name) < 0) {
1519 default_output = NULL;
1521 for (i = output_count; i < option_count; i++) {
1522 if (asprintf(&default_output, "screen%d", i) < 0) {
1526 if (api->output_create(c, default_output) < 0) {
1527 free(default_output);
1530 free(default_output);
1537 wayland_backend_output_configure_hotplug(struct wl_listener *listener, void *data)
1539 struct weston_output *output = data;
1541 /* This backend has all values hardcoded, so nothing can be configured here */
1542 weston_output_enable(output);
1546 wayland_backend_output_configure(struct wl_listener *listener, void *data)
1548 struct weston_output *output = data;
1549 struct wet_output_config defaults = {
1553 .transform = WL_OUTPUT_TRANSFORM_NORMAL
1556 if (wet_configure_windowed_output_from_config(output, &defaults) < 0)
1557 weston_log("Cannot configure output \"%s\".\n", output->name);
1561 load_wayland_backend(struct weston_compositor *c,
1562 int *argc, char **argv, struct weston_config *wc)
1564 struct weston_wayland_backend_config config = {{ 0, }};
1565 struct weston_config_section *section;
1566 const struct weston_windowed_output_api *api;
1567 const char *section_name;
1568 char *output_name = NULL;
1573 struct wet_output_config *parsed_options = wet_init_parsed_options(c);
1574 if (!parsed_options)
1577 config.cursor_size = 32;
1578 config.cursor_theme = NULL;
1579 config.display_name = NULL;
1580 config.fullscreen = 0;
1582 config.use_pixman = false;
1584 const struct weston_option wayland_options[] = {
1585 { WESTON_OPTION_INTEGER, "width", 0, &parsed_options->width },
1586 { WESTON_OPTION_INTEGER, "height", 0, &parsed_options->height },
1587 { WESTON_OPTION_INTEGER, "scale", 0, &parsed_options->scale },
1588 { WESTON_OPTION_STRING, "display", 0, &config.display_name },
1589 { WESTON_OPTION_BOOLEAN, "use-pixman", 0, &config.use_pixman },
1590 { WESTON_OPTION_INTEGER, "output-count", 0, &count },
1591 { WESTON_OPTION_BOOLEAN, "fullscreen", 0, &config.fullscreen },
1592 { WESTON_OPTION_BOOLEAN, "sprawl", 0, &config.sprawl },
1595 parse_options(wayland_options, ARRAY_LENGTH(wayland_options), argc, argv);
1597 section = weston_config_get_section(wc, "shell", NULL, NULL);
1598 weston_config_section_get_string(section, "cursor-theme",
1599 &config.cursor_theme, NULL);
1600 weston_config_section_get_int(section, "cursor-size",
1601 &config.cursor_size, 32);
1603 config.base.struct_size = sizeof(struct weston_wayland_backend_config);
1604 config.base.struct_version = WESTON_WAYLAND_BACKEND_CONFIG_VERSION;
1606 /* load the actual wayland backend and configure it */
1607 ret = weston_compositor_load_backend(c, WESTON_BACKEND_WAYLAND,
1610 free(config.cursor_theme);
1611 free(config.display_name);
1616 api = weston_windowed_output_get_api(c);
1619 /* We will just assume if load_backend() finished cleanly and
1620 * windowed_output_api is not present that wayland backend is
1621 * started with --sprawl or runs on fullscreen-shell. */
1622 wet_set_pending_output_handler(c, wayland_backend_output_configure_hotplug);
1627 wet_set_pending_output_handler(c, wayland_backend_output_configure);
1630 while (weston_config_next_section(wc, §ion, §ion_name)) {
1634 if (strcmp(section_name, "output") != 0) {
1638 weston_config_section_get_string(section, "name", &output_name, NULL);
1640 if (output_name == NULL)
1643 if (output_name[0] != 'W' || output_name[1] != 'L') {
1648 if (api->output_create(c, output_name) < 0) {
1657 for (i = 0; i < count; i++) {
1658 if (asprintf(&output_name, "wayland%d", i) < 0)
1661 if (api->output_create(c, output_name) < 0) {
1673 load_backend(struct weston_compositor *compositor, const char *backend,
1674 int *argc, char **argv, struct weston_config *config)
1676 if (strstr(backend, "headless-backend.so"))
1677 return load_headless_backend(compositor, argc, argv, config);
1678 else if (strstr(backend, "rdp-backend.so"))
1679 return load_rdp_backend(compositor, argc, argv, config);
1680 else if (strstr(backend, "fbdev-backend.so"))
1681 return load_fbdev_backend(compositor, argc, argv, config);
1682 else if (strstr(backend, "drm-backend.so"))
1683 return load_drm_backend(compositor, argc, argv, config);
1684 else if (strstr(backend, "x11-backend.so"))
1685 return load_x11_backend(compositor, argc, argv, config);
1686 else if (strstr(backend, "wayland-backend.so"))
1687 return load_wayland_backend(compositor, argc, argv, config);
1689 weston_log("Error: unknown backend \"%s\"\n", backend);
1694 copy_command_line(int argc, char * const argv[])
1701 fp = open_memstream(&str, &size);
1705 fprintf(fp, "%s", argv[0]);
1706 for (i = 1; i < argc; i++)
1707 fprintf(fp, " %s", argv[i]);
1713 int main(int argc, char *argv[])
1715 int ret = EXIT_FAILURE;
1717 struct wl_display *display;
1718 struct weston_compositor *ec;
1719 struct wl_event_source *signals[4];
1720 struct wl_event_loop *loop;
1722 char *backend = NULL;
1724 char *modules = NULL;
1725 char *option_modules = NULL;
1727 char *server_socket = NULL;
1728 int32_t idle_time = -1;
1730 char *socket_name = NULL;
1731 int32_t version = 0;
1732 int32_t noconfig = 0;
1734 char *config_file = NULL;
1735 struct weston_config *config = NULL;
1736 struct weston_config_section *section;
1737 struct wl_client *primary_client;
1738 struct wl_listener primary_client_destroyed;
1739 struct weston_seat *seat;
1740 struct wet_compositor user_data;
1742 const struct weston_option core_options[] = {
1743 { WESTON_OPTION_STRING, "backend", 'B', &backend },
1744 { WESTON_OPTION_STRING, "shell", 0, &shell },
1745 { WESTON_OPTION_STRING, "socket", 'S', &socket_name },
1746 { WESTON_OPTION_INTEGER, "idle-time", 'i', &idle_time },
1747 { WESTON_OPTION_STRING, "modules", 0, &option_modules },
1748 { WESTON_OPTION_STRING, "log", 0, &log },
1749 { WESTON_OPTION_BOOLEAN, "help", 'h', &help },
1750 { WESTON_OPTION_BOOLEAN, "version", 0, &version },
1751 { WESTON_OPTION_BOOLEAN, "no-config", 0, &noconfig },
1752 { WESTON_OPTION_STRING, "config", 'c', &config_file },
1755 cmdline = copy_command_line(argc, argv);
1756 parse_options(core_options, ARRAY_LENGTH(core_options), &argc, argv);
1760 usage(EXIT_SUCCESS);
1764 printf(PACKAGE_STRING "\n");
1767 return EXIT_SUCCESS;
1770 weston_log_set_handler(vlog, vlog_continue);
1771 weston_log_file_open(log);
1775 STAMP_SPACE "Bug reports to: %s\n"
1776 STAMP_SPACE "Build: %s\n",
1777 PACKAGE_STRING, PACKAGE_URL, PACKAGE_BUGREPORT,
1779 weston_log("Command line: %s\n", cmdline);
1783 verify_xdg_runtime_dir();
1785 display = wl_display_create();
1787 loop = wl_display_get_event_loop(display);
1788 signals[0] = wl_event_loop_add_signal(loop, SIGTERM, on_term_signal,
1790 signals[1] = wl_event_loop_add_signal(loop, SIGINT, on_term_signal,
1792 signals[2] = wl_event_loop_add_signal(loop, SIGQUIT, on_term_signal,
1795 wl_list_init(&child_process_list);
1796 signals[3] = wl_event_loop_add_signal(loop, SIGCHLD, sigchld_handler,
1799 if (!signals[0] || !signals[1] || !signals[2] || !signals[3])
1802 if (load_configuration(&config, noconfig, config_file) < 0)
1804 user_data.config = config;
1805 user_data.parsed_options = NULL;
1807 section = weston_config_get_section(config, "core", NULL, NULL);
1810 weston_config_section_get_string(section, "backend", &backend,
1813 backend = weston_choose_default_backend();
1816 ec = weston_compositor_create(display, &user_data);
1818 weston_log("fatal: failed to create compositor\n");
1822 if (weston_compositor_init_config(ec, config) < 0)
1825 if (load_backend(ec, backend, &argc, argv, config) < 0) {
1826 weston_log("fatal: failed to create compositor backend\n");
1830 weston_pending_output_coldplug(ec);
1833 segv_compositor = ec;
1836 weston_config_section_get_int(section, "idle-time", &idle_time, -1);
1838 idle_time = 300; /* default idle timeout, in seconds */
1840 ec->idle_time = idle_time;
1841 ec->default_pointer_grab = NULL;
1842 ec->exit = handle_exit;
1844 weston_compositor_log_capabilities(ec);
1846 server_socket = getenv("WAYLAND_SERVER_SOCKET");
1847 if (server_socket) {
1848 weston_log("Running with single client\n");
1849 if (!safe_strtoint(server_socket, &fd))
1856 primary_client = wl_client_create(display, fd);
1857 if (!primary_client) {
1858 weston_log("fatal: failed to add client: %m\n");
1861 primary_client_destroyed.notify =
1862 handle_primary_client_destroyed;
1863 wl_client_add_destroy_listener(primary_client,
1864 &primary_client_destroyed);
1865 } else if (weston_create_listening_socket(display, socket_name)) {
1870 weston_config_section_get_string(section, "shell", &shell,
1871 "desktop-shell.so");
1873 if (load_modules(ec, shell, &argc, argv) < 0)
1876 weston_config_section_get_string(section, "modules", &modules, "");
1877 if (load_modules(ec, modules, &argc, argv) < 0)
1880 if (load_modules(ec, option_modules, &argc, argv) < 0)
1883 section = weston_config_get_section(config, "keyboard", NULL, NULL);
1884 weston_config_section_get_bool(section, "numlock-on", &numlock_on, 0);
1886 wl_list_for_each(seat, &ec->seat_list, link) {
1887 struct weston_keyboard *keyboard =
1888 weston_seat_get_keyboard(seat);
1891 weston_keyboard_set_locks(keyboard,
1897 for (i = 1; i < argc; i++)
1898 weston_log("fatal: unhandled option: %s\n", argv[i]);
1902 weston_compositor_wake(ec);
1904 wl_display_run(display);
1906 /* Allow for setting return exit code after
1907 * wl_display_run returns normally. This is
1908 * useful for devs/testers and automated tests
1909 * that want to indicate failure status to
1910 * testing infrastructure above
1912 ret = ec->exit_code;
1915 /* free(NULL) is valid, and it won't be NULL if it's used */
1916 free(user_data.parsed_options);
1918 weston_compositor_destroy(ec);
1921 for (i = ARRAY_LENGTH(signals) - 1; i >= 0; i--)
1923 wl_event_source_remove(signals[i]);
1925 wl_display_destroy(display);
1927 weston_log_file_close();
1930 weston_config_destroy(config);
1935 free(option_modules);