aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNRK <nrk@disroot.org>2023-01-17 10:48:59 +0100
committerGitea <gitea@fake.local>2023-01-28 11:23:11 +0100
commit1f788a318bedc0e6a83632c1f126e747c0430d6c (patch)
tree96c734a6977a4407f4c3105ca5c680595656c264
parentfddad757c6d2645ed7b2d8f64931818d5b3b7a00 (diff)
downloadnsxiv-1f788a318bedc0e6a83632c1f126e747c0430d6c.tar.zst
add cli flag --alpha-layer
now that we have long-opts, we don't have to worry about exhausting the alphabet list for short-opts. so adding a cli flag to set/unset the checker background makes sense. ref: https://codeberg.org/nsxiv/nsxiv/issues/404
-rw-r--r--config.def.h10
-rw-r--r--etc/nsxiv.15
-rw-r--r--image.c2
-rw-r--r--nsxiv.h1
-rw-r--r--options.c16
5 files changed, 26 insertions, 8 deletions
diff --git a/config.def.h b/config.def.h
index 198c696..a0935f6 100644
--- a/config.def.h
+++ b/config.def.h
@@ -45,11 +45,6 @@ static const double CONTRAST_MAX = 4.0;
/* command i_scroll pans image 1/PAN_FRACTION of screen width/height */
static const int PAN_FRACTION = 5;
-/* if true, use a checkerboard background for alpha layer,
- * toggled with 'A' key binding
- */
-static const bool ALPHA_LAYER = false;
-
/* percentage of memory to use for imlib2's cache size.
* 3 means use 3% of total memory which is about 245MiB on 8GiB machine.
* 0 or less means disable cache.
@@ -70,6 +65,11 @@ static const int CACHE_SIZE_FALLBACK = 32 * 1024 * 1024; /* fallback to 32MiB if
*/
static const bool ANTI_ALIAS = true;
+/* if true, use a checkerboard background for alpha layer,
+ * toggled with 'A' key binding (overwritten via `--alpha-layer` option)
+ */
+static const bool ALPHA_LAYER = false;
+
#endif
#ifdef INCLUDE_THUMBS_CONFIG
diff --git a/etc/nsxiv.1 b/etc/nsxiv.1
index 57a6c39..a0c3d53 100644
--- a/etc/nsxiv.1
+++ b/etc/nsxiv.1
@@ -119,6 +119,11 @@ key-handler and the input of \-i will be separated by a NULL character.
Enables anti-aliasing, when given
.I no
as an argument, disables it instead.
+.TP
+.BI "\-\-alpha\-layer" [=no]
+Enables checkerboard background for alpha layer, when given
+.I no
+as an argument, disables it instead.
.SH KEYBOARD COMMANDS
.SS General
The following keyboard commands are available in both image and thumbnail modes:
diff --git a/image.c b/image.c
index 56d409a..8ac7a27 100644
--- a/image.c
+++ b/image.c
@@ -91,7 +91,7 @@ void img_init(img_t *img, win_t *win)
img->checkpan = false;
img->dirty = false;
img->anti_alias = options->anti_alias;
- img->alpha = ALPHA_LAYER;
+ img->alpha = options->alpha_layer;
img->multi.cap = img->multi.cnt = 0;
img->multi.animate = options->animate;
img->multi.framedelay = options->framerate > 0 ? 1000 / options->framerate : 0;
diff --git a/nsxiv.h b/nsxiv.h
index 19e5399..ab3673f 100644
--- a/nsxiv.h
+++ b/nsxiv.h
@@ -241,6 +241,7 @@ struct opt {
float zoom;
bool animate;
bool anti_alias;
+ bool alpha_layer;
int gamma;
unsigned int slideshow;
int framerate;
diff --git a/options.c b/options.c
index ac91c63..37ad60d 100644
--- a/options.c
+++ b/options.c
@@ -66,8 +66,13 @@ static void print_version(void)
void parse_options(int argc, char **argv)
{
- enum { /* ensure these can't be represented in a single byte */
- OPT_AA = UCHAR_MAX + 1
+ enum {
+ /* ensure these can't be represented in a single byte in order
+ * to avoid conflicts with short opts
+ */
+ OPT_START = UCHAR_MAX,
+ OPT_AA,
+ OPT_AL
};
static const struct optparse_long longopts[] = {
{ "framerate", 'A', OPTPARSE_REQUIRED },
@@ -95,6 +100,7 @@ void parse_options(int argc, char **argv)
{ "zoom", 'z', OPTPARSE_REQUIRED },
{ "null", '0', OPTPARSE_NONE },
{ "anti-alias", OPT_AA, OPTPARSE_OPTIONAL },
+ { "alpha-layer", OPT_AL, OPTPARSE_OPTIONAL },
{ 0 }, /* end */
};
@@ -115,6 +121,7 @@ void parse_options(int argc, char **argv)
_options.scalemode = SCALE_DOWN;
_options.zoom = 1.0;
_options.anti_alias = ANTI_ALIAS;
+ _options.alpha_layer = ALPHA_LAYER;
_options.animate = false;
_options.gamma = 0;
_options.slideshow = 0;
@@ -247,6 +254,11 @@ void parse_options(int argc, char **argv)
error(EXIT_FAILURE, 0, "Invalid argument for option --anti-alias: %s", op.optarg);
_options.anti_alias = op.optarg == NULL;
break;
+ case OPT_AL:
+ if (op.optarg != NULL && !STREQ(op.optarg, "no"))
+ error(EXIT_FAILURE, 0, "Invalid argument for option --alpha-layer: %s", op.optarg);
+ _options.alpha_layer = op.optarg == NULL;
+ break;
}
}