[vte] lib: Use Timer class for text blink timer
- From: Christian Persch <chpe src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vte] lib: Use Timer class for text blink timer
- Date: Sun, 1 Dec 2019 21:59:05 +0000 (UTC)
commit 0746dad188a3c3337dff01474aa586edafcf615c
Author: Christian Persch <chpe src gnome org>
Date: Sun Dec 1 22:58:51 2019 +0100
lib: Use Timer class for text blink timer
src/vte.cc | 39 +++++++++++++--------------------------
src/vteinternal.hh | 11 ++++++-----
2 files changed, 19 insertions(+), 31 deletions(-)
---
diff --git a/src/vte.cc b/src/vte.cc
index 75eb8141..9323090f 100644
--- a/src/vte.cc
+++ b/src/vte.cc
@@ -4453,16 +4453,6 @@ Terminal::check_cursor_blink()
remove_cursor_timeout();
}
-void
-Terminal::remove_text_blink_timeout()
-{
- if (m_text_blink_tag == 0)
- return;
-
- g_source_remove (m_text_blink_tag);
- m_text_blink_tag = 0;
-}
-
void
Terminal::beep()
{
@@ -7154,7 +7144,7 @@ Terminal::widget_focus_in(GdkEventFocus *event)
* If blinking gets disabled, only repaint if there's blinking stuff present
* (we could further optimize by checking its current phase). */
if (m_text_blink_mode == TextBlinkMode::eFOCUSED ||
- (m_text_blink_mode == TextBlinkMode::eUNFOCUSED && m_text_blink_tag != 0)) {
+ (m_text_blink_mode == TextBlinkMode::eUNFOCUSED && m_text_blink_timer)) {
invalidate_all();
}
@@ -7185,7 +7175,7 @@ Terminal::widget_focus_out(GdkEventFocus *event)
* If blinking gets disabled, only repaint if there's blinking stuff present
* (we could further optimize by checking its current phase). */
if (m_text_blink_mode == TextBlinkMode::eUNFOCUSED ||
- (m_text_blink_mode == TextBlinkMode::eFOCUSED && m_text_blink_tag != 0)) {
+ (m_text_blink_mode == TextBlinkMode::eFOCUSED && m_text_blink_timer)) {
invalidate_all();
}
@@ -8006,7 +7996,7 @@ Terminal::widget_unrealize()
remove_cursor_timeout();
/* Remove the contents blink timeout function. */
- remove_text_blink_timeout();
+ m_text_blink_timer.abort();
/* Cancel any pending redraws. */
remove_update_timeout(this);
@@ -8034,11 +8024,11 @@ Terminal::set_blink_settings(bool blink,
/* Misuse gtk-cursor-blink-time for text blinking as well. This might change in the future. */
m_text_blink_cycle = m_cursor_blink_cycle;
- if (m_text_blink_tag != 0) {
+ 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
* repaint the contents (which will install a correct new timer). */
- remove_text_blink_timeout();
+ m_text_blink_timer.abort();
invalidate_all();
}
}
@@ -8260,12 +8250,12 @@ Terminal::determine_cursor_colors(VteCell const* cell,
fore, back, deco);
}
-static gboolean
-invalidate_text_blink_cb(vte::terminal::Terminal* that)
+// FIXMEchpe this constantly removes and reschedules the timer. improve this!
+bool
+Terminal::text_blink_timer_callback()
{
- that->m_text_blink_tag = 0;
- that->invalidate_all();
- return G_SOURCE_REMOVE;
+ invalidate_all();
+ return false; /* don't run again */
}
/* Draw a string of characters with similar attributes. */
@@ -9404,12 +9394,9 @@ Terminal::widget_draw(cairo_t *cr)
* for an explicit step to stop the timer when blinking cells are no longer present, this happens
* 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_tag == 0))
- m_text_blink_tag = g_timeout_add_full(G_PRIORITY_LOW,
- m_text_blink_cycle - now % m_text_blink_cycle,
- (GSourceFunc)invalidate_text_blink_cb,
- this,
- NULL);
+ 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,
+ vte::glib::Timer::Priority::eLOW);
m_invalidated_all = FALSE;
}
diff --git a/src/vteinternal.hh b/src/vteinternal.hh
index d361373a..4740e22e 100644
--- a/src/vteinternal.hh
+++ b/src/vteinternal.hh
@@ -507,11 +507,14 @@ public:
gboolean m_has_focus; /* is the terminal window focused */
/* Contents blinking */
+ bool text_blink_timer_callback() noexcept;
+ vte::glib::Timer m_text_blink_timer{std::bind(&Terminal::text_blink_timer_callback,
+ this),
+ "text-blink-timer"};
+ 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 */
- bool m_text_blink_state; /* whether blinking text should be visible at this very moment */
- bool m_text_to_blink; /* drawing signals here if it encounters any cell with blink attribute */
- guint m_text_blink_tag{0}; /* timeout ID for redrawing due to blinking */
/* DECSCUSR cursor style (shape and blinking possibly overridden
* via escape sequence) */
@@ -842,8 +845,6 @@ public:
CursorBlinkMode decscusr_cursor_blink() const noexcept;
CursorShape decscusr_cursor_shape() const noexcept;
- void remove_text_blink_timeout();
-
/* The allocation of the widget */
cairo_rectangle_int_t m_allocated_rect;
/* The usable view area. This is the allocation, minus the padding, but
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]