[vte] lib: Use Timer class for cursor blink timer
- From: Christian Persch <chpe src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vte] lib: Use Timer class for cursor blink timer
- Date: Sun, 1 Dec 2019 21:59:00 +0000 (UTC)
commit b80417fc07b279ffb1fa8507f65ad8327546854b
Author: Christian Persch <chpe src gnome org>
Date: Sun Dec 1 22:58:51 2019 +0100
lib: Use Timer class for cursor blink timer
src/vte.cc | 36 ++++++++++--------------------------
src/vteinternal.hh | 11 +++++++----
2 files changed, 17 insertions(+), 30 deletions(-)
---
diff --git a/src/vte.cc b/src/vte.cc
index 1431c1e3..75eb8141 100644
--- a/src/vte.cc
+++ b/src/vte.cc
@@ -687,20 +687,12 @@ Terminal::invalidate_cursor_once(bool periodic)
/* Invalidate the cursor repeatedly. */
// FIXMEchpe this continually adds and removes the blink timeout. Find a better solution
-static gboolean
-invalidate_cursor_periodic_cb(vte::terminal::Terminal* that)
-{
- that->invalidate_cursor_periodic();
- return G_SOURCE_REMOVE;
-}
-
-void
-Terminal::invalidate_cursor_periodic()
+bool
+Terminal::cursor_blink_timer_callback() noexcept
{
m_cursor_blink_state = !m_cursor_blink_state;
m_cursor_blink_time += m_cursor_blink_cycle;
- m_cursor_blink_tag = 0;
invalidate_cursor_once(true);
/* only disable the blink if the cursor is currently shown.
@@ -708,14 +700,11 @@ Terminal::invalidate_cursor_periodic()
*/
if (m_cursor_blink_time / 1000 >= m_cursor_blink_timeout &&
m_cursor_blink_state) {
- return;
+ return false;
}
- m_cursor_blink_tag = g_timeout_add_full(G_PRIORITY_LOW,
- m_cursor_blink_cycle,
- (GSourceFunc)invalidate_cursor_periodic_cb,
- this,
- NULL);
+ m_cursor_blink_timer.schedule(m_cursor_blink_cycle, vte::glib::Timer::Priority::eLOW);
+ return false;
}
/* Emit a "selection_changed" signal. */
@@ -4432,25 +4421,20 @@ Terminal::widget_style_updated()
void
Terminal::add_cursor_timeout()
{
- if (m_cursor_blink_tag)
+ if (m_cursor_blink_timer)
return; /* already added */
m_cursor_blink_time = 0;
- m_cursor_blink_tag = g_timeout_add_full(G_PRIORITY_LOW,
- m_cursor_blink_cycle,
- (GSourceFunc)invalidate_cursor_periodic_cb,
- this,
- NULL);
+ m_cursor_blink_timer.schedule(m_cursor_blink_cycle, vte::glib::Timer::Priority::eLOW);
}
void
Terminal::remove_cursor_timeout()
{
- if (m_cursor_blink_tag == 0)
+ if (!m_cursor_blink_timer)
return; /* already removed */
- g_source_remove(m_cursor_blink_tag);
- m_cursor_blink_tag = 0;
+ m_cursor_blink_timer.abort();
if (!m_cursor_blink_state) {
invalidate_cursor_once();
m_cursor_blink_state = true;
@@ -4563,7 +4547,7 @@ Terminal::widget_key_press(GdkEventKey *event)
read_modifiers((GdkEvent*)event);
// FIXMEchpe?
- if (m_cursor_blink_tag != 0) {
+ if (m_cursor_blink_timer) {
remove_cursor_timeout();
add_cursor_timeout();
}
diff --git a/src/vteinternal.hh b/src/vteinternal.hh
index dc30b111..d361373a 100644
--- a/src/vteinternal.hh
+++ b/src/vteinternal.hh
@@ -36,6 +36,7 @@
/* END sanity checks */
#include <glib.h>
+#include "glib-glue.hh"
#include "vtedefines.hh"
#include "vtetypes.hh"
@@ -494,14 +495,16 @@ public:
double m_cursor_aspect_ratio{0.04};
/* Cursor blinking */
+ vte::glib::Timer m_cursor_blink_timer{std::bind(&Terminal::cursor_blink_timer_callback,
+ this),
+ "cursor-blink-timer"};
CursorBlinkMode m_cursor_blink_mode{CursorBlinkMode::eSYSTEM};
- gboolean m_cursor_blink_state;
- guint m_cursor_blink_tag{0}; /* cursor blinking timeout ID */
+ bool m_cursor_blink_state{false};
+ bool m_cursor_blinks{false}; /* whether the cursor is actually blinking */
gint m_cursor_blink_cycle; /* 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 */
gboolean m_has_focus; /* is the terminal window focused */
- bool m_cursor_blinks{false}; /* whether the cursor is actually blinking */
/* Contents blinking */
TextBlinkMode m_text_blink_mode{TextBlinkMode::eALWAYS};
@@ -831,7 +834,7 @@ public:
gssize get_preedit_length(bool left_only);
void invalidate_cursor_once(bool periodic = false);
- void invalidate_cursor_periodic();
+ bool cursor_blink_timer_callback() noexcept;
void check_cursor_blink();
void add_cursor_timeout();
void remove_cursor_timeout();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]