-- Leo's gemini proxy

-- Connecting to git.thebackupbox.net:1965...

-- Connected

-- Sending request

-- Meta line: 20 text/gemini

repo: rxvt-unicode-sixel
action: commit
revision:
path_from:
revision_from: ff64adbb7c510a17037f19bcbb11733be57b2e04:
path_to:
revision_to:

git.thebackupbox.net

rxvt-unicode-sixel

git://git.thebackupbox.net/rxvt-unicode-sixel

commit ff64adbb7c510a17037f19bcbb11733be57b2e04
Author: Marc Lehmann <schmorp@schmorp.de>
Date:   Sun Jan 15 06:02:41 2006 +0000

    *** empty log message ***

diff --git a/Changes b/Changes

index a130e04ac9b2066f72eb04d637aa866328bb0c06..

index ..b92a40eabc304f041a1142c617bf4f47fc585209 100644

--- a/Changes
+++ b/Changes
@@ -20,6 +20,8 @@ WISH: support tex fonts
           :-> Matching is now done on UTF-8, which makes it almost instant.
         - perl/selection, perl/selection-autotransform: regexes are now
           being interpreted in the locale urxvt was started.
+        - perl-overlays and refresh hooks were not applied in correct order.
+        - changed coordinate-system of view_start/nsaved to be top to bottom.
         - applied many patches by Emanuele Giaquinta that clean the code up
           and fix more bugs in the utmp logging code.
 	- add tsl/fsl and related capabilities to the terminfo description,
diff --git a/src/command.C b/src/command.C

index 76334d39983f4beabd34a082174501db6e36af41..

index ..bd4aed7f53c980448219fe56b2eac7367ca699f9 100644

