aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBoris Faure <billiob@gmail.com>2016-11-20 18:23:56 +0100
committerBoris Faure <billiob@gmail.com>2016-11-20 18:23:56 +0100
commitc47b0c39d5930dc82927a890e1e833df35835c62 (patch)
tree3c9fa41f450a5cc35355853ac24a8d93c1c58700
parentmouse wheel on tab counter: fix navigation (diff)
downloadterminology-c47b0c39d5930dc82927a890e1e833df35835c62.tar.gz
scrolling: fix issues with the beacon
Add a few comments on how it works
-rw-r--r--src/bin/termpty.c76
-rw-r--r--src/bin/termpty.h2
2 files changed, 48 insertions, 30 deletions
diff --git a/src/bin/termpty.c b/src/bin/termpty.c
index eaf6a41..32f01b4 100644
--- a/src/bin/termpty.c
+++ b/src/bin/termpty.c
@@ -845,21 +845,18 @@ termpty_backscroll_adjust(Termpty *ty, int *scroll)
Termsave *ts;
ts = BACKLOG_ROW_GET(ty, backlog_y);
- if (*scroll <= screen_y)
- {
- return;
- }
if (!ts->cells || backlog_y >= (int)ty->backsize)
{
*scroll = ty->backlog_beacon.screen_y;
return;
}
-
nb_lines = (ts->w == 0) ? 1 : (ts->w + ty->w - 1) / ty->w;
ty->backlog_beacon.screen_y = screen_y;
ty->backlog_beacon.backlog_y = backlog_y;
screen_y += nb_lines;
backlog_y++;
+ if (*scroll <= screen_y)
+ return;
}
}
@@ -868,50 +865,69 @@ _termpty_cellrow_from_beacon_get(Termpty *ty, int requested_y, ssize_t *wret)
{
int backlog_y = ty->backlog_beacon.backlog_y;
int screen_y = ty->backlog_beacon.screen_y;
- Eina_Bool going_forward = EINA_TRUE;
+ Termsave *ts;
+ int nb_lines;
requested_y = -requested_y;
/* check if going from 0,0 is faster than using the beacon */
if (screen_y - requested_y > requested_y)
{
- backlog_y = 1;
- screen_y = 1;
+ ty->backlog_beacon.backlog_y = 0;
+ ty->backlog_beacon.screen_y = 0;
}
- while (42) {
- Termsave *ts;
- int nb_lines;
+ /* going upward */
+ while (requested_y >= screen_y)
+ {
ts = BACKLOG_ROW_GET(ty, backlog_y);
- if (!ts->cells)
- return NULL;
+ if (!ts->cells || backlog_y >= (int)ty->backsize)
+ {
+ return NULL;
+ }
nb_lines = (ts->w == 0) ? 1 : (ts->w + ty->w - 1) / ty->w;
- if (!going_forward) {
- screen_y -= nb_lines;
- }
- if ((screen_y <= requested_y) && (requested_y < screen_y + nb_lines))
+ ty->backlog_beacon.screen_y = screen_y;
+ ty->backlog_beacon.backlog_y = backlog_y;
+
+ if ((screen_y - nb_lines < requested_y) && (requested_y <= screen_y))
{
- int delta = screen_y + nb_lines - 1 - requested_y;
+ /* found the line */
+ int delta = screen_y - requested_y;
*wret = ts->w - delta * ty->w;
if (*wret > ts->w)
*wret = ts->w;
- ty->backlog_beacon.screen_y = screen_y;
- ty->backlog_beacon.backlog_y = backlog_y;
return &ts->cells[delta * ty->w];
}
-
- if (requested_y > screen_y)
+ screen_y += nb_lines;
+ backlog_y++;
+ }
+ /* else, going downward */
+ while (requested_y <= screen_y)
+ {
+ ts = BACKLOG_ROW_GET(ty, backlog_y);
+ if (!ts->cells)
{
- screen_y += nb_lines;
- backlog_y++;
+ return NULL;
}
- else
+ nb_lines = (ts->w == 0) ? 1 : (ts->w + ty->w - 1) / ty->w;
+
+ ty->backlog_beacon.screen_y = screen_y;
+ ty->backlog_beacon.backlog_y = backlog_y;
+
+
+ if ((screen_y - nb_lines < requested_y) && (requested_y <= screen_y))
{
- backlog_y--;
- going_forward = EINA_FALSE;
+ /* found the line */
+ int delta = screen_y - requested_y;
+ *wret = ts->w - delta * ty->w;
+ if (*wret > ts->w)
+ *wret = ts->w;
+ return &ts->cells[delta * ty->w];
}
- }
+ screen_y -= nb_lines;
+ backlog_y--;
+ }
return NULL;
}
@@ -1165,8 +1181,8 @@ termpty_resize(Termpty *ty, int new_w, int new_h)
termpty_backlog_unlock();
- ty->backlog_beacon.backlog_y = 1;
- ty->backlog_beacon.screen_y = 1;
+ ty->backlog_beacon.backlog_y = 0;
+ ty->backlog_beacon.screen_y = 0;
return;
diff --git a/src/bin/termpty.h b/src/bin/termpty.h
index 6de51ba..3573dbe 100644
--- a/src/bin/termpty.h
+++ b/src/bin/termpty.h
@@ -96,6 +96,8 @@ struct _Termpty
unsigned char oldbuf[4];
Termsave *back;
size_t backsize, backpos;
+ /* this beacon in the backlog tells about the top line in screen
+ * coordinates that maps to a line in the backlog */
struct {
int screen_y;
int backlog_y;