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 = 0;
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);
Birte Kristina Friesel
committed
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/*
* XXX gib_imlib_save_image_with_error_return breaks with *.END and
* similar because it tries to set the image format, which only works
* with .end .
* So we leave that part out.
*/
void ungib_imlib_save_image_with_error_return(Imlib_Image im, char *file,
Imlib_Load_Error * error_return)
{
char *tmp;
imlib_context_set_image(im);
tmp = strrchr(file, '.');
if (tmp) {
char *p, *pp;
p = gib_estrdup(tmp + 1);
pp = p;
while(*pp) {
*pp = tolower(*pp);
pp++;
}
imlib_image_set_format(p);
gib_efree(p);
}
imlib_save_image_with_error_return(file, error_return);
}
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
void feh_imlib_print_load_error(char *file, winwidget w, Imlib_Load_Error err)
{
if (err == IMLIB_LOAD_ERROR_OUT_OF_FILE_DESCRIPTORS)
eprintf("%s - Out of file descriptors while loading", file);
else if (!opt.quiet || w) {
switch (err) {
case IMLIB_LOAD_ERROR_FILE_DOES_NOT_EXIST:
im_weprintf(w, "%s - File does not exist", file);
break;
case IMLIB_LOAD_ERROR_FILE_IS_DIRECTORY:
im_weprintf(w, "%s - Directory specified for image filename", file);
break;
case IMLIB_LOAD_ERROR_PERMISSION_DENIED_TO_READ:
im_weprintf(w, "%s - No read access", file);
break;
case IMLIB_LOAD_ERROR_UNKNOWN:
case IMLIB_LOAD_ERROR_NO_LOADER_FOR_FILE_FORMAT:
im_weprintf(w, "%s - No Imlib2 loader for that file format", file);
break;
case IMLIB_LOAD_ERROR_PATH_TOO_LONG:
im_weprintf(w, "%s - Path specified is too long", file);
break;
case IMLIB_LOAD_ERROR_PATH_COMPONENT_NON_EXISTANT:
im_weprintf(w, "%s - Path component does not exist", file);
break;
case IMLIB_LOAD_ERROR_PATH_COMPONENT_NOT_DIRECTORY:
im_weprintf(w, "%s - Path component is not a directory", file);
break;
case IMLIB_LOAD_ERROR_PATH_POINTS_OUTSIDE_ADDRESS_SPACE:
im_weprintf(w, "%s - Path points outside address space", file);
break;
case IMLIB_LOAD_ERROR_TOO_MANY_SYMBOLIC_LINKS:
im_weprintf(w, "%s - Too many levels of symbolic links", file);
break;
case IMLIB_LOAD_ERROR_OUT_OF_MEMORY:
im_weprintf(w, "While loading %s - Out of memory", file);
break;
case IMLIB_LOAD_ERROR_PERMISSION_DENIED_TO_WRITE:
im_weprintf(w, "%s - Cannot write to directory", file);
break;
case IMLIB_LOAD_ERROR_OUT_OF_DISK_SPACE:
im_weprintf(w, "%s - Cannot write - out of disk space", file);
break;
Loading
Loading full blame...