summaryrefslogtreecommitdiff
path: root/src/input_handler.cc
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2015-03-22 10:08:44 +0000
committerMaxime Coste <frrrwww@gmail.com>2015-03-22 11:41:20 +0000
commit5eaf472fc0fd0d2e5a76ab91f685ea89018a6d33 (patch)
treeb9fcf32d5be1004248bc5d6c78a6134fdc8e03e0 /src/input_handler.cc
parentdef33de9bc78cb8109034ed5e015b5b39316cd55 (diff)
Experimental support for mouse
Diffstat (limited to 'src/input_handler.cc')
-rw-r--r--src/input_handler.cc47
1 files changed, 46 insertions, 1 deletions
diff --git a/src/input_handler.cc b/src/input_handler.cc
index 08412a02..7b6339ff 100644
--- a/src/input_handler.cc
+++ b/src/input_handler.cc
@@ -49,6 +49,45 @@ namespace InputModes
static constexpr std::chrono::milliseconds idle_timeout{50};
static constexpr std::chrono::milliseconds fs_check_timeout{500};
+struct MouseHandler
+{
+ bool handle_key(Key key, Context& context)
+ {
+ if (not context.has_window())
+ return false;
+
+ if (key.modifiers == Key::Modifiers::MousePress)
+ {
+ m_dragging = true;
+ m_anchor = context.window().buffer_coord(key.mouse_coord());
+ context.selections() = SelectionList{ context.buffer(), m_anchor };
+ return true;
+ }
+ if (key.modifiers == Key::Modifiers::MouseRelease)
+ {
+ if (not m_dragging)
+ return true;
+ m_dragging = false;
+ auto cursor = context.window().buffer_coord(key.mouse_coord());
+ context.selections() = SelectionList{ context.buffer(), Selection{m_anchor, cursor} };
+ return true;
+ }
+ if (key.modifiers == Key::Modifiers::MousePos)
+ {
+ if (not m_dragging)
+ return true;
+ auto cursor = context.window().buffer_coord(key.mouse_coord());
+ context.selections() = SelectionList{ context.buffer(), Selection{m_anchor, cursor} };
+ return true;
+ }
+ return false;
+ }
+
+private:
+ bool m_dragging = false;
+ ByteCoord m_anchor;
+};
+
class Normal : public InputMode
{
public:
@@ -87,6 +126,9 @@ public:
void on_key(Key key) override
{
+ if (m_mouse_handler.handle_key(key, context()))
+ return;
+
if (m_waiting_for_reg)
{
if (key.modifiers == Key::Modifiers::None)
@@ -139,6 +181,7 @@ public:
}
m_params = { 0, '"' };
}
+
context().hooks().run_hook("NormalKey", key_to_str(key), context());
m_idle_timer.set_next_date(Clock::now() + idle_timeout);
}
@@ -167,6 +210,7 @@ private:
bool m_waiting_for_reg = false;
Timer m_idle_timer;
Timer m_fs_check_timer;
+ MouseHandler m_mouse_handler;
};
template<WordType word_type>
@@ -1109,7 +1153,8 @@ void InputHandler::on_next_key(KeymapMode keymap_mode, KeyCallback callback)
static bool is_valid(Key key)
{
- return key != Key::Invalid and key.key <= 0x10FFFF;
+ return key != Key::Invalid and
+ ((key.modifiers & ~Key::Modifiers::ControlAlt) or key.key <= 0x10FFFF);
}
void InputHandler::handle_key(Key key)