Merge remote-tracking branch 'arachsys/mouse-modifiers'
This commit is contained in:
commit
1a5a31cfbf
54
src/keys.cc
54
src/keys.cc
|
@ -184,37 +184,33 @@ Key::MouseButton str_to_button(StringView str)
|
||||||
String to_string(Key key)
|
String to_string(Key key)
|
||||||
{
|
{
|
||||||
const auto coord = key.coord() + DisplayCoord{1,1};
|
const auto coord = key.coord() + DisplayCoord{1,1};
|
||||||
switch (Key::Modifiers(key.modifiers & ~Key::Modifiers::MouseButtonMask))
|
bool named = true;
|
||||||
{
|
|
||||||
case Key::Modifiers::MousePos:
|
|
||||||
return format("<mouse:move:{}.{}>", coord.line, coord.column);
|
|
||||||
case Key::Modifiers::MousePress:
|
|
||||||
return format("<mouse:press:{}:{}.{}>", key.mouse_button(), coord.line, coord.column);
|
|
||||||
case Key::Modifiers::MouseRelease:
|
|
||||||
return format("<mouse:release:{}:{}.{}>", key.mouse_button(), coord.line, coord.column);
|
|
||||||
case Key::Modifiers::Scroll:
|
|
||||||
return format("<scroll:{}>", static_cast<int>(key.key));
|
|
||||||
case Key::Modifiers::Resize:
|
|
||||||
return format("<resize:{}.{}>", coord.line, coord.column);
|
|
||||||
default: break;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool named = false;
|
|
||||||
String res;
|
String res;
|
||||||
auto it = find_if(keynamemap, [&key](const KeyAndName& item)
|
|
||||||
{ return item.key == key.key; });
|
if (key.modifiers & Key::Modifiers::MousePos)
|
||||||
if (it != std::end(keynamemap))
|
res = format("mouse:move:{}.{}", coord.line, coord.column);
|
||||||
{
|
else if (key.modifiers & Key::Modifiers::MousePress)
|
||||||
named = true;
|
res = format("mouse:press:{}:{}.{}", key.mouse_button(), coord.line, coord.column);
|
||||||
res = it->name;
|
else if (key.modifiers & Key::Modifiers::MouseRelease)
|
||||||
}
|
res = format("mouse:release:{}:{}.{}", key.mouse_button(), coord.line, coord.column);
|
||||||
else if (key.key >= Key::F1 and key.key <= Key::F12)
|
else if (key.modifiers & Key::Modifiers::Scroll)
|
||||||
{
|
res = format("scroll:{}", static_cast<int>(key.key));
|
||||||
named = true;
|
else if (key.modifiers & Key::Modifiers::Resize)
|
||||||
res = "F" + to_string((int)(key.key - Key::F1 + 1));
|
res = format("resize:{}.{}", coord.line, coord.column);
|
||||||
}
|
|
||||||
else
|
else
|
||||||
res = String{key.key};
|
{
|
||||||
|
auto it = find_if(keynamemap, [&key](const KeyAndName& item)
|
||||||
|
{ return item.key == key.key; });
|
||||||
|
if (it != std::end(keynamemap))
|
||||||
|
res = it->name;
|
||||||
|
else if (key.key >= Key::F1 and key.key <= Key::F12)
|
||||||
|
res = "F" + to_string((int)(key.key - Key::F1 + 1));
|
||||||
|
else
|
||||||
|
{
|
||||||
|
named = false;
|
||||||
|
res = String{key.key};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (key.modifiers & Key::Modifiers::Shift) { res = "s-" + res; named = true; }
|
if (key.modifiers & Key::Modifiers::Shift) { res = "s-" + res; named = true; }
|
||||||
if (key.modifiers & Key::Modifiers::Alt) { res = "a-" + res; named = true; }
|
if (key.modifiers & Key::Modifiers::Alt) { res = "a-" + res; named = true; }
|
||||||
|
|
Loading…
Reference in New Issue
Block a user