compositor: extract choose_default_backend and create_listening_socket

Extract these two new functions from main() to improve readability.
Refactoring only, no functioncal changes.

[Pekka Paalanen: commit message]

Signed-off-by: Ryo Munakata <ryomnktml@gmail.com>
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
dev
Ryo Munakata 10 years ago committed by Pekka Paalanen
parent 041a981a4e
commit d8deff617a
  1. 62
      src/compositor.c

@ -4279,6 +4279,42 @@ handle_primary_client_destroyed(struct wl_listener *listener, void *data)
wl_display_terminate(wl_client_get_display(client)); wl_display_terminate(wl_client_get_display(client));
} }
static char *
weston_choose_default_backend(void)
{
char *backend = NULL;
if (getenv("WAYLAND_DISPLAY") || getenv("WAYLAND_SOCKET"))
backend = strdup("wayland-backend.so");
else if (getenv("DISPLAY"))
backend = strdup("x11-backend.so");
else
backend = strdup(WESTON_NATIVE_BACKEND);
return backend;
}
static int
weston_create_listening_socket(struct wl_display *display, const char *socket_name)
{
if (socket_name) {
if (wl_display_add_socket(display, socket_name)) {
weston_log("fatal: failed to add socket: %m\n");
return -1;
}
} else {
socket_name = wl_display_add_socket_auto(display);
if (!socket_name) {
weston_log("fatal: failed to add socket: %m\n");
return -1;
}
}
setenv("WAYLAND_DISPLAY", socket_name, 1);
return 0;
}
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
int ret = EXIT_SUCCESS; int ret = EXIT_SUCCESS;
@ -4379,14 +4415,8 @@ int main(int argc, char *argv[])
weston_config_section_get_string(section, "backend", &backend, weston_config_section_get_string(section, "backend", &backend,
NULL); NULL);
if (!backend) { if (!backend)
if (getenv("WAYLAND_DISPLAY") || getenv("WAYLAND_SOCKET")) backend = weston_choose_default_backend();
backend = strdup("wayland-backend.so");
else if (getenv("DISPLAY"))
backend = strdup("x11-backend.so");
else
backend = strdup(WESTON_NATIVE_BACKEND);
}
backend_init = weston_load_module(backend, "backend_init"); backend_init = weston_load_module(backend, "backend_init");
free(backend); free(backend);
@ -4438,24 +4468,10 @@ int main(int argc, char *argv[])
handle_primary_client_destroyed; handle_primary_client_destroyed;
wl_client_add_destroy_listener(primary_client, wl_client_add_destroy_listener(primary_client,
&primary_client_destroyed); &primary_client_destroyed);
} else { } else if (weston_create_listening_socket(display, socket_name)) {
if (socket_name) {
if (wl_display_add_socket(display, socket_name)) {
weston_log("fatal: failed to add socket: %m\n");
ret = EXIT_FAILURE; ret = EXIT_FAILURE;
goto out; goto out;
} }
} else {
socket_name = wl_display_add_socket_auto(display);
if (!socket_name) {
weston_log("fatal: failed to add socket: %m\n");
ret = EXIT_FAILURE;
goto out;
}
}
setenv("WAYLAND_DISPLAY", socket_name, 1);
}
if (option_shell) if (option_shell)
shell = strdup(option_shell); shell = strdup(option_shell);

Loading…
Cancel
Save