shithub: vdir

Download patch

ref: aaea83de4f6eddc62dbcdedc69a70e08a5db7e5f
parent: e3d75ecc0a3305126ed697789cc16df264c5939d
author: phil9 <telephil9@gmail.com>
date: Tue May 11 14:54:10 EDT 2021

handle mouse clicks on scrollbar

	scrollbar now reacts to mouse clicks like any standard 9 application.
	mouse 1 and 3 scroll up and down respectively with the scroll speed based
	on where the click occurs in the scrollbar (the lower the faster and vice versa)
	mouse 2 moves the scroll position to where the click occurs

--- a/vdir.c	Fri Apr  2 13:39:15 2021
+++ b/vdir.c	Tue May 11 14:54:10 2021
@@ -386,11 +386,23 @@
 void
 evtmouse(Mouse m)
 {
-	int n;
+	int n, dy;
 	Dir d;
 	char buf[256] = {0};
 
-	if(m.buttons&4){
+	if(m.buttons&1){
+		if(ptinrect(m.xy, scrollr)){
+			dy = 1+nlines*((double)(m.xy.y - scrollr.min.y)/Dy(scrollr));
+			scrollup(dy);
+		}
+	}else if(m.buttons&2){
+		if(ptinrect(m.xy, scrollr)){
+			if(nlines<ndirs){
+				offset = (m.xy.y - scrollr.min.y) * ndirs/Dy(scrollr);
+				redraw();
+			}
+		}
+	}if(m.buttons&4){
 		if(ptinrect(m.xy, homer)){
 			cd(nil);
 			redraw();
@@ -425,6 +437,9 @@
 				redraw();
 			}else
 				plumbfile(path, d.name);
+		}else if(ptinrect(m.xy, scrollr)){
+			dy = 1+nlines*((double)(m.xy.y - scrollr.min.y)/Dy(scrollr));
+			scrolldown(dy);
 		}
 	}else if(m.buttons&8)
 		scrollup(Slowscroll);