Giulio Camuffo | bab996e | 2014-10-12 00:24:25 +0300 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2010-2011 Intel Corporation |
| 3 | * Copyright © 2008-2011 Kristian Høgsberg |
| 4 | * Copyright © 2012-2015 Collabora, Ltd. |
Benoit Gschwind | 3ff10da | 2016-05-10 22:47:49 +0200 | [diff] [blame^] | 5 | * Copyright © 2010-2011 Benjamin Franzke |
| 6 | * Copyright © 2013 Jason Ekstrand |
Giulio Camuffo | bab996e | 2014-10-12 00:24:25 +0300 | [diff] [blame] | 7 | * |
| 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> |
| 40 | |
| 41 | #ifdef HAVE_LIBUNWIND |
| 42 | #define UNW_LOCAL_ONLY |
| 43 | #include <libunwind.h> |
| 44 | #endif |
| 45 | |
| 46 | #include "compositor.h" |
| 47 | #include "../shared/os-compatibility.h" |
| 48 | #include "../shared/helpers.h" |
| 49 | #include "git-version.h" |
| 50 | #include "version.h" |
| 51 | |
Giulio Camuffo | 1c0e40d | 2016-04-29 15:40:34 -0700 | [diff] [blame] | 52 | #include "compositor-drm.h" |
Benoit Gschwind | 3c53094 | 2016-04-15 20:28:32 -0700 | [diff] [blame] | 53 | #include "compositor-headless.h" |
Benoit Gschwind | bd57310 | 2016-04-22 17:05:26 +0200 | [diff] [blame] | 54 | #include "compositor-rdp.h" |
Benoit Gschwind | 934e89a | 2016-04-27 23:56:42 +0200 | [diff] [blame] | 55 | #include "compositor-fbdev.h" |
Benoit Gschwind | e16acab | 2016-04-15 20:28:31 -0700 | [diff] [blame] | 56 | #include "compositor-x11.h" |
Benoit Gschwind | 3ff10da | 2016-05-10 22:47:49 +0200 | [diff] [blame^] | 57 | #include "compositor-wayland.h" |
| 58 | |
| 59 | #define WINDOW_TITLE "Weston Compositor" |
Benoit Gschwind | 3c53094 | 2016-04-15 20:28:32 -0700 | [diff] [blame] | 60 | |
Giulio Camuffo | bab996e | 2014-10-12 00:24:25 +0300 | [diff] [blame] | 61 | static struct wl_list child_process_list; |
| 62 | static struct weston_compositor *segv_compositor; |
| 63 | |
| 64 | static int |
| 65 | sigchld_handler(int signal_number, void *data) |
| 66 | { |
| 67 | struct weston_process *p; |
| 68 | int status; |
| 69 | pid_t pid; |
| 70 | |
| 71 | while ((pid = waitpid(-1, &status, WNOHANG)) > 0) { |
| 72 | wl_list_for_each(p, &child_process_list, link) { |
| 73 | if (p->pid == pid) |
| 74 | break; |
| 75 | } |
| 76 | |
| 77 | if (&p->link == &child_process_list) { |
| 78 | weston_log("unknown child process exited\n"); |
| 79 | continue; |
| 80 | } |
| 81 | |
| 82 | wl_list_remove(&p->link); |
| 83 | p->cleanup(p, status); |
| 84 | } |
| 85 | |
| 86 | if (pid < 0 && errno != ECHILD) |
| 87 | weston_log("waitpid error %m\n"); |
| 88 | |
| 89 | return 1; |
| 90 | } |
| 91 | |
| 92 | #ifdef HAVE_LIBUNWIND |
| 93 | |
| 94 | static void |
| 95 | print_backtrace(void) |
| 96 | { |
| 97 | unw_cursor_t cursor; |
| 98 | unw_context_t context; |
| 99 | unw_word_t off; |
| 100 | unw_proc_info_t pip; |
| 101 | int ret, i = 0; |
| 102 | char procname[256]; |
| 103 | const char *filename; |
| 104 | Dl_info dlinfo; |
| 105 | |
| 106 | pip.unwind_info = NULL; |
| 107 | ret = unw_getcontext(&context); |
| 108 | if (ret) { |
| 109 | weston_log("unw_getcontext: %d\n", ret); |
| 110 | return; |
| 111 | } |
| 112 | |
| 113 | ret = unw_init_local(&cursor, &context); |
| 114 | if (ret) { |
| 115 | weston_log("unw_init_local: %d\n", ret); |
| 116 | return; |
| 117 | } |
| 118 | |
| 119 | ret = unw_step(&cursor); |
| 120 | while (ret > 0) { |
| 121 | ret = unw_get_proc_info(&cursor, &pip); |
| 122 | if (ret) { |
| 123 | weston_log("unw_get_proc_info: %d\n", ret); |
| 124 | break; |
| 125 | } |
| 126 | |
| 127 | ret = unw_get_proc_name(&cursor, procname, 256, &off); |
| 128 | if (ret && ret != -UNW_ENOMEM) { |
| 129 | if (ret != -UNW_EUNSPEC) |
| 130 | weston_log("unw_get_proc_name: %d\n", ret); |
| 131 | procname[0] = '?'; |
| 132 | procname[1] = 0; |
| 133 | } |
| 134 | |
| 135 | if (dladdr((void *)(pip.start_ip + off), &dlinfo) && dlinfo.dli_fname && |
| 136 | *dlinfo.dli_fname) |
| 137 | filename = dlinfo.dli_fname; |
| 138 | else |
| 139 | filename = "?"; |
| 140 | |
| 141 | weston_log("%u: %s (%s%s+0x%x) [%p]\n", i++, filename, procname, |
| 142 | ret == -UNW_ENOMEM ? "..." : "", (int)off, (void *)(pip.start_ip + off)); |
| 143 | |
| 144 | ret = unw_step(&cursor); |
| 145 | if (ret < 0) |
| 146 | weston_log("unw_step: %d\n", ret); |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | #else |
| 151 | |
| 152 | static void |
| 153 | print_backtrace(void) |
| 154 | { |
| 155 | void *buffer[32]; |
| 156 | int i, count; |
| 157 | Dl_info info; |
| 158 | |
| 159 | count = backtrace(buffer, ARRAY_LENGTH(buffer)); |
| 160 | for (i = 0; i < count; i++) { |
| 161 | dladdr(buffer[i], &info); |
| 162 | weston_log(" [%016lx] %s (%s)\n", |
| 163 | (long) buffer[i], |
| 164 | info.dli_sname ? info.dli_sname : "--", |
| 165 | info.dli_fname); |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | #endif |
| 170 | |
| 171 | WL_EXPORT void |
| 172 | weston_watch_process(struct weston_process *process) |
| 173 | { |
| 174 | wl_list_insert(&child_process_list, &process->link); |
| 175 | } |
| 176 | |
| 177 | static void |
| 178 | log_uname(void) |
| 179 | { |
| 180 | struct utsname usys; |
| 181 | |
| 182 | uname(&usys); |
| 183 | |
| 184 | weston_log("OS: %s, %s, %s, %s\n", usys.sysname, usys.release, |
| 185 | usys.version, usys.machine); |
| 186 | } |
| 187 | |
| 188 | static const char xdg_error_message[] = |
| 189 | "fatal: environment variable XDG_RUNTIME_DIR is not set.\n"; |
| 190 | |
| 191 | static const char xdg_wrong_message[] = |
| 192 | "fatal: environment variable XDG_RUNTIME_DIR\n" |
| 193 | "is set to \"%s\", which is not a directory.\n"; |
| 194 | |
| 195 | static const char xdg_wrong_mode_message[] = |
| 196 | "warning: XDG_RUNTIME_DIR \"%s\" is not configured\n" |
| 197 | "correctly. Unix access mode must be 0700 (current mode is %o),\n" |
| 198 | "and must be owned by the user (current owner is UID %d).\n"; |
| 199 | |
| 200 | static const char xdg_detail_message[] = |
| 201 | "Refer to your distribution on how to get it, or\n" |
| 202 | "http://www.freedesktop.org/wiki/Specifications/basedir-spec\n" |
| 203 | "on how to implement it.\n"; |
| 204 | |
| 205 | static void |
| 206 | verify_xdg_runtime_dir(void) |
| 207 | { |
| 208 | char *dir = getenv("XDG_RUNTIME_DIR"); |
| 209 | struct stat s; |
| 210 | |
| 211 | if (!dir) { |
| 212 | weston_log(xdg_error_message); |
| 213 | weston_log_continue(xdg_detail_message); |
| 214 | exit(EXIT_FAILURE); |
| 215 | } |
| 216 | |
| 217 | if (stat(dir, &s) || !S_ISDIR(s.st_mode)) { |
| 218 | weston_log(xdg_wrong_message, dir); |
| 219 | weston_log_continue(xdg_detail_message); |
| 220 | exit(EXIT_FAILURE); |
| 221 | } |
| 222 | |
| 223 | if ((s.st_mode & 0777) != 0700 || s.st_uid != getuid()) { |
| 224 | weston_log(xdg_wrong_mode_message, |
| 225 | dir, s.st_mode & 0777, s.st_uid); |
| 226 | weston_log_continue(xdg_detail_message); |
| 227 | } |
| 228 | } |
| 229 | |
| 230 | static int |
| 231 | usage(int error_code) |
| 232 | { |
| 233 | fprintf(stderr, |
| 234 | "Usage: weston [OPTIONS]\n\n" |
| 235 | "This is weston version " VERSION ", the Wayland reference compositor.\n" |
| 236 | "Weston supports multiple backends, and depending on which backend is in use\n" |
| 237 | "different options will be accepted.\n\n" |
| 238 | |
| 239 | |
| 240 | "Core options:\n\n" |
| 241 | " --version\t\tPrint weston version\n" |
| 242 | " -B, --backend=MODULE\tBackend module, one of\n" |
| 243 | #if defined(BUILD_DRM_COMPOSITOR) |
| 244 | "\t\t\t\tdrm-backend.so\n" |
| 245 | #endif |
| 246 | #if defined(BUILD_FBDEV_COMPOSITOR) |
| 247 | "\t\t\t\tfbdev-backend.so\n" |
| 248 | #endif |
Dawid Gajownik | 71f5704 | 2015-07-31 17:39:00 -0300 | [diff] [blame] | 249 | #if defined(BUILD_HEADLESS_COMPOSITOR) |
| 250 | "\t\t\t\theadless-backend.so\n" |
Giulio Camuffo | bab996e | 2014-10-12 00:24:25 +0300 | [diff] [blame] | 251 | #endif |
| 252 | #if defined(BUILD_RDP_COMPOSITOR) |
| 253 | "\t\t\t\trdp-backend.so\n" |
| 254 | #endif |
Giulio Camuffo | bab996e | 2014-10-12 00:24:25 +0300 | [diff] [blame] | 255 | #if defined(BUILD_RPI_COMPOSITOR) && defined(HAVE_BCM_HOST) |
| 256 | "\t\t\t\trpi-backend.so\n" |
| 257 | #endif |
Dawid Gajownik | 71f5704 | 2015-07-31 17:39:00 -0300 | [diff] [blame] | 258 | #if defined(BUILD_WAYLAND_COMPOSITOR) |
| 259 | "\t\t\t\twayland-backend.so\n" |
| 260 | #endif |
| 261 | #if defined(BUILD_X11_COMPOSITOR) |
| 262 | "\t\t\t\tx11-backend.so\n" |
| 263 | #endif |
Giulio Camuffo | bab996e | 2014-10-12 00:24:25 +0300 | [diff] [blame] | 264 | " --shell=MODULE\tShell module, defaults to desktop-shell.so\n" |
| 265 | " -S, --socket=NAME\tName of socket to listen on\n" |
| 266 | " -i, --idle-time=SECS\tIdle time in seconds\n" |
| 267 | " --modules\t\tLoad the comma-separated list of modules\n" |
| 268 | " --log=FILE\t\tLog to the given file\n" |
| 269 | " -c, --config=FILE\tConfig file to load, defaults to weston.ini\n" |
| 270 | " --no-config\t\tDo not read weston.ini\n" |
| 271 | " -h, --help\t\tThis help message\n\n"); |
| 272 | |
| 273 | #if defined(BUILD_DRM_COMPOSITOR) |
| 274 | fprintf(stderr, |
| 275 | "Options for drm-backend.so:\n\n" |
| 276 | " --connector=ID\tBring up only this connector\n" |
| 277 | " --seat=SEAT\t\tThe seat that weston should run on\n" |
| 278 | " --tty=TTY\t\tThe tty to use\n" |
| 279 | " --use-pixman\t\tUse the pixman (CPU) renderer\n" |
| 280 | " --current-mode\tPrefer current KMS mode over EDID preferred mode\n\n"); |
| 281 | #endif |
| 282 | |
| 283 | #if defined(BUILD_FBDEV_COMPOSITOR) |
| 284 | fprintf(stderr, |
| 285 | "Options for fbdev-backend.so:\n\n" |
| 286 | " --tty=TTY\t\tThe tty to use\n" |
| 287 | " --device=DEVICE\tThe framebuffer device to use\n" |
| 288 | " --use-gl\t\tUse the GL renderer\n\n"); |
| 289 | #endif |
| 290 | |
Dawid Gajownik | 71f5704 | 2015-07-31 17:39:00 -0300 | [diff] [blame] | 291 | #if defined(BUILD_HEADLESS_COMPOSITOR) |
Giulio Camuffo | bab996e | 2014-10-12 00:24:25 +0300 | [diff] [blame] | 292 | fprintf(stderr, |
Dawid Gajownik | 71f5704 | 2015-07-31 17:39:00 -0300 | [diff] [blame] | 293 | "Options for headless-backend.so:\n\n" |
| 294 | " --width=WIDTH\t\tWidth of memory surface\n" |
| 295 | " --height=HEIGHT\tHeight of memory surface\n" |
Giulio Camuffo | bab996e | 2014-10-12 00:24:25 +0300 | [diff] [blame] | 296 | " --transform=TR\tThe output transformation, TR is one of:\n" |
| 297 | "\tnormal 90 180 270 flipped flipped-90 flipped-180 flipped-270\n" |
Dawid Gajownik | 71f5704 | 2015-07-31 17:39:00 -0300 | [diff] [blame] | 298 | " --use-pixman\t\tUse the pixman (CPU) renderer (default: no rendering)\n\n"); |
Giulio Camuffo | bab996e | 2014-10-12 00:24:25 +0300 | [diff] [blame] | 299 | #endif |
| 300 | |
| 301 | #if defined(BUILD_RDP_COMPOSITOR) |
| 302 | fprintf(stderr, |
| 303 | "Options for rdp-backend.so:\n\n" |
| 304 | " --width=WIDTH\t\tWidth of desktop\n" |
| 305 | " --height=HEIGHT\tHeight of desktop\n" |
Dawid Gajownik | d99a050 | 2015-07-31 14:49:57 -0300 | [diff] [blame] | 306 | " --env-socket\t\tUse socket defined in RDP_FD env variable as peer connection\n" |
Giulio Camuffo | bab996e | 2014-10-12 00:24:25 +0300 | [diff] [blame] | 307 | " --address=ADDR\tThe address to bind\n" |
| 308 | " --port=PORT\t\tThe port to listen on\n" |
| 309 | " --no-clients-resize\tThe RDP peers will be forced to the size of the desktop\n" |
| 310 | " --rdp4-key=FILE\tThe file containing the key for RDP4 encryption\n" |
| 311 | " --rdp-tls-cert=FILE\tThe file containing the certificate for TLS encryption\n" |
| 312 | " --rdp-tls-key=FILE\tThe file containing the private key for TLS encryption\n" |
| 313 | "\n"); |
| 314 | #endif |
| 315 | |
Dawid Gajownik | 71f5704 | 2015-07-31 17:39:00 -0300 | [diff] [blame] | 316 | #if defined(BUILD_RPI_COMPOSITOR) && defined(HAVE_BCM_HOST) |
Giulio Camuffo | bab996e | 2014-10-12 00:24:25 +0300 | [diff] [blame] | 317 | fprintf(stderr, |
Dawid Gajownik | 71f5704 | 2015-07-31 17:39:00 -0300 | [diff] [blame] | 318 | "Options for rpi-backend.so:\n\n" |
| 319 | " --tty=TTY\t\tThe tty to use\n" |
| 320 | " --single-buffer\tUse single-buffered Dispmanx elements.\n" |
Giulio Camuffo | bab996e | 2014-10-12 00:24:25 +0300 | [diff] [blame] | 321 | " --transform=TR\tThe output transformation, TR is one of:\n" |
| 322 | "\tnormal 90 180 270 flipped flipped-90 flipped-180 flipped-270\n" |
Dawid Gajownik | 71f5704 | 2015-07-31 17:39:00 -0300 | [diff] [blame] | 323 | " --opaque-regions\tEnable support for opaque regions, can be " |
| 324 | "very slow without support in the GPU firmware.\n" |
| 325 | "\n"); |
| 326 | #endif |
| 327 | |
| 328 | #if defined(BUILD_WAYLAND_COMPOSITOR) |
| 329 | fprintf(stderr, |
| 330 | "Options for wayland-backend.so:\n\n" |
| 331 | " --width=WIDTH\t\tWidth of Wayland surface\n" |
| 332 | " --height=HEIGHT\tHeight of Wayland surface\n" |
| 333 | " --scale=SCALE\t\tScale factor of output\n" |
| 334 | " --fullscreen\t\tRun in fullscreen mode\n" |
| 335 | " --use-pixman\t\tUse the pixman (CPU) renderer\n" |
| 336 | " --output-count=COUNT\tCreate multiple outputs\n" |
| 337 | " --sprawl\t\tCreate one fullscreen output for every parent output\n" |
| 338 | " --display=DISPLAY\tWayland display to connect to\n\n"); |
| 339 | #endif |
| 340 | |
| 341 | #if defined(BUILD_X11_COMPOSITOR) |
| 342 | fprintf(stderr, |
| 343 | "Options for x11-backend.so:\n\n" |
| 344 | " --width=WIDTH\t\tWidth of X window\n" |
| 345 | " --height=HEIGHT\tHeight of X window\n" |
| 346 | " --scale=SCALE\t\tScale factor of output\n" |
| 347 | " --fullscreen\t\tRun in fullscreen mode\n" |
| 348 | " --use-pixman\t\tUse the pixman (CPU) renderer\n" |
| 349 | " --output-count=COUNT\tCreate multiple outputs\n" |
| 350 | " --no-input\t\tDont create input devices\n\n"); |
Giulio Camuffo | bab996e | 2014-10-12 00:24:25 +0300 | [diff] [blame] | 351 | #endif |
| 352 | |
| 353 | exit(error_code); |
| 354 | } |
| 355 | |
| 356 | static int on_term_signal(int signal_number, void *data) |
| 357 | { |
| 358 | struct wl_display *display = data; |
| 359 | |
| 360 | weston_log("caught signal %d\n", signal_number); |
| 361 | wl_display_terminate(display); |
| 362 | |
| 363 | return 1; |
| 364 | } |
| 365 | |
| 366 | static void |
| 367 | on_caught_signal(int s, siginfo_t *siginfo, void *context) |
| 368 | { |
| 369 | /* This signal handler will do a best-effort backtrace, and |
| 370 | * then call the backend restore function, which will switch |
| 371 | * back to the vt we launched from or ungrab X etc and then |
| 372 | * raise SIGTRAP. If we run weston under gdb from X or a |
| 373 | * different vt, and tell gdb "handle *s* nostop", this |
| 374 | * will allow weston to switch back to gdb on crash and then |
| 375 | * gdb will catch the crash with SIGTRAP.*/ |
| 376 | |
| 377 | weston_log("caught signal: %d\n", s); |
| 378 | |
| 379 | print_backtrace(); |
| 380 | |
| 381 | segv_compositor->backend->restore(segv_compositor); |
| 382 | |
| 383 | raise(SIGTRAP); |
| 384 | } |
| 385 | |
| 386 | static void |
| 387 | catch_signals(void) |
| 388 | { |
| 389 | struct sigaction action; |
| 390 | |
| 391 | action.sa_flags = SA_SIGINFO | SA_RESETHAND; |
| 392 | action.sa_sigaction = on_caught_signal; |
| 393 | sigemptyset(&action.sa_mask); |
| 394 | sigaction(SIGSEGV, &action, NULL); |
| 395 | sigaction(SIGABRT, &action, NULL); |
| 396 | } |
| 397 | |
| 398 | static const char * |
| 399 | clock_name(clockid_t clk_id) |
| 400 | { |
| 401 | static const char *names[] = { |
| 402 | [CLOCK_REALTIME] = "CLOCK_REALTIME", |
| 403 | [CLOCK_MONOTONIC] = "CLOCK_MONOTONIC", |
| 404 | [CLOCK_MONOTONIC_RAW] = "CLOCK_MONOTONIC_RAW", |
| 405 | [CLOCK_REALTIME_COARSE] = "CLOCK_REALTIME_COARSE", |
| 406 | [CLOCK_MONOTONIC_COARSE] = "CLOCK_MONOTONIC_COARSE", |
Derek Foreman | 32838c9 | 2015-06-29 13:20:34 -0500 | [diff] [blame] | 407 | #ifdef CLOCK_BOOTTIME |
Giulio Camuffo | bab996e | 2014-10-12 00:24:25 +0300 | [diff] [blame] | 408 | [CLOCK_BOOTTIME] = "CLOCK_BOOTTIME", |
Derek Foreman | 32838c9 | 2015-06-29 13:20:34 -0500 | [diff] [blame] | 409 | #endif |
Giulio Camuffo | bab996e | 2014-10-12 00:24:25 +0300 | [diff] [blame] | 410 | }; |
| 411 | |
| 412 | if (clk_id < 0 || (unsigned)clk_id >= ARRAY_LENGTH(names)) |
| 413 | return "unknown"; |
| 414 | |
| 415 | return names[clk_id]; |
| 416 | } |
| 417 | |
| 418 | static const struct { |
| 419 | uint32_t bit; /* enum weston_capability */ |
| 420 | const char *desc; |
| 421 | } capability_strings[] = { |
| 422 | { WESTON_CAP_ROTATION_ANY, "arbitrary surface rotation:" }, |
| 423 | { WESTON_CAP_CAPTURE_YFLIP, "screen capture uses y-flip:" }, |
| 424 | }; |
| 425 | |
| 426 | static void |
| 427 | weston_compositor_log_capabilities(struct weston_compositor *compositor) |
| 428 | { |
| 429 | unsigned i; |
| 430 | int yes; |
| 431 | |
| 432 | weston_log("Compositor capabilities:\n"); |
| 433 | for (i = 0; i < ARRAY_LENGTH(capability_strings); i++) { |
| 434 | yes = compositor->capabilities & capability_strings[i].bit; |
| 435 | weston_log_continue(STAMP_SPACE "%s %s\n", |
| 436 | capability_strings[i].desc, |
| 437 | yes ? "yes" : "no"); |
| 438 | } |
| 439 | |
| 440 | weston_log_continue(STAMP_SPACE "presentation clock: %s, id %d\n", |
| 441 | clock_name(compositor->presentation_clock), |
| 442 | compositor->presentation_clock); |
| 443 | } |
| 444 | |
| 445 | static void |
| 446 | handle_primary_client_destroyed(struct wl_listener *listener, void *data) |
| 447 | { |
| 448 | struct wl_client *client = data; |
| 449 | |
| 450 | weston_log("Primary client died. Closing...\n"); |
| 451 | |
| 452 | wl_display_terminate(wl_client_get_display(client)); |
| 453 | } |
| 454 | |
| 455 | static int |
| 456 | weston_create_listening_socket(struct wl_display *display, const char *socket_name) |
| 457 | { |
| 458 | if (socket_name) { |
| 459 | if (wl_display_add_socket(display, socket_name)) { |
| 460 | weston_log("fatal: failed to add socket: %m\n"); |
| 461 | return -1; |
| 462 | } |
| 463 | } else { |
| 464 | socket_name = wl_display_add_socket_auto(display); |
| 465 | if (!socket_name) { |
| 466 | weston_log("fatal: failed to add socket: %m\n"); |
| 467 | return -1; |
| 468 | } |
| 469 | } |
| 470 | |
| 471 | setenv("WAYLAND_DISPLAY", socket_name, 1); |
| 472 | |
| 473 | return 0; |
| 474 | } |
| 475 | |
| 476 | static int |
| 477 | load_modules(struct weston_compositor *ec, const char *modules, |
| 478 | int *argc, char *argv[]) |
| 479 | { |
| 480 | const char *p, *end; |
| 481 | char buffer[256]; |
| 482 | int (*module_init)(struct weston_compositor *ec, |
| 483 | int *argc, char *argv[]); |
| 484 | |
| 485 | if (modules == NULL) |
| 486 | return 0; |
| 487 | |
| 488 | p = modules; |
| 489 | while (*p) { |
| 490 | end = strchrnul(p, ','); |
| 491 | snprintf(buffer, sizeof buffer, "%.*s", (int) (end - p), p); |
| 492 | module_init = weston_load_module(buffer, "module_init"); |
| 493 | if (!module_init) |
| 494 | return -1; |
| 495 | if (module_init(ec, argc, argv) < 0) |
| 496 | return -1; |
| 497 | p = end; |
| 498 | while (*p == ',') |
| 499 | p++; |
| 500 | |
| 501 | } |
| 502 | |
| 503 | return 0; |
| 504 | } |
| 505 | |
| 506 | static int |
| 507 | weston_compositor_init_config(struct weston_compositor *ec, |
| 508 | struct weston_config *config) |
| 509 | { |
| 510 | struct xkb_rule_names xkb_names; |
| 511 | struct weston_config_section *s; |
| 512 | int repaint_msec; |
Bob Ham | 91880f1 | 2016-01-12 10:21:47 +0000 | [diff] [blame] | 513 | int vt_switching; |
Giulio Camuffo | bab996e | 2014-10-12 00:24:25 +0300 | [diff] [blame] | 514 | |
| 515 | s = weston_config_get_section(config, "keyboard", NULL, NULL); |
| 516 | weston_config_section_get_string(s, "keymap_rules", |
| 517 | (char **) &xkb_names.rules, NULL); |
| 518 | weston_config_section_get_string(s, "keymap_model", |
| 519 | (char **) &xkb_names.model, NULL); |
| 520 | weston_config_section_get_string(s, "keymap_layout", |
| 521 | (char **) &xkb_names.layout, NULL); |
| 522 | weston_config_section_get_string(s, "keymap_variant", |
| 523 | (char **) &xkb_names.variant, NULL); |
| 524 | weston_config_section_get_string(s, "keymap_options", |
| 525 | (char **) &xkb_names.options, NULL); |
| 526 | |
| 527 | if (weston_compositor_xkb_init(ec, &xkb_names) < 0) |
| 528 | return -1; |
| 529 | |
| 530 | weston_config_section_get_int(s, "repeat-rate", |
| 531 | &ec->kb_repeat_rate, 40); |
| 532 | weston_config_section_get_int(s, "repeat-delay", |
| 533 | &ec->kb_repeat_delay, 400); |
| 534 | |
Bob Ham | 91880f1 | 2016-01-12 10:21:47 +0000 | [diff] [blame] | 535 | weston_config_section_get_bool(s, "vt-switching", |
| 536 | &vt_switching, true); |
| 537 | ec->vt_switching = vt_switching; |
| 538 | |
Giulio Camuffo | bab996e | 2014-10-12 00:24:25 +0300 | [diff] [blame] | 539 | s = weston_config_get_section(config, "core", NULL, NULL); |
| 540 | weston_config_section_get_int(s, "repaint-window", &repaint_msec, |
| 541 | ec->repaint_msec); |
| 542 | if (repaint_msec < -10 || repaint_msec > 1000) { |
| 543 | weston_log("Invalid repaint_window value in config: %d\n", |
| 544 | repaint_msec); |
| 545 | } else { |
| 546 | ec->repaint_msec = repaint_msec; |
| 547 | } |
| 548 | weston_log("Output repaint window is %d ms maximum.\n", |
| 549 | ec->repaint_msec); |
| 550 | |
| 551 | return 0; |
| 552 | } |
| 553 | |
| 554 | static char * |
| 555 | weston_choose_default_backend(void) |
| 556 | { |
| 557 | char *backend = NULL; |
| 558 | |
| 559 | if (getenv("WAYLAND_DISPLAY") || getenv("WAYLAND_SOCKET")) |
| 560 | backend = strdup("wayland-backend.so"); |
| 561 | else if (getenv("DISPLAY")) |
| 562 | backend = strdup("x11-backend.so"); |
| 563 | else |
| 564 | backend = strdup(WESTON_NATIVE_BACKEND); |
| 565 | |
| 566 | return backend; |
| 567 | } |
| 568 | |
| 569 | static const struct { const char *name; uint32_t token; } transforms[] = { |
| 570 | { "normal", WL_OUTPUT_TRANSFORM_NORMAL }, |
| 571 | { "90", WL_OUTPUT_TRANSFORM_90 }, |
| 572 | { "180", WL_OUTPUT_TRANSFORM_180 }, |
| 573 | { "270", WL_OUTPUT_TRANSFORM_270 }, |
| 574 | { "flipped", WL_OUTPUT_TRANSFORM_FLIPPED }, |
| 575 | { "flipped-90", WL_OUTPUT_TRANSFORM_FLIPPED_90 }, |
| 576 | { "flipped-180", WL_OUTPUT_TRANSFORM_FLIPPED_180 }, |
| 577 | { "flipped-270", WL_OUTPUT_TRANSFORM_FLIPPED_270 }, |
| 578 | }; |
| 579 | |
| 580 | WL_EXPORT int |
| 581 | weston_parse_transform(const char *transform, uint32_t *out) |
| 582 | { |
| 583 | unsigned int i; |
| 584 | |
| 585 | for (i = 0; i < ARRAY_LENGTH(transforms); i++) |
| 586 | if (strcmp(transforms[i].name, transform) == 0) { |
| 587 | *out = transforms[i].token; |
| 588 | return 0; |
| 589 | } |
| 590 | |
| 591 | *out = WL_OUTPUT_TRANSFORM_NORMAL; |
| 592 | return -1; |
| 593 | } |
| 594 | |
| 595 | WL_EXPORT const char * |
| 596 | weston_transform_to_string(uint32_t output_transform) |
| 597 | { |
| 598 | unsigned int i; |
| 599 | |
| 600 | for (i = 0; i < ARRAY_LENGTH(transforms); i++) |
| 601 | if (transforms[i].token == output_transform) |
| 602 | return transforms[i].name; |
| 603 | |
| 604 | return "<illegal value>"; |
| 605 | } |
| 606 | |
| 607 | static int |
| 608 | load_configuration(struct weston_config **config, int32_t noconfig, |
| 609 | const char *config_file) |
| 610 | { |
| 611 | const char *file = "weston.ini"; |
| 612 | const char *full_path; |
| 613 | |
| 614 | *config = NULL; |
| 615 | |
| 616 | if (config_file) |
| 617 | file = config_file; |
| 618 | |
| 619 | if (noconfig == 0) |
| 620 | *config = weston_config_parse(file); |
| 621 | |
| 622 | if (*config) { |
| 623 | full_path = weston_config_get_full_path(*config); |
| 624 | |
| 625 | weston_log("Using config file '%s'\n", full_path); |
| 626 | setenv(WESTON_CONFIG_FILE_ENV_VAR, full_path, 1); |
| 627 | |
| 628 | return 0; |
| 629 | } |
| 630 | |
| 631 | if (config_file && noconfig == 0) { |
| 632 | weston_log("fatal: error opening or reading config file" |
| 633 | " '%s'.\n", config_file); |
| 634 | |
| 635 | return -1; |
| 636 | } |
| 637 | |
| 638 | weston_log("Starting with no config file.\n"); |
| 639 | setenv(WESTON_CONFIG_FILE_ENV_VAR, "", 1); |
| 640 | |
| 641 | return 0; |
| 642 | } |
| 643 | |
| 644 | static void |
| 645 | handle_exit(struct weston_compositor *c) |
| 646 | { |
| 647 | wl_display_terminate(c->wl_display); |
| 648 | } |
| 649 | |
Giulio Camuffo | 43008c7 | 2015-10-17 19:24:15 +0300 | [diff] [blame] | 650 | /* Temporary function to be removed when all backends are converted. */ |
| 651 | static int |
| 652 | load_backend_old(struct weston_compositor *compositor, const char *backend, |
| 653 | int *argc, char **argv, struct weston_config *wc) |
| 654 | { |
| 655 | int (*backend_init)(struct weston_compositor *c, |
| 656 | int *argc, char *argv[], |
| 657 | struct weston_config *config, |
| 658 | struct weston_backend_config *config_base); |
| 659 | |
| 660 | backend_init = weston_load_module(backend, "backend_init"); |
| 661 | if (!backend_init) |
| 662 | return -1; |
| 663 | |
| 664 | return backend_init(compositor, argc, argv, wc, NULL); |
| 665 | } |
| 666 | |
Bryce Harrington | 98ab08b | 2016-04-15 20:28:36 -0700 | [diff] [blame] | 667 | /** Main module call-point for backends. |
| 668 | * |
| 669 | * All backends should use this routine to access their init routine. |
| 670 | * Backends may subclass weston_backend_config to add their own |
| 671 | * configuration data, setting the major/minor version in config_base |
| 672 | * accordingly. |
| 673 | * |
| 674 | * The config_base object should be treated as temporary, and any data |
| 675 | * copied out of it by backend_init before returning. The load_backend_new |
| 676 | * callers may then free the config_base object. |
| 677 | * |
| 678 | * NOTE: This is a temporary function intended to eventually be replaced |
| 679 | * by weston_compositor_load_backend(). |
| 680 | */ |
Bryce Harrington | 6ca25b3 | 2016-04-15 20:28:27 -0700 | [diff] [blame] | 681 | static int |
| 682 | load_backend_new(struct weston_compositor *compositor, const char *backend, |
| 683 | struct weston_backend_config *config_base) |
| 684 | { |
| 685 | int (*backend_init)(struct weston_compositor *c, |
| 686 | int *argc, char *argv[], |
| 687 | struct weston_config *config, |
| 688 | struct weston_backend_config *config_base); |
| 689 | |
| 690 | backend_init = weston_load_module(backend, "backend_init"); |
| 691 | if (!backend_init) |
| 692 | return -1; |
| 693 | |
| 694 | return backend_init(compositor, NULL, NULL, NULL, config_base); |
| 695 | } |
| 696 | |
Giulio Camuffo | 1c0e40d | 2016-04-29 15:40:34 -0700 | [diff] [blame] | 697 | static enum weston_drm_backend_output_mode |
| 698 | drm_configure_output(struct weston_compositor *c, |
| 699 | bool use_current_mode, |
| 700 | const char *name, |
| 701 | struct weston_drm_backend_output_config *config) |
| 702 | { |
| 703 | struct weston_config *wc = weston_compositor_get_user_data(c); |
| 704 | struct weston_config_section *section; |
| 705 | char *s; |
| 706 | int scale; |
| 707 | enum weston_drm_backend_output_mode mode = |
| 708 | WESTON_DRM_BACKEND_OUTPUT_PREFERRED; |
| 709 | |
| 710 | section = weston_config_get_section(wc, "output", "name", name); |
| 711 | weston_config_section_get_string(section, "mode", &s, "preferred"); |
| 712 | if (strcmp(s, "off") == 0) { |
| 713 | free(s); |
| 714 | return WESTON_DRM_BACKEND_OUTPUT_OFF; |
| 715 | } |
| 716 | |
| 717 | if (use_current_mode || strcmp(s, "current") == 0) { |
| 718 | mode = WESTON_DRM_BACKEND_OUTPUT_CURRENT; |
| 719 | } else if (strcmp(s, "preferred") != 0) { |
| 720 | config->modeline = s; |
| 721 | s = NULL; |
| 722 | } |
| 723 | free(s); |
| 724 | |
| 725 | weston_config_section_get_int(section, "scale", &scale, 1); |
| 726 | config->base.scale = scale >= 1 ? scale : 1; |
| 727 | weston_config_section_get_string(section, "transform", &s, "normal"); |
| 728 | if (weston_parse_transform(s, &config->base.transform) < 0) |
| 729 | weston_log("Invalid transform \"%s\" for output %s\n", |
| 730 | s, name); |
| 731 | free(s); |
| 732 | |
| 733 | weston_config_section_get_string(section, |
| 734 | "gbm-format", &config->gbm_format, NULL); |
| 735 | weston_config_section_get_string(section, "seat", &config->seat, ""); |
| 736 | return mode; |
| 737 | } |
| 738 | |
| 739 | static int |
| 740 | load_drm_backend(struct weston_compositor *c, const char *backend, |
| 741 | int *argc, char **argv, struct weston_config *wc) |
| 742 | { |
| 743 | struct weston_drm_backend_config config = {{ 0, }}; |
| 744 | struct weston_config_section *section; |
| 745 | int ret = 0; |
| 746 | |
| 747 | const struct weston_option options[] = { |
| 748 | { WESTON_OPTION_INTEGER, "connector", 0, &config.connector }, |
| 749 | { WESTON_OPTION_STRING, "seat", 0, &config.seat_id }, |
| 750 | { WESTON_OPTION_INTEGER, "tty", 0, &config.tty }, |
| 751 | { WESTON_OPTION_BOOLEAN, "current-mode", 0, &config.use_current_mode }, |
| 752 | { WESTON_OPTION_BOOLEAN, "use-pixman", 0, &config.use_pixman }, |
| 753 | }; |
| 754 | |
| 755 | parse_options(options, ARRAY_LENGTH(options), argc, argv); |
| 756 | |
| 757 | section = weston_config_get_section(wc, "core", NULL, NULL); |
| 758 | weston_config_section_get_string(section, |
| 759 | "gbm-format", &config.gbm_format, |
| 760 | NULL); |
| 761 | |
| 762 | config.base.struct_version = WESTON_DRM_BACKEND_CONFIG_VERSION; |
| 763 | config.base.struct_size = sizeof(struct weston_drm_backend_config); |
| 764 | config.configure_output = drm_configure_output; |
| 765 | |
| 766 | ret = load_backend_new(c, backend, &config.base); |
| 767 | |
| 768 | free(config.gbm_format); |
| 769 | free(config.seat_id); |
| 770 | |
| 771 | return ret; |
| 772 | } |
| 773 | |
Giulio Camuffo | 43008c7 | 2015-10-17 19:24:15 +0300 | [diff] [blame] | 774 | static int |
Benoit Gschwind | 3c53094 | 2016-04-15 20:28:32 -0700 | [diff] [blame] | 775 | load_headless_backend(struct weston_compositor *c, char const * backend, |
| 776 | int *argc, char **argv, struct weston_config *wc) |
| 777 | { |
| 778 | struct weston_headless_backend_config config = {{ 0, }}; |
| 779 | int ret = 0; |
Benoit Gschwind | 2da6d0c | 2016-04-29 15:21:54 +0200 | [diff] [blame] | 780 | char *transform = NULL; |
Benoit Gschwind | 3c53094 | 2016-04-15 20:28:32 -0700 | [diff] [blame] | 781 | |
| 782 | config.width = 1024; |
| 783 | config.height = 640; |
| 784 | |
| 785 | const struct weston_option options[] = { |
| 786 | { WESTON_OPTION_INTEGER, "width", 0, &config.width }, |
| 787 | { WESTON_OPTION_INTEGER, "height", 0, &config.height }, |
| 788 | { WESTON_OPTION_BOOLEAN, "use-pixman", 0, &config.use_pixman }, |
| 789 | { WESTON_OPTION_STRING, "transform", 0, &transform }, |
| 790 | }; |
| 791 | |
| 792 | parse_options(options, ARRAY_LENGTH(options), argc, argv); |
| 793 | |
Benoit Gschwind | 2da6d0c | 2016-04-29 15:21:54 +0200 | [diff] [blame] | 794 | config.transform = WL_OUTPUT_TRANSFORM_NORMAL; |
| 795 | if (transform) { |
| 796 | if (weston_parse_transform(transform, &config.transform) < 0) |
| 797 | weston_log("Invalid transform \"%s\"\n", transform); |
| 798 | free(transform); |
| 799 | } |
Benoit Gschwind | 3c53094 | 2016-04-15 20:28:32 -0700 | [diff] [blame] | 800 | |
| 801 | config.base.struct_version = WESTON_HEADLESS_BACKEND_CONFIG_VERSION; |
| 802 | config.base.struct_size = sizeof(struct weston_headless_backend_config); |
| 803 | |
| 804 | /* load the actual wayland backend and configure it */ |
| 805 | ret = load_backend_new(c, backend, &config.base); |
| 806 | |
| 807 | return ret; |
| 808 | } |
| 809 | |
Benoit Gschwind | bd57310 | 2016-04-22 17:05:26 +0200 | [diff] [blame] | 810 | static void |
| 811 | weston_rdp_backend_config_init(struct weston_rdp_backend_config *config) |
| 812 | { |
| 813 | config->base.struct_version = WESTON_RDP_BACKEND_CONFIG_VERSION; |
| 814 | config->base.struct_size = sizeof(struct weston_rdp_backend_config); |
| 815 | |
| 816 | config->width = 640; |
| 817 | config->height = 480; |
| 818 | config->bind_address = NULL; |
| 819 | config->port = 3389; |
| 820 | config->rdp_key = NULL; |
| 821 | config->server_cert = NULL; |
| 822 | config->server_key = NULL; |
| 823 | config->env_socket = 0; |
| 824 | config->no_clients_resize = 0; |
| 825 | } |
| 826 | |
| 827 | static int |
| 828 | load_rdp_backend(struct weston_compositor *c, char const * backend, |
| 829 | int *argc, char *argv[], struct weston_config *wc) |
| 830 | { |
| 831 | struct weston_rdp_backend_config config = {{ 0, }}; |
| 832 | int ret = 0; |
| 833 | |
| 834 | weston_rdp_backend_config_init(&config); |
| 835 | |
| 836 | const struct weston_option rdp_options[] = { |
| 837 | { WESTON_OPTION_BOOLEAN, "env-socket", 0, &config.env_socket }, |
| 838 | { WESTON_OPTION_INTEGER, "width", 0, &config.width }, |
| 839 | { WESTON_OPTION_INTEGER, "height", 0, &config.height }, |
| 840 | { WESTON_OPTION_STRING, "address", 0, &config.bind_address }, |
| 841 | { WESTON_OPTION_INTEGER, "port", 0, &config.port }, |
| 842 | { WESTON_OPTION_BOOLEAN, "no-clients-resize", 0, &config.no_clients_resize }, |
| 843 | { WESTON_OPTION_STRING, "rdp4-key", 0, &config.rdp_key }, |
| 844 | { WESTON_OPTION_STRING, "rdp-tls-cert", 0, &config.server_cert }, |
| 845 | { WESTON_OPTION_STRING, "rdp-tls-key", 0, &config.server_key } |
| 846 | }; |
| 847 | |
| 848 | parse_options(rdp_options, ARRAY_LENGTH(rdp_options), argc, argv); |
| 849 | |
| 850 | ret = load_backend_new(c, backend, &config.base); |
| 851 | |
| 852 | free(config.bind_address); |
| 853 | free(config.rdp_key); |
| 854 | free(config.server_cert); |
| 855 | free(config.server_key); |
| 856 | return ret; |
| 857 | } |
| 858 | |
Benoit Gschwind | 3c53094 | 2016-04-15 20:28:32 -0700 | [diff] [blame] | 859 | static int |
Benoit Gschwind | 934e89a | 2016-04-27 23:56:42 +0200 | [diff] [blame] | 860 | load_fbdev_backend(struct weston_compositor *c, char const * backend, |
| 861 | int *argc, char **argv, struct weston_config *wc) |
| 862 | { |
| 863 | struct weston_fbdev_backend_config config = {{ 0, }}; |
| 864 | struct weston_config_section *section; |
| 865 | char *s = NULL; |
| 866 | int ret = 0; |
| 867 | |
| 868 | const struct weston_option fbdev_options[] = { |
| 869 | { WESTON_OPTION_INTEGER, "tty", 0, &config.tty }, |
| 870 | { WESTON_OPTION_STRING, "device", 0, &config.device }, |
| 871 | { WESTON_OPTION_BOOLEAN, "use-gl", 0, &config.use_gl }, |
| 872 | }; |
| 873 | |
| 874 | parse_options(fbdev_options, ARRAY_LENGTH(fbdev_options), argc, argv); |
| 875 | |
| 876 | if (!config.device) |
| 877 | config.device = strdup("/dev/fb0"); |
| 878 | |
| 879 | section = weston_config_get_section(wc, "output", "name", "fbdev"); |
| 880 | weston_config_section_get_string(section, "transform", &s, "normal"); |
| 881 | if (weston_parse_transform(s, &config.output_transform) < 0) |
| 882 | weston_log("Invalid transform \"%s\" for output fbdev\n", s); |
| 883 | free(s); |
| 884 | |
| 885 | config.base.struct_version = WESTON_FBDEV_BACKEND_CONFIG_VERSION; |
| 886 | config.base.struct_size = sizeof(struct weston_fbdev_backend_config); |
| 887 | |
| 888 | /* load the actual wayland backend and configure it */ |
| 889 | ret = load_backend_new(c, backend, &config.base); |
| 890 | |
| 891 | free(config.device); |
Benoit Gschwind | e16acab | 2016-04-15 20:28:31 -0700 | [diff] [blame] | 892 | |
| 893 | return ret; |
| 894 | } |
| 895 | |
| 896 | static int |
| 897 | weston_x11_backend_config_append_output_config(struct weston_x11_backend_config *config, |
| 898 | struct weston_x11_backend_output_config *output_config) { |
| 899 | struct weston_x11_backend_output_config *new_outputs; |
| 900 | |
| 901 | new_outputs = realloc(config->outputs, (config->num_outputs+1) * |
| 902 | sizeof(struct weston_x11_backend_output_config)); |
| 903 | if (new_outputs == NULL) |
| 904 | return -1; |
| 905 | |
| 906 | config->outputs = new_outputs; |
| 907 | config->outputs[config->num_outputs].width = output_config->width; |
| 908 | config->outputs[config->num_outputs].height = output_config->height; |
| 909 | config->outputs[config->num_outputs].transform = output_config->transform; |
| 910 | config->outputs[config->num_outputs].scale = output_config->scale; |
| 911 | config->outputs[config->num_outputs].name = strdup(output_config->name); |
| 912 | config->num_outputs++; |
| 913 | |
| 914 | return 0; |
| 915 | } |
| 916 | |
| 917 | static int |
| 918 | load_x11_backend(struct weston_compositor *c, char const * backend, |
| 919 | int *argc, char **argv, struct weston_config *wc) |
| 920 | { |
| 921 | struct weston_x11_backend_output_config default_output; |
| 922 | struct weston_x11_backend_config config = {{ 0, }}; |
| 923 | struct weston_config_section *section; |
| 924 | int ret = 0; |
| 925 | int option_width = 0; |
| 926 | int option_height = 0; |
| 927 | int option_scale = 0; |
| 928 | int option_count = 1; |
| 929 | int output_count = 0; |
| 930 | char const *section_name; |
| 931 | int i; |
| 932 | uint32_t j; |
| 933 | |
| 934 | const struct weston_option options[] = { |
| 935 | { WESTON_OPTION_INTEGER, "width", 0, &option_width }, |
| 936 | { WESTON_OPTION_INTEGER, "height", 0, &option_height }, |
| 937 | { WESTON_OPTION_INTEGER, "scale", 0, &option_scale }, |
| 938 | { WESTON_OPTION_BOOLEAN, "fullscreen", 'f', &config.fullscreen }, |
| 939 | { WESTON_OPTION_INTEGER, "output-count", 0, &option_count }, |
| 940 | { WESTON_OPTION_BOOLEAN, "no-input", 0, &config.no_input }, |
| 941 | { WESTON_OPTION_BOOLEAN, "use-pixman", 0, &config.use_pixman }, |
| 942 | }; |
| 943 | |
| 944 | parse_options(options, ARRAY_LENGTH(options), argc, argv); |
| 945 | |
| 946 | section = NULL; |
| 947 | while (weston_config_next_section(wc, §ion, §ion_name)) { |
| 948 | struct weston_x11_backend_output_config current_output = { 0, }; |
| 949 | char *t; |
| 950 | char *mode; |
| 951 | |
| 952 | if (strcmp(section_name, "output") != 0) { |
| 953 | continue; |
| 954 | } |
| 955 | |
| 956 | weston_config_section_get_string(section, "name", ¤t_output.name, NULL); |
| 957 | if (current_output.name == NULL || current_output.name[0] != 'X') { |
| 958 | free(current_output.name); |
| 959 | continue; |
| 960 | } |
| 961 | |
| 962 | weston_config_section_get_string(section, "mode", &mode, "1024x600"); |
| 963 | if (sscanf(mode, "%dx%d", ¤t_output.width, |
| 964 | ¤t_output.height) != 2) { |
| 965 | weston_log("Invalid mode \"%s\" for output %s\n", |
| 966 | mode, current_output.name); |
| 967 | current_output.width = 1024; |
| 968 | current_output.height = 600; |
| 969 | } |
| 970 | free(mode); |
| 971 | if (current_output.width < 1) |
| 972 | current_output.width = 1024; |
| 973 | if (current_output.height < 1) |
| 974 | current_output.height = 600; |
| 975 | if (option_width) |
| 976 | current_output.width = option_width; |
| 977 | if (option_height) |
| 978 | current_output.height = option_height; |
| 979 | |
| 980 | weston_config_section_get_int(section, "scale", ¤t_output.scale, 1); |
| 981 | if (option_scale) |
| 982 | current_output.scale = option_scale; |
| 983 | |
| 984 | weston_config_section_get_string(section, |
| 985 | "transform", &t, "normal"); |
| 986 | if (weston_parse_transform(t, ¤t_output.transform) < 0) |
| 987 | weston_log("Invalid transform \"%s\" for output %s\n", |
| 988 | t, current_output.name); |
| 989 | free(t); |
| 990 | |
| 991 | if (weston_x11_backend_config_append_output_config(&config, ¤t_output) < 0) { |
| 992 | ret = -1; |
| 993 | goto out; |
| 994 | } |
| 995 | |
| 996 | output_count++; |
Bryce Harrington | aa25898 | 2016-05-03 01:34:23 -0700 | [diff] [blame] | 997 | if (output_count >= option_count) |
Benoit Gschwind | e16acab | 2016-04-15 20:28:31 -0700 | [diff] [blame] | 998 | break; |
| 999 | } |
| 1000 | |
| 1001 | default_output.name = NULL; |
| 1002 | default_output.width = option_width ? option_width : 1024; |
| 1003 | default_output.height = option_height ? option_height : 600; |
| 1004 | default_output.scale = option_scale ? option_scale : 1; |
| 1005 | default_output.transform = WL_OUTPUT_TRANSFORM_NORMAL; |
| 1006 | |
| 1007 | for (i = output_count; i < option_count; i++) { |
| 1008 | if (asprintf(&default_output.name, "screen%d", i) < 0) { |
| 1009 | ret = -1; |
| 1010 | goto out; |
| 1011 | } |
| 1012 | |
| 1013 | if (weston_x11_backend_config_append_output_config(&config, &default_output) < 0) { |
| 1014 | ret = -1; |
| 1015 | free(default_output.name); |
| 1016 | goto out; |
| 1017 | } |
| 1018 | free(default_output.name); |
| 1019 | } |
| 1020 | |
| 1021 | config.base.struct_version = WESTON_X11_BACKEND_CONFIG_VERSION; |
| 1022 | config.base.struct_size = sizeof(struct weston_x11_backend_config); |
| 1023 | |
| 1024 | /* load the actual backend and configure it */ |
| 1025 | ret = load_backend_new(c, backend, &config.base); |
| 1026 | |
| 1027 | out: |
| 1028 | for (j = 0; j < config.num_outputs; ++j) |
| 1029 | free(config.outputs[j].name); |
| 1030 | free(config.outputs); |
| 1031 | |
Benoit Gschwind | 934e89a | 2016-04-27 23:56:42 +0200 | [diff] [blame] | 1032 | return ret; |
| 1033 | } |
| 1034 | |
Benoit Gschwind | 3ff10da | 2016-05-10 22:47:49 +0200 | [diff] [blame^] | 1035 | static void |
| 1036 | weston_wayland_output_config_init(struct weston_wayland_backend_output_config *output_config, |
| 1037 | struct weston_config_section *config_section, |
| 1038 | int option_width, int option_height, |
| 1039 | int option_scale) |
| 1040 | { |
| 1041 | char *mode, *t, *str; |
| 1042 | unsigned int slen; |
| 1043 | |
| 1044 | weston_config_section_get_string(config_section, "name", &output_config->name, |
| 1045 | NULL); |
| 1046 | if (output_config->name) { |
| 1047 | slen = strlen(output_config->name); |
| 1048 | slen += strlen(WINDOW_TITLE " - "); |
| 1049 | str = malloc(slen + 1); |
| 1050 | if (str) |
| 1051 | snprintf(str, slen + 1, WINDOW_TITLE " - %s", |
| 1052 | output_config->name); |
| 1053 | free(output_config->name); |
| 1054 | output_config->name = str; |
| 1055 | } |
| 1056 | if (!output_config->name) |
| 1057 | output_config->name = strdup(WINDOW_TITLE); |
| 1058 | |
| 1059 | weston_config_section_get_string(config_section, |
| 1060 | "mode", &mode, "1024x600"); |
| 1061 | if (sscanf(mode, "%dx%d", &output_config->width, &output_config->height) != 2) { |
| 1062 | weston_log("Invalid mode \"%s\" for output %s\n", |
| 1063 | mode, output_config->name); |
| 1064 | output_config->width = 1024; |
| 1065 | output_config->height = 640; |
| 1066 | } |
| 1067 | free(mode); |
| 1068 | |
| 1069 | if (option_width) |
| 1070 | output_config->width = option_width; |
| 1071 | if (option_height) |
| 1072 | output_config->height = option_height; |
| 1073 | |
| 1074 | weston_config_section_get_int(config_section, "scale", &output_config->scale, 1); |
| 1075 | |
| 1076 | if (option_scale) |
| 1077 | output_config->scale = option_scale; |
| 1078 | |
| 1079 | weston_config_section_get_string(config_section, |
| 1080 | "transform", &t, "normal"); |
| 1081 | if (weston_parse_transform(t, &output_config->transform) < 0) |
| 1082 | weston_log("Invalid transform \"%s\" for output %s\n", |
| 1083 | t, output_config->name); |
| 1084 | free(t); |
| 1085 | |
| 1086 | } |
| 1087 | |
| 1088 | static void |
| 1089 | wayland_backend_config_release(struct weston_wayland_backend_config *new_config) |
| 1090 | { |
| 1091 | int i; |
| 1092 | |
| 1093 | for (i = 0; i < new_config->num_outputs; ++i) { |
| 1094 | free(new_config->outputs[i].name); |
| 1095 | } |
| 1096 | free(new_config->cursor_theme); |
| 1097 | free(new_config->display_name); |
| 1098 | free(new_config->outputs); |
| 1099 | } |
| 1100 | |
| 1101 | /* |
| 1102 | * Append a new output struct at the end of new_config.outputs and return a |
| 1103 | * pointer to the newly allocated structure or NULL if fail. The allocated |
| 1104 | * structure is NOT cleared nor set to default values. |
| 1105 | */ |
| 1106 | static struct weston_wayland_backend_output_config * |
| 1107 | wayland_backend_config_add_new_output(struct weston_wayland_backend_config *new_config) |
| 1108 | { |
| 1109 | struct weston_wayland_backend_output_config *outputs; |
| 1110 | const size_t element_size = sizeof(struct weston_wayland_backend_output_config); |
| 1111 | |
| 1112 | outputs = realloc(new_config->outputs, |
| 1113 | (new_config->num_outputs + 1) * element_size); |
| 1114 | if (!outputs) |
| 1115 | return NULL; |
| 1116 | new_config->num_outputs += 1; |
| 1117 | new_config->outputs = outputs; |
| 1118 | return &(new_config->outputs[new_config->num_outputs - 1]); |
| 1119 | } |
| 1120 | |
| 1121 | static int |
| 1122 | load_wayland_backend_config(struct weston_compositor *compositor, int *argc, |
| 1123 | char *argv[], struct weston_config *config, |
| 1124 | struct weston_wayland_backend_config *out_config) |
| 1125 | { |
| 1126 | struct weston_wayland_backend_config new_config = {{ 0, }}; |
| 1127 | struct weston_config_section *section; |
| 1128 | struct weston_wayland_backend_output_config *oc; |
| 1129 | int count, width, height, scale; |
| 1130 | const char *section_name; |
| 1131 | char *name; |
| 1132 | |
| 1133 | const struct weston_option wayland_options[] = { |
| 1134 | { WESTON_OPTION_INTEGER, "width", 0, &width }, |
| 1135 | { WESTON_OPTION_INTEGER, "height", 0, &height }, |
| 1136 | { WESTON_OPTION_INTEGER, "scale", 0, &scale }, |
| 1137 | { WESTON_OPTION_STRING, "display", 0, &new_config.display_name }, |
| 1138 | { WESTON_OPTION_BOOLEAN, "use-pixman", 0, &new_config.use_pixman }, |
| 1139 | { WESTON_OPTION_INTEGER, "output-count", 0, &count }, |
| 1140 | { WESTON_OPTION_BOOLEAN, "fullscreen", 0, &new_config.fullscreen }, |
| 1141 | { WESTON_OPTION_BOOLEAN, "sprawl", 0, &new_config.sprawl }, |
| 1142 | }; |
| 1143 | |
| 1144 | width = 0; |
| 1145 | height = 0; |
| 1146 | scale = 0; |
| 1147 | new_config.display_name = NULL; |
| 1148 | new_config.use_pixman = 0; |
| 1149 | count = 1; |
| 1150 | new_config.fullscreen = 0; |
| 1151 | new_config.sprawl = 0; |
| 1152 | parse_options(wayland_options, |
| 1153 | ARRAY_LENGTH(wayland_options), argc, argv); |
| 1154 | |
| 1155 | new_config.cursor_size = 32; |
| 1156 | new_config.cursor_theme = NULL; |
| 1157 | new_config.base.struct_size = sizeof(struct weston_wayland_backend_config); |
| 1158 | new_config.base.struct_version = WESTON_WAYLAND_BACKEND_CONFIG_VERSION; |
| 1159 | |
| 1160 | section = weston_config_get_section(config, "shell", NULL, NULL); |
| 1161 | weston_config_section_get_string(section, "cursor-theme", |
| 1162 | &new_config.cursor_theme, NULL); |
| 1163 | weston_config_section_get_int(section, "cursor-size", |
| 1164 | &new_config.cursor_size, 32); |
| 1165 | |
| 1166 | if (new_config.sprawl) { |
| 1167 | /* do nothing, everything is already set */ |
| 1168 | *out_config = new_config; |
| 1169 | return 0; |
| 1170 | } |
| 1171 | |
| 1172 | if (new_config.fullscreen) { |
| 1173 | oc = wayland_backend_config_add_new_output(&new_config); |
| 1174 | if (!oc) |
| 1175 | goto err_outputs; |
| 1176 | |
| 1177 | oc->width = width; |
| 1178 | oc->height = height; |
| 1179 | oc->name = NULL; |
| 1180 | oc->transform = WL_OUTPUT_TRANSFORM_NORMAL; |
| 1181 | oc->scale = 1; |
| 1182 | |
| 1183 | *out_config = new_config; |
| 1184 | return 0; |
| 1185 | } |
| 1186 | |
| 1187 | section = NULL; |
| 1188 | while (weston_config_next_section(config, §ion, §ion_name)) { |
| 1189 | if (!section_name || strcmp(section_name, "output") != 0) |
| 1190 | continue; |
| 1191 | weston_config_section_get_string(section, "name", &name, NULL); |
| 1192 | if (name == NULL) |
| 1193 | continue; |
| 1194 | |
| 1195 | if (name[0] != 'W' || name[1] != 'L') { |
| 1196 | free(name); |
| 1197 | continue; |
| 1198 | } |
| 1199 | free(name); |
| 1200 | |
| 1201 | oc = wayland_backend_config_add_new_output(&new_config); |
| 1202 | |
| 1203 | if (!oc) |
| 1204 | goto err_outputs; |
| 1205 | |
| 1206 | weston_wayland_output_config_init(oc, section, width, |
| 1207 | height, scale); |
| 1208 | --count; |
| 1209 | } |
| 1210 | |
| 1211 | if (!width) |
| 1212 | width = 1024; |
| 1213 | if (!height) |
| 1214 | height = 640; |
| 1215 | if (!scale) |
| 1216 | scale = 1; |
| 1217 | while (count > 0) { |
| 1218 | |
| 1219 | oc = wayland_backend_config_add_new_output(&new_config); |
| 1220 | |
| 1221 | if (!oc) |
| 1222 | goto err_outputs; |
| 1223 | |
| 1224 | oc->width = width; |
| 1225 | oc->height = height; |
| 1226 | oc->name = NULL; |
| 1227 | oc->transform = WL_OUTPUT_TRANSFORM_NORMAL; |
| 1228 | oc->scale = scale; |
| 1229 | |
| 1230 | --count; |
| 1231 | } |
| 1232 | |
| 1233 | *out_config = new_config; |
| 1234 | return 0; |
| 1235 | |
| 1236 | err_outputs: |
| 1237 | wayland_backend_config_release(&new_config); |
| 1238 | return -1; |
| 1239 | } |
| 1240 | |
| 1241 | static int |
| 1242 | load_wayland_backend(struct weston_compositor *c, char const * backend, |
| 1243 | int *argc, char **argv, struct weston_config *wc) |
| 1244 | { |
| 1245 | struct weston_wayland_backend_config config = {{ 0, }}; |
| 1246 | int ret = 0; |
| 1247 | |
| 1248 | ret = load_wayland_backend_config(c, argc, argv, wc, &config); |
| 1249 | if(ret < 0) { |
| 1250 | return ret; |
| 1251 | } |
| 1252 | |
| 1253 | /* load the actual wayland backend and configure it */ |
| 1254 | ret = load_backend_new(c, backend, &config.base); |
| 1255 | wayland_backend_config_release(&config); |
| 1256 | return ret; |
| 1257 | } |
| 1258 | |
| 1259 | |
Benoit Gschwind | 934e89a | 2016-04-27 23:56:42 +0200 | [diff] [blame] | 1260 | static int |
Giulio Camuffo | 43008c7 | 2015-10-17 19:24:15 +0300 | [diff] [blame] | 1261 | load_backend(struct weston_compositor *compositor, const char *backend, |
| 1262 | int *argc, char **argv, struct weston_config *config) |
| 1263 | { |
Benoit Gschwind | 3c53094 | 2016-04-15 20:28:32 -0700 | [diff] [blame] | 1264 | if (strstr(backend, "headless-backend.so")) |
| 1265 | return load_headless_backend(compositor, backend, argc, argv, config); |
Benoit Gschwind | bd57310 | 2016-04-22 17:05:26 +0200 | [diff] [blame] | 1266 | else if (strstr(backend, "rdp-backend.so")) |
| 1267 | return load_rdp_backend(compositor, backend, argc, argv, config); |
Benoit Gschwind | 934e89a | 2016-04-27 23:56:42 +0200 | [diff] [blame] | 1268 | else if (strstr(backend, "fbdev-backend.so")) |
| 1269 | return load_fbdev_backend(compositor, backend, argc, argv, config); |
Giulio Camuffo | 1c0e40d | 2016-04-29 15:40:34 -0700 | [diff] [blame] | 1270 | else if (strstr(backend, "drm-backend.so")) |
| 1271 | return load_drm_backend(compositor, backend, argc, argv, config); |
Benoit Gschwind | e16acab | 2016-04-15 20:28:31 -0700 | [diff] [blame] | 1272 | else if (strstr(backend, "x11-backend.so")) |
| 1273 | return load_x11_backend(compositor, backend, argc, argv, config); |
Giulio Camuffo | 43008c7 | 2015-10-17 19:24:15 +0300 | [diff] [blame] | 1274 | else if (strstr(backend, "wayland-backend.so")) |
| 1275 | return load_wayland_backend(compositor, backend, argc, argv, config); |
Benoit Gschwind | 3ff10da | 2016-05-10 22:47:49 +0200 | [diff] [blame^] | 1276 | #if 0 |
Giulio Camuffo | 43008c7 | 2015-10-17 19:24:15 +0300 | [diff] [blame] | 1277 | else if (strstr(backend, "rpi-backend.so")) |
| 1278 | return load_rpi_backend(compositor, backend, argc, argv, config); |
Giulio Camuffo | 43008c7 | 2015-10-17 19:24:15 +0300 | [diff] [blame] | 1279 | #endif |
| 1280 | |
| 1281 | return load_backend_old(compositor, backend, argc, argv, config); |
| 1282 | } |
| 1283 | |
Giulio Camuffo | bab996e | 2014-10-12 00:24:25 +0300 | [diff] [blame] | 1284 | int main(int argc, char *argv[]) |
| 1285 | { |
| 1286 | int ret = EXIT_FAILURE; |
| 1287 | struct wl_display *display; |
| 1288 | struct weston_compositor *ec; |
| 1289 | struct wl_event_source *signals[4]; |
| 1290 | struct wl_event_loop *loop; |
Giulio Camuffo | bab996e | 2014-10-12 00:24:25 +0300 | [diff] [blame] | 1291 | int i, fd; |
| 1292 | char *backend = NULL; |
| 1293 | char *shell = NULL; |
| 1294 | char *modules = NULL; |
| 1295 | char *option_modules = NULL; |
| 1296 | char *log = NULL; |
| 1297 | char *server_socket = NULL, *end; |
| 1298 | int32_t idle_time = -1; |
| 1299 | int32_t help = 0; |
| 1300 | char *socket_name = NULL; |
| 1301 | int32_t version = 0; |
| 1302 | int32_t noconfig = 0; |
| 1303 | int32_t numlock_on; |
| 1304 | char *config_file = NULL; |
| 1305 | struct weston_config *config = NULL; |
| 1306 | struct weston_config_section *section; |
| 1307 | struct wl_client *primary_client; |
| 1308 | struct wl_listener primary_client_destroyed; |
| 1309 | struct weston_seat *seat; |
| 1310 | |
| 1311 | const struct weston_option core_options[] = { |
| 1312 | { WESTON_OPTION_STRING, "backend", 'B', &backend }, |
| 1313 | { WESTON_OPTION_STRING, "shell", 0, &shell }, |
| 1314 | { WESTON_OPTION_STRING, "socket", 'S', &socket_name }, |
| 1315 | { WESTON_OPTION_INTEGER, "idle-time", 'i', &idle_time }, |
| 1316 | { WESTON_OPTION_STRING, "modules", 0, &option_modules }, |
| 1317 | { WESTON_OPTION_STRING, "log", 0, &log }, |
| 1318 | { WESTON_OPTION_BOOLEAN, "help", 'h', &help }, |
| 1319 | { WESTON_OPTION_BOOLEAN, "version", 0, &version }, |
| 1320 | { WESTON_OPTION_BOOLEAN, "no-config", 0, &noconfig }, |
| 1321 | { WESTON_OPTION_STRING, "config", 'c', &config_file }, |
| 1322 | }; |
| 1323 | |
| 1324 | parse_options(core_options, ARRAY_LENGTH(core_options), &argc, argv); |
| 1325 | |
| 1326 | if (help) |
| 1327 | usage(EXIT_SUCCESS); |
| 1328 | |
| 1329 | if (version) { |
| 1330 | printf(PACKAGE_STRING "\n"); |
| 1331 | return EXIT_SUCCESS; |
| 1332 | } |
| 1333 | |
| 1334 | weston_log_file_open(log); |
| 1335 | |
| 1336 | weston_log("%s\n" |
| 1337 | STAMP_SPACE "%s\n" |
| 1338 | STAMP_SPACE "Bug reports to: %s\n" |
| 1339 | STAMP_SPACE "Build: %s\n", |
| 1340 | PACKAGE_STRING, PACKAGE_URL, PACKAGE_BUGREPORT, |
| 1341 | BUILD_ID); |
| 1342 | log_uname(); |
| 1343 | |
| 1344 | verify_xdg_runtime_dir(); |
| 1345 | |
| 1346 | display = wl_display_create(); |
| 1347 | |
| 1348 | loop = wl_display_get_event_loop(display); |
| 1349 | signals[0] = wl_event_loop_add_signal(loop, SIGTERM, on_term_signal, |
| 1350 | display); |
| 1351 | signals[1] = wl_event_loop_add_signal(loop, SIGINT, on_term_signal, |
| 1352 | display); |
| 1353 | signals[2] = wl_event_loop_add_signal(loop, SIGQUIT, on_term_signal, |
| 1354 | display); |
| 1355 | |
| 1356 | wl_list_init(&child_process_list); |
| 1357 | signals[3] = wl_event_loop_add_signal(loop, SIGCHLD, sigchld_handler, |
| 1358 | NULL); |
| 1359 | |
| 1360 | if (!signals[0] || !signals[1] || !signals[2] || !signals[3]) |
| 1361 | goto out_signals; |
| 1362 | |
| 1363 | if (load_configuration(&config, noconfig, config_file) < 0) |
| 1364 | goto out_signals; |
| 1365 | |
| 1366 | section = weston_config_get_section(config, "core", NULL, NULL); |
| 1367 | |
| 1368 | if (!backend) { |
| 1369 | weston_config_section_get_string(section, "backend", &backend, |
| 1370 | NULL); |
| 1371 | if (!backend) |
| 1372 | backend = weston_choose_default_backend(); |
| 1373 | } |
| 1374 | |
Giulio Camuffo | 1c0e40d | 2016-04-29 15:40:34 -0700 | [diff] [blame] | 1375 | ec = weston_compositor_create(display, config); |
Giulio Camuffo | bab996e | 2014-10-12 00:24:25 +0300 | [diff] [blame] | 1376 | if (ec == NULL) { |
| 1377 | weston_log("fatal: failed to create compositor\n"); |
Giulio Camuffo | 3c241b1 | 2015-10-03 16:25:16 +0300 | [diff] [blame] | 1378 | goto out; |
Giulio Camuffo | bab996e | 2014-10-12 00:24:25 +0300 | [diff] [blame] | 1379 | } |
| 1380 | |
| 1381 | ec->config = config; |
| 1382 | if (weston_compositor_init_config(ec, config) < 0) |
Giulio Camuffo | 3c241b1 | 2015-10-03 16:25:16 +0300 | [diff] [blame] | 1383 | goto out; |
Giulio Camuffo | bab996e | 2014-10-12 00:24:25 +0300 | [diff] [blame] | 1384 | |
Giulio Camuffo | 43008c7 | 2015-10-17 19:24:15 +0300 | [diff] [blame] | 1385 | if (load_backend(ec, backend, &argc, argv, config) < 0) { |
Giulio Camuffo | bab996e | 2014-10-12 00:24:25 +0300 | [diff] [blame] | 1386 | weston_log("fatal: failed to create compositor backend\n"); |
Giulio Camuffo | 3c241b1 | 2015-10-03 16:25:16 +0300 | [diff] [blame] | 1387 | goto out; |
Giulio Camuffo | bab996e | 2014-10-12 00:24:25 +0300 | [diff] [blame] | 1388 | } |
| 1389 | |
| 1390 | catch_signals(); |
| 1391 | segv_compositor = ec; |
| 1392 | |
| 1393 | if (idle_time < 0) |
| 1394 | weston_config_section_get_int(section, "idle-time", &idle_time, -1); |
| 1395 | if (idle_time < 0) |
| 1396 | idle_time = 300; /* default idle timeout, in seconds */ |
| 1397 | |
| 1398 | ec->idle_time = idle_time; |
| 1399 | ec->default_pointer_grab = NULL; |
| 1400 | ec->exit = handle_exit; |
| 1401 | |
| 1402 | weston_compositor_log_capabilities(ec); |
| 1403 | |
| 1404 | server_socket = getenv("WAYLAND_SERVER_SOCKET"); |
| 1405 | if (server_socket) { |
| 1406 | weston_log("Running with single client\n"); |
| 1407 | fd = strtol(server_socket, &end, 0); |
| 1408 | if (*end != '\0') |
| 1409 | fd = -1; |
| 1410 | } else { |
| 1411 | fd = -1; |
| 1412 | } |
| 1413 | |
| 1414 | if (fd != -1) { |
| 1415 | primary_client = wl_client_create(display, fd); |
| 1416 | if (!primary_client) { |
| 1417 | weston_log("fatal: failed to add client: %m\n"); |
| 1418 | goto out; |
| 1419 | } |
| 1420 | primary_client_destroyed.notify = |
| 1421 | handle_primary_client_destroyed; |
| 1422 | wl_client_add_destroy_listener(primary_client, |
| 1423 | &primary_client_destroyed); |
| 1424 | } else if (weston_create_listening_socket(display, socket_name)) { |
| 1425 | goto out; |
| 1426 | } |
| 1427 | |
| 1428 | if (!shell) |
| 1429 | weston_config_section_get_string(section, "shell", &shell, |
| 1430 | "desktop-shell.so"); |
| 1431 | |
| 1432 | if (load_modules(ec, shell, &argc, argv) < 0) |
| 1433 | goto out; |
| 1434 | |
| 1435 | weston_config_section_get_string(section, "modules", &modules, ""); |
| 1436 | if (load_modules(ec, modules, &argc, argv) < 0) |
| 1437 | goto out; |
| 1438 | |
| 1439 | if (load_modules(ec, option_modules, &argc, argv) < 0) |
| 1440 | goto out; |
| 1441 | |
| 1442 | section = weston_config_get_section(config, "keyboard", NULL, NULL); |
| 1443 | weston_config_section_get_bool(section, "numlock-on", &numlock_on, 0); |
| 1444 | if (numlock_on) { |
| 1445 | wl_list_for_each(seat, &ec->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1446 | struct weston_keyboard *keyboard = |
| 1447 | weston_seat_get_keyboard(seat); |
| 1448 | |
| 1449 | if (keyboard) |
| 1450 | weston_keyboard_set_locks(keyboard, |
Giulio Camuffo | bab996e | 2014-10-12 00:24:25 +0300 | [diff] [blame] | 1451 | WESTON_NUM_LOCK, |
| 1452 | WESTON_NUM_LOCK); |
| 1453 | } |
| 1454 | } |
| 1455 | |
| 1456 | for (i = 1; i < argc; i++) |
| 1457 | weston_log("fatal: unhandled option: %s\n", argv[i]); |
| 1458 | if (argc > 1) |
| 1459 | goto out; |
| 1460 | |
| 1461 | weston_compositor_wake(ec); |
| 1462 | |
| 1463 | wl_display_run(display); |
| 1464 | |
| 1465 | /* Allow for setting return exit code after |
| 1466 | * wl_display_run returns normally. This is |
| 1467 | * useful for devs/testers and automated tests |
| 1468 | * that want to indicate failure status to |
| 1469 | * testing infrastructure above |
| 1470 | */ |
| 1471 | ret = ec->exit_code; |
| 1472 | |
| 1473 | out: |
| 1474 | weston_compositor_destroy(ec); |
| 1475 | |
| 1476 | out_signals: |
| 1477 | for (i = ARRAY_LENGTH(signals) - 1; i >= 0; i--) |
| 1478 | if (signals[i]) |
| 1479 | wl_event_source_remove(signals[i]); |
| 1480 | |
| 1481 | wl_display_destroy(display); |
| 1482 | |
| 1483 | weston_log_file_close(); |
| 1484 | |
| 1485 | if (config) |
| 1486 | weston_config_destroy(config); |
| 1487 | free(config_file); |
| 1488 | free(backend); |
| 1489 | free(shell); |
| 1490 | free(socket_name); |
| 1491 | free(option_modules); |
| 1492 | free(log); |
| 1493 | free(modules); |
| 1494 | |
| 1495 | return ret; |
| 1496 | } |