blob: 6cf9194030319182d814e414645d1b15668eb22f [file] [log] [blame]
Giulio Camuffobab996e2014-10-12 00:24:25 +03001/*
2 * Copyright © 2010-2011 Intel Corporation
3 * Copyright © 2008-2011 Kristian Høgsberg
4 * Copyright © 2012-2015 Collabora, Ltd.
Benoit Gschwind3ff10da2016-05-10 22:47:49 +02005 * Copyright © 2010-2011 Benjamin Franzke
6 * Copyright © 2013 Jason Ekstrand
Giulio Camuffobab996e2014-10-12 00:24:25 +03007 *
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:
15 *
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.
19 *
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
27 * SOFTWARE.
28 */
29
30#include "config.h"
31
32#include <unistd.h>
33#include <signal.h>
34#include <errno.h>
35#include <dlfcn.h>
36#include <string.h>
37#include <sys/utsname.h>
38#include <sys/stat.h>
39#include <sys/wait.h>
Giulio Camuffofba27fb2016-06-02 21:48:10 +030040#include <sys/socket.h>
Giulio Camuffo8aedf7b2016-06-02 21:48:12 +030041#include <libinput.h>
Giulio Camuffobe2b11a2016-06-02 21:48:13 +030042#include <sys/time.h>
Giulio Camuffo179fcda2016-06-02 21:48:14 +030043#include <linux/limits.h>
Giulio Camuffobab996e2014-10-12 00:24:25 +030044
45#ifdef HAVE_LIBUNWIND
46#define UNW_LOCAL_ONLY
47#include <libunwind.h>
48#endif
49
Giulio Camuffo179fcda2016-06-02 21:48:14 +030050#include "weston.h"
Giulio Camuffobab996e2014-10-12 00:24:25 +030051#include "compositor.h"
52#include "../shared/os-compatibility.h"
53#include "../shared/helpers.h"
54#include "git-version.h"
55#include "version.h"
Giulio Camuffofba27fb2016-06-02 21:48:10 +030056#include "weston.h"
Giulio Camuffobab996e2014-10-12 00:24:25 +030057
Giulio Camuffo1c0e40d2016-04-29 15:40:34 -070058#include "compositor-drm.h"
Benoit Gschwind3c530942016-04-15 20:28:32 -070059#include "compositor-headless.h"
Benoit Gschwindbd573102016-04-22 17:05:26 +020060#include "compositor-rdp.h"
Benoit Gschwind934e89a2016-04-27 23:56:42 +020061#include "compositor-fbdev.h"
Benoit Gschwinde16acab2016-04-15 20:28:31 -070062#include "compositor-x11.h"
Benoit Gschwind3ff10da2016-05-10 22:47:49 +020063#include "compositor-wayland.h"
64
65#define WINDOW_TITLE "Weston Compositor"
Benoit Gschwind3c530942016-04-15 20:28:32 -070066
Giulio Camuffobe2b11a2016-06-02 21:48:13 +030067static FILE *weston_logfile = NULL;
68
69static int cached_tm_mday = -1;
70
71static int weston_log_timestamp(void)
72{
73 struct timeval tv;
74 struct tm *brokendown_time;
75 char string[128];
76
77 gettimeofday(&tv, NULL);
78
79 brokendown_time = localtime(&tv.tv_sec);
80 if (brokendown_time == NULL)
81 return fprintf(weston_logfile, "[(NULL)localtime] ");
82
83 if (brokendown_time->tm_mday != cached_tm_mday) {
84 strftime(string, sizeof string, "%Y-%m-%d %Z", brokendown_time);
85 fprintf(weston_logfile, "Date: %s\n", string);
86
87 cached_tm_mday = brokendown_time->tm_mday;
88 }
89
90 strftime(string, sizeof string, "%H:%M:%S", brokendown_time);
91
92 return fprintf(weston_logfile, "[%s.%03li] ", string, tv.tv_usec/1000);
93}
94
95static void
96custom_handler(const char *fmt, va_list arg)
97{
98 weston_log_timestamp();
99 fprintf(weston_logfile, "libwayland: ");
100 vfprintf(weston_logfile, fmt, arg);
101}
102
103static void
104weston_log_file_open(const char *filename)
105{
106 wl_log_set_handler_server(custom_handler);
107
108 if (filename != NULL) {
109 weston_logfile = fopen(filename, "a");
110 if (weston_logfile)
111 os_fd_set_cloexec(fileno(weston_logfile));
112 }
113
114 if (weston_logfile == NULL)
115 weston_logfile = stderr;
116 else
117 setvbuf(weston_logfile, NULL, _IOLBF, 256);
118}
119
120static void
121weston_log_file_close(void)
122{
123 if ((weston_logfile != stderr) && (weston_logfile != NULL))
124 fclose(weston_logfile);
125 weston_logfile = stderr;
126}
127
128static int
129vlog(const char *fmt, va_list ap)
130{
131 int l;
132
133 l = weston_log_timestamp();
134 l += vfprintf(weston_logfile, fmt, ap);
135
136 return l;
137}
138
139static int
140vlog_continue(const char *fmt, va_list argp)
141{
142 return vfprintf(weston_logfile, fmt, argp);
143}
144
Giulio Camuffobab996e2014-10-12 00:24:25 +0300145static struct wl_list child_process_list;
146static struct weston_compositor *segv_compositor;
147
148static int
149sigchld_handler(int signal_number, void *data)
150{
151 struct weston_process *p;
152 int status;
153 pid_t pid;
154
155 while ((pid = waitpid(-1, &status, WNOHANG)) > 0) {
156 wl_list_for_each(p, &child_process_list, link) {
157 if (p->pid == pid)
158 break;
159 }
160
161 if (&p->link == &child_process_list) {
162 weston_log("unknown child process exited\n");
163 continue;
164 }
165
166 wl_list_remove(&p->link);
167 p->cleanup(p, status);
168 }
169
170 if (pid < 0 && errno != ECHILD)
171 weston_log("waitpid error %m\n");
172
173 return 1;
174}
175
176#ifdef HAVE_LIBUNWIND
177
178static void
179print_backtrace(void)
180{
181 unw_cursor_t cursor;
182 unw_context_t context;
183 unw_word_t off;
184 unw_proc_info_t pip;
185 int ret, i = 0;
186 char procname[256];
187 const char *filename;
188 Dl_info dlinfo;
189
190 pip.unwind_info = NULL;
191 ret = unw_getcontext(&context);
192 if (ret) {
193 weston_log("unw_getcontext: %d\n", ret);
194 return;
195 }
196
197 ret = unw_init_local(&cursor, &context);
198 if (ret) {
199 weston_log("unw_init_local: %d\n", ret);
200 return;
201 }
202
203 ret = unw_step(&cursor);
204 while (ret > 0) {
205 ret = unw_get_proc_info(&cursor, &pip);
206 if (ret) {
207 weston_log("unw_get_proc_info: %d\n", ret);
208 break;
209 }
210
211 ret = unw_get_proc_name(&cursor, procname, 256, &off);
212 if (ret && ret != -UNW_ENOMEM) {
213 if (ret != -UNW_EUNSPEC)
214 weston_log("unw_get_proc_name: %d\n", ret);
215 procname[0] = '?';
216 procname[1] = 0;
217 }
218
219 if (dladdr((void *)(pip.start_ip + off), &dlinfo) && dlinfo.dli_fname &&
220 *dlinfo.dli_fname)
221 filename = dlinfo.dli_fname;
222 else
223 filename = "?";
224
225 weston_log("%u: %s (%s%s+0x%x) [%p]\n", i++, filename, procname,
226 ret == -UNW_ENOMEM ? "..." : "", (int)off, (void *)(pip.start_ip + off));
227
228 ret = unw_step(&cursor);
229 if (ret < 0)
230 weston_log("unw_step: %d\n", ret);
231 }
232}
233
234#else
235
236static void
237print_backtrace(void)
238{
239 void *buffer[32];
240 int i, count;
241 Dl_info info;
242
243 count = backtrace(buffer, ARRAY_LENGTH(buffer));
244 for (i = 0; i < count; i++) {
245 dladdr(buffer[i], &info);
246 weston_log(" [%016lx] %s (%s)\n",
247 (long) buffer[i],
248 info.dli_sname ? info.dli_sname : "--",
249 info.dli_fname);
250 }
251}
252
253#endif
254
Giulio Camuffofba27fb2016-06-02 21:48:10 +0300255static void
256child_client_exec(int sockfd, const char *path)
257{
258 int clientfd;
259 char s[32];
260 sigset_t allsigs;
261
262 /* do not give our signal mask to the new process */
263 sigfillset(&allsigs);
264 sigprocmask(SIG_UNBLOCK, &allsigs, NULL);
265
266 /* Launch clients as the user. Do not lauch clients with wrong euid.*/
267 if (seteuid(getuid()) == -1) {
268 weston_log("compositor: failed seteuid\n");
269 return;
270 }
271
272 /* SOCK_CLOEXEC closes both ends, so we dup the fd to get a
273 * non-CLOEXEC fd to pass through exec. */
274 clientfd = dup(sockfd);
275 if (clientfd == -1) {
276 weston_log("compositor: dup failed: %m\n");
277 return;
278 }
279
280 snprintf(s, sizeof s, "%d", clientfd);
281 setenv("WAYLAND_SOCKET", s, 1);
282
283 if (execl(path, path, NULL) < 0)
284 weston_log("compositor: executing '%s' failed: %m\n",
285 path);
286}
287
288WL_EXPORT struct wl_client *
289weston_client_launch(struct weston_compositor *compositor,
290 struct weston_process *proc,
291 const char *path,
292 weston_process_cleanup_func_t cleanup)
293{
294 int sv[2];
295 pid_t pid;
296 struct wl_client *client;
297
298 weston_log("launching '%s'\n", path);
299
300 if (os_socketpair_cloexec(AF_UNIX, SOCK_STREAM, 0, sv) < 0) {
301 weston_log("weston_client_launch: "
302 "socketpair failed while launching '%s': %m\n",
303 path);
304 return NULL;
305 }
306
307 pid = fork();
308 if (pid == -1) {
309 close(sv[0]);
310 close(sv[1]);
311 weston_log("weston_client_launch: "
312 "fork failed while launching '%s': %m\n", path);
313 return NULL;
314 }
315
316 if (pid == 0) {
317 child_client_exec(sv[1], path);
318 _exit(-1);
319 }
320
321 close(sv[1]);
322
323 client = wl_client_create(compositor->wl_display, sv[0]);
324 if (!client) {
325 close(sv[0]);
326 weston_log("weston_client_launch: "
327 "wl_client_create failed while launching '%s'.\n",
328 path);
329 return NULL;
330 }
331
332 proc->pid = pid;
333 proc->cleanup = cleanup;
334 weston_watch_process(proc);
335
336 return client;
337}
338
Giulio Camuffobab996e2014-10-12 00:24:25 +0300339WL_EXPORT void
340weston_watch_process(struct weston_process *process)
341{
342 wl_list_insert(&child_process_list, &process->link);
343}
344
Giulio Camuffofba27fb2016-06-02 21:48:10 +0300345struct process_info {
346 struct weston_process proc;
347 char *path;
348};
349
350static void
351process_handle_sigchld(struct weston_process *process, int status)
352{
353 struct process_info *pinfo =
354 container_of(process, struct process_info, proc);
355
356 /*
357 * There are no guarantees whether this runs before or after
358 * the wl_client destructor.
359 */
360
361 if (WIFEXITED(status)) {
362 weston_log("%s exited with status %d\n", pinfo->path,
363 WEXITSTATUS(status));
364 } else if (WIFSIGNALED(status)) {
365 weston_log("%s died on signal %d\n", pinfo->path,
366 WTERMSIG(status));
367 } else {
368 weston_log("%s disappeared\n", pinfo->path);
369 }
370
371 free(pinfo->path);
372 free(pinfo);
373}
374
375WL_EXPORT struct wl_client *
376weston_client_start(struct weston_compositor *compositor, const char *path)
377{
378 struct process_info *pinfo;
379 struct wl_client *client;
380
381 pinfo = zalloc(sizeof *pinfo);
382 if (!pinfo)
383 return NULL;
384
385 pinfo->path = strdup(path);
386 if (!pinfo->path)
387 goto out_free;
388
389 client = weston_client_launch(compositor, &pinfo->proc, path,
390 process_handle_sigchld);
391 if (!client)
392 goto out_str;
393
394 return client;
395
396out_str:
397 free(pinfo->path);
398
399out_free:
400 free(pinfo);
401
402 return NULL;
403}
404
Giulio Camuffobab996e2014-10-12 00:24:25 +0300405static void
406log_uname(void)
407{
408 struct utsname usys;
409
410 uname(&usys);
411
412 weston_log("OS: %s, %s, %s, %s\n", usys.sysname, usys.release,
413 usys.version, usys.machine);
414}
415
Giulio Camuffod52f3b72016-06-02 21:48:11 +0300416WL_EXPORT struct weston_config *
417wet_get_config(struct weston_compositor *compositor)
418{
419 return weston_compositor_get_user_data(compositor);
420}
421
Giulio Camuffobab996e2014-10-12 00:24:25 +0300422static const char xdg_error_message[] =
423 "fatal: environment variable XDG_RUNTIME_DIR is not set.\n";
424
425static const char xdg_wrong_message[] =
426 "fatal: environment variable XDG_RUNTIME_DIR\n"
427 "is set to \"%s\", which is not a directory.\n";
428
429static const char xdg_wrong_mode_message[] =
430 "warning: XDG_RUNTIME_DIR \"%s\" is not configured\n"
431 "correctly. Unix access mode must be 0700 (current mode is %o),\n"
432 "and must be owned by the user (current owner is UID %d).\n";
433
434static const char xdg_detail_message[] =
435 "Refer to your distribution on how to get it, or\n"
436 "http://www.freedesktop.org/wiki/Specifications/basedir-spec\n"
437 "on how to implement it.\n";
438
439static void
440verify_xdg_runtime_dir(void)
441{
442 char *dir = getenv("XDG_RUNTIME_DIR");
443 struct stat s;
444
445 if (!dir) {
446 weston_log(xdg_error_message);
447 weston_log_continue(xdg_detail_message);
448 exit(EXIT_FAILURE);
449 }
450
451 if (stat(dir, &s) || !S_ISDIR(s.st_mode)) {
452 weston_log(xdg_wrong_message, dir);
453 weston_log_continue(xdg_detail_message);
454 exit(EXIT_FAILURE);
455 }
456
457 if ((s.st_mode & 0777) != 0700 || s.st_uid != getuid()) {
458 weston_log(xdg_wrong_mode_message,
459 dir, s.st_mode & 0777, s.st_uid);
460 weston_log_continue(xdg_detail_message);
461 }
462}
463
464static int
465usage(int error_code)
466{
467 fprintf(stderr,
468 "Usage: weston [OPTIONS]\n\n"
469 "This is weston version " VERSION ", the Wayland reference compositor.\n"
470 "Weston supports multiple backends, and depending on which backend is in use\n"
471 "different options will be accepted.\n\n"
472
473
474 "Core options:\n\n"
475 " --version\t\tPrint weston version\n"
476 " -B, --backend=MODULE\tBackend module, one of\n"
477#if defined(BUILD_DRM_COMPOSITOR)
478 "\t\t\t\tdrm-backend.so\n"
479#endif
480#if defined(BUILD_FBDEV_COMPOSITOR)
481 "\t\t\t\tfbdev-backend.so\n"
482#endif
Dawid Gajownik71f57042015-07-31 17:39:00 -0300483#if defined(BUILD_HEADLESS_COMPOSITOR)
484 "\t\t\t\theadless-backend.so\n"
Giulio Camuffobab996e2014-10-12 00:24:25 +0300485#endif
486#if defined(BUILD_RDP_COMPOSITOR)
487 "\t\t\t\trdp-backend.so\n"
488#endif
Dawid Gajownik71f57042015-07-31 17:39:00 -0300489#if defined(BUILD_WAYLAND_COMPOSITOR)
490 "\t\t\t\twayland-backend.so\n"
491#endif
492#if defined(BUILD_X11_COMPOSITOR)
493 "\t\t\t\tx11-backend.so\n"
494#endif
Giulio Camuffobab996e2014-10-12 00:24:25 +0300495 " --shell=MODULE\tShell module, defaults to desktop-shell.so\n"
496 " -S, --socket=NAME\tName of socket to listen on\n"
497 " -i, --idle-time=SECS\tIdle time in seconds\n"
498 " --modules\t\tLoad the comma-separated list of modules\n"
499 " --log=FILE\t\tLog to the given file\n"
500 " -c, --config=FILE\tConfig file to load, defaults to weston.ini\n"
501 " --no-config\t\tDo not read weston.ini\n"
502 " -h, --help\t\tThis help message\n\n");
503
504#if defined(BUILD_DRM_COMPOSITOR)
505 fprintf(stderr,
506 "Options for drm-backend.so:\n\n"
507 " --connector=ID\tBring up only this connector\n"
508 " --seat=SEAT\t\tThe seat that weston should run on\n"
509 " --tty=TTY\t\tThe tty to use\n"
510 " --use-pixman\t\tUse the pixman (CPU) renderer\n"
511 " --current-mode\tPrefer current KMS mode over EDID preferred mode\n\n");
512#endif
513
514#if defined(BUILD_FBDEV_COMPOSITOR)
515 fprintf(stderr,
516 "Options for fbdev-backend.so:\n\n"
517 " --tty=TTY\t\tThe tty to use\n"
518 " --device=DEVICE\tThe framebuffer device to use\n"
Pekka Paalanene77f8ad2016-06-08 17:39:37 +0300519 "\n");
Giulio Camuffobab996e2014-10-12 00:24:25 +0300520#endif
521
Dawid Gajownik71f57042015-07-31 17:39:00 -0300522#if defined(BUILD_HEADLESS_COMPOSITOR)
Giulio Camuffobab996e2014-10-12 00:24:25 +0300523 fprintf(stderr,
Dawid Gajownik71f57042015-07-31 17:39:00 -0300524 "Options for headless-backend.so:\n\n"
525 " --width=WIDTH\t\tWidth of memory surface\n"
526 " --height=HEIGHT\tHeight of memory surface\n"
Giulio Camuffobab996e2014-10-12 00:24:25 +0300527 " --transform=TR\tThe output transformation, TR is one of:\n"
528 "\tnormal 90 180 270 flipped flipped-90 flipped-180 flipped-270\n"
Armin Krezovićd84deeb2016-06-23 11:59:29 +0200529 " --use-pixman\t\tUse the pixman (CPU) renderer (default: no rendering)\n"
530 " --no-outputs\t\tDo not create any virtual outputs\n"
531 "\n");
Giulio Camuffobab996e2014-10-12 00:24:25 +0300532#endif
533
534#if defined(BUILD_RDP_COMPOSITOR)
535 fprintf(stderr,
536 "Options for rdp-backend.so:\n\n"
537 " --width=WIDTH\t\tWidth of desktop\n"
538 " --height=HEIGHT\tHeight of desktop\n"
Dawid Gajownikd99a0502015-07-31 14:49:57 -0300539 " --env-socket\t\tUse socket defined in RDP_FD env variable as peer connection\n"
Giulio Camuffobab996e2014-10-12 00:24:25 +0300540 " --address=ADDR\tThe address to bind\n"
541 " --port=PORT\t\tThe port to listen on\n"
542 " --no-clients-resize\tThe RDP peers will be forced to the size of the desktop\n"
543 " --rdp4-key=FILE\tThe file containing the key for RDP4 encryption\n"
544 " --rdp-tls-cert=FILE\tThe file containing the certificate for TLS encryption\n"
545 " --rdp-tls-key=FILE\tThe file containing the private key for TLS encryption\n"
546 "\n");
547#endif
548
Dawid Gajownik71f57042015-07-31 17:39:00 -0300549#if defined(BUILD_WAYLAND_COMPOSITOR)
550 fprintf(stderr,
551 "Options for wayland-backend.so:\n\n"
552 " --width=WIDTH\t\tWidth of Wayland surface\n"
553 " --height=HEIGHT\tHeight of Wayland surface\n"
554 " --scale=SCALE\t\tScale factor of output\n"
555 " --fullscreen\t\tRun in fullscreen mode\n"
556 " --use-pixman\t\tUse the pixman (CPU) renderer\n"
557 " --output-count=COUNT\tCreate multiple outputs\n"
558 " --sprawl\t\tCreate one fullscreen output for every parent output\n"
559 " --display=DISPLAY\tWayland display to connect to\n\n");
560#endif
561
562#if defined(BUILD_X11_COMPOSITOR)
563 fprintf(stderr,
564 "Options for x11-backend.so:\n\n"
565 " --width=WIDTH\t\tWidth of X window\n"
566 " --height=HEIGHT\tHeight of X window\n"
567 " --scale=SCALE\t\tScale factor of output\n"
568 " --fullscreen\t\tRun in fullscreen mode\n"
569 " --use-pixman\t\tUse the pixman (CPU) renderer\n"
570 " --output-count=COUNT\tCreate multiple outputs\n"
571 " --no-input\t\tDont create input devices\n\n");
Giulio Camuffobab996e2014-10-12 00:24:25 +0300572#endif
573
574 exit(error_code);
575}
576
577static int on_term_signal(int signal_number, void *data)
578{
579 struct wl_display *display = data;
580
581 weston_log("caught signal %d\n", signal_number);
582 wl_display_terminate(display);
583
584 return 1;
585}
586
587static void
588on_caught_signal(int s, siginfo_t *siginfo, void *context)
589{
590 /* This signal handler will do a best-effort backtrace, and
591 * then call the backend restore function, which will switch
592 * back to the vt we launched from or ungrab X etc and then
593 * raise SIGTRAP. If we run weston under gdb from X or a
594 * different vt, and tell gdb "handle *s* nostop", this
595 * will allow weston to switch back to gdb on crash and then
596 * gdb will catch the crash with SIGTRAP.*/
597
598 weston_log("caught signal: %d\n", s);
599
600 print_backtrace();
601
602 segv_compositor->backend->restore(segv_compositor);
603
604 raise(SIGTRAP);
605}
606
607static void
608catch_signals(void)
609{
610 struct sigaction action;
611
612 action.sa_flags = SA_SIGINFO | SA_RESETHAND;
613 action.sa_sigaction = on_caught_signal;
614 sigemptyset(&action.sa_mask);
615 sigaction(SIGSEGV, &action, NULL);
616 sigaction(SIGABRT, &action, NULL);
617}
618
619static const char *
620clock_name(clockid_t clk_id)
621{
622 static const char *names[] = {
623 [CLOCK_REALTIME] = "CLOCK_REALTIME",
624 [CLOCK_MONOTONIC] = "CLOCK_MONOTONIC",
625 [CLOCK_MONOTONIC_RAW] = "CLOCK_MONOTONIC_RAW",
626 [CLOCK_REALTIME_COARSE] = "CLOCK_REALTIME_COARSE",
627 [CLOCK_MONOTONIC_COARSE] = "CLOCK_MONOTONIC_COARSE",
Derek Foreman32838c92015-06-29 13:20:34 -0500628#ifdef CLOCK_BOOTTIME
Giulio Camuffobab996e2014-10-12 00:24:25 +0300629 [CLOCK_BOOTTIME] = "CLOCK_BOOTTIME",
Derek Foreman32838c92015-06-29 13:20:34 -0500630#endif
Giulio Camuffobab996e2014-10-12 00:24:25 +0300631 };
632
633 if (clk_id < 0 || (unsigned)clk_id >= ARRAY_LENGTH(names))
634 return "unknown";
635
636 return names[clk_id];
637}
638
639static const struct {
640 uint32_t bit; /* enum weston_capability */
641 const char *desc;
642} capability_strings[] = {
643 { WESTON_CAP_ROTATION_ANY, "arbitrary surface rotation:" },
644 { WESTON_CAP_CAPTURE_YFLIP, "screen capture uses y-flip:" },
645};
646
647static void
648weston_compositor_log_capabilities(struct weston_compositor *compositor)
649{
650 unsigned i;
651 int yes;
Pekka Paalanenbe112d42016-04-18 15:53:38 +0300652 struct timespec res;
Giulio Camuffobab996e2014-10-12 00:24:25 +0300653
654 weston_log("Compositor capabilities:\n");
655 for (i = 0; i < ARRAY_LENGTH(capability_strings); i++) {
656 yes = compositor->capabilities & capability_strings[i].bit;
657 weston_log_continue(STAMP_SPACE "%s %s\n",
658 capability_strings[i].desc,
659 yes ? "yes" : "no");
660 }
661
662 weston_log_continue(STAMP_SPACE "presentation clock: %s, id %d\n",
663 clock_name(compositor->presentation_clock),
664 compositor->presentation_clock);
Pekka Paalanenbe112d42016-04-18 15:53:38 +0300665
666 if (clock_getres(compositor->presentation_clock, &res) == 0)
667 weston_log_continue(STAMP_SPACE
668 "presentation clock resolution: %d.%09ld s\n",
669 (int)res.tv_sec, res.tv_nsec);
670 else
671 weston_log_continue(STAMP_SPACE
672 "presentation clock resolution: N/A\n");
Giulio Camuffobab996e2014-10-12 00:24:25 +0300673}
674
675static void
676handle_primary_client_destroyed(struct wl_listener *listener, void *data)
677{
678 struct wl_client *client = data;
679
680 weston_log("Primary client died. Closing...\n");
681
682 wl_display_terminate(wl_client_get_display(client));
683}
684
685static int
686weston_create_listening_socket(struct wl_display *display, const char *socket_name)
687{
688 if (socket_name) {
689 if (wl_display_add_socket(display, socket_name)) {
690 weston_log("fatal: failed to add socket: %m\n");
691 return -1;
692 }
693 } else {
694 socket_name = wl_display_add_socket_auto(display);
695 if (!socket_name) {
696 weston_log("fatal: failed to add socket: %m\n");
697 return -1;
698 }
699 }
700
701 setenv("WAYLAND_DISPLAY", socket_name, 1);
702
703 return 0;
704}
705
Giulio Camuffo179fcda2016-06-02 21:48:14 +0300706WL_EXPORT void *
707wet_load_module(const char *name, const char *entrypoint)
708{
709 const char *builddir = getenv("WESTON_BUILD_DIR");
710 char path[PATH_MAX];
711 void *module, *init;
712
713 if (name == NULL)
714 return NULL;
715
716 if (name[0] != '/') {
717 if (builddir)
718 snprintf(path, sizeof path, "%s/.libs/%s", builddir, name);
719 else
720 snprintf(path, sizeof path, "%s/%s", MODULEDIR, name);
721 } else {
722 snprintf(path, sizeof path, "%s", name);
723 }
724
725 module = dlopen(path, RTLD_NOW | RTLD_NOLOAD);
726 if (module) {
727 weston_log("Module '%s' already loaded\n", path);
728 dlclose(module);
729 return NULL;
730 }
731
732 weston_log("Loading module '%s'\n", path);
733 module = dlopen(path, RTLD_NOW);
734 if (!module) {
735 weston_log("Failed to load module: %s\n", dlerror());
736 return NULL;
737 }
738
739 init = dlsym(module, entrypoint);
740 if (!init) {
741 weston_log("Failed to lookup init function: %s\n", dlerror());
742 dlclose(module);
743 return NULL;
744 }
745
746 return init;
747}
748
Giulio Camuffobab996e2014-10-12 00:24:25 +0300749static int
750load_modules(struct weston_compositor *ec, const char *modules,
751 int *argc, char *argv[])
752{
753 const char *p, *end;
754 char buffer[256];
755 int (*module_init)(struct weston_compositor *ec,
756 int *argc, char *argv[]);
757
758 if (modules == NULL)
759 return 0;
760
761 p = modules;
762 while (*p) {
763 end = strchrnul(p, ',');
764 snprintf(buffer, sizeof buffer, "%.*s", (int) (end - p), p);
Giulio Camuffo9c764df2016-06-29 11:54:27 +0200765
766 if (strstr(buffer, "xwayland.so")) {
767 if (wet_load_xwayland(ec) < 0)
768 return -1;
769 } else {
770 module_init = wet_load_module(buffer, "module_init");
771 if (!module_init)
772 return -1;
773 if (module_init(ec, argc, argv) < 0)
774 return -1;
775 }
Giulio Camuffobab996e2014-10-12 00:24:25 +0300776 p = end;
777 while (*p == ',')
778 p++;
779
780 }
781
782 return 0;
783}
784
785static int
786weston_compositor_init_config(struct weston_compositor *ec,
787 struct weston_config *config)
788{
789 struct xkb_rule_names xkb_names;
790 struct weston_config_section *s;
791 int repaint_msec;
Bob Ham91880f12016-01-12 10:21:47 +0000792 int vt_switching;
Giulio Camuffobab996e2014-10-12 00:24:25 +0300793
794 s = weston_config_get_section(config, "keyboard", NULL, NULL);
795 weston_config_section_get_string(s, "keymap_rules",
796 (char **) &xkb_names.rules, NULL);
797 weston_config_section_get_string(s, "keymap_model",
798 (char **) &xkb_names.model, NULL);
799 weston_config_section_get_string(s, "keymap_layout",
800 (char **) &xkb_names.layout, NULL);
801 weston_config_section_get_string(s, "keymap_variant",
802 (char **) &xkb_names.variant, NULL);
803 weston_config_section_get_string(s, "keymap_options",
804 (char **) &xkb_names.options, NULL);
805
Giulio Camuffo0358af42016-06-02 21:48:08 +0300806 if (weston_compositor_set_xkb_rule_names(ec, &xkb_names) < 0)
Giulio Camuffobab996e2014-10-12 00:24:25 +0300807 return -1;
808
809 weston_config_section_get_int(s, "repeat-rate",
810 &ec->kb_repeat_rate, 40);
811 weston_config_section_get_int(s, "repeat-delay",
812 &ec->kb_repeat_delay, 400);
813
Bob Ham91880f12016-01-12 10:21:47 +0000814 weston_config_section_get_bool(s, "vt-switching",
815 &vt_switching, true);
816 ec->vt_switching = vt_switching;
817
Giulio Camuffobab996e2014-10-12 00:24:25 +0300818 s = weston_config_get_section(config, "core", NULL, NULL);
819 weston_config_section_get_int(s, "repaint-window", &repaint_msec,
820 ec->repaint_msec);
821 if (repaint_msec < -10 || repaint_msec > 1000) {
822 weston_log("Invalid repaint_window value in config: %d\n",
823 repaint_msec);
824 } else {
825 ec->repaint_msec = repaint_msec;
826 }
827 weston_log("Output repaint window is %d ms maximum.\n",
828 ec->repaint_msec);
829
830 return 0;
831}
832
833static char *
834weston_choose_default_backend(void)
835{
836 char *backend = NULL;
837
838 if (getenv("WAYLAND_DISPLAY") || getenv("WAYLAND_SOCKET"))
839 backend = strdup("wayland-backend.so");
840 else if (getenv("DISPLAY"))
841 backend = strdup("x11-backend.so");
842 else
843 backend = strdup(WESTON_NATIVE_BACKEND);
844
845 return backend;
846}
847
848static const struct { const char *name; uint32_t token; } transforms[] = {
849 { "normal", WL_OUTPUT_TRANSFORM_NORMAL },
850 { "90", WL_OUTPUT_TRANSFORM_90 },
851 { "180", WL_OUTPUT_TRANSFORM_180 },
852 { "270", WL_OUTPUT_TRANSFORM_270 },
853 { "flipped", WL_OUTPUT_TRANSFORM_FLIPPED },
854 { "flipped-90", WL_OUTPUT_TRANSFORM_FLIPPED_90 },
855 { "flipped-180", WL_OUTPUT_TRANSFORM_FLIPPED_180 },
856 { "flipped-270", WL_OUTPUT_TRANSFORM_FLIPPED_270 },
857};
858
859WL_EXPORT int
860weston_parse_transform(const char *transform, uint32_t *out)
861{
862 unsigned int i;
863
864 for (i = 0; i < ARRAY_LENGTH(transforms); i++)
865 if (strcmp(transforms[i].name, transform) == 0) {
866 *out = transforms[i].token;
867 return 0;
868 }
869
870 *out = WL_OUTPUT_TRANSFORM_NORMAL;
871 return -1;
872}
873
874WL_EXPORT const char *
875weston_transform_to_string(uint32_t output_transform)
876{
877 unsigned int i;
878
879 for (i = 0; i < ARRAY_LENGTH(transforms); i++)
880 if (transforms[i].token == output_transform)
881 return transforms[i].name;
882
883 return "<illegal value>";
884}
885
886static int
887load_configuration(struct weston_config **config, int32_t noconfig,
888 const char *config_file)
889{
890 const char *file = "weston.ini";
891 const char *full_path;
892
893 *config = NULL;
894
895 if (config_file)
896 file = config_file;
897
898 if (noconfig == 0)
899 *config = weston_config_parse(file);
900
901 if (*config) {
902 full_path = weston_config_get_full_path(*config);
903
904 weston_log("Using config file '%s'\n", full_path);
905 setenv(WESTON_CONFIG_FILE_ENV_VAR, full_path, 1);
906
907 return 0;
908 }
909
910 if (config_file && noconfig == 0) {
911 weston_log("fatal: error opening or reading config file"
912 " '%s'.\n", config_file);
913
914 return -1;
915 }
916
917 weston_log("Starting with no config file.\n");
918 setenv(WESTON_CONFIG_FILE_ENV_VAR, "", 1);
919
920 return 0;
921}
922
923static void
924handle_exit(struct weston_compositor *c)
925{
926 wl_display_terminate(c->wl_display);
927}
928
Giulio Camuffo1c0e40d2016-04-29 15:40:34 -0700929static enum weston_drm_backend_output_mode
930drm_configure_output(struct weston_compositor *c,
931 bool use_current_mode,
932 const char *name,
933 struct weston_drm_backend_output_config *config)
934{
Giulio Camuffod52f3b72016-06-02 21:48:11 +0300935 struct weston_config *wc = wet_get_config(c);
Giulio Camuffo1c0e40d2016-04-29 15:40:34 -0700936 struct weston_config_section *section;
937 char *s;
938 int scale;
939 enum weston_drm_backend_output_mode mode =
940 WESTON_DRM_BACKEND_OUTPUT_PREFERRED;
941
942 section = weston_config_get_section(wc, "output", "name", name);
943 weston_config_section_get_string(section, "mode", &s, "preferred");
944 if (strcmp(s, "off") == 0) {
945 free(s);
946 return WESTON_DRM_BACKEND_OUTPUT_OFF;
947 }
948
949 if (use_current_mode || strcmp(s, "current") == 0) {
950 mode = WESTON_DRM_BACKEND_OUTPUT_CURRENT;
951 } else if (strcmp(s, "preferred") != 0) {
952 config->modeline = s;
953 s = NULL;
954 }
955 free(s);
956
957 weston_config_section_get_int(section, "scale", &scale, 1);
958 config->base.scale = scale >= 1 ? scale : 1;
959 weston_config_section_get_string(section, "transform", &s, "normal");
960 if (weston_parse_transform(s, &config->base.transform) < 0)
961 weston_log("Invalid transform \"%s\" for output %s\n",
962 s, name);
963 free(s);
964
965 weston_config_section_get_string(section,
966 "gbm-format", &config->gbm_format, NULL);
967 weston_config_section_get_string(section, "seat", &config->seat, "");
968 return mode;
969}
970
Giulio Camuffo8aedf7b2016-06-02 21:48:12 +0300971static void
972configure_input_device(struct weston_compositor *compositor,
973 struct libinput_device *device)
974{
975 struct weston_config_section *s;
976 struct weston_config *config = wet_get_config(compositor);
977 int enable_tap;
978 int enable_tap_default;
979
980 s = weston_config_get_section(config,
981 "libinput", NULL, NULL);
982
983 if (libinput_device_config_tap_get_finger_count(device) > 0) {
984 enable_tap_default =
985 libinput_device_config_tap_get_default_enabled(
986 device);
987 weston_config_section_get_bool(s, "enable_tap",
988 &enable_tap,
989 enable_tap_default);
990 libinput_device_config_tap_set_enabled(device,
991 enable_tap);
992 }
993}
994
Giulio Camuffo1c0e40d2016-04-29 15:40:34 -0700995static int
Pekka Paalanen321ede72016-06-03 15:28:40 +0300996load_drm_backend(struct weston_compositor *c,
Giulio Camuffo1c0e40d2016-04-29 15:40:34 -0700997 int *argc, char **argv, struct weston_config *wc)
998{
999 struct weston_drm_backend_config config = {{ 0, }};
1000 struct weston_config_section *section;
1001 int ret = 0;
1002
1003 const struct weston_option options[] = {
1004 { WESTON_OPTION_INTEGER, "connector", 0, &config.connector },
1005 { WESTON_OPTION_STRING, "seat", 0, &config.seat_id },
1006 { WESTON_OPTION_INTEGER, "tty", 0, &config.tty },
1007 { WESTON_OPTION_BOOLEAN, "current-mode", 0, &config.use_current_mode },
1008 { WESTON_OPTION_BOOLEAN, "use-pixman", 0, &config.use_pixman },
1009 };
1010
1011 parse_options(options, ARRAY_LENGTH(options), argc, argv);
1012
1013 section = weston_config_get_section(wc, "core", NULL, NULL);
1014 weston_config_section_get_string(section,
1015 "gbm-format", &config.gbm_format,
1016 NULL);
1017
1018 config.base.struct_version = WESTON_DRM_BACKEND_CONFIG_VERSION;
1019 config.base.struct_size = sizeof(struct weston_drm_backend_config);
1020 config.configure_output = drm_configure_output;
Giulio Camuffo8aedf7b2016-06-02 21:48:12 +03001021 config.configure_device = configure_input_device;
Giulio Camuffo1c0e40d2016-04-29 15:40:34 -07001022
Pekka Paalanen50dbf382016-06-03 15:23:46 +03001023 ret = weston_compositor_load_backend(c, WESTON_BACKEND_DRM,
1024 &config.base);
Giulio Camuffo1c0e40d2016-04-29 15:40:34 -07001025
1026 free(config.gbm_format);
1027 free(config.seat_id);
1028
1029 return ret;
1030}
1031
Giulio Camuffo43008c72015-10-17 19:24:15 +03001032static int
Pekka Paalanen321ede72016-06-03 15:28:40 +03001033load_headless_backend(struct weston_compositor *c,
Benoit Gschwind3c530942016-04-15 20:28:32 -07001034 int *argc, char **argv, struct weston_config *wc)
1035{
1036 struct weston_headless_backend_config config = {{ 0, }};
1037 int ret = 0;
Benoit Gschwind2da6d0c2016-04-29 15:21:54 +02001038 char *transform = NULL;
Benoit Gschwind3c530942016-04-15 20:28:32 -07001039
1040 config.width = 1024;
1041 config.height = 640;
1042
1043 const struct weston_option options[] = {
1044 { WESTON_OPTION_INTEGER, "width", 0, &config.width },
1045 { WESTON_OPTION_INTEGER, "height", 0, &config.height },
1046 { WESTON_OPTION_BOOLEAN, "use-pixman", 0, &config.use_pixman },
1047 { WESTON_OPTION_STRING, "transform", 0, &transform },
Armin Krezovićd84deeb2016-06-23 11:59:29 +02001048 { WESTON_OPTION_BOOLEAN, "no-outputs", 0, &config.no_outputs },
Benoit Gschwind3c530942016-04-15 20:28:32 -07001049 };
1050
1051 parse_options(options, ARRAY_LENGTH(options), argc, argv);
1052
Benoit Gschwind2da6d0c2016-04-29 15:21:54 +02001053 config.transform = WL_OUTPUT_TRANSFORM_NORMAL;
1054 if (transform) {
1055 if (weston_parse_transform(transform, &config.transform) < 0)
1056 weston_log("Invalid transform \"%s\"\n", transform);
1057 free(transform);
1058 }
Benoit Gschwind3c530942016-04-15 20:28:32 -07001059
1060 config.base.struct_version = WESTON_HEADLESS_BACKEND_CONFIG_VERSION;
1061 config.base.struct_size = sizeof(struct weston_headless_backend_config);
1062
1063 /* load the actual wayland backend and configure it */
Pekka Paalanen50dbf382016-06-03 15:23:46 +03001064 ret = weston_compositor_load_backend(c, WESTON_BACKEND_HEADLESS,
1065 &config.base);
Benoit Gschwind3c530942016-04-15 20:28:32 -07001066
1067 return ret;
1068}
1069
Benoit Gschwindbd573102016-04-22 17:05:26 +02001070static void
1071weston_rdp_backend_config_init(struct weston_rdp_backend_config *config)
1072{
1073 config->base.struct_version = WESTON_RDP_BACKEND_CONFIG_VERSION;
1074 config->base.struct_size = sizeof(struct weston_rdp_backend_config);
1075
1076 config->width = 640;
1077 config->height = 480;
1078 config->bind_address = NULL;
1079 config->port = 3389;
1080 config->rdp_key = NULL;
1081 config->server_cert = NULL;
1082 config->server_key = NULL;
1083 config->env_socket = 0;
1084 config->no_clients_resize = 0;
1085}
1086
1087static int
Pekka Paalanen321ede72016-06-03 15:28:40 +03001088load_rdp_backend(struct weston_compositor *c,
Benoit Gschwindbd573102016-04-22 17:05:26 +02001089 int *argc, char *argv[], struct weston_config *wc)
1090{
1091 struct weston_rdp_backend_config config = {{ 0, }};
1092 int ret = 0;
1093
1094 weston_rdp_backend_config_init(&config);
1095
1096 const struct weston_option rdp_options[] = {
1097 { WESTON_OPTION_BOOLEAN, "env-socket", 0, &config.env_socket },
1098 { WESTON_OPTION_INTEGER, "width", 0, &config.width },
1099 { WESTON_OPTION_INTEGER, "height", 0, &config.height },
1100 { WESTON_OPTION_STRING, "address", 0, &config.bind_address },
1101 { WESTON_OPTION_INTEGER, "port", 0, &config.port },
1102 { WESTON_OPTION_BOOLEAN, "no-clients-resize", 0, &config.no_clients_resize },
1103 { WESTON_OPTION_STRING, "rdp4-key", 0, &config.rdp_key },
1104 { WESTON_OPTION_STRING, "rdp-tls-cert", 0, &config.server_cert },
1105 { WESTON_OPTION_STRING, "rdp-tls-key", 0, &config.server_key }
1106 };
1107
1108 parse_options(rdp_options, ARRAY_LENGTH(rdp_options), argc, argv);
1109
Pekka Paalanen50dbf382016-06-03 15:23:46 +03001110 ret = weston_compositor_load_backend(c, WESTON_BACKEND_RDP,
1111 &config.base);
Benoit Gschwindbd573102016-04-22 17:05:26 +02001112
1113 free(config.bind_address);
1114 free(config.rdp_key);
1115 free(config.server_cert);
1116 free(config.server_key);
1117 return ret;
1118}
1119
Benoit Gschwind3c530942016-04-15 20:28:32 -07001120static int
Pekka Paalanen321ede72016-06-03 15:28:40 +03001121load_fbdev_backend(struct weston_compositor *c,
Benoit Gschwind934e89a2016-04-27 23:56:42 +02001122 int *argc, char **argv, struct weston_config *wc)
1123{
1124 struct weston_fbdev_backend_config config = {{ 0, }};
1125 struct weston_config_section *section;
1126 char *s = NULL;
1127 int ret = 0;
1128
1129 const struct weston_option fbdev_options[] = {
1130 { WESTON_OPTION_INTEGER, "tty", 0, &config.tty },
1131 { WESTON_OPTION_STRING, "device", 0, &config.device },
Benoit Gschwind934e89a2016-04-27 23:56:42 +02001132 };
1133
1134 parse_options(fbdev_options, ARRAY_LENGTH(fbdev_options), argc, argv);
1135
1136 if (!config.device)
1137 config.device = strdup("/dev/fb0");
1138
1139 section = weston_config_get_section(wc, "output", "name", "fbdev");
1140 weston_config_section_get_string(section, "transform", &s, "normal");
1141 if (weston_parse_transform(s, &config.output_transform) < 0)
1142 weston_log("Invalid transform \"%s\" for output fbdev\n", s);
1143 free(s);
1144
1145 config.base.struct_version = WESTON_FBDEV_BACKEND_CONFIG_VERSION;
1146 config.base.struct_size = sizeof(struct weston_fbdev_backend_config);
Giulio Camuffo8aedf7b2016-06-02 21:48:12 +03001147 config.configure_device = configure_input_device;
Benoit Gschwind934e89a2016-04-27 23:56:42 +02001148
1149 /* load the actual wayland backend and configure it */
Pekka Paalanen50dbf382016-06-03 15:23:46 +03001150 ret = weston_compositor_load_backend(c, WESTON_BACKEND_FBDEV,
1151 &config.base);
Benoit Gschwind934e89a2016-04-27 23:56:42 +02001152
1153 free(config.device);
Benoit Gschwinde16acab2016-04-15 20:28:31 -07001154
1155 return ret;
1156}
1157
1158static int
1159weston_x11_backend_config_append_output_config(struct weston_x11_backend_config *config,
1160 struct weston_x11_backend_output_config *output_config) {
1161 struct weston_x11_backend_output_config *new_outputs;
1162
1163 new_outputs = realloc(config->outputs, (config->num_outputs+1) *
1164 sizeof(struct weston_x11_backend_output_config));
1165 if (new_outputs == NULL)
1166 return -1;
1167
1168 config->outputs = new_outputs;
1169 config->outputs[config->num_outputs].width = output_config->width;
1170 config->outputs[config->num_outputs].height = output_config->height;
1171 config->outputs[config->num_outputs].transform = output_config->transform;
1172 config->outputs[config->num_outputs].scale = output_config->scale;
1173 config->outputs[config->num_outputs].name = strdup(output_config->name);
1174 config->num_outputs++;
1175
1176 return 0;
1177}
1178
1179static int
Pekka Paalanen321ede72016-06-03 15:28:40 +03001180load_x11_backend(struct weston_compositor *c,
Benoit Gschwinde16acab2016-04-15 20:28:31 -07001181 int *argc, char **argv, struct weston_config *wc)
1182{
1183 struct weston_x11_backend_output_config default_output;
1184 struct weston_x11_backend_config config = {{ 0, }};
1185 struct weston_config_section *section;
1186 int ret = 0;
1187 int option_width = 0;
1188 int option_height = 0;
1189 int option_scale = 0;
1190 int option_count = 1;
1191 int output_count = 0;
1192 char const *section_name;
1193 int i;
1194 uint32_t j;
1195
1196 const struct weston_option options[] = {
1197 { WESTON_OPTION_INTEGER, "width", 0, &option_width },
1198 { WESTON_OPTION_INTEGER, "height", 0, &option_height },
1199 { WESTON_OPTION_INTEGER, "scale", 0, &option_scale },
1200 { WESTON_OPTION_BOOLEAN, "fullscreen", 'f', &config.fullscreen },
1201 { WESTON_OPTION_INTEGER, "output-count", 0, &option_count },
1202 { WESTON_OPTION_BOOLEAN, "no-input", 0, &config.no_input },
1203 { WESTON_OPTION_BOOLEAN, "use-pixman", 0, &config.use_pixman },
1204 };
1205
1206 parse_options(options, ARRAY_LENGTH(options), argc, argv);
1207
1208 section = NULL;
1209 while (weston_config_next_section(wc, &section, &section_name)) {
1210 struct weston_x11_backend_output_config current_output = { 0, };
1211 char *t;
1212 char *mode;
1213
1214 if (strcmp(section_name, "output") != 0) {
1215 continue;
1216 }
1217
1218 weston_config_section_get_string(section, "name", &current_output.name, NULL);
1219 if (current_output.name == NULL || current_output.name[0] != 'X') {
1220 free(current_output.name);
1221 continue;
1222 }
1223
1224 weston_config_section_get_string(section, "mode", &mode, "1024x600");
1225 if (sscanf(mode, "%dx%d", &current_output.width,
1226 &current_output.height) != 2) {
1227 weston_log("Invalid mode \"%s\" for output %s\n",
1228 mode, current_output.name);
1229 current_output.width = 1024;
1230 current_output.height = 600;
1231 }
1232 free(mode);
1233 if (current_output.width < 1)
1234 current_output.width = 1024;
1235 if (current_output.height < 1)
1236 current_output.height = 600;
1237 if (option_width)
1238 current_output.width = option_width;
1239 if (option_height)
1240 current_output.height = option_height;
1241
1242 weston_config_section_get_int(section, "scale", &current_output.scale, 1);
1243 if (option_scale)
1244 current_output.scale = option_scale;
1245
1246 weston_config_section_get_string(section,
1247 "transform", &t, "normal");
1248 if (weston_parse_transform(t, &current_output.transform) < 0)
1249 weston_log("Invalid transform \"%s\" for output %s\n",
1250 t, current_output.name);
1251 free(t);
1252
1253 if (weston_x11_backend_config_append_output_config(&config, &current_output) < 0) {
1254 ret = -1;
1255 goto out;
1256 }
1257
1258 output_count++;
Bryce Harringtonaa258982016-05-03 01:34:23 -07001259 if (output_count >= option_count)
Benoit Gschwinde16acab2016-04-15 20:28:31 -07001260 break;
1261 }
1262
1263 default_output.name = NULL;
1264 default_output.width = option_width ? option_width : 1024;
1265 default_output.height = option_height ? option_height : 600;
1266 default_output.scale = option_scale ? option_scale : 1;
1267 default_output.transform = WL_OUTPUT_TRANSFORM_NORMAL;
1268
1269 for (i = output_count; i < option_count; i++) {
1270 if (asprintf(&default_output.name, "screen%d", i) < 0) {
1271 ret = -1;
1272 goto out;
1273 }
1274
1275 if (weston_x11_backend_config_append_output_config(&config, &default_output) < 0) {
1276 ret = -1;
1277 free(default_output.name);
1278 goto out;
1279 }
1280 free(default_output.name);
1281 }
1282
1283 config.base.struct_version = WESTON_X11_BACKEND_CONFIG_VERSION;
1284 config.base.struct_size = sizeof(struct weston_x11_backend_config);
1285
1286 /* load the actual backend and configure it */
Pekka Paalanen50dbf382016-06-03 15:23:46 +03001287 ret = weston_compositor_load_backend(c, WESTON_BACKEND_X11,
1288 &config.base);
Benoit Gschwinde16acab2016-04-15 20:28:31 -07001289
1290out:
1291 for (j = 0; j < config.num_outputs; ++j)
1292 free(config.outputs[j].name);
1293 free(config.outputs);
1294
Benoit Gschwind934e89a2016-04-27 23:56:42 +02001295 return ret;
1296}
1297
Benoit Gschwind3ff10da2016-05-10 22:47:49 +02001298static void
1299weston_wayland_output_config_init(struct weston_wayland_backend_output_config *output_config,
1300 struct weston_config_section *config_section,
1301 int option_width, int option_height,
1302 int option_scale)
1303{
1304 char *mode, *t, *str;
1305 unsigned int slen;
1306
1307 weston_config_section_get_string(config_section, "name", &output_config->name,
1308 NULL);
1309 if (output_config->name) {
1310 slen = strlen(output_config->name);
1311 slen += strlen(WINDOW_TITLE " - ");
1312 str = malloc(slen + 1);
1313 if (str)
1314 snprintf(str, slen + 1, WINDOW_TITLE " - %s",
1315 output_config->name);
1316 free(output_config->name);
1317 output_config->name = str;
1318 }
1319 if (!output_config->name)
1320 output_config->name = strdup(WINDOW_TITLE);
1321
1322 weston_config_section_get_string(config_section,
1323 "mode", &mode, "1024x600");
1324 if (sscanf(mode, "%dx%d", &output_config->width, &output_config->height) != 2) {
1325 weston_log("Invalid mode \"%s\" for output %s\n",
1326 mode, output_config->name);
1327 output_config->width = 1024;
1328 output_config->height = 640;
1329 }
1330 free(mode);
1331
1332 if (option_width)
1333 output_config->width = option_width;
1334 if (option_height)
1335 output_config->height = option_height;
1336
1337 weston_config_section_get_int(config_section, "scale", &output_config->scale, 1);
1338
1339 if (option_scale)
1340 output_config->scale = option_scale;
1341
1342 weston_config_section_get_string(config_section,
1343 "transform", &t, "normal");
1344 if (weston_parse_transform(t, &output_config->transform) < 0)
1345 weston_log("Invalid transform \"%s\" for output %s\n",
1346 t, output_config->name);
1347 free(t);
1348
1349}
1350
1351static void
Benoit Gschwinde48ab5f2016-05-10 22:47:55 +02001352weston_wayland_backend_config_release(struct weston_wayland_backend_config *config)
Benoit Gschwind3ff10da2016-05-10 22:47:49 +02001353{
1354 int i;
1355
Benoit Gschwinde48ab5f2016-05-10 22:47:55 +02001356 for (i = 0; i < config->num_outputs; ++i) {
1357 free(config->outputs[i].name);
Benoit Gschwind3ff10da2016-05-10 22:47:49 +02001358 }
Benoit Gschwinde48ab5f2016-05-10 22:47:55 +02001359 free(config->cursor_theme);
1360 free(config->display_name);
1361 free(config->outputs);
Benoit Gschwind3ff10da2016-05-10 22:47:49 +02001362}
1363
1364/*
1365 * Append a new output struct at the end of new_config.outputs and return a
1366 * pointer to the newly allocated structure or NULL if fail. The allocated
1367 * structure is NOT cleared nor set to default values.
1368 */
1369static struct weston_wayland_backend_output_config *
Benoit Gschwind44e302b2016-05-10 22:47:56 +02001370weston_wayland_backend_config_add_new_output(struct weston_wayland_backend_config *config)
Benoit Gschwind3ff10da2016-05-10 22:47:49 +02001371{
1372 struct weston_wayland_backend_output_config *outputs;
1373 const size_t element_size = sizeof(struct weston_wayland_backend_output_config);
1374
Benoit Gschwind44e302b2016-05-10 22:47:56 +02001375 outputs = realloc(config->outputs,
1376 (config->num_outputs + 1) * element_size);
Benoit Gschwind3ff10da2016-05-10 22:47:49 +02001377 if (!outputs)
1378 return NULL;
Benoit Gschwind44e302b2016-05-10 22:47:56 +02001379 config->num_outputs += 1;
1380 config->outputs = outputs;
1381 return &(config->outputs[config->num_outputs - 1]);
Benoit Gschwind3ff10da2016-05-10 22:47:49 +02001382}
1383
1384static int
1385load_wayland_backend_config(struct weston_compositor *compositor, int *argc,
Benoit Gschwind6c1cd2f2016-05-10 22:47:50 +02001386 char *argv[], struct weston_config *wc,
Benoit Gschwind55a22882016-05-10 22:47:51 +02001387 struct weston_wayland_backend_config *config)
Benoit Gschwind3ff10da2016-05-10 22:47:49 +02001388{
Benoit Gschwind3ff10da2016-05-10 22:47:49 +02001389 struct weston_config_section *section;
1390 struct weston_wayland_backend_output_config *oc;
1391 int count, width, height, scale;
1392 const char *section_name;
1393 char *name;
1394
1395 const struct weston_option wayland_options[] = {
1396 { WESTON_OPTION_INTEGER, "width", 0, &width },
1397 { WESTON_OPTION_INTEGER, "height", 0, &height },
1398 { WESTON_OPTION_INTEGER, "scale", 0, &scale },
Benoit Gschwind55a22882016-05-10 22:47:51 +02001399 { WESTON_OPTION_STRING, "display", 0, &config->display_name },
1400 { WESTON_OPTION_BOOLEAN, "use-pixman", 0, &config->use_pixman },
Benoit Gschwind3ff10da2016-05-10 22:47:49 +02001401 { WESTON_OPTION_INTEGER, "output-count", 0, &count },
Benoit Gschwind55a22882016-05-10 22:47:51 +02001402 { WESTON_OPTION_BOOLEAN, "fullscreen", 0, &config->fullscreen },
1403 { WESTON_OPTION_BOOLEAN, "sprawl", 0, &config->sprawl },
Benoit Gschwind3ff10da2016-05-10 22:47:49 +02001404 };
1405
1406 width = 0;
1407 height = 0;
1408 scale = 0;
Benoit Gschwind55a22882016-05-10 22:47:51 +02001409 config->display_name = NULL;
1410 config->use_pixman = 0;
Benoit Gschwind3ff10da2016-05-10 22:47:49 +02001411 count = 1;
Benoit Gschwind55a22882016-05-10 22:47:51 +02001412 config->fullscreen = 0;
1413 config->sprawl = 0;
Benoit Gschwind3ff10da2016-05-10 22:47:49 +02001414 parse_options(wayland_options,
1415 ARRAY_LENGTH(wayland_options), argc, argv);
1416
Benoit Gschwind55a22882016-05-10 22:47:51 +02001417 config->cursor_size = 32;
1418 config->cursor_theme = NULL;
1419 config->base.struct_size = sizeof(struct weston_wayland_backend_config);
1420 config->base.struct_version = WESTON_WAYLAND_BACKEND_CONFIG_VERSION;
Benoit Gschwind3ff10da2016-05-10 22:47:49 +02001421
Benoit Gschwind6c1cd2f2016-05-10 22:47:50 +02001422 section = weston_config_get_section(wc, "shell", NULL, NULL);
Benoit Gschwind3ff10da2016-05-10 22:47:49 +02001423 weston_config_section_get_string(section, "cursor-theme",
Benoit Gschwind55a22882016-05-10 22:47:51 +02001424 &config->cursor_theme, NULL);
Benoit Gschwind3ff10da2016-05-10 22:47:49 +02001425 weston_config_section_get_int(section, "cursor-size",
Benoit Gschwind55a22882016-05-10 22:47:51 +02001426 &config->cursor_size, 32);
Benoit Gschwind3ff10da2016-05-10 22:47:49 +02001427
Benoit Gschwind55a22882016-05-10 22:47:51 +02001428 if (config->sprawl) {
Benoit Gschwind3ff10da2016-05-10 22:47:49 +02001429 /* do nothing, everything is already set */
Benoit Gschwind3ff10da2016-05-10 22:47:49 +02001430 return 0;
1431 }
1432
Benoit Gschwind55a22882016-05-10 22:47:51 +02001433 if (config->fullscreen) {
Benoit Gschwind390af6d2016-05-10 22:47:52 +02001434 oc = weston_wayland_backend_config_add_new_output(config);
Benoit Gschwind3ff10da2016-05-10 22:47:49 +02001435 if (!oc)
Benoit Gschwind53753842016-05-10 22:47:57 +02001436 return -1;
Benoit Gschwind3ff10da2016-05-10 22:47:49 +02001437
1438 oc->width = width;
1439 oc->height = height;
1440 oc->name = NULL;
1441 oc->transform = WL_OUTPUT_TRANSFORM_NORMAL;
1442 oc->scale = 1;
1443
Benoit Gschwind3ff10da2016-05-10 22:47:49 +02001444 return 0;
1445 }
1446
1447 section = NULL;
Benoit Gschwind6c1cd2f2016-05-10 22:47:50 +02001448 while (weston_config_next_section(wc, &section, &section_name)) {
Benoit Gschwind3ff10da2016-05-10 22:47:49 +02001449 if (!section_name || strcmp(section_name, "output") != 0)
1450 continue;
1451 weston_config_section_get_string(section, "name", &name, NULL);
1452 if (name == NULL)
1453 continue;
1454
1455 if (name[0] != 'W' || name[1] != 'L') {
1456 free(name);
1457 continue;
1458 }
1459 free(name);
1460
Benoit Gschwind390af6d2016-05-10 22:47:52 +02001461 oc = weston_wayland_backend_config_add_new_output(config);
Benoit Gschwind3ff10da2016-05-10 22:47:49 +02001462 if (!oc)
Benoit Gschwind53753842016-05-10 22:47:57 +02001463 return -1;
Benoit Gschwind3ff10da2016-05-10 22:47:49 +02001464
1465 weston_wayland_output_config_init(oc, section, width,
1466 height, scale);
1467 --count;
1468 }
1469
1470 if (!width)
1471 width = 1024;
1472 if (!height)
1473 height = 640;
1474 if (!scale)
1475 scale = 1;
Benoit Gschwind55a22882016-05-10 22:47:51 +02001476
Benoit Gschwind3ff10da2016-05-10 22:47:49 +02001477 while (count > 0) {
Benoit Gschwind390af6d2016-05-10 22:47:52 +02001478 oc = weston_wayland_backend_config_add_new_output(config);
Benoit Gschwind3ff10da2016-05-10 22:47:49 +02001479 if (!oc)
Benoit Gschwind53753842016-05-10 22:47:57 +02001480 return -1;
Benoit Gschwind3ff10da2016-05-10 22:47:49 +02001481
1482 oc->width = width;
1483 oc->height = height;
1484 oc->name = NULL;
1485 oc->transform = WL_OUTPUT_TRANSFORM_NORMAL;
1486 oc->scale = scale;
1487
1488 --count;
1489 }
1490
Benoit Gschwind3ff10da2016-05-10 22:47:49 +02001491 return 0;
Benoit Gschwind3ff10da2016-05-10 22:47:49 +02001492}
1493
1494static int
Pekka Paalanen321ede72016-06-03 15:28:40 +03001495load_wayland_backend(struct weston_compositor *c,
Benoit Gschwind3ff10da2016-05-10 22:47:49 +02001496 int *argc, char **argv, struct weston_config *wc)
1497{
1498 struct weston_wayland_backend_config config = {{ 0, }};
1499 int ret = 0;
1500
1501 ret = load_wayland_backend_config(c, argc, argv, wc, &config);
1502 if(ret < 0) {
Benoit Gschwind53753842016-05-10 22:47:57 +02001503 weston_wayland_backend_config_release(&config);
Benoit Gschwind3ff10da2016-05-10 22:47:49 +02001504 return ret;
1505 }
1506
1507 /* load the actual wayland backend and configure it */
Pekka Paalanen50dbf382016-06-03 15:23:46 +03001508 ret = weston_compositor_load_backend(c, WESTON_BACKEND_WAYLAND,
1509 &config.base);
Benoit Gschwind68d6a6c2016-05-10 22:47:53 +02001510 weston_wayland_backend_config_release(&config);
Benoit Gschwind3ff10da2016-05-10 22:47:49 +02001511 return ret;
1512}
1513
1514
Benoit Gschwind934e89a2016-04-27 23:56:42 +02001515static int
Giulio Camuffo43008c72015-10-17 19:24:15 +03001516load_backend(struct weston_compositor *compositor, const char *backend,
1517 int *argc, char **argv, struct weston_config *config)
1518{
Benoit Gschwind3c530942016-04-15 20:28:32 -07001519 if (strstr(backend, "headless-backend.so"))
Pekka Paalanen321ede72016-06-03 15:28:40 +03001520 return load_headless_backend(compositor, argc, argv, config);
Benoit Gschwindbd573102016-04-22 17:05:26 +02001521 else if (strstr(backend, "rdp-backend.so"))
Pekka Paalanen321ede72016-06-03 15:28:40 +03001522 return load_rdp_backend(compositor, argc, argv, config);
Benoit Gschwind934e89a2016-04-27 23:56:42 +02001523 else if (strstr(backend, "fbdev-backend.so"))
Pekka Paalanen321ede72016-06-03 15:28:40 +03001524 return load_fbdev_backend(compositor, argc, argv, config);
Giulio Camuffo1c0e40d2016-04-29 15:40:34 -07001525 else if (strstr(backend, "drm-backend.so"))
Pekka Paalanen321ede72016-06-03 15:28:40 +03001526 return load_drm_backend(compositor, argc, argv, config);
Benoit Gschwinde16acab2016-04-15 20:28:31 -07001527 else if (strstr(backend, "x11-backend.so"))
Pekka Paalanen321ede72016-06-03 15:28:40 +03001528 return load_x11_backend(compositor, argc, argv, config);
Giulio Camuffo43008c72015-10-17 19:24:15 +03001529 else if (strstr(backend, "wayland-backend.so"))
Pekka Paalanen321ede72016-06-03 15:28:40 +03001530 return load_wayland_backend(compositor, argc, argv, config);
Giulio Camuffo43008c72015-10-17 19:24:15 +03001531
Pekka Paalanen808b0062016-06-03 13:56:17 +03001532 weston_log("Error: unknown backend \"%s\"\n", backend);
1533 return -1;
Giulio Camuffo43008c72015-10-17 19:24:15 +03001534}
1535
Pekka Paalanen20436e22016-02-11 14:42:21 +02001536static char *
1537copy_command_line(int argc, char * const argv[])
1538{
1539 FILE *fp;
1540 char *str = NULL;
1541 size_t size = 0;
1542 int i;
1543
1544 fp = open_memstream(&str, &size);
1545 if (!fp)
1546 return NULL;
1547
1548 fprintf(fp, "%s", argv[0]);
1549 for (i = 1; i < argc; i++)
1550 fprintf(fp, " %s", argv[i]);
1551 fclose(fp);
1552
1553 return str;
1554}
1555
Giulio Camuffobab996e2014-10-12 00:24:25 +03001556int main(int argc, char *argv[])
1557{
1558 int ret = EXIT_FAILURE;
Pekka Paalanen20436e22016-02-11 14:42:21 +02001559 char *cmdline;
Giulio Camuffobab996e2014-10-12 00:24:25 +03001560 struct wl_display *display;
1561 struct weston_compositor *ec;
1562 struct wl_event_source *signals[4];
1563 struct wl_event_loop *loop;
Giulio Camuffobab996e2014-10-12 00:24:25 +03001564 int i, fd;
1565 char *backend = NULL;
1566 char *shell = NULL;
1567 char *modules = NULL;
1568 char *option_modules = NULL;
1569 char *log = NULL;
1570 char *server_socket = NULL, *end;
1571 int32_t idle_time = -1;
1572 int32_t help = 0;
1573 char *socket_name = NULL;
1574 int32_t version = 0;
1575 int32_t noconfig = 0;
1576 int32_t numlock_on;
1577 char *config_file = NULL;
1578 struct weston_config *config = NULL;
1579 struct weston_config_section *section;
1580 struct wl_client *primary_client;
1581 struct wl_listener primary_client_destroyed;
1582 struct weston_seat *seat;
1583
1584 const struct weston_option core_options[] = {
1585 { WESTON_OPTION_STRING, "backend", 'B', &backend },
1586 { WESTON_OPTION_STRING, "shell", 0, &shell },
1587 { WESTON_OPTION_STRING, "socket", 'S', &socket_name },
1588 { WESTON_OPTION_INTEGER, "idle-time", 'i', &idle_time },
1589 { WESTON_OPTION_STRING, "modules", 0, &option_modules },
1590 { WESTON_OPTION_STRING, "log", 0, &log },
1591 { WESTON_OPTION_BOOLEAN, "help", 'h', &help },
1592 { WESTON_OPTION_BOOLEAN, "version", 0, &version },
1593 { WESTON_OPTION_BOOLEAN, "no-config", 0, &noconfig },
1594 { WESTON_OPTION_STRING, "config", 'c', &config_file },
1595 };
1596
Pekka Paalanen20436e22016-02-11 14:42:21 +02001597 cmdline = copy_command_line(argc, argv);
Giulio Camuffobab996e2014-10-12 00:24:25 +03001598 parse_options(core_options, ARRAY_LENGTH(core_options), &argc, argv);
1599
Pekka Paalanen20436e22016-02-11 14:42:21 +02001600 if (help) {
1601 free(cmdline);
Giulio Camuffobab996e2014-10-12 00:24:25 +03001602 usage(EXIT_SUCCESS);
Pekka Paalanen20436e22016-02-11 14:42:21 +02001603 }
Giulio Camuffobab996e2014-10-12 00:24:25 +03001604
1605 if (version) {
1606 printf(PACKAGE_STRING "\n");
Pekka Paalanen20436e22016-02-11 14:42:21 +02001607 free(cmdline);
1608
Giulio Camuffobab996e2014-10-12 00:24:25 +03001609 return EXIT_SUCCESS;
1610 }
1611
Giulio Camuffobe2b11a2016-06-02 21:48:13 +03001612 weston_log_set_handler(vlog, vlog_continue);
Giulio Camuffobab996e2014-10-12 00:24:25 +03001613 weston_log_file_open(log);
1614
1615 weston_log("%s\n"
1616 STAMP_SPACE "%s\n"
1617 STAMP_SPACE "Bug reports to: %s\n"
1618 STAMP_SPACE "Build: %s\n",
1619 PACKAGE_STRING, PACKAGE_URL, PACKAGE_BUGREPORT,
1620 BUILD_ID);
Pekka Paalanen20436e22016-02-11 14:42:21 +02001621 weston_log("Command line: %s\n", cmdline);
1622 free(cmdline);
Giulio Camuffobab996e2014-10-12 00:24:25 +03001623 log_uname();
1624
1625 verify_xdg_runtime_dir();
1626
1627 display = wl_display_create();
1628
1629 loop = wl_display_get_event_loop(display);
1630 signals[0] = wl_event_loop_add_signal(loop, SIGTERM, on_term_signal,
1631 display);
1632 signals[1] = wl_event_loop_add_signal(loop, SIGINT, on_term_signal,
1633 display);
1634 signals[2] = wl_event_loop_add_signal(loop, SIGQUIT, on_term_signal,
1635 display);
1636
1637 wl_list_init(&child_process_list);
1638 signals[3] = wl_event_loop_add_signal(loop, SIGCHLD, sigchld_handler,
1639 NULL);
1640
1641 if (!signals[0] || !signals[1] || !signals[2] || !signals[3])
1642 goto out_signals;
1643
1644 if (load_configuration(&config, noconfig, config_file) < 0)
1645 goto out_signals;
1646
1647 section = weston_config_get_section(config, "core", NULL, NULL);
1648
1649 if (!backend) {
1650 weston_config_section_get_string(section, "backend", &backend,
1651 NULL);
1652 if (!backend)
1653 backend = weston_choose_default_backend();
1654 }
1655
Giulio Camuffo1c0e40d2016-04-29 15:40:34 -07001656 ec = weston_compositor_create(display, config);
Giulio Camuffobab996e2014-10-12 00:24:25 +03001657 if (ec == NULL) {
1658 weston_log("fatal: failed to create compositor\n");
Giulio Camuffo3c241b12015-10-03 16:25:16 +03001659 goto out;
Giulio Camuffobab996e2014-10-12 00:24:25 +03001660 }
1661
Giulio Camuffobab996e2014-10-12 00:24:25 +03001662 if (weston_compositor_init_config(ec, config) < 0)
Giulio Camuffo3c241b12015-10-03 16:25:16 +03001663 goto out;
Giulio Camuffobab996e2014-10-12 00:24:25 +03001664
Giulio Camuffo43008c72015-10-17 19:24:15 +03001665 if (load_backend(ec, backend, &argc, argv, config) < 0) {
Giulio Camuffobab996e2014-10-12 00:24:25 +03001666 weston_log("fatal: failed to create compositor backend\n");
Giulio Camuffo3c241b12015-10-03 16:25:16 +03001667 goto out;
Giulio Camuffobab996e2014-10-12 00:24:25 +03001668 }
1669
1670 catch_signals();
1671 segv_compositor = ec;
1672
1673 if (idle_time < 0)
1674 weston_config_section_get_int(section, "idle-time", &idle_time, -1);
1675 if (idle_time < 0)
1676 idle_time = 300; /* default idle timeout, in seconds */
1677
1678 ec->idle_time = idle_time;
1679 ec->default_pointer_grab = NULL;
1680 ec->exit = handle_exit;
1681
1682 weston_compositor_log_capabilities(ec);
1683
1684 server_socket = getenv("WAYLAND_SERVER_SOCKET");
1685 if (server_socket) {
1686 weston_log("Running with single client\n");
1687 fd = strtol(server_socket, &end, 0);
1688 if (*end != '\0')
1689 fd = -1;
1690 } else {
1691 fd = -1;
1692 }
1693
1694 if (fd != -1) {
1695 primary_client = wl_client_create(display, fd);
1696 if (!primary_client) {
1697 weston_log("fatal: failed to add client: %m\n");
1698 goto out;
1699 }
1700 primary_client_destroyed.notify =
1701 handle_primary_client_destroyed;
1702 wl_client_add_destroy_listener(primary_client,
1703 &primary_client_destroyed);
1704 } else if (weston_create_listening_socket(display, socket_name)) {
1705 goto out;
1706 }
1707
1708 if (!shell)
1709 weston_config_section_get_string(section, "shell", &shell,
1710 "desktop-shell.so");
1711
1712 if (load_modules(ec, shell, &argc, argv) < 0)
1713 goto out;
1714
1715 weston_config_section_get_string(section, "modules", &modules, "");
1716 if (load_modules(ec, modules, &argc, argv) < 0)
1717 goto out;
1718
1719 if (load_modules(ec, option_modules, &argc, argv) < 0)
1720 goto out;
1721
1722 section = weston_config_get_section(config, "keyboard", NULL, NULL);
1723 weston_config_section_get_bool(section, "numlock-on", &numlock_on, 0);
1724 if (numlock_on) {
1725 wl_list_for_each(seat, &ec->seat_list, link) {
Derek Foreman1281a362015-07-31 16:55:32 -05001726 struct weston_keyboard *keyboard =
1727 weston_seat_get_keyboard(seat);
1728
1729 if (keyboard)
1730 weston_keyboard_set_locks(keyboard,
Giulio Camuffobab996e2014-10-12 00:24:25 +03001731 WESTON_NUM_LOCK,
1732 WESTON_NUM_LOCK);
1733 }
1734 }
1735
1736 for (i = 1; i < argc; i++)
1737 weston_log("fatal: unhandled option: %s\n", argv[i]);
1738 if (argc > 1)
1739 goto out;
1740
1741 weston_compositor_wake(ec);
1742
1743 wl_display_run(display);
1744
1745 /* Allow for setting return exit code after
1746 * wl_display_run returns normally. This is
1747 * useful for devs/testers and automated tests
1748 * that want to indicate failure status to
1749 * testing infrastructure above
1750 */
1751 ret = ec->exit_code;
1752
1753out:
1754 weston_compositor_destroy(ec);
1755
1756out_signals:
1757 for (i = ARRAY_LENGTH(signals) - 1; i >= 0; i--)
1758 if (signals[i])
1759 wl_event_source_remove(signals[i]);
1760
1761 wl_display_destroy(display);
1762
1763 weston_log_file_close();
1764
1765 if (config)
1766 weston_config_destroy(config);
1767 free(config_file);
1768 free(backend);
1769 free(shell);
1770 free(socket_name);
1771 free(option_modules);
1772 free(log);
1773 free(modules);
1774
1775 return ret;
1776}