Mouse tracking [wip]

Works with TERM=linux, does not work with TERM=xterm-256color.
Will need to update libtsm to handle mouse events as there is an escape
sequence to turn tracking on/off.
Probably something similar to tsm_vte_handle_keyboard().
This commit is contained in:
Leroy Hopson 2021-07-23 13:03:43 +07:00
parent 5f399ed46e
commit 8269fc90a2
No known key found for this signature in database
GPG key ID: D2747312A6DB51AA
4 changed files with 39 additions and 8 deletions

View file

@ -63,9 +63,10 @@ void Pipe::close() {
uv_run(uv_default_loop(), UV_RUN_NOWAIT);
}
godot_error Pipe::write(String p_data) {
char *s = p_data.alloc_c_string();
ULONG len = strlen(s);
godot_error Pipe::write(PoolByteArray p_data) {
ULONG len = p_data.size();
char *s = (char *)malloc(len);
memcpy(s, p_data.read().ptr(), len);
uv_buf_t bufs[1];
bufs[0].base = s;
@ -113,7 +114,7 @@ void _read_cb(uv_stream_t *handle, ssize_t nread, const uv_buf_t *buf) {
pipe->emit_signal("data_received", data);
}
void _write_cb(uv_write_t *req, int status) {}
void _write_cb(uv_write_t *req, int status) { std::free(req->data); }
void _alloc_buffer(uv_handle_t *handle, size_t suggested_size, uv_buf_t *buf) {
buf->base = (char *)malloc(suggested_size);

View file

@ -26,7 +26,7 @@ public:
void close();
int get_status();
godot_error write(String p_data);
godot_error write(PoolByteArray p_data);
void pause();
void resume();

View file

@ -174,7 +174,9 @@ func write(data) -> void:
_write(data)
func _write(data: String) -> void:
func _write(data) -> void:
assert(data is PoolByteArray or data is String)
data = data if data is PoolByteArray else data.to_utf8()
if _pipe:
_pipe.write(data)

View file

@ -29,8 +29,12 @@ export (UpdateMode) var update_mode = UpdateMode.AUTO setget set_update_mode
var cols = 2
var rows = 2
# Mouse
# If true, text in the terminal will be copied to the clipboard when selected.
export (bool) var copy_on_selection
# If true mouse events will be emitted by the signal when clicking on the Terminal.
export (bool) var mouse_tracking := true
# Bell
# If muted, the "bell" signal will not be emitted when the bell "\u0007" character
@ -160,10 +164,34 @@ func _refresh():
func _gui_input(event):
_native_terminal._gui_input(event)
#_native_terminal._gui_input(event)
if event is InputEventKey:
_native_terminal.sb_reset() # Return to bottom of scrollback buffer if we scrolled up.
pass
_native_terminal._gui_input(event)
#_native_terminal.sb_reset() # Return to bottom of scrollback buffer if we scrolled up.
# Mouse tracking.
# Reference: https://www.xfree86.org/current/ctlseqs.html#Mouse%20Tracking
if mouse_tracking:
if event is InputEventMouseButton:
var b: int
if event.pressed:
if event.button_index == BUTTON_LEFT:
b = 0
if event.button_index == BUTTON_RIGHT:
b = 1
if event.button_index == BUTTON_MIDDLE:
b = 2
else:
b = 3
# Xterm coords start at 1,1 for the top/leftmost cell.
var position: Vector2 = _mouse_to_cell(get_local_mouse_position()) + Vector2.ONE
var e = "\u001b[M".to_ascii()
print(_native_terminal.cell_size)
e = PoolByteArray([0x1b, 0x5b, 0x4d, b + 32, position.x + 32, position.y + 32])
emit_signal("data_sent", e)
_handle_mouse_wheel(event)
_handle_selection(event)