src: Add support for right click events
The current implementation treats left mouse button clicks as a generic "mouse press" modifier, this commit extends the list of modifiers by adding a "right mouse click" one. The proper way to implement this would be to ship the coordinates of mouse key press events in each `Key` object, and pass whichever button was clicked as a codepoint value (instead of coordinates currently), but this would require more work. This commit allows: * right clicks to set the cursor of the main selection * control-right clicks to merge all the selections, and then set its cursor Fixes #843
This commit is contained in:
parent
cb798fa369
commit
b1f5639d8c
|
@ -92,9 +92,20 @@ struct MouseHandler
|
||||||
Buffer& buffer = context.buffer();
|
Buffer& buffer = context.buffer();
|
||||||
BufferCoord cursor;
|
BufferCoord cursor;
|
||||||
auto& selections = context.selections();
|
auto& selections = context.selections();
|
||||||
switch ((Key::Modifiers)(key.modifiers & Key::Modifiers::MouseEvent))
|
const auto key_modifier = (Key::Modifiers)(key.modifiers & Key::Modifiers::MouseEvent);
|
||||||
|
switch (key_modifier)
|
||||||
{
|
{
|
||||||
case Key::Modifiers::MousePress:
|
case Key::Modifiers::MousePressRight:
|
||||||
|
m_dragging = false;
|
||||||
|
cursor = context.window().buffer_coord(key.coord());
|
||||||
|
if (key.modifiers & Key::Modifiers::Control)
|
||||||
|
selections = {{selections.begin()->anchor(), cursor}};
|
||||||
|
else
|
||||||
|
selections.main() = {selections.main().anchor(), cursor};
|
||||||
|
selections.sort_and_merge_overlapping();
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case Key::Modifiers::MousePressLeft:
|
||||||
m_dragging = true;
|
m_dragging = true;
|
||||||
m_anchor = context.window().buffer_coord(key.coord());
|
m_anchor = context.window().buffer_coord(key.coord());
|
||||||
if (not (key.modifiers & Key::Modifiers::Control))
|
if (not (key.modifiers & Key::Modifiers::Control))
|
||||||
|
@ -108,7 +119,8 @@ struct MouseHandler
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
case Key::Modifiers::MouseRelease:
|
case Key::Modifiers::MouseReleaseLeft:
|
||||||
|
case Key::Modifiers::MouseReleaseRight:
|
||||||
if (not m_dragging)
|
if (not m_dragging)
|
||||||
return true;
|
return true;
|
||||||
m_dragging = false;
|
m_dragging = false;
|
||||||
|
|
|
@ -424,10 +424,14 @@ void JsonUI::eval_json(const Value& json)
|
||||||
const Codepoint coord = encode_coord({params[1].as<int>(), params[2].as<int>()});
|
const Codepoint coord = encode_coord({params[1].as<int>(), params[2].as<int>()});
|
||||||
if (type == "move")
|
if (type == "move")
|
||||||
m_on_key({Key::Modifiers::MousePos, coord});
|
m_on_key({Key::Modifiers::MousePos, coord});
|
||||||
else if (type == "press")
|
else if (type == "press_left")
|
||||||
m_on_key({Key::Modifiers::MousePress, coord});
|
m_on_key({Key::Modifiers::MousePressLeft, coord});
|
||||||
else if (type == "release")
|
else if (type == "press_right")
|
||||||
m_on_key({Key::Modifiers::MouseRelease, coord});
|
m_on_key({Key::Modifiers::MousePressRight, coord});
|
||||||
|
else if (type == "release_left")
|
||||||
|
m_on_key({Key::Modifiers::MouseReleaseLeft, coord});
|
||||||
|
else if (type == "release_right")
|
||||||
|
m_on_key({Key::Modifiers::MouseReleaseRight, coord});
|
||||||
else if (type == "wheel_up")
|
else if (type == "wheel_up")
|
||||||
m_on_key({Key::Modifiers::MouseWheelUp, coord});
|
m_on_key({Key::Modifiers::MouseWheelUp, coord});
|
||||||
else if (type == "wheel_down")
|
else if (type == "wheel_down")
|
||||||
|
|
12
src/keys.cc
12
src/keys.cc
|
@ -152,10 +152,14 @@ String key_to_str(Key key)
|
||||||
{
|
{
|
||||||
case Key::Modifiers::MousePos:
|
case Key::Modifiers::MousePos:
|
||||||
return format("<mouse:move:{}.{}>", coord.line, coord.column);
|
return format("<mouse:move:{}.{}>", coord.line, coord.column);
|
||||||
case Key::Modifiers::MousePress:
|
case Key::Modifiers::MousePressLeft:
|
||||||
return format("<mouse:press:{}.{}>", coord.line, coord.column);
|
return format("<mouse:press_left:{}.{}>", coord.line, coord.column);
|
||||||
case Key::Modifiers::MouseRelease:
|
case Key::Modifiers::MousePressRight:
|
||||||
return format("<mouse:release:{}.{}>", coord.line, coord.column);
|
return format("<mouse:press_right:{}.{}>", coord.line, coord.column);
|
||||||
|
case Key::Modifiers::MouseReleaseLeft:
|
||||||
|
return format("<mouse:release_left:{}.{}>", coord.line, coord.column);
|
||||||
|
case Key::Modifiers::MouseReleaseRight:
|
||||||
|
return format("<mouse:release_right:{}.{}>", coord.line, coord.column);
|
||||||
case Key::Modifiers::MouseWheelDown:
|
case Key::Modifiers::MouseWheelDown:
|
||||||
return "<mouse:wheel_down>";
|
return "<mouse:wheel_down>";
|
||||||
case Key::Modifiers::MouseWheelUp:
|
case Key::Modifiers::MouseWheelUp:
|
||||||
|
|
21
src/keys.hh
21
src/keys.hh
|
@ -21,16 +21,19 @@ struct Key
|
||||||
Alt = 1 << 1,
|
Alt = 1 << 1,
|
||||||
Shift = 1 << 2,
|
Shift = 1 << 2,
|
||||||
|
|
||||||
MousePress = 1 << 3,
|
MousePressLeft = 1 << 3,
|
||||||
MouseRelease = 1 << 4,
|
MousePressRight = 1 << 4,
|
||||||
MousePos = 1 << 5,
|
MouseReleaseLeft = 1 << 5,
|
||||||
MouseWheelDown = 1 << 6,
|
MouseReleaseRight = 1 << 6,
|
||||||
MouseWheelUp = 1 << 7,
|
MousePos = 1 << 7,
|
||||||
MouseEvent = MousePress | MouseRelease | MousePos |
|
MouseWheelDown = 1 << 8,
|
||||||
MouseWheelDown | MouseWheelUp,
|
MouseWheelUp = 1 << 9,
|
||||||
|
MouseEvent = MousePressLeft | MousePressRight |
|
||||||
|
MouseReleaseLeft | MouseReleaseRight |
|
||||||
|
MousePos | MouseWheelDown | MouseWheelUp,
|
||||||
|
|
||||||
Resize = 1 << 8,
|
Resize = 1 << 10,
|
||||||
MenuSelect = 1 << 10,
|
MenuSelect = 1 << 11,
|
||||||
};
|
};
|
||||||
enum NamedKey : Codepoint
|
enum NamedKey : Codepoint
|
||||||
{
|
{
|
||||||
|
|
|
@ -565,9 +565,13 @@ Optional<Key> NCursesUI::get_next_key()
|
||||||
res |= Key::Modifiers::Alt;
|
res |= Key::Modifiers::Alt;
|
||||||
|
|
||||||
if (BUTTON_PRESS(mask, 1))
|
if (BUTTON_PRESS(mask, 1))
|
||||||
return res | Key::Modifiers::MousePress;
|
return res | Key::Modifiers::MousePressLeft;
|
||||||
|
if (BUTTON_PRESS(mask, 3))
|
||||||
|
return res | Key::Modifiers::MousePressRight;
|
||||||
if (BUTTON_RELEASE(mask, 1))
|
if (BUTTON_RELEASE(mask, 1))
|
||||||
return res | Key::Modifiers::MouseRelease;
|
return res | Key::Modifiers::MouseReleaseLeft;
|
||||||
|
if (BUTTON_RELEASE(mask, 3))
|
||||||
|
return res | Key::Modifiers::MouseReleaseRight;
|
||||||
if (BUTTON_PRESS(mask, m_wheel_down_button))
|
if (BUTTON_PRESS(mask, m_wheel_down_button))
|
||||||
return res | Key::Modifiers::MouseWheelDown;
|
return res | Key::Modifiers::MouseWheelDown;
|
||||||
if (BUTTON_PRESS(mask, m_wheel_up_button))
|
if (BUTTON_PRESS(mask, m_wheel_up_button))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user