diff --git a/tools/event-debug.c b/tools/event-debug.c index becde168..77133851 100644 --- a/tools/event-debug.c +++ b/tools/event-debug.c @@ -45,24 +45,6 @@ static const uint32_t screen_height = 100; struct tools_options options; static unsigned int stop = 0; -static int -open_restricted(const char *path, int flags, void *user_data) -{ - int fd = open(path, flags); - return fd < 0 ? -errno : fd; -} - -static void -close_restricted(int fd, void *user_data) -{ - close(fd); -} - -static const struct libinput_interface interface = { - .open_restricted = open_restricted, - .close_restricted = close_restricted, -}; - static void print_event_header(struct libinput_event *ev) { @@ -403,7 +385,7 @@ main(int argc, char **argv) if (tools_parse_args(argc, argv, &options)) return 1; - li = tools_open_backend(&options, NULL, &interface); + li = tools_open_backend(&options, NULL); if (!li) return 1; diff --git a/tools/event-gui.c b/tools/event-gui.c index 9d291956..7af2a303 100644 --- a/tools/event-gui.c +++ b/tools/event-gui.c @@ -489,24 +489,6 @@ sockets_init(struct libinput *li) g_io_add_watch(c, G_IO_IN, handle_event_libinput, li); } -static int -open_restricted(const char *path, int flags, void *user_data) -{ - int fd = open(path, flags); - return fd < 0 ? -errno : fd; -} - -static void -close_restricted(int fd, void *user_data) -{ - close(fd); -} - -static const struct libinput_interface interface = { - .open_restricted = open_restricted, - .close_restricted = close_restricted, -}; - int main(int argc, char *argv[]) { @@ -525,7 +507,7 @@ main(int argc, char *argv[]) if (!udev) error("Failed to initialize udev\n"); - li = tools_open_backend(&options, &w, &interface); + li = tools_open_backend(&options, &w); if (!li) return 1; diff --git a/tools/libinput-list-devices.c b/tools/libinput-list-devices.c index b3f7e2f9..e66aa3c9 100644 --- a/tools/libinput-list-devices.c +++ b/tools/libinput-list-devices.c @@ -23,7 +23,6 @@ #define _GNU_SOURCE #include -#include #include #include #include @@ -36,27 +35,6 @@ #include "shared.h" -static int -open_restricted(const char *path, int flags, void *user_data) -{ - int fd = open(path, flags); - if (fd < 0) - fprintf(stderr, "Failed to open %s (%s)\n", - path, strerror(errno)); - return fd < 0 ? -errno : fd; -} - -static void -close_restricted(int fd, void *user_data) -{ - close(fd); -} - -static const struct libinput_interface interface = { - .open_restricted = open_restricted, - .close_restricted = close_restricted, -}; - static inline const char* bool_to_str(bool b) { @@ -308,7 +286,7 @@ main(int argc, char **argv) tools_init_options(&options); - li = tools_open_backend(&options, NULL, &interface); + li = tools_open_backend(&options, NULL); if (!li) return 1; diff --git a/tools/shared.c b/tools/shared.c index a0ff779c..7b032080 100644 --- a/tools/shared.c +++ b/tools/shared.c @@ -25,6 +25,7 @@ #include #include +#include #include #include #include @@ -344,17 +345,37 @@ open_device(const struct libinput_interface *interface, return li; } +static int +open_restricted(const char *path, int flags, void *user_data) +{ + int fd = open(path, flags); + if (fd < 0) + fprintf(stderr, "Failed to open %s (%s)\n", + path, strerror(errno)); + return fd < 0 ? -errno : fd; +} + +static void +close_restricted(int fd, void *user_data) +{ + close(fd); +} + +static const struct libinput_interface interface = { + .open_restricted = open_restricted, + .close_restricted = close_restricted, +}; + struct libinput * tools_open_backend(struct tools_options *options, - void *userdata, - const struct libinput_interface *interface) + void *userdata) { struct libinput *li = NULL; if (options->backend == BACKEND_UDEV) { - li = open_udev(interface, userdata, options->seat, options->verbose); + li = open_udev(&interface, userdata, options->seat, options->verbose); } else if (options->backend == BACKEND_DEVICE) { - li = open_device(interface, userdata, options->device, options->verbose); + li = open_device(&interface, userdata, options->device, options->verbose); } else abort(); diff --git a/tools/shared.h b/tools/shared.h index da752d59..dad33a16 100644 --- a/tools/shared.h +++ b/tools/shared.h @@ -51,8 +51,7 @@ struct tools_options { void tools_init_options(struct tools_options *options); int tools_parse_args(int argc, char **argv, struct tools_options *options); struct libinput* tools_open_backend(struct tools_options *options, - void *userdata, - const struct libinput_interface *interface); + void *userdata); void tools_device_apply_config(struct libinput_device *device, struct tools_options *options); void tools_usage();