summaryrefslogtreecommitdiffhomepage
path: root/Touchpad.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Touchpad.cpp')
-rw-r--r--Touchpad.cpp35
1 files changed, 24 insertions, 11 deletions
diff --git a/Touchpad.cpp b/Touchpad.cpp
index 5fe6bf4..3989df7 100644
--- a/Touchpad.cpp
+++ b/Touchpad.cpp
@@ -6,7 +6,7 @@
#include "log.h"
-Touchpad::Touchpad(): m_valid{}
+Touchpad::Touchpad(): m_valid{}, m_ev{}
{
m_fd = open("/dev/input/event0", O_RDONLY | O_NONBLOCK);
int rc = libevdev_new_from_fd(m_fd, &m_dev);
@@ -39,21 +39,34 @@ bool Touchpad::event_available()
if (!m_valid) {
return false;
}
- struct pollfd fds{};
- fds.fd = m_fd;
- fds.events = POLLIN;
- int ret = poll(&fds, 1, 0);
- if (ret == 0)
- return false;
- else if (ret == 1)
+
+ if (m_ev.has_value()) {
return true;
- else
- log_cout << "Error: Touchpad::event_available()" << std::endl;
- return false;
+ }
+
+ input_event ev{};
+ int rc = libevdev_next_event(m_dev, LIBEVDEV_READ_FLAG_NORMAL, &ev);
+ if (rc != 0) {
+ return false;
+ }
+ log_cout << fmt::format("Event: {} {} {}\n",
+ libevdev_event_type_get_name(ev.type),
+ libevdev_event_code_get_name(ev.type, ev.code),
+ ev.value);
+
+ m_ev = ev;
+
+ return true;
}
input_event Touchpad::get_event()
{
+ if (m_ev.has_value()) {
+ input_event result = *m_ev;
+ m_ev.reset();
+ return result;
+ }
+
input_event ev{};
int rc = libevdev_next_event(m_dev, LIBEVDEV_READ_FLAG_NORMAL, &ev);
if (rc != 0) {