[vte] lib: Use Timer class for mouse autoscroll timer
- From: Christian Persch <chpe src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vte] lib: Use Timer class for mouse autoscroll timer
- Date: Sun, 1 Dec 2019 21:59:10 +0000 (UTC)
commit fbdaa7c71b0a79bee9a8b638c4b96854be519473
Author: Christian Persch <chpe src gnome org>
Date: Sun Dec 1 22:58:51 2019 +0100
lib: Use Timer class for mouse autoscroll timer
src/vte.cc | 45 +++++++++------------------------------------
src/vteinternal.hh | 8 +++++---
2 files changed, 14 insertions(+), 39 deletions(-)
---
diff --git a/src/vte.cc b/src/vte.cc
index 9323090f..2eb3cd51 100644
--- a/src/vte.cc
+++ b/src/vte.cc
@@ -6759,25 +6759,15 @@ Terminal::select_all()
invalidate_all();
}
-/* Autoscroll a bit. */
-static gboolean
-vte_terminal_autoscroll_cb(vte::terminal::Terminal* that)
-{
- return that->autoscroll() ? G_SOURCE_CONTINUE : G_SOURCE_REMOVE;
-}
-
-/*
- * Terminal::autoscroll():
- *
- * Returns: %true to continue autoscrolling, %false to stop
- */
bool
-Terminal::autoscroll()
+Terminal::mouse_autoscroll_timer_callback() noexcept
{
bool extend = false;
long x, y, xmax, ymax;
glong adj;
+ auto again = bool{true};
+
/* Provide an immediate effect for mouse wigglers. */
if (m_mouse_last_position.y < 0) {
if (m_vadjustment) {
@@ -6817,35 +6807,20 @@ Terminal::autoscroll()
modify_selection(vte::view::coords(x, y));
} else {
/* Stop autoscrolling. */
- m_mouse_autoscroll_tag = 0;
+ again = false;
}
- return (m_mouse_autoscroll_tag != 0);
+ return again;
}
/* Start autoscroll. */
void
Terminal::start_autoscroll()
{
- if (m_mouse_autoscroll_tag != 0)
- return;
-
- m_mouse_autoscroll_tag =
- g_timeout_add_full(G_PRIORITY_LOW,
- 666 / m_row_count, // FIXME WTF?
- (GSourceFunc)vte_terminal_autoscroll_cb,
- this,
- NULL);// FIXME make sure m_mouse_autoscroll_tag is nulled!
-}
-
-/* Stop autoscroll. */
-void
-Terminal::stop_autoscroll()
-{
- if (m_mouse_autoscroll_tag == 0)
+ if (m_mouse_autoscroll_timer)
return;
- g_source_remove(m_mouse_autoscroll_tag);
- m_mouse_autoscroll_tag = 0;
+ m_mouse_autoscroll_timer.schedule(666 / m_row_count, // FIXME WTF?
+ vte::glib::Timer::Priority::eLOW);
}
bool
@@ -6888,9 +6863,7 @@ Terminal::widget_motion_notify(GdkEventMotion *event)
if (pos.y < 0 || pos.y >= m_view_usable_extents.height()) {
/* Give mouse wigglers something. */
stop_autoscroll();
- autoscroll();
- /* Start a timed autoscroll if we're not doing it
- * already. */
+ mouse_autoscroll_timer_callback();
start_autoscroll();
}
diff --git a/src/vteinternal.hh b/src/vteinternal.hh
index 4740e22e..bab7f756 100644
--- a/src/vteinternal.hh
+++ b/src/vteinternal.hh
@@ -533,8 +533,11 @@ public:
* the viewable area, and also want to catch in-cell movements if they make the pointer visible.
*/
vte::view::coords m_mouse_last_position{-1, -1};
- guint m_mouse_autoscroll_tag;
double m_mouse_smooth_scroll_delta{0.0};
+ bool mouse_autoscroll_timer_callback() noexcept;
+ vte::glib::Timer m_mouse_autoscroll_timer{std::bind(&Terminal::mouse_autoscroll_timer_callback,
+ this),
+ "mouse-autoscroll-timer"};
/* State variables for handling match checks. */
int m_match_regex_next_tag{0};
@@ -958,9 +961,8 @@ public:
gint column_width,
gint row_height);
- bool autoscroll();
void start_autoscroll();
- void stop_autoscroll();
+ void stop_autoscroll() noexcept { m_mouse_autoscroll_timer.abort(); }
void connect_pty_read();
void disconnect_pty_read();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]