unsticky scrollbars
scrollbars used to put the mouse on the scrollbar while scrolling. if latency is high, this often results to the cursor jumping back. instead, make button 2 srolling work without needing the mouse to be inside the scrollbar and leave the mouse position alone.
This commit is contained in:
parent
cdc0b89d81
commit
1df707a0b2
4 changed files with 41 additions and 63 deletions
|
@ -108,11 +108,10 @@ textscroll(Text *t, int but)
|
||||||
{
|
{
|
||||||
uint p0, oldp0;
|
uint p0, oldp0;
|
||||||
Rectangle s;
|
Rectangle s;
|
||||||
int x, y, my, h, first;
|
int y, my, h, first;
|
||||||
|
|
||||||
s = insetrect(t->scrollr, 1);
|
s = insetrect(t->scrollr, 1);
|
||||||
h = s.max.y-s.min.y;
|
h = s.max.y-s.min.y;
|
||||||
x = (s.min.x+s.max.x)/2;
|
|
||||||
oldp0 = ~0;
|
oldp0 = ~0;
|
||||||
first = TRUE;
|
first = TRUE;
|
||||||
do{
|
do{
|
||||||
|
@ -122,10 +121,6 @@ textscroll(Text *t, int but)
|
||||||
my = s.min.y;
|
my = s.min.y;
|
||||||
if(my >= s.max.y)
|
if(my >= s.max.y)
|
||||||
my = s.max.y;
|
my = s.max.y;
|
||||||
if(!eqpt(mouse->xy, Pt(x, my))){
|
|
||||||
moveto(mousectl, Pt(x, my));
|
|
||||||
readmouse(mousectl); /* absorb event generated by moveto() */
|
|
||||||
}
|
|
||||||
if(but == 2){
|
if(but == 2){
|
||||||
y = my;
|
y = my;
|
||||||
p0 = (vlong)t->rs.nr*(y-s.min.y)/h;
|
p0 = (vlong)t->rs.nr*(y-s.min.y)/h;
|
||||||
|
@ -240,10 +235,12 @@ pagescroll(Page *p, int but, int horizontal)
|
||||||
else
|
else
|
||||||
m = mouse->xy.y;
|
m = mouse->xy.y;
|
||||||
|
|
||||||
if(m > om)
|
if(but != 2){
|
||||||
m += (m-om)*Panspeed;
|
if(m > om)
|
||||||
else if(m < om)
|
m += (m-om)*Panspeed;
|
||||||
m -= (om-m)*Panspeed;
|
else if(m < om)
|
||||||
|
m -= (om-m)*Panspeed;
|
||||||
|
}
|
||||||
|
|
||||||
if(m < smin)
|
if(m < smin)
|
||||||
m = smin;
|
m = smin;
|
||||||
|
@ -255,10 +252,6 @@ pagescroll(Page *p, int but, int horizontal)
|
||||||
mxy = Pt(m, i);
|
mxy = Pt(m, i);
|
||||||
else
|
else
|
||||||
mxy = Pt(i, m);
|
mxy = Pt(i, m);
|
||||||
if(!eqpt(mouse->xy, mxy)){
|
|
||||||
moveto(mousectl, mxy);
|
|
||||||
readmouse(mousectl); /* absorb event generated by moveto() */
|
|
||||||
}
|
|
||||||
if(but == 2){
|
if(but == 2){
|
||||||
p0 = muldiv(m-smin, size, ss);
|
p0 = muldiv(m-smin, size, ss);
|
||||||
p0 = max(p0, 0);
|
p0 = max(p0, 0);
|
||||||
|
|
|
@ -108,11 +108,10 @@ textscroll(Text *t, int but)
|
||||||
{
|
{
|
||||||
uint p0, oldp0;
|
uint p0, oldp0;
|
||||||
Rectangle s;
|
Rectangle s;
|
||||||
int x, y, my, h, first;
|
int y, my, h, first;
|
||||||
|
|
||||||
s = insetrect(t->scrollr, 1);
|
s = insetrect(t->scrollr, 1);
|
||||||
h = s.max.y-s.min.y;
|
h = s.max.y-s.min.y;
|
||||||
x = (s.min.x+s.max.x)/2;
|
|
||||||
oldp0 = ~0;
|
oldp0 = ~0;
|
||||||
first = TRUE;
|
first = TRUE;
|
||||||
do{
|
do{
|
||||||
|
@ -122,10 +121,6 @@ textscroll(Text *t, int but)
|
||||||
my = s.min.y;
|
my = s.min.y;
|
||||||
if(my >= s.max.y)
|
if(my >= s.max.y)
|
||||||
my = s.max.y;
|
my = s.max.y;
|
||||||
if(!eqpt(mouse->xy, Pt(x, my))){
|
|
||||||
moveto(mousectl, Pt(x, my));
|
|
||||||
readmouse(mousectl); /* absorb event generated by moveto() */
|
|
||||||
}
|
|
||||||
if(but == 2){
|
if(but == 2){
|
||||||
y = my;
|
y = my;
|
||||||
p0 = (vlong)t->file->nc*(y-s.min.y)/h;
|
p0 = (vlong)t->file->nc*(y-s.min.y)/h;
|
||||||
|
|
|
@ -135,48 +135,40 @@ wscroll(Window *w, int but)
|
||||||
first = TRUE;
|
first = TRUE;
|
||||||
do{
|
do{
|
||||||
flushimage(display, 1);
|
flushimage(display, 1);
|
||||||
if(w->mc.xy.x<s.min.x || s.max.x<=w->mc.xy.x){
|
my = w->mc.xy.y;
|
||||||
readmouse(&w->mc);
|
if(my < s.min.y)
|
||||||
}else{
|
my = s.min.y;
|
||||||
my = w->mc.xy.y;
|
if(my >= s.max.y)
|
||||||
if(my < s.min.y)
|
my = s.max.y;
|
||||||
my = s.min.y;
|
if(but == 2){
|
||||||
if(my >= s.max.y)
|
y = my;
|
||||||
my = s.max.y;
|
if(y > s.max.y-2)
|
||||||
if(!eqpt(w->mc.xy, Pt(x, my))){
|
y = s.max.y-2;
|
||||||
wmovemouse(w, Pt(x, my));
|
if(w->nr > 1024*1024)
|
||||||
readmouse(&w->mc); /* absorb event generated by moveto() */
|
p0 = ((w->nr>>10)*(y-s.min.y)/h)<<10;
|
||||||
}
|
|
||||||
if(but == 2){
|
|
||||||
y = my;
|
|
||||||
if(y > s.max.y-2)
|
|
||||||
y = s.max.y-2;
|
|
||||||
if(w->nr > 1024*1024)
|
|
||||||
p0 = ((w->nr>>10)*(y-s.min.y)/h)<<10;
|
|
||||||
else
|
|
||||||
p0 = w->nr*(y-s.min.y)/h;
|
|
||||||
if(oldp0 != p0)
|
|
||||||
wsetorigin(w, p0, FALSE);
|
|
||||||
oldp0 = p0;
|
|
||||||
readmouse(&w->mc);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if(but == 1)
|
|
||||||
p0 = wbacknl(w, w->org, (my-s.min.y)/w->font->height);
|
|
||||||
else
|
else
|
||||||
p0 = w->org+frcharofpt(w, Pt(s.max.x, my));
|
p0 = w->nr*(y-s.min.y)/h;
|
||||||
if(oldp0 != p0)
|
if(oldp0 != p0)
|
||||||
wsetorigin(w, p0, TRUE);
|
wsetorigin(w, p0, FALSE);
|
||||||
oldp0 = p0;
|
oldp0 = p0;
|
||||||
/* debounce */
|
readmouse(&w->mc);
|
||||||
if(first){
|
continue;
|
||||||
flushimage(display, 1);
|
|
||||||
sleep(200);
|
|
||||||
nbrecv(w->mc.c, &w->mc.Mouse);
|
|
||||||
first = FALSE;
|
|
||||||
}
|
|
||||||
wscrsleep(w, 100);
|
|
||||||
}
|
}
|
||||||
|
if(but == 1)
|
||||||
|
p0 = wbacknl(w, w->org, (my-s.min.y)/w->font->height);
|
||||||
|
else
|
||||||
|
p0 = w->org+frcharofpt(w, Pt(s.max.x, my));
|
||||||
|
if(oldp0 != p0)
|
||||||
|
wsetorigin(w, p0, TRUE);
|
||||||
|
oldp0 = p0;
|
||||||
|
/* debounce */
|
||||||
|
if(first){
|
||||||
|
flushimage(display, 1);
|
||||||
|
sleep(200);
|
||||||
|
nbrecv(w->mc.c, &w->mc.Mouse);
|
||||||
|
first = FALSE;
|
||||||
|
}
|
||||||
|
wscrsleep(w, 100);
|
||||||
}while(w->mc.buttons & (1<<(but-1)));
|
}while(w->mc.buttons & (1<<(but-1)));
|
||||||
while(w->mc.buttons)
|
while(w->mc.buttons)
|
||||||
readmouse(&w->mc);
|
readmouse(&w->mc);
|
||||||
|
|
|
@ -120,10 +120,10 @@ scroll(Flayer *l, int but)
|
||||||
draw(scrback, Rect(0,0,Dx(l->scroll), Dy(l->scroll)), l->f.b, nil, l->scroll.min);
|
draw(scrback, Rect(0,0,Dx(l->scroll), Dy(l->scroll)), l->f.b, nil, l->scroll.min);
|
||||||
do{
|
do{
|
||||||
oin = in;
|
oin = in;
|
||||||
in = abs(x-mousep->xy.x)<=FLSCROLLWID/2;
|
in = (but > 3) || (but == 2) || abs(x-mousep->xy.x)<=FLSCROLLWID/2;
|
||||||
if(oin && !in)
|
if(oin && !in)
|
||||||
scrunmark(l, r);
|
scrunmark(l, r);
|
||||||
if(but > 3 || in){
|
if(in){
|
||||||
scrmark(l, r);
|
scrmark(l, r);
|
||||||
oy = y;
|
oy = y;
|
||||||
my = mousep->xy.y;
|
my = mousep->xy.y;
|
||||||
|
@ -131,8 +131,6 @@ scroll(Flayer *l, int but)
|
||||||
my = s.min.y;
|
my = s.min.y;
|
||||||
if(my >= s.max.y)
|
if(my >= s.max.y)
|
||||||
my = s.max.y;
|
my = s.max.y;
|
||||||
if(in && !eqpt(mousep->xy, Pt(x, my)))
|
|
||||||
moveto(mousectl, Pt(x, my));
|
|
||||||
if(but == 1 || but == 4){
|
if(but == 1 || but == 4){
|
||||||
p0 = l->origin-frcharofpt(&l->f, Pt(s.max.x, my));
|
p0 = l->origin-frcharofpt(&l->f, Pt(s.max.x, my));
|
||||||
rt = scrpos(l->scroll, p0, p0+l->f.nchars, tot);
|
rt = scrpos(l->scroll, p0, p0+l->f.nchars, tot);
|
||||||
|
@ -153,7 +151,7 @@ scroll(Flayer *l, int but)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}while(but <= 3 && button(but));
|
}while(but <= 3 && button(but));
|
||||||
if(but > 3 || in){
|
if(in){
|
||||||
h = s.max.y-s.min.y;
|
h = s.max.y-s.min.y;
|
||||||
scrunmark(l, r);
|
scrunmark(l, r);
|
||||||
p0 = 0;
|
p0 = 0;
|
||||||
|
|
Loading…
Reference in a new issue