diff options
36 files changed, 121 insertions, 70 deletions
diff --git a/backend/backend.c b/backend/backend.c index a391b272..4da3fe7a 100644 --- a/backend/backend.c +++ b/backend/backend.c @@ -4,7 +4,7 @@ #include <string.h> #include <errno.h> #include <libinput.h> -#include <wlr/session.h> +#include <wlr/backend/session.h> #include <wlr/backend/interface.h> #include <wlr/backend/drm.h> #include <wlr/backend/libinput.h> @@ -62,8 +62,7 @@ static struct wlr_backend *attempt_wl_backend(struct wl_display *display) { return backend; } -struct wlr_backend *wlr_backend_autocreate(struct wl_display *display, - struct wlr_session *session) { +struct wlr_backend *wlr_backend_autocreate(struct wl_display *display) { struct wlr_backend *backend; if (getenv("WAYLAND_DISPLAY") || getenv("_WAYLAND_DISPLAY")) { backend = attempt_wl_backend(display); @@ -71,43 +70,61 @@ struct wlr_backend *wlr_backend_autocreate(struct wl_display *display, return backend; } } + + if (getenv("DISPLAY")) { + wlr_log(L_ERROR, "X11 backend is not implemented"); // TODO + return NULL; + } + // Attempt DRM+libinput - struct wlr_udev *udev; - if (!(udev = wlr_udev_create(display))) { + + struct wlr_session *session = wlr_session_start(display); + if (!session) { + wlr_log(L_ERROR, "Failed to start a DRM session"); + return NULL; + } + + struct wlr_udev *udev = wlr_udev_create(display); + if (!udev) { wlr_log(L_ERROR, "Failed to start udev"); - goto error; + goto error_session; } + int gpu = wlr_udev_find_gpu(udev, session); if (gpu == -1) { wlr_log(L_ERROR, "Failed to open DRM device"); goto error_udev; } - backend = wlr_multi_backend_create(); + + backend = wlr_multi_backend_create(session, udev); if (!backend) { goto error_gpu; } - struct wlr_backend *libinput = - wlr_libinput_backend_create(display, session, udev); + + struct wlr_backend *libinput = wlr_libinput_backend_create(display, session, udev); if (!libinput) { goto error_multi; } - struct wlr_backend *drm = - wlr_drm_backend_create(display, session, udev, gpu); + + struct wlr_backend *drm = wlr_drm_backend_create(display, session, udev, gpu); if (!drm) { goto error_libinput; } + wlr_multi_backend_add(backend, libinput); wlr_multi_backend_add(backend, drm); return backend; + error_libinput: wlr_backend_destroy(libinput); error_multi: wlr_backend_destroy(backend); error_gpu: - close(gpu); + wlr_session_close_file(session, gpu); error_udev: wlr_udev_destroy(udev); -error: +error_session: + wlr_session_finish(session); return NULL; } diff --git a/backend/drm/backend.c b/backend/drm/backend.c index d52adba9..a2c71317 100644 --- a/backend/drm/backend.c +++ b/backend/drm/backend.c @@ -7,7 +7,7 @@ #include <wayland-server.h> #include <xf86drm.h> #include <sys/stat.h> -#include <wlr/session.h> +#include <wlr/backend/session.h> #include <wlr/backend/interface.h> #include <wlr/interfaces/wlr_output.h> #include <wlr/util/list.h> diff --git a/backend/libinput/backend.c b/backend/libinput/backend.c index a3523dc0..68f1752b 100644 --- a/backend/libinput/backend.c +++ b/backend/libinput/backend.c @@ -1,7 +1,7 @@ #include <stdlib.h> #include <assert.h> #include <libinput.h> -#include <wlr/session.h> +#include <wlr/backend/session.h> #include <wlr/backend/interface.h> #include <wlr/util/log.h> #include "backend/udev.h" diff --git a/backend/libinput/events.c b/backend/libinput/events.c index 6cd33e3d..9fe81782 100644 --- a/backend/libinput/events.c +++ b/backend/libinput/events.c @@ -1,7 +1,7 @@ #include <stdlib.h> #include <assert.h> #include <libinput.h> -#include <wlr/session.h> +#include <wlr/backend/session.h> #include <wlr/interfaces/wlr_input_device.h> #include <wlr/util/list.h> #include <wlr/util/log.h> diff --git a/backend/libinput/keyboard.c b/backend/libinput/keyboard.c index f19d7120..957cc3f2 100644 --- a/backend/libinput/keyboard.c +++ b/backend/libinput/keyboard.c @@ -1,7 +1,7 @@ #include <stdlib.h> #include <assert.h> #include <libinput.h> -#include <wlr/session.h> +#include <wlr/backend/session.h> #include <wlr/types/wlr_input_device.h> #include <wlr/interfaces/wlr_keyboard.h> #include <wlr/util/log.h> diff --git a/backend/libinput/pointer.c b/backend/libinput/pointer.c index 57c417c8..59e219d8 100644 --- a/backend/libinput/pointer.c +++ b/backend/libinput/pointer.c @@ -1,7 +1,7 @@ #include <stdlib.h> #include <assert.h> #include <libinput.h> -#include <wlr/session.h> +#include <wlr/backend/session.h> #include <wlr/types/wlr_input_device.h> #include <wlr/interfaces/wlr_pointer.h> #include <wlr/util/log.h> diff --git a/backend/libinput/tablet_pad.c b/backend/libinput/tablet_pad.c index 5517fa63..9bf45ba6 100644 --- a/backend/libinput/tablet_pad.c +++ b/backend/libinput/tablet_pad.c @@ -1,7 +1,7 @@ #include <stdlib.h> #include <assert.h> #include <libinput.h> -#include <wlr/session.h> +#include <wlr/backend/session.h> #include <wlr/types/wlr_input_device.h> #include <wlr/interfaces/wlr_tablet_pad.h> #include <wlr/util/log.h> diff --git a/backend/libinput/tablet_tool.c b/backend/libinput/tablet_tool.c index 95bdd3fd..9bbb0e34 100644 --- a/backend/libinput/tablet_tool.c +++ b/backend/libinput/tablet_tool.c @@ -1,7 +1,7 @@ #include <stdlib.h> #include <assert.h> #include <libinput.h> -#include <wlr/session.h> +#include <wlr/backend/session.h> #include <wlr/types/wlr_input_device.h> #include <wlr/interfaces/wlr_tablet_tool.h> #include <wlr/util/log.h> diff --git a/backend/libinput/touch.c b/backend/libinput/touch.c index c002b6a0..e0e866b0 100644 --- a/backend/libinput/touch.c +++ b/backend/libinput/touch.c @@ -1,7 +1,7 @@ #include <stdlib.h> #include <assert.h> #include <libinput.h> -#include <wlr/session.h> +#include <wlr/backend/session.h> #include <wlr/types/wlr_input_device.h> #include <wlr/interfaces/wlr_touch.h> #include <wlr/util/log.h> diff --git a/backend/meson.build b/backend/meson.build index 02b79e65..dc5a3d66 100644 --- a/backend/meson.build +++ b/backend/meson.build @@ -2,6 +2,9 @@ wlr_files += files( 'backend.c', 'egl.c', 'udev.c', + 'session/direct-ipc.c', + 'session/direct.c', + 'session/session.c', 'drm/backend.c', 'drm/drm.c', 'libinput/backend.c', @@ -17,3 +20,7 @@ wlr_files += files( 'wayland/registry.c', 'wayland/wl_seat.c', ) + +if dep_systemd.found() + wlr_files += files('session/logind.c') +endif diff --git a/backend/multi/backend.c b/backend/multi/backend.c index d33d137c..19839629 100644 --- a/backend/multi/backend.c +++ b/backend/multi/backend.c @@ -1,6 +1,8 @@ #include <stdbool.h> #include <stdlib.h> #include <wlr/backend/interface.h> +#include <wlr/backend/udev.h> +#include <wlr/backend/session.h> #include <wlr/util/log.h> #include "backend/multi.h" @@ -31,6 +33,8 @@ static void multi_backend_destroy(struct wlr_backend_state *state) { free(sub); } list_free(state->backends); + wlr_session_finish(state->session); + wlr_udev_destroy(state->udev); free(state); } @@ -39,24 +43,33 @@ struct wlr_backend_impl backend_impl = { .destroy = multi_backend_destroy }; -struct wlr_backend *wlr_multi_backend_create() { +struct wlr_backend *wlr_multi_backend_create(struct wlr_session *session, + struct wlr_udev *udev) { struct wlr_backend_state *state = calloc(1, sizeof(struct wlr_backend_state)); if (!state) { wlr_log(L_ERROR, "Backend allocation failed"); return NULL; } + state->backends = list_create(); if (!state->backends) { free(state); wlr_log(L_ERROR, "Backend allocation failed"); return NULL; } + struct wlr_backend *backend = wlr_backend_create(&backend_impl, state); state->backend = backend; + state->session = session; + state->udev = udev; return backend; } +bool wlr_backend_is_multi(struct wlr_backend *b) { + return b->impl == &backend_impl; +} + static void input_add_reemit(struct wl_listener *listener, void *data) { struct subbackend_state *state = wl_container_of(listener, state, input_add); @@ -104,3 +117,11 @@ void wlr_multi_backend_add(struct wlr_backend *multi, list_add(multi->state->backends, sub); } + +struct wlr_session *wlr_multi_get_session(struct wlr_backend *base) { + if (base->impl != &backend_impl) + return NULL; + + struct wlr_backend_state *multi = base->state; + return multi->session; +} diff --git a/session/direct-ipc.c b/backend/session/direct-ipc.c index 885662e0..71e22148 100644 --- a/session/direct-ipc.c +++ b/backend/session/direct-ipc.c @@ -13,7 +13,7 @@ #include <xf86drm.h> #include <linux/major.h> #include <wlr/util/log.h> -#include "session/direct-ipc.h" +#include "backend/session/direct-ipc.h" enum { DRM_MAJOR = 226 }; diff --git a/session/direct.c b/backend/session/direct.c index 1247663b..82aa8e00 100644 --- a/session/direct.c +++ b/backend/session/direct.c @@ -13,9 +13,9 @@ #include <linux/input.h> #include <linux/vt.h> #include <wayland-server.h> -#include <wlr/session/interface.h> +#include <wlr/backend/session/interface.h> #include <wlr/util/log.h> -#include "session/direct-ipc.h" +#include "backend/session/direct-ipc.h" enum { DRM_MAJOR = 226 }; diff --git a/session/logind.c b/backend/session/logind.c index 6744215a..20d9b5ed 100644 --- a/session/logind.c +++ b/backend/session/logind.c @@ -11,7 +11,7 @@ #include <sys/stat.h> #include <fcntl.h> #include <wayland-server.h> -#include <wlr/session/interface.h> +#include <wlr/backend/session/interface.h> #include <wlr/util/log.h> enum { DRM_MAJOR = 226 }; diff --git a/session/session.c b/backend/session/session.c index 6f6aa2ea..a07d3cda 100644 --- a/session/session.c +++ b/backend/session/session.c @@ -1,7 +1,7 @@ #include <stddef.h> #include <stdarg.h> -#include <wlr/session.h> -#include <wlr/session/interface.h> +#include <wlr/backend/session.h> +#include <wlr/backend/session/interface.h> #include <wlr/util/log.h> extern const struct session_impl session_logind; @@ -30,6 +30,10 @@ struct wlr_session *wlr_session_start(struct wl_display *disp) { } void wlr_session_finish(struct wlr_session *session) { + if (!session) { + return; + } + session->impl->finish(session); }; @@ -42,5 +46,9 @@ void wlr_session_close_file(struct wlr_session *session, int fd) { } bool wlr_session_change_vt(struct wlr_session *session, unsigned vt) { + if (!session) { + return false; + } + return session->impl->change_vt(session, vt); } diff --git a/backend/udev.c b/backend/udev.c index 1fecaee4..1cc53f60 100644 --- a/backend/udev.c +++ b/backend/udev.c @@ -8,7 +8,7 @@ #include <xf86drm.h> #include <xf86drmMode.h> #include <wayland-server.h> -#include <wlr/session.h> +#include <wlr/backend/session.h> #include <wlr/util/log.h> #include "backend/udev.h" diff --git a/examples/compositor/main.c b/examples/compositor/main.c index e13fda24..c618961d 100644 --- a/examples/compositor/main.c +++ b/examples/compositor/main.c @@ -6,7 +6,7 @@ #include <inttypes.h> #include <wayland-server.h> #include <wlr/backend.h> -#include <wlr/session.h> +#include <wlr/backend/session.h> #include <wlr/render.h> #include <wlr/render/gles2.h> #include <wlr/types/wlr_output.h> diff --git a/examples/pointer.c b/examples/pointer.c index c7518841..d159caf5 100644 --- a/examples/pointer.c +++ b/examples/pointer.c @@ -14,7 +14,7 @@ #include <wlr/render/gles2.h> #include <wlr/render.h> #include <wlr/backend.h> -#include <wlr/session.h> +#include <wlr/backend/session.h> #include <wlr/types/wlr_keyboard.h> #include <wlr/util/log.h> #include "shared.h" diff --git a/examples/rotation.c b/examples/rotation.c index 36e95f50..bcf855d9 100644 --- a/examples/rotation.c +++ b/examples/rotation.c @@ -14,7 +14,7 @@ #include <wlr/render/gles2.h> #include <wlr/render.h> #include <wlr/backend.h> -#include <wlr/session.h> +#include <wlr/backend/session.h> #include <wlr/types/wlr_keyboard.h> #include <math.h> #include "shared.h" diff --git a/examples/shared.c b/examples/shared.c index 6d225a85..c66b8a23 100644 --- a/examples/shared.c +++ b/examples/shared.c @@ -8,7 +8,8 @@ #include <xkbcommon/xkbcommon.h> #include <wayland-server-protocol.h> #include <wlr/backend.h> -#include <wlr/session.h> +#include <wlr/backend/session.h> +#include <wlr/backend/multi.h> #include <wlr/types/wlr_output.h> #include <wlr/types/wlr_input_device.h> #include <wlr/util/log.h> @@ -44,8 +45,16 @@ static void keyboard_key_notify(struct wl_listener *listener, void *data) { } if (sym == XKB_KEY_Escape) { wl_display_terminate(kbstate->compositor->display); - } else if (key_state == WLR_KEY_PRESSED && sym >= XKB_KEY_F1 && sym <= XKB_KEY_F12) { - wlr_session_change_vt(kbstate->compositor->session, sym - XKB_KEY_F1 + 1); + } else if (key_state == WLR_KEY_PRESSED && + sym >= XKB_KEY_XF86Switch_VT_1 && + sym <= XKB_KEY_XF86Switch_VT_12) { + if (wlr_backend_is_multi(kbstate->compositor->backend)) { + struct wlr_session *session = + wlr_multi_get_session(kbstate->compositor->backend); + if (session) { + wlr_session_change_vt(session, sym - XKB_KEY_XF86Switch_VT_1 + 1); + } + } } } xkb_state_update_key(kbstate->xkb_state, keycode, @@ -440,12 +449,6 @@ static void output_remove_notify(struct wl_listener *listener, void *data) { void compositor_init(struct compositor_state *state) { state->display = wl_display_create(); state->event_loop = wl_display_get_event_loop(state->display); - state->session = wlr_session_start(state->display); - if (!state->session - || !state->display - || !state->event_loop) { - exit(1); - } wl_list_init(&state->keyboards); wl_list_init(&state->pointers); @@ -463,10 +466,8 @@ void compositor_init(struct compositor_state *state) { wl_list_init(&state->output_remove.link); state->output_remove.notify = output_remove_notify; - struct wlr_backend *wlr = wlr_backend_autocreate( - state->display, state->session); + struct wlr_backend *wlr = wlr_backend_autocreate(state->display); if (!wlr) { - wlr_session_finish(state->session); exit(1); } wl_signal_add(&wlr->events.input_add, &state->input_add); @@ -481,7 +482,6 @@ void compositor_init(struct compositor_state *state) { if (!socket) { wlr_log_errno(L_ERROR, "Unable to open wayland socket"); wlr_backend_destroy(wlr); - wlr_session_finish(state->session); exit(1); } @@ -490,7 +490,6 @@ void compositor_init(struct compositor_state *state) { if (!wlr_backend_init(state->backend)) { wlr_log(L_ERROR, "Failed to initialize backend"); wlr_backend_destroy(wlr); - wlr_session_finish(state->session); exit(1); } } @@ -498,6 +497,5 @@ void compositor_init(struct compositor_state *state) { void compositor_run(struct compositor_state *state) { wl_display_run(state->display); wlr_backend_destroy(state->backend); - wlr_session_finish(state->session); wl_display_destroy(state->display); } diff --git a/examples/shared.h b/examples/shared.h index 1633f2c8..2379eef9 100644 --- a/examples/shared.h +++ b/examples/shared.h @@ -8,7 +8,7 @@ #include <xkbcommon/xkbcommon.h> #include <wayland-server-protocol.h> #include <wlr/backend.h> -#include <wlr/session.h> +#include <wlr/backend/session.h> #include <wlr/types/wlr_output.h> #include <wlr/types/wlr_input_device.h> diff --git a/examples/simple.c b/examples/simple.c index 45cb2b93..8e098e18 100644 --- a/examples/simple.c +++ b/examples/simple.c @@ -7,7 +7,7 @@ #include <wayland-server.h> #include <GLES2/gl2.h> #include <wlr/backend.h> -#include <wlr/session.h> +#include <wlr/backend/session.h> #include <wlr/types/wlr_output.h> #include <xkbcommon/xkbcommon.h> #include "shared.h" diff --git a/examples/tablet.c b/examples/tablet.c index d7f7d042..0be6dcb9 100644 --- a/examples/tablet.c +++ b/examples/tablet.c @@ -13,7 +13,7 @@ #include <wlr/render/gles2.h> #include <wlr/render.h> #include <wlr/backend.h> -#include <wlr/session.h> +#include <wlr/backend/session.h> #include <wlr/types/wlr_output.h> #include <wlr/types/wlr_tablet_tool.h> #include <wlr/types/wlr_tablet_pad.h> diff --git a/examples/touch.c b/examples/touch.c index 97009e81..15ad9d49 100644 --- a/examples/touch.c +++ b/examples/touch.c @@ -15,7 +15,7 @@ #include <wlr/render/gles2.h> #include <wlr/render.h> #include <wlr/backend.h> -#include <wlr/session.h> +#include <wlr/backend/session.h> #include <wlr/util/list.h> #include "shared.h" #include "cat.h" diff --git a/include/backend/drm.h b/include/backend/drm.h index dc12c258..ecdd945b 100644 --- a/include/backend/drm.h +++ b/include/backend/drm.h @@ -10,7 +10,7 @@ #include <libudev.h> #include <gbm.h> -#include <wlr/session.h> +#include <wlr/backend/session.h> #include <wlr/backend/drm.h> #include <wlr/util/list.h> diff --git a/include/backend/multi.h b/include/backend/multi.h index efaf61b9..5ac9cc1d 100644 --- a/include/backend/multi.h +++ b/include/backend/multi.h @@ -3,10 +3,14 @@ #include <wlr/backend/interface.h> #include <wlr/backend/multi.h> +#include <wlr/backend/udev.h> #include <wlr/util/list.h> +#include <wlr/backend/session.h> struct wlr_backend_state { struct wlr_backend *backend; + struct wlr_session *session; + struct wlr_udev *udev; list_t *backends; }; diff --git a/include/session/direct-ipc.h b/include/backend/session/direct-ipc.h index 96504f04..96504f04 100644 --- a/include/session/direct-ipc.h +++ b/include/backend/session/direct-ipc.h diff --git a/include/backend/udev.h b/include/backend/udev.h index a2834063..080422c0 100644 --- a/include/backend/udev.h +++ b/include/backend/udev.h @@ -3,7 +3,7 @@ #include <sys/types.h> #include <libudev.h> -#include <wlr/session.h> +#include <wlr/backend/session.h> #include <wayland-server.h> #include <wlr/backend/udev.h> diff --git a/include/wlr/backend.h b/include/wlr/backend.h index db85c169..3910e406 100644 --- a/include/wlr/backend.h +++ b/include/wlr/backend.h @@ -2,7 +2,7 @@ #define _WLR_BACKEND_H #include <wayland-server.h> -#include <wlr/session.h> +#include <wlr/backend/session.h> struct wlr_backend_impl; struct wlr_backend_state; @@ -19,8 +19,7 @@ struct wlr_backend { } events; }; -struct wlr_backend *wlr_backend_autocreate(struct wl_display *display, - struct wlr_session *session); +struct wlr_backend *wlr_backend_autocreate(struct wl_display *display); bool wlr_backend_init(struct wlr_backend *backend); void wlr_backend_destroy(struct wlr_backend *backend); diff --git a/include/wlr/backend/drm.h b/include/wlr/backend/drm.h index a486757d..7332d608 100644 --- a/include/wlr/backend/drm.h +++ b/include/wlr/backend/drm.h @@ -2,7 +2,7 @@ #define WLR_BACKEND_DRM_H #include <wayland-server.h> -#include <wlr/session.h> +#include <wlr/backend/session.h> #include <wlr/backend.h> #include <wlr/backend/udev.h> diff --git a/include/wlr/backend/libinput.h b/include/wlr/backend/libinput.h index 29748b77..bba68888 100644 --- a/include/wlr/backend/libinput.h +++ b/include/wlr/backend/libinput.h @@ -3,7 +3,7 @@ #include <libinput.h> #include <wayland-server.h> -#include <wlr/session.h> +#include <wlr/backend/session.h> #include <wlr/backend.h> #include <wlr/backend/udev.h> #include <wlr/types/wlr_input_device.h> diff --git a/include/wlr/backend/multi.h b/include/wlr/backend/multi.h index a07ca770..e8e46bed 100644 --- a/include/wlr/backend/multi.h +++ b/include/wlr/backend/multi.h @@ -2,9 +2,16 @@ #define _WLR_BACKEND_MULTI_H #include <wlr/backend.h> +#include <wlr/backend/udev.h> +#include <wlr/backend/session.h> -struct wlr_backend *wlr_multi_backend_create(); +struct wlr_backend *wlr_multi_backend_create(struct wlr_session *session, + struct wlr_udev *udev); void wlr_multi_backend_add(struct wlr_backend *multi, struct wlr_backend *backend); +bool wlr_backend_is_multi(struct wlr_backend *backend); + +struct wlr_session *wlr_multi_get_session(struct wlr_backend *base); + #endif diff --git a/include/wlr/session.h b/include/wlr/backend/session.h index 7961e620..7961e620 100644 --- a/include/wlr/session.h +++ b/include/wlr/backend/session.h diff --git a/include/wlr/session/interface.h b/include/wlr/backend/session/interface.h index 4938110d..16814446 100644 --- a/include/wlr/session/interface.h +++ b/include/wlr/backend/session/interface.h @@ -1,7 +1,7 @@ #ifndef WLR_SESSION_INTERFACE_H #define WLR_SESSION_INTERFACE_H -#include <wlr/session.h> +#include <wlr/backend/session.h> struct session_impl { struct wlr_session *(*start)(struct wl_display *disp); diff --git a/meson.build b/meson.build index 9d603e22..ed687f56 100644 --- a/meson.build +++ b/meson.build @@ -63,7 +63,6 @@ wlr_files = [] subdir('backend') subdir('render') -subdir('session') subdir('types') subdir('util') diff --git a/session/meson.build b/session/meson.build deleted file mode 100644 index 4521cff6..00000000 --- a/session/meson.build +++ /dev/null @@ -1,9 +0,0 @@ -wlr_files += files( - 'direct-ipc.c', - 'direct.c', - 'session.c', -) - -if dep_systemd.found() - wlr_files += files('logind.c') -endif |