ref: 1df707a0b2aaddb750fb707ae413dc67a19027a3
parent: cdc0b89d816aab6322e04f715019a7f8da2f2b75
author: cinap_lenrek <[email protected]>
date: Sun Aug 4 20:25:40 EDT 2013
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.
--- a/sys/src/cmd/abaco/scrl.c
+++ b/sys/src/cmd/abaco/scrl.c
@@ -108,11 +108,10 @@
{
uint p0, oldp0;
Rectangle s;
- int x, y, my, h, first;
+ int y, my, h, first;
s = insetrect(t->scrollr, 1);
h = s.max.y-s.min.y;
- x = (s.min.x+s.max.x)/2;
oldp0 = ~0;
first = TRUE;
do{
@@ -122,10 +121,6 @@
my = s.min.y;
if(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){
y = my;
p0 = (vlong)t->rs.nr*(y-s.min.y)/h;
@@ -240,10 +235,12 @@
else
m = mouse->xy.y;
- if(m > om)
- m += (m-om)*Panspeed;
- else if(m < om)
- m -= (om-m)*Panspeed;
+ if(but != 2){
+ if(m > om)
+ m += (m-om)*Panspeed;
+ else if(m < om)
+ m -= (om-m)*Panspeed;
+ }
if(m < smin)
m = smin;
@@ -255,10 +252,6 @@
mxy = Pt(m, i);
else
mxy = Pt(i, m);
- if(!eqpt(mouse->xy, mxy)){
- moveto(mousectl, mxy);
- readmouse(mousectl); /* absorb event generated by moveto() */
- }
if(but == 2){
p0 = muldiv(m-smin, size, ss);
p0 = max(p0, 0);
--- a/sys/src/cmd/acme/scrl.c
+++ b/sys/src/cmd/acme/scrl.c
@@ -108,11 +108,10 @@
{
uint p0, oldp0;
Rectangle s;
- int x, y, my, h, first;
+ int y, my, h, first;
s = insetrect(t->scrollr, 1);
h = s.max.y-s.min.y;
- x = (s.min.x+s.max.x)/2;
oldp0 = ~0;
first = TRUE;
do{
@@ -122,10 +121,6 @@
my = s.min.y;
if(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){
y = my;
p0 = (vlong)t->file->nc*(y-s.min.y)/h;
--- a/sys/src/cmd/rio/scrl.c
+++ b/sys/src/cmd/rio/scrl.c
@@ -135,48 +135,40 @@
first = TRUE;
do{
flushimage(display, 1);
- if(w->mc.xy.x<s.min.x || s.max.x<=w->mc.xy.x){
- readmouse(&w->mc);
- }else{
- my = w->mc.xy.y;
- if(my < s.min.y)
- my = s.min.y;
- if(my >= s.max.y)
- my = s.max.y;
- if(!eqpt(w->mc.xy, Pt(x, my))){
- wmovemouse(w, Pt(x, my));
- readmouse(&w->mc); /* absorb event generated by moveto() */
- }
- 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);
+ my = w->mc.xy.y;
+ if(my < s.min.y)
+ my = s.min.y;
+ if(my >= s.max.y)
+ my = s.max.y;
+ 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->org+frcharofpt(w, Pt(s.max.x, my));
+ p0 = w->nr*(y-s.min.y)/h;
if(oldp0 != p0)
- wsetorigin(w, p0, TRUE);
+ wsetorigin(w, p0, FALSE);
oldp0 = p0;
- /* debounce */
- if(first){
- flushimage(display, 1);
- sleep(200);
- nbrecv(w->mc.c, &w->mc.Mouse);
- first = FALSE;
- }
- wscrsleep(w, 100);
+ readmouse(&w->mc);
+ continue;
}
+ 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)
readmouse(&w->mc);
--- a/sys/src/cmd/samterm/scroll.c
+++ b/sys/src/cmd/samterm/scroll.c
@@ -120,10 +120,10 @@
draw(scrback, Rect(0,0,Dx(l->scroll), Dy(l->scroll)), l->f.b, nil, l->scroll.min);
do{
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)
scrunmark(l, r);
- if(but > 3 || in){
+ if(in){
scrmark(l, r);
oy = y;
my = mousep->xy.y;
@@ -131,8 +131,6 @@
my = s.min.y;
if(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){
p0 = l->origin-frcharofpt(&l->f, Pt(s.max.x, my));
rt = scrpos(l->scroll, p0, p0+l->f.nchars, tot);
@@ -153,7 +151,7 @@
}
}
}while(but <= 3 && button(but));
- if(but > 3 || in){
+ if(in){
h = s.max.y-s.min.y;
scrunmark(l, r);
p0 = 0;