From c2637f08d95b03fbe6db5b0f98b28c2a54fd4126 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Thu, 3 May 2018 22:17:24 +1000 Subject: [PATCH] JsonUI: Add support for a "mouse" RPC calls from the UI As discussed on issue #2019 --- doc/json_ui.asciidoc | 3 +++ src/json_ui.cc | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/doc/json_ui.asciidoc b/doc/json_ui.asciidoc index f6f9b02f..61407a62 100644 --- a/doc/json_ui.asciidoc +++ b/doc/json_ui.asciidoc @@ -57,3 +57,6 @@ The requests that the json ui can interpret on stdin are: * keys(String key1, String key2...): keystrokes * resize(int rows, int columns): notify ui resize +* mouse(String type, int line, int column): mouse event, type + can be: 'move', 'press', 'release', 'wheel_up', 'wheel_down', + line, column is the cursor position. diff --git a/src/json_ui.cc b/src/json_ui.cc index f58cbbc5..8629395d 100644 --- a/src/json_ui.cc +++ b/src/json_ui.cc @@ -390,6 +390,26 @@ void JsonUI::eval_json(const Value& json) m_on_key(key); } } + else if (method == "mouse") + { + if (params.size() != 3) + throw runtime_error("mouse type/coordinates not specified"); + + const StringView type = params[0].as(); + const Codepoint coord = encode_coord({params[1].as(), params[2].as()}); + if (type == "move") + m_on_key({Key::Modifiers::MousePos, coord}); + else if (type == "press") + m_on_key({Key::Modifiers::MousePress, coord}); + else if (type == "release") + m_on_key({Key::Modifiers::MouseRelease, coord}); + else if (type == "wheel_up") + m_on_key({Key::Modifiers::MouseWheelUp, coord}); + else if (type == "wheel_down") + m_on_key({Key::Modifiers::MouseWheelDown, coord}); + else + throw runtime_error(format("invalid mouse event type: {}", type)); + } else if (method == "resize") { if (params.size() != 2)