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
This commit is contained in:
NRK 2022-06-01 14:59:16 +06:00 committed by N-R-K
parent 364c3d6f01
commit 810a9651a3
7 changed files with 16 additions and 6 deletions

View file

@ -63,6 +63,7 @@ bool cg_switch_mode(arg_t _)
}
close_info();
open_info();
title_dirty = true;
return true;
}

View file

@ -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:

View file

@ -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;

8
main.c
View file

@ -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();

View file

@ -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

View file

@ -470,5 +470,6 @@ extern int alternate;
extern int markcnt;
extern int markidx;
extern int prefix;
extern bool title_dirty;
#endif /* NSXIV_H */

View file

@ -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;
}