From 65ab987a8717937ce31cd24cf1b4b5af831b6bf0 Mon Sep 17 00:00:00 2001 From: June Tate-Gans Date: Sun, 25 Apr 2021 14:32:24 -0500 Subject: [PATCH] g13d: Simplify G13_Action_Keys::act Migrate to C++11 iteration and clean up the mess of code that this was originally with a single call to send_event and a proper use of a ternary for logging. --- g13d/g13.cc | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/g13d/g13.cc b/g13d/g13.cc index c72801d..fde41a4 100644 --- a/g13d/g13.cc +++ b/g13d/g13.cc @@ -405,16 +405,9 @@ G13_Action_Keys::G13_Action_Keys(G13_Device &keypad, G13_Action_Keys::~G13_Action_Keys() {} void G13_Action_Keys::act(G13_Device &g13, bool is_down) { - if (is_down) { - for (int i = 0; i < _keys.size(); i++) { - g13.send_event(EV_KEY, _keys[i], is_down); - G13_LOG(trace, "sending KEY DOWN " << _keys[i]); - } - } else { - for (int i = _keys.size() - 1; i >= 0; i--) { - g13.send_event(EV_KEY, _keys[i], is_down); - G13_LOG(trace, "sending KEY UP " << _keys[i]); - } + for (auto key : _keys) { + g13.send_event(EV_KEY, key, is_down); + G13_LOG(trace, "sending KEY " << (is_down ? "DOWN " : "UP ") << key); } }