From f904402486e98fa2cfbac626f1d149db038110f6 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Thu, 6 Oct 2016 23:47:44 +0100 Subject: [PATCH] Handle all available keys when a RemoteClient input is available We were just treating the next key. Which led to byte remaining after suspend, that led that being interpretted as when the following key got available. Fixes #739 --- src/remote.cc | 13 +++++++------ src/remote.hh | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/remote.cc b/src/remote.cc index 427f52b2..9de0a13a 100644 --- a/src/remote.cc +++ b/src/remote.cc @@ -518,7 +518,7 @@ RemoteClient::RemoteClient(StringView session, std::unique_ptr&& msg.write(env_vars); } - m_ui->set_input_callback([this](EventMode){ write_next_key(); }); + m_ui->set_input_callback([this](EventMode){ send_available_keys(); }); MsgReader reader; m_socket_watcher.reset(new FDWatcher{sock, [this, reader](FDWatcher& watcher, EventMode) mutable { @@ -589,12 +589,13 @@ RemoteClient::RemoteClient(StringView session, std::unique_ptr&& }}); } -void RemoteClient::write_next_key() +void RemoteClient::send_available_keys() { - MsgWriter msg(m_socket_watcher->fd(), MessageType::Key); - // do that before checking dimensions as get_key may - // handle a resize event. - msg.write(m_ui->get_key()); + while (m_ui->is_key_available()) + { + MsgWriter msg(m_socket_watcher->fd(), MessageType::Key); + msg.write(m_ui->get_key()); + } } void send_command(StringView session, StringView command) diff --git a/src/remote.hh b/src/remote.hh index 5740def9..5537e3fd 100644 --- a/src/remote.hh +++ b/src/remote.hh @@ -37,7 +37,7 @@ public: const EnvVarMap& env_vars, StringView init_command); private: - void write_next_key(); + void send_available_keys(); std::unique_ptr m_ui; std::unique_ptr m_socket_watcher;