mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2024-11-22 07:02:28 +00:00
backend: return wlr_session in wlr_backend_autocreate() call
Up until now, wlr_backend_autocreate() created the wlr_session and then stuffed it into struct wlr_multi_backend so that compositors can grab it later. This is an abuse of wlr_multi_backend and the wlr_backend API: wlr_backend_get_session() and wlr_multi_backend.session only exist to accomodate the needs of wlr_backend_autocreate(). What's more, the DRM and libinput backends don't implement wlr_backend_impl.get_session. Instead, return the struct wlr_session to the compositor in the wlr_backend_autocreate() call. wlr_backend_get_session() will be removed in the next commit.
This commit is contained in:
parent
265439600e
commit
41b7acbab7
@ -245,7 +245,8 @@ static struct wlr_backend *attempt_drm_backend(struct wl_display *display,
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
static bool attempt_backend_by_name(struct wl_display *display,
|
static bool attempt_backend_by_name(struct wl_display *display,
|
||||||
struct wlr_multi_backend *multi, char *name) {
|
struct wlr_backend *multi, char *name,
|
||||||
|
struct wlr_session **session_ptr) {
|
||||||
struct wlr_backend *backend = NULL;
|
struct wlr_backend *backend = NULL;
|
||||||
if (strcmp(name, "wayland") == 0) {
|
if (strcmp(name, "wayland") == 0) {
|
||||||
backend = attempt_wl_backend(display);
|
backend = attempt_wl_backend(display);
|
||||||
@ -257,9 +258,9 @@ static bool attempt_backend_by_name(struct wl_display *display,
|
|||||||
backend = attempt_headless_backend(display);
|
backend = attempt_headless_backend(display);
|
||||||
} else if (strcmp(name, "drm") == 0 || strcmp(name, "libinput") == 0) {
|
} else if (strcmp(name, "drm") == 0 || strcmp(name, "libinput") == 0) {
|
||||||
// DRM and libinput need a session
|
// DRM and libinput need a session
|
||||||
if (multi->session == NULL) {
|
if (*session_ptr == NULL) {
|
||||||
multi->session = session_create_and_wait(display);
|
*session_ptr = session_create_and_wait(display);
|
||||||
if (multi->session == NULL) {
|
if (*session_ptr == NULL) {
|
||||||
wlr_log(WLR_ERROR, "failed to start a session");
|
wlr_log(WLR_ERROR, "failed to start a session");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -267,13 +268,13 @@ static bool attempt_backend_by_name(struct wl_display *display,
|
|||||||
|
|
||||||
if (strcmp(name, "libinput") == 0) {
|
if (strcmp(name, "libinput") == 0) {
|
||||||
#if WLR_HAS_LIBINPUT_BACKEND
|
#if WLR_HAS_LIBINPUT_BACKEND
|
||||||
backend = wlr_libinput_backend_create(display, multi->session);
|
backend = wlr_libinput_backend_create(display, *session_ptr);
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
#if WLR_HAS_DRM_BACKEND
|
#if WLR_HAS_DRM_BACKEND
|
||||||
// attempt_drm_backend adds the multi drm backends itself
|
// attempt_drm_backend adds the multi drm backends itself
|
||||||
return attempt_drm_backend(display, &multi->backend,
|
return attempt_drm_backend(display, multi,
|
||||||
multi->session) != NULL;
|
*session_ptr) != NULL;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -281,12 +282,17 @@ static bool attempt_backend_by_name(struct wl_display *display,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return wlr_multi_backend_add(&multi->backend, backend);
|
return wlr_multi_backend_add(multi, backend);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct wlr_backend *wlr_backend_autocreate(struct wl_display *display) {
|
struct wlr_backend *wlr_backend_autocreate(struct wl_display *display,
|
||||||
|
struct wlr_session **session_ptr) {
|
||||||
|
if (session_ptr != NULL) {
|
||||||
|
*session_ptr = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct wlr_session *session = NULL;
|
||||||
struct wlr_backend *backend = wlr_multi_backend_create(display);
|
struct wlr_backend *backend = wlr_multi_backend_create(display);
|
||||||
struct wlr_multi_backend *multi = (struct wlr_multi_backend *)backend;
|
|
||||||
if (!backend) {
|
if (!backend) {
|
||||||
wlr_log(WLR_ERROR, "could not allocate multibackend");
|
wlr_log(WLR_ERROR, "could not allocate multibackend");
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -300,26 +306,23 @@ struct wlr_backend *wlr_backend_autocreate(struct wl_display *display) {
|
|||||||
names = strdup(names);
|
names = strdup(names);
|
||||||
if (names == NULL) {
|
if (names == NULL) {
|
||||||
wlr_log(WLR_ERROR, "allocation failed");
|
wlr_log(WLR_ERROR, "allocation failed");
|
||||||
wlr_backend_destroy(backend);
|
goto error;
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
char *saveptr;
|
char *saveptr;
|
||||||
char *name = strtok_r(names, ",", &saveptr);
|
char *name = strtok_r(names, ",", &saveptr);
|
||||||
while (name != NULL) {
|
while (name != NULL) {
|
||||||
if (!attempt_backend_by_name(display, multi, name)) {
|
if (!attempt_backend_by_name(display, backend, name, &session)) {
|
||||||
wlr_log(WLR_ERROR, "failed to add backend '%s'", name);
|
wlr_log(WLR_ERROR, "failed to add backend '%s'", name);
|
||||||
wlr_session_destroy(multi->session);
|
|
||||||
wlr_backend_destroy(backend);
|
|
||||||
free(names);
|
free(names);
|
||||||
return NULL;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
name = strtok_r(NULL, ",", &saveptr);
|
name = strtok_r(NULL, ",", &saveptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(names);
|
free(names);
|
||||||
return backend;
|
goto success;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (getenv("WAYLAND_DISPLAY") || getenv("WAYLAND_SOCKET")) {
|
if (getenv("WAYLAND_DISPLAY") || getenv("WAYLAND_SOCKET")) {
|
||||||
@ -329,7 +332,7 @@ struct wlr_backend *wlr_backend_autocreate(struct wl_display *display) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
wlr_multi_backend_add(backend, wl_backend);
|
wlr_multi_backend_add(backend, wl_backend);
|
||||||
return backend;
|
goto success;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if WLR_HAS_X11_BACKEND
|
#if WLR_HAS_X11_BACKEND
|
||||||
@ -342,26 +345,23 @@ struct wlr_backend *wlr_backend_autocreate(struct wl_display *display) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
wlr_multi_backend_add(backend, x11_backend);
|
wlr_multi_backend_add(backend, x11_backend);
|
||||||
return backend;
|
goto success;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Attempt DRM+libinput
|
// Attempt DRM+libinput
|
||||||
multi->session = session_create_and_wait(display);
|
session = session_create_and_wait(display);
|
||||||
if (!multi->session) {
|
if (!session) {
|
||||||
wlr_log(WLR_ERROR, "Failed to start a DRM session");
|
wlr_log(WLR_ERROR, "Failed to start a DRM session");
|
||||||
wlr_backend_destroy(backend);
|
goto error;
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if WLR_HAS_LIBINPUT_BACKEND
|
#if WLR_HAS_LIBINPUT_BACKEND
|
||||||
struct wlr_backend *libinput = wlr_libinput_backend_create(display,
|
struct wlr_backend *libinput =
|
||||||
multi->session);
|
wlr_libinput_backend_create(display, session);
|
||||||
if (!libinput) {
|
if (!libinput) {
|
||||||
wlr_log(WLR_ERROR, "Failed to start libinput backend");
|
wlr_log(WLR_ERROR, "Failed to start libinput backend");
|
||||||
wlr_session_destroy(multi->session);
|
goto error;
|
||||||
wlr_backend_destroy(backend);
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
wlr_multi_backend_add(backend, libinput);
|
wlr_multi_backend_add(backend, libinput);
|
||||||
#else
|
#else
|
||||||
@ -372,28 +372,31 @@ struct wlr_backend *wlr_backend_autocreate(struct wl_display *display) {
|
|||||||
wlr_log(WLR_ERROR, "libinput support is not compiled in, "
|
wlr_log(WLR_ERROR, "libinput support is not compiled in, "
|
||||||
"refusing to start");
|
"refusing to start");
|
||||||
wlr_log(WLR_ERROR, "Set WLR_LIBINPUT_NO_DEVICES=1 to suppress this check");
|
wlr_log(WLR_ERROR, "Set WLR_LIBINPUT_NO_DEVICES=1 to suppress this check");
|
||||||
wlr_session_destroy(multi->session);
|
goto error;
|
||||||
wlr_backend_destroy(backend);
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if WLR_HAS_DRM_BACKEND
|
#if WLR_HAS_DRM_BACKEND
|
||||||
struct wlr_backend *primary_drm =
|
struct wlr_backend *primary_drm =
|
||||||
attempt_drm_backend(display, backend, multi->session);
|
attempt_drm_backend(display, backend, session);
|
||||||
if (!primary_drm) {
|
if (!primary_drm) {
|
||||||
wlr_log(WLR_ERROR, "Failed to open any DRM device");
|
wlr_log(WLR_ERROR, "Failed to open any DRM device");
|
||||||
wlr_session_destroy(multi->session);
|
goto error;
|
||||||
wlr_backend_destroy(backend);
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
drm_backend_monitor_create(backend, primary_drm, multi->session);
|
drm_backend_monitor_create(backend, primary_drm, session);
|
||||||
|
|
||||||
return backend;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
success:
|
||||||
|
struct wlr_multi_backend *multi = wl_container_of(backend, multi, backend);
|
||||||
|
multi->session = session;
|
||||||
|
if (session_ptr != NULL) {
|
||||||
|
*session_ptr = session;
|
||||||
|
}
|
||||||
|
return backend;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
wlr_backend_destroy(backend);
|
wlr_backend_destroy(backend);
|
||||||
|
wlr_session_destroy(session);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -205,7 +205,7 @@ int main(int argc, char *argv[]) {
|
|||||||
|
|
||||||
struct fullscreen_server server = {0};
|
struct fullscreen_server server = {0};
|
||||||
server.wl_display = wl_display_create();
|
server.wl_display = wl_display_create();
|
||||||
server.backend = wlr_backend_autocreate(server.wl_display);
|
server.backend = wlr_backend_autocreate(server.wl_display, NULL);
|
||||||
server.renderer = wlr_renderer_autocreate(server.backend);
|
server.renderer = wlr_renderer_autocreate(server.backend);
|
||||||
wlr_renderer_init_wl_display(server.renderer, server.wl_display);
|
wlr_renderer_init_wl_display(server.renderer, server.wl_display);
|
||||||
server.allocator = wlr_allocator_autocreate(server.backend,
|
server.allocator = wlr_allocator_autocreate(server.backend,
|
||||||
|
@ -272,7 +272,7 @@ int main(int argc, char *argv[]) {
|
|||||||
.clear_color = { 0.25f, 0.25f, 0.25f, 1 },
|
.clear_color = { 0.25f, 0.25f, 0.25f, 1 },
|
||||||
.display = display,
|
.display = display,
|
||||||
};
|
};
|
||||||
struct wlr_backend *wlr = wlr_backend_autocreate(display);
|
struct wlr_backend *wlr = wlr_backend_autocreate(display, NULL);
|
||||||
if (!wlr) {
|
if (!wlr) {
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
@ -268,7 +268,7 @@ int main(int argc, char *argv[]) {
|
|||||||
state.layout = wlr_output_layout_create();
|
state.layout = wlr_output_layout_create();
|
||||||
clock_gettime(CLOCK_MONOTONIC, &state.ts_last);
|
clock_gettime(CLOCK_MONOTONIC, &state.ts_last);
|
||||||
|
|
||||||
struct wlr_backend *wlr = wlr_backend_autocreate(display);
|
struct wlr_backend *wlr = wlr_backend_autocreate(display, NULL);
|
||||||
if (!wlr) {
|
if (!wlr) {
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
@ -333,7 +333,7 @@ int main(int argc, char *argv[]) {
|
|||||||
.display = display
|
.display = display
|
||||||
};
|
};
|
||||||
|
|
||||||
struct wlr_backend *wlr = wlr_backend_autocreate(display);
|
struct wlr_backend *wlr = wlr_backend_autocreate(display, NULL);
|
||||||
if (!wlr) {
|
if (!wlr) {
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
@ -189,7 +189,7 @@ int main(int argc, char *argv[]) {
|
|||||||
};
|
};
|
||||||
wl_list_init(&state.outputs);
|
wl_list_init(&state.outputs);
|
||||||
|
|
||||||
struct wlr_backend *wlr = wlr_backend_autocreate(display);
|
struct wlr_backend *wlr = wlr_backend_autocreate(display, NULL);
|
||||||
if (!wlr) {
|
if (!wlr) {
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
@ -239,7 +239,7 @@ int main(int argc, char *argv[]) {
|
|||||||
};
|
};
|
||||||
wl_list_init(&state.outputs);
|
wl_list_init(&state.outputs);
|
||||||
|
|
||||||
struct wlr_backend *wlr = wlr_backend_autocreate(display);
|
struct wlr_backend *wlr = wlr_backend_autocreate(display, NULL);
|
||||||
if (!wlr) {
|
if (!wlr) {
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
@ -157,7 +157,7 @@ int main(int argc, char *argv[]) {
|
|||||||
struct server server = {0};
|
struct server server = {0};
|
||||||
server.surface_offset = 0;
|
server.surface_offset = 0;
|
||||||
server.display = wl_display_create();
|
server.display = wl_display_create();
|
||||||
server.backend = wlr_backend_autocreate(server.display);
|
server.backend = wlr_backend_autocreate(server.display, NULL);
|
||||||
server.scene = wlr_scene_create();
|
server.scene = wlr_scene_create();
|
||||||
|
|
||||||
server.renderer = wlr_renderer_autocreate(server.backend);
|
server.renderer = wlr_renderer_autocreate(server.backend);
|
||||||
|
@ -172,7 +172,7 @@ int main(void) {
|
|||||||
.last_frame = { 0 },
|
.last_frame = { 0 },
|
||||||
.display = display
|
.display = display
|
||||||
};
|
};
|
||||||
struct wlr_backend *backend = wlr_backend_autocreate(display);
|
struct wlr_backend *backend = wlr_backend_autocreate(display, NULL);
|
||||||
if (!backend) {
|
if (!backend) {
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
@ -355,7 +355,7 @@ int main(int argc, char *argv[]) {
|
|||||||
};
|
};
|
||||||
wl_list_init(&state.tablet_pads);
|
wl_list_init(&state.tablet_pads);
|
||||||
wl_list_init(&state.tablet_tools);
|
wl_list_init(&state.tablet_tools);
|
||||||
struct wlr_backend *wlr = wlr_backend_autocreate(display);
|
struct wlr_backend *wlr = wlr_backend_autocreate(display, NULL);
|
||||||
if (!wlr) {
|
if (!wlr) {
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
@ -248,7 +248,7 @@ int main(int argc, char *argv[]) {
|
|||||||
wl_list_init(&state.touch_points);
|
wl_list_init(&state.touch_points);
|
||||||
wl_list_init(&state.touch);
|
wl_list_init(&state.touch);
|
||||||
|
|
||||||
struct wlr_backend *wlr = wlr_backend_autocreate(display);
|
struct wlr_backend *wlr = wlr_backend_autocreate(display, NULL);
|
||||||
if (!wlr) {
|
if (!wlr) {
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
@ -34,8 +34,12 @@ struct wlr_backend {
|
|||||||
* Automatically initializes the most suitable backend given the environment.
|
* Automatically initializes the most suitable backend given the environment.
|
||||||
* Will always return a multi-backend. The backend is created but not started.
|
* Will always return a multi-backend. The backend is created but not started.
|
||||||
* Returns NULL on failure.
|
* Returns NULL on failure.
|
||||||
|
*
|
||||||
|
* If session_ptr is not NULL, it's populated with the session which has been
|
||||||
|
* created with the backend, if any.
|
||||||
*/
|
*/
|
||||||
struct wlr_backend *wlr_backend_autocreate(struct wl_display *display);
|
struct wlr_backend *wlr_backend_autocreate(struct wl_display *display,
|
||||||
|
struct wlr_session **session_ptr);
|
||||||
/**
|
/**
|
||||||
* Start the backend. This may signal new_input or new_output immediately, but
|
* Start the backend. This may signal new_input or new_output immediately, but
|
||||||
* may also wait until the display's event loop begins. Returns false on
|
* may also wait until the display's event loop begins. Returns false on
|
||||||
|
@ -828,7 +828,7 @@ int main(int argc, char *argv[]) {
|
|||||||
* output hardware. The autocreate option will choose the most suitable
|
* output hardware. The autocreate option will choose the most suitable
|
||||||
* backend based on the current environment, such as opening an X11 window
|
* backend based on the current environment, such as opening an X11 window
|
||||||
* if an X11 server is running. */
|
* if an X11 server is running. */
|
||||||
server.backend = wlr_backend_autocreate(server.wl_display);
|
server.backend = wlr_backend_autocreate(server.wl_display, NULL);
|
||||||
if (server.backend == NULL) {
|
if (server.backend == NULL) {
|
||||||
wlr_log(WLR_ERROR, "failed to create wlr_backend");
|
wlr_log(WLR_ERROR, "failed to create wlr_backend");
|
||||||
return 1;
|
return 1;
|
||||||
|
Loading…
Reference in New Issue
Block a user