Add error handling and init in backend_autocreate

This commit is contained in:
Drew DeVault 2017-06-09 11:38:38 -04:00
parent 1262f1400c
commit af69591e62
5 changed files with 26 additions and 2 deletions

View File

@ -2,6 +2,7 @@ include_directories(
${PROTOCOLS_INCLUDE_DIRS} ${PROTOCOLS_INCLUDE_DIRS}
${WAYLAND_INCLUDE_DIR} ${WAYLAND_INCLUDE_DIR}
${DRM_INCLUDE_DIRS} ${DRM_INCLUDE_DIRS}
${LIBINPUT_INCLUDE_DIRS}
) )
add_library(wlr-backend add_library(wlr-backend
@ -30,5 +31,6 @@ target_link_libraries(wlr-backend
${EGL_LIBRARIES} ${EGL_LIBRARIES}
${SYSTEMD_LIBRARIES} ${SYSTEMD_LIBRARIES}
${UDEV_LIBRARIES} ${UDEV_LIBRARIES}
${LIBINPUT_LIBRARIES}
${GBM_LIBRARIES} ${GBM_LIBRARIES}
) )

View File

@ -5,8 +5,10 @@
#include <errno.h> #include <errno.h>
#include <wlr/session.h> #include <wlr/session.h>
#include <wlr/backend/interface.h> #include <wlr/backend/interface.h>
#include <wlr/backend/drm.h>
#include <wlr/backend/libinput.h>
#include "backend/udev.h"
#include "common/log.h" #include "common/log.h"
#include "backend/drm.h"
struct wlr_backend *wlr_backend_create(const struct wlr_backend_impl *impl, struct wlr_backend *wlr_backend_create(const struct wlr_backend_impl *impl,
struct wlr_backend_state *state) { 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"); wlr_log(L_ERROR, "Failed to start udev");
goto error; goto error;
} }
struct wlr_backend *wlr;
wlr = wlr_libinput_backend_create(display, session, udev);
return wlr;
int gpu = wlr_udev_find_gpu(udev, session); int gpu = wlr_udev_find_gpu(udev, session);
if (gpu == -1) { if (gpu == -1) {
wlr_log(L_ERROR, "Failed to open DRM device"); wlr_log(L_ERROR, "Failed to open DRM device");
goto error_udev; goto error_udev;
} }
struct wlr_backend *wlr;
wlr = wlr_drm_backend_create(display, session, udev, gpu); wlr = wlr_drm_backend_create(display, session, udev, gpu);
if (!wlr) { if (!wlr) {
goto error_gpu; goto error_gpu;

View File

@ -34,14 +34,17 @@ static void wlr_libinput_log(struct libinput *libinput,
} }
static bool wlr_libinput_backend_init(struct wlr_backend_state *state) { 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->handle = libinput_udev_create_context(&libinput_impl, state,
state->udev->udev); state->udev->udev);
if (!state->handle) { if (!state->handle) {
wlr_log(L_ERROR, "Failed to create libinput context");
return false; return false;
} }
// TODO: Let user customize seat used // TODO: Let user customize seat used
if (!libinput_udev_assign_seat(state->handle, "seat0")) { if (!libinput_udev_assign_seat(state->handle, "seat0")) {
wlr_log(L_ERROR, "Failed to assign libinput seat");
return false; 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, libinput_get_fd(state->handle), WL_EVENT_READABLE,
wlr_libinput_handle_event, state); wlr_libinput_handle_event, state);
if (!state->input_event) { if (!state->input_event) {
wlr_log(L_ERROR, "Failed to create input event on event loop");
return false; return false;
} }
wlr_log(L_DEBUG, "libinput sucessfully initialized");
return true; return true;
} }

View File

@ -219,6 +219,7 @@ int main(int argc, char *argv[]) {
wl_signal_add(&wlr->events.output_remove, &state.output_remove); wl_signal_add(&wlr->events.output_remove, &state.output_remove);
if (!wlr_backend_init(wlr)) { if (!wlr_backend_init(wlr)) {
printf("Failed to initialize backend, bailing out\n");
return 1; return 1;
} }

View File

@ -0,0 +1,12 @@
#ifndef WLR_BACKEND_LIBINPUT_H
#define WLR_BACKEND_LIBINPUT_H
#include <wayland-server.h>
#include <wlr/session.h>
#include <wlr/backend.h>
#include <wlr/backend/udev.h>
struct wlr_backend *wlr_libinput_backend_create(struct wl_display *display,
struct wlr_session *session, struct wlr_udev *udev);
#endif