From 5e6cbb6c8d1435b3122dfc55b6e5cfeefb1a3aab Mon Sep 17 00:00:00 2001 From: James Knight Date: Mon, 22 Jun 2015 11:56:00 -0400 Subject: ensure fehbg is free'ed The 'fehbg' variable can be allocated whether or not the user wishes to generated a fehbg file. Ensure the variable is free'ed before we return. Signed-off-by: James Knight --- src/wallpaper.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/wallpaper.c b/src/wallpaper.c index 3e19c41..9327d74 100644 --- a/src/wallpaper.c +++ b/src/wallpaper.c @@ -465,8 +465,9 @@ void feh_wm_set_bg(char *fil, Imlib_Image im, int centered, int scaled, } free(path); } - free(fehbg); } + + if (fehbg) free(fehbg); /* create new display, copy pixmap to new display */ disp2 = XOpenDisplay(NULL); -- cgit v1.2.3 From 740daf5c8b2908211b4ae1ad2c9353688bb1e2f9 Mon Sep 17 00:00:00 2001 From: James Knight Date: Mon, 22 Jun 2015 12:15:37 -0400 Subject: support background setter for specific screen The following adds the ability, when using `feh` as a background setter, to use a specific Xinerama screen to render a provided image. Along with the provided '--bg-*' option, the '--xinerama-index' argument will be used to identify the index of the detected Xinerama screen to use. Signed-off-by: James Knight --- man/feh.pre | 14 ++++++++- src/options.c | 5 +++ src/options.h | 1 + src/wallpaper.c | 97 +++++++++++++++++++++++++++++++++++++++++++++------------ 4 files changed, 96 insertions(+), 21 deletions(-) diff --git a/man/feh.pre b/man/feh.pre index 10ea58f..b994478 100644 --- a/man/feh.pre +++ b/man/feh.pre @@ -470,6 +470,13 @@ managers. Disable Xinerama support. Only makes sense when you have Xinerama support compiled in. . +.It Cm --xinerama-index +. +Force Xinerama screen index to use. Only makes sense when you have +Xinerama support compiled in and using +.Nm +as a background setter. +. .It Cm -j , --output-dir Ar directory . Save files to @@ -820,7 +827,12 @@ on screen 0, the second on screen 1, and so on. . Use .Cm --no-xinerama -to treat the whole X display as one screen when setting wallpapers. +to treat the whole X display as one screen when setting wallpapers. You +may also use +.Cm --xinerama-index +to use +.Nm +as a background setter for a specific screen. . .Bl -tag -width indent . diff --git a/src/options.c b/src/options.c index cbeb729..bff46c3 100644 --- a/src/options.c +++ b/src/options.c @@ -71,6 +71,7 @@ void init_parse_options(int argc, char **argv) /* if we're using xinerama, then enable it by default */ opt.xinerama = 1; #endif /* HAVE_LIBXINERAMA */ + opt.xinerama_index = -1; feh_getopt_theme(argc, argv); @@ -404,6 +405,7 @@ static void feh_parse_option_array(int argc, char **argv, int finalrun) {"no-fehbg" , 0, 0, 236}, {"keep-zoom-vp" , 0, 0, 237}, {"scroll-step" , 1, 0, 238}, + {"xinerama-index", 1, 0, 239}, {0, 0, 0, 0} }; @@ -744,6 +746,9 @@ static void feh_parse_option_array(int argc, char **argv, int finalrun) case 238: opt.scroll_step = atoi(optarg); break; + case 239: + opt.xinerama_index = atoi(optarg); + break; default: break; } diff --git a/src/options.h b/src/options.h index a22cc05..923aa41 100644 --- a/src/options.h +++ b/src/options.h @@ -109,6 +109,7 @@ struct __fehoptions { int default_zoom; int zoom_mode; unsigned char adjust_reload; + int xinerama_index; /* signed in case someone wants to invert scrolling real quick */ int scroll_step; diff --git a/src/wallpaper.c b/src/wallpaper.c index 9327d74..b992ec1 100644 --- a/src/wallpaper.c +++ b/src/wallpaper.c @@ -298,11 +298,23 @@ void feh_wm_set_bg(char *fil, Imlib_Image im, int centered, int scaled, /* string for sticking in ~/.fehbg */ char *fehbg = NULL; + char fehbg_args[512]; + fehbg_args[0] = '\0'; char *home; char filbuf[4096]; - char fehbg_xinerama[] = "--no-xinerama"; char *bgfill = NULL; bgfill = opt.image_bg == IMAGE_BG_WHITE ? "--image-bg white" : "--image-bg black" ; + + if (opt.xinerama) + { + if (opt.xinerama_index >= 0) + { + snprintf(fehbg_args, sizeof(fehbg_args), + "--xinerama-index %d", opt.xinerama_index); + } + } + else + snprintf(fehbg_args, sizeof(fehbg_args), "--no-xinerama"); /* local display to set closedownmode on */ Display *disp2; @@ -310,9 +322,6 @@ void feh_wm_set_bg(char *fil, Imlib_Image im, int centered, int scaled, int depth2; int in, out, w, h; - if (opt.xinerama) - fehbg_xinerama[0] = '\0'; - D(("Falling back to XSetRootWindowPixmap\n")); /* Put the filename in filbuf between ' and escape ' in the filename */ @@ -357,16 +366,33 @@ void feh_wm_set_bg(char *fil, Imlib_Image im, int centered, int scaled, pmap_d1 = XCreatePixmap(disp, root, scr->width, scr->height, depth); #ifdef HAVE_LIBXINERAMA + if (opt.xinerama_index >= 0) + { + if (opt.image_bg == IMAGE_BG_WHITE) + gcval.foreground = WhitePixel(disp, DefaultScreen(disp)); + else + gcval.foreground = BlackPixel(disp, DefaultScreen(disp)); + gc = XCreateGC(disp, root, GCForeground, &gcval); + XFillRectangle(disp, pmap_d1, gc, 0, 0, scr->width, scr->height); + } + if (opt.xinerama && xinerama_screens) + { for (i = 0; i < num_xinerama_screens; i++) - feh_wm_set_bg_scaled(pmap_d1, im, use_filelist, - xinerama_screens[i].x_org, xinerama_screens[i].y_org, - xinerama_screens[i].width, xinerama_screens[i].height); + { + if (opt.xinerama_index < 0 || opt.xinerama_index == i) + { + feh_wm_set_bg_scaled(pmap_d1, im, use_filelist, + xinerama_screens[i].x_org, xinerama_screens[i].y_org, + xinerama_screens[i].width, xinerama_screens[i].height); + } + } + } else #endif /* HAVE_LIBXINERAMA */ feh_wm_set_bg_scaled(pmap_d1, im, use_filelist, 0, 0, scr->width, scr->height); - fehbg = estrjoin(" ", "feh", fehbg_xinerama, "--bg-scale", filbuf, NULL); + fehbg = estrjoin(" ", "feh", fehbg_args, "--bg-scale", filbuf, NULL); } else if (centered) { D(("centering\n")); @@ -381,10 +407,17 @@ void feh_wm_set_bg(char *fil, Imlib_Image im, int centered, int scaled, #ifdef HAVE_LIBXINERAMA if (opt.xinerama && xinerama_screens) + { for (i = 0; i < num_xinerama_screens; i++) - feh_wm_set_bg_centered(pmap_d1, im, use_filelist, - xinerama_screens[i].x_org, xinerama_screens[i].y_org, - xinerama_screens[i].width, xinerama_screens[i].height); + { + if (opt.xinerama_index < 0 || opt.xinerama_index == i) + { + feh_wm_set_bg_centered(pmap_d1, im, use_filelist, + xinerama_screens[i].x_org, xinerama_screens[i].y_org, + xinerama_screens[i].width, xinerama_screens[i].height); + } + } + } else #endif /* HAVE_LIBXINERAMA */ feh_wm_set_bg_centered(pmap_d1, im, use_filelist, @@ -392,24 +425,41 @@ void feh_wm_set_bg(char *fil, Imlib_Image im, int centered, int scaled, XFreeGC(disp, gc); - fehbg = estrjoin(" ", "feh", fehbg_xinerama, bgfill, "--bg-center", filbuf, NULL); + fehbg = estrjoin(" ", "feh", fehbg_args, bgfill, "--bg-center", filbuf, NULL); } else if (filled == 1) { pmap_d1 = XCreatePixmap(disp, root, scr->width, scr->height, depth); #ifdef HAVE_LIBXINERAMA + if (opt.xinerama_index >= 0) + { + if (opt.image_bg == IMAGE_BG_WHITE) + gcval.foreground = WhitePixel(disp, DefaultScreen(disp)); + else + gcval.foreground = BlackPixel(disp, DefaultScreen(disp)); + gc = XCreateGC(disp, root, GCForeground, &gcval); + XFillRectangle(disp, pmap_d1, gc, 0, 0, scr->width, scr->height); + } + if (opt.xinerama && xinerama_screens) + { for (i = 0; i < num_xinerama_screens; i++) - feh_wm_set_bg_filled(pmap_d1, im, use_filelist, - xinerama_screens[i].x_org, xinerama_screens[i].y_org, - xinerama_screens[i].width, xinerama_screens[i].height); + { + if (opt.xinerama_index < 0 || opt.xinerama_index == i) + { + feh_wm_set_bg_filled(pmap_d1, im, use_filelist, + xinerama_screens[i].x_org, xinerama_screens[i].y_org, + xinerama_screens[i].width, xinerama_screens[i].height); + } + } + } else #endif /* HAVE_LIBXINERAMA */ feh_wm_set_bg_filled(pmap_d1, im, use_filelist , 0, 0, scr->width, scr->height); - fehbg = estrjoin(" ", "feh", fehbg_xinerama, "--bg-fill", filbuf, NULL); + fehbg = estrjoin(" ", "feh", fehbg_args, "--bg-fill", filbuf, NULL); } else if (filled == 2) { @@ -423,10 +473,17 @@ void feh_wm_set_bg(char *fil, Imlib_Image im, int centered, int scaled, #ifdef HAVE_LIBXINERAMA if (opt.xinerama && xinerama_screens) + { for (i = 0; i < num_xinerama_screens; i++) - feh_wm_set_bg_maxed(pmap_d1, im, use_filelist, - xinerama_screens[i].x_org, xinerama_screens[i].y_org, - xinerama_screens[i].width, xinerama_screens[i].height); + { + if (opt.xinerama_index < 0 || opt.xinerama_index == i) + { + feh_wm_set_bg_maxed(pmap_d1, im, use_filelist, + xinerama_screens[i].x_org, xinerama_screens[i].y_org, + xinerama_screens[i].width, xinerama_screens[i].height); + } + } + } else #endif /* HAVE_LIBXINERAMA */ feh_wm_set_bg_maxed(pmap_d1, im, use_filelist, @@ -434,7 +491,7 @@ void feh_wm_set_bg(char *fil, Imlib_Image im, int centered, int scaled, XFreeGC(disp, gc); - fehbg = estrjoin(" ", "feh", fehbg_xinerama, bgfill, "--bg-max", filbuf, NULL); + fehbg = estrjoin(" ", "feh", fehbg_args, bgfill, "--bg-max", filbuf, NULL); } else { if (use_filelist) -- cgit v1.2.3 From 8220640589fefde156963d35a8248ed01487555e Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Fri, 26 Jun 2015 16:47:52 +0200 Subject: adjust coding style in patch, always free gc, coherent HAVE_LIBXINERAMA wrapping --- src/options.c | 2 +- src/wallpaper.c | 60 +++++++++++++++++++++++---------------------------------- 2 files changed, 25 insertions(+), 37 deletions(-) diff --git a/src/options.c b/src/options.c index bff46c3..120541a 100644 --- a/src/options.c +++ b/src/options.c @@ -70,8 +70,8 @@ void init_parse_options(int argc, char **argv) #ifdef HAVE_LIBXINERAMA /* if we're using xinerama, then enable it by default */ opt.xinerama = 1; -#endif /* HAVE_LIBXINERAMA */ opt.xinerama_index = -1; +#endif /* HAVE_LIBXINERAMA */ feh_getopt_theme(argc, argv); diff --git a/src/wallpaper.c b/src/wallpaper.c index b992ec1..b6f2c0c 100644 --- a/src/wallpaper.c +++ b/src/wallpaper.c @@ -304,17 +304,17 @@ void feh_wm_set_bg(char *fil, Imlib_Image im, int centered, int scaled, char filbuf[4096]; char *bgfill = NULL; bgfill = opt.image_bg == IMAGE_BG_WHITE ? "--image-bg white" : "--image-bg black" ; - - if (opt.xinerama) - { - if (opt.xinerama_index >= 0) - { + +#ifdef HAVE_LIBXINERAMA + if (opt.xinerama) { + if (opt.xinerama_index >= 0) { snprintf(fehbg_args, sizeof(fehbg_args), "--xinerama-index %d", opt.xinerama_index); } } else snprintf(fehbg_args, sizeof(fehbg_args), "--no-xinerama"); +#endif /* HAVE_LIBXINERAMA */ /* local display to set closedownmode on */ Display *disp2; @@ -366,22 +366,19 @@ void feh_wm_set_bg(char *fil, Imlib_Image im, int centered, int scaled, pmap_d1 = XCreatePixmap(disp, root, scr->width, scr->height, depth); #ifdef HAVE_LIBXINERAMA - if (opt.xinerama_index >= 0) - { + if (opt.xinerama_index >= 0) { if (opt.image_bg == IMAGE_BG_WHITE) gcval.foreground = WhitePixel(disp, DefaultScreen(disp)); else gcval.foreground = BlackPixel(disp, DefaultScreen(disp)); gc = XCreateGC(disp, root, GCForeground, &gcval); XFillRectangle(disp, pmap_d1, gc, 0, 0, scr->width, scr->height); + XFreeGC(disp, gc); } - - if (opt.xinerama && xinerama_screens) - { - for (i = 0; i < num_xinerama_screens; i++) - { - if (opt.xinerama_index < 0 || opt.xinerama_index == i) - { + + if (opt.xinerama && xinerama_screens) { + for (i = 0; i < num_xinerama_screens; i++) { + if (opt.xinerama_index < 0 || opt.xinerama_index == i) { feh_wm_set_bg_scaled(pmap_d1, im, use_filelist, xinerama_screens[i].x_org, xinerama_screens[i].y_org, xinerama_screens[i].width, xinerama_screens[i].height); @@ -406,12 +403,9 @@ void feh_wm_set_bg(char *fil, Imlib_Image im, int centered, int scaled, XFillRectangle(disp, pmap_d1, gc, 0, 0, scr->width, scr->height); #ifdef HAVE_LIBXINERAMA - if (opt.xinerama && xinerama_screens) - { - for (i = 0; i < num_xinerama_screens; i++) - { - if (opt.xinerama_index < 0 || opt.xinerama_index == i) - { + if (opt.xinerama && xinerama_screens) { + for (i = 0; i < num_xinerama_screens; i++) { + if (opt.xinerama_index < 0 || opt.xinerama_index == i) { feh_wm_set_bg_centered(pmap_d1, im, use_filelist, xinerama_screens[i].x_org, xinerama_screens[i].y_org, xinerama_screens[i].width, xinerama_screens[i].height); @@ -432,22 +426,19 @@ void feh_wm_set_bg(char *fil, Imlib_Image im, int centered, int scaled, pmap_d1 = XCreatePixmap(disp, root, scr->width, scr->height, depth); #ifdef HAVE_LIBXINERAMA - if (opt.xinerama_index >= 0) - { + if (opt.xinerama_index >= 0) { if (opt.image_bg == IMAGE_BG_WHITE) gcval.foreground = WhitePixel(disp, DefaultScreen(disp)); else gcval.foreground = BlackPixel(disp, DefaultScreen(disp)); gc = XCreateGC(disp, root, GCForeground, &gcval); XFillRectangle(disp, pmap_d1, gc, 0, 0, scr->width, scr->height); + XFreeGC(disp, gc); } - - if (opt.xinerama && xinerama_screens) - { - for (i = 0; i < num_xinerama_screens; i++) - { - if (opt.xinerama_index < 0 || opt.xinerama_index == i) - { + + if (opt.xinerama && xinerama_screens) { + for (i = 0; i < num_xinerama_screens; i++) { + if (opt.xinerama_index < 0 || opt.xinerama_index == i) { feh_wm_set_bg_filled(pmap_d1, im, use_filelist, xinerama_screens[i].x_org, xinerama_screens[i].y_org, xinerama_screens[i].width, xinerama_screens[i].height); @@ -472,12 +463,9 @@ void feh_wm_set_bg(char *fil, Imlib_Image im, int centered, int scaled, XFillRectangle(disp, pmap_d1, gc, 0, 0, scr->width, scr->height); #ifdef HAVE_LIBXINERAMA - if (opt.xinerama && xinerama_screens) - { - for (i = 0; i < num_xinerama_screens; i++) - { - if (opt.xinerama_index < 0 || opt.xinerama_index == i) - { + if (opt.xinerama && xinerama_screens) { + for (i = 0; i < num_xinerama_screens; i++) { + if (opt.xinerama_index < 0 || opt.xinerama_index == i) { feh_wm_set_bg_maxed(pmap_d1, im, use_filelist, xinerama_screens[i].x_org, xinerama_screens[i].y_org, xinerama_screens[i].width, xinerama_screens[i].height); @@ -524,7 +512,7 @@ void feh_wm_set_bg(char *fil, Imlib_Image im, int centered, int scaled, } } - if (fehbg) free(fehbg); + free(fehbg); /* create new display, copy pixmap to new display */ disp2 = XOpenDisplay(NULL); -- cgit v1.2.3 From 9593169d627085699d60a52794d65e64a247c030 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Fri, 26 Jun 2015 16:48:23 +0200 Subject: feh(1): move --xinerama-index to background setting section, extend description --- man/feh.pre | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/man/feh.pre b/man/feh.pre index b994478..d3d3d1f 100644 --- a/man/feh.pre +++ b/man/feh.pre @@ -470,13 +470,6 @@ managers. Disable Xinerama support. Only makes sense when you have Xinerama support compiled in. . -.It Cm --xinerama-index -. -Force Xinerama screen index to use. Only makes sense when you have -Xinerama support compiled in and using -.Nm -as a background setter. -. .It Cm -j , --output-dir Ar directory . Save files to @@ -871,6 +864,21 @@ Do not write a .Pa ~/.fehbg file . +.It Cm --xinerama-index Ar screen +. +When used with any option other than +.Cm --bg-tile : +Only set wallpaper on +.Ar screen . +All other screens will be filled black/white. +. +This is most useful in a Xinerama configuration with overlapping screens. +For instance, assume you have two overlapping displays (index 0 and 1), where +index 0 is smaller. To center a background on the display with index 0 and +fill the extra space on index 1 black/white, use +.Qq --xinerama-index 0 +when setting the wallpaper. +. .El . . -- cgit v1.2.3