summaryrefslogtreecommitdiffstats
path: root/main.c
diff options
context:
space:
mode:
authorLuXu <oliver_lew@outlook.com>2021-11-04 05:20:28 +0100
committerGitHub <noreply@github.com>2021-11-04 05:20:28 +0100
commit36f42081d0d3e6f401e18bf84f6796ca8f8bcfb5 (patch)
tree0cca3a0880cd47fb1e21d8d16ff291e83337ec20 /main.c
parentabf316a066ed19e2f6c1a38c7faaa594de7287c4 (diff)
downloadnsxiv-36f42081d0d3e6f401e18bf84f6796ca8f8bcfb5.tar.zst
make width of navigation area configurable (#155)
this allows users to configure navigation width from config.h. it also allows disabling the navigation function entirely by using a 0 width. one extra functionality this adds is being able to define an absolute width (in pixels) instead of just percentage via `NAV_IS_REL`. Co-authored-by: NRK <nrk@disroot.org>
Diffstat (limited to 'main.c')
-rw-r--r--main.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/main.c b/main.c
index 4cd9a33..2643cad 100644
--- a/main.c
+++ b/main.c
@@ -392,12 +392,23 @@ void update_info(void)
}
}
-int ptr_third_x(void)
+int nav_button(void)
{
- int x, y;
+ int x, y, nw;
+
+ if (NAV_WIDTH == 0)
+ return 1;
win_cursor_pos(&win, &x, &y);
- return MAX(0, MIN(2, (x / (win.w * 0.33))));
+ nw = NAV_IS_REL ? win.w * NAV_WIDTH / 100 : NAV_WIDTH;
+ nw = MIN(nw, (win.w + 1) / 2);
+
+ if (x < nw)
+ return 0;
+ else if (x < win.w-nw)
+ return 1;
+ else
+ return 2;
}
void redraw(void)
@@ -431,7 +442,7 @@ void reset_cursor(void)
for (i = 0; i < ARRLEN(timeouts); i++) {
if (timeouts[i].handler == reset_cursor) {
if (timeouts[i].active) {
- c = ptr_third_x();
+ c = nav_button();
c = MAX(fileidx > 0 ? 0 : 1, c);
c = MIN(fileidx + 1 < filecnt ? 2 : 1, c);
cursor = imgcursor[c];