summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--config.def.h16
-rw-r--r--st.c1
-rw-r--r--win.h1
-rw-r--r--x.c31
4 files changed, 44 insertions, 5 deletions
diff --git a/config.def.h b/config.def.h
index d7e1fe5..3daa8fc 100644
--- a/config.def.h
+++ b/config.def.h
@@ -9,6 +9,16 @@ static char *font = "Liberation Mono:pixelsize=14:antialias=true:autohint=true";
9static int borderpx = 2; 9static int borderpx = 2;
10 10
11/* 11/*
12 * scrollbar options
13 * scrollbarwidth: width of the scrollbar in pixels (0 to disable)
14 * scrollbarcolor: color of the scrollbar thumb
15 * scrollbarbg: color of the scrollbar background (use -1 for none)
16 */
17static int scrollbarwidth = 3;
18static unsigned int scrollbarcolor = 8;
19static int scrollbarbg = 257;
20
21/*
12 * What program is execed by st depends of these precedence rules: 22 * What program is execed by st depends of these precedence rules:
13 * 1: program passed with -e 23 * 1: program passed with -e
14 * 2: scroll and/or utmp 24 * 2: scroll and/or utmp
@@ -203,10 +213,8 @@ static uint forcemousemod = ShiftMask;
203static MouseShortcut mshortcuts[] = { 213static MouseShortcut mshortcuts[] = {
204 /* mask button function argument release */ 214 /* mask button function argument release */
205 { XK_ANY_MOD, Button2, selpaste, {.i = 0}, 1 }, 215 { XK_ANY_MOD, Button2, selpaste, {.i = 0}, 1 },
206 { ShiftMask, Button4, ttysend, {.s = "\033[5;2~"} }, 216 { XK_ANY_MOD, Button4, kscrollup, {.i = 1} },
207 { XK_ANY_MOD, Button4, ttysend, {.s = "\031"} }, 217 { XK_ANY_MOD, Button5, kscrolldown, {.i = 1} },
208 { ShiftMask, Button5, ttysend, {.s = "\033[6;2~"} },
209 { XK_ANY_MOD, Button5, ttysend, {.s = "\005"} },
210}; 218};
211 219
212/* Internal keyboard shortcuts. */ 220/* Internal keyboard shortcuts. */
diff --git a/st.c b/st.c
index 170a8a8..0f2ed03 100644
--- a/st.c
+++ b/st.c
@@ -2903,6 +2903,7 @@ draw(void)
2903 term.ocx, term.ocy, TLINE(term.ocy)[term.ocx]); 2903 term.ocx, term.ocy, TLINE(term.ocy)[term.ocx]);
2904 term.ocx = cx; 2904 term.ocx = cx;
2905 term.ocy = term.c.y; 2905 term.ocy = term.c.y;
2906 xdrawscrollbar(TSCREEN.off, TSCREEN.size, term.row);
2906 xfinishdraw(); 2907 xfinishdraw();
2907 if (ocx != term.ocx || ocy != term.ocy) 2908 if (ocx != term.ocx || ocy != term.ocy)
2908 xximspot(term.ocx, term.ocy); 2909 xximspot(term.ocx, term.ocy);
diff --git a/win.h b/win.h
index 6de960d..fbd3159 100644
--- a/win.h
+++ b/win.h
@@ -39,3 +39,4 @@ void xsetpointermotion(int);
39void xsetsel(char *); 39void xsetsel(char *);
40int xstartdraw(void); 40int xstartdraw(void);
41void xximspot(int, int); 41void xximspot(int, int);
42void xdrawscrollbar(int, int, int);
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)