From e7115df8922e47432ddf97f992330860c44ab6b1 Mon Sep 17 00:00:00 2001 From: Thomas Ingram Date: Mon, 25 Jun 2018 11:37:53 -0600 Subject: Added flag to dissallow setting brightness to zero when using delta values (#21) * Added flag never-zero that stops brightness being set to 0. * Updated README to show never-zero flag. * Replaced never-zero with min-value flag --- brightnessctl.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'brightnessctl.c') diff --git a/brightnessctl.c b/brightnessctl.c index 4cfaf29..fef1c20 100644 --- a/brightnessctl.c +++ b/brightnessctl.c @@ -67,6 +67,7 @@ struct params { char *class; char *device; struct value val; + long min; unsigned int quiet : 1; unsigned int list : 1; unsigned int pretend : 1; @@ -84,6 +85,7 @@ static const struct option options[] = { {"help", no_argument, NULL, 'h'}, {"list", no_argument, NULL, 'l'}, {"machine-readable", no_argument, NULL, 'm'}, + {"min-value", optional_argument, NULL, 'n'}, {"quiet", no_argument, NULL, 'q'}, {"pretend", no_argument, NULL, 'p'}, {"restore", no_argument, NULL, 'r'}, @@ -103,7 +105,7 @@ int main(int argc, char **argv) { if (strcmp(name.sysname, "Linux")) fail("This program only supports Linux.\n"); while (1) { - if ((c = getopt_long(argc, argv, "lqpmsrhVc:d:", options, NULL)) < 0) + if ((c = getopt_long(argc, argv, "lqpmn::srhVc:d:", options, NULL)) < 0) break; switch (c) { case 'l': @@ -124,6 +126,12 @@ int main(int argc, char **argv) { case 'm': p.mach = 1; break; + case 'n': + if (optarg) + p.min = atol(optarg); + else + p.min = 1; + break; case 'h': usage(); exit(EXIT_SUCCESS); @@ -301,6 +309,8 @@ void apply_value(struct device *d, struct value *val) { } mod *= val->sign == PLUS ? 1 : -1; new = d->curr_brightness + mod; + if (new < p.min) + new = p.min; if (new < 0) new = 0; if (new > d->max_brightness) @@ -550,6 +560,7 @@ Options:\n\ -q, --quiet\t\t\tsuppress output.\n\ -p, --pretend\t\t\tdo not perform write operations.\n\ -m, --machine-readable\tproduce machine-readable output.\n\ + -n, --min-value\t\tset minimum brightness, defaults to 1.\n\ -s, --save\t\t\tsave previous state in a temporary file.\n\ -r, --restore\t\t\trestore previous saved state.\n\ -h, --help\t\t\tprint this help.\n\ -- cgit v1.2.3