Skip to content

Commit

Permalink
Final review pass for now
Browse files Browse the repository at this point in the history
  • Loading branch information
NiLuJe committed May 11, 2024
1 parent 175b73e commit 0f5528b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 17 deletions.
1 change: 0 additions & 1 deletion fbink.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
6 changes: 3 additions & 3 deletions fbink.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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);

Expand Down
21 changes: 9 additions & 12 deletions fbink_input_scan.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion utils/input_scan.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ static void
"\n"
"Input Scan (via FBInk %s)\n"
"\n"
"Usage: input_scan\n"
"Usage: input_scan [-m] <type...> [-p]\n"
"\n"
"Scan & classify input devices.\n"
"\n"
Expand Down

0 comments on commit 0f5528b

Please sign in to comment.