mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-11-22 04:45:58 +01: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
13 changed files with 57 additions and 50 deletions
|
@ -245,7 +245,8 @@ static struct wlr_backend *attempt_drm_backend(struct wl_display *display,
|
|||
#endif
|
||||
|
||||
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;
|
||||
if (strcmp(name, "wayland") == 0) {
|
||||
backend = attempt_wl_backend(display);
|
||||
|
@ -257,9 +258,9 @@ static bool attempt_backend_by_name(struct wl_display *display,
|
|||
backend = attempt_headless_backend(display);
|
||||
} else if (strcmp(name, "drm") == 0 || strcmp(name, "libinput") == 0) {
|
||||
// DRM and libinput need a session
|
||||
if (multi->session == NULL) {
|
||||
multi->session = session_create_and_wait(display);
|
||||
if (multi->session == NULL) {
|
||||
if (*session_ptr == NULL) {
|
||||
*session_ptr = session_create_and_wait(display);
|
||||
if (*session_ptr == NULL) {
|
||||
wlr_log(WLR_ERROR, "failed to start a session");
|
||||
return false;
|
||||
}
|
||||
|
@ -267,13 +268,13 @@ static bool attempt_backend_by_name(struct wl_display *display,
|
|||
|
||||
if (strcmp(name, "libinput") == 0) {
|
||||
#if WLR_HAS_LIBINPUT_BACKEND
|
||||
backend = wlr_libinput_backend_create(display, multi->session);
|
||||
backend = wlr_libinput_backend_create(display, *session_ptr);
|
||||
#endif
|
||||
} else {
|
||||
#if WLR_HAS_DRM_BACKEND
|
||||
// attempt_drm_backend adds the multi drm backends itself
|
||||
return attempt_drm_backend(display, &multi->backend,
|
||||
multi->session) != NULL;
|
||||
return attempt_drm_backend(display, multi,
|
||||
*session_ptr) != NULL;
|
||||
#endif
|
||||
}
|
||||
} else {
|
||||
|
@ -281,12 +282,17 @@ static bool attempt_backend_by_name(struct wl_display *display,
|
|||
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_multi_backend *multi = (struct wlr_multi_backend *)backend;
|
||||
if (!backend) {
|
||||
wlr_log(WLR_ERROR, "could not allocate multibackend");
|
||||
return NULL;
|
||||
|
@ -300,26 +306,23 @@ struct wlr_backend *wlr_backend_autocreate(struct wl_display *display) {
|
|||
names = strdup(names);
|
||||
if (names == NULL) {
|
||||
wlr_log(WLR_ERROR, "allocation failed");
|
||||
wlr_backend_destroy(backend);
|
||||
return NULL;
|
||||
goto error;
|
||||
}
|
||||
|
||||
char *saveptr;
|
||||
char *name = strtok_r(names, ",", &saveptr);
|
||||
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_session_destroy(multi->session);
|
||||
wlr_backend_destroy(backend);
|
||||
free(names);
|
||||
return NULL;
|
||||
goto error;
|
||||
}
|
||||
|
||||
name = strtok_r(NULL, ",", &saveptr);
|
||||
}
|
||||
|
||||
free(names);
|
||||
return backend;
|
||||
goto success;
|
||||
}
|
||||
|
||||
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);
|
||||
return backend;
|
||||
goto success;
|
||||
}
|
||||
|
||||
#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);
|
||||
return backend;
|
||||
goto success;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Attempt DRM+libinput
|
||||
multi->session = session_create_and_wait(display);
|
||||
if (!multi->session) {
|
||||
session = session_create_and_wait(display);
|
||||
if (!session) {
|
||||
wlr_log(WLR_ERROR, "Failed to start a DRM session");
|
||||
wlr_backend_destroy(backend);
|
||||
return NULL;
|
||||
goto error;
|
||||
}
|
||||
|
||||
#if WLR_HAS_LIBINPUT_BACKEND
|
||||
struct wlr_backend *libinput = wlr_libinput_backend_create(display,
|
||||
multi->session);
|
||||
struct wlr_backend *libinput =
|
||||
wlr_libinput_backend_create(display, session);
|
||||
if (!libinput) {
|
||||
wlr_log(WLR_ERROR, "Failed to start libinput backend");
|
||||
wlr_session_destroy(multi->session);
|
||||
wlr_backend_destroy(backend);
|
||||
return NULL;
|
||||
goto error;
|
||||
}
|
||||
wlr_multi_backend_add(backend, libinput);
|
||||
#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, "
|
||||
"refusing to start");
|
||||
wlr_log(WLR_ERROR, "Set WLR_LIBINPUT_NO_DEVICES=1 to suppress this check");
|
||||
wlr_session_destroy(multi->session);
|
||||
wlr_backend_destroy(backend);
|
||||
return NULL;
|
||||
goto error;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if WLR_HAS_DRM_BACKEND
|
||||
struct wlr_backend *primary_drm =
|
||||
attempt_drm_backend(display, backend, multi->session);
|
||||
attempt_drm_backend(display, backend, session);
|
||||
if (!primary_drm) {
|
||||
wlr_log(WLR_ERROR, "Failed to open any DRM device");
|
||||
wlr_session_destroy(multi->session);
|
||||
wlr_backend_destroy(backend);
|
||||
return NULL;
|
||||
goto error;
|
||||
}
|
||||
|
||||
drm_backend_monitor_create(backend, primary_drm, multi->session);
|
||||
|
||||
return backend;
|
||||
drm_backend_monitor_create(backend, primary_drm, session);
|
||||
#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:
|
||||
wlr_backend_destroy(backend);
|
||||
wlr_session_destroy(session);
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -205,7 +205,7 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
struct fullscreen_server server = {0};
|
||||
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);
|
||||
wlr_renderer_init_wl_display(server.renderer, server.wl_display);
|
||||
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 },
|
||||
.display = display,
|
||||
};
|
||||
struct wlr_backend *wlr = wlr_backend_autocreate(display);
|
||||
struct wlr_backend *wlr = wlr_backend_autocreate(display, NULL);
|
||||
if (!wlr) {
|
||||
exit(1);
|
||||
}
|
||||
|
|
|
@ -268,7 +268,7 @@ int main(int argc, char *argv[]) {
|
|||
state.layout = wlr_output_layout_create();
|
||||
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) {
|
||||
exit(1);
|
||||
}
|
||||
|
|
|
@ -333,7 +333,7 @@ int main(int argc, char *argv[]) {
|
|||
.display = display
|
||||
};
|
||||
|
||||
struct wlr_backend *wlr = wlr_backend_autocreate(display);
|
||||
struct wlr_backend *wlr = wlr_backend_autocreate(display, NULL);
|
||||
if (!wlr) {
|
||||
exit(1);
|
||||
}
|
||||
|
|
|
@ -189,7 +189,7 @@ int main(int argc, char *argv[]) {
|
|||
};
|
||||
wl_list_init(&state.outputs);
|
||||
|
||||
struct wlr_backend *wlr = wlr_backend_autocreate(display);
|
||||
struct wlr_backend *wlr = wlr_backend_autocreate(display, NULL);
|
||||
if (!wlr) {
|
||||
exit(1);
|
||||
}
|
||||
|
|
|
@ -239,7 +239,7 @@ int main(int argc, char *argv[]) {
|
|||
};
|
||||
wl_list_init(&state.outputs);
|
||||
|
||||
struct wlr_backend *wlr = wlr_backend_autocreate(display);
|
||||
struct wlr_backend *wlr = wlr_backend_autocreate(display, NULL);
|
||||
if (!wlr) {
|
||||
exit(1);
|
||||
}
|
||||
|
|
|
@ -157,7 +157,7 @@ int main(int argc, char *argv[]) {
|
|||
struct server server = {0};
|
||||
server.surface_offset = 0;
|
||||
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.renderer = wlr_renderer_autocreate(server.backend);
|
||||
|
|
|
@ -172,7 +172,7 @@ int main(void) {
|
|||
.last_frame = { 0 },
|
||||
.display = display
|
||||
};
|
||||
struct wlr_backend *backend = wlr_backend_autocreate(display);
|
||||
struct wlr_backend *backend = wlr_backend_autocreate(display, NULL);
|
||||
if (!backend) {
|
||||
exit(1);
|
||||
}
|
||||
|
|
|
@ -355,7 +355,7 @@ int main(int argc, char *argv[]) {
|
|||
};
|
||||
wl_list_init(&state.tablet_pads);
|
||||
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) {
|
||||
exit(1);
|
||||
}
|
||||
|
|
|
@ -248,7 +248,7 @@ int main(int argc, char *argv[]) {
|
|||
wl_list_init(&state.touch_points);
|
||||
wl_list_init(&state.touch);
|
||||
|
||||
struct wlr_backend *wlr = wlr_backend_autocreate(display);
|
||||
struct wlr_backend *wlr = wlr_backend_autocreate(display, NULL);
|
||||
if (!wlr) {
|
||||
exit(1);
|
||||
}
|
||||
|
|
|
@ -34,8 +34,12 @@ struct wlr_backend {
|
|||
* Automatically initializes the most suitable backend given the environment.
|
||||
* Will always return a multi-backend. The backend is created but not started.
|
||||
* 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
|
||||
* 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
|
||||
* backend based on the current environment, such as opening an X11 window
|
||||
* 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) {
|
||||
wlr_log(WLR_ERROR, "failed to create wlr_backend");
|
||||
return 1;
|
||||
|
|
Loading…
Reference in a new issue