summaryrefslogtreecommitdiff
path: root/src/imlib.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/imlib.c')
-rw-r--r--src/imlib.c107
1 files changed, 69 insertions, 38 deletions
diff --git a/src/imlib.c b/src/imlib.c
index 10ab718..16fbfba 100644
--- a/src/imlib.c
+++ b/src/imlib.c
@@ -78,8 +78,8 @@ void init_xinerama(void)
XineramaQueryVersion(disp, &major, &minor);
xinerama_screens = XineramaQueryScreens(disp, &num_xinerama_screens);
- if (getenv("XINERAMA_SCREEN"))
- xinerama_screen = atoi(getenv("XINERAMA_SCREEN"));
+ if (opt.xinerama_index >= 0)
+ xinerama_screen = opt.xinerama_index;
else {
xinerama_screen = 0;
XQueryPointer(disp, root, &dw, &dw, &px, &py, &di, &di, &du);
@@ -312,7 +312,13 @@ static char *feh_magick_load_image(char *filename)
snprintf(argv_fd, sizeof(argv_fd), "png:fd:%d", fd);
- if ((childpid = fork()) == 0) {
+ if ((childpid = fork()) < 0) {
+ weprintf("%s: Can't load with imagemagick. Fork failed:", filename);
+ unlink(sfn);
+ free(sfn);
+ sfn = NULL;
+ }
+ else if (childpid == 0) {
/* discard convert output */
devnull = open("/dev/null", O_WRONLY);
@@ -326,7 +332,7 @@ static char *feh_magick_load_image(char *filename)
setpgid(0, 0);
execlp("convert", "convert", filename, argv_fd, NULL);
- exit(1);
+ _exit(1);
}
else {
alarm(opt.magick_timeout);
@@ -394,7 +400,7 @@ static char *feh_http_load_image(char *url)
if (strlen(tmpname) > (NAME_MAX-6))
tmpname[NAME_MAX-7] = '\0';
-
+
sfn = estrjoin("_", tmpname, "XXXXXX", NULL);
free(tmpname);
@@ -411,6 +417,10 @@ static char *feh_http_load_image(char *url)
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, ebuff);
curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1L);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
+ if (opt.insecure_ssl) {
+ curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
+ curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0);
+ }
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
@@ -597,8 +607,12 @@ void feh_draw_filename(winwidget w)
len = snprintf(NULL, 0, "%d of %d", gib_list_length(filelist),
gib_list_length(filelist)) + 1;
s = emalloc(len);
- snprintf(s, len, "%d of %d", gib_list_num(filelist, current_file) +
- 1, gib_list_length(filelist));
+ 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);
@@ -631,7 +645,7 @@ void feh_draw_filename(winwidget w)
return;
}
-#ifdef HAVE_LIBEXIF
+#ifdef HAVE_LIBEXIF
void feh_draw_exif(winwidget w)
{
static Imlib_Font fn = NULL;
@@ -656,13 +670,13 @@ void feh_draw_exif(winwidget w)
fn = feh_load_font(w);
- if (buffer == NULL)
+ if (buffer == NULL)
{
snprintf(buffer, EXIF_MAX_DATA, "%s", estrdup("Failed to run exif command"));
gib_imlib_get_text_size(fn, &buffer[0], NULL, &width, &height, IMLIB_TEXT_TO_RIGHT);
no_lines = 1;
}
- else
+ else
{
while ( (no_lines < 128) && (pos < EXIF_MAX_DATA) )
@@ -688,9 +702,9 @@ void feh_draw_exif(winwidget w)
pos++;
break;
}
-
+
pos++;
- pos2++;
+ pos2++;
}
gib_imlib_get_text_size(fn, info_line, NULL, &line_width,
@@ -720,7 +734,7 @@ void feh_draw_exif(winwidget w)
feh_imlib_image_fill_text_bg(im, width, height);
- for (i = 0; i < no_lines; i++)
+ for (i = 0; i < no_lines; i++)
{
gib_imlib_text_draw(im, fn, NULL, 2, (i * line_height) + 2,
info_buf[i], IMLIB_TEXT_TO_RIGHT, 0, 0, 0, 255);
@@ -1007,28 +1021,29 @@ void feh_display_status(char stat)
void feh_edit_inplace(winwidget w, int op)
{
- int ret;
- Imlib_Image old;
- Imlib_Load_Error err;
+ int tmp;
+ Imlib_Image old = NULL;
+ Imlib_Load_Error err = IMLIB_LOAD_ERROR_NONE;
if (!w->file || !w->file->data || !FEH_FILE(w->file->data)->filename)
return;
- if (!strcmp(gib_imlib_image_format(w->im), "jpeg")) {
+ if (!strcmp(gib_imlib_image_format(w->im), "jpeg") &&
+ !path_is_url(FEH_FILE(w->file->data)->filename)) {
feh_edit_inplace_lossless(w, op);
feh_reload_image(w, 1, 1);
return;
}
- ret = feh_load_image(&old, FEH_FILE(w->file->data));
- if (ret) {
- if (op == INPLACE_EDIT_FLIP) {
- imlib_context_set_image(old);
+ old = imlib_load_image_with_error_return(FEH_FILE(w->file->data)->filename, &err);
+
+ if ((old != NULL) && (err == IMLIB_LOAD_ERROR_NONE)) {
+ imlib_context_set_image(old);
+ if (op == INPLACE_EDIT_FLIP)
imlib_image_flip_vertical();
- } else if (op == INPLACE_EDIT_MIRROR) {
- imlib_context_set_image(old);
+ else if (op == INPLACE_EDIT_MIRROR)
imlib_image_flip_horizontal();
- } else
- gib_imlib_image_orientate(old, op);
+ else
+ imlib_image_orientate(op);
gib_imlib_save_image_with_error_return(old,
FEH_FILE(w->file->data)->filename, &err);
gib_imlib_free_image(old);
@@ -1037,7 +1052,23 @@ void feh_edit_inplace(winwidget w, int op)
w, err);
feh_reload_image(w, 1, 1);
} else {
- im_weprintf(w, "failed to load image from disk to edit it in place");
+ /*
+ * Image was opened using curl/magick or has been deleted after
+ * opening it
+ */
+ imlib_context_set_image(w->im);
+ if (op == INPLACE_EDIT_FLIP)
+ imlib_image_flip_vertical();
+ else if (op == INPLACE_EDIT_MIRROR)
+ imlib_image_flip_horizontal();
+ else {
+ imlib_image_orientate(op);
+ tmp = w->im_w;
+ FEH_FILE(w->file->data)->info->width = w->im_w = w->im_h;
+ FEH_FILE(w->file->data)->info->height = w->im_h = tmp;
+ }
+ im_weprintf(w, "unable to edit in place. Changes have not been saved.");
+ winwidget_render_image(w, 1, 0);
}
return;
@@ -1165,15 +1196,16 @@ void feh_edit_inplace_lossless(winwidget w, int op)
if ((pid = fork()) < 0) {
im_weprintf(w, "lossless %s: fork failed:", op_name);
- exit(1);
+ free(file_str);
+ return;
}
else if (pid == 0) {
execlp("jpegtran", "jpegtran", "-copy", "all", op_op, op_value,
"-outfile", file_str, file_str, NULL);
- im_weprintf(w, "lossless %s: Is 'jpegtran' installed? Failed to exec:", op_name);
- exit(1);
+ weprintf("lossless %s: Is 'jpegtran' installed? Failed to exec:", op_name);
+ _exit(1);
}
else {
waitpid(pid, &status, 0);
@@ -1189,8 +1221,7 @@ void feh_edit_inplace_lossless(winwidget w, int op)
}
}
if ((pid = fork()) < 0) {
- im_weprintf(w, "lossless %s: cannot fix rotation: fork:", op_name);
- exit(1);
+ im_weprintf(w, "lossless %s: fork failed while updating EXIF tags:", op_name);
}
else if (pid == 0) {
@@ -1199,8 +1230,8 @@ void feh_edit_inplace_lossless(winwidget w, int op)
dup2(devnull, 1);
execlp("jpegexiforient", "jpegexiforient", "-1", file_str, NULL);
- im_weprintf(w, "lossless %s: Failed to exec jpegexiforient:", op_name);
- exit(1);
+ weprintf("lossless %s: Failed to exec jpegexiforient:", op_name);
+ _exit(1);
}
else {
waitpid(pid, &status, 0);
@@ -1253,9 +1284,9 @@ void feh_draw_actions(winwidget w)
for (i = 0; i < 10; i++) {
if (opt.actions[i]) {
- line = emalloc(strlen(opt.actions[i]) + 5);
+ line = emalloc(strlen(opt.action_titles[i]) + 5);
strcpy(line, "0: ");
- line = strcat(line, opt.actions[i]);
+ line = strcat(line, opt.action_titles[i]);
gib_imlib_get_text_size(fn, line, NULL, &tw, &th, IMLIB_TEXT_TO_RIGHT);
free(line);
if (tw > max_tw)
@@ -1285,13 +1316,13 @@ void feh_draw_actions(winwidget w)
gib_imlib_text_draw(im, fn, NULL, 1, 1, "defined actions:", IMLIB_TEXT_TO_RIGHT, 255, 255, 255, 255);
for (i = 0; i < 10; i++) {
- if (opt.actions[i]) {
+ if (opt.action_titles[i]) {
cur_action++;
- line = emalloc(strlen(opt.actions[i]) + 5);
+ line = emalloc(strlen(opt.action_titles[i]) + 5);
sprintf(index, "%d", i);
strcpy(line, index);
strcat(line, ": ");
- strcat(line, opt.actions[i]);
+ strcat(line, opt.action_titles[i]);
gib_imlib_text_draw(im, fn, NULL, 2,
(cur_action * line_th) + 2, line,