summaryrefslogtreecommitdiffstats
path: root/x.c
diff options
context:
space:
mode:
authorsalmonik <raisersoft@proton.me>2026-04-28 17:51:33 +0200
committersalmonik <raisersoft@proton.me>2026-04-28 17:51:33 +0200
commit1c9fbd0059d93b6dd57837020f3ef951a729acbb (patch)
tree8450dcbb0a5e8937c3e65ea20461a9df24cb6c76 /x.c
parentadd a .gitignore (diff)
downloadst-master.tar.gz
st-master.zip
scrollbar + scroll on mousescrollHEADmaster
Diffstat (limited to 'x.c')
-rw-r--r--x.c31
1 files changed, 30 insertions, 1 deletions
diff --git a/x.c b/x.c
index 8c9a74e..9c0ddc5 100644
--- a/x.c
+++ b/x.c
@@ -749,7 +749,7 @@ cresize(int width, int height)
749 if (height != 0) 749 if (height != 0)
750 win.h = height; 750 win.h = height;
751 751
752 col = (win.w - 2 * borderpx) / win.cw; 752 col = (win.w - 2 * borderpx - scrollbarwidth) / win.cw;
753 row = (win.h - 2 * borderpx) / win.ch; 753 row = (win.h - 2 * borderpx) / win.ch;
754 col = MAX(1, col); 754 col = MAX(1, col);
755 row = MAX(1, row); 755 row = MAX(1, row);
@@ -1751,6 +1751,35 @@ xdrawline(Line line, int x1, int y1, int x2)
1751} 1751}
1752 1752
1753void 1753void
1754xdrawscrollbar(int offset, int total, int visible)
1755{
1756 int sb_width = scrollbarwidth;
1757 int sb_x = win.w - sb_width;
1758 int max_off = total - visible;
1759
1760 if (max_off <= 0 || sb_width == 0)
1761 return;
1762
1763 /* draw scrollbar background - full height from top to bottom */
1764 if (scrollbarbg >= 0) {
1765 XSetForeground(xw.dpy, dc.gc, dc.col[scrollbarbg].pixel);
1766 XFillRectangle(xw.dpy, xw.buf, dc.gc, sb_x, 0,
1767 sb_width, win.h);
1768 }
1769
1770 /* calculate thumb position and height */
1771 int sb_height = win.h;
1772 int thumb_h = MAX(2, ((float)visible / total) * sb_height);
1773 int thumb_y = ((float)(max_off - offset) / max_off) *
1774 (sb_height - thumb_h);
1775
1776 /* draw scrollbar thumb */
1777 XSetForeground(xw.dpy, dc.gc, dc.col[scrollbarcolor].pixel);
1778 XFillRectangle(xw.dpy, xw.buf, dc.gc, sb_x,
1779 thumb_y, sb_width, thumb_h);
1780}
1781
1782void
1754xfinishdraw(void) 1783xfinishdraw(void)
1755{ 1784{
1756 if (vbellset && vbellmode == 1) 1785 if (vbellset && vbellmode == 1)