From de66bdb8679de14377306b7a903f2bc5d62fd169 Mon Sep 17 00:00:00 2001 From: Calvin Lee Date: Sun, 13 Aug 2017 23:05:57 +0200 Subject: Add backend detection functions Resolves #80 --- backend/drm/backend.c | 4 ++++ backend/libinput/backend.c | 4 ++++ backend/multi/backend.c | 9 +++++---- include/wlr/backend/drm.h | 2 ++ include/wlr/backend/libinput.h | 2 ++ 5 files changed, 17 insertions(+), 4 deletions(-) diff --git a/backend/drm/backend.c b/backend/drm/backend.c index a2c9dff3..a84130ee 100644 --- a/backend/drm/backend.c +++ b/backend/drm/backend.c @@ -52,6 +52,10 @@ static struct wlr_backend_impl backend_impl = { .get_egl = wlr_drm_backend_get_egl }; +bool wlr_backend_is_drm(struct wlr_backend *b) { + return b->impl == &backend_impl; +} + static void session_signal(struct wl_listener *listener, void *data) { struct wlr_drm_backend *backend = wl_container_of(listener, backend, session_signal); diff --git a/backend/libinput/backend.c b/backend/libinput/backend.c index 44a1a4a9..18e4826c 100644 --- a/backend/libinput/backend.c +++ b/backend/libinput/backend.c @@ -103,6 +103,10 @@ static struct wlr_backend_impl backend_impl = { .destroy = wlr_libinput_backend_destroy }; +bool wlr_backend_is_libinput(struct wlr_backend *b) { + return b->impl == &backend_impl; +} + static void session_signal(struct wl_listener *listener, void *data) { struct wlr_libinput_backend *backend = wl_container_of(listener, backend, session_signal); struct wlr_session *session = data; diff --git a/backend/multi/backend.c b/backend/multi/backend.c index 99cf3db9..94b7dd60 100644 --- a/backend/multi/backend.c +++ b/backend/multi/backend.c @@ -1,3 +1,4 @@ +#include #include #include #include @@ -111,6 +112,8 @@ static void output_remove_reemit(struct wl_listener *listener, void *data) { void wlr_multi_backend_add(struct wlr_backend *_multi, struct wlr_backend *backend) { + assert(wlr_backend_is_multi(backend)); + struct wlr_multi_backend *multi = (struct wlr_multi_backend *)_multi; struct subbackend_state *sub = calloc(1, sizeof(struct subbackend_state)); sub->backend = backend; @@ -135,10 +138,8 @@ void wlr_multi_backend_add(struct wlr_backend *_multi, } struct wlr_session *wlr_multi_get_session(struct wlr_backend *_backend) { - // TODO: assert(wlr_backend_is_multi(_backend)); - if (_backend->impl != &backend_impl) { - return NULL; - } + assert(wlr_backend_is_multi(_backend)); + struct wlr_multi_backend *backend = (struct wlr_multi_backend *)_backend; return backend->session; } diff --git a/include/wlr/backend/drm.h b/include/wlr/backend/drm.h index 7332d608..fe1cc5a7 100644 --- a/include/wlr/backend/drm.h +++ b/include/wlr/backend/drm.h @@ -9,4 +9,6 @@ struct wlr_backend *wlr_drm_backend_create(struct wl_display *display, struct wlr_session *session, struct wlr_udev *udev, int gpu_fd); +bool wlr_backend_is_drm(struct wlr_backend *backend); + #endif diff --git a/include/wlr/backend/libinput.h b/include/wlr/backend/libinput.h index bba68888..b227a7ad 100644 --- a/include/wlr/backend/libinput.h +++ b/include/wlr/backend/libinput.h @@ -12,4 +12,6 @@ struct wlr_backend *wlr_libinput_backend_create(struct wl_display *display, struct wlr_session *session, struct wlr_udev *udev); struct libinput_device *wlr_libinput_get_device_handle(struct wlr_input_device *dev); +bool wlr_backend_is_libinput(struct wlr_backend *backend); + #endif -- cgit v1.2.3