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