--- a/src/command.C
+++ b/src/command.C
@@ -149,7 +149,7 @@ rxvt_term::iso14755_54 (int x, int y)

   for (;;)
     {
-      const line_t &l = ROW(y - view_start);
+      const line_t &l = ROW(y + view_start);

       text_t t = l.t[x];

@@ -974,10 +974,10 @@ rxvt_term::flush ()
     {
       if (SHOULD_INVOKE (HOOK_LINE_UPDATE))
         {
-          int row = -view_start;
+          int row = view_start;
           int end_row = row + nrow;

-          while (row > -nsaved && ROW (row - 1).is_longer ())
+          while (row > top_row && ROW (row - 1).is_longer ())
             --row;

           do
@@ -1103,8 +1103,7 @@ rxvt_term::slip_wheel_cb (time_watcher &w)
       || mouse_slip_wheel_speed < 0 ? scr_page (DN, -mouse_slip_wheel_speed)
                                     : scr_page (UP,  mouse_slip_wheel_speed))
     {
-      if (view_start == nsaved ||
-          view_start == 0)
+      if (view_start == top_row || view_start == 0)
         mouse_slip_wheel_speed = 0;

       refresh_type |= SMOOTH_REFRESH;
diff --git a/src/perl/searchable-scrollback b/src/perl/searchable-scrollback

index dad36d98b55b3e791c06763945184e2dab748e5e..

index ..f89bcd2788833ec253c3a525a42d67046f11ca1b 100644

--- a/src/perl/searchable-scrollback
+++ b/src/perl/searchable-scrollback
@@ -81,7 +81,7 @@ sub search {

    no re 'eval'; # just to be sure
    if (my $re = eval { qr/$search/ }) {
-      while ($self->nrow > $row && $row > -$self->nsaved) {
+      while ($self->nrow > $row && $row > $self->top_row) {
          my $line = $self->line ($row)
             or last;

@@ -92,7 +92,7 @@ sub search {
             } while $text =~ /$re/g;

             $self->{row} = $row;
-            $self->view_start (List::Util::max 0, -$row + ($self->nrow >> 1));
+            $self->view_start (List::Util::min 0, $row - ($self->nrow >> 1));
             $self->want_refresh;
             last;
          }
@@ -138,7 +138,7 @@ sub key_press {
       $self->{row} = $self->nrow - 1;
       $self->view_start (0);
    } elsif ($keysym == 0xff52) { # up
-      $self->{row}-- if $self->{row} > -$self->nsaved;
+      $self->{row}-- if $self->{row} > $self->top_row;
       $self->search (-1);
    } elsif ($keysym == 0xff54) { # down
       $self->{row}++ if $self->{row} < $self->nrow;
diff --git a/src/rxvt.h b/src/rxvt.h

index 4faded65641da9cd7aea5abfc24ac00a7a40ae06..

index ..3d1e9babf810a47549762ff5ec73365eda3a9cd4 100644

--- a/src/rxvt.h
+++ b/src/rxvt.h
@@ -1535,9 +1535,9 @@ struct rxvt_term : zero_initialized, rxvt_vars {
   void set_font_style ();
   void scr_charset_choose (int set);
   void scr_charset_set (int set, unsigned int ch);
-  int scr_move_to (int y, int len);
-  int scr_page (enum page_dirn direction, int nlines);
-  int scr_changeview (unsigned int oldviewstart);
+  void scr_move_to (int y, int len);
+  bool scr_page (enum page_dirn direction, int nlines);
+  bool scr_changeview (int new_view_start);
   void scr_bell ();
   void scr_printscreen (int fullhist);
   void scr_xor_rect (int beg_row, int beg_col, int end_row, int end_col, rend_t rstyle1, rend_t rstyle2);
diff --git a/src/rxvtlib.h.in b/src/rxvtlib.h.in

index 0776c18ab03fe47d497c916bf4b1e7415d70fb3e..

index ..47039c69c56ba945712008988178de256936dbcc 100644

--- a/src/rxvtlib.h.in
+++ b/src/rxvtlib.h.in
@@ -92,10 +92,11 @@ struct line_t;
  *  ncol       : 1 <= ncol       <= MAX(tlen_t)
  *  nrow       : 1 <= nrow       <= MAX(int)
  *  saveLines  : 0 <= saveLines  <= MAX(int)
- *  total_rows : nrow + saveLines
- *  nsaved     : 0 <= nsaved     <= saveLines
  *  term_start : 0 <= term_start < saveLines
- *  view_start : 0 <= view_start < saveLines
+ *  total_rows : nrow + saveLines
+ *
+ *  top_row    : -saveLines <= top_row    <= 0
+ *  view_start : top_row    <= view_start <= 0
  *
  *          | most coordinates are stored relative to term_start,
  *  ROW_BUF | which is the first line of the terminal screen
@@ -103,9 +104,9 @@ struct line_t;
  *  |························= row_buf[1]
  *  |························= row_buf[2] etc.
  *  |
- *  +------------+···········= term_start - nsaved
+ *  +------------+···········= term_start + top_row
  *  | scrollback |
- *  | scrollback +---------+·= term_start - view_start
+ *  | scrollback +---------+·= term_start + view_start
  *  | scrollback | display |
  *  | scrollback | display |
  *  +------------+·display·+·= term_start
@@ -134,9 +135,9 @@ struct TermWin_t {
   int            lineSpace;     /* number of extra pixels between rows      */
   int            saveLines;     /* number of lines that fit in scrollback   */
   int            total_rows;    /* total number of rows in this terminal    */
-  int            nsaved;        /* number of rows saved to scrollback       */
   int            term_start;    /* term lines start here                    */
   int            view_start;    /* scrollback view starts here              */
+  int            top_row;       /* topmost row index of scrollback          */
   Window         parent[6];     /* parent identifiers - we're parent[0]     */
   Window         vt;            /* vt100 window                             */
   GC             gc;            /* GC for drawing                           */
diff --git a/src/rxvtperl.xs b/src/rxvtperl.xs

index bff6aee3904a6ad7377f8ff7116030ba3b727b93..

index ..e5afe1385063c4efacfbc7ab5f1160053a2b23aa 100644

--- a/src/rxvtperl.xs
+++ b/src/rxvtperl.xs
@@ -351,8 +351,8 @@ void overlay::swap ()
       text_t *t1 = text [y];
       rend_t *r1 = rend [y];

-      text_t *t2 = ROW(y + ov_y - THIS->view_start).t + ov_x;
-      rend_t *r2 = ROW(y + ov_y - THIS->view_start).r + ov_x;
+      text_t *t2 = ROW(y + ov_y + THIS->view_start).t + ov_x;
+      rend_t *r2 = ROW(y + ov_y + THIS->view_start).r + ov_x;

       for (int x = ov_w; x--; )
         {
@@ -450,6 +450,20 @@ ungrab (rxvt_term *THIS)
     }
 }

+static void
+swap_overlays (rxvt_term *term)
+{
+  HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0));
+
+  if (HvKEYS (hv))
+    {
+      hv_iterinit (hv);
+
+      while (HE *he = hv_iternext (hv))
+        ((overlay *)SvIV (hv_iterval (hv, he)))->swap ();
+    }
+}
+
 bool
 rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...)
 {
@@ -469,22 +483,16 @@ rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...)
     }
   else
     {
-      if (htype == HOOK_REFRESH_BEGIN || htype == HOOK_REFRESH_END)
-        {
-          HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0));
+      if (htype == HOOK_REFRESH_END)
+        swap_overlays (term);

-          if (HvKEYS (hv))
-            {
-              hv_iterinit (hv);
-
-              while (HE *he = hv_iternext (hv))
-                ((overlay *)SvIV (hv_iterval (hv, he)))->swap ();
-            }
+      if (!term->perl.should_invoke [htype])
+        {
+          if (htype == HOOK_REFRESH_BEGIN)
+            swap_overlays (term);

+          return false;
         }
-
-      if (!term->perl.should_invoke [htype])
-        return false;
     }

   swap (perl_environ, environ);
@@ -615,7 +623,9 @@ rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...)
                     ungrab (term); // better lose the grab than the session
                   }

-                if (htype == HOOK_DESTROY)
+                if (htype == HOOK_REFRESH_BEGIN)
+                  swap_overlays (term);
+                else if (htype == HOOK_DESTROY)
                   {
                     clearSVptr ((SV *)term->perl.self);
                     SvREFCNT_dec ((SV *)term->perl.self);
@@ -1101,7 +1111,7 @@ rxvt_term::locale_decode (SV *octets)
 #define TERM_OFFSET_mapped     TERM_OFFSET(mapped)
 #define TERM_OFFSET_saveLines  TERM_OFFSET(saveLines)
 #define TERM_OFFSET_total_rows TERM_OFFSET(total_rows)
-#define TERM_OFFSET_nsaved     TERM_OFFSET(nsaved)
+#define TERM_OFFSET_top_row    TERM_OFFSET(top_row)

 int
 rxvt_term::width ()
@@ -1117,7 +1127,7 @@ rxvt_term::width ()
            mapped     = TERM_OFFSET_mapped
            saveLines  = TERM_OFFSET_saveLines
            total_rows = TERM_OFFSET_total_rows
-           nsaved     = TERM_OFFSET_nsaved
+           top_row    = TERM_OFFSET_top_row
 	CODE:
         RETVAL = *(int *)((char *)THIS + ix);
         OUTPUT:
@@ -1211,17 +1221,14 @@ rxvt_term::rstyle (U32 new_rstyle = THIS->rstyle)
 	RETVAL

 int
-rxvt_term::view_start (int newval = -1)
+rxvt_term::view_start (int newval = 1)
 	PROTOTYPE: $;$
 	CODE:
 {
         RETVAL = THIS->view_start;

-        if (newval >= 0)
-          {
-            THIS->view_start = min (newval, THIS->nsaved);
-            THIS->scr_changeview (RETVAL);
-          }
+        if (newval <= 0)
+          THIS->scr_changeview (max (newval, THIS->top_row));
 }
         OUTPUT:
 	RETVAL
@@ -1235,7 +1242,7 @@ void
 rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS)
 	PPCODE:
 {
-        if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow))
+        if (!IN_RANGE_EXC (row_number, THIS->top_row, THIS->nrow))
           XSRETURN_EMPTY;

         line_t &l = ROW(row_number);
