Replace device discovery with upstreamed code
This commit is contained in:
parent
0e10e9236a
commit
bc293a3cf6
4 changed files with 11 additions and 268 deletions
2
Makefile
2
Makefile
|
|
@ -10,7 +10,7 @@ BIN = unl0kr
|
|||
|
||||
|
||||
#Collect the files to compile
|
||||
MAINSRC = ./main.c ./libinput_device_discovery.c ./libinput_multi.c ./libinput_xkb.c ./layouts.c ./montserrat_extended_32.c ./uskr_layouts.c
|
||||
MAINSRC = ./main.c ./libinput_multi.c ./libinput_xkb.c ./layouts.c ./montserrat_extended_32.c ./uskr_layouts.c
|
||||
|
||||
include $(LVGL_DIR)/lvgl/lvgl.mk
|
||||
include $(LVGL_DIR)/lv_drivers/lv_drivers.mk
|
||||
|
|
|
|||
|
|
@ -1,169 +0,0 @@
|
|||
/**
|
||||
* @file libinput_device_discovery.c
|
||||
*
|
||||
*/
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "libinput_device_discovery.h"
|
||||
#if USE_LIBINPUT || USE_BSD_LIBINPUT
|
||||
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <libinput.h>
|
||||
|
||||
#if USE_BSD_LIBINPUT
|
||||
#include <dev/evdev/input.h>
|
||||
#else
|
||||
#include <linux/input.h>
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
static int open_restricted(const char *path, int flags, void *user_data);
|
||||
static void close_restricted(int fd, void *user_data);
|
||||
static bool is_keyboard(struct libinput_device *device);
|
||||
static bool is_pointer_device(struct libinput_device *device);
|
||||
static bool is_touchscreen(struct libinput_device *device);
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
static const struct libinput_interface interface = {
|
||||
.open_restricted = open_restricted,
|
||||
.close_restricted = close_restricted,
|
||||
};
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL FUNCTIONS
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* find connected keyboard devices
|
||||
* @param match function returning true if device matches desired condition
|
||||
* @param devices pre-allocated array to store device paths into
|
||||
* @param count maximum number of devices
|
||||
* @return number of devices discovered
|
||||
*/
|
||||
size_t libinput_discover(bool match(struct libinput_device *), char devices[][32], size_t count) {
|
||||
struct libinput * context = libinput_path_create_context(&interface, NULL);
|
||||
|
||||
DIR *dir;
|
||||
struct dirent *ent;
|
||||
if (!(dir = opendir("/dev/input"))) {
|
||||
perror("unable to open directory /dev/input:");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int index = 0;
|
||||
while (index < count && (ent = readdir(dir))) {
|
||||
if (strncmp(ent->d_name, "event", strlen("event")) != 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
char path[32];
|
||||
strcpy(path, "/dev/input/");
|
||||
strcat(path, ent->d_name);
|
||||
|
||||
struct libinput_device * device = libinput_path_add_device(context, path);
|
||||
if(!device) {
|
||||
perror("unable to add device to libinput context:");
|
||||
continue;
|
||||
}
|
||||
|
||||
device = libinput_device_ref(device);
|
||||
if(!device) {
|
||||
perror("unable to reference device within libinput context:");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (match(device)) {
|
||||
strcpy(devices[index], path);
|
||||
index++;
|
||||
}
|
||||
|
||||
device = libinput_device_unref(device);
|
||||
libinput_path_remove_device(device);
|
||||
}
|
||||
|
||||
libinput_unref(context);
|
||||
return index;
|
||||
}
|
||||
|
||||
/**
|
||||
* find connected keyboard devices
|
||||
* @param devices pre-allocated array to store device paths into
|
||||
* @param count maximum number of devices
|
||||
* @return number of devices discovered
|
||||
*/
|
||||
size_t libinput_discover_keyboards(char devices[][32], size_t count) {
|
||||
return libinput_discover(is_keyboard, devices, count);
|
||||
}
|
||||
|
||||
/**
|
||||
* find connected pointer devices
|
||||
* @param devices pre-allocated array to store device paths into
|
||||
* @param count maximum number of devices
|
||||
* @return number of devices discovered
|
||||
*/
|
||||
size_t libinput_discover_pointer_devices(char devices[][32], size_t count) {
|
||||
return libinput_discover(is_pointer_device, devices, count);
|
||||
}
|
||||
|
||||
/**
|
||||
* find connected touchscreen devices
|
||||
* @param devices pre-allocated array to store device paths into
|
||||
* @param count maximum number of devices
|
||||
* @return number of devices discovered
|
||||
*/
|
||||
size_t libinput_discover_touchscreens(char devices[][32], size_t count) {
|
||||
return libinput_discover(is_touchscreen, devices, count);
|
||||
}
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
|
||||
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 bool is_keyboard(struct libinput_device * device) {
|
||||
return libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_KEYBOARD)
|
||||
&& libinput_device_keyboard_has_key(device, KEY_A);
|
||||
}
|
||||
|
||||
static bool is_pointer_device(struct libinput_device * device) {
|
||||
return libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_POINTER);
|
||||
}
|
||||
|
||||
static bool is_touchscreen(struct libinput_device * device) {
|
||||
return libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_TOUCH);
|
||||
}
|
||||
|
||||
#endif /* USE_LIBINPUT || USE_BSD_LIBINPUT */
|
||||
|
|
@ -1,88 +0,0 @@
|
|||
/**
|
||||
* @file libInput_device_discovery.h
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef LVGL_DEVICE_DISCOVERY_H
|
||||
#define LVGL_DEVICE_DISCOVERY_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
// #ifndef LV_DRV_NO_CONF
|
||||
// #ifdef LV_CONF_INCLUDE_SIMPLE
|
||||
#include "lv_drv_conf.h"
|
||||
// #else
|
||||
// #include "../../lv_drv_conf.h"
|
||||
// #endif
|
||||
// #endif
|
||||
|
||||
#if USE_LIBINPUT || USE_BSD_LIBINPUT
|
||||
|
||||
#ifdef LV_LVGL_H_INCLUDE_SIMPLE
|
||||
#include "lvgl.h"
|
||||
#else
|
||||
#include "lvgl/lvgl.h"
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
struct libinput_device;
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* find connected keyboard devices
|
||||
* @param match function returning true if device matches desired condition
|
||||
* @param devices pre-allocated array to store device paths into
|
||||
* @param count maximum number of devices
|
||||
* @return number of devices discovered
|
||||
*/
|
||||
size_t libinput_discover(bool match(struct libinput_device *), char devices[][32], size_t count);
|
||||
|
||||
/**
|
||||
* find connected keyboard devices
|
||||
* @param devices pre-allocated array to store device paths into
|
||||
* @param count maximum number of devices
|
||||
* @return number of devices discovered
|
||||
*/
|
||||
size_t libinput_discover_keyboards(char devices[][32], size_t count);
|
||||
|
||||
/**
|
||||
* find connected pointer devices
|
||||
* @param devices pre-allocated array to store device paths into
|
||||
* @param count maximum number of devices
|
||||
* @return number of devices discovered
|
||||
*/
|
||||
size_t libinput_discover_pointer_devices(char devices[][32], size_t count);
|
||||
|
||||
/**
|
||||
* find connected touchscreen devices
|
||||
* @param devices pre-allocated array to store device paths into
|
||||
* @param count maximum number of devices
|
||||
* @return number of devices discovered
|
||||
*/
|
||||
size_t libinput_discover_touchscreens(char devices[][32], size_t count);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
#endif /* USE_LIBINPUT || USE_BSD_LIBINPUT */
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /* LVGL_DEVICE_DISCOVERY_H */
|
||||
20
main.c
20
main.c
|
|
@ -7,8 +7,8 @@
|
|||
|
||||
#include "lvgl/lvgl.h"
|
||||
#include "lv_drivers/display/fbdev.h"
|
||||
#include "lv_drivers/indev/libinput_drv.h"
|
||||
|
||||
#include "libinput_device_discovery.h"
|
||||
#include "libinput_multi.h"
|
||||
#include "libinput_xkb.h"
|
||||
#include "layouts.h"
|
||||
|
|
@ -312,10 +312,10 @@ int main(void)
|
|||
|
||||
// Connect keyboards
|
||||
#define MAX_KEYBOARDS 3
|
||||
char keyboard_devices[MAX_KEYBOARDS][32] = { "", "", "" };
|
||||
char *keyboard_devices[MAX_KEYBOARDS] = { NULL, NULL, NULL };
|
||||
lv_indev_drv_t keyboard_indev_drvs[MAX_KEYBOARDS];
|
||||
lv_indev_t *keyboard_indevs[MAX_KEYBOARDS] = { 0, 0, 0 };
|
||||
int num_keyboards = libinput_discover_keyboards(keyboard_devices, MAX_KEYBOARDS);
|
||||
lv_indev_t *keyboard_indevs[MAX_KEYBOARDS] = { NULL, NULL, NULL };
|
||||
size_t num_keyboards = libinput_find_devs(LIBINPUT_CAPABILITY_KEYBOARD, keyboard_devices, MAX_KEYBOARDS, false);
|
||||
for (int i = 0; i < num_keyboards; ++i) {
|
||||
printf("found keyboard device %s\n", keyboard_devices[i]);
|
||||
lv_indev_drv_init(&keyboard_indev_drvs[i]);
|
||||
|
|
@ -328,10 +328,10 @@ int main(void)
|
|||
|
||||
// Connect mice and trackpads
|
||||
#define MAX_POINTER_DEVICES 4
|
||||
char pointer_devices[MAX_POINTER_DEVICES][32] = { "", "", "", "" };
|
||||
char *pointer_devices[MAX_POINTER_DEVICES] = { NULL, NULL, NULL, NULL };
|
||||
lv_indev_drv_t pointer_indev_drvs[MAX_POINTER_DEVICES];
|
||||
lv_indev_t *pointer_indevs[MAX_POINTER_DEVICES] = { 0, 0, 0, 0 };
|
||||
int num_pointer_devices = libinput_discover_pointer_devices(pointer_devices, MAX_POINTER_DEVICES);
|
||||
lv_indev_t *pointer_indevs[MAX_POINTER_DEVICES] = { NULL, NULL, NULL, NULL };
|
||||
size_t num_pointer_devices = libinput_find_devs(LIBINPUT_CAPABILITY_POINTER, pointer_devices, MAX_POINTER_DEVICES, false);
|
||||
for (int i = 0; i < num_pointer_devices; ++i) {
|
||||
printf("found pointer device %s\n", pointer_devices[i]);
|
||||
lv_indev_drv_init(&pointer_indev_drvs[i]);
|
||||
|
|
@ -345,10 +345,10 @@ int main(void)
|
|||
|
||||
// Connect touchscreens
|
||||
#define MAX_TOUCHSCREENS 1
|
||||
char touchscreens[MAX_TOUCHSCREENS][32] = { "" };
|
||||
char *touchscreens[MAX_TOUCHSCREENS] = { NULL };
|
||||
lv_indev_drv_t touchscreen_indev_drvs[MAX_TOUCHSCREENS];
|
||||
lv_indev_t *touchscreen_indevs[MAX_TOUCHSCREENS] = { 0 };
|
||||
int num_touchscreens = libinput_discover_touchscreens(touchscreens, MAX_TOUCHSCREENS);
|
||||
lv_indev_t *touchscreen_indevs[MAX_TOUCHSCREENS] = { NULL };
|
||||
size_t num_touchscreens = libinput_find_devs(LIBINPUT_CAPABILITY_TOUCH, touchscreens, MAX_TOUCHSCREENS, false);
|
||||
for (int i = 0; i < num_touchscreens; ++i) {
|
||||
printf("found touchscreen %s\n", touchscreens[i]);
|
||||
lv_indev_drv_init(&touchscreen_indev_drvs[i]);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue