summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEnrico Zandomeni Borba <enricozb@gmail.com>2024-08-04 09:16:15 +0200
committerEnrico Zandomeni Borba <enricozb@gmail.com>2024-08-04 17:40:29 +0200
commit7093f142916d1e6887432dfd88697a1c2ed1b004 (patch)
tree527df8c4b4bf1adde97a730665baad99457dde8c
parent10ed78fe8a580b3558348746ee53f81c5b0aeae1 (diff)
add scroll coordinates
adds scroll amount in the upper 16-bits of `Key.modifiers`, reclaiming the space in `Key.key` for coordinates. Previously, while mouse events included their coordinates, scrolling did not. Scroll events are now emitted as <scroll:amount:line.column>.
-rw-r--r--src/keys.cc3
-rw-r--r--src/keys.hh1
-rw-r--r--src/terminal_ui.cc9
3 files changed, 7 insertions, 6 deletions
diff --git a/src/keys.cc b/src/keys.cc
index 5ba44181..ad66658a 100644
--- a/src/keys.cc
+++ b/src/keys.cc
@@ -7,6 +7,7 @@
#include "utf8_iterator.hh"
#include "utils.hh"
#include "string_utils.hh"
+#include "terminal_ui.hh"
namespace Kakoune
{
@@ -196,7 +197,7 @@ String to_string(Key key)
else if (key.modifiers & Key::Modifiers::MouseRelease)
res = format("mouse:release:{}:{}.{}", key.mouse_button(), coord.line, coord.column);
else if (key.modifiers & Key::Modifiers::Scroll)
- res = format("scroll:{}", static_cast<int>(key.key));
+ res = format("scroll:{}:{}.{}", key.scroll_amount(), coord.line, coord.column);
else if (key.modifiers & Key::Modifiers::Resize)
res = format("resize:{}.{}", coord.line, coord.column);
else
diff --git a/src/keys.hh b/src/keys.hh
index ccafe336..b4796ea5 100644
--- a/src/keys.hh
+++ b/src/keys.hh
@@ -91,6 +91,7 @@ struct Key
constexpr DisplayCoord coord() const { return {(int)((key & 0xFFFF0000) >> 16), (int)(key & 0x0000FFFF)}; }
constexpr MouseButton mouse_button() { return MouseButton{((int)modifiers & (int)Modifiers::MouseButtonMask) >> 6}; }
+ constexpr int scroll_amount() { return (int)modifiers >> 16; }
static Modifiers to_modifier(MouseButton button) { return Key::Modifiers{((int)button << 6) & (int)Modifiers::MouseButtonMask}; }
Optional<Codepoint> codepoint() const;
diff --git a/src/terminal_ui.cc b/src/terminal_ui.cc
index 33574e90..01afab48 100644
--- a/src/terminal_ui.cc
+++ b/src/terminal_ui.cc
@@ -798,9 +798,8 @@ Optional<Key> TerminalUI::get_next_key()
return Key{mod | Key::to_modifier(button), coord};
};
- auto mouse_scroll = [this](Key::Modifiers mod, bool down) -> Key {
- return {mod | Key::Modifiers::Scroll,
- (Codepoint)((down ? 1 : -1) * m_wheel_scroll_amount)};
+ auto mouse_scroll = [this](Key::Modifiers mod, Codepoint coord, bool down) -> Key {
+ return {mod | Key::Modifiers::Scroll | (Key::Modifiers)((down ? m_wheel_scroll_amount : -1 * m_wheel_scroll_amount) << 16), coord};
};
auto masked_key = [&](Codepoint key, Codepoint shifted_key = 0) {
@@ -921,8 +920,8 @@ Optional<Key> TerminalUI::get_next_key()
else if (int guess = ffs(m_mouse_state) - 1; 0 <= guess and guess < 3)
return mouse_button(mod, Key::MouseButton{guess}, coord, true);
break;
- case 64: return mouse_scroll(mod, false);
- case 65: return mouse_scroll(mod, true);
+ case 64: return mouse_scroll(mod, coord, false);
+ case 65: return mouse_scroll(mod, coord, true);
}
return Key{Key::Modifiers::MousePos, coord};
}