diff options
Diffstat (limited to '')
-rw-r--r-- | minui/Android.mk | 7 | ||||
-rw-r--r-- | minui/events.cpp | 51 | ||||
-rw-r--r-- | minui/graphics_adf.cpp | 3 | ||||
-rw-r--r-- | minui/include/minui/minui.h | 5 | ||||
-rw-r--r-- | minui/resources.cpp | 2 |
5 files changed, 55 insertions, 13 deletions
diff --git a/minui/Android.mk b/minui/Android.mk index 8df5a4914..cb56b739a 100644 --- a/minui/Android.mk +++ b/minui/Android.mk @@ -51,8 +51,11 @@ ifeq ($(TW_NEW_ION_HEAP), true) endif LOCAL_STATIC_LIBRARIES += libpng -LOCAL_WHOLE_STATIC_LIBRARIES += \ - libdrm +ifneq ($(wildcard external/libdrm/Android.common.mk),) +LOCAL_WHOLE_STATIC_LIBRARIES += libdrm_platform +else +LOCAL_WHOLE_STATIC_LIBRARIES += libdrm +endif ifeq ($(shell test $(PLATFORM_SDK_VERSION) -ge 26; echo $$?),0) LOCAL_CFLAGS += -DHAS_LIBSYNC LOCAL_WHOLE_STATIC_LIBRARIES += libsync_recovery diff --git a/minui/events.cpp b/minui/events.cpp index 470a17a69..e9383ca8a 100644 --- a/minui/events.cpp +++ b/minui/events.cpp @@ -57,40 +57,47 @@ static bool test_bit(size_t bit, unsigned long* array) { // NOLINT return (array[bit/BITS_PER_LONG] & (1UL << (bit % BITS_PER_LONG))) != 0; } +#ifdef TW_USE_MINUI_WITH_OPTIONAL_TOUCH_EVENTS +int ev_init(ev_callback input_cb, bool allow_touch_inputs) { +#else #ifdef TW_USE_MINUI_WITH_DATA int ev_init(ev_callback input_cb, void* data) { #else int ev_init(ev_callback input_cb) { #endif - bool epollctlfail = false; + bool allow_touch_inputs = false; +#endif g_epoll_fd = epoll_create(MAX_DEVICES + MAX_MISC_FDS); if (g_epoll_fd == -1) { return -1; } + bool epollctlfail = false; DIR* dir = opendir("/dev/input"); - if (dir != NULL) { + if (dir != nullptr) { dirent* de; while ((de = readdir(dir))) { - // Use unsigned long to match ioctl's parameter type. - unsigned long ev_bits[BITS_TO_LONGS(EV_MAX)]; // NOLINT - - // fprintf(stderr,"/dev/input/%s\n", de->d_name); if (strncmp(de->d_name, "event", 5)) continue; int fd = openat(dirfd(dir), de->d_name, O_RDONLY); if (fd == -1) continue; + // Use unsigned long to match ioctl's parameter type. + unsigned long ev_bits[BITS_TO_LONGS(EV_MAX)]; // NOLINT + // Read the evbits of the input device. if (ioctl(fd, EVIOCGBIT(0, sizeof(ev_bits)), ev_bits) == -1) { close(fd); continue; } - // We assume that only EV_KEY, EV_REL, and EV_SW event types are ever needed. + // We assume that only EV_KEY, EV_REL, and EV_SW event types are ever needed. EV_ABS is also + // allowed if allow_touch_inputs is set. if (!test_bit(EV_KEY, ev_bits) && !test_bit(EV_REL, ev_bits) && !test_bit(EV_SW, ev_bits)) { - close(fd); - continue; + if (!allow_touch_inputs || !test_bit(EV_ABS, ev_bits)) { + close(fd); + continue; + } } epoll_event ev; @@ -261,3 +268,29 @@ void ev_iterate_available_keys(const std::function<void(int)>& f) { } } } + +#ifdef TW_USE_MINUI_WITH_OPTIONAL_TOUCH_EVENTS +void ev_iterate_touch_inputs(const std::function<void(int)>& action) { + for (size_t i = 0; i < ev_dev_count; ++i) { + // Use unsigned long to match ioctl's parameter type. + unsigned long ev_bits[BITS_TO_LONGS(EV_MAX)] = {}; // NOLINT + if (ioctl(ev_fdinfo[i].fd, EVIOCGBIT(0, sizeof(ev_bits)), ev_bits) == -1) { + continue; + } + if (!test_bit(EV_ABS, ev_bits)) { + continue; + } + + unsigned long key_bits[BITS_TO_LONGS(KEY_MAX)] = {}; // NOLINT + if (ioctl(ev_fdinfo[i].fd, EVIOCGBIT(EV_ABS, KEY_MAX), key_bits) == -1) { + continue; + } + + for (int key_code = 0; key_code <= KEY_MAX; ++key_code) { + if (test_bit(key_code, key_bits)) { + action(key_code); + } + } + } +} +#endif diff --git a/minui/graphics_adf.cpp b/minui/graphics_adf.cpp index 79f4db8b5..72b563b42 100644 --- a/minui/graphics_adf.cpp +++ b/minui/graphics_adf.cpp @@ -30,7 +30,8 @@ #include "minui/minui.h" -MinuiBackendAdf::MinuiBackendAdf() : intf_fd(-1), dev(), n_surfaces(0), surfaces() {} +MinuiBackendAdf::MinuiBackendAdf() + : intf_fd(-1), dev(), current_surface(0), n_surfaces(0), surfaces() {} int MinuiBackendAdf::SurfaceInit(const drm_mode_modeinfo* mode, GRSurfaceAdf* surf) { *surf = {}; diff --git a/minui/include/minui/minui.h b/minui/include/minui/minui.h index 766b943ff..bd8c3865d 100644 --- a/minui/include/minui/minui.h +++ b/minui/include/minui/minui.h @@ -91,7 +91,12 @@ int ev_sync_key_state(ev_set_key_callback set_key_cb, void* data); using ev_callback = std::function<int(int fd, uint32_t epevents)>; using ev_set_key_callback = std::function<int(int code, int value)>; +#ifdef TW_USE_MINUI_WITH_OPTIONAL_TOUCH_EVENTS +int ev_init(ev_callback input_cb, bool allow_touch_inputs = false); +void ev_iterate_touch_inputs(const std::function<void(int)>& action); +#else int ev_init(ev_callback input_cb); +#endif int ev_add_fd(int fd, ev_callback cb); int ev_sync_key_state(const ev_set_key_callback& set_key_cb); #endif diff --git a/minui/resources.cpp b/minui/resources.cpp index 026e1dc2b..b9797b905 100644 --- a/minui/resources.cpp +++ b/minui/resources.cpp @@ -56,7 +56,7 @@ static int open_png(const char* name, png_structp* png_ptr, png_infop* info_ptr, snprintf(resPath, sizeof(resPath)-1, "/res/images/%s.png", name); resPath[sizeof(resPath)-1] = '\0'; - FILE* fp = fopen(resPath, "rb"); + FILE* fp = fopen(resPath, "rbe"); if (fp == NULL) { result = -1; goto exit; |