# Exo wayland server [exo::wayland::Server](https://source.chromium.org/chromium/chromium/src/+/main:components/exo/wayland/server.h;l=46;drc=8ff7bf3a27e401e9f7d214a4cd7cb587da36ce54) is a wrapper class around a Wayland display server. ## Initialization To create wayland server, we call [Server::Create](https://source.chromium.org/chromium/chromium/src/+/main:components/exo/wayland/server.cc;l=420;drc=1e688463e91aa65cd47d54b7c2a8c4516b912646) with [Display](https://source.chromium.org/chromium/chromium/src/+/main:components/exo/display.h;l=45;drc=1e688463e91aa65cd47d54b7c2a8c4516b912646) and [SecurityDelegate](https://source.chromium.org/chromium/chromium/src/+/main:components/exo/security_delegate.h;l=42;drc=1e688463e91aa65cd47d54b7c2a8c4516b912646). It creates Server instance and call [Server::Initialize](https://source.chromium.org/chromium/chromium/src/+/main:components/exo/wayland/server.cc;l=262;drc=b8be952f6cd08d311fd10d4de475fdac151e33f0). On construction, it initializes `wl_display_` via `wl_display_create`. And it sets security delegate. [`wayland_log`](https://source.chromium.org/chromium/chromium/src/+/main:components/exo/wayland/server.cc;l=138;drc=b8be952f6cd08d311fd10d4de475fdac151e33f0) logs out "libwayland: error" as waning message. This is set by wl_log_set_handler_server on construction as well. On initialization, it creates each wayland global object via [`wl_global_create`](https://source.chromium.org/chromium/chromium/src/+/main:third_party/wayland/src/src/wayland-server.c;l=1231;drc=1e688463e91aa65cd47d54b7c2a8c4516b912646). It also holds some data object such as WaylandDataDeviceManager, WaylandSeat, WaylandXdgShell.. which are used to create global object. Then the server is started by [StartWithDefaultPath](https://source.chromium.org/chromium/chromium/src/+/main:components/exo/wayland/server.cc;l=440;drc=1e688463e91aa65cd47d54b7c2a8c4516b912646) or [StartWithFdAsync](https://source.chromium.org/chromium/chromium/src/+/main:components/exo/wayland/server.cc;l=448;drc=1e688463e91aa65cd47d54b7c2a8c4516b912646). The first one uses `XDG_RUNTIME_DIR` env var as a socket path. It calls [Open](https://source.chromium.org/chromium/chromium/src/+/main:components/exo/wayland/server.cc;l=166;drc=1e688463e91aa65cd47d54b7c2a8c4516b912646) and gets runtime dir by `getenv` and readh it. On the other hand, the second one uses given `fd`. It calls [OpenFd](https://source.chromium.org/chromium/chromium/src/+/main:components/exo/wayland/server.cc;l=229;drc=1e688463e91aa65cd47d54b7c2a8c4516b912646). `listen` fd and `wl_display_add_socket_fd` adds the socket to the `wl_display`. ## Wayland Server Controller Who owns Server in the production? [WaylandServerController](https://source.chromium.org/chromium/chromium/src/+/main:components/exo/server/wayland_server_controller.h;l=32;drc=7c9ff73e53a7b1e947dffc15d7019cf852907ea7) controlls Server. It calls Server::Create. WaylandServerController is a part of [ExoParts](https://source.chromium.org/chromium/chromium/src/+/main:chrome/browser/exo_parts.cc;l=40-45;drc=1e688463e91aa65cd47d54b7c2a8c4516b912646). This is created on [PrProfileInit](https://source.chromium.org/chromium/chromium/src/+/main:chrome/browser/ui/ash/chrome_browser_main_extra_parts_ash.cc;l=290;drc=1e688463e91aa65cd47d54b7c2a8c4516b912646). ## On testing We have [WaylandClientTestHelper](https://source.chromium.org/chromium/chromium/src/+/main:components/exo/wayland/clients/test/wayland_client_test_helper.h;l=28;drc=8ba1bad80dc22235693a0dd41fe55c0fd2dbdabd), the helper class to test on server side. Here, we initialize Server on [SetUpOnUIThread](https://source.chromium.org/chromium/chromium/src/+/main:components/exo/wayland/clients/test/wayland_client_test_helper.cc;l=95-96;drc=1e688463e91aa65cd47d54b7c2a8c4516b912646).