ref: 49eb490914a8cda35cf1320981ebf7beaea8d79a
parent: 62c8c846fb32c99ed496fbda8c4baa46dcb42549
author: phil9 <[email protected]>
date: Sun Jan 28 15:51:54 EST 2024
fix scrolling issues scrolling using the scrollbar was behaving weirdly with the menu showing when leaving the scrollbar rectangle and keeping the button pressed.
--- a/vexed.c
+++ b/vexed.c
@@ -71,6 +71,8 @@
Rectangle scrollr;
Rectangle viewr;
Rectangle statusr;
+int scrolling;
+int lastbuttons;
int nlines;
int offset;
int sel = 0;
@@ -486,6 +488,15 @@
flushimage(display, 1);
}
+void
+clampoffset(void)
+{
+ if(offset < 0)
+ offset = 0;
+ if(offset + blines%nlines >= blines)
+ offset = blines - blines%nlines;
+}
+
int
scroll(int lines)
{
@@ -497,10 +508,7 @@
return 0;
}
offset += lines;
- if(offset < 0)
- offset = 0;
- if(offset + blines%nlines >= blines)
- offset = blines - blines%nlines;
+ clampoffset();
sel += lines * 16;
if(sel < 0)
sel = 0;
@@ -593,13 +601,17 @@
{
int n;
- if(ptinrect(m->xy, scrollr)){
+ if(lastbuttons == 0 && m->buttons != 0 && ptinrect(m->xy, scrollr))
+ scrolling = 1;
+ else if(m->buttons == 0)
+ scrolling = 0;
+ if(scrolling){
if(m->buttons == 1){
n = (m->xy.y - scrollr.min.y) / font->height;
scroll(-n);
}else if(m->buttons == 2){
- n = (m->xy.y - scrollr.min.y) * blines / Dy(scrollr);
- offset = n;
+ offset = (m->xy.y - scrollr.min.y) * blines / Dy(scrollr);
+ clampoffset();
sel = offset*16;
redraw();
}else if(m->buttons == 4){
@@ -631,6 +643,7 @@
scroll(scrollsize);
}
}
+ lastbuttons = m->buttons;
}
void
@@ -799,6 +812,8 @@
};
int reverse;
+ scrolling = 0;
+ lastbuttons = 0;
reverse = 0;
ARGBEGIN{
case 'b':