Krolyxon
Commit 1f788a3

Branches

Refs →

nsxiv1f788a3

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.
Author
NRK
Date
2023-01-17 15:48 +0600
Committer
Gitea · 2023-01-28 10:23 +0000
Parent
fddad75
Commit
1f788a318bedc0e6a83632c1f126e747c0430d6c

+26 −8

5 files changed

  1. M config.def.h +5 −5
  2. M etc/nsxiv.1 +5 −0
  3. M image.c +1 −1
  4. M nsxiv.h +1 −0
  5. M options.c +14 −2
M config.def.h View
@@ -45,11 +45,6 @@ static const double CONTRAST_MAX = 4.0;
4545 /* command i_scroll pans image 1/PAN_FRACTION of screen width/height */
4646 static const int PAN_FRACTION = 5;
4747
48−/* if true, use a checkerboard background for alpha layer,
49− * toggled with 'A' key binding
50− */
51−static const bool ALPHA_LAYER = false;
52−
5348 /* percentage of memory to use for imlib2's cache size.
5449 * 3 means use 3% of total memory which is about 245MiB on 8GiB machine.
5550 * 0 or less means disable cache.
@@ -70,6 +65,11 @@ static const int CACHE_SIZE_FALLBACK = 32 * 1024 * 1024; /* fallback to 32MiB if
7065 */
7166 static const bool ANTI_ALIAS = true;
7267
68+/* if true, use a checkerboard background for alpha layer,
69+ * toggled with 'A' key binding (overwritten via `--alpha-layer` option)
70+ */
71+static const bool ALPHA_LAYER = false;
72+
7373 #endif
7474 #ifdef INCLUDE_THUMBS_CONFIG
7575
M etc/nsxiv.1 View
@@ -119,6 +119,11 @@ key-handler and the input of \-i will be separated by a NULL character.
119119 Enables anti-aliasing, when given
120120 .I no
121121 as an argument, disables it instead.
122+.TP
123+.BI "\-\-alpha\-layer" [=no]
124+Enables checkerboard background for alpha layer, when given
125+.I no
126+as an argument, disables it instead.
122127 .SH KEYBOARD COMMANDS
123128 .SS General
124129 The following keyboard commands are available in both image and thumbnail modes:
M image.c View
@@ -91,7 +91,7 @@ void img_init(img_t *img, win_t *win)
9191 img->checkpan = false;
9292 img->dirty = false;
9393 img->anti_alias = options->anti_alias;
94− img->alpha = ALPHA_LAYER;
94+ img->alpha = options->alpha_layer;
9595 img->multi.cap = img->multi.cnt = 0;
9696 img->multi.animate = options->animate;
9797 img->multi.framedelay = options->framerate > 0 ? 1000 / options->framerate : 0;
M nsxiv.h View
@@ -241,6 +241,7 @@ struct opt {
241241 float zoom;
242242 bool animate;
243243 bool anti_alias;
244+ bool alpha_layer;
244245 int gamma;
245246 unsigned int slideshow;
246247 int framerate;
M options.c View
@@ -66,8 +66,13 @@ static void print_version(void)
6666
6767 void parse_options(int argc, char **argv)
6868 {
69− enum { /* ensure these can't be represented in a single byte */
70− OPT_AA = UCHAR_MAX + 1
69+ enum {
70+ /* ensure these can't be represented in a single byte in order
71+ * to avoid conflicts with short opts
72+ */
73+ OPT_START = UCHAR_MAX,
74+ OPT_AA,
75+ OPT_AL
7176 };
7277 static const struct optparse_long longopts[] = {
7378 { "framerate", 'A', OPTPARSE_REQUIRED },
@@ -95,6 +100,7 @@ void parse_options(int argc, char **argv)
95100 { "zoom", 'z', OPTPARSE_REQUIRED },
96101 { "null", '0', OPTPARSE_NONE },
97102 { "anti-alias", OPT_AA, OPTPARSE_OPTIONAL },
103+ { "alpha-layer", OPT_AL, OPTPARSE_OPTIONAL },
98104 { 0 }, /* end */
99105 };
100106
@@ -115,6 +121,7 @@ void parse_options(int argc, char **argv)
115121 _options.scalemode = SCALE_DOWN;
116122 _options.zoom = 1.0;
117123 _options.anti_alias = ANTI_ALIAS;
124+ _options.alpha_layer = ALPHA_LAYER;
118125 _options.animate = false;
119126 _options.gamma = 0;
120127 _options.slideshow = 0;
@@ -247,6 +254,11 @@ void parse_options(int argc, char **argv)
247254 error(EXIT_FAILURE, 0, "Invalid argument for option --anti-alias: %s", op.optarg);
248255 _options.anti_alias = op.optarg == NULL;
249256 break;
257+ case OPT_AL:
258+ if (op.optarg != NULL && !STREQ(op.optarg, "no"))
259+ error(EXIT_FAILURE, 0, "Invalid argument for option --alpha-layer: %s", op.optarg);
260+ _options.alpha_layer = op.optarg == NULL;
261+ break;
250262 }
251263 }
252264