summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Persch <chpe@src.gnome.org>2023-04-05 19:17:06 +0200
committerChristian Persch <chpe@src.gnome.org>2023-04-05 19:17:06 +0200
commitaa024f25245d7c7810bc4404e7aa2046486d229d (patch)
tree007bf99fa0dd2535132ae1a5a6a7ecd331c642bc
parente7f8f858536b3beee5515caa96b9f2d9714f22bb (diff)
downloadvte-aa024f25245d7c7810bc4404e7aa2046486d229d.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 (cherry picked from commit 4da9d055f68f5b5dad9946b289a1836bd7c0fe8d) (cherry picked from commit c4e8371fe65fdb3ea4c81c838d8373444e6d3400)
-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 7cc26c48..9f5801a4 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;
}
@@ -4471,8 +4472,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
@@ -7891,17 +7893,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
@@ -9237,7 +9239,7 @@ Terminal::draw(cairo_t* cr,
int allocated_width, allocated_height;
int extra_area_for_cursor;
bool text_blink_enabled_now;
- gint64 now = 0;
+ auto now_ms = int64_t{0};
allocated_width = get_allocated_width();
allocated_height = get_allocated_height();
@@ -9283,8 +9285,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 */
@@ -9335,7 +9337,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 0d454649..569c90ea 100644
--- a/src/vteinternal.hh
+++ b/src/vteinternal.hh
@@ -462,9 +462,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 */
@@ -475,7 +475,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) */
@@ -922,8 +922,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 49e02049..166318fa 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);