parent
a2e90c2c25
commit
0755366cb1
|
@ -73,6 +73,8 @@ void Client::handle_available_input(EventMode mode)
|
||||||
context().hooks().run_hook("FocusIn", context().name(), context());
|
context().hooks().run_hook("FocusIn", context().name(), context());
|
||||||
else if (*key == Key::FocusOut)
|
else if (*key == Key::FocusOut)
|
||||||
context().hooks().run_hook("FocusOut", context().name(), context());
|
context().hooks().run_hook("FocusOut", context().name(), context());
|
||||||
|
else if (key->modifiers == Key::Modifiers::Resize)
|
||||||
|
force_redraw();
|
||||||
else
|
else
|
||||||
m_input_handler.handle_key(*key);
|
m_input_handler.handle_key(*key);
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,7 +78,7 @@ struct MouseHandler
|
||||||
{
|
{
|
||||||
case Key::Modifiers::MousePress:
|
case Key::Modifiers::MousePress:
|
||||||
m_dragging = true;
|
m_dragging = true;
|
||||||
m_anchor = context.window().buffer_coord(key.mouse_coord());
|
m_anchor = context.window().buffer_coord(key.coord());
|
||||||
context.selections_write_only() = SelectionList{ buffer, m_anchor };
|
context.selections_write_only() = SelectionList{ buffer, m_anchor };
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
@ -86,7 +86,7 @@ struct MouseHandler
|
||||||
if (not m_dragging)
|
if (not m_dragging)
|
||||||
return true;
|
return true;
|
||||||
m_dragging = false;
|
m_dragging = false;
|
||||||
cursor = context.window().buffer_coord(key.mouse_coord());
|
cursor = context.window().buffer_coord(key.coord());
|
||||||
context.selections_write_only() =
|
context.selections_write_only() =
|
||||||
SelectionList{ buffer, Selection{buffer.clamp(m_anchor), cursor} };
|
SelectionList{ buffer, Selection{buffer.clamp(m_anchor), cursor} };
|
||||||
return true;
|
return true;
|
||||||
|
@ -94,7 +94,7 @@ struct MouseHandler
|
||||||
case Key::Modifiers::MousePos:
|
case Key::Modifiers::MousePos:
|
||||||
if (not m_dragging)
|
if (not m_dragging)
|
||||||
return true;
|
return true;
|
||||||
cursor = context.window().buffer_coord(key.mouse_coord());
|
cursor = context.window().buffer_coord(key.coord());
|
||||||
context.selections_write_only() =
|
context.selections_write_only() =
|
||||||
SelectionList{ buffer, Selection{buffer.clamp(m_anchor), cursor} };
|
SelectionList{ buffer, Selection{buffer.clamp(m_anchor), cursor} };
|
||||||
return true;
|
return true;
|
||||||
|
|
18
src/keys.hh
18
src/keys.hh
|
@ -27,6 +27,8 @@ struct Key
|
||||||
MouseWheelUp = 1 << 6,
|
MouseWheelUp = 1 << 6,
|
||||||
MouseEvent = MousePress | MouseRelease | MousePos |
|
MouseEvent = MousePress | MouseRelease | MousePos |
|
||||||
MouseWheelDown | MouseWheelUp,
|
MouseWheelDown | MouseWheelUp,
|
||||||
|
|
||||||
|
Resize = 1 << 7,
|
||||||
};
|
};
|
||||||
enum NamedKey : Codepoint
|
enum NamedKey : Codepoint
|
||||||
{
|
{
|
||||||
|
@ -75,7 +77,7 @@ struct Key
|
||||||
constexpr bool operator!=(Key other) const { return val() != other.val(); }
|
constexpr bool operator!=(Key other) const { return val() != other.val(); }
|
||||||
constexpr bool operator<(Key other) const { return val() < other.val(); }
|
constexpr bool operator<(Key other) const { return val() < other.val(); }
|
||||||
|
|
||||||
constexpr CharCoord mouse_coord() const { return {(int)((key & 0xFFFF0000) >> 16), (int)(key & 0x0000FFFF)}; }
|
constexpr CharCoord coord() const { return {(int)((key & 0xFFFF0000) >> 16), (int)(key & 0x0000FFFF)}; }
|
||||||
|
|
||||||
Optional<Codepoint> codepoint() const;
|
Optional<Codepoint> codepoint() const;
|
||||||
};
|
};
|
||||||
|
@ -94,13 +96,15 @@ constexpr Key alt(Codepoint key) { return { Key::Modifiers::Alt, key }; }
|
||||||
constexpr Key ctrl(Codepoint key) { return { Key::Modifiers::Control, key }; }
|
constexpr Key ctrl(Codepoint key) { return { Key::Modifiers::Control, key }; }
|
||||||
constexpr Key ctrlalt(Codepoint key) { return { Key::Modifiers::ControlAlt, key }; }
|
constexpr Key ctrlalt(Codepoint key) { return { Key::Modifiers::ControlAlt, key }; }
|
||||||
|
|
||||||
constexpr Codepoint encode_mouse_coord(CharCoord coord) { return (Codepoint)(((int)coord.line << 16) | ((int)coord.column & 0x0000FFFF)); }
|
constexpr Codepoint encode_coord(CharCoord coord) { return (Codepoint)(((int)coord.line << 16) | ((int)coord.column & 0x0000FFFF)); }
|
||||||
|
|
||||||
constexpr Key mouse_press(CharCoord pos) { return { Key::Modifiers::MousePress, encode_mouse_coord(pos) }; }
|
constexpr Key mouse_press(CharCoord pos) { return { Key::Modifiers::MousePress, encode_coord(pos) }; }
|
||||||
constexpr Key mouse_release(CharCoord pos) { return { Key::Modifiers::MouseRelease, encode_mouse_coord(pos) }; }
|
constexpr Key mouse_release(CharCoord pos) { return { Key::Modifiers::MouseRelease, encode_coord(pos) }; }
|
||||||
constexpr Key mouse_pos(CharCoord pos) { return { Key::Modifiers::MousePos, encode_mouse_coord(pos) }; }
|
constexpr Key mouse_pos(CharCoord pos) { return { Key::Modifiers::MousePos, encode_coord(pos) }; }
|
||||||
constexpr Key mouse_wheel_down(CharCoord pos) { return { Key::Modifiers::MouseWheelDown, encode_mouse_coord(pos) }; }
|
constexpr Key mouse_wheel_down(CharCoord pos) { return { Key::Modifiers::MouseWheelDown, encode_coord(pos) }; }
|
||||||
constexpr Key mouse_wheel_up(CharCoord pos) { return { Key::Modifiers::MouseWheelUp, encode_mouse_coord(pos) }; }
|
constexpr Key mouse_wheel_up(CharCoord pos) { return { Key::Modifiers::MouseWheelUp, encode_coord(pos) }; }
|
||||||
|
|
||||||
|
constexpr Key resize(CharCoord dim) { return { Key::Modifiers::Resize, encode_coord(dim) }; }
|
||||||
|
|
||||||
inline size_t hash_value(const Key& key) { return hash_values(key.modifiers, key.key); }
|
inline size_t hash_value(const Key& key) { return hash_values(key.modifiers, key.key); }
|
||||||
|
|
||||||
|
|
|
@ -542,6 +542,7 @@ Key NCursesUI::get_key()
|
||||||
case KEY_HOME: return Key::Home;
|
case KEY_HOME: return Key::Home;
|
||||||
case KEY_END: return Key::End;
|
case KEY_END: return Key::End;
|
||||||
case KEY_BTAB: return Key::BackTab;
|
case KEY_BTAB: return Key::BackTab;
|
||||||
|
case KEY_RESIZE: return resize(m_dimensions);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < 12; ++i)
|
for (int i = 0; i < 12; ++i)
|
||||||
|
|
|
@ -401,11 +401,8 @@ Key RemoteUI::get_key()
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Key key = read<Key>(m_socket_watcher.fd());
|
Key key = read<Key>(m_socket_watcher.fd());
|
||||||
if (key.modifiers == resize_modifier)
|
if (key.modifiers == Key::Modifiers::Resize)
|
||||||
{
|
m_dimensions = key.coord();
|
||||||
m_dimensions = { (int)(key.key >> 16), (int)(key.key & 0xFFFF) };
|
|
||||||
return Key::Invalid;
|
|
||||||
}
|
|
||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
catch (peer_disconnected&)
|
catch (peer_disconnected&)
|
||||||
|
@ -449,7 +446,7 @@ static int connect_to(StringView session)
|
||||||
|
|
||||||
RemoteClient::RemoteClient(StringView session, std::unique_ptr<UserInterface>&& ui,
|
RemoteClient::RemoteClient(StringView session, std::unique_ptr<UserInterface>&& ui,
|
||||||
const EnvVarMap& env_vars, StringView init_command)
|
const EnvVarMap& env_vars, StringView init_command)
|
||||||
: m_ui(std::move(ui)), m_dimensions(m_ui->dimensions())
|
: m_ui(std::move(ui))
|
||||||
{
|
{
|
||||||
int sock = connect_to(session);
|
int sock = connect_to(session);
|
||||||
|
|
||||||
|
@ -458,10 +455,6 @@ RemoteClient::RemoteClient(StringView session, std::unique_ptr<UserInterface>&&
|
||||||
msg.write(init_command.data(), (int)init_command.length());
|
msg.write(init_command.data(), (int)init_command.length());
|
||||||
msg.write((char)0);
|
msg.write((char)0);
|
||||||
msg.write(env_vars);
|
msg.write(env_vars);
|
||||||
|
|
||||||
Key key{ resize_modifier, Codepoint(((int)m_dimensions.line << 16) |
|
|
||||||
(int)m_dimensions.column) };
|
|
||||||
msg.write(key);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m_ui->set_input_callback([this](EventMode){ write_next_key(); });
|
m_ui->set_input_callback([this](EventMode){ write_next_key(); });
|
||||||
|
@ -548,15 +541,6 @@ void RemoteClient::write_next_key()
|
||||||
// do that before checking dimensions as get_key may
|
// do that before checking dimensions as get_key may
|
||||||
// handle a resize event.
|
// handle a resize event.
|
||||||
msg.write(m_ui->get_key());
|
msg.write(m_ui->get_key());
|
||||||
|
|
||||||
CharCoord dimensions = m_ui->dimensions();
|
|
||||||
if (dimensions != m_dimensions)
|
|
||||||
{
|
|
||||||
m_dimensions = dimensions;
|
|
||||||
Key key{ resize_modifier, Codepoint(((int)dimensions.line << 16) |
|
|
||||||
(int)dimensions.column) };
|
|
||||||
msg.write(key);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void send_command(StringView session, StringView command)
|
void send_command(StringView session, StringView command)
|
||||||
|
|
|
@ -38,7 +38,6 @@ private:
|
||||||
|
|
||||||
std::unique_ptr<UserInterface> m_ui;
|
std::unique_ptr<UserInterface> m_ui;
|
||||||
std::unique_ptr<FDWatcher> m_socket_watcher;
|
std::unique_ptr<FDWatcher> m_socket_watcher;
|
||||||
CharCoord m_dimensions;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void send_command(StringView session, StringView command);
|
void send_command(StringView session, StringView command);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user