JsonUI: Add support for a "mouse" RPC calls from the UI

As discussed on issue #2019
This commit is contained in:
Maxime Coste 2018-05-03 22:17:24 +10:00
parent a19ce37634
commit c2637f08d9
2 changed files with 23 additions and 0 deletions

View File

@ -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.

View File

@ -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)