diff options
author | Daniel Friesel <derf@finalrewind.org> | 2021-01-28 22:10:29 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-28 22:10:29 +0100 |
commit | a1a47cf12c38b777e2d368363a85ccb5e94ded36 (patch) | |
tree | 51197761af67f605c6137862705628b4734b5663 /src | |
parent | c61984986c4e9f3de5baacf2331745dc1bac3f0d (diff) | |
parent | 31fd2f6412e3535500fef9da6164320dbbdb6bff (diff) |
Merge pull request #588 from avlec/master
.fehbg now stores the full path to the feh binary when it was run using a relative path (i.e., not from $PATH)
Diffstat (limited to 'src')
-rw-r--r-- | src/wallpaper.c | 185 |
1 files changed, 102 insertions, 83 deletions
diff --git a/src/wallpaper.c b/src/wallpaper.c index 37b5a1d..b62d28b 100644 --- a/src/wallpaper.c +++ b/src/wallpaper.c @@ -245,6 +245,106 @@ static void feh_wm_set_bg_maxed(Pixmap pmap, Imlib_Image im, int use_filelist, return; } +/* +** Creates a script that can be used to create the same background +** as the last time the program was called. +*/ +void feh_wm_gen_bg_script(char* fil, int centered, int scaled, int filled, int use_filelist) { + char * home = getenv("HOME"); + + if (!home) + return; + + FILE *fp; + int fd; + char *path; + char *exec_method; + char *absolute_path; + struct stat s; + gib_list *filelist_pos = filelist; + + if (strchr(cmdargv[0], '/')) + exec_method = feh_absolute_path(cmdargv[0]); + else + exec_method = cmdargv[0]; + + path = estrjoin("/", home, ".fehbg", NULL); + + if ((fp = fopen(path, "w")) == NULL) { + weprintf("Can't write to %s", path); + } else { + fputs("#!/bin/sh\n", fp); + fputs(exec_method, fp); + fputs(" --no-fehbg --bg-", fp); + if (centered) + fputs("center", fp); + else if (scaled) + fputs("scale", fp); + else if (filled == 1) + fputs("fill", fp); + else if (filled == 2) + fputs("max", fp); + else + fputs("tile", fp); + if (opt.image_bg) { + fputs(" --image-bg ", fp); + fputs(shell_escape(opt.image_bg), fp); + } +#ifdef HAVE_LIBXINERAMA + if (opt.xinerama) { + if (opt.xinerama_index >= 0) { + fprintf(fp, " --xinerama-index %d", opt.xinerama_index); + } + } + else { + fputs(" --no-xinerama", fp); + } +#endif /* HAVE_LIBXINERAMA */ + if (opt.geom_flags & XValue) { + fprintf(fp, " --geometry %c%d", + opt.geom_flags & XNegative ? '-' : '+', + opt.geom_flags & XNegative ? abs(opt.geom_x) : opt.geom_x); + if (opt.geom_flags & YValue) { + fprintf(fp, "%c%d", + opt.geom_flags & YNegative ? '-' : '+', + opt.geom_flags & YNegative ? abs(opt.geom_y) : opt.geom_y); + } + } + if (opt.force_aliasing) { + fputs(" --force-aliasing", fp); + } + fputc(' ', fp); + if (use_filelist) { +#ifdef HAVE_LIBXINERAMA + for (int i = 0; (i < opt.xinerama ? num_xinerama_screens : 1) && filelist_pos; i++) +#else + for (int i = 0; (i < 1 ) && filelist_pos; i++) +#endif + { + absolute_path = feh_absolute_path(FEH_FILE(filelist_pos->data)->filename); + fputs(shell_escape(absolute_path), fp); + filelist_pos = filelist_pos->next; + free(absolute_path); + fputc(' ', fp); + } + } else if (fil) { + absolute_path = feh_absolute_path(fil); + fputs(shell_escape(absolute_path), fp); + free(absolute_path); + } + fputc('\n', fp); + fd = fileno(fp); + if (fstat(fd, &s) != 0 || fchmod(fd, s.st_mode | S_IXUSR | S_IXGRP) != 0) { + weprintf("Can't set %s as executable", path); + } + fclose(fp); + } + free(path); + + if(exec_method != cmdargv[0]) + free(exec_method); +} + void feh_wm_set_bg(char *fil, Imlib_Image im, int centered, int scaled, int filled, int desktop, int use_filelist) { @@ -322,8 +422,6 @@ void feh_wm_set_bg(char *fil, Imlib_Image im, int centered, int scaled, unsigned char *data_root = NULL, *data_esetroot = NULL; Pixmap pmap_d1, pmap_d2; - char *home; - /* local display to set closedownmode on */ Display *disp2; Window root2; @@ -448,87 +546,8 @@ void feh_wm_set_bg(char *fil, Imlib_Image im, int centered, int scaled, gib_imlib_render_image_on_drawable(pmap_d1, im, 0, 0, 1, 1, 0); } - if (!opt.no_fehbg) { - home = getenv("HOME"); - if (home) { - FILE *fp; - int fd; - char *path; - char *absolute_path; - struct stat s; - gib_list *filelist_pos = filelist; - path = estrjoin("/", home, ".fehbg", NULL); - if ((fp = fopen(path, "w")) == NULL) { - weprintf("Can't write to %s", path); - } else { - fputs("#!/bin/sh\n", fp); - fputs(cmdargv[0], fp); - fputs(" --no-fehbg --bg-", fp); - if (centered) - fputs("center", fp); - else if (scaled) - fputs("scale", fp); - else if (filled == 1) - fputs("fill", fp); - else if (filled == 2) - fputs("max", fp); - else - fputs("tile", fp); - if (opt.image_bg) { - fputs(" --image-bg ", fp); - fputs(shell_escape(opt.image_bg), fp); - } -#ifdef HAVE_LIBXINERAMA - if (opt.xinerama) { - if (opt.xinerama_index >= 0) { - fprintf(fp, " --xinerama-index %d", opt.xinerama_index); - } - } - else { - fputs(" --no-xinerama", fp); - } -#endif /* HAVE_LIBXINERAMA */ - if (opt.geom_flags & XValue) { - fprintf(fp, " --geometry %c%d", - opt.geom_flags & XNegative ? '-' : '+', - opt.geom_flags & XNegative ? abs(opt.geom_x) : opt.geom_x); - if (opt.geom_flags & YValue) { - fprintf(fp, "%c%d", - opt.geom_flags & YNegative ? '-' : '+', - opt.geom_flags & YNegative ? abs(opt.geom_y) : opt.geom_y); - } - } - if (opt.force_aliasing) { - fputs(" --force-aliasing", fp); - } - fputc(' ', fp); - if (use_filelist) { -#ifdef HAVE_LIBXINERAMA - for (int i = 0; (i < opt.xinerama ? num_xinerama_screens : 1) && filelist_pos; i++) { -#else - for (int i = 0; (i < 1 ) && filelist_pos; i++) { -#endif - absolute_path = feh_absolute_path(FEH_FILE(filelist_pos->data)->filename); - fputs(shell_escape(absolute_path), fp); - filelist_pos = filelist_pos->next; - free(absolute_path); - fputc(' ', fp); - } - } else if (fil) { - absolute_path = feh_absolute_path(fil); - fputs(shell_escape(absolute_path), fp); - free(absolute_path); - } - fputc('\n', fp); - fd = fileno(fp); - if (fstat(fd, &s) != 0 || fchmod(fd, s.st_mode | S_IXUSR | S_IXGRP) != 0) { - weprintf("Can't set %s as executable", path); - } - fclose(fp); - } - free(path); - } - } + if (!opt.no_fehbg) + feh_wm_gen_bg_script(fil, centered, scaled, filled, use_filelist); /* create new display, copy pixmap to new display */ disp2 = XOpenDisplay(NULL); |