Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/* 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>
#include <jpeglib.h>
#include "transupp.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;
#endif /* HAVE_LIBXINERAMA */
#ifdef HAVE_LIBXINERAMA
void
init_xinerama(void)
{
if (opt.xinerama && XineramaIsActive(disp)) {
int major, minor;
xinerama_screen = 0;
XineramaQueryVersion(disp, &major, &minor);
xinerama_screens = XineramaQueryScreens(disp, &num_xinerama_screens);
}
}
#endif /* HAVE_LIBXINERAMA */
void
init_imlib_fonts(void)
{
D_ENTER(4);
/* Set up the font stuff */
imlib_add_path_to_font_path(".");
imlib_add_path_to_font_path(PREFIX "/share/feh/fonts");
imlib_add_path_to_font_path("./ttfonts");
D_RETURN_(4);
}
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
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
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
init_x_and_imlib(void)
{
D_ENTER(4);
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));
D_RETURN_(4);
}
int
feh_load_image_char(Imlib_Image * im, char *filename)
{
feh_file *file;
int i;
D_ENTER(4);
file = feh_file_new(filename);
i = feh_load_image(im, file);
feh_file_free(file);
D_RETURN(4, i);
}
int
feh_load_image(Imlib_Image * im, feh_file * file)
{
Imlib_Load_Error err;
D_ENTER(4);
D(3, ("filename is %s, image is %p\n", file->filename, im));
if (!file || !file->filename)
D_RETURN(4, 0);
/* 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)
D_RETURN(4, 0);
*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:
Loading
Loading full blame...