diff options
author | NRK <nrk@disroot.org> | 2022-06-01 14:59:16 +0600 |
---|---|---|
committer | N-R-K <nrk@disroot.org> | 2022-06-02 08:09:51 +0000 |
commit | 810a9651a362992383081619ca63122f41f1cd0a (patch) | |
tree | bea298b12676f642a4801a5d6385a781f918a639 | |
parent | 364c3d6f019a26e68f2bfb9594d6bc599a947be2 (diff) |
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
-rw-r--r-- | commands.c | 1 | ||||
-rwxr-xr-x | examples/win-title | 2 | ||||
-rw-r--r-- | image.c | 5 | ||||
-rw-r--r-- | main.c | 8 | ||||
-rw-r--r-- | nsxiv.1 | 3 | ||||
-rw-r--r-- | nsxiv.h | 1 | ||||
-rw-r--r-- | thumbs.c | 2 |
7 files changed, 16 insertions, 6 deletions
@@ -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: @@ -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; @@ -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(); @@ -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 @@ -470,5 +470,6 @@ extern int alternate; extern int markcnt; extern int markidx; extern int prefix; +extern bool title_dirty; #endif /* NSXIV_H */ @@ -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; } |