mirror of
https://github.com/lihop/godot-xterm.git
synced 2024-11-22 01:30:25 +01:00
Re-add bell support
This commit is contained in:
parent
07687e2cd8
commit
fd2c33c486
2 changed files with 63 additions and 0 deletions
|
@ -9,6 +9,7 @@
|
||||||
#include <godot_cpp/classes/rendering_server.hpp>
|
#include <godot_cpp/classes/rendering_server.hpp>
|
||||||
#include <godot_cpp/classes/resource_loader.hpp>
|
#include <godot_cpp/classes/resource_loader.hpp>
|
||||||
#include <godot_cpp/classes/shader_material.hpp>
|
#include <godot_cpp/classes/shader_material.hpp>
|
||||||
|
#include <godot_cpp/classes/timer.hpp>
|
||||||
#include <libtsm.h>
|
#include <libtsm.h>
|
||||||
|
|
||||||
#define SHADERS_DIR "res://addons/godot_xterm/shaders/"
|
#define SHADERS_DIR "res://addons/godot_xterm/shaders/"
|
||||||
|
@ -39,6 +40,16 @@ void Terminal::_bind_methods()
|
||||||
ClassDB::bind_method(D_METHOD("set_inverse_mode", "inverse_mode"), &Terminal::set_inverse_mode);
|
ClassDB::bind_method(D_METHOD("set_inverse_mode", "inverse_mode"), &Terminal::set_inverse_mode);
|
||||||
ClassDB::add_property("Terminal", PropertyInfo(Variant::INT, "inverse_mode", PROPERTY_HINT_ENUM, "Invert,Swap"), "set_inverse_mode", "get_inverse_mode");
|
ClassDB::add_property("Terminal", PropertyInfo(Variant::INT, "inverse_mode", PROPERTY_HINT_ENUM, "Invert,Swap"), "set_inverse_mode", "get_inverse_mode");
|
||||||
|
|
||||||
|
// Bell.
|
||||||
|
ADD_SIGNAL(MethodInfo("bell"));
|
||||||
|
ClassDB::add_property_group("Terminal", "Bell", "bell_");
|
||||||
|
ClassDB::bind_method(D_METHOD("get_bell_muted"), &Terminal::get_bell_muted);
|
||||||
|
ClassDB::bind_method(D_METHOD("set_bell_muted", "muted"), &Terminal::set_bell_muted);
|
||||||
|
ClassDB::add_property("Terminal", PropertyInfo(Variant::BOOL, "bell_muted"), "set_bell_muted", "get_bell_muted");
|
||||||
|
ClassDB::bind_method(D_METHOD("get_bell_cooldown"), &Terminal::get_bell_cooldown);
|
||||||
|
ClassDB::bind_method(D_METHOD("set_bell_cooldown", "time"), &Terminal::set_bell_cooldown);
|
||||||
|
ClassDB::add_property("Terminal", PropertyInfo(Variant::FLOAT, "bell_cooldown"), "set_bell_cooldown", "get_bell_cooldown");
|
||||||
|
|
||||||
// Blink.
|
// Blink.
|
||||||
|
|
||||||
ClassDB::add_property_group("Terminal", "Blink", "blink_");
|
ClassDB::add_property_group("Terminal", "Blink", "blink_");
|
||||||
|
@ -62,6 +73,12 @@ Terminal::Terminal()
|
||||||
blink_on_time = 0.6;
|
blink_on_time = 0.6;
|
||||||
blink_off_time = 0.3;
|
blink_off_time = 0.3;
|
||||||
|
|
||||||
|
bell_muted = false;
|
||||||
|
bell_cooldown = 0;
|
||||||
|
bell_timer = memnew(Timer);
|
||||||
|
bell_timer->set_one_shot(true);
|
||||||
|
add_child(bell_timer, false, INTERNAL_MODE_FRONT);
|
||||||
|
|
||||||
inverse_mode = InverseMode::INVERSE_MODE_INVERT;
|
inverse_mode = InverseMode::INVERSE_MODE_INVERT;
|
||||||
|
|
||||||
if (tsm_screen_new(&screen, NULL, NULL))
|
if (tsm_screen_new(&screen, NULL, NULL))
|
||||||
|
@ -74,6 +91,7 @@ Terminal::Terminal()
|
||||||
{
|
{
|
||||||
ERR_PRINT("Failed to create tsm vte.");
|
ERR_PRINT("Failed to create tsm vte.");
|
||||||
}
|
}
|
||||||
|
tsm_vte_set_bell_cb(vte, &Terminal::_bell_cb, this);
|
||||||
|
|
||||||
initialize_rendering();
|
initialize_rendering();
|
||||||
update_theme();
|
update_theme();
|
||||||
|
@ -252,6 +270,18 @@ int Terminal::_draw_cb(struct tsm_screen *con,
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Terminal::_bell_cb(struct tsm_vte *vte, void *data)
|
||||||
|
{
|
||||||
|
Terminal *term = static_cast<Terminal *>(data);
|
||||||
|
|
||||||
|
if (!term->bell_muted && term->bell_timer->is_stopped()) {
|
||||||
|
term->emit_signal("bell");
|
||||||
|
|
||||||
|
if (term->bell_cooldown > 0)
|
||||||
|
term->bell_timer->start(term->bell_cooldown);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool Terminal::_set(const StringName &property, const Variant &value)
|
bool Terminal::_set(const StringName &property, const Variant &value)
|
||||||
{
|
{
|
||||||
if (property.begins_with("theme_override_colors/"))
|
if (property.begins_with("theme_override_colors/"))
|
||||||
|
@ -505,6 +535,27 @@ void Terminal::cleanup_rendering() {
|
||||||
rs->free_rid(char_shader);
|
rs->free_rid(char_shader);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Terminal::set_bell_muted(const bool muted) {
|
||||||
|
bell_muted = muted;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Terminal::get_bell_muted() const {
|
||||||
|
return bell_muted;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Terminal::set_bell_cooldown(const double time) {
|
||||||
|
bell_cooldown = time;
|
||||||
|
bell_timer->stop();
|
||||||
|
|
||||||
|
double remaining_time = std::max(0.0, bell_cooldown - bell_timer->get_time_left());
|
||||||
|
if (remaining_time > 0)
|
||||||
|
bell_timer->start(remaining_time);
|
||||||
|
}
|
||||||
|
|
||||||
|
double Terminal::get_bell_cooldown() const {
|
||||||
|
return bell_cooldown;
|
||||||
|
}
|
||||||
|
|
||||||
void Terminal::set_blink_on_time(const float time)
|
void Terminal::set_blink_on_time(const float time)
|
||||||
{
|
{
|
||||||
blink_on_time = time;
|
blink_on_time = time;
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include <godot_cpp/classes/image_texture.hpp>
|
#include <godot_cpp/classes/image_texture.hpp>
|
||||||
#include <godot_cpp/classes/rendering_server.hpp>
|
#include <godot_cpp/classes/rendering_server.hpp>
|
||||||
#include <godot_cpp/classes/shader_material.hpp>
|
#include <godot_cpp/classes/shader_material.hpp>
|
||||||
|
#include <godot_cpp/classes/timer.hpp>
|
||||||
#include <libtsm.h>
|
#include <libtsm.h>
|
||||||
|
|
||||||
namespace godot
|
namespace godot
|
||||||
|
@ -62,6 +63,12 @@ namespace godot
|
||||||
void set_max_scrollback(const int p_max_scrollback);
|
void set_max_scrollback(const int p_max_scrollback);
|
||||||
int get_max_scrollback() const;
|
int get_max_scrollback() const;
|
||||||
|
|
||||||
|
void set_bell_muted(const bool p_bell_muted);
|
||||||
|
bool get_bell_muted() const;
|
||||||
|
|
||||||
|
void set_bell_cooldown(const double p_bell_cooldown);
|
||||||
|
double get_bell_cooldown() const;
|
||||||
|
|
||||||
void set_blink_on_time(const float p_blink_on_time);
|
void set_blink_on_time(const float p_blink_on_time);
|
||||||
float get_blink_on_time() const;
|
float get_blink_on_time() const;
|
||||||
|
|
||||||
|
@ -97,6 +104,11 @@ namespace godot
|
||||||
static void _write_cb(struct tsm_vte *vte, const char *u8, size_t len,
|
static void _write_cb(struct tsm_vte *vte, const char *u8, size_t len,
|
||||||
void *data);
|
void *data);
|
||||||
|
|
||||||
|
bool bell_muted;
|
||||||
|
double bell_cooldown;
|
||||||
|
Timer* bell_timer;
|
||||||
|
static void _bell_cb(struct tsm_vte *vte, void *data);
|
||||||
|
|
||||||
static int _draw_cb(struct tsm_screen *con, uint64_t id, const uint32_t *ch,
|
static int _draw_cb(struct tsm_screen *con, uint64_t id, const uint32_t *ch,
|
||||||
size_t len, unsigned int width, unsigned int posx,
|
size_t len, unsigned int width, unsigned int posx,
|
||||||
unsigned int posy, const struct tsm_screen_attr *attr,
|
unsigned int posy, const struct tsm_screen_attr *attr,
|
||||||
|
|
Loading…
Reference in a new issue