nsxiv810a965
reduce calls to win-title
rather than calling the script unconditionally per redraw, we now have a `title_dirty` flag and keep track of when any of the relavent information changes. Co-authored-by: Arthur Williams <taaparthur@gmail.com> Partially fixes: https://github.com/nsxiv/nsxiv/issues/258
+16 −6
7 files changed
- M commands.c +1 −0
- M examples/win-title +1 −1
- M image.c +2 −3
- M main.c +7 −1
- M nsxiv.1 +2 −1
- M nsxiv.h +1 −0
- M thumbs.c +2 −0
| @@ -63,6 +63,7 @@ bool cg_switch_mode(arg_t _) | |||
| 63 | 63 | } | |
| 64 | 64 | close_info(); | |
| 65 | 65 | open_info(); | |
| 66 | + | title_dirty = true; | |
| 66 | 67 | return true; | |
| 67 | 68 | } | |
| 68 | 69 | ||
| @@ -1,7 +1,7 @@ | |||
| 1 | 1 | #!/bin/sh | |
| 2 | 2 | ||
| 3 | 3 | # Example for $XDG_CONFIG_HOME/nsxiv/exec/win-title | |
| 4 | − | # Called by nsxiv(1) on each redraw. | |
| 4 | + | # Called by nsxiv(1) whenever any of the relevant information changes. | |
| 5 | 5 | # The output is set as nsxiv's window title. | |
| 6 | 6 | # | |
| 7 | 7 | # Arguments, "Optional" arguments might be empty: | |
| @@ -546,7 +546,7 @@ static bool img_fit(img_t *img) | |||
| 546 | 546 | ||
| 547 | 547 | if (ABS(img->zoom - z) > 1.0/MAX(img->w, img->h)) { | |
| 548 | 548 | img->zoom = z; | |
| 549 | − | img->dirty = true; | |
| 549 | + | img->dirty = title_dirty = true; | |
| 550 | 550 | return true; | |
| 551 | 551 | } else { | |
| 552 | 552 | return false; | |
| @@ -677,8 +677,7 @@ bool img_zoom_to(img_t *img, float z) | |||
| 677 | 677 | img->y = y - (y - img->y) * z / img->zoom; | |
| 678 | 678 | img->zoom = z; | |
| 679 | 679 | img->scalemode = SCALE_ZOOM; | |
| 680 | − | img->checkpan = true; | |
| 681 | − | img->dirty = true; | |
| 680 | + | img->dirty = img->checkpan = title_dirty = true; | |
| 682 | 681 | return true; | |
| 683 | 682 | } else { | |
| 684 | 683 | return false; | |
| @@ -85,6 +85,8 @@ static struct { | |||
| 85 | 85 | extcmd_t f; | |
| 86 | 86 | } wintitle; | |
| 87 | 87 | ||
| 88 | + | bool title_dirty; | |
| 89 | + | ||
| 88 | 90 | static timeout_t timeouts[] = { | |
| 89 | 91 | { { 0, 0 }, false, redraw }, | |
| 90 | 92 | { { 0, 0 }, false, reset_cursor }, | |
| @@ -343,6 +345,7 @@ void load_image(int new) | |||
| 343 | 345 | close_info(); | |
| 344 | 346 | open_info(); | |
| 345 | 347 | arl_setup(&arl, files[fileidx].path); | |
| 348 | + | title_dirty = true; | |
| 346 | 349 | ||
| 347 | 350 | if (img.multi.cnt > 0 && img.multi.animate) | |
| 348 | 351 | set_timeout(animate, img.multi.frames[img.multi.sel].delay, true); | |
| @@ -451,7 +454,10 @@ void redraw(void) | |||
| 451 | 454 | tns_render(&tns); | |
| 452 | 455 | } | |
| 453 | 456 | update_info(); | |
| 454 | − | win_set_title(&win, false); | |
| 457 | + | if (title_dirty) { | |
| 458 | + | win_set_title(&win, false); | |
| 459 | + | title_dirty = false; | |
| 460 | + | } | |
| 455 | 461 | win_draw(&win); | |
| 456 | 462 | reset_timeout(redraw); | |
| 457 | 463 | reset_cursor(); | |
| @@ -426,7 +426,8 @@ Color of the mark foreground. Defaults to window.foreground | |||
| 426 | 426 | Please see xrdb(1) on how to change them. | |
| 427 | 427 | .SH WINDOW TITLE | |
| 428 | 428 | The window title can be replaced with the output of a user-provided script, | |
| 429 | − | which is called by nsxiv whenever there's a redraw. The path of this script is | |
| 429 | + | which is called by nsxiv whenever any of the relevant information changes. | |
| 430 | + | The path of this script is | |
| 430 | 431 | .I $XDG_CONFIG_HOME/nsxiv/exec/win-title | |
| 431 | 432 | and the arguments given to it (where "Optional" arguments might be empty) are: | |
| 432 | 433 | .IP $1 4 | |
| @@ -470,5 +470,6 @@ extern int alternate; | |||
| 470 | 470 | extern int markcnt; | |
| 471 | 471 | extern int markidx; | |
| 472 | 472 | extern int prefix; | |
| 473 | + | extern bool title_dirty; | |
| 473 | 474 | ||
| 474 | 475 | #endif /* NSXIV_H */ | |
| @@ -459,6 +459,7 @@ void tns_render(tns_t *tns) | |||
| 459 | 459 | } | |
| 460 | 460 | tns->dirty = false; | |
| 461 | 461 | tns_highlight(tns, *tns->sel, true); | |
| 462 | + | title_dirty = true; | |
| 462 | 463 | } | |
| 463 | 464 | ||
| 464 | 465 | void tns_mark(tns_t *tns, int n, bool mark) | |
| @@ -527,6 +528,7 @@ bool tns_move_selection(tns_t *tns, direction_t dir, int cnt) | |||
| 527 | 528 | tns_check_view(tns, false); | |
| 528 | 529 | if (!tns->dirty) | |
| 529 | 530 | tns_highlight(tns, *tns->sel, true); | |
| 531 | + | title_dirty = true; | |
| 530 | 532 | } | |
| 531 | 533 | return *tns->sel != old; | |
| 532 | 534 | } | |