aboutsummaryrefslogtreecommitdiffstats
path: root/main.c
diff options
context:
space:
mode:
authorNRK <nrk@disroot.org>2022-06-01 12:47:17 +0200
committerN-R-K <nrk@disroot.org>2022-06-02 10:09:51 +0200
commite9a0096d6df602aefac5ce63b4bda2e1c85ed846 (patch)
treef49db09049324a1280c2aaf86d5a2de15471e22b /main.c
parent810a9651a362992383081619ca63122f41f1cd0a (diff)
downloadnsxiv-e9a0096d6df602aefac5ce63b4bda2e1c85ed846.tar.zst
code-style: simplify window title related code
instead of dancing around with some `init` parameter, directly give `win_set_title()` what it needs. `get_win_title()` now also does *just* what the name says. this simplifies things quite a bit and the functions now do what their name implies more closely instead of doing some `init` dance internally.
Diffstat (limited to 'main.c')
-rw-r--r--main.c43
1 files changed, 21 insertions, 22 deletions
diff --git a/main.c b/main.c
index 7c7b436..f148250 100644
--- a/main.c
+++ b/main.c
@@ -233,35 +233,30 @@ static bool check_timeouts(int *t)
return tmin > 0;
}
-size_t get_win_title(unsigned char *buf, int len, bool init)
+static size_t get_win_title(char *buf, size_t len)
{
char *argv[8];
spawn_t pfd;
char w[12] = "", h[12] = "", z[12] = "", fidx[12], fcnt[12];
ssize_t n = -1;
- if (buf == NULL || len <= 0)
+ if (wintitle.f.err || buf == NULL || len == 0)
return 0;
- if (init) {
- n = snprintf((char *)buf, len, "%s", options->res_name != NULL ?
- options->res_name : "nsxiv");
- } else if (!wintitle.f.err) {
- if (mode == MODE_IMAGE) {
- snprintf(w, ARRLEN(w), "%d", img.w);
- snprintf(h, ARRLEN(h), "%d", img.h);
- snprintf(z, ARRLEN(z), "%d", (int)(img.zoom * 100));
- }
- snprintf(fidx, ARRLEN(fidx), "%d", fileidx+1);
- snprintf(fcnt, ARRLEN(fcnt), "%d", filecnt);
- construct_argv(argv, ARRLEN(argv), wintitle.f.cmd, files[fileidx].path,
- fidx, fcnt, w, h, z, NULL);
- pfd = spawn(wintitle.f.cmd, argv, X_READ);
- if (pfd.readfd >= 0) {
- if ((n = read(pfd.readfd, buf, len-1)) > 0)
- buf[n] = '\0';
- close(pfd.readfd);
- }
+ if (mode == MODE_IMAGE) {
+ snprintf(w, ARRLEN(w), "%d", img.w);
+ snprintf(h, ARRLEN(h), "%d", img.h);
+ snprintf(z, ARRLEN(z), "%d", (int)(img.zoom * 100));
+ }
+ snprintf(fidx, ARRLEN(fidx), "%d", fileidx+1);
+ snprintf(fcnt, ARRLEN(fcnt), "%d", filecnt);
+ construct_argv(argv, ARRLEN(argv), wintitle.f.cmd, files[fileidx].path,
+ fidx, fcnt, w, h, z, NULL);
+ pfd = spawn(wintitle.f.cmd, argv, X_READ);
+ if (pfd.readfd >= 0) {
+ if ((n = read(pfd.readfd, buf, len-1)) > 0)
+ buf[n] = '\0';
+ close(pfd.readfd);
}
return MAX(0, n);
@@ -455,7 +450,11 @@ void redraw(void)
}
update_info();
if (title_dirty) {
- win_set_title(&win, false);
+ size_t n;
+ char buf[512];
+
+ if ((n = get_win_title(buf, sizeof(buf))) > 0)
+ win_set_title(&win, buf, n);
title_dirty = false;
}
win_draw(&win);