@@ -1278,7 +1285,7 @@ void
 rxvt_term::ROW_r (int row_number, SV *new_rend = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS)
 	PPCODE:
 {
-        if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow))
+        if (!IN_RANGE_EXC (row_number, THIS->top_row, THIS->nrow))
           XSRETURN_EMPTY;

         line_t &l = ROW(row_number);
@@ -1318,7 +1325,7 @@ int
 rxvt_term::ROW_l (int row_number, int new_length = -1)
 	CODE:
 {
-        if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow))
+        if (!IN_RANGE_EXC (row_number, THIS->top_row, THIS->nrow))
           XSRETURN_EMPTY;

         line_t &l = ROW(row_number);
@@ -1334,7 +1341,7 @@ bool
 rxvt_term::ROW_is_longer (int row_number, int new_is_longer = -1)
 	CODE:
 {
-        if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow))
+        if (!IN_RANGE_EXC (row_number, THIS->top_row, THIS->nrow))
           XSRETURN_EMPTY;

         line_t &l = ROW(row_number);
@@ -1534,7 +1541,7 @@ rxvt_term::screen_cur (...)

         if (items == 3)
           {
-            rc.row = clamp (SvIV (ST (1)), -THIS->nsaved, THIS->nrow - 1);
+            rc.row = clamp (SvIV (ST (1)), THIS->top_row, THIS->nrow - 1);
             rc.col = clamp (SvIV (ST (2)), 0, THIS->ncol - 1);

             if (ix)
diff --git a/src/screen.C b/src/screen.C

index 77d3575974fad8c522d02ded21048e2bd1bb3979..

index ..058e249a45d382ea28d615b0c99e180b55d12a03 100644

--- a/src/screen.C
+++ b/src/screen.C
@@ -181,7 +181,7 @@ rxvt_term::scr_reset ()
       //TODO//FIXME
       saveLines++;
       prev_nrow--;
-      nsaved++;
+      top_row--;
     }

   want_refresh = 1;
