From 810a9651a362992383081619ca63122f41f1cd0a Mon Sep 17 00:00:00 2001 From: NRK Date: Wed, 1 Jun 2022 14:59:16 +0600 Subject: [PATCH] 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 Partially fixes: https://github.com/nsxiv/nsxiv/issues/258 --- commands.c | 1 + examples/win-title | 2 +- image.c | 5 ++--- main.c | 8 +++++++- nsxiv.1 | 3 ++- nsxiv.h | 1 + thumbs.c | 2 ++ 7 files changed, 16 insertions(+), 6 deletions(-) diff --git a/commands.c b/commands.c index 9ee83ec..2c4f4a7 100644 --- a/commands.c +++ b/commands.c @@ -63,6 +63,7 @@ bool cg_switch_mode(arg_t _) } close_info(); open_info(); + title_dirty = true; return true; } diff --git a/examples/win-title b/examples/win-title index ac7b982..31994ef 100755 --- a/examples/win-title +++ b/examples/win-title @@ -1,7 +1,7 @@ #!/bin/sh # Example for $XDG_CONFIG_HOME/nsxiv/exec/win-title -# Called by nsxiv(1) on each redraw. +# Called by nsxiv(1) whenever any of the relevant information changes. # The output is set as nsxiv's window title. # # Arguments, "Optional" arguments might be empty: diff --git a/image.c b/image.c index 2904887..02e3957 100644 --- a/image.c +++ b/image.c @@ -546,7 +546,7 @@ static bool img_fit(img_t *img) if (ABS(img->zoom - z) > 1.0/MAX(img->w, img->h)) { img->zoom = z; - img->dirty = true; + img->dirty = title_dirty = true; return true; } else { return false; @@ -677,8 +677,7 @@ bool img_zoom_to(img_t *img, float z) img->y = y - (y - img->y) * z / img->zoom; img->zoom = z; img->scalemode = SCALE_ZOOM; - img->checkpan = true; - img->dirty = true; + img->dirty = img->checkpan = title_dirty = true; return true; } else { return false; diff --git a/main.c b/main.c index 5dc52d4..7c7b436 100644 --- a/main.c +++ b/main.c @@ -85,6 +85,8 @@ static struct { extcmd_t f; } wintitle; +bool title_dirty; + static timeout_t timeouts[] = { { { 0, 0 }, false, redraw }, { { 0, 0 }, false, reset_cursor }, @@ -343,6 +345,7 @@ void load_image(int new) close_info(); open_info(); arl_setup(&arl, files[fileidx].path); + title_dirty = true; if (img.multi.cnt > 0 && img.multi.animate) set_timeout(animate, img.multi.frames[img.multi.sel].delay, true); @@ -451,7 +454,10 @@ void redraw(void) tns_render(&tns); } update_info(); - win_set_title(&win, false); + if (title_dirty) { + win_set_title(&win, false); + title_dirty = false; + } win_draw(&win); reset_timeout(redraw); reset_cursor(); diff --git a/nsxiv.1 b/nsxiv.1 index 4488146..d5cd0ef 100644 --- a/nsxiv.1 +++ b/nsxiv.1 @@ -426,7 +426,8 @@ Color of the mark foreground. Defaults to window.foreground Please see xrdb(1) on how to change them. .SH WINDOW TITLE The window title can be replaced with the output of a user-provided script, -which is called by nsxiv whenever there's a redraw. The path of this script is +which is called by nsxiv whenever any of the relevant information changes. +The path of this script is .I $XDG_CONFIG_HOME/nsxiv/exec/win-title and the arguments given to it (where "Optional" arguments might be empty) are: .IP $1 4 diff --git a/nsxiv.h b/nsxiv.h index 1b11cba..c781aa5 100644 --- a/nsxiv.h +++ b/nsxiv.h @@ -470,5 +470,6 @@ extern int alternate; extern int markcnt; extern int markidx; extern int prefix; +extern bool title_dirty; #endif /* NSXIV_H */ diff --git a/thumbs.c b/thumbs.c index 52820d4..8ca0c58 100644 --- a/thumbs.c +++ b/thumbs.c @@ -459,6 +459,7 @@ void tns_render(tns_t *tns) } tns->dirty = false; tns_highlight(tns, *tns->sel, true); + title_dirty = true; } 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) tns_check_view(tns, false); if (!tns->dirty) tns_highlight(tns, *tns->sel, true); + title_dirty = true; } return *tns->sel != old; }