diff options
-rw-r--r-- | MainLoop.cpp | 2 | ||||
-rw-r--r-- | Touchpad.cpp | 7 | ||||
-rw-r--r-- | UI.cpp | 4 |
3 files changed, 8 insertions, 5 deletions
diff --git a/MainLoop.cpp b/MainLoop.cpp index 8f3e399..c01ccdb 100644 --- a/MainLoop.cpp +++ b/MainLoop.cpp @@ -141,7 +141,7 @@ int MainLoop::run() m_pcm.write(); } - if (m_ui.key_available()) { + while (m_ui.key_available()) { m_ui.handle_input(); } diff --git a/Touchpad.cpp b/Touchpad.cpp index 073fbde..5fe6bf4 100644 --- a/Touchpad.cpp +++ b/Touchpad.cpp @@ -36,6 +36,9 @@ bool Touchpad::is_valid() bool Touchpad::event_available() { + if (!m_valid) { + return false; + } struct pollfd fds{}; fds.fd = m_fd; fds.events = POLLIN; @@ -65,10 +68,10 @@ input_event Touchpad::get_event() bool Touchpad::event_is_button1(const input_event& ev) { - return ev.type == EV_KEY && ev.code == BTN_LEFT; + return ev.type == EV_KEY && ev.code == BTN_LEFT && ev.value == 0; // Press down } bool Touchpad::event_is_button2(const input_event& ev) { - return ev.type == EV_KEY && ev.code == BTN_RIGHT; + return ev.type == EV_KEY && ev.code == BTN_RIGHT && ev.value == 0; // Press down } @@ -174,7 +174,7 @@ void UI::draw() void UI::handle_input() { // handle console key - if (key_available()) { + if (stdin_available()) { char c; std::cin >> c; @@ -203,7 +203,7 @@ void UI::handle_input() } // handle touchpad - if (m_touchpad.is_valid() && m_touchpad.event_available()) { + if (m_touchpad.event_available()) { input_event ev = m_touchpad.get_event(); if (m_touchpad.event_is_button1(ev)) { |