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