[vte] widget: Make scroll adjustment range start at 0 always
- From: Christian Persch <chpe src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vte] widget: Make scroll adjustment range start at 0 always
- Date: Sat, 13 Mar 2021 21:11:27 +0000 (UTC)
commit cf4984c4c35b6c15b239fbea5abf3a92271665d2
Author: Christian Persch <chpe src gnome org>
Date: Sat Mar 13 22:10:42 2021 +0100
widget: Make scroll adjustment range start at 0 always
https://gitlab.gnome.org/GNOME/vte/-/issues/336
src/vte.cc | 29 ++++++++++++++++++-----------
src/vteinternal.hh | 2 +-
src/widget.cc | 21 ++++++++++++---------
3 files changed, 31 insertions(+), 21 deletions(-)
---
diff --git a/src/vte.cc b/src/vte.cc
index fd933e8b..7819dbec 100644
--- a/src/vte.cc
+++ b/src/vte.cc
@@ -7633,27 +7633,34 @@ Terminal::set_size(long columns,
void
Terminal::set_scroll_value(double value)
{
- /* Save the difference. */
- auto const dy = value - m_screen->scroll_delta;
+ auto const lower = _vte_ring_delta(m_screen->row_data);
+ auto const upper_minus_row_count = m_screen->insert_delta;
+
+ value = std::clamp(value,
+ double(lower),
+ double(std::max(lower, upper_minus_row_count)));
- m_screen->scroll_delta = value;
+ /* Save the difference. */
+ auto const dy = value - m_screen->scroll_delta;
- /* Sanity checks. */
+ m_screen->scroll_delta = value;
+
+ /* Sanity checks. */
if (G_UNLIKELY(!widget_realized()))
return;
/* FIXME: do this check in pixel space */
- if (!_vte_double_equal(dy, 0)) {
- _vte_debug_print(VTE_DEBUG_ADJ,
+ if (!_vte_double_equal(dy, 0)) {
+ _vte_debug_print(VTE_DEBUG_ADJ,
"Scrolling by %f\n", dy);
invalidate_all();
match_contents_clear();
- emit_text_scrolled(dy);
- queue_contents_changed();
- } else {
- _vte_debug_print(VTE_DEBUG_ADJ, "Not scrolling\n");
- }
+ emit_text_scrolled(dy);
+ queue_contents_changed();
+ } else {
+ _vte_debug_print(VTE_DEBUG_ADJ, "Not scrolling\n");
+ }
}
Terminal::Terminal(vte::platform::Widget* w,
diff --git a/src/vteinternal.hh b/src/vteinternal.hh
index 1489062e..9e5eabd8 100644
--- a/src/vteinternal.hh
+++ b/src/vteinternal.hh
@@ -438,7 +438,7 @@ public:
return _vte_ring_delta (m_screen->row_data);
}
- inline auto scroll_limit_upper() const noexcept
+ inline constexpr auto scroll_limit_upper() const noexcept
{
return m_screen->insert_delta + m_row_count;
}
diff --git a/src/widget.cc b/src/widget.cc
index 29b633de..233f36fc 100644
--- a/src/widget.cc
+++ b/src/widget.cc
@@ -918,13 +918,14 @@ Widget::notify_scroll_bounds_changed(bool value_changed)
auto const freezer = vte::glib::FreezeObjectNotify{m_vadjustment.get()};
auto changed = false;
- auto dlower = double(terminal()->scroll_limit_lower());
- auto dupper = double(terminal()->scroll_limit_upper());
+ auto const lower = terminal()->scroll_limit_lower();
+ auto const upper = terminal()->scroll_limit_upper();
+ auto dlower = 0.;
+ auto dupper = double(upper - lower);
auto dline = 1.;
auto row_count = terminal()->row_count();
if (scroll_unit_is_pixels()) [[unlikely]] {
auto const factor = m_terminal->get_cell_height();
- dlower *= factor;
dupper *= factor;
dline *= factor;
row_count *= factor;
@@ -994,9 +995,8 @@ Widget::notify_scroll_value_changed()
_vte_debug_print(VTE_DEBUG_ADJ,
"Updating scroll adjustment value\n");
- m_changing_scroll_position = true;
-
- auto value = terminal()->scroll_position();
+ auto const lower = terminal()->scroll_limit_lower();
+ auto value = terminal()->scroll_position() - lower;
if (scroll_unit_is_pixels()) [[unlikely]] {
auto const factor = m_terminal->get_cell_height();
value *= factor;
@@ -1004,11 +1004,10 @@ Widget::notify_scroll_value_changed()
auto const v = gtk_adjustment_get_value(m_vadjustment.get());
if (!_vte_double_equal(v, value)) {
- /* Note that this will generate a 'value-changed' signal */
+ m_changing_scroll_position = true;
gtk_adjustment_set_value(m_vadjustment.get(), value);
+ m_changing_scroll_position = false;
}
-
- m_changing_scroll_position = false;
}
#if VTE_GTK == 3
@@ -1594,6 +1593,10 @@ Widget::vadjustment_value_changed()
adj /= factor;
}
+ /* Add offset */
+ auto const lower = terminal()->scroll_limit_lower();
+ adj += lower;
+
m_terminal->set_scroll_value(adj);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]