From ad571e7448eb53fb099ec0cb87baf97cb38d3450 Mon Sep 17 00:00:00 2001 From: NRK Date: Sun, 27 Feb 2022 16:53:45 +0600 Subject: always initialize window title before if exec/win-title didn't exist then window title wouldn't be set. this patch makes it so window title is always set to something. --- main.c | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) (limited to 'main.c') diff --git a/main.c b/main.c index f485d39..d33d6ab 100644 --- a/main.c +++ b/main.c @@ -233,30 +233,36 @@ static bool check_timeouts(struct timeval *t) return tmin > 0; } -size_t get_win_title(unsigned char *buf, int len) +size_t get_win_title(unsigned char *buf, int len, bool init) { char *argv[8]; spawn_t pfd; char w[12] = "", h[12] = "", z[12] = "", fidx[12], fcnt[12]; ssize_t n = -1; - if (wintitle.f.err || buf == NULL || len <= 0) + if (buf == NULL || len <= 0) return 0; - 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'; + 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'; + } } + return MAX(0, n); } @@ -459,7 +465,7 @@ void redraw(void) tns_render(&tns); } update_info(); - win_set_title(&win); + win_set_title(&win, false); win_draw(&win); reset_timeout(redraw); reset_cursor(); -- cgit v1.2.3-70-g09d2