shithub: zuke

Download patch

ref: e62f9b68f8c6669be92c868688f72538f96350e9
parent: 8167a433d7023a864c8539df91a146f72c45004a
author: Sigrid Haflínudóttir <[email protected]>
date: Wed Jun 3 14:50:00 EDT 2020

make left/right mouse buttons work on scrollbar

--- a/zuke.c
+++ b/zuke.c
@@ -4,6 +4,9 @@
 #include <ctype.h>
 #include "plist.h"
 
+#define MAX(a,b) ((a)>=(b)?(a):(b))
+#define MIN(a,b) ((a)<=(b)?(a):(b))
+
 typedef struct Player Player;
 
 enum
@@ -905,6 +908,27 @@
 
 		switch(alt(a)){
 		case 0:
+			if(m.buttons != 2)
+				scrolling = 0;
+			if(m.buttons == 0)
+				break;
+
+			n = (m.xy.y - screen->r.min.y)/f->height;
+
+			if(oldbuttons == 0 && m.xy.x <= screen->r.min.x+Scrollwidth){
+				if(m.buttons == 1){
+					scroll = MAX(0, scroll-n-1);
+					redraw(1);
+					break;
+				}else if(m.buttons == 4){
+					scroll = MIN(scroll+n+1, plnum-scrollsz-1);
+					redraw(1);
+					break;
+				}else if(m.buttons == 2){
+					scrolling = 1;
+				}
+			}
+
 			if(m.buttons == 4){
 				n = menuhit(3, mctl, &menu3, nil);
 				if(n == 0)
@@ -913,25 +937,15 @@
 					goto end;
 				goto ev;
 			}
-			if(m.buttons != 2)
-				scrolling = 0;
-			else if(oldbuttons == 0 && m.xy.x <= screen->r.min.x+Scrollwidth)
-				scrolling = 1;
-			oldbuttons = m.buttons;
-			if(m.buttons == 0)
-				break;
 
 			if(scrolling){
 				if(scrollsz >= plnum)
 					break;
 				scroll = (m.xy.y - screen->r.min.y - Scrollheight/4)*(plnum-scrollsz) / (Dy(screen->r)-Scrollheight/2);
-				if(scroll > plnum-scrollsz-1)
-					scroll = plnum-scrollsz-1;
-				if(scroll < 0)
-					scroll = 0;
+				scroll = MAX(0, MIN(scroll, plnum-scrollsz-1));
 				redraw(1);
 			}else if(m.buttons == 1 || m.buttons == 2){
-				pcur = scroll + (m.xy.y - screen->r.min.y)/f->height;
+				pcur = scroll + n;
 				if(m.buttons == 2){
 					stop(playercurr);
 					playercurr = newplayer(pcur, 1);