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>
#ifdef HAVE_LIBCURL
#ifdef HAVE_LIBEXIF
#include "exif.h"
#endif
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;
#endif /* HAVE_LIBXINERAMA */
int childpid;
static char *feh_http_load_image(char *url);
static char *feh_magick_load_image(char *filename);
void init_xinerama(void)
if (opt.xinerama && XineramaIsActive(disp)) {
int major, minor;
Birte Kristina Friesel
committed
if (getenv("XINERAMA_SCREEN"))
xinerama_screen = atoi(getenv("XINERAMA_SCREEN"));
else
xinerama_screen = 0;
XineramaQueryVersion(disp, &major, &minor);
xinerama_screens = XineramaQueryScreens(disp, &num_xinerama_screens);
}
#endif /* HAVE_LIBXINERAMA */
void init_imlib_fonts(void)
{
/* Set up the font stuff */
imlib_add_path_to_font_path(".");
imlib_add_path_to_font_path(PREFIX "/share/feh/fonts");
Birte Kristina Friesel
committed
return;
}
void init_x_and_imlib(void)
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();
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));
Birte Kristina Friesel
committed
return;
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);
Birte Kristina Friesel
committed
return(i);
int feh_load_image(Imlib_Image * im, feh_file * file)
Imlib_Load_Error err;
enum { SRC_IMLIB, SRC_HTTP, SRC_MAGICK } image_source = SRC_IMLIB;
char *tmpname = NULL;
char *real_filename = NULL;
D(("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))) {
image_source = SRC_HTTP;
tmpname = feh_http_load_image(file->filename);
}
else
*im = imlib_load_image_with_error_return(file->filename, &err);
if ((err == IMLIB_LOAD_ERROR_UNKNOWN)
|| (err == IMLIB_LOAD_ERROR_NO_LOADER_FOR_FILE_FORMAT)) {
image_source = SRC_MAGICK;
tmpname = feh_magick_load_image(file->filename);
}
if (image_source != SRC_IMLIB) {
if (tmpname == NULL)
return 0;
*im = imlib_load_image_with_error_return(tmpname, &err);
if (im) {
real_filename = file->filename;
file->filename = tmpname;
feh_file_info_load(file, *im);
file->filename = real_filename;
#ifdef HAVE_LIBEXIF
file->ed = exif_get_data(tmpname);
if ((opt.slideshow) && (opt.reload == 0) && (image_source != SRC_MAGICK)) {
free(file->filename);
file->filename = estrdup(tmpname);
add_file_to_rm_filelist(tmpname);
else if ((image_source == SRC_MAGICK) || !opt.keep_http)
unlink(tmpname);
free(tmpname);
}
if ((err) || (!im)) {
if (opt.verbose && !opt.quiet) {
reset_output = 1;
}
if (err == IMLIB_LOAD_ERROR_OUT_OF_FILE_DESCRIPTORS)
eprintf("%s - Out of file descriptors while loading", file->filename);
else if (!opt.quiet) {
switch (err) {
case IMLIB_LOAD_ERROR_FILE_DOES_NOT_EXIST:
weprintf("%s - File does not exist", file->filename);
break;
case IMLIB_LOAD_ERROR_FILE_IS_DIRECTORY:
weprintf("%s - Directory specified for image filename", file->filename);
Loading
Loading full blame...