shithub: nc

Download patch

ref: 1c0fa9831213db402235433ce9fdbbb2fa8a5356
parent: caaa98b02b1ac6ccf94b9c0cb6e27a8c9a87f631
author: phil9 <telephil9@gmail.com>
date: Thu Dec 29 18:27:52 EST 2022

add support for changing the selected file with the mouse

--- a/dirpanel.c
+++ b/dirpanel.c
@@ -176,8 +176,19 @@
 }
 
 void
-dirpanelemouse(Dirpanel*, Mouse)
+dirpanelemouse(Dirpanel *p, Mouse m)
 {
+	Point pt;
+	int n;
+
+	pt = subpt(m.xy, screen->r.min);
+	if((m.buttons&1) && ptinrect(pt, p->filesr)){
+		n = (pt.y - p->filesr.min.y) / (font->height+2);
+		if(n != p->cursor && n < p->nlines){
+			p->cursor = n;
+			dirpanelredrawnotify(p);
+		}
+	}
 }
 
 void
--- a/dirview.c
+++ b/dirview.c
@@ -54,6 +54,10 @@
 	if((ptinrect(m.xy, v->leftp->r) && !v->leftp->focused) 
 	|| (ptinrect(m.xy, v->rightp->r) && !v->rightp->focused))
 		switchfocus(v);
+	if(ptinrect(m.xy, v->leftp->r) && v->leftp->focused)
+		dirpanelemouse(v->leftp, m);
+	else if(ptinrect(m.xy, v->rightp->r) && v->rightp->focused)
+		dirpanelemouse(v->rightp, m);
 }
 
 Dirview*