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`.
+22 −6
3 files changed
- M commands.c +2 −2
- M config.def.h +5 −0
- M main.c +15 −4
| @@ -29,7 +29,7 @@ void load_image(int); | |||
| 29 | 29 | bool mark_image(int, bool); | |
| 30 | 30 | void close_info(void); | |
| 31 | 31 | void open_info(void); | |
| 32 | − | int ptr_third_x(void); | |
| 32 | + | int nav_button(void); | |
| 33 | 33 | void redraw(void); | |
| 34 | 34 | void reset_cursor(void); | |
| 35 | 35 | void animate(void); | |
| @@ -286,7 +286,7 @@ bool ci_navigate(arg_t n) | |||
| 286 | 286 | ||
| 287 | 287 | bool ci_cursor_navigate(arg_t _) | |
| 288 | 288 | { | |
| 289 | − | return ci_navigate(ptr_third_x() - 1); | |
| 289 | + | return ci_navigate(nav_button() - 1); | |
| 290 | 290 | } | |
| 291 | 291 | ||
| 292 | 292 | bool ci_alternate(arg_t _) | |
| @@ -173,6 +173,11 @@ static const button_t buttons[] = { | |||
| 173 | 173 | { 0, 5, g_zoom, -1 }, | |
| 174 | 174 | }; | |
| 175 | 175 | ||
| 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 | + | ||
| 176 | 181 | /* mouse cursor on left, middle and right part of the window */ | |
| 177 | 182 | static const cursor_t imgcursor[3] = { | |
| 178 | 183 | CURSOR_LEFT, CURSOR_ARROW, CURSOR_RIGHT | |
| @@ -392,12 +392,23 @@ void update_info(void) | |||
| 392 | 392 | } | |
| 393 | 393 | } | |
| 394 | 394 | ||
| 395 | − | int ptr_third_x(void) | |
| 395 | + | int nav_button(void) | |
| 396 | 396 | { | |
| 397 | − | int x, y; | |
| 397 | + | int x, y, nw; | |
| 398 | + | ||
| 399 | + | if (NAV_WIDTH == 0) | |
| 400 | + | return 1; | |
| 398 | 401 | ||
| 399 | 402 | 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; | |
| 401 | 412 | } | |
| 402 | 413 | ||
| 403 | 414 | void redraw(void) | |
| @@ -431,7 +442,7 @@ void reset_cursor(void) | |||
| 431 | 442 | for (i = 0; i < ARRLEN(timeouts); i++) { | |
| 432 | 443 | if (timeouts[i].handler == reset_cursor) { | |
| 433 | 444 | if (timeouts[i].active) { | |
| 434 | − | c = ptr_third_x(); | |
| 445 | + | c = nav_button(); | |
| 435 | 446 | c = MAX(fileidx > 0 ? 0 : 1, c); | |
| 436 | 447 | c = MIN(fileidx + 1 < filecnt ? 2 : 1, c); | |
| 437 | 448 | cursor = imgcursor[c]; | |