summaryrefslogtreecommitdiffstats
path: root/minui/events.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'minui/events.cpp')
-rw-r--r--minui/events.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/minui/events.cpp b/minui/events.cpp
index 0e1fd44a0..470a17a69 100644
--- a/minui/events.cpp
+++ b/minui/events.cpp
@@ -23,6 +23,7 @@
#include <sys/epoll.h>
#include <sys/ioctl.h>
#include <unistd.h>
+#include <errno.h>
#include <functional>
@@ -37,6 +38,9 @@
struct fd_info {
int fd;
ev_callback cb;
+#ifdef TW_USE_MINUI_WITH_DATA
+ void* data;
+#endif
};
static int g_epoll_fd;
@@ -53,7 +57,11 @@ 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_DATA
+int ev_init(ev_callback input_cb, void* data) {
+#else
int ev_init(ev_callback input_cb) {
+#endif
bool epollctlfail = false;
g_epoll_fd = epoll_create(MAX_DEVICES + MAX_MISC_FDS);
@@ -96,6 +104,9 @@ int ev_init(ev_callback input_cb) {
ev_fdinfo[ev_count].fd = fd;
ev_fdinfo[ev_count].cb = std::move(input_cb);
+#ifdef TW_USE_MINUI_WITH_DATA
+ ev_fdinfo[ev_count].data = data;
+#endif
ev_count++;
ev_dev_count++;
if (ev_dev_count == MAX_DEVICES) break;
@@ -117,7 +128,11 @@ int ev_get_epollfd(void) {
return g_epoll_fd;
}
+#ifdef TW_USE_MINUI_WITH_DATA
+int ev_add_fd(int fd, ev_callback cb, void* data) {
+#else
int ev_add_fd(int fd, ev_callback cb) {
+#endif
if (ev_misc_count == MAX_MISC_FDS || cb == NULL) {
return -1;
}
@@ -129,6 +144,9 @@ int ev_add_fd(int fd, ev_callback cb) {
if (!ret) {
ev_fdinfo[ev_count].fd = fd;
ev_fdinfo[ev_count].cb = std::move(cb);
+#ifdef TW_USE_MINUI_WITH_DATA
+ ev_fdinfo[ev_count].data = data;
+#endif
ev_count++;
ev_misc_count++;
}
@@ -158,7 +176,11 @@ void ev_dispatch(void) {
fd_info* fdi = static_cast<fd_info*>(polledevents[n].data.ptr);
const ev_callback& cb = fdi->cb;
if (cb) {
+#ifdef TW_USE_MINUI_WITH_DATA
+ cb(fdi->fd, polledevents[n].events, fdi->data);
+#else
cb(fdi->fd, polledevents[n].events);
+#endif
}
}
}
@@ -173,7 +195,11 @@ int ev_get_input(int fd, uint32_t epevents, input_event* ev) {
return -1;
}
+#ifdef TW_USE_MINUI_WITH_DATA
+int ev_sync_key_state(ev_set_key_callback set_key_cb, void* data) {
+#else
int ev_sync_key_state(const ev_set_key_callback& set_key_cb) {
+#endif
// Use unsigned long to match ioctl's parameter type.
unsigned long ev_bits[BITS_TO_LONGS(EV_MAX)]; // NOLINT
unsigned long key_bits[BITS_TO_LONGS(KEY_MAX)]; // NOLINT
@@ -194,7 +220,11 @@ int ev_sync_key_state(const ev_set_key_callback& set_key_cb) {
for (int code = 0; code <= KEY_MAX; code++) {
if (test_bit(code, key_bits)) {
+#ifdef TW_USE_MINUI_WITH_DATA
+ set_key_cb(code, 1, data);
+#else
set_key_cb(code, 1);
+#endif
}
}
}