@@ -197,7 +197,7 @@ rxvt_term::scr_reset ()
       /*
        * first time called so just malloc everything: don't rely on realloc
        */
-      nsaved = 0;       /* no saved lines */
+      top_row = 0;       /* no saved lines */
       term_start = 0;

       talloc = new rxvt_salloc (ncol * sizeof (text_t));
@@ -278,10 +278,10 @@ rxvt_term::scr_reset ()
       row_buf = (line_t *)rxvt_calloc (total_rows + nrow, sizeof (line_t));

       int p    = MOD (term_start + prev_nrow, prev_total_rows);  // previous row
-      int pend = MOD (term_start - nsaved   , prev_total_rows);
+      int pend = MOD (term_start + top_row  , prev_total_rows);
       int q    = total_rows; // rewrapped row

-      if (nsaved)
+      if (top_row)
         {
           // re-wrap lines, this is rather ugly, possibly because I am too dumb
           // to come up with a lean and mean algorithm.
@@ -364,11 +364,11 @@ rxvt_term::scr_reset ()
           while (p != pend && q > 0);

           term_start = total_rows - nrow;
-          nsaved = term_start - q;
+          top_row = q - term_start;

           // make sure all terminal lines exist
-          while (nsaved < 0)
-            scr_blank_screen_mem (ROW (-++nsaved), DEFAULT_RSTYLE);
+          while (top_row > 0)
+            scr_blank_screen_mem (ROW (--top_row), DEFAULT_RSTYLE);
         }
       else
         {
@@ -392,7 +392,7 @@ rxvt_term::scr_reset ()
         }

 #ifdef DEBUG_STRICT //TODO: remove
-      for (int i = -nsaved; i < nrow; i++)
+      for (int i = top_row; i < nrow; i++)
         assert (ROW (i).t);
 #endif

@@ -617,9 +617,9 @@ rxvt_term::scr_scroll_text (int row1, int row2, int count)
       && row1 == 0
       && (current_screen == PRIMARY || OPTION (Opt_secondaryScroll)))
     {
-      nsaved = min (nsaved + count, saveLines);
+      top_row = max (top_row - count, -saveLines);

-      HOOK_INVOKE ((this, HOOK_SCROLL_BACK, DT_INT, count, DT_INT, nsaved, DT_END));
+      HOOK_INVOKE ((this, HOOK_SCROLL_BACK, DT_INT, count, DT_INT, top_row, DT_END));

       // scroll everything up 'count' lines
       term_start = (term_start + count) % total_rows;
@@ -663,9 +663,9 @@ rxvt_term::scr_scroll_text (int row1, int row2, int count)
           selection.end.row  -= count;
           selection.mark.row -= count;

-          if (selection.beg.row < -nsaved
-              || selection.end.row < -nsaved
-              || selection.mark.row < -nsaved)
+          if (selection.beg.row < top_row
+              || selection.end.row < top_row
+              || selection.mark.row < top_row)
             {
               CLEAR_ALL_SELECTION ();
               selection.op = SELECTION_CLEAR;
@@ -675,7 +675,7 @@ rxvt_term::scr_scroll_text (int row1, int row2, int count)
       // finally move the view window, if desired
       if (OPTION (Opt_scrollWithBuffer)
           && view_start != 0
-          && view_start != saveLines)
+          && view_start != -saveLines)
         scr_page (UP, count);
     }
   else
