Commit 5dc0d677 authored by ulteq's avatar ulteq
Browse files

Simplify window title generation

parent 32653a52
Loading
Loading
Loading
Loading
+2 −10
Original line number Diff line number Diff line
@@ -41,7 +41,6 @@ void init_collage_mode(void)
	feh_file *file = NULL;
	unsigned char trans_bg = 0;
	gib_list *l, *last = NULL;
	char *s;

	mode = "collage";

@@ -105,15 +104,9 @@ void init_collage_mode(void)
		gib_imlib_image_fill_rectangle(im_main, 0, 0, w, h, 0, 0, 0, 255);
	}

	/* Create the title string */

	if (!opt.title)
		s = estrdup(PACKAGE " [collage mode]");
	else
		s = estrdup(feh_printf(opt.title, NULL, NULL));

	if (opt.display) {
		winwid = winwidget_create_from_image(im_main, s, WIN_TYPE_SINGLE);
		winwid = winwidget_create_from_image(im_main, WIN_TYPE_SINGLE);
		winwidget_rename(winwid, PACKAGE " [collage mode]");
		winwidget_show(winwid);
	}

@@ -210,7 +203,6 @@ void init_collage_mode(void)

	if (!opt.display)
		gib_imlib_free_image_and_decache(im_main);
	free(s);

	return;
}
+0 −2
Original line number Diff line number Diff line
@@ -137,8 +137,6 @@ int feh_load_image(Imlib_Image * im, feh_file * file);
void show_mini_usage(void);
void slideshow_change_image(winwidget winwid, int change, int render);
void slideshow_pause_toggle(winwidget w);
char *slideshow_create_name(feh_file * file, winwidget winwid);
char *thumbnail_create_name(feh_file * file, winwidget winwid);
void init_keyevents(void);
void init_buttonbindings(void);
void setup_stdin(void);
+2 −10
Original line number Diff line number Diff line
@@ -59,7 +59,6 @@ void init_index_mode(void)
	int lineno;
	unsigned char trans_bg = 0;
	int index_image_width, index_image_height;
	char *s;
	gib_list *line, *lines;

	if (opt.montage) {
@@ -164,15 +163,9 @@ void init_index_mode(void)
		gib_imlib_image_fill_rectangle(im_main, 0, 0, w, h + title_area_h, 0, 0, 0, 255);
	}

	/* Create the window title at this point */

	if (!opt.title)
		s = estrdup(PACKAGE " [index mode]");
	else
		s = estrdup(feh_printf(opt.title, NULL, NULL));

	if (opt.display) {
		winwid = winwidget_create_from_image(im_main, s, WIN_TYPE_SINGLE);
		winwid = winwidget_create_from_image(im_main, WIN_TYPE_SINGLE);
		winwidget_rename(winwid, PACKAGE " [index mode]");
		winwidget_show(winwid);
	}

@@ -348,7 +341,6 @@ void init_index_mode(void)
	if (!opt.display)
		gib_imlib_free_image_and_decache(im_main);

	free(s);
	return;
}

