aboutsummaryrefslogtreecommitdiff
path: root/brightnessctl.c
diff options
context:
space:
mode:
authorGravatar Thomas Ingram <taingram@mtu.edu>2018-06-25 11:37:53 -0600
committerGravatar Hummer12007 <hilobakho@gmail.com>2018-06-25 20:37:53 +0300
commite7115df8922e47432ddf97f992330860c44ab6b1 (patch)
treecb33dfdea1a1f4f5884b3f206f4bcb822a6d00a5 /brightnessctl.c
parentff221f7584eba45e779c43cf2db5d2a437de7722 (diff)
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
Diffstat (limited to 'brightnessctl.c')
-rw-r--r--brightnessctl.c13
1 files changed, 12 insertions, 1 deletions
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\