Krolyxon
Commit 810a965

Branches

Refs →

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
Author
NRK
Date
2022-06-01 14:59 +0600
Committer
N-R-K · 2022-06-02 08:09 +0000
Parent
364c3d6
Commit
810a9651a362992383081619ca63122f41f1cd0a

+16 −6

7 files changed

  1. M commands.c +1 −0
  2. M examples/win-title +1 −1
  3. M image.c +2 −3
  4. M main.c +7 −1
  5. M nsxiv.1 +2 −1
  6. M nsxiv.h +1 −0
  7. M thumbs.c +2 −0
M commands.c View
@@ -63,6 +63,7 @@ bool cg_switch_mode(arg_t _)
6363 }
6464 close_info();
6565 open_info();
66+ title_dirty = true;
6667 return true;
6768 }
6869
M examples/win-title View
@@ -1,7 +1,7 @@
11 #!/bin/sh
22
33 # 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.
55 # The output is set as nsxiv's window title.
66 #
77 # Arguments, "Optional" arguments might be empty:
M image.c View
@@ -546,7 +546,7 @@ static bool img_fit(img_t *img)
546546
547547 if (ABS(img->zoom - z) > 1.0/MAX(img->w, img->h)) {
548548 img->zoom = z;
549− img->dirty = true;
549+ img->dirty = title_dirty = true;
550550 return true;
551551 } else {
552552 return false;
@@ -677,8 +677,7 @@ bool img_zoom_to(img_t *img, float z)
677677 img->y = y - (y - img->y) * z / img->zoom;
678678 img->zoom = z;
679679 img->scalemode = SCALE_ZOOM;
680− img->checkpan = true;
681− img->dirty = true;
680+ img->dirty = img->checkpan = title_dirty = true;
682681 return true;
683682 } else {
684683 return false;
M main.c View
@@ -85,6 +85,8 @@ static struct {
8585 extcmd_t f;
8686 } wintitle;
8787
88+bool title_dirty;
89+
8890 static timeout_t timeouts[] = {
8991 { { 0, 0 }, false, redraw },
9092 { { 0, 0 }, false, reset_cursor },
@@ -343,6 +345,7 @@ void load_image(int new)
343345 close_info();
344346 open_info();
345347 arl_setup(&arl, files[fileidx].path);
348+ title_dirty = true;
346349
347350 if (img.multi.cnt > 0 && img.multi.animate)
348351 set_timeout(animate, img.multi.frames[img.multi.sel].delay, true);
@@ -451,7 +454,10 @@ void redraw(void)
451454 tns_render(&tns);
452455 }
453456 update_info();
454− win_set_title(&win, false);
457+ if (title_dirty) {
458+ win_set_title(&win, false);
459+ title_dirty = false;
460+ }
455461 win_draw(&win);
456462 reset_timeout(redraw);
457463 reset_cursor();
M nsxiv.1 View
@@ -426,7 +426,8 @@ Color of the mark foreground. Defaults to window.foreground
426426 Please see xrdb(1) on how to change them.
427427 .SH WINDOW TITLE
428428 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
430431 .I $XDG_CONFIG_HOME/nsxiv/exec/win-title
431432 and the arguments given to it (where "Optional" arguments might be empty) are:
432433 .IP $1 4
M nsxiv.h View
@@ -470,5 +470,6 @@ extern int alternate;
470470 extern int markcnt;
471471 extern int markidx;
472472 extern int prefix;
473+extern bool title_dirty;
473474
474475 #endif /* NSXIV_H */
M thumbs.c View
@@ -459,6 +459,7 @@ void tns_render(tns_t *tns)
459459 }
460460 tns->dirty = false;
461461 tns_highlight(tns, *tns->sel, true);
462+ title_dirty = true;
462463 }
463464
464465 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)
527528 tns_check_view(tns, false);
528529 if (!tns->dirty)
529530 tns_highlight(tns, *tns->sel, true);
531+ title_dirty = true;
530532 }
531533 return *tns->sel != old;
532534 }