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.
+26 −8
5 files changed
- M config.def.h +5 −5
- M etc/nsxiv.1 +5 −0
- M image.c +1 −1
- M nsxiv.h +1 −0
- M options.c +14 −2
| @@ -45,11 +45,6 @@ static const double CONTRAST_MAX = 4.0; | |||
| 45 | 45 | /* command i_scroll pans image 1/PAN_FRACTION of screen width/height */ | |
| 46 | 46 | static const int PAN_FRACTION = 5; | |
| 47 | 47 | ||
| 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 | − | ||
| 53 | 48 | /* percentage of memory to use for imlib2's cache size. | |
| 54 | 49 | * 3 means use 3% of total memory which is about 245MiB on 8GiB machine. | |
| 55 | 50 | * 0 or less means disable cache. | |
| @@ -70,6 +65,11 @@ static const int CACHE_SIZE_FALLBACK = 32 * 1024 * 1024; /* fallback to 32MiB if | |||
| 70 | 65 | */ | |
| 71 | 66 | static const bool ANTI_ALIAS = true; | |
| 72 | 67 | ||
| 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 | + | ||
| 73 | 73 | #endif | |
| 74 | 74 | #ifdef INCLUDE_THUMBS_CONFIG | |
| 75 | 75 | ||
| @@ -119,6 +119,11 @@ key-handler and the input of \-i will be separated by a NULL character. | |||
| 119 | 119 | Enables anti-aliasing, when given | |
| 120 | 120 | .I no | |
| 121 | 121 | 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. | |
| 122 | 127 | .SH KEYBOARD COMMANDS | |
| 123 | 128 | .SS General | |
| 124 | 129 | The following keyboard commands are available in both image and thumbnail modes: | |
| @@ -91,7 +91,7 @@ void img_init(img_t *img, win_t *win) | |||
| 91 | 91 | img->checkpan = false; | |
| 92 | 92 | img->dirty = false; | |
| 93 | 93 | img->anti_alias = options->anti_alias; | |
| 94 | − | img->alpha = ALPHA_LAYER; | |
| 94 | + | img->alpha = options->alpha_layer; | |
| 95 | 95 | img->multi.cap = img->multi.cnt = 0; | |
| 96 | 96 | img->multi.animate = options->animate; | |
| 97 | 97 | img->multi.framedelay = options->framerate > 0 ? 1000 / options->framerate : 0; | |
| @@ -241,6 +241,7 @@ struct opt { | |||
| 241 | 241 | float zoom; | |
| 242 | 242 | bool animate; | |
| 243 | 243 | bool anti_alias; | |
| 244 | + | bool alpha_layer; | |
| 244 | 245 | int gamma; | |
| 245 | 246 | unsigned int slideshow; | |
| 246 | 247 | int framerate; | |
| @@ -66,8 +66,13 @@ static void print_version(void) | |||
| 66 | 66 | ||
| 67 | 67 | void parse_options(int argc, char **argv) | |
| 68 | 68 | { | |
| 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 | |
| 71 | 76 | }; | |
| 72 | 77 | static const struct optparse_long longopts[] = { | |
| 73 | 78 | { "framerate", 'A', OPTPARSE_REQUIRED }, | |
| @@ -95,6 +100,7 @@ void parse_options(int argc, char **argv) | |||
| 95 | 100 | { "zoom", 'z', OPTPARSE_REQUIRED }, | |
| 96 | 101 | { "null", '0', OPTPARSE_NONE }, | |
| 97 | 102 | { "anti-alias", OPT_AA, OPTPARSE_OPTIONAL }, | |
| 103 | + | { "alpha-layer", OPT_AL, OPTPARSE_OPTIONAL }, | |
| 98 | 104 | { 0 }, /* end */ | |
| 99 | 105 | }; | |
| 100 | 106 | ||
| @@ -115,6 +121,7 @@ void parse_options(int argc, char **argv) | |||
| 115 | 121 | _options.scalemode = SCALE_DOWN; | |
| 116 | 122 | _options.zoom = 1.0; | |
| 117 | 123 | _options.anti_alias = ANTI_ALIAS; | |
| 124 | + | _options.alpha_layer = ALPHA_LAYER; | |
| 118 | 125 | _options.animate = false; | |
| 119 | 126 | _options.gamma = 0; | |
| 120 | 127 | _options.slideshow = 0; | |
| @@ -247,6 +254,11 @@ void parse_options(int argc, char **argv) | |||
| 247 | 254 | error(EXIT_FAILURE, 0, "Invalid argument for option --anti-alias: %s", op.optarg); | |
| 248 | 255 | _options.anti_alias = op.optarg == NULL; | |
| 249 | 256 | 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; | |
| 250 | 262 | } | |
| 251 | 263 | } | |
| 252 | 264 | ||