diff --git a/fbink.c b/fbink.c index e0aa2e63..7a01d552 100644 --- a/fbink.c +++ b/fbink.c @@ -12750,5 +12750,4 @@ void // Contains the Kobo only native/canonical rotation conversion helpers #include "fbink_rota_quirks.c" // Contains the input device scanner & classifier -// FIXME: Only w/ FBINK_WITH_INPUT #include "fbink_input_scan.c" diff --git a/fbink.h b/fbink.h index e778bc54..00166595 100644 --- a/fbink.h +++ b/fbink.h @@ -1656,7 +1656,7 @@ FBINK_API int fbink_mtk_toggle_auto_reagl(int fbfd, bool toggle); FBINK_API int fbink_mtk_toggle_pen_mode(int fbfd, bool toggle); // -// The functions below are small utilities to make working with input devicesslightly less painful. +// The functions below are small utilities to make working with input devices slightly less painful. // typedef enum { @@ -1698,13 +1698,13 @@ typedef struct // Regardless of the filter you request, this will always contain *all* the device's input devices. // The `matched` field will be set to true if that device matches *any* of the bits in `req_types`, // meaning you can throw out a fairly wide net, and still catch everything you care about. -// You *MUST* free the returned pointer after use. +// You *MUST* free the returned pointer after use (it's heap allocated). // Returns NULL on failure (no input devices can be read, or MINIMAL build w/o INPUT). // req_types: Bitmask used to filter the type of input devices you want to open. // if the OPEN_BLOCKING bit is set, fds will be opened in *blocking* mode. // Otherwise, the default open flags are O_RDONLY|O_NONBLOCK|O_CLOEXEC // if the SCAN_ONLY bit is set, *no* fds will be returned, regardless of the filter. -// dev_count: out pointer, will be set to the amount of array elements. +// dev_count: out pointer, will be set to the amount of array elements in the returned data. // NOTE: This does *NOT* require fbink to be initialized, but *does* honor its internal verbosity state. FBINK_API FBInkInputDevice* fbink_input_scan(INPUT_DEVICE_TYPE_T req_types, size_t* dev_count); diff --git a/fbink_input_scan.c b/fbink_input_scan.c index 35648929..0594c181 100644 --- a/fbink_input_scan.c +++ b/fbink_input_scan.c @@ -256,13 +256,8 @@ static __attribute__((cold)) void { bool first = true; // Udev - if (type & INPUT_UNKNOWN) { - if (first) { - strcat(string, " = UNKNOWN"); - first = false; - } else { - strcat(string, " | UNKNOWN"); - } + if (type == INPUT_UNKNOWN) { + strcat(string, " = UNKNOWN"); } if (type & INPUT_POINTINGSTICK) { if (first) { @@ -411,19 +406,21 @@ FBInkInputDevice* return NULL; } + // Default to NONBLOCK + int o_flags = O_RDONLY | O_CLOEXEC; + if ((req_types & OPEN_BLOCKING) == 0) { + o_flags |= O_NONBLOCK; + } + for (int i = 0; i < ndev; i++) { FBInkInputDevice* dev = devices + i; dev->fd = -1; snprintf(dev->path, sizeof(dev->path), "%s/%s", DEV_INPUT_EVENT, namelist[i]->d_name); - // Default to NONBLOCK - int o_flags = O_RDONLY | O_CLOEXEC; - if ((req_types & OPEN_BLOCKING) == 0) { - o_flags |= O_NONBLOCK; - } dev->fd = open(dev->path, o_flags); if (dev->fd < 0) { PFWARN("open `%s`: %m", dev->path); + free(namelist[i]); continue; } diff --git a/utils/input_scan.c b/utils/input_scan.c index 836f721d..f2bfe07c 100644 --- a/utils/input_scan.c +++ b/utils/input_scan.c @@ -90,7 +90,7 @@ static void "\n" "Input Scan (via FBInk %s)\n" "\n" - "Usage: input_scan\n" + "Usage: input_scan [-m] [-p]\n" "\n" "Scan & classify input devices.\n" "\n"