+4 −16
Original line number Diff line number Diff line
@@ -34,25 +34,14 @@ void init_multiwindow_mode(void)
{
	winwidget w = NULL;
	gib_list *l;
	feh_file *file = NULL;

	if (!opt.title)
		opt.title = PACKAGE " - %f";

	mode = "multiwindow";

	for (l = filelist; l; l = l->next) {
		char *s = NULL;
		int len = 0;
		file = FEH_FILE(l->data);
		current_file = l;

		if (!opt.title) {
			len = strlen(PACKAGE " - ") + strlen(file->filename) + 1;
			s = emalloc(len);
			snprintf(s, len, PACKAGE " - %s", file->filename);
		} else {
			s = estrdup(feh_printf(opt.title, file, w));
		}

		if ((w = winwidget_create_from_file(l, s, WIN_TYPE_SINGLE)) != NULL) {
		if ((w = winwidget_create_from_file(l, WIN_TYPE_SINGLE)) != NULL) {
			winwidget_show(w);
			if (opt.reload > 0)
				feh_add_unique_timer(cb_reload_timer, w, opt.reload);
@@ -62,7 +51,6 @@ void init_multiwindow_mode(void)
			D(("EEEK. Couldn't load image in multiwindow mode. "
						"I 'm not sure if this is a problem\n"));
		}
		free(s);
	}

	return;
+9 −47
Original line number Diff line number Diff line
@@ -48,6 +48,9 @@ void init_slideshow_mode(void)
		eprintf("--start-at %s: File not found in filelist",
				opt.start_list_at);

	if (!opt.title)
		opt.title = PACKAGE " [%u of %l] - %f",

	mode = "slideshow";
	for (; l; l = l->next) {
		if (last) {
@@ -55,7 +58,7 @@ void init_slideshow_mode(void)
			last = NULL;
		}
		current_file = l;
		if ((w = winwidget_create_from_file(l, NULL, WIN_TYPE_SLIDESHOW)) != NULL) {
		if ((w = winwidget_create_from_file(l, WIN_TYPE_SLIDESHOW)) != NULL) {
			success = 1;
			winwidget_show(w);
			if (opt.slideshow_delay > 0.0)
@@ -124,13 +127,6 @@ void cb_reload_timer(void *data)
		current_file = filelist;
	w->file = current_file;

	/* reset window name in case of current file order,
	 * filename, or filelist_length has changed.
	 */
	current_filename = slideshow_create_name(FEH_FILE(current_file->data), w);
	winwidget_rename(w, current_filename);
	free(current_filename);

	feh_reload_image(w, 1, 0);
	feh_add_unique_timer(cb_reload_timer, w, opt.reload);
	return;
@@ -138,7 +134,7 @@ void cb_reload_timer(void *data)

void feh_reload_image(winwidget w, int resize, int force_new)
{
	char *title, *new_title;
	char *new_title;
	int len;
	Imlib_Image tmp;
	int old_w, old_h;
@@ -167,8 +163,8 @@ void feh_reload_image(winwidget w, int resize, int force_new)
	len = strlen(w->name) + sizeof("Reloading: ") + 1;
	new_title = emalloc(len);
	snprintf(new_title, len, "Reloading: %s", w->name);
	title = estrdup(w->name);
	winwidget_rename(w, new_title);
	free(new_title);

	old_w = gib_imlib_image_get_width(w->im);
	old_h = gib_imlib_image_get_height(w->im);
@@ -189,9 +185,6 @@ void feh_reload_image(winwidget w, int resize, int force_new)
			im_weprintf(w, "Couldn't reload image. Is it still there?");
			winwidget_render_image(w, 0, 0);
		}
		winwidget_rename(w, title);
		free(title);
		free(new_title);
		return;
	}

@@ -231,10 +224,6 @@ void feh_reload_image(winwidget w, int resize, int force_new)
		winwidget_render_image(w, resize, 0);
	}

	winwidget_rename(w, title);
	free(title);
	free(new_title);

	return;
}

@@ -247,7 +236,6 @@ void slideshow_change_image(winwidget winwid, int change, int render)
	 * encounter invalid images.
	 */
	int our_filelist_len = filelist_len;
	char *s;

	unsigned char tmode =0;
	int tim_x =0;
@@ -396,11 +384,6 @@ void slideshow_change_image(winwidget winwid, int change, int render)
					winwidget_render_image(winwid, 1, 0);
				}
			}

			s = slideshow_create_name(FEH_FILE(current_file->data), winwid);
			winwidget_rename(winwid, s);
			free(s);

			break;
		} else
			last = current_file;
@@ -427,23 +410,6 @@ void slideshow_pause_toggle(winwidget w)
	winwidget_rename(w, NULL);
}

char *slideshow_create_name(feh_file * file, winwidget winwid)
{
	char *s = NULL;
	int len = 0;

	if (!opt.title) {
		len = strlen(PACKAGE " [slideshow mode] - ") + strlen(file->filename) + 1;
		s = emalloc(len);
		snprintf(s, len, PACKAGE " [%d of %d] - %s",
			gib_list_num(filelist, current_file) + 1, gib_list_length(filelist), file->filename);
	} else {
		s = estrdup(feh_printf(opt.title, file, winwid));
	}

	return(s);
}

void feh_action_run(feh_file * file, char *action, winwidget winwid)
{
	if (action) {
@@ -480,6 +446,7 @@ char *feh_printf(char *str, feh_file * file, winwidget winwid)

	ret[0] = '\0';
	filelist_tmppath = NULL;
	gib_list *f;

	for (c = str; *c != '\0'; c++) {
		if ((*c == '%') && (*(c+1) != '\0')) {
@@ -564,9 +531,8 @@ char *feh_printf(char *str, feh_file * file, winwidget winwid)
				}
				break;
			case 'u':
				snprintf(buf, sizeof(buf), "%d",
					 current_file != NULL ? gib_list_num(filelist, current_file)
					 + 1 : 0);
				f = current_file ? current_file : gib_list_find_by_data(filelist, file);
				snprintf(buf, sizeof(buf), "%d", f ? gib_list_num(filelist, f) + 1 : 0);
				strncat(ret, buf, sizeof(ret) - strlen(ret) - 1);
				break;
			case 'v':
@@ -620,7 +586,6 @@ char *feh_printf(char *str, feh_file * file, winwidget winwid)
void feh_filelist_image_remove(winwidget winwid, char do_delete)
{
	if (winwid->type == WIN_TYPE_SLIDESHOW) {
		char *s;
		gib_list *doomed;

		doomed = current_file;
@@ -647,9 +612,6 @@ void feh_filelist_image_remove(winwidget winwid, char do_delete)
			winwidget_destroy(winwid);
			return;
		}
		s = slideshow_create_name(FEH_FILE(winwid->file->data), winwid);
		winwidget_rename(winwid, s);
		free(s);
		winwidget_render_image(winwid, 1, 0);
	} else if ((winwid->type == WIN_TYPE_SINGLE)
		   || (winwid->type == WIN_TYPE_THUMBNAIL_VIEWER)) {
Loading