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