aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md1
-rw-r--r--brightnessctl.110
-rw-r--r--brightnessctl.c51
3 files changed, 34 insertions, 28 deletions
diff --git a/README.md b/README.md
index a4ebca3..9963724 100644
--- a/README.md
+++ b/README.md
@@ -36,6 +36,7 @@ Options:
-p, --pretend do not perform write operations.
-m, --machine-readable produce machine-readable output.
-n, --min-value set minimum brightness, defaults to 1.
+ -e, --exponent[=K] changes percentage curve to exponential.
-s, --save save previous state in a temporary file.
-r, --restore restore previous saved state.
-h, --help print this help.
diff --git a/brightnessctl.1 b/brightnessctl.1
index fa798c7..83faf8d 100644
--- a/brightnessctl.1
+++ b/brightnessctl.1
@@ -49,6 +49,16 @@ Set minimum brightness when using delta values, defaults to 1.
.RE
.sp
+\fB\-e, \-\-exponent\fP=\fIK\fP
+.RS 4
+Changes percentage scaling curve to exponential (linear by default). Default exponent is 4.
+
+Percentage equation: % = \fI[VALUE]\fR^\fI[K]\fR * \fI[MAX]\fR * 100^-\fI[K]\fR.
+
+The exponential curve may make the adjustments perceptually equal.
+.RE
+
+.sp
\fB\-s, \-\-save\fP
.RS 4
Save state in a temporary file.
diff --git a/brightnessctl.c b/brightnessctl.c
index ab87ef3..f46b2bd 100644
--- a/brightnessctl.c
+++ b/brightnessctl.c
@@ -305,46 +305,43 @@ void list_devices(struct device **devs) {
print_device(dev);
}
-float val_to_percent(long val,struct device *d) {
- if (val < 0) return 0;
- return powf(powf(100,p.exponent)*val/d->max_brightness,1.0f/p.exponent);
+float val_to_percent(long val, struct device *d) {
+ if (val < 0)
+ return 0;
+ return powf(powf(100, p.exponent) * val / d->max_brightness, 1.0f / p.exponent);
}
-unsigned long percent_to_val(float percent,struct device *d) {
- float r = (powf(percent,p.exponent)*d->max_brightness)*(powf(100,-p.exponent));
- return r < 0 ? 0 : (unsigned long)r;
+unsigned long percent_to_val(float percent, struct device *d) {
+ float r = (powf(percent, p.exponent) * d->max_brightness) * powf(100, -p.exponent);
+ return (unsigned long) r;
}
void print_device(struct device *dev) {
- char *format = p.mach ? "%s,%s,%d,%d%%,%d\n":
+ char *format = p.mach ? "%s,%s,%d,%d%%,%d\n" :
"Device '%s' of class '%s':\n\tCurrent brightness: %d (%d%%)\n\tMax brightness: %d\n\n";
fprintf(stdout, format,
dev->id, dev->class,
dev->curr_brightness,
- (int) val_to_percent(dev->curr_brightness,dev),
+ (int) val_to_percent(dev->curr_brightness, dev),
dev->max_brightness);
}
void apply_value(struct device *d, struct value *val) {
- long new;
+ long new = d->curr_brightness;
if (val->d_type == DIRECT) {
- if(val->v_type == ABSOLUTE)
- new = val->val > d->max_brightness ? d->max_brightness : val->val;
- else
- new = percent_to_val(val->val,d);
- } else {//DELTA
- if(val->v_type == ABSOLUTE) {
- new = d->curr_brightness + (val->sign == PLUS ? val->val : -val->val);
- } else {
- new = percent_to_val(val_to_percent(d->curr_brightness,d) + ((long)(val->sign == PLUS ? val->val : -val->val)),d);
- if(new == d->curr_brightness) {
- if(val->sign == PLUS)
- new += 1;
- else
- new -= 1;
- }
- }
+ new = val->v_type == ABSOLUTE ? val->val : percent_to_val(val->val, d);
+ goto apply;
+ }
+ long mod = val->val;
+ if (val->sign == MINUS)
+ mod *= -1;
+ if (val->v_type == RELATIVE) {
+ mod = percent_to_val(val_to_percent(d->curr_brightness, d) + mod, d) - d->curr_brightness;
+ if (val->val != 0 && mod == 0)
+ mod = val->sign == PLUS ? 1 : -1;
}
+ new += mod;
+apply:
if (new < p.min)
new = p.min;
if (new < 0)
@@ -598,9 +595,7 @@ Options:\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\
- -e, --exponent\t\tchange percent value mapping to polynominal.\n\
- \t\t\t%%=x^k*max*100^-k, k defaults to 4.\n\
- \t\t\tTry changing the value until the changes \"feel\" equal.\n\
+ -e, --exponent[=K]\t\tchanges percentage curve to exponential.\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\