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.
This commit is contained in:
		
							
								
								
									
										38
									
								
								main.c
									
									
									
									
									
								
							
							
						
						
									
										38
									
								
								main.c
									
									
									
									
									
								
							| @@ -233,30 +233,36 @@ static bool check_timeouts(struct timeval *t) | |||||||
| 	return tmin > 0; | 	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]; | 	char *argv[8]; | ||||||
| 	spawn_t pfd; | 	spawn_t pfd; | ||||||
| 	char w[12] = "", h[12] = "", z[12] = "", fidx[12], fcnt[12]; | 	char w[12] = "", h[12] = "", z[12] = "", fidx[12], fcnt[12]; | ||||||
| 	ssize_t n = -1; | 	ssize_t n = -1; | ||||||
|  |  | ||||||
| 	if (wintitle.f.err || buf == NULL || len <= 0) | 	if (buf == NULL || len <= 0) | ||||||
| 		return 0; | 		return 0; | ||||||
|  |  | ||||||
| 	if (mode == MODE_IMAGE) { | 	if (init) { | ||||||
| 		snprintf(w, ARRLEN(w), "%d", img.w); | 		n = snprintf((char *)buf, len, "%s", options->res_name != NULL ? | ||||||
| 		snprintf(h, ARRLEN(h), "%d", img.h); | 		             options->res_name : "nsxiv"); | ||||||
| 		snprintf(z, ARRLEN(z), "%d", (int)(img.zoom * 100)); | 	} else if (!wintitle.f.err) { | ||||||
| 	} | 		if (mode == MODE_IMAGE) { | ||||||
| 	snprintf(fidx, ARRLEN(fidx), "%d", fileidx+1); | 			snprintf(w, ARRLEN(w), "%d", img.w); | ||||||
| 	snprintf(fcnt, ARRLEN(fcnt), "%d", filecnt); | 			snprintf(h, ARRLEN(h), "%d", img.h); | ||||||
| 	construct_argv(argv, ARRLEN(argv), wintitle.f.cmd, files[fileidx].path, | 			snprintf(z, ARRLEN(z), "%d", (int)(img.zoom * 100)); | ||||||
| 	               fidx, fcnt, w, h, z, NULL); | 		} | ||||||
| 	pfd = spawn(wintitle.f.cmd, argv, X_READ); | 		snprintf(fidx, ARRLEN(fidx), "%d", fileidx+1); | ||||||
| 	if (pfd.readfd >= 0) { | 		snprintf(fcnt, ARRLEN(fcnt), "%d", filecnt); | ||||||
| 		if ((n = read(pfd.readfd, buf, len-1)) > 0) | 		construct_argv(argv, ARRLEN(argv), wintitle.f.cmd, files[fileidx].path, | ||||||
| 			buf[n] = '\0'; | 		               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); | 	return MAX(0, n); | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -459,7 +465,7 @@ void redraw(void) | |||||||
| 		tns_render(&tns); | 		tns_render(&tns); | ||||||
| 	} | 	} | ||||||
| 	update_info(); | 	update_info(); | ||||||
| 	win_set_title(&win); | 	win_set_title(&win, false); | ||||||
| 	win_draw(&win); | 	win_draw(&win); | ||||||
| 	reset_timeout(redraw); | 	reset_timeout(redraw); | ||||||
| 	reset_cursor(); | 	reset_cursor(); | ||||||
|   | |||||||
							
								
								
									
										2
									
								
								nsxiv.h
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								nsxiv.h
									
									
									
									
									
								
							| @@ -442,7 +442,7 @@ void win_toggle_bar(win_t*); | |||||||
| void win_clear(win_t*); | void win_clear(win_t*); | ||||||
| void win_draw(win_t*); | void win_draw(win_t*); | ||||||
| void win_draw_rect(win_t*, int, int, int, int, bool, int, unsigned long); | void win_draw_rect(win_t*, int, int, int, int, bool, int, unsigned long); | ||||||
| void win_set_title(win_t*); | void win_set_title(win_t*, bool); | ||||||
| void win_set_cursor(win_t*, cursor_t); | void win_set_cursor(win_t*, cursor_t); | ||||||
| void win_cursor_pos(win_t*, int*, int*); | void win_cursor_pos(win_t*, int*, int*); | ||||||
|  |  | ||||||
|   | |||||||
							
								
								
									
										8
									
								
								window.c
									
									
									
									
									
								
							
							
						
						
									
										8
									
								
								window.c
									
									
									
									
									
								
							| @@ -30,7 +30,7 @@ | |||||||
| #include <X11/Xatom.h> | #include <X11/Xatom.h> | ||||||
| #include <X11/Xresource.h> | #include <X11/Xresource.h> | ||||||
|  |  | ||||||
| extern size_t get_win_title(unsigned char *, int); | extern size_t get_win_title(unsigned char *, int, bool); | ||||||
|  |  | ||||||
| #if HAVE_LIBFONTS | #if HAVE_LIBFONTS | ||||||
| #include "utf8.h" | #include "utf8.h" | ||||||
| @@ -289,9 +289,9 @@ void win_open(win_t *win) | |||||||
| 	} | 	} | ||||||
| 	free(icon_data); | 	free(icon_data); | ||||||
|  |  | ||||||
| 	/* These two atoms won't change and thus only need to be set once. */ |  | ||||||
| 	XStoreName(win->env.dpy, win->xwin, res_name); | 	XStoreName(win->env.dpy, win->xwin, res_name); | ||||||
| 	XSetIconName(win->env.dpy, win->xwin, res_name); | 	XSetIconName(win->env.dpy, win->xwin, res_name); | ||||||
|  | 	win_set_title(win, true); | ||||||
|  |  | ||||||
| 	classhint.res_class = res_class; | 	classhint.res_class = res_class; | ||||||
| 	classhint.res_name = options->res_name != NULL ? options->res_name : res_name; | 	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, | |||||||
| 		XDrawRectangle(win->env.dpy, win->buf.pm, gc, x, y, w, h); | 		XDrawRectangle(win->env.dpy, win->buf.pm, gc, x, y, w, h); | ||||||
| } | } | ||||||
|  |  | ||||||
| void win_set_title(win_t *win) | void win_set_title(win_t *win, bool init) | ||||||
| { | { | ||||||
| 	unsigned char title[512]; | 	unsigned char title[512]; | ||||||
| 	size_t len; | 	size_t len; | ||||||
|  |  | ||||||
| 	if ((len = get_win_title(title, ARRLEN(title))) <= 0) | 	if ((len = get_win_title(title, ARRLEN(title), init)) <= 0) | ||||||
| 		return; | 		return; | ||||||
|  |  | ||||||
| 	XChangeProperty(win->env.dpy, win->xwin, atoms[ATOM__NET_WM_NAME], | 	XChangeProperty(win->env.dpy, win->xwin, atoms[ATOM__NET_WM_NAME], | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user