[vte] widget: Simplify coordinate handling



commit 63259c4fe2b5608a0a4236ed33cee706fcce4896
Author: Christian Persch <chpe gnome org>
Date:   Fri Dec 25 21:55:44 2015 +0100

    widget: Simplify coordinate handling
    
    Store the last mouse position only in view coordinates, and
    convert to grid coordinates only on the few occasions we compare
    to grid coordinates. Use view coordinates because we do want to
    test the last position for being outside the viewable area.

 src/vte.cc         |   75 ++++++++++++++++------------------------------------
 src/vteinternal.hh |   14 +++------
 2 files changed, 28 insertions(+), 61 deletions(-)
---
diff --git a/src/vte.cc b/src/vte.cc
index d5c5268..a50ab19 100644
--- a/src/vte.cc
+++ b/src/vte.cc
@@ -322,28 +322,6 @@ VteTerminalPrivate::last_displayed_row() const
         return r;
 }
 
-/* x, y are coordinates excluding the padding.
- * col, row are in 0..width-1, 0..height-1.
- * Returns FALSE if clicked over scrollback content; output values are unchanged then.
- */
-bool
-VteTerminalPrivate::mouse_pixels_to_grid (long x,
-                                          long y,
-                                          vte::grid::column_t *col,
-                                          vte::grid::row_t *row)
-{
-        auto rowcol = grid_coords_from_view_coords(vte::view::coords(x, y));
-        rowcol = confine_grid_coords(rowcol);
-
-        /* Don't allow clicking on scrollback contents: bug 755187. */
-        if (grid_coords_in_scrollback(rowcol))
-                return false;
-
-        *col = rowcol.column();
-        *row = rowcol.row() - m_screen->insert_delta;
-        return true;
-}
-
 void
 VteTerminalPrivate::invalidate_cells(vte::grid::column_t column_start,
                                      int n_columns,
@@ -1880,7 +1858,7 @@ VteTerminalPrivate::grid_coords_from_event(GdkEvent const* event) const
 }
 
 /*
- * VteTerminalPrivate::grid_coords_from_event:
+ * VteTerminalPrivate::confined_grid_coords_from_event:
  * @event: a #GdkEvent
  *
  * Like grid_coords_from_event(), but also confines the coordinates
@@ -1889,14 +1867,13 @@ VteTerminalPrivate::grid_coords_from_event(GdkEvent const* event) const
 vte::grid::coords
 VteTerminalPrivate::confined_grid_coords_from_event(GdkEvent const* event) const
 {
-        auto rowcol = grid_coords_from_view_coords(view_coords_from_event(event));
-        return confine_grid_coords(rowcol);
+        auto pos = view_coords_from_event(event);
+        return confined_grid_coords_from_view_coords(pos);
 }
 
 /*
  * VteTerminalPrivate::grid_coords_from_view_coords:
  * @pos: the view coordinates
- * @rowcol: the grid coordinates
  *
  * Translates view coordinates to grid coordinates. If the view coordinates point to
  * cells that are not visible, may return any value < 0 or >= m_column_count, and
@@ -1919,6 +1896,20 @@ VteTerminalPrivate::grid_coords_from_view_coords(vte::view::coords const& pos) c
 }
 
 /*
+ * VteTerminalPrivate::confined_grid_coords_from_view_coords:
+ * @pos: the view coordinates
+ *
+ * Like grid_coords_from_view_coords(), but also confines the coordinates
+ * to an actual cell in the visible area.
+ */
+vte::grid::coords
+VteTerminalPrivate::confined_grid_coords_from_view_coords(vte::view::coords const& pos) const
+{
+        auto rowcol = grid_coords_from_view_coords(pos);
+        return confine_grid_coords(rowcol);
+}
+
+/*
  * VteTerminalPrivate::view_coords_from_grid_coords:
  * @rowcol: the grid coordinates
  *
@@ -5749,7 +5740,7 @@ VteTerminalPrivate::maybe_send_mouse_drag(vte::grid::coords const& unconfined_ro
                         * all-tracking also sends degenerate same-cell events;
                          * we don't.
                          */
-                        if (rowcol == vte::grid::coords(m_mouse_last_row, m_mouse_last_column))
+                        if (rowcol == confined_grid_coords_from_view_coords(m_mouse_last_position))
                                return false;
                }
                break;
