From 1c4c68dcc6160911441097c5a41b441e2a6b9b72 Mon Sep 17 00:00:00 2001 From: speedie Date: Mon, 12 Jun 2023 00:26:35 +0200 Subject: [PATCH] Add image resize option --- docs/docs.md | 6 ++++++ docs/example.Xresources | 1 + docs/spmenu.conf | 1 + libs/argv.c | 29 ++++++++++++++++++++++------- libs/conf/config.c | 1 + libs/img.c | 2 +- libs/options.h | 5 +++-- libs/x11/xresources.h | 1 + spmenu.1 | 6 ++++++ 9 files changed, 42 insertions(+), 10 deletions(-) diff --git a/docs/docs.md b/docs/docs.md index 79cc1ca..c8eb1a7 100644 --- a/docs/docs.md +++ b/docs/docs.md @@ -317,6 +317,12 @@ You may use long, descriptive arguments or the shorter arguments. `-itc, --image-topcenter` : Position the image in the top center +`-ir, --image-resize` +: Allow spmenu to resize itself to fit the image + +`-nir, --no-image-resize` +: Don't allow spmenu to resize itself to fit the image + `-wm, --managed, --x11-client` : Spawn spmenu as a window manager controlled client/window (X11 only) diff --git a/docs/example.Xresources b/docs/example.Xresources index 93f022f..0e4a37e 100644 --- a/docs/example.Xresources +++ b/docs/example.Xresources @@ -165,6 +165,7 @@ spmenu.sgr: 1 !! Image spmenu.imagewidth: 200 spmenu.imageheight: 200 +spmenu.imageresize: 1 spmenu.imagegaps: 0 spmenu.imageposition: 0 spmenu.generatecache: 1 diff --git a/docs/spmenu.conf b/docs/spmenu.conf index 753b313..3410674 100644 --- a/docs/spmenu.conf +++ b/docs/spmenu.conf @@ -194,6 +194,7 @@ spmenu = { /* Image options */ image = ( { width = 200; // Image width (px) height = 200; // Image height (px) + resize = 1; // Allow spmenu to resize itself to fit the image (0/1) gaps = 0; // Image gaps (px) position = 0; // Image position (0: Top, 1: Bottom, 2: Center, 3: Top center) cache = 1; // Cache images (0/1) diff --git a/libs/argv.c b/libs/argv.c index dc254a6..68e9c20 100644 --- a/libs/argv.c +++ b/libs/argv.c @@ -369,7 +369,10 @@ void readargs(int argc, char *argv[]) { if(sscanf(buf, "%dx%d", &imagewidth, &imageheight) == 1) imageheight = imagewidth; - + } else if (!strcmp(argv[i], "-ir") || (!strcmp(argv[i], "--image-resize"))) { // image resize + imageresize = 1; + } else if (!strcmp(argv[i], "-nir") || (!strcmp(argv[i], "--no-image-resize"))) { // no image resize + imageresize = 0; } else if (!strcmp(argv[i], "-w") || (!strcmp(argv[i], "--embed"))) { // embedding window id #if USEX embed = argv[++i]; @@ -562,7 +565,8 @@ void usage(int status) { "spmenu -nt, --no-allow-typing Don't allow typing, the user must select an option\n" , status ? stderr : stdout); - fputs("spmenu -x, --x-position Offset spmenu x position by (X11 only)\n" + fputs( + "spmenu -x, --x-position Offset spmenu x position by (X11 only)\n" "spmenu -y, --y-position Offset spmenu y position by (X11 only)\n" "spmenu -n, --preselect Preselect in the list of items\n" "spmenu -z, --width Width of the spmenu window\n" @@ -584,7 +588,8 @@ void usage(int status) { , status ? stderr : stdout); // more args - fputs("spmenu -hm, --hide-mode Hide mode indicator\n" + fputs( + "spmenu -hm, --hide-mode Hide mode indicator\n" "spmenu -hmc, --hide-match-count Hide match count\n" "spmenu -hla, --hide-left-arrow Hide left arrow\n" "spmenu -hra, --hide-right-arrow Hide right arrow\n" @@ -624,15 +629,22 @@ void usage(int status) { "spmenu -hom, --horizontal-margin Set the horizontal margin to \n" "spmenu -la, --left-arrow-symbol Set the left arrow to \n" "spmenu -ra, --right-arrow-symbol Set the right arrow to \n" + , status ? stderr : stdout); + + // image related + fputs( "spmenu -is, --image-size Set image size to \n" "spmenu -it, --image-top Position the image at the top\n" "spmenu -ib, --image-bottom Position the image at the bottom\n" "spmenu -ic, --image-center Position the image in the center\n" "spmenu -itc, --image-topcenter Position the image in the top center\n" + "spmenu -ir, --image-resize Allow spmenu to resize itself to fit the image\n" + "spmenu -nir, --no-image-resize Don't allow spmenu to resize itself to fit the image\n" , status ? stderr : stdout); // general/config related - fputs("spmenu -wm, --managed, --x11-client Spawn spmenu as a window manager controlled client/window (X11 only)\n" + fputs( + "spmenu -wm, --managed, --x11-client Spawn spmenu as a window manager controlled client/window (X11 only)\n" "spmenu -nwm, --unmanaged Don't spawn spmenu as a window manager controlled client/window (X11 only)\n" "spmenu -cf, --config-file Set config file to load to \n" "spmenu -lcfg, --load-config Load spmenu configuration (~/.config/spmenu/spmenu.conf)\n" @@ -650,7 +662,8 @@ void usage(int status) { "\n", status ? stderr : stdout); // colors - fputs("- Appearance arguments -\n" + fputs( + "- Appearance arguments -\n" "spmenu -fn, --font Set the spmenu font to \n" "spmenu -nif, --normal-item-foreground Set the normal item foreground color\n" "spmenu -nib, --normal-item-background Set the normal item background color\n" @@ -685,7 +698,8 @@ void usage(int status) { , status ? stderr : stdout); // sgr sequences - fputs("spmenu -sgr0, --sgr0 Set the SGR 0 color\n" + fputs( + "spmenu -sgr0, --sgr0 Set the SGR 0 color\n" "spmenu -sgr1, --sgr1 Set the SGR 1 color\n" "spmenu -sgr2, --sgr2 Set the SGR 2 color\n" "spmenu -sgr3, --sgr3 Set the SGR 3 color\n" @@ -704,7 +718,8 @@ void usage(int status) { "\n", status ? stderr : stdout); // dmenu compat - fputs("- dmenu compatibility -\n" + fputs( + "- dmenu compatibility -\n" "spmenu -S Don't sort matches\n" "spmenu -i Use case-insensitive matching\n" "spmenu -nb Set the normal background color\n" diff --git a/libs/conf/config.c b/libs/conf/config.c index 4b50f4a..6e7249d 100644 --- a/libs/conf/config.c +++ b/libs/conf/config.c @@ -410,6 +410,7 @@ void conf_init(void) { // look up config_setting_lookup_int(conf, "width", &imagewidth); // spmenu.image.width config_setting_lookup_int(conf, "height", &imageheight); // spmenu.image.height + config_setting_lookup_int(conf, "resize", &imageresize); // spmenu.image.resize config_setting_lookup_int(conf, "gaps", &imageheight); // spmenu.image.gaps config_setting_lookup_int(conf, "position", &imageposition); // spmenu.image.position config_setting_lookup_int(conf, "cache", &generatecache); // spmenu.image.cache diff --git a/libs/img.c b/libs/img.c index c5c3b2b..a7905f4 100644 --- a/libs/img.c +++ b/libs/img.c @@ -71,7 +71,7 @@ void drawimage(void) { xta += menumarginh; wta += menumarginv; - if (mh != bh + height + leftmargin * 2 - wtr) { // menu height cannot be smaller than image height + if (mh != bh + height + leftmargin * 2 - wtr && imageresize) { // menu height cannot be smaller than image height resizetoimageheight(width, height); } diff --git a/libs/options.h b/libs/options.h index e2e03dd..2e62cb2 100644 --- a/libs/options.h +++ b/libs/options.h @@ -49,8 +49,9 @@ static int capspwlstyle = 2; /* Caps lock indicator powerline sty static int dockproperty = 1; /* Set _NET_WM_WINDOW_TYPE_DOCK */ /* Image options */ -static int imagewidth = 200; /* Default image width */ -static int imageheight = 200; /* Default image height */ +static int imagewidth = 200; /* Default image width (px) */ +static int imageheight = 200; /* Default image height (px) */ +static int imageresize = 1; /* Allow the spmenu window to resize itself to fit the image (0/1) */ static int imagegaps = 0; /* Image gaps */ static int imageposition = 0; /* Image position (0: Top, 1: Bottom, 2: Center, 3: Top center) */ static int generatecache = 1; /* Generate image cache by default */ diff --git a/libs/x11/xresources.h b/libs/x11/xresources.h index e12411f..23c2b13 100644 --- a/libs/x11/xresources.h +++ b/libs/x11/xresources.h @@ -152,6 +152,7 @@ ResourcePref resources[] = { { "imageheight", INTEGER, &imageheight }, { "imagegaps", INTEGER, &imagegaps }, { "imageposition", INTEGER, &imageposition }, + { "imageresize", INTEGER, &imageresize }, { "generatecache", INTEGER, &generatecache }, { "maxcache", INTEGER, &maxcache }, { "mode", INTEGER, &mode }, diff --git a/spmenu.1 b/spmenu.1 index e7f53b8..86ccbfa 100644 --- a/spmenu.1 +++ b/spmenu.1 @@ -341,6 +341,12 @@ Position the image in the center \f[V]-itc, --image-topcenter\f[R] Position the image in the top center .TP +\f[V]-ir, --image-resize\f[R] +Allow spmenu to resize itself to fit the image +.TP +\f[V]-nir, --no-image-resize\f[R] +Don\[cq]t allow spmenu to resize itself to fit the image +.TP \f[V]-wm, --managed, --x11-client\f[R] Spawn spmenu as a window manager controlled client/window (X11 only) .TP