Skip to content

Commit

Permalink
Autoscroll
Browse files Browse the repository at this point in the history
  • Loading branch information
Joseph Hallen committed Apr 2, 2005
1 parent 2f1602c commit 70651fb
Show file tree
Hide file tree
Showing 8 changed files with 169 additions and 16 deletions.
2 changes: 2 additions & 0 deletions ChangeLog
Expand Up @@ -4,6 +4,8 @@ Fri Apr 1 00:14:58 EST 2005

Fix ^X ^S bug (was using vsdup() on a non-dynamic string).

Add autoscrolling (when mouse goes past window edge).

Wed Mar 30 23:47:00 EST 2005

New xterm-patch fixes i18n problems with mouse.
Expand Down
6 changes: 6 additions & 0 deletions NEWS
Expand Up @@ -6,6 +6,12 @@ JOE 3.3

- Mouse can resize windows and select menu entries

- During selection with the mouse, window will autoscroll when
you go past the edge.

- An xterm-patch is included which makes "-mouse" mode work better. (With
the patch, also set "-joexterm").

JOE 3.2

- A Perforce SCM "p4 edit" macro has been supplied (along with the hooks
Expand Down
6 changes: 5 additions & 1 deletion TODO
Expand Up @@ -5,9 +5,13 @@ Short (infinite) list for 3.3:
- grep and grep-find commands
- smart-end key

-wrap: after it says "Not Found", it will keep saying this until you
start a new search.

Mouse issues:

- auto scroll when drag past edge
- autoscroll: keep track of selection type (double-click or triple-click)
- scroll window with right button down?

help screen mouse commands?
double-click at prompts hits enter?
Expand Down
22 changes: 22 additions & 0 deletions cmd.c
Expand Up @@ -458,6 +458,28 @@ int execmd(CMD *cmd, int k)
return ret;
}

extern int auto_scroll;

void do_auto_scroll()
{
static CMD *scrup = 0;
static CMD *scrdn = 0;
static CMD *drag = 0;
if (!scrup) {
scrup = findcmd(US "upslide");
scrdn = findcmd(US "dnslide");
drag = findcmd(US "defmdrag");
}
if (auto_scroll > 0)
execmd(scrdn,0);
else if (auto_scroll < 0)
execmd(scrup,0);

execmd(drag,0);

reset_trig_time();
}

/* Return command table index for given command name */

HASH *cmdhash = NULL;
Expand Down
1 change: 1 addition & 0 deletions cmd.h
Expand Up @@ -36,6 +36,7 @@ void addcmd PARAMS((unsigned char *s, MACRO *m));

/* Execute a command. Returns return value of command */
int execmd PARAMS((CMD *cmd, int k));
void do_auto_scroll();

extern B *cmdhist;

Expand Down
98 changes: 84 additions & 14 deletions mouse.c
Expand Up @@ -36,6 +36,10 @@ JOE; see the file COPYING. If not, write to the Free Software Foundation,
#include "utf8.h"
#include "mouse.h"

int auto_scroll = 0; /* Set for autoscroll */
int auto_rate; /* Rate */
int auto_trig_time; /* Time of next scroll */

int rtbutton=0; /* use button 3 instead of 1 */
int floatmouse=0; /* don't fix xcol after tomouse */
int joexterm=0; /* set if we're using Joe's modified xterm */
Expand Down Expand Up @@ -112,7 +116,7 @@ int uxtmouse(BW *bw)
return 0;
}