@@ -762,7 +762,7 @@ rxvt_term::scr_add_lines (const wchar_t *str, int len, int minlines)
 #ifdef DEBUG_STRICT
   assert (screen.cur.col < ncol);
   assert (screen.cur.row < nrow
-          && screen.cur.row >= -nsaved);
+          && screen.cur.row >= top_row);
 #endif
   int row = screen.cur.row;

@@ -1347,7 +1347,7 @@ rxvt_term::scr_erase_savelines ()
   want_refresh = 1;
   ZERO_SCROLLBACK ();

-  nsaved = 0;
+  top_row = 0;
 }
 #endif

@@ -1810,24 +1810,12 @@ rxvt_term::scr_touch (bool refresh)
  * Move the display so that the line represented by scrollbar value Y is at
  * the top of the screen
  */
-int
+void
 rxvt_term::scr_move_to (int y, int len)
 {
-  long p = 0;
-  unsigned int oldviewstart;
-
-  oldviewstart = view_start;
-
-  if (y < len)
-    {
-      p = (nrow + nsaved) * (len - y) / len;
-      p -= (long) (nrow - 1);
-      p = max (p, 0);
-    }
+  int p = (top_row - nrow) * (len - y) / len + (nrow - 1);

-  view_start = (unsigned int)min (p, nsaved);
-
-  return scr_changeview (oldviewstart);
+  scr_changeview (p);
 }

 /* ------------------------------------------------------------------------- */
@@ -1835,40 +1823,32 @@ rxvt_term::scr_move_to (int y, int len)
  * Page the screen up/down nlines
  * direction should be UP or DN
  */
-int
+bool
 rxvt_term::scr_page (enum page_dirn direction, int nlines)
 {
-  int n;
-  unsigned int oldviewstart;
-
-  oldviewstart = view_start;
-
-  if (direction == UP)
-    {
-      n = view_start + nlines;
-      view_start = min (n, nsaved);
-    }
-  else
-    {
-      n = view_start - nlines;
-      view_start = max (n, 0);
-    }
+  int new_view_start =
+    direction == UP ? view_start - nlines
+                    : view_start + nlines;

-  return scr_changeview (oldviewstart);
+  return scr_changeview (new_view_start);
 }

-int
-rxvt_term::scr_changeview (unsigned int oldviewstart)
+bool
+rxvt_term::scr_changeview (int new_view_start)
 {
-  if (view_start != oldviewstart)
+  clamp_it (new_view_start, top_row, 0);
+
+  if (new_view_start != view_start)
     {
+      num_scr += new_view_start - view_start;
+      view_start = new_view_start;
       HOOK_INVOKE ((this, HOOK_VIEW_CHANGE, DT_INT, view_start, DT_END));
-
       want_refresh = 1;
-      num_scr -= (view_start - oldviewstart);
-    }

-  return (int)view_start - (int)oldviewstart;
+      return true;
+    }
+  else
+    return false;
 }

 /* ------------------------------------------------------------------------- */
@@ -1911,13 +1891,13 @@ rxvt_term::scr_printscreen (int fullhist)

   if (fullhist)
     {
-      nrows = nrow + nsaved;
-      row_start = -nsaved;
+      nrows = nrow - top_row;
+      row_start = top_row;
     }
   else
     {
       nrows = nrow;
-      row_start = -view_start;
+      row_start = view_start;
     }

   wctomb (0, 0);
