diff --git a/CMakeLists.txt b/CMakeLists.txt index 8554391..4cd8fb0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,6 +22,7 @@ find_package(Freescale) find_package(PkgConfig REQUIRED) pkg_check_modules(EVDEV REQUIRED libevdev) pkg_check_modules(AVAHI REQUIRED avahi-client) +pkg_check_modules(UDEV REQUIRED libudev) if(BROADCOM_FOUND) aux_source_directory(./ilclient SRC_LIST) @@ -45,5 +46,5 @@ elseif(FREESCALE_FOUND) target_link_libraries (moonlight PUBLIC ${FREESCALE_LIBRARIES}) endif() -include_directories(./moonlight-common-c ${OPUS_INCLUDE_DIRS} ${EVDEV_INCLUDE_DIRS} ${AVAHI_INCLUDE_DIRS}) -target_link_libraries (moonlight PUBLIC ${CMAKE_THREAD_LIBS_INIT} ${CURL_LIBRARIES} ${OPENSSL_LIBRARIES} ${EXPAT_LIBRARIES} ${EVDEV_LIBRARIES} ${ALSA_LIBRARY} ${OPUS_LIBRARY} ${AVAHI_LIBRARIES}) +include_directories(./moonlight-common-c ${OPUS_INCLUDE_DIRS} ${EVDEV_INCLUDE_DIRS} ${AVAHI_INCLUDE_DIRS} ${UDEV_INCLUDE_DIRS}) +target_link_libraries (moonlight PUBLIC ${CMAKE_THREAD_LIBS_INIT} ${CURL_LIBRARIES} ${OPENSSL_LIBRARIES} ${EXPAT_LIBRARIES} ${EVDEV_LIBRARIES} ${ALSA_LIBRARY} ${OPUS_LIBRARY} ${AVAHI_LIBRARIES} ${UDEV_LIBRARIES}) diff --git a/src/input.c b/src/input.c index e0dc040..24a9073 100644 --- a/src/input.c +++ b/src/input.c @@ -23,6 +23,7 @@ #include "libevdev/libevdev.h" #include "limelight-common/Limelight.h" +#include #include #include #include @@ -93,8 +94,8 @@ void input_create(char* device, char* mapFile) { devices[dev].fd = open(device, O_RDONLY|O_NONBLOCK); if (devices[dev].fd <= 0) { - fprintf(stderr, "Failed to open device\n"); - exit(EXIT_FAILURE); + fprintf(stderr, "Failed to open device %s\n", device); + return; } devices[dev].dev = libevdev_new(); @@ -116,6 +117,35 @@ void input_create(char* device, char* mapFile) { input_init_parms(&devices[dev], &(devices[dev].dpadyParms), devices[dev].map.abs_dpad_y); } +void input_autoload(char* mapfile) { + struct udev *udev = udev_new(); + if (!udev) { + fprintf(stderr, "Can't create udev\n"); + exit(1); + } + + struct udev_enumerate *enumerate = udev_enumerate_new(udev); + udev_enumerate_add_match_subsystem(enumerate, "input"); + udev_enumerate_scan_devices(enumerate); + struct udev_list_entry *devices = udev_enumerate_get_list_entry(enumerate); + + struct udev_list_entry *dev_list_entry; + udev_list_entry_foreach(dev_list_entry, devices) { + const char *path = udev_list_entry_get_name(dev_list_entry); + struct udev_device *dev = udev_device_new_from_syspath(udev, path); + const char *devnode = udev_device_get_devnode(dev); + int id; + if (devnode != NULL && sscanf(devnode, "/dev/input/event%d", &id) == 1) { + input_create(devnode, mapfile); + } + udev_device_unref(dev); + } + + udev_enumerate_unref(enumerate); + + udev_unref(udev); +} + static short input_convert_value(struct input_event *ev, struct input_device *dev, struct input_abs_parms *parms, bool reverse) { if (abs(ev->value - parms->avg) < parms->flat) return 0; diff --git a/src/input.h b/src/input.h index 6ab5014..c44f6b4 100644 --- a/src/input.h +++ b/src/input.h @@ -17,6 +17,7 @@ * along with Moonlight; if not, see . */ +void input_autoload(char* mapfile); void input_create(char* device, char* mapFile); void input_loop(); void input_map(char* fileName); diff --git a/src/main.c b/src/main.c index 78504ae..738e920 100644 --- a/src/main.c +++ b/src/main.c @@ -122,6 +122,7 @@ int main(int argc, char* argv[]) { char* action = NULL; char* address = NULL; char* mapping = NULL; + bool inputs = false; int option_index = 0; bool sops = true; bool localaudio = false; @@ -159,6 +160,7 @@ int main(int argc, char* argv[]) { break; case 'j': input_create(optarg, mapping); + inputs = true; break; case 'k': mapping = optarg; @@ -209,6 +211,10 @@ int main(int argc, char* argv[]) { } } + if (!inputs) { + input_autoload(mapping); + } + client_init(address); if (strcmp("applist", action) == 0)