@@ -5917,25 +5908,16 @@ VteTerminalPrivate::match_hilite_update(vte::view::coords const& pos)
 void
 VteTerminalPrivate::match_hilite(vte::view::coords const& pos)
 {
-        auto x = pos.x;
-        auto y = pos.y;
-
        /* if the cursor is not above a cell, skip */
-       if (x < 0 || x >= m_view_usable_extents.width() ||
-            y < 0 || y >= m_view_usable_extents.height()) {
+        if (!view_coords_visible(pos))
                return;
-       }
 
        /* If the pointer hasn't moved to another character cell, then we
         * need do nothing. Note: Don't use mouse_last_row as that's relative
         * to insert_delta, and we care about the absolute row number. */
-       if (x / m_char_width  == m_mouse_last_position.x / m_char_width &&
-           pixel_to_row(y) == pixel_to_row(m_mouse_last_position.y)) {
-               m_show_match = m_match != nullptr;
-               return;
-       }
-
-       if (cursor_inside_match(pos)) {
+       if (grid_coords_from_view_coords(pos) ==
+            confined_grid_coords_from_view_coords(m_mouse_last_position) ||
+            cursor_inside_match(pos)) {
                m_show_match = m_match != nullptr;
                return;
        }
@@ -7229,9 +7211,6 @@ VteTerminalPrivate::widget_motion_notify(GdkEventMotion *event)
 
        /* Save the pointer coordinates for later use. */
        m_mouse_last_position = pos;
-        mouse_pixels_to_grid (pos.x, pos.y,
-                                            &m_mouse_last_column,
-                                            &m_mouse_last_row);
 
        return handled;
 }
@@ -7385,9 +7364,6 @@ VteTerminalPrivate::widget_button_press(GdkEventButton *event)
         if (event->button >= 1 && event->button <= 3)
                 m_mouse_pressed_buttons |= (1 << (event->button - 1));
        m_mouse_last_position = pos;
-        mouse_pixels_to_grid (pos.x, pos.y,
-                                            &m_mouse_last_column,
-                                            &m_mouse_last_row);
 
        return handled;
 }
@@ -7439,9 +7415,6 @@ VteTerminalPrivate::widget_button_release(GdkEventButton *event)
         if (event->button >= 1 && event->button <= 3)
                 m_mouse_pressed_buttons &= ~(1 << (event->button - 1));
        m_mouse_last_position = pos;
-        mouse_pixels_to_grid (pos.x, pos.y,
-                                            &m_mouse_last_column,
-                                            &m_mouse_last_row);
        m_selecting_after_threshold = false;
 
        return handled;
@@ -10402,9 +10375,7 @@ VteTerminalPrivate::reset(bool clear_tabstops,
        m_mouse_tracking_mode = MOUSE_TRACKING_NONE;
         m_mouse_pressed_buttons = 0;
         m_mouse_handled_buttons = 0;
-       m_mouse_last_position = vte::view::coords(0, 0);
-        m_mouse_last_column = 0;
-        m_mouse_last_row = 0;
+       m_mouse_last_position = vte::view::coords(-1, -1);
        m_mouse_xterm_extension = FALSE;
        m_mouse_urxvt_extension = FALSE;
        m_mouse_smooth_scroll_delta = 0.;
diff --git a/src/vteinternal.hh b/src/vteinternal.hh
index 4d207df..8826ccd 100644
--- a/src/vteinternal.hh
+++ b/src/vteinternal.hh
@@ -338,9 +338,11 @@ public:
                                    but we need to guarantee its type. */
         guint mouse_pressed_buttons;      /* bits 0, 1, 2 resp. for buttons 1, 2, 3 */
         guint mouse_handled_buttons;      /* similar bitmap for buttons we handled ourselves */
-        /* The last known position the mouse pointer from an event */
+        /* The last known position the mouse pointer from an event. We don't store
+         * this in grid coordinates because we want also to check if they were outside
+         * the viewable area.
+         */
         vte::view::coords m_mouse_last_position;
-        long mouse_last_col, mouse_last_row;
        gboolean mouse_autohide;
        guint m_mouse_autoscroll_tag;
        gboolean mouse_xterm_extension;
@@ -531,6 +533,7 @@ public:
 
         vte::grid::coords confine_grid_coords(vte::grid::coords const& rowcol) const;
         vte::grid::coords confined_grid_coords_from_event(GdkEvent const* event) const;
+        vte::grid::coords confined_grid_coords_from_view_coords(vte::view::coords const& pos) const;
 
         void confine_coordinates(long *xp,
                                  long *yp);
@@ -894,11 +897,6 @@ public:
                                    gsize *start,
                                    gsize *end);
 
-        bool mouse_pixels_to_grid (long x,
-                                   long y,
-                                   vte::grid::column_t *col,
-                                   vte::grid::row_t *row);
-
         bool feed_mouse_event(vte::grid::coords const& unconfined_rowcol,
                               int button,
                               bool is_drag,
@@ -1021,8 +1019,6 @@ public:
 #define m_match_regex_mode match_regex_mode
 #define m_mouse_tracking_mode mouse_tracking_mode
 #define m_mouse_pressed_buttons mouse_pressed_buttons
-#define m_mouse_last_column mouse_last_col
-#define m_mouse_last_row mouse_last_row
 #define m_mouse_xterm_extension mouse_xterm_extension
 #define m_mouse_urxvt_extension mouse_urxvt_extension
 #define m_modifiers modifiers


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