summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Persch <chpe@src.gnome.org>2023-04-05 19:06:13 +0200
committerChristian Persch <chpe@src.gnome.org>2023-04-05 19:06:13 +0200
commit4da9d055f68f5b5dad9946b289a1836bd7c0fe8d (patch)
treefeed4f1506085f72424a151ab55955d65dfaae8f
parent7fa3e6220de8aad9174e5976d73553a8073c6e4f (diff)
downloadvte-4da9d055f68f5b5dad9946b289a1836bd7c0fe8d.tar.gz
widget: Fix cursor blink timeout
Fix s/ms confusion to make the cursor stop blinking correctly. Fixes: https://gitlab.gnome.org/GNOME/vte/-/issues/2622
-rw-r--r--src/vte.cc30
-rw-r--r--src/vteinternal.hh12
-rw-r--r--src/widget.cc12
3 files changed, 28 insertions, 26 deletions
diff --git a/src/vte.cc b/src/vte.cc
index 9f331a38..b3542038 100644
--- a/src/vte.cc
+++ b/src/vte.cc
@@ -840,19 +840,20 @@ bool
Terminal::cursor_blink_timer_callback()
{
m_cursor_blink_state = !m_cursor_blink_state;
- m_cursor_blink_time += m_cursor_blink_cycle;
+ m_cursor_blink_time_ms += m_cursor_blink_cycle_ms;
invalidate_cursor_once(true);
/* only disable the blink if the cursor is currently shown.
* else, wait until next time.
*/
- if (m_cursor_blink_time / 1000 >= m_cursor_blink_timeout &&
+ if (m_cursor_blink_time_ms >= m_cursor_blink_timeout_ms &&
m_cursor_blink_state) {
return false;
}
- m_cursor_blink_timer.schedule(m_cursor_blink_cycle, vte::glib::Timer::Priority::eLOW);
+ m_cursor_blink_timer.schedule(m_cursor_blink_cycle_ms,
+ vte::glib::Timer::Priority::eLOW);
return false;
}
@@ -4546,8 +4547,9 @@ Terminal::add_cursor_timeout()
if (m_cursor_blink_timer)
return; /* already added */
- m_cursor_blink_time = 0;
- m_cursor_blink_timer.schedule(m_cursor_blink_cycle, vte::glib::Timer::Priority::eLOW);
+ m_cursor_blink_time_ms = 0;
+ m_cursor_blink_timer.schedule(m_cursor_blink_cycle_ms,
+ vte::glib::Timer::Priority::eLOW);
}
void
@@ -8009,17 +8011,17 @@ Terminal::widget_unrealize()
void
Terminal::set_blink_settings(bool blink,
- int blink_time,
- int blink_timeout) noexcept
+ int blink_time_ms,
+ int blink_timeout_ms) noexcept
{
m_cursor_blinks = m_cursor_blinks_system = blink;
- m_cursor_blink_cycle = std::max(blink_time / 2, VTE_MIN_CURSOR_BLINK_CYCLE);
- m_cursor_blink_timeout = std::max(blink_timeout, VTE_MIN_CURSOR_BLINK_TIMEOUT);
+ m_cursor_blink_cycle_ms = std::max(blink_time_ms / 2, VTE_MIN_CURSOR_BLINK_CYCLE);
+ m_cursor_blink_timeout_ms = std::max(blink_timeout_ms, VTE_MIN_CURSOR_BLINK_TIMEOUT);
update_cursor_blinks();
/* Misuse gtk-cursor-blink-time for text blinking as well. This might change in the future. */
- m_text_blink_cycle = m_cursor_blink_cycle;
+ m_text_blink_cycle_ms = m_cursor_blink_cycle_ms;
if (m_text_blink_timer) {
/* The current phase might have changed, and an already installed
* timer to blink might fire too late. So remove the timer and
@@ -9378,7 +9380,7 @@ Terminal::draw(cairo_t* cr,
#if WITH_SIXEL
VteRing *ring = m_screen->row_data;
#endif
- gint64 now = 0;
+ auto now_ms = int64_t{0};
allocated_width = get_allocated_width();
allocated_height = get_allocated_height();
@@ -9451,8 +9453,8 @@ Terminal::draw(cairo_t* cr,
m_text_blink_state = true;
text_blink_enabled_now = (unsigned)m_text_blink_mode & (unsigned)(m_has_focus ? TextBlinkMode::eFOCUSED : TextBlinkMode::eUNFOCUSED);
if (text_blink_enabled_now) {
- now = g_get_monotonic_time() / 1000;
- if (now % (m_text_blink_cycle * 2) >= m_text_blink_cycle)
+ now_ms = g_get_monotonic_time() / 1000;
+ if (now_ms % (m_text_blink_cycle_ms * 2) >= m_text_blink_cycle_ms)
m_text_blink_state = false;
}
/* Painting will flip this if it encounters any cell with blink attribute */
@@ -9503,7 +9505,7 @@ Terminal::draw(cairo_t* cr,
* implicitly by the timer not getting reinstalled anymore (often after a final unnecessary but
* harmless repaint). */
if (G_UNLIKELY (m_text_to_blink && text_blink_enabled_now && !m_text_blink_timer))
- m_text_blink_timer.schedule(m_text_blink_cycle - now % m_text_blink_cycle,
+ m_text_blink_timer.schedule(m_text_blink_cycle_ms - now_ms % m_text_blink_cycle_ms,
vte::glib::Timer::Priority::eLOW);
m_invalidated_all = FALSE;
diff --git a/src/vteinternal.hh b/src/vteinternal.hh
index 6c27e767..3f47c7da 100644
--- a/src/vteinternal.hh
+++ b/src/vteinternal.hh
@@ -472,9 +472,9 @@ public:
bool m_cursor_blink_state{false};
bool m_cursor_blinks{false}; /* whether the cursor is actually blinking */
bool m_cursor_blinks_system{true}; /* gtk-cursor-blink */
- gint m_cursor_blink_cycle{1000}; /* gtk-cursor-blink-time / 2 */
- int m_cursor_blink_timeout{500}; /* gtk-cursor-blink-timeout */
- gint64 m_cursor_blink_time; /* how long the cursor has been blinking yet */
+ int m_cursor_blink_cycle_ms{1000}; /* gtk-cursor-blink-time / 2 */
+ int m_cursor_blink_timeout_ms{500}; /* gtk-cursor-blink-timeout */
+ int64_t m_cursor_blink_time_ms; /* how long the cursor has been blinking yet */
bool m_has_focus{false}; /* is the widget focused */
/* Contents blinking */
@@ -485,7 +485,7 @@ public:
bool m_text_blink_state{false}; /* whether blinking text should be visible at this very moment */
bool m_text_to_blink{false}; /* drawing signals here if it encounters any cell with blink attribute */
TextBlinkMode m_text_blink_mode{TextBlinkMode::eALWAYS};
- gint m_text_blink_cycle; /* gtk-cursor-blink-time / 2 */
+ int m_text_blink_cycle_ms; /* gtk-cursor-blink-time / 2 */
/* DECSCUSR cursor style (shape and blinking possibly overridden
* via escape sequence) */
@@ -957,8 +957,8 @@ public:
#endif /* VTE_GTK */
void set_blink_settings(bool blink,
- int blink_time,
- int blink_timeout) noexcept;
+ int blink_time_ms,
+ int blink_timeout_ms) noexcept;
void draw(cairo_t *cr,
cairo_region_t const* region) noexcept;
diff --git a/src/widget.cc b/src/widget.cc
index 84704275..fe56ff6c 100644
--- a/src/widget.cc
+++ b/src/widget.cc
@@ -1861,15 +1861,15 @@ void
Widget::settings_changed()
{
auto blink = gboolean{};
- auto blink_time = int{};
- auto blink_timeout = int{};
+ auto blink_time_ms = int{};
+ auto blink_timeout_s = int{};
#if VTE_GTK == 4
auto aspect = double{};
#endif
g_object_get(m_settings.get(),
"gtk-cursor-blink", &blink,
- "gtk-cursor-blink-time", &blink_time,
- "gtk-cursor-blink-timeout", &blink_timeout,
+ "gtk-cursor-blink-time", &blink_time_ms,
+ "gtk-cursor-blink-timeout", &blink_timeout_s,
#if VTE_GTK == 4
"gtk-cursor-aspect-ratio", &aspect,
#endif
@@ -1877,9 +1877,9 @@ Widget::settings_changed()
_vte_debug_print(VTE_DEBUG_MISC,
"Cursor blinking settings: blink=%d time=%d timeout=%d\n",
- blink, blink_time, blink_timeout);
+ blink, blink_time_ms, blink_timeout_s * 1000);
- m_terminal->set_blink_settings(blink, blink_time, blink_timeout);
+ m_terminal->set_blink_settings(blink, blink_time_ms, blink_timeout_s * 1000);
#if VTE_GTK == 4
m_terminal->set_cursor_aspect(aspect);