summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2018-05-03 22:17:24 +1000
committerMaxime Coste <mawww@kakoune.org>2018-05-03 22:27:59 +1000
commitc2637f08d95b03fbe6db5b0f98b28c2a54fd4126 (patch)
treed19e1bea508115b856ab273ba5fd2a59b127c2f0
parenta19ce3763468879df0548d6c803e54f8fd1a13cc (diff)
JsonUI: Add support for a "mouse" RPC calls from the UI
As discussed on issue #2019
-rw-r--r--doc/json_ui.asciidoc3
-rw-r--r--src/json_ui.cc20
2 files changed, 23 insertions, 0 deletions
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<String>();
+ const Codepoint coord = encode_coord({params[1].as<int>(), params[2].as<int>()});
+ 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)