Krolyxon
Commit ad571e7

Branches

Refs →

nsxivad571e7

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.
Author
NRK
Date
2022-02-27 16:53 +0600
Committer
N-R-K · 2022-03-02 09:32 +0000
Parent
bdd9521
Commit
ad571e7448eb53fb099ec0cb87baf97cb38d3450

+27 −21

3 files changed

  1. M main.c +22 −16
  2. M nsxiv.h +1 −1
  3. M window.c +4 −4
M main.c View
@@ -233,30 +233,36 @@ static bool check_timeouts(struct timeval *t)
233233 return tmin > 0;
234234 }
235235
236−size_t get_win_title(unsigned char *buf, int len)
236+size_t get_win_title(unsigned char *buf, int len, bool init)
237237 {
238238 char *argv[8];
239239 spawn_t pfd;
240240 char w[12] = "", h[12] = "", z[12] = "", fidx[12], fcnt[12];
241241 ssize_t n = -1;
242242
243− if (wintitle.f.err || buf == NULL || len <= 0)
243+ if (buf == NULL || len <= 0)
244244 return 0;
245245
246− if (mode == MODE_IMAGE) {
247− snprintf(w, ARRLEN(w), "%d", img.w);
248− snprintf(h, ARRLEN(h), "%d", img.h);
249− snprintf(z, ARRLEN(z), "%d", (int)(img.zoom * 100));
250− }
251− snprintf(fidx, ARRLEN(fidx), "%d", fileidx+1);
252− snprintf(fcnt, ARRLEN(fcnt), "%d", filecnt);
253− construct_argv(argv, ARRLEN(argv), wintitle.f.cmd, files[fileidx].path,
254− fidx, fcnt, w, h, z, NULL);
255− pfd = spawn(wintitle.f.cmd, argv, X_READ);
256− if (pfd.readfd >= 0) {
257− if ((n = read(pfd.readfd, buf, len-1)) > 0)
258− buf[n] = '\0';
246+ if (init) {
247+ n = snprintf((char *)buf, len, "%s", options->res_name != NULL ?
248+ options->res_name : "nsxiv");
249+ } else if (!wintitle.f.err) {
250+ if (mode == MODE_IMAGE) {
251+ snprintf(w, ARRLEN(w), "%d", img.w);
252+ snprintf(h, ARRLEN(h), "%d", img.h);
253+ snprintf(z, ARRLEN(z), "%d", (int)(img.zoom * 100));
254+ }
255+ snprintf(fidx, ARRLEN(fidx), "%d", fileidx+1);
256+ snprintf(fcnt, ARRLEN(fcnt), "%d", filecnt);
257+ construct_argv(argv, ARRLEN(argv), wintitle.f.cmd, files[fileidx].path,
258+ fidx, fcnt, w, h, z, NULL);
259+ pfd = spawn(wintitle.f.cmd, argv, X_READ);
260+ if (pfd.readfd >= 0) {
261+ if ((n = read(pfd.readfd, buf, len-1)) > 0)
262+ buf[n] = '\0';
263+ }
259264 }
265+
260266 return MAX(0, n);
261267 }
262268
@@ -459,7 +465,7 @@ void redraw(void)
459465 tns_render(&tns);
460466 }
461467 update_info();
462− win_set_title(&win);
468+ win_set_title(&win, false);
463469 win_draw(&win);
464470 reset_timeout(redraw);
465471 reset_cursor();
M nsxiv.h View
@@ -442,7 +442,7 @@ void win_toggle_bar(win_t*);
442442 void win_clear(win_t*);
443443 void win_draw(win_t*);
444444 void win_draw_rect(win_t*, int, int, int, int, bool, int, unsigned long);
445−void win_set_title(win_t*);
445+void win_set_title(win_t*, bool);
446446 void win_set_cursor(win_t*, cursor_t);
447447 void win_cursor_pos(win_t*, int*, int*);
448448
M window.c View
@@ -30,7 +30,7 @@
3030 #include <X11/Xatom.h>
3131 #include <X11/Xresource.h>
3232
33−extern size_t get_win_title(unsigned char *, int);
33+extern size_t get_win_title(unsigned char *, int, bool);
3434
3535 #if HAVE_LIBFONTS
3636 #include "utf8.h"
@@ -289,9 +289,9 @@ void win_open(win_t *win)
289289 }
290290 free(icon_data);
291291
292− /* These two atoms won't change and thus only need to be set once. */
293292 XStoreName(win->env.dpy, win->xwin, res_name);
294293 XSetIconName(win->env.dpy, win->xwin, res_name);
294+ win_set_title(win, true);
295295
296296 classhint.res_class = res_class;
297297 classhint.res_name = options->res_name != NULL ? options->res_name : res_name;
@@ -503,12 +503,12 @@ void win_draw_rect(win_t *win, int x, int y, int w, int h, bool fill, int lw,
503503 XDrawRectangle(win->env.dpy, win->buf.pm, gc, x, y, w, h);
504504 }
505505
506−void win_set_title(win_t *win)
506+void win_set_title(win_t *win, bool init)
507507 {
508508 unsigned char title[512];
509509 size_t len;
510510
511− if ((len = get_win_title(title, ARRLEN(title))) <= 0)
511+ if ((len = get_win_title(title, ARRLEN(title), init)) <= 0)
512512 return;
513513
514514 XChangeProperty(win->env.dpy, win->xwin, atoms[ATOM__NET_WM_NAME],