Skip to content

Commit

Permalink
libinput: initialize the quirks subsystem
Browse files Browse the repository at this point in the history
A bit quirky (haha), because we cannot do this during context creation - we
really want any parsing error messages to show up in the right log file and
the log handler isn't set up during context creation. So we do it on the first
real call to the backend - path_add_device or udev_assign_seat.

Also, failure to initialize the quirks subsystem just means we continue as
normal. This shouldn't be a hard failure, it just means a lot of devices won't
work properly.

If the LIBINPUT_DATA_DIR environment variable is set, that directory is used
for the data file. Only that directory, no custom override file in that case.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
  • Loading branch information
whot committed Jun 8, 2018
1 parent 12b0722 commit 33341dd
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/libinput-private.h
Expand Up @@ -140,6 +140,9 @@ struct libinput {
struct list device_group_list;

uint64_t last_event_time;

bool quirks_initialized;
struct quirks_context *quirks;
};

typedef void (*libinput_seat_destroy_func) (struct libinput_seat *seat);
Expand Down Expand Up @@ -427,6 +430,9 @@ libinput_init(struct libinput *libinput,
const struct libinput_interface_backend *interface_backend,
void *user_data);

void
libinput_init_quirks(struct libinput *libinput);

struct libinput_source *
libinput_add_fd(struct libinput *libinput,
int fd,
Expand Down
42 changes: 42 additions & 0 deletions src/libinput.c
Expand Up @@ -38,6 +38,7 @@
#include "libinput-private.h"
#include "evdev.h"
#include "timer.h"
#include "quirks.h"

#define require_event_type(li_, type_, retval_, ...) \
if (type_ == LIBINPUT_EVENT_NONE) abort(); \
Expand Down Expand Up @@ -1720,6 +1721,46 @@ libinput_init(struct libinput *libinput,
return 0;
}

void
libinput_init_quirks(struct libinput *libinput)
{
const char *data_path,
*override_file = NULL;
struct quirks_context *quirks;

if (libinput->quirks_initialized)
return;

/* If we fail, we'll fail next time too */
libinput->quirks_initialized = true;

data_path = getenv("LIBINPUT_DATA_DIR");
if (!data_path) {
data_path = LIBINPUT_DATA_DIR;
override_file = LIBINPUT_DATA_OVERRIDE_FILE;
}

quirks = quirks_init_subsystem(data_path,
override_file,
log_msg_va,
libinput,
QLOG_LIBINPUT_LOGGING);
if (!quirks) {
log_error(libinput,
"Failed to load the device quirks from %s%s%s. "
"This will negatively affect device behavior. "
"See %sdevice-quirks.html for details.\n",
data_path,
override_file ? " and " : "",
override_file ? override_file : "",
HTTP_DOC_LINK
);
return;
}

libinput->quirks = quirks;
}

static void
libinput_device_destroy(struct libinput_device *device);

Expand Down Expand Up @@ -1791,6 +1832,7 @@ libinput_unref(struct libinput *libinput)

libinput_timer_subsys_destroy(libinput);
libinput_drop_destroyed_sources(libinput);
quirks_context_unref(libinput->quirks);
close(libinput->epoll_fd);
free(libinput);

Expand Down
7 changes: 7 additions & 0 deletions src/path-seat.c
Expand Up @@ -337,6 +337,13 @@ libinput_path_add_device(struct libinput *libinput,
return NULL;
}

/* We cannot do this during path_create_context because the log
* handler isn't set up there but we really want to log to the right
* place if the quirks run into parser errors. So we have to do it
* on the first call to add_device.
*/
libinput_init_quirks(libinput);

udev_device = udev_device_from_devnode(libinput, udev, path);
if (!udev_device) {
log_bug_client(libinput, "Invalid path %s\n", path);
Expand Down
7 changes: 7 additions & 0 deletions src/udev-seat.c
Expand Up @@ -382,6 +382,13 @@ libinput_udev_assign_seat(struct libinput *libinput,
{
struct udev_input *input = (struct udev_input*)libinput;

/* We cannot do this during udev_create_context because the log
* handler isn't set up there but we really want to log to the right
* place if the quirks run into parser errors. So we have to do it
* here since we can expect the log handler to be set up by now.
*/
libinput_init_quirks(libinput);

if (!seat_id)
return -1;

Expand Down

0 comments on commit 33341dd

Please sign in to comment.