Skip to content
imlib.c 27.9 KiB
Newer Older
/* imlib.c

Copyright (C) 1999-2003 Tom Gilbert.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to
deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies of the Software and its documentation and acknowledgment shall be
given in the documentation and software packages that this Software was
used.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

*/

#include "feh.h"
#include "filelist.h"
#include "winwidget.h"
#include "options.h"

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>

Display *disp = NULL;
Visual *vis = NULL;
Screen *scr = NULL;
Colormap cm;
int depth;
Atom wmDeleteWindow;
XContext xid_context = 0;
Window root = 0;

/* Xinerama support */
#ifdef HAVE_LIBXINERAMA
XineramaScreenInfo *xinerama_screens = NULL;
int xinerama_screen;
int num_xinerama_screens;

#ifdef HAVE_LIBXINERAMA
	if (opt.xinerama && XineramaIsActive(disp)) {
		int major, minor;
		xinerama_screen = 0;
		XineramaQueryVersion(disp, &major, &minor);
		xinerama_screens = XineramaQueryScreens(disp, &num_xinerama_screens);
	}
	/* Set up the font stuff */
	imlib_add_path_to_font_path(".");
	imlib_add_path_to_font_path(PREFIX "/share/feh/fonts");
	disp = XOpenDisplay(NULL);
	if (!disp)
		eprintf("Can't open X display. It *is* running, yeah?");
	vis = DefaultVisual(disp, DefaultScreen(disp));
	depth = DefaultDepth(disp, DefaultScreen(disp));
	cm = DefaultColormap(disp, DefaultScreen(disp));
	root = RootWindow(disp, DefaultScreen(disp));
	scr = ScreenOfDisplay(disp, DefaultScreen(disp));
	xid_context = XUniqueContext();

#ifdef HAVE_LIBXINERAMA
	init_xinerama();
#endif				/* HAVE_LIBXINERAMA */
	imlib_context_set_display(disp);
	imlib_context_set_visual(vis);
	imlib_context_set_colormap(cm);
	imlib_context_set_color_modifier(NULL);
	imlib_context_set_progress_function(NULL);
	imlib_context_set_operation(IMLIB_OP_COPY);
	wmDeleteWindow = XInternAtom(disp, "WM_DELETE_WINDOW", False);
	/* Initialise random numbers */
	srand(getpid() * time(NULL) % ((unsigned int) -1));
int feh_load_image_char(Imlib_Image * im, char *filename)
	feh_file *file;
	int i;

	file = feh_file_new(filename);
	i = feh_load_image(im, file);
	feh_file_free(file);
int feh_load_image(Imlib_Image * im, feh_file * file)
	Imlib_Load_Error err;

	D(3, ("filename is %s, image is %p\n", file->filename, im));

	if (!file || !file->filename)

	/* Handle URLs */
	if ((!strncmp(file->filename, "http://", 7)) || (!strncmp(file->filename, "https://", 8))
			|| (!strncmp(file->filename, "ftp://", 6))) {
		char *tmpname = NULL;
		char *tempcpy;

		tmpname = feh_http_load_image(file->filename);
		if (tmpname == NULL)
		*im = imlib_load_image_with_error_return(tmpname, &err);
		if (im) {
			/* load the info now, in case it's needed after we delete the
			   temporary image file */
			tempcpy = file->filename;
			file->filename = tmpname;
			feh_file_info_load(file, *im);
			file->filename = tempcpy;
		}
		if ((opt.slideshow) && (opt.reload == 0)) {
			/* Http, no reload, slideshow. Let's keep this image on hand... */
			free(file->filename);
			file->filename = estrdup(tmpname);
		} else {
			/* Don't cache the image if we're doing reload + http (webcams etc) */
			if (!opt.keep_http)
				unlink(tmpname);
		}
		if (!opt.keep_http)
			add_file_to_rm_filelist(tmpname);
		free(tmpname);
	} else {
		*im = imlib_load_image_with_error_return(file->filename, &err);
	}

	if ((err) || (!im)) {
		if (opt.verbose && !opt.quiet) {
			fprintf(stdout, "\n");
			reset_output = 1;
		}
		/* Check error code */
		switch (err) {
		case IMLIB_LOAD_ERROR_FILE_DOES_NOT_EXIST:
			if (!opt.quiet)
				weprintf("%s - File does not exist", file->filename);
			break;
		case IMLIB_LOAD_ERROR_FILE_IS_DIRECTORY:
			if (!opt.quiet)
				weprintf("%s - Directory specified for image filename", file->filename);
			break;
		case IMLIB_LOAD_ERROR_PERMISSION_DENIED_TO_READ:
			if (!opt.quiet)
				weprintf("%s - No read access to directory", file->filename);
			break;
		case IMLIB_LOAD_ERROR_UNKNOWN:
		case IMLIB_LOAD_ERROR_NO_LOADER_FOR_FILE_FORMAT:
			if (!opt.quiet)
				weprintf("%s - No Imlib2 loader for that file format", file->filename);
			break;
		case IMLIB_LOAD_ERROR_PATH_TOO_LONG:
			if (!opt.quiet)
				weprintf("%s - Path specified is too long", file->filename);
			break;
		case IMLIB_LOAD_ERROR_PATH_COMPONENT_NON_EXISTANT:
			if (!opt.quiet)
				weprintf("%s - Path component does not exist", file->filename);
			break;
		case IMLIB_LOAD_ERROR_PATH_COMPONENT_NOT_DIRECTORY:
			if (!opt.quiet)
				weprintf("%s - Path component is not a directory", file->filename);
			break;
		case IMLIB_LOAD_ERROR_PATH_POINTS_OUTSIDE_ADDRESS_SPACE:
			if (!opt.quiet)
				weprintf("%s - Path points outside address space", file->filename);
			break;
		case IMLIB_LOAD_ERROR_TOO_MANY_SYMBOLIC_LINKS:
			if (!opt.quiet)
				weprintf("%s - Too many levels of symbolic links", file->filename);
Loading
Loading full blame...