Krolyxon
Commit 36f4208

Branches

Refs →

nsxiv36f4208

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`.
Author
LuXu
Date
2021-11-04 12:20 +0800
Committer
GitHub · 2021-11-04 04:20 +0000
Parent
abf316a
Commit
36f42081d0d3e6f401e18bf84f6796ca8f8bcfb5

+22 −6

3 files changed

  1. M commands.c +2 −2
  2. M config.def.h +5 −0
  3. M main.c +15 −4
M commands.c View
@@ -29,7 +29,7 @@ void load_image(int);
2929 bool mark_image(int, bool);
3030 void close_info(void);
3131 void open_info(void);
32−int ptr_third_x(void);
32+int nav_button(void);
3333 void redraw(void);
3434 void reset_cursor(void);
3535 void animate(void);
@@ -286,7 +286,7 @@ bool ci_navigate(arg_t n)
286286
287287 bool ci_cursor_navigate(arg_t _)
288288 {
289− return ci_navigate(ptr_third_x() - 1);
289+ return ci_navigate(nav_button() - 1);
290290 }
291291
292292 bool ci_alternate(arg_t _)
M config.def.h View
@@ -173,6 +173,11 @@ static const button_t buttons[] = {
173173 { 0, 5, g_zoom, -1 },
174174 };
175175
176+/* true means NAV_WIDTH is relative (33%), false means absolute (33 pixels) */
177+static const bool NAV_IS_REL = true;
178+/* width of navigation area, 0 disables cursor navigation, */
179+static const unsigned int NAV_WIDTH = 33;
180+
176181 /* mouse cursor on left, middle and right part of the window */
177182 static const cursor_t imgcursor[3] = {
178183 CURSOR_LEFT, CURSOR_ARROW, CURSOR_RIGHT
M main.c View
@@ -392,12 +392,23 @@ void update_info(void)
392392 }
393393 }
394394
395−int ptr_third_x(void)
395+int nav_button(void)
396396 {
397− int x, y;
397+ int x, y, nw;
398+
399+ if (NAV_WIDTH == 0)
400+ return 1;
398401
399402 win_cursor_pos(&win, &x, &y);
400− return MAX(0, MIN(2, (x / (win.w * 0.33))));
403+ nw = NAV_IS_REL ? win.w * NAV_WIDTH / 100 : NAV_WIDTH;
404+ nw = MIN(nw, (win.w + 1) / 2);
405+
406+ if (x < nw)
407+ return 0;
408+ else if (x < win.w-nw)
409+ return 1;
410+ else
411+ return 2;
401412 }
402413
403414 void redraw(void)
@@ -431,7 +442,7 @@ void reset_cursor(void)
431442 for (i = 0; i < ARRLEN(timeouts); i++) {
432443 if (timeouts[i].handler == reset_cursor) {
433444 if (timeouts[i].active) {
434− c = ptr_third_x();
445+ c = nav_button();
435446 c = MAX(fileidx > 0 ? 0 : 1, c);
436447 c = MIN(fileidx + 1 < filecnt ? 2 : 1, c);
437448 cursor = imgcursor[c];