@@ -2055,7 +2035,7 @@ rxvt_term::scr_refresh (unsigned char refresh_type)
     setoldcursor = 0;
     if (ocrow != -1)
       {
-        if (screen.cur.row + view_start != ocrow
+        if (screen.cur.row - view_start != ocrow
             || screen.cur.col != oldcursor.col)
           {
             if (ocrow < nrow
@@ -2073,11 +2053,11 @@ rxvt_term::scr_refresh (unsigned char refresh_type)

     if (setoldcursor)
       {
-        if (screen.cur.row + view_start >= nrow)
+        if (screen.cur.row - view_start >= nrow)
           oldcursor.row = -1;
         else
           {
-            oldcursor.row = screen.cur.row + view_start;
+            oldcursor.row = screen.cur.row - view_start;
             oldcursor.col = screen.cur.col;
           }
       }
@@ -2109,7 +2089,7 @@ rxvt_term::scr_refresh (unsigned char refresh_type)
         {
           if (row + i >= 0 && row + i < nrow && row + i != ocrow)
             {
-              line_t s  = ROW(row - view_start);
+              line_t s  = ROW(view_start + row);
               line_t d  = drawn_buf[row];
               line_t d2 = drawn_buf[row + i];

@@ -2157,8 +2137,8 @@ rxvt_term::scr_refresh (unsigned char refresh_type)
    */
   for (row = 0; row < nrow; row++)
     {
-      text_t *stp = ROW(row - view_start).t;
-      rend_t *srp = ROW(row - view_start).r;
+      text_t *stp = ROW(view_start + row).t;
+      rend_t *srp = ROW(view_start + row).r;
       text_t *dtp = drawn_buf[row].t;
       rend_t *drp = drawn_buf[row].r;

@@ -2481,10 +2461,10 @@ rxvt_term::scr_clear (bool really)
 void
 rxvt_term::scr_xor_rect (int beg_row, int beg_col, int end_row, int end_col, rend_t rstyle1, rend_t rstyle2)
 {
-  int view_end = -view_start + nrow;
+  int view_end = view_start + nrow;
   int row, col;

-  for (row = max (beg_row, -view_start); row <= min (end_row, view_end); row++)
+  for (row = max (beg_row, view_start); row <= min (end_row, view_end); row++)
     {
       text_t *stp = ROW(row).t;
       rend_t *srp = ROW(row).r;
@@ -2503,10 +2483,10 @@ rxvt_term::scr_xor_rect (int beg_row, int beg_col, int end_row, int end_col, ren
 void
 rxvt_term::scr_xor_span (int beg_row, int beg_col, int end_row, int end_col, rend_t rstyle)
 {
-  int view_end = -view_start + nrow;
+  int view_end = view_start + nrow;
   int row, col;

-  if (beg_row >= -view_start)
+  if (beg_row >= view_start)
     {
       col = beg_col;
       row = beg_row;
@@ -2514,7 +2494,7 @@ rxvt_term::scr_xor_span (int beg_row, int beg_col, int end_row, int end_col, ren
   else
     {
       col = 0;
-      row = -view_start;
+      row = view_start;
     }

   for (; row < min (end_row, view_end); row++, col = 0)
@@ -2532,7 +2512,7 @@ rxvt_term::scr_reverse_selection ()
 {
   if (selection.op
       && current_screen == selection.screen
-      && selection.end.row >= -view_start)
+      && selection.end.row >= view_start)
     {
 #if ENABLE_FRILLS
       if (selection.rect)
@@ -2591,9 +2571,9 @@ rxvt_term::selection_check (int check_more)
     return;

   pos.row = pos.col = 0;
-  if (!IN_RANGE_EXC (selection.beg.row, -nsaved, nrow)
-      || !IN_RANGE_EXC (selection.mark.row, -nsaved, nrow)
-      || !IN_RANGE_EXC (selection.end.row, -nsaved, nrow)
+  if (!IN_RANGE_EXC (selection.beg.row, top_row, nrow)
+      || !IN_RANGE_EXC (selection.mark.row, top_row, nrow)
+      || !IN_RANGE_EXC (selection.end.row, top_row, nrow)
       || (check_more == 1
           && current_screen == selection.screen
           && !ROWCOL_IS_BEFORE (screen.cur, selection.beg)
@@ -3085,7 +3065,7 @@ rxvt_term::selection_click (int clicks, int x, int y)

   if (clicks == 2 || clicks == 3)
     selection_extend_colrow (selection.mark.col,
-                             selection.mark.row + view_start,
+                             selection.mark.row - view_start,
                              0, /* button 3     */
                              1, /* button press */
                              0);        /* click change */
@@ -3100,10 +3080,10 @@ rxvt_term::selection_start_colrow (int col, int row)
 {
   want_refresh = 1;

-  selection.mark.row = row - view_start;
+  selection.mark.row = row + view_start;
   selection.mark.col = col;

-  selection.mark.row = clamp (selection.mark.row, -nsaved, nrow - 1);
+  selection.mark.row = clamp (selection.mark.row, top_row, nrow - 1);
   selection.mark.col = clamp (selection.mark.col,       0, ncol - 1);

   while (selection.mark.col > 0
@@ -3141,7 +3121,7 @@ rxvt_term::selection_delimit_word (enum page_dirn dirn, const row_col_t *mark, r

   if (dirn == UP)
     {
-      bound.row = - nsaved - 1;
+      bound.row = top_row - 1;
       bound.col = 0;
       dirnadd = -1;
     }
@@ -3229,7 +3209,7 @@ rxvt_term::selection_extend (int x, int y, int flag)
   */
   if (((selection.clicks % 3) == 1) && !flag
       && (col == selection.mark.col
-          && (row == selection.mark.row + view_start)))
+          && (row == selection.mark.row - view_start)))
     {
       /* select nothing */
       selection.beg.row = selection.end.row = 0;
@@ -3294,7 +3274,7 @@ rxvt_term::selection_extend_colrow (int32_t col, int32_t row, int button3, int b
     }

   pos.col = col;
-  pos.row = row - view_start;
+  pos.row = view_start + row;

   /*
    * This is mainly xterm style selection with a couple of differences, mainly
@@ -3789,8 +3769,8 @@ rxvt_term::scr_swap_overlay ()
       text_t *t1 = ov_text[y];
       rend_t *r1 = ov_rend[y];

-      text_t *t2 = ROW(y + ov_y - view_start).t + ov_x;
-      rend_t *r2 = ROW(y + ov_y - view_start).r + ov_x;
+      text_t *t2 = ROW(y + ov_y + view_start).t + ov_x;
+      rend_t *r2 = ROW(y + ov_y + view_start).r + ov_x;

       for (int x = ov_w; x--; )
         {
diff --git a/src/scrollbar-next.C b/src/scrollbar-next.C

index 9131f4feb6db2b1b1ccbcca2b83f2d3cba995544..

index ..eddf37ef9c81d7f0b42109dc839f71acab071209 100644

--- a/src/scrollbar-next.C
+++ b/src/scrollbar-next.C
@@ -242,7 +242,7 @@ rxvt_term::scrollbar_show_next (int update, int last_top, int last_bot, int scro
       init_scrollbar_stuff ();
     }

-  if (nsaved == 0 || !update)
+  if (top_row == 0 || !update)
     {
       XFillRectangle (disp, scrollBar.win, grayGC, 0, 0,
                      SB_WIDTH_NEXT + 1, height);
@@ -253,7 +253,7 @@ rxvt_term::scrollbar_show_next (int update, int last_top, int last_bot, int scro
                      SB_LEFT_PADDING, 0, SB_BUTTON_WIDTH, height);
     }

-  if (nsaved)
+  if (top_row)
     {
       if (last_top < scrollBar.top || !update)
         XFillRectangle (disp, scrollBar.win, stippleGC,
diff --git a/src/scrollbar.C b/src/scrollbar.C

index 4e72080fd00f88769d489f08aec8f139c854c382..

index ..0a12edf777fc6c3e7445b25259b2f051e9dc0f61 100644

--- a/src/scrollbar.C
+++ b/src/scrollbar.C
@@ -155,9 +155,9 @@ rxvt_term::scrollbar_show (int update)

   if (update)
     {
-      top = nsaved - view_start;
+      top = view_start - top_row;
       bot = top + (nrow - 1);
-      len = max (nsaved + (nrow - 1), 1);
+      len = max (nrow - 1 - top_row, 1);
       adj = (((bot - top) * scrollbar_size ()) % len) > 0 ? 1 : 0;

       scrollBar.top = (scrollBar.beg + (top * scrollbar_size ()) / len);
diff --git a/src/urxvt.pm b/src/urxvt.pm

index 054f90295958f87834424776ea5b8ecca3328ef4..

index ..8d9c98e62af02dcad65dddb329528be69b739660 100644

--- a/src/urxvt.pm
+++ b/src/urxvt.pm
@@ -1184,7 +1184,7 @@ to receive pointer events all the times:

 =item $nrow_plus_saveLines = $term->total_rows

-=item $lines_in_scrollback = $term->nsaved
+=item $topmost_scrollback_row = $term->top_row

 Return various integers describing terminal characteristics.

@@ -1222,8 +1222,8 @@ AltGr), the meta key (often Alt) and the num lock key, if applicable.

 =item $view_start = $term->view_start ([$newvalue])

-Returns the negative row number of the topmost line. Minimum value is
-C<0>, which displays the normal terminal contents. Larger values scroll
+Returns the row number of the topmost displayed line. Maximum value is
+C<0>, which displays the normal terminal contents. Lower values scroll
 this many lines into the scrollback buffer.

 =item $term->want_refresh

-----END OF PAGE-----

-- Response ended

-- Page fetched on Sun Jun 2 11:25:12 2024