From b70e4366354eb7c182c9adb0bd7ac952f432d96a Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Mon, 1 Mar 2010 21:29:35 +0100 Subject: Apply patchto add --bg-fill (fullscreen background preserving aspect ratio) --- feh.1 | 2 ++ src/feh.h | 4 ++-- src/menu.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++------------- src/options.c | 6 +++++ src/support.c | 35 ++++++++++++++++++++++++---- src/support.h | 3 ++- 6 files changed, 100 insertions(+), 24 deletions(-) diff --git a/feh.1 b/feh.1 index 28a5d56..333a9d6 100644 --- a/feh.1 +++ b/feh.1 @@ -290,6 +290,8 @@ Show/Don't show image dimensions in thumbnail/index mode. .TP 5 .B --bg-scale FILE .TP 5 +.B --bg-fill FILE +.TP 5 .B --bg-seamless FILE Set your desktop background to FILE. Feh can use enlightenment IPC if you are running diff --git a/src/feh.h b/src/feh.h index 8641a3c..2e278e5 100644 --- a/src/feh.h +++ b/src/feh.h @@ -91,8 +91,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. enum mode_type { MODE_NORMAL = 0, MODE_PAN, MODE_ZOOM, MODE_ROTATE, MODE_BLUR, MODE_NEXT }; -enum bgmode_type { BG_MODE_NONE = 0, BG_MODE_TILE, BG_MODE_CENTER, BG_MODE_SEAMLESS, - BG_MODE_SCALE +enum bgmode_type { BG_MODE_NONE = 0, BG_MODE_TILE, BG_MODE_CENTER, + BG_MODE_SEAMLESS, BG_MODE_SCALE, BG_MODE_FILL }; enum slide_change { SLIDE_NEXT, SLIDE_PREV, SLIDE_FIRST, SLIDE_LAST, diff --git a/src/menu.c b/src/menu.c index b55329f..ed725bc 100644 --- a/src/menu.c +++ b/src/menu.c @@ -55,9 +55,11 @@ static void feh_menu_cb_background_set_tiled(feh_menu * m, feh_menu_item * i, vo static void feh_menu_cb_background_set_scaled(feh_menu * m, feh_menu_item * i, void *data); static void feh_menu_cb_background_set_seamless(feh_menu * m, feh_menu_item * i, void *data); static void feh_menu_cb_background_set_centered(feh_menu * m, feh_menu_item * i, void *data); +static void feh_menu_cb_background_set_filled(feh_menu * m, feh_menu_item * i, void *data); static void feh_menu_cb_background_set_tiled_no_file(feh_menu * m, feh_menu_item * i, void *data); static void feh_menu_cb_background_set_scaled_no_file(feh_menu * m, feh_menu_item * i, void *data); static void feh_menu_cb_background_set_centered_no_file(feh_menu * m, feh_menu_item * i, void *data); +static void feh_menu_cb_background_set_filled_no_file(feh_menu * m, feh_menu_item * i, void *data); static void feh_menu_cb_sort_filename(feh_menu * m, feh_menu_item * i, void *data); static void feh_menu_cb_sort_imagename(feh_menu * m, feh_menu_item * i, void *data); @@ -1109,6 +1111,7 @@ void feh_menu_init_common() feh_menu_add_entry(menu_bg, "Set Seamless", NULL, "SEAMLESS", NULL, NULL, NULL); feh_menu_add_entry(menu_bg, "Set Scaled", NULL, "SCALED", NULL, NULL, NULL); feh_menu_add_entry(menu_bg, "Set Centered", NULL, "CENTERED", NULL, NULL, NULL); + feh_menu_add_entry(menu_bg, "Set Filled", NULL, "FILLED", NULL, NULL, NULL); m = feh_menu_new(); m->name = estrdup("TILED"); @@ -1151,27 +1154,46 @@ void feh_menu_init_common() feh_menu_cb_background_set_centered, (void *) i, NULL); else feh_menu_add_entry(m, buf, NULL, NULL, - feh_menu_cb_background_set_centered_no_file, (void *) i, NULL); + feh_menu_cb_background_set_centered_no_file, + (void *) i, NULL); + } + + m = feh_menu_new(); + m->name = estrdup("FILLED"); + for (i = 0; i < num_desks; i++) { + snprintf(buf, sizeof(buf), "Desktop %d", i + 1); + if (opt.slideshow || opt.multiwindow) + feh_menu_add_entry(m, buf, NULL, NULL, + feh_menu_cb_background_set_filled, + (void *) i, NULL); + else + feh_menu_add_entry(m, buf, NULL, NULL, + feh_menu_cb_background_set_filled_no_file, + (void *) i, NULL); } } else { if (opt.slideshow || opt.multiwindow) { feh_menu_add_entry(menu_bg, "Set Tiled", NULL, - NULL, feh_menu_cb_background_set_tiled, NULL, NULL); + NULL, feh_menu_cb_background_set_tiled, NULL, NULL); feh_menu_add_entry(menu_bg, "Set Seamless", NULL, - NULL, feh_menu_cb_background_set_seamless, NULL, NULL); + NULL, feh_menu_cb_background_set_seamless, NULL, NULL); feh_menu_add_entry(menu_bg, "Set Scaled", NULL, - NULL, feh_menu_cb_background_set_scaled, NULL, NULL); + NULL, feh_menu_cb_background_set_scaled, NULL, NULL); feh_menu_add_entry(menu_bg, "Set Centered", NULL, - NULL, feh_menu_cb_background_set_centered, NULL, NULL); + NULL, feh_menu_cb_background_set_centered, NULL, NULL); + feh_menu_add_entry(menu_bg, "Set Filled", NULL, + NULL, feh_menu_cb_background_set_filled, NULL, NULL); } else { feh_menu_add_entry(menu_bg, "Set Tiled", NULL, - NULL, feh_menu_cb_background_set_tiled_no_file, NULL, NULL); + NULL, feh_menu_cb_background_set_tiled_no_file, NULL, NULL); feh_menu_add_entry(menu_bg, "Set Seamless", NULL, - NULL, feh_menu_cb_background_set_seamless, NULL, NULL); + NULL, feh_menu_cb_background_set_seamless, NULL, NULL); feh_menu_add_entry(menu_bg, "Set Scaled", NULL, - NULL, feh_menu_cb_background_set_scaled_no_file, NULL, NULL); + NULL, feh_menu_cb_background_set_scaled_no_file, NULL, NULL); feh_menu_add_entry(menu_bg, "Set Centered", NULL, - NULL, feh_menu_cb_background_set_centered_no_file, NULL, NULL); + NULL, feh_menu_cb_background_set_centered_no_file, NULL, NULL); + feh_menu_add_entry(menu_bg, "Set Filled", NULL, + NULL, feh_menu_cb_background_set_filled_no_file, NULL, NULL); } } common_menus = 1; @@ -1306,7 +1328,7 @@ static void feh_menu_cb_background_set_tiled(feh_menu * m, feh_menu_item * i, vo D_ENTER(4); path = feh_absolute_path(FEH_FILE(m->fehwin->file->data)->filename); - feh_wm_set_bg(path, m->fehwin->im, 0, 0, (int) data, 1); + feh_wm_set_bg(path, m->fehwin->im, 0, 0, 0, (int) data, 1); free(path); D_RETURN_(4); i = NULL; @@ -1319,7 +1341,7 @@ static void feh_menu_cb_background_set_seamless(feh_menu * m, feh_menu_item * i, D_ENTER(4); im = gib_imlib_clone_image(m->fehwin->im); gib_imlib_image_tile(im); - feh_wm_set_bg(NULL, im, 0, 0, (int) data, 1); + feh_wm_set_bg(NULL, im, 0, 0, 0, (int) data, 1); gib_imlib_free_image_and_decache(im); D_RETURN_(4); i = NULL; @@ -1331,7 +1353,7 @@ static void feh_menu_cb_background_set_scaled(feh_menu * m, feh_menu_item * i, v D_ENTER(4); path = feh_absolute_path(FEH_FILE(m->fehwin->file->data)->filename); - feh_wm_set_bg(path, m->fehwin->im, 0, 1, (int) data, 1); + feh_wm_set_bg(path, m->fehwin->im, 0, 1, 0, (int) data, 1); free(path); D_RETURN_(4); i = NULL; @@ -1343,7 +1365,19 @@ static void feh_menu_cb_background_set_centered(feh_menu * m, feh_menu_item * i, D_ENTER(4); path = feh_absolute_path(FEH_FILE(m->fehwin->file->data)->filename); - feh_wm_set_bg(path, m->fehwin->im, 1, 0, (int) data, 1); + feh_wm_set_bg(path, m->fehwin->im, 1, 0, 0, (int) data, 1); + free(path); + D_RETURN_(4); + i = NULL; +} + +static void feh_menu_cb_background_set_filled(feh_menu * m, feh_menu_item * i, void *data) +{ + char *path; + + D_ENTER(4); + path = feh_absolute_path(FEH_FILE(m->fehwin->file->data)->filename); + feh_wm_set_bg(path, m->fehwin->im, 0, 0, 1, (int) data, 1); free(path); D_RETURN_(4); i = NULL; @@ -1352,7 +1386,7 @@ static void feh_menu_cb_background_set_centered(feh_menu * m, feh_menu_item * i, static void feh_menu_cb_background_set_tiled_no_file(feh_menu * m, feh_menu_item * i, void *data) { D_ENTER(4); - feh_wm_set_bg(NULL, m->fehwin->im, 0, 0, (int) data, 1); + feh_wm_set_bg(NULL, m->fehwin->im, 0, 0, 0, (int) data, 1); D_RETURN_(4); i = NULL; } @@ -1360,7 +1394,7 @@ static void feh_menu_cb_background_set_tiled_no_file(feh_menu * m, feh_menu_item static void feh_menu_cb_background_set_scaled_no_file(feh_menu * m, feh_menu_item * i, void *data) { D_ENTER(4); - feh_wm_set_bg(NULL, m->fehwin->im, 0, 1, (int) data, 1); + feh_wm_set_bg(NULL, m->fehwin->im, 0, 1, 0, (int) data, 1); D_RETURN_(4); i = NULL; } @@ -1368,7 +1402,15 @@ static void feh_menu_cb_background_set_scaled_no_file(feh_menu * m, feh_menu_ite static void feh_menu_cb_background_set_centered_no_file(feh_menu * m, feh_menu_item * i, void *data) { D_ENTER(4); - feh_wm_set_bg(NULL, m->fehwin->im, 1, 0, (int) data, 1); + feh_wm_set_bg(NULL, m->fehwin->im, 1, 0, 0, (int) data, 1); + D_RETURN_(4); + i = NULL; +} + +static void feh_menu_cb_background_set_filled_no_file(feh_menu * m, feh_menu_item * i, void *data) +{ + D_ENTER(4); + feh_wm_set_bg(NULL, m->fehwin->im, 0, 0, 1, (int) data, 1); D_RETURN_(4); i = NULL; } diff --git a/src/options.c b/src/options.c index 870388b..89dcedd 100644 --- a/src/options.c +++ b/src/options.c @@ -389,6 +389,7 @@ static void feh_parse_option_array(int argc, char **argv) {"action7", 1, 0, 215}, {"action8", 1, 0, 216}, {"action9", 1, 0, 217}, + {"bg-fill", 1, 0, 218}, {"index-name", 1, 0, 230}, {"index-size", 1, 0, 231}, {"index-dim", 1, 0, 232}, @@ -652,6 +653,10 @@ static void feh_parse_option_array(int argc, char **argv) opt.bgmode = BG_MODE_SEAMLESS; opt.output_file = estrdup(optarg); break; + case 218: + opt.bgmode = BG_MODE_FILL; + opt.output_file = estrdup(optarg); + break; case 204: free(opt.menu_style); opt.menu_style = estrdup(optarg); @@ -960,6 +965,7 @@ void show_usage(void) " --bg-tile FILE\n" " --bg-center FILE\n" " --bg-scale FILE\n" + " --bg-fill FILE\n" " --bg-seamless FILE Set your desktop background to FILE. Feh can\n" " use enlightenment IPC if you are running it,\n" " or will fall back to X methods.\n" diff --git a/src/support.c b/src/support.c index abe18ce..4688d6f 100644 --- a/src/support.c +++ b/src/support.c @@ -53,16 +53,19 @@ void feh_wm_set_bg_file(char *file, unsigned char bgmode) switch (bgmode) { case BG_MODE_SEAMLESS: gib_imlib_image_tile(im); - feh_wm_set_bg(NULL, im, 0, 0, 0, 1); + feh_wm_set_bg(NULL, im, 0, 0, 0, 0, 1); break; case BG_MODE_TILE: - feh_wm_set_bg(file, im, 0, 0, 0, 1); + feh_wm_set_bg(file, im, 0, 0, 0, 0, 1); break; case BG_MODE_SCALE: - feh_wm_set_bg(file, im, 0, 1, 0, 1); + feh_wm_set_bg(file, im, 0, 1, 0, 0, 1); + break; + case BG_MODE_FILL: + feh_wm_set_bg(file, im, 0, 0, 1, 0, 1); break; default: - feh_wm_set_bg(file, im, 1, 0, 0, 1); + feh_wm_set_bg(file, im, 1, 0, 0, 0, 1); break; } gib_imlib_free_image_and_decache(im); @@ -70,7 +73,8 @@ void feh_wm_set_bg_file(char *file, unsigned char bgmode) } } -void feh_wm_set_bg(char *fil, Imlib_Image im, int centered, int scaled, int desktop, int set) +void feh_wm_set_bg(char *fil, Imlib_Image im, int centered, int scaled, + int filled, int desktop, int set) { char bgname[20]; int num = (int) rand(); @@ -203,6 +207,27 @@ void feh_wm_set_bg(char *fil, Imlib_Image im, int centered, int scaled, int desk gib_imlib_render_image_on_drawable(pmap_d1, im, x, y, 1, 0, 0); XFreeGC(disp, gc); fehbg = estrjoin(" ", "feh --bg-center", filbuf, NULL); + } else if (filled) { + int x = scr->width; + int y = scr->height; + int u = gib_imlib_image_get_width(im); + int v = gib_imlib_image_get_height(im); + int s = 0; + int t = 0; + + if ((u * y) > (x * v)) { + h = y; + w = (y * u) / v; + s = (x - w) / 2; + } else { + h = (x * v) / u; + w = x; + t = (y - h) / 2; + } + pmap_d1 = XCreatePixmap(disp, root, w, h, depth); + gib_imlib_render_image_on_drawable_at_size(pmap_d1, im, s, t, + w, h, 1, 0, 1); + fehbg = estrjoin(" ", "feh --bg-fill", filbuf, NULL); } else { w = gib_imlib_image_get_width(im); h = gib_imlib_image_get_height(im); diff --git a/src/support.h b/src/support.h index c50f999..bb17082 100644 --- a/src/support.h +++ b/src/support.h @@ -46,7 +46,8 @@ extern void enl_ipc_send(char *); extern char *enl_wait_for_reply(void); extern char *enl_ipc_get(const char *); extern char *enl_send_and_wait(char *); -extern void feh_wm_set_bg(char *fil, Imlib_Image im, int centered, int scaled, int desktop, int set); +extern void feh_wm_set_bg(char *fil, Imlib_Image im, int centered, int scaled, + int fill, int desktop, int set); extern int feh_wm_get_num_desks(void); extern signed char feh_wm_get_wm_is_e(void); void feh_wm_set_bg_file(char *file, unsigned char bgmode); -- cgit v1.2.3