Esempio n. 1
0
File: imlib.c Progetto: Caellian/feh
void feh_draw_filename(winwidget w)
{
	static Imlib_Font fn = NULL;
	int tw = 0, th = 0, nw = 0;
	Imlib_Image im = NULL;
	char *s = NULL;
	int len = 0;

	if ((!w->file) || (!FEH_FILE(w->file->data))
			|| (!FEH_FILE(w->file->data)->filename))
		return;

	fn = feh_load_font(w);

	/* Work out how high the font is */
	gib_imlib_get_text_size(fn, FEH_FILE(w->file->data)->filename, NULL, &tw,
			&th, IMLIB_TEXT_TO_RIGHT);

	if (gib_list_length(filelist) > 1) {
		len = snprintf(NULL, 0, "%d of %d",  gib_list_length(filelist),
				gib_list_length(filelist)) + 1;
		s = emalloc(len);
		if (w->file)
			snprintf(s, len, "%d of %d", gib_list_num(filelist, w->file) +
					1, gib_list_length(filelist));
		else
			snprintf(s, len, "%d of %d", gib_list_num(filelist, current_file) +
					1, gib_list_length(filelist));

		gib_imlib_get_text_size(fn, s, NULL, &nw, NULL, IMLIB_TEXT_TO_RIGHT);

		if (nw > tw)
			tw = nw;
	}

	tw += 3;
	th += 3;
	im = imlib_create_image(tw, 2 * th);
	if (!im)
		eprintf("Couldn't create image. Out of memory?");

	feh_imlib_image_fill_text_bg(im, tw, 2 * th);

	gib_imlib_text_draw(im, fn, NULL, 2, 2, FEH_FILE(w->file->data)->filename,
			IMLIB_TEXT_TO_RIGHT, 0, 0, 0, 255);
	gib_imlib_text_draw(im, fn, NULL, 1, 1, FEH_FILE(w->file->data)->filename,
			IMLIB_TEXT_TO_RIGHT, 255, 255, 255, 255);

	if (s) {
		gib_imlib_text_draw(im, fn, NULL, 2, th + 1, s, IMLIB_TEXT_TO_RIGHT, 0, 0, 0, 255);
		gib_imlib_text_draw(im, fn, NULL, 1, th, s, IMLIB_TEXT_TO_RIGHT, 255, 255, 255, 255);
		free(s);
	}

	gib_imlib_render_image_on_drawable(w->bg_pmap, im, 0, 0, 1, 1, 0);

	gib_imlib_free_image_and_decache(im);
	return;
}
Esempio n. 2
0
void cb_reload_timer(void *data)
{
	gib_list *l;
	char *current_filename;

	winwidget w = (winwidget) data;

	/* save the current filename for refinding it in new list */
	current_filename = estrdup(FEH_FILE(current_file->data)->filename);

	for (l = filelist; l; l = l->next) {
		feh_file_free(l->data);
		l->data = NULL;
	}
	gib_list_free_and_data(filelist);
	filelist = NULL;
	filelist_len = 0;
	current_file = NULL;

	/* rebuild filelist from original_file_items */
	if (gib_list_length(original_file_items) > 0)
		for (l = gib_list_last(original_file_items); l; l = l->prev)
			add_file_to_filelist_recursively(l->data, FILELIST_FIRST);
	else if (!opt.filelistfile && !opt.bgmode)
		add_file_to_filelist_recursively(".", FILELIST_FIRST);
	
	if (!(filelist_len = gib_list_length(filelist))) {
		eprintf("No files found to reload.");
	}

	/* find the previously current file */
	for (l = filelist; l; l = l->next)
		if (strcmp(FEH_FILE(l->data)->filename, current_filename) == 0) {
			current_file = l;
			break;
		}

	free(current_filename);

	filelist = gib_list_first(gib_list_reverse(filelist));

	if (!current_file)
		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);
	if (opt.reload)
		feh_add_unique_timer(cb_reload_timer, w, opt.reload);
	return;
}
Esempio n. 3
0
File: options.c Progetto: 12qu/feh
void init_parse_options(int argc, char **argv)
{
	/* TODO: sort these to match declaration of __fehoptions */

	/* For setting the command hint on X windows */
	cmdargc = argc;
	cmdargv = argv;

	/* Set default options */
	memset(&opt, 0, sizeof(fehoptions));
	opt.display = 1;
	opt.aspect = 1;
	opt.slideshow_delay = 0.0;
	opt.magick_timeout = -1;
	opt.thumb_w = 60;
	opt.thumb_h = 60;
	opt.thumb_redraw = 10;
	opt.menu_font = estrdup(DEFAULT_MENU_FONT);
	opt.font = NULL;
	opt.menu_bg = estrdup(PREFIX "/share/feh/images/menubg_default.png");
	opt.max_height = opt.max_width = UINT_MAX;

	opt.start_list_at = NULL;
	opt.jump_on_resort = 1;

	opt.screen_clip = 1;
#ifdef HAVE_LIBXINERAMA
	/* if we're using xinerama, then enable it by default */
	opt.xinerama = 1;
#endif				/* HAVE_LIBXINERAMA */

	feh_getopt_theme(argc, argv);

	D(("About to check for theme configuration\n"));
	feh_check_theme_options(argv);

	D(("About to parse commandline options\n"));
	/* Parse the cmdline args */
	feh_parse_option_array(argc, argv, 1);

	/* If we have a filelist to read, do it now */
	if (opt.filelistfile) {
		/* joining two reverse-sorted lists in this manner works nicely for us
		   here, as files specified on the commandline end up at the *end* of
		   the combined filelist, in the specified order. */
		D(("About to load filelist from file\n"));
		filelist = gib_list_cat(filelist, feh_read_filelist(opt.filelistfile));
	}

	D(("Options parsed\n"));

	filelist_len = gib_list_length(filelist);
	if (!filelist_len)
		show_mini_usage();

	check_options();

	feh_prepare_filelist();
	return;
}
Esempio n. 4
0
void feh_display_status(char stat)
{
	static int i = 0;
	static int init_len = 0;
	int j = 0;

	D(("filelist %p, filelist->next %p\n", filelist, filelist->next));

	if (!stat) {
		putc('\n', stdout);
		init_len = 0;
		i = 0;
		return;
	}

	if (!init_len)
		init_len = gib_list_length(filelist);

	if (i) {
		if (reset_output) {
			/* There's just been an error message. Unfortunate ;) */
			for (j = 0; j < (((i % 50) + ((i % 50) / 10)) + 7); j++)
				putc(' ', stdout);
		}

		if (!(i % 50)) {
			int len = gib_list_length(filelist);

			fprintf(stdout, " %5d/%d (%d)\n[%3d%%] ",
					i, init_len, len, ((int) ((float) i / init_len * 100)));

		} else if ((!(i % 10)) && (!reset_output))
			putc(' ', stdout);

		reset_output = 0;
	} else
		fputs("[  0%] ", stdout);

	fprintf(stdout, "%c", stat);
	fflush(stdout);
	i++;
	return;
}
Esempio n. 5
0
void feh_prepare_filelist(void)
{
	if (opt.list || opt.customlist || (opt.sort > SORT_FILENAME)
			|| opt.preload) {
		/* For these sort options, we have to preload images */
		filelist = feh_file_info_preload(filelist);
		if (!gib_list_length(filelist))
			show_mini_usage();
	}

	D(3, ("sort mode requested is: %d\n", opt.sort));
	switch (opt.sort) {
	case SORT_NONE:
		if (opt.randomize) {
			/* Randomize the filename order */
			filelist = gib_list_randomize(filelist);
		} else if (!opt.reverse) {
			/* Let's reverse the list. Its back-to-front right now ;) */
			filelist = gib_list_reverse(filelist);
		}
		break;
	case SORT_NAME:
		filelist = gib_list_sort(filelist, feh_cmp_name);
		break;
	case SORT_FILENAME:
		filelist = gib_list_sort(filelist, feh_cmp_filename);
		break;
	case SORT_WIDTH:
		filelist = gib_list_sort(filelist, feh_cmp_width);
		break;
	case SORT_HEIGHT:
		filelist = gib_list_sort(filelist, feh_cmp_height);
		break;
	case SORT_PIXELS:
		filelist = gib_list_sort(filelist, feh_cmp_pixels);
		break;
	case SORT_SIZE:
		filelist = gib_list_sort(filelist, feh_cmp_size);
		break;
	case SORT_FORMAT:
		filelist = gib_list_sort(filelist, feh_cmp_format);
		break;
	default:
		break;
	}

	/* no point reversing a random list */
	if (opt.reverse && (opt.sort != SORT_NONE)) {
		D(3, ("Reversing filelist as requested\n"));
		filelist = gib_list_reverse(filelist);
	}

	return;
}
Esempio n. 6
0
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);
}
Esempio n. 7
0
File: main.c Progetto: braneed/scrot
Imlib_Image
stalk_image_concat(gib_list * images)
{
  int tot_w = 0, max_h = 0, w, h;
  int x = 0;
  gib_list *l, *item;
  Imlib_Image ret, im;

  if (gib_list_length(images) == 0)
    return NULL;

  l = images;
  while (l) {
    im = (Imlib_Image) l->data;
    h = gib_imlib_image_get_height(im);
    w = gib_imlib_image_get_width(im);
    if (h > max_h)
      max_h = h;
    tot_w += w;
    l = l->next;
  }
  ret = imlib_create_image(tot_w, max_h);
  gib_imlib_image_fill_rectangle(ret, 0, 0, tot_w, max_h, 255, 0, 0, 0);
  l = images;
  while (l) {
    im = (Imlib_Image) l->data;
    item = l;
    l = l->next;
    h = gib_imlib_image_get_height(im);
    w = gib_imlib_image_get_width(im);
    gib_imlib_blend_image_onto_image(ret, im, 0, 0, 0, w, h, x, 0, w, h, 1, 0,
                                     0);
    x += w;
    gib_imlib_free_image_and_decache(im);
    free(item);
  }
  return ret;
}
Esempio n. 8
0
char *feh_printf(char *str, feh_file * file, winwidget winwid)
{
	char *c;
	char buf[20];
	static char ret[4096];
	char *filelist_tmppath;

	ret[0] = '\0';
	filelist_tmppath = NULL;

	for (c = str; *c != '\0'; c++) {
		if ((*c == '%') && (*(c+1) != '\0')) {
			c++;
			switch (*c) {
			case 'f':
				if (file)
					strncat(ret, file->filename, sizeof(ret) - strlen(ret) - 1);
				break;
			case 'F':
				if (file)
					strncat(ret, shell_escape(file->filename), sizeof(ret) - strlen(ret) - 1);
				break;
			case 'h':
				if (file && (file->info || !feh_file_info_load(file, NULL))) {
					snprintf(buf, sizeof(buf), "%d", file->info->height);
					strncat(ret, buf, sizeof(ret) - strlen(ret) - 1);
				}
				break;
			case 'l':
				snprintf(buf, sizeof(buf), "%d", gib_list_length(filelist));
				strncat(ret, buf, sizeof(ret) - strlen(ret) - 1);
				break;
			case 'L':
				if (filelist_tmppath != NULL) {
					strncat(ret, filelist_tmppath, sizeof(ret) - strlen(ret) - 1);
				} else {
					filelist_tmppath = feh_unique_filename("/tmp/","filelist");
					feh_write_filelist(filelist, filelist_tmppath);
					strncat(ret, filelist_tmppath, sizeof(ret) - strlen(ret) - 1);
				}
				break;
			case 'm':
				strncat(ret, mode, sizeof(ret) - strlen(ret) - 1);
				break;
			case 'n':
				if (file)
					strncat(ret, file->name, sizeof(ret) - strlen(ret) - 1);
				break;
			case 'N':
				if (file)
					strncat(ret, shell_escape(file->name), sizeof(ret) - strlen(ret) - 1);
				break;
			case 'o':
				if (winwid) {
					snprintf(buf, sizeof(buf), "%d,%d", winwid->im_x,
						winwid->im_y);
					strncat(ret, buf, sizeof(ret) - strlen(ret) - 1);
				}
				break;
			case 'p':
				if (file && (file->info || !feh_file_info_load(file, NULL))) {
					snprintf(buf, sizeof(buf), "%d", file->info->pixels);
					strncat(ret, buf, sizeof(ret) - strlen(ret) - 1);
				}
				break;
			case 'P':
				if (file && (file->info || !feh_file_info_load(file, NULL))) {
					strncat(ret, format_size(file->info->pixels), sizeof(ret) - strlen(ret) - 1);
				}
				break;
			case 'r':
				if (winwid) {
					snprintf(buf, sizeof(buf), "%.1f", winwid->im_angle);
					strncat(ret, buf, sizeof(ret) - strlen(ret) - 1);
				}
				break;
			case 's':
				if (file && (file->info || !feh_file_info_load(file, NULL))) {
					snprintf(buf, sizeof(buf), "%d", file->info->size);
					strncat(ret, buf, sizeof(ret) - strlen(ret) - 1);
				}
				break;
			case 'S':
				if (file && (file->info || !feh_file_info_load(file, NULL))) {
					strncat(ret, format_size(file->info->size), sizeof(ret) - strlen(ret) - 1);
				}
				break;
			case 't':
				if (file && (file->info || !feh_file_info_load(file, NULL))) {
					strncat(ret, file->info->format, sizeof(ret) - strlen(ret) - 1);
				}
				break;
			case 'u':
				snprintf(buf, sizeof(buf), "%d",
					 current_file != NULL ? gib_list_num(filelist, current_file)
					 + 1 : 0);
				strncat(ret, buf, sizeof(ret) - strlen(ret) - 1);
				break;
			case 'v':
				strncat(ret, VERSION, sizeof(ret) - strlen(ret) - 1);
				break;
			case 'V':
				snprintf(buf, sizeof(buf), "%d", getpid());
				strncat(ret, buf, sizeof(ret) - strlen(ret) - 1);
				break;
			case 'w':
				if (file && (file->info || !feh_file_info_load(file, NULL))) {
					snprintf(buf, sizeof(buf), "%d", file->info->width);
					strncat(ret, buf, sizeof(ret) - strlen(ret) - 1);
				}
				break;
			case 'z':
				if (winwid) {
					snprintf(buf, sizeof(buf), "%.2f", winwid->zoom);
					strncat(ret, buf, sizeof(ret) - strlen(ret) - 1);
				}
				break;
			case '%':
				strncat(ret, "%", sizeof(ret) - strlen(ret) - 1);
				break;
			default:
				weprintf("Unrecognized format specifier %%%c", *c);
				if ((strlen(ret) + 3) < sizeof(ret))
					strncat(ret, c - 1, 2);
				break;
			}
		} else if ((*c == '\\') && (*(c+1) != '\0') && ((strlen(ret) + 3) < sizeof(ret))) {
			c++;
			switch (*c) {
			case 'n':
				strcat(ret, "\n");
				break;
			default:
				strncat(ret, c - 1, 2);
				break;
			}
		} else if ((strlen(ret) + 2) < sizeof(ret))
			strncat(ret, c, 1);
	}
	if (filelist_tmppath != NULL)
		free(filelist_tmppath);
	return(ret);
}