From 8730ffb4e24992a0d4061aa3d924cb9bba93c292 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Wed, 24 Oct 2018 22:20:58 -0400 Subject: [PATCH] Restores multi-machine keyboard propagation. --- .../Implementation/MultiKeyboardMachine.cpp | 36 +++++++++++++++---- .../Implementation/MultiKeyboardMachine.hpp | 23 +++++++++--- 2 files changed, 48 insertions(+), 11 deletions(-) diff --git a/Analyser/Dynamic/MultiMachine/Implementation/MultiKeyboardMachine.cpp b/Analyser/Dynamic/MultiMachine/Implementation/MultiKeyboardMachine.cpp index 24c666336..f85035be5 100644 --- a/Analyser/Dynamic/MultiMachine/Implementation/MultiKeyboardMachine.cpp +++ b/Analyser/Dynamic/MultiMachine/Implementation/MultiKeyboardMachine.cpp @@ -10,7 +10,8 @@ using namespace Analyser::Dynamic; -MultiKeyboardMachine::MultiKeyboardMachine(const std::vector> &machines) { +MultiKeyboardMachine::MultiKeyboardMachine(const std::vector> &machines) : + keyboard_(machines_) { for(const auto &machine: machines) { KeyboardMachine::Machine *keyboard_machine = machine->keyboard_machine(); if(keyboard_machine) machines_.push_back(keyboard_machine); @@ -39,9 +40,30 @@ Inputs::Keyboard &MultiKeyboardMachine::get_keyboard() { return keyboard_; } -//void MultiKeyboardMachine::keyboard_did_change_key(Inputs::Keyboard *keyboard, Inputs::Keyboard::Key key, bool is_pressed) { -// for(const auto &machine: machines_) { -// uint16_t mapped_key = machine->get_keyboard_mapper()->mapped_key_for_key(key); -// if(mapped_key != KeyNotMapped) machine->set_key_state(mapped_key, is_pressed); -// } -//} +MultiKeyboardMachine::MultiKeyboard::MultiKeyboard(const std::vector<::KeyboardMachine::Machine *> &machines) + : machines_(machines) { + for(const auto &machine: machines_) { + observed_keys_.insert(machine->get_keyboard().observed_keys().begin(), machine->get_keyboard().observed_keys().end()); + is_exclusive_ |= machine->get_keyboard().is_exclusive(); + } +} + +void MultiKeyboardMachine::MultiKeyboard::set_key_pressed(Key key, char value, bool is_pressed) { + for(const auto &machine: machines_) { + machine->get_keyboard().set_key_pressed(key, value, is_pressed); + } +} + +void MultiKeyboardMachine::MultiKeyboard::reset_all_keys() { + for(const auto &machine: machines_) { + machine->get_keyboard().reset_all_keys(); + } +} + +const std::set &MultiKeyboardMachine::MultiKeyboard::observed_keys() { + return observed_keys_; +} + +bool MultiKeyboardMachine::MultiKeyboard::is_exclusive() { + return is_exclusive_; +} diff --git a/Analyser/Dynamic/MultiMachine/Implementation/MultiKeyboardMachine.hpp b/Analyser/Dynamic/MultiMachine/Implementation/MultiKeyboardMachine.hpp index 6a0af3cc7..6675d21de 100644 --- a/Analyser/Dynamic/MultiMachine/Implementation/MultiKeyboardMachine.hpp +++ b/Analyser/Dynamic/MultiMachine/Implementation/MultiKeyboardMachine.hpp @@ -25,6 +25,25 @@ namespace Dynamic { order of delivered messages. */ class MultiKeyboardMachine: public KeyboardMachine::Machine { + private: + std::vector<::KeyboardMachine::Machine *> machines_; + + class MultiKeyboard: public Inputs::Keyboard { + public: + MultiKeyboard(const std::vector<::KeyboardMachine::Machine *> &machines); + + void set_key_pressed(Key key, char value, bool is_pressed) override; + void reset_all_keys() override; + const std::set &observed_keys() override; + bool is_exclusive() override; + + private: + const std::vector<::KeyboardMachine::Machine *> &machines_; + std::set observed_keys_; + bool is_exclusive_ = false; + }; + MultiKeyboard keyboard_; + public: MultiKeyboardMachine(const std::vector> &machines); @@ -33,10 +52,6 @@ class MultiKeyboardMachine: public KeyboardMachine::Machine { void set_key_state(uint16_t key, bool is_pressed) override; void type_string(const std::string &) override; Inputs::Keyboard &get_keyboard() override; - - private: - std::vector<::KeyboardMachine::Machine *> machines_; - Inputs::Keyboard keyboard_; }; }