From af69591e6233c83ed749b2f51922edb45bdaef2e Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Fri, 9 Jun 2017 11:38:38 -0400 Subject: [PATCH] Add error handling and init in backend_autocreate --- backend/CMakeLists.txt | 2 ++ backend/backend.c | 8 ++++++-- backend/libinput/backend.c | 5 +++++ example/rotation.c | 1 + include/wlr/backend/libinput.h | 12 ++++++++++++ 5 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 include/wlr/backend/libinput.h diff --git a/backend/CMakeLists.txt b/backend/CMakeLists.txt index bca615fb..c3e7ef54 100644 --- a/backend/CMakeLists.txt +++ b/backend/CMakeLists.txt @@ -2,6 +2,7 @@ include_directories( ${PROTOCOLS_INCLUDE_DIRS} ${WAYLAND_INCLUDE_DIR} ${DRM_INCLUDE_DIRS} + ${LIBINPUT_INCLUDE_DIRS} ) add_library(wlr-backend @@ -30,5 +31,6 @@ target_link_libraries(wlr-backend ${EGL_LIBRARIES} ${SYSTEMD_LIBRARIES} ${UDEV_LIBRARIES} + ${LIBINPUT_LIBRARIES} ${GBM_LIBRARIES} ) diff --git a/backend/backend.c b/backend/backend.c index 38b65dca..1a0c3295 100644 --- a/backend/backend.c +++ b/backend/backend.c @@ -5,8 +5,10 @@ #include #include #include +#include +#include +#include "backend/udev.h" #include "common/log.h" -#include "backend/drm.h" struct wlr_backend *wlr_backend_create(const struct wlr_backend_impl *impl, struct wlr_backend_state *state) { @@ -46,12 +48,14 @@ struct wlr_backend *wlr_backend_autocreate(struct wl_display *display, wlr_log(L_ERROR, "Failed to start udev"); goto error; } + struct wlr_backend *wlr; + wlr = wlr_libinput_backend_create(display, session, udev); + return wlr; int gpu = wlr_udev_find_gpu(udev, session); if (gpu == -1) { wlr_log(L_ERROR, "Failed to open DRM device"); goto error_udev; } - struct wlr_backend *wlr; wlr = wlr_drm_backend_create(display, session, udev, gpu); if (!wlr) { goto error_gpu; diff --git a/backend/libinput/backend.c b/backend/libinput/backend.c index 6142bde3..b49bf6b4 100644 --- a/backend/libinput/backend.c +++ b/backend/libinput/backend.c @@ -34,14 +34,17 @@ static void wlr_libinput_log(struct libinput *libinput, } static bool wlr_libinput_backend_init(struct wlr_backend_state *state) { + wlr_log(L_DEBUG, "Initializing libinput"); state->handle = libinput_udev_create_context(&libinput_impl, state, state->udev->udev); if (!state->handle) { + wlr_log(L_ERROR, "Failed to create libinput context"); return false; } // TODO: Let user customize seat used if (!libinput_udev_assign_seat(state->handle, "seat0")) { + wlr_log(L_ERROR, "Failed to assign libinput seat"); return false; } @@ -58,8 +61,10 @@ static bool wlr_libinput_backend_init(struct wlr_backend_state *state) { libinput_get_fd(state->handle), WL_EVENT_READABLE, wlr_libinput_handle_event, state); if (!state->input_event) { + wlr_log(L_ERROR, "Failed to create input event on event loop"); return false; } + wlr_log(L_DEBUG, "libinput sucessfully initialized"); return true; } diff --git a/example/rotation.c b/example/rotation.c index 25755f5f..12778f8e 100644 --- a/example/rotation.c +++ b/example/rotation.c @@ -219,6 +219,7 @@ int main(int argc, char *argv[]) { wl_signal_add(&wlr->events.output_remove, &state.output_remove); if (!wlr_backend_init(wlr)) { + printf("Failed to initialize backend, bailing out\n"); return 1; } diff --git a/include/wlr/backend/libinput.h b/include/wlr/backend/libinput.h new file mode 100644 index 00000000..1e8c3555 --- /dev/null +++ b/include/wlr/backend/libinput.h @@ -0,0 +1,12 @@ +#ifndef WLR_BACKEND_LIBINPUT_H +#define WLR_BACKEND_LIBINPUT_H + +#include +#include +#include +#include + +struct wlr_backend *wlr_libinput_backend_create(struct wl_display *display, + struct wlr_session *session, struct wlr_udev *udev); + +#endif