static int mnow()
int mnow()
{
struct timeval tv;
gettimeofday(&tv, NULL);
Expand Down Expand Up @@ -197,6 +201,7 @@ void select_done(struct charmap *map)
void mouseup(int x,int y)
{
struct timeval tv;
auto_scroll = 0;
Cx = x, Cy = y;
if (selecting) {
select_done(((BW *)maint->curwin->object)->b->o.charmap);
Expand Down Expand Up @@ -317,9 +322,13 @@ static int tomousestay()
{
BW *bw;
int x = Cx - 1,y = Cy - 1;
W *w = watpos(maint,x,y);
W *w;
/*
w = watpos(maint,x,y);
if(!w || w != maint->curwin)
return -1;
*/
w = maint->curwin;
bw = w->object;
if (w->watom->what == TYPETW) {
if (bw->o.hex) {
Expand All @@ -328,17 +337,27 @@ static int tomousestay()
long goal_byte;
if (goal_col < 0)
goal_col = 0;
if (goal_col >15)
if (goal_col > 15)
goal_col = 15;
/* window has a status line? */
if (((TW *)bw->object)->staon)
/* clicked on it? */
if (y == w->y) {
return -1;
if (y <= w->y) {
goal_col = 0;
goal_line = bw->top->byte/16;
} else if (y >= w->y + w->h) {
goal_line = bw->top->byte/16 + w->h - 2;
goal_col = 15;
} else
goal_line = y - w->y + bw->top->byte/16 - 1;
else
goal_line = y - w->y + bw->top->byte/16;
if (y < w->y) {
goal_col = 0;
goal_line = bw->top->byte/16;
} else if (y >= w->y + w->h) {
goal_line = bw->top->byte/16 + w->h - 1;
goal_col = 15;
} else
goal_line = y - w->y + bw->top->byte/16;
goal_byte = goal_line*16L + goal_col;
if (goal_byte > bw->b->eof->byte)
goal_byte = bw->b->eof->byte;
Expand All @@ -353,13 +372,23 @@ static int tomousestay()
goal_col = 0;
/* window has a status line? */
if (((TW *)bw->object)->staon)
/* clicked on it? */
if (y == w->y)
return -1;
else
if (y <= w->y) {
goal_col = 0;
goal_line = bw->top->line;
} else if (y >= w->y + w->h) {
goal_col = 1000;
goal_line = w->h + bw->top->line - 2;
} else
goal_line = y - w->y + bw->top->line - 1;
else
goal_line = y - w->y + bw->top->line;
if (y < w->y) {
goal_col = 0;
goal_line = bw->top->line;
} else if (y >= w->y + w->h) {
goal_col = 1000;
goal_line = w->h + bw->top->line - 1;
} else
goal_line = y - w->y + bw->top->line;
pline(bw->cursor, goal_line);
pcol(bw->cursor, goal_col);
tmspos = bw->cursor->xcol = goal_col;
Expand Down Expand Up @@ -393,11 +422,20 @@ int udefmdown(BW *xx)
marked = reversed = 0;
}

void reset_trig_time()
{
if (!auto_rate)
auto_rate = 1;
auto_trig_time = mnow() + 300 / (1 + auto_rate);
}

int udefmdrag(BW *xx)
{
BW *bw = (BW *)maint->curwin->object;
int ax = Cx - 1;
int ay = Cy - 1;
int new_scroll;
int new_rate;
if (drag_size) {
while (ay > bw->parent->y) {
int y = bw->parent->y;
Expand All @@ -413,6 +451,38 @@ int udefmdrag(BW *xx)
}
return 0;
}

if (ay < bw->y) {
new_scroll = -1;
new_rate = bw->y - ay;
}
else if (ay >= bw->y + bw->h) {
new_scroll = 1;
new_rate = ay - (bw->y + bw->h) + 1;
} else {
new_scroll = 0;
new_rate = 1;
}

if (new_rate > 10)
new_rate = 10;

if (!new_scroll)
auto_scroll = 0;
else if (new_scroll != auto_scroll) {
auto_scroll = new_scroll;
auto_rate = new_rate;
reset_trig_time();
} else if (new_rate != auto_rate) {
/*
int left = auto_trig_time - mnow();
if (left > 0) {
left = left * auto_rate / new_rate;
}
*/
auto_rate = new_rate;
}

if (!marked)
marked++, umarkb(bw);
if (tomousestay())
Expand Down Expand Up @@ -537,7 +607,7 @@ void mouseopen()
if (usexmouse) {
ttputs(US "\33[?1002h");
if (joexterm)
ttputs(US "\33[?2004h");
ttputs(US "\33[?2004h\33[?2007h");
ttflsh();
}
#endif
Expand All @@ -548,7 +618,7 @@ void mouseclose()
#ifdef MOUSE_XTERM
if (usexmouse) {
if (joexterm)
ttputs(US "\33[?2004l");
ttputs(US "\33[?2007l\33[?2004l");
ttputs(US "\33[?1002l");
ttflsh();
}
Expand Down
3 changes: 3 additions & 0 deletions mouse.h
Expand Up @@ -55,6 +55,9 @@ int udefm3down(BW *);
int udefm3up(BW *);
int udefm3drag(BW *);

int mnow();
void reset_trig_time();

/* options */
extern int floatmouse, rtbutton;

Expand Down
47 changes: 46 additions & 1 deletion tty.c
Expand Up @@ -97,6 +97,8 @@ int idleout = 1;
#include "path.h"
#include "tty.h"
#include "utils.h"
#include "mouse.h"
#include "cmd.h"

/** Aliased defines **/

Expand Down Expand Up @@ -270,16 +272,50 @@ static RETSIGTYPE dotick(int unused)
ticked = 1;
}

extern int auto_scroll;

void tickoff(void)
{
#ifdef HAVE_SETITIMER
struct itimerval val;
val.it_value.tv_sec = 0;
val.it_value.tv_usec = 0;
val.it_interval.tv_sec = 0;
val.it_interval.tv_usec = 0;
setitimer(ITIMER_REAL,&val,NULL);
#else
alarm(0);
#endif
}

extern int auto_scroll;
extern int auto_trig_time;

void tickon(void)
{
#ifdef HAVE_SETITIMER
struct itimerval val;
val.it_interval.tv_sec = 0;
val.it_interval.tv_usec = 0;
if (auto_scroll) {
int tim = auto_trig_time - mnow();
if (tim < 0)
tim = 1;
tim *= 1000;
val.it_value.tv_sec = 0;
val.it_value.tv_usec = tim;
} else {
val.it_value.tv_sec = 1;
val.it_value.tv_usec = 0;
}
ticked = 0;
joe_set_signal(SIGALRM, dotick);
setitimer(ITIMER_REAL,&val,NULL);
#else
ticked = 0;
joe_set_signal(SIGALRM, dotick);
alarm(1);
#endif
}

/* Open terminal */
Expand Down Expand Up @@ -571,25 +607,34 @@ int ttgetc(void)
{
int stat;
long new_time;
int flg;


tickon();

loop:
flg = 0;
/* Status line clock */
new_time = time(NULL);
if (new_time != last_time) {
last_time = new_time;
dostaupd = 1;
ticked = 1;
}
/* Autoscroller */
if (auto_scroll && mnow() >= auto_trig_time) {
do_auto_scroll();
ticked = 1;
flg = 1;
}
ttflsh();
while (winched) {
winched = 0;
edupd(1);
ttflsh();
}
if (ticked) {
edupd(0);
edupd(flg);
ttflsh();
tickon();
}
Expand Down

0 comments on commit 70651fb

Please sign in to comment.