handle an update to the event stream This returns OK(()) if all keys are handled by the handlers and an Err(()) otherwise. that way the down stream can decide what to do (tests: panic. Firmare/MatrixToStream -> drop unhandled events)
(&mut self)
| 145 | /// that way the down stream can decide what to do |
| 146 | /// (tests: panic. Firmare/MatrixToStream -> drop unhandled events) |
| 147 | pub fn handle_keys(&mut self) -> Result<(), ()> { |
| 148 | for (_e, status) in self.events.iter_mut() { |
| 149 | *status = EventStatus::Unhandled; |
| 150 | } |
| 151 | //skip the modifiers |
| 152 | for (ii, h) in self.handlers.iter_mut().enumerate() { |
| 153 | if self.output.state().modifiers_and_enabled_handlers[ii + KEYBOARD_STATE_RESERVED_BITS] |
| 154 | { |
| 155 | match h.process_keys(&mut self.events, &mut self.output) { |
| 156 | HandlerResult::NoOp => {} |
| 157 | HandlerResult::Disable => { |
| 158 | self.output |
| 159 | .state() |
| 160 | .disable_handler((ii + KEYBOARD_STATE_RESERVED_BITS) as HandlerID); |
| 161 | } |
| 162 | } |
| 163 | if self.output.state()._aborted() { |
| 164 | self.output.state()._clear_abort(); |
| 165 | self.events.clear(); |
| 166 | break; // no more handlers being done |
| 167 | } |
| 168 | } |
| 169 | } |
| 170 | // remove handled & timeout events. |
| 171 | self.events.drain_filter(|(event, status)| { |
| 172 | (EventStatus::Handled == *status) |
| 173 | || (match event { |
| 174 | Event::TimeOut(_) => true, |
| 175 | _ => false, |
| 176 | }) |
| 177 | }); |
| 178 | if self |
| 179 | .events |
| 180 | .iter() |
| 181 | .any(|(_e, status)| EventStatus::Unhandled == *status) |
| 182 | { |
| 183 | return Err(()); |
| 184 | } |
| 185 | Ok(()) |
| 186 | } |
| 187 | //throw away unhandled key events |
| 188 | pub fn clear_unhandled(&mut self) { |
| 189 | self.events |