mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-11-22 04:45:58 +01:00
backend: take wl_event_loop instead of wl_display in wlr_backend_autocreate()
This commit is contained in:
parent
f27808b8d9
commit
d1b39b5843
13 changed files with 28 additions and 35 deletions
|
@ -71,10 +71,9 @@ void wlr_backend_destroy(struct wlr_backend *backend) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct wlr_session *session_create_and_wait(struct wl_display *disp) {
|
static struct wlr_session *session_create_and_wait(struct wl_event_loop *loop) {
|
||||||
#if WLR_HAS_SESSION
|
#if WLR_HAS_SESSION
|
||||||
struct wl_event_loop *event_loop = wl_display_get_event_loop(disp);
|
struct wlr_session *session = wlr_session_create(loop);
|
||||||
struct wlr_session *session = wlr_session_create(event_loop);
|
|
||||||
|
|
||||||
if (!session) {
|
if (!session) {
|
||||||
wlr_log(WLR_ERROR, "Failed to start a session");
|
wlr_log(WLR_ERROR, "Failed to start a session");
|
||||||
|
@ -88,7 +87,7 @@ static struct wlr_session *session_create_and_wait(struct wl_display *disp) {
|
||||||
int64_t timeout = WAIT_SESSION_TIMEOUT;
|
int64_t timeout = WAIT_SESSION_TIMEOUT;
|
||||||
|
|
||||||
while (!session->active) {
|
while (!session->active) {
|
||||||
int ret = wl_event_loop_dispatch(event_loop, (int)timeout);
|
int ret = wl_event_loop_dispatch(loop, (int)timeout);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
wlr_log_errno(WLR_ERROR, "Failed to wait for session active: "
|
wlr_log_errno(WLR_ERROR, "Failed to wait for session active: "
|
||||||
"wl_event_loop_dispatch failed");
|
"wl_event_loop_dispatch failed");
|
||||||
|
@ -193,8 +192,7 @@ static struct wlr_auto_backend_monitor *auto_backend_monitor_create(
|
||||||
return monitor;
|
return monitor;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct wlr_backend *attempt_wl_backend(struct wl_display *display) {
|
static struct wlr_backend *attempt_wl_backend(struct wl_event_loop *loop) {
|
||||||
struct wl_event_loop *loop = wl_display_get_event_loop(display);
|
|
||||||
struct wlr_backend *backend = wlr_wl_backend_create(loop, NULL);
|
struct wlr_backend *backend = wlr_wl_backend_create(loop, NULL);
|
||||||
if (backend == NULL) {
|
if (backend == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -208,10 +206,9 @@ static struct wlr_backend *attempt_wl_backend(struct wl_display *display) {
|
||||||
return backend;
|
return backend;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct wlr_backend *attempt_x11_backend(struct wl_display *display,
|
static struct wlr_backend *attempt_x11_backend(struct wl_event_loop *loop,
|
||||||
const char *x11_display) {
|
const char *x11_display) {
|
||||||
#if WLR_HAS_X11_BACKEND
|
#if WLR_HAS_X11_BACKEND
|
||||||
struct wl_event_loop *loop = wl_display_get_event_loop(display);
|
|
||||||
struct wlr_backend *backend = wlr_x11_backend_create(loop, x11_display);
|
struct wlr_backend *backend = wlr_x11_backend_create(loop, x11_display);
|
||||||
if (backend == NULL) {
|
if (backend == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -229,9 +226,7 @@ static struct wlr_backend *attempt_x11_backend(struct wl_display *display,
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct wlr_backend *attempt_headless_backend(
|
static struct wlr_backend *attempt_headless_backend(struct wl_event_loop *loop) {
|
||||||
struct wl_display *display) {
|
|
||||||
struct wl_event_loop *loop = wl_display_get_event_loop(display);
|
|
||||||
struct wlr_backend *backend = wlr_headless_backend_create(loop);
|
struct wlr_backend *backend = wlr_headless_backend_create(loop);
|
||||||
if (backend == NULL) {
|
if (backend == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -300,20 +295,20 @@ static struct wlr_backend *attempt_libinput_backend(struct wlr_session *session)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool attempt_backend_by_name(struct wl_display *display,
|
static bool attempt_backend_by_name(struct wl_event_loop *loop,
|
||||||
struct wlr_backend *multi, char *name,
|
struct wlr_backend *multi, char *name,
|
||||||
struct wlr_session **session_ptr) {
|
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(loop);
|
||||||
} else if (strcmp(name, "x11") == 0) {
|
} else if (strcmp(name, "x11") == 0) {
|
||||||
backend = attempt_x11_backend(display, NULL);
|
backend = attempt_x11_backend(loop, NULL);
|
||||||
} else if (strcmp(name, "headless") == 0) {
|
} else if (strcmp(name, "headless") == 0) {
|
||||||
backend = attempt_headless_backend(display);
|
backend = attempt_headless_backend(loop);
|
||||||
} 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 (*session_ptr == NULL) {
|
if (*session_ptr == NULL) {
|
||||||
*session_ptr = session_create_and_wait(display);
|
*session_ptr = session_create_and_wait(loop);
|
||||||
if (*session_ptr == 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;
|
||||||
|
@ -337,14 +332,13 @@ static bool attempt_backend_by_name(struct wl_display *display,
|
||||||
return wlr_multi_backend_add(multi, 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_event_loop *loop,
|
||||||
struct wlr_session **session_ptr) {
|
struct wlr_session **session_ptr) {
|
||||||
if (session_ptr != NULL) {
|
if (session_ptr != NULL) {
|
||||||
*session_ptr = NULL;
|
*session_ptr = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct wlr_session *session = NULL;
|
struct wlr_session *session = NULL;
|
||||||
struct wl_event_loop *loop = wl_display_get_event_loop(display);
|
|
||||||
struct wlr_backend *multi = wlr_multi_backend_create(loop);
|
struct wlr_backend *multi = wlr_multi_backend_create(loop);
|
||||||
if (!multi) {
|
if (!multi) {
|
||||||
wlr_log(WLR_ERROR, "could not allocate multibackend");
|
wlr_log(WLR_ERROR, "could not allocate multibackend");
|
||||||
|
@ -365,7 +359,7 @@ struct wlr_backend *wlr_backend_autocreate(struct wl_display *display,
|
||||||
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, &session)) {
|
if (!attempt_backend_by_name(loop, multi, name, &session)) {
|
||||||
wlr_log(WLR_ERROR, "failed to add backend '%s'", name);
|
wlr_log(WLR_ERROR, "failed to add backend '%s'", name);
|
||||||
free(names);
|
free(names);
|
||||||
goto error;
|
goto error;
|
||||||
|
@ -379,7 +373,7 @@ struct wlr_backend *wlr_backend_autocreate(struct wl_display *display,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (getenv("WAYLAND_DISPLAY") || getenv("WAYLAND_SOCKET")) {
|
if (getenv("WAYLAND_DISPLAY") || getenv("WAYLAND_SOCKET")) {
|
||||||
struct wlr_backend *wl_backend = attempt_wl_backend(display);
|
struct wlr_backend *wl_backend = attempt_wl_backend(loop);
|
||||||
if (!wl_backend) {
|
if (!wl_backend) {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
@ -394,8 +388,7 @@ struct wlr_backend *wlr_backend_autocreate(struct wl_display *display,
|
||||||
|
|
||||||
const char *x11_display = getenv("DISPLAY");
|
const char *x11_display = getenv("DISPLAY");
|
||||||
if (x11_display) {
|
if (x11_display) {
|
||||||
struct wlr_backend *x11_backend =
|
struct wlr_backend *x11_backend = attempt_x11_backend(loop, x11_display);
|
||||||
attempt_x11_backend(display, x11_display);
|
|
||||||
if (!x11_backend) {
|
if (!x11_backend) {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
@ -409,7 +402,7 @@ struct wlr_backend *wlr_backend_autocreate(struct wl_display *display,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Attempt DRM+libinput
|
// Attempt DRM+libinput
|
||||||
session = session_create_and_wait(display);
|
session = session_create_and_wait(loop);
|
||||||
if (!session) {
|
if (!session) {
|
||||||
wlr_log(WLR_ERROR, "Failed to start a DRM session");
|
wlr_log(WLR_ERROR, "Failed to start a DRM session");
|
||||||
goto error;
|
goto error;
|
||||||
|
|
|
@ -125,7 +125,7 @@ int main(void) {
|
||||||
|
|
||||||
struct server server = {0};
|
struct server server = {0};
|
||||||
server.display = wl_display_create();
|
server.display = wl_display_create();
|
||||||
server.backend = wlr_backend_autocreate(server.display, NULL);
|
server.backend = wlr_backend_autocreate(wl_display_get_event_loop(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);
|
||||||
|
|
|
@ -212,7 +212,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, NULL);
|
server.backend = wlr_backend_autocreate(wl_display_get_event_loop(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,
|
||||||
|
|
|
@ -286,7 +286,7 @@ int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
struct server server = {0};
|
struct server server = {0};
|
||||||
server.wl_display = wl_display_create();
|
server.wl_display = wl_display_create();
|
||||||
server.backend = wlr_backend_autocreate(server.wl_display, NULL);
|
server.backend = wlr_backend_autocreate(wl_display_get_event_loop(server.wl_display), NULL);
|
||||||
|
|
||||||
server.renderer = wlr_renderer_autocreate(server.backend);
|
server.renderer = wlr_renderer_autocreate(server.backend);
|
||||||
wlr_renderer_init_wl_shm(server.renderer, server.wl_display);
|
wlr_renderer_init_wl_shm(server.renderer, server.wl_display);
|
||||||
|
|
|
@ -275,7 +275,7 @@ int main(int argc, char *argv[]) {
|
||||||
state.layout = wlr_output_layout_create(display);
|
state.layout = wlr_output_layout_create(display);
|
||||||
clock_gettime(CLOCK_MONOTONIC, &state.ts_last);
|
clock_gettime(CLOCK_MONOTONIC, &state.ts_last);
|
||||||
|
|
||||||
struct wlr_backend *wlr = wlr_backend_autocreate(display, NULL);
|
struct wlr_backend *wlr = wlr_backend_autocreate(wl_display_get_event_loop(display), NULL);
|
||||||
if (!wlr) {
|
if (!wlr) {
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -341,7 +341,7 @@ int main(int argc, char *argv[]) {
|
||||||
.display = display
|
.display = display
|
||||||
};
|
};
|
||||||
|
|
||||||
struct wlr_backend *wlr = wlr_backend_autocreate(display, NULL);
|
struct wlr_backend *wlr = wlr_backend_autocreate(wl_display_get_event_loop(display), NULL);
|
||||||
if (!wlr) {
|
if (!wlr) {
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -250,7 +250,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, NULL);
|
struct wlr_backend *wlr = wlr_backend_autocreate(wl_display_get_event_loop(display), NULL);
|
||||||
if (!wlr) {
|
if (!wlr) {
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -160,7 +160,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, NULL);
|
server.backend = wlr_backend_autocreate(wl_display_get_event_loop(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);
|
||||||
|
|
|
@ -181,7 +181,7 @@ int main(void) {
|
||||||
.last_frame = { 0 },
|
.last_frame = { 0 },
|
||||||
.display = display
|
.display = display
|
||||||
};
|
};
|
||||||
struct wlr_backend *backend = wlr_backend_autocreate(display, NULL);
|
struct wlr_backend *backend = wlr_backend_autocreate(wl_display_get_event_loop(display), NULL);
|
||||||
if (!backend) {
|
if (!backend) {
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -385,7 +385,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, NULL);
|
struct wlr_backend *wlr = wlr_backend_autocreate(wl_display_get_event_loop(display), NULL);
|
||||||
if (!wlr) {
|
if (!wlr) {
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -274,7 +274,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, NULL);
|
struct wlr_backend *wlr = wlr_backend_autocreate(wl_display_get_event_loop(display), NULL);
|
||||||
if (!wlr) {
|
if (!wlr) {
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,7 @@ struct wlr_backend {
|
||||||
* The multi-backend will be destroyed if one of the primary underlying
|
* The multi-backend will be destroyed if one of the primary underlying
|
||||||
* backends is destroyed (e.g. if the primary DRM device is unplugged).
|
* backends is destroyed (e.g. if the primary DRM device is unplugged).
|
||||||
*/
|
*/
|
||||||
struct wlr_backend *wlr_backend_autocreate(struct wl_display *display,
|
struct wlr_backend *wlr_backend_autocreate(struct wl_event_loop *loop,
|
||||||
struct wlr_session **session_ptr);
|
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
|
||||||
|
|
|
@ -851,7 +851,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, NULL);
|
server.backend = wlr_backend_autocreate(wl_display_get_event_loop(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 a new issue