[vte/wip/regex-builtins] widget: Refactor offscreen cursor detection



commit 146c5f55865e5c1f0fa60d0ee7e971f29b34bfe1
Author: Egmont Koblinger <egmont gmail com>
Date:   Thu May 30 15:29:41 2019 +0200

    widget: Refactor offscreen cursor detection
    
    https://gitlab.gnome.org/GNOME/vte/issues/75

 src/vte.cc         | 23 ++++++++++++++++++-----
 src/vteinternal.hh |  1 +
 2 files changed, 19 insertions(+), 5 deletions(-)
---
diff --git a/src/vte.cc b/src/vte.cc
index fa2137da..e04b05d9 100644
--- a/src/vte.cc
+++ b/src/vte.cc
@@ -231,6 +231,21 @@ Terminal::last_displayed_row() const
         return r;
 }
 
+/* Checks if the cursor is potentially at least partially onscreen.
+ * An outline cursor has an additional height of VTE_LINE_WIDTH pixels.
+ * It's also intentionally painted over the padding, up to VTE_LINE_WIDTH
+ * pixels under the real contents area. This method takes these into account.
+ * Only checks the cursor's row; not its visibility, shape, or offscreen column.
+ */
+inline bool
+Terminal::cursor_is_onscreen() const noexcept
+{
+        /* Note: the cursor can only be offscreen below the visible area, not above. */
+        auto cursor_top = row_to_pixel (m_screen->cursor.row) - VTE_LINE_WIDTH;
+        auto display_bottom = m_view_usable_extents.height() + MIN(m_padding.bottom, VTE_LINE_WIDTH);
+        return cursor_top < display_bottom;
+}
+
 /* Note that end_row is inclusive. This is not as nice as end-exclusive,
  * but saves us from a +1 almost everywhere where this method is called. */
 void
@@ -8885,9 +8900,7 @@ Terminal::paint_cursor()
        width = m_cell_width;
        height = m_cell_height;
 
-        /* Show a tiny bit of an outline rectangle cursor just under the last displayed row,
-         * hence the +1. The cursor can't be offscreen in the other direction vertically. */
-        if (drow > last_displayed_row() + 1)
+        if (!cursor_is_onscreen())
                 return;
        if (CLAMP(col, 0, m_column_count - 1) != col)
                return;
@@ -9195,10 +9208,10 @@ Terminal::widget_draw(cairo_t *cr)
 
         cairo_restore(cr);
 
-        /* Re-clip, allowing 1 more pixel row for the outline cursor. */
+        /* Re-clip, allowing VTE_LINE_WIDTH more pixel rows for the outline cursor. */
         /* TODOegmont: It's really ugly to do it here. */
         cairo_save(cr);
-        extra_area_for_cursor = (decscusr_cursor_shape() == VTE_CURSOR_SHAPE_BLOCK && !m_has_focus) ? 1 : 0;
+        extra_area_for_cursor = (decscusr_cursor_shape() == VTE_CURSOR_SHAPE_BLOCK && !m_has_focus) ? 
VTE_LINE_WIDTH : 0;
         cairo_rectangle(cr, 0, m_padding.top - extra_area_for_cursor, allocated_width, allocated_height - 
m_padding.top - m_padding.bottom + 2 * extra_area_for_cursor);
         cairo_clip(cr);
 
diff --git a/src/vteinternal.hh b/src/vteinternal.hh
index cca7b210..4401a852 100644
--- a/src/vteinternal.hh
+++ b/src/vteinternal.hh
@@ -690,6 +690,7 @@ public:
         inline vte::view::coord_t row_to_pixel(vte::grid::row_t row) const;
         inline vte::grid::row_t first_displayed_row() const;
         inline vte::grid::row_t last_displayed_row() const;
+        inline bool cursor_is_onscreen() const noexcept;
 
         inline VteRowData *insert_rows (guint cnt);
         VteRowData *ensure_row();


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]