aboutsummaryrefslogtreecommitdiff
path: root/brightnessctl.c
Commit message (Collapse)AuthorAge
* Support fractional valuesHEADmasterGravatar Benjamin Barenblat2020-05-13
| | | | | | | | | | | | | | | | Treat values passed on the command line as floats instead of longs. This allows you to specify fractional percentages (and fractional absolute values, too, though they’ll just be rounded down, so they’re not particularly useful). Report the display brightness as a percentage with two decimal places rather than zero. To ensure backward compatibility in machine-readable mode, report the high-precision percentage in a new field rather than replacing the existing field. This does cause some redundancy in the output, but that’s better than breaking scripts that assume the 4th field is an integer followed by “%”. Closes: https://github.com/Hummer12007/brightnessctl/issues/50
* Allow relative --min-value argumentsGravatar Alexander Kobel2020-04-20
|
* Make optarg parsing more robustGravatar Alexander Kobel2020-04-20
| | | | Allow -n MIN as equivalent to -nMIN and --min-value=MIN.
* Build fixupGravatar Mykyta Holubakha2020-02-02
| | | | | | systemd install fixup Closes #42, #44
* Improve saving device dataGravatar Mykyta Holubakha2020-01-25
|
* Fix roundings for percentage calculationsGravatar Mykyta Holubakha2020-01-25
|
* Stop leaking temporary pathsGravatar Mykyta Holubakha2020-01-25
|
* Make the use of `SetBrightness` dynamicGravatar Antoine Damhet2019-09-19
| | | | | | | It will only be used if the user do not have the permission to directly write to the backlight device. Signed-off-by: Antoine Damhet <antoine.damhet@lse.epita.fr>
* Support the new `SetBrightness` logind APIGravatar Antoine Damhet2019-09-19
| | | | | | | | | This API from `org.freedesktop.login1.Session` allows an unprivileged user with an active session to change its own backlight. Systemd >= v243 is needed. Signed-off-by: Antoine Damhet <antoine.damhet@lse.epita.fr>
* Documented new changesGravatar Mykyta Holubakha2019-08-02
| | | | Rewritten some contributed code
* Added a mapping function (exponent)Gravatar Schnilz2019-08-02
| | | | | | | | added -e / --exponent. As the perceived brightness change from 10% to 20% is not the same as 90% to 100%, there is now a float parameter--exponent / -e to set the mapping of the percentage form linear (as it was) to polynominal. (%=x^k*max*100^-k) k is the value that you can change now.
* Fixes return code when set in quiet modeGravatar Antoni Villalonga2019-08-02
|
* Fix read_device returnGravatar Hummer120072018-07-22
| | | closes #24
* Considered bitfields harmfulGravatar Mykyta Holubakha2018-07-13
|
* Refactor to use stdbool.h for consistent booleansGravatar Mykyta Holubakha2018-07-13
|
* Create temporary directory under XDG_RUNTIME_DIRGravatar Mykyta Holubakha2018-07-13
| | | | | | fallback to /tmp closes #22
* Added flag to dissallow setting brightness to zero when using delta values (#21)Gravatar Thomas Ingram2018-06-25
| | | | | | | | * 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
* Allow to specify device name as a wildcardGravatar Mykyta Holubakha2018-01-19
|
* Fix rounding errors when using percentagesGravatar Markus Schneider2017-08-26
|
* Add --version flagGravatar Christoph Gysin2017-07-28
|
* Add "info" operation and make it defaultGravatar hcpl2017-07-28
| | | | There should be an option to get a sole "current brightness" value.
* Add comment to silence -Wimplicit-fallthroughGravatar Christoph Gysin2017-07-28
|
* Remove trailing whitespaceGravatar Christoph Gysin2017-07-28
|
* Fix logical errorsGravatar Mykyta Holubakha2017-01-18
| | | | | | | | | | Restore device data only after successful read Do not set curr_brightness to max after an unsuccessful restore Fix ensure_dir Do not ignore ignore value of fread (fixes #6)
* No longer require root privilegesGravatar Mykyta Holubakha2017-01-17
|
* Ensure state files are world-writableGravatar Mykyta Holubakha2017-01-15
|
* Refactor directory accessGravatar Mykyta Holubakha2017-01-15
| | | | Add static specifier to functions
* Fix a null-pointer dereference in read_deviceGravatar Mykyta Holubakha2017-01-15
|
* Print error if run dir is not a directoryGravatar Miciah Masters2017-01-15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Print an error message if the run directory or the device-class subdirectory exists but is not a directory. Before: % rm -rf /tmp/brightnessctl % touch /tmp/brightnessctl % brightnessctl -s Device 'intel_backlight' of class 'backlight': Current brightness: 1000 (20%) Max brightness: 4794 % file /tmp/brightnessctl /tmp/brightnessctl: empty % After: % brightnessctl -s Error saving device data: Not a directory Could not save data for device 'intel_backlight'. Device 'intel_backlight' of class 'backlight': Current brightness: 1000 (20%) Max brightness: 4794 %
* Clean up error handlingGravatar Miciah Masters2017-01-15
| | | | | | | | | | | | | | | | | | | | | Make several changes to error handling: • Check for negative values from sprintf, and treat them as errors. • Check for errors from fscanf both by comparing its return value against EOF and by checking ferror. • Avoiding calling perror with errno set to -1. Either set a meaningful value, such as EINVAL, or use fprintf if errno cannot be expected to have a meaningful value. • Instead of re-using errno for internal error handling, use a new variable to indicate errors where it makes sense to do so. • In read_device, print more specific error messages if we fail to read a device's current or max brightness, and print an error message immediately if a read fails, instead of only maybe at the end of read_device.
* Do not write NUL to state fileGravatar Miciah Masters2017-01-15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Do not write a trailing NUL byte to the state file. Before: % brightnessctl -ms intel_backlight,backlight,1000,20%,4794 % od -t x1z /tmp/brightnessctl/backlight/intel_backlight 0000000 31 30 30 30 00 >1000.< 0000005 % After: % brightnessctl -ms intel_backlight,backlight,1000,20%,4794 % od -t x1z /tmp/brightnessctl/backlight/intel_backlight 0000000 31 30 30 30 >1000< 0000004 % Note that restore still works: % brightnessctl -mr intel_backlight,backlight,1000,20%,4794 %
* Fix logic for directory creation when saving stateGravatar Miciah Masters2017-01-15
| | | | | | | | | | | | | | | | | | | | | When creating the /tmp/brightnessctl directory or its subdirectories, clear errno before calling mkdir, and call stat a second time after mkdir. Previously, errno was not cleared, so even if the error was handled (by creating the missing directory with mkdir), subsequent error handling code read the old errno value from the failed stat call and printed an error message. Additionally, because we did not call stat again after calling mkdir, the stat buffer had outdated information, and so S_ISDIR returned a false negative. As a result of these defects, invoking brightnessctl -s when /tmp/brightnessctl did not exist would create /tmp/brightnessctl and fail. Invoking brightnessctl -s a second time would create /tmp/brightnessctl/backlight and fail. Invoking the command a third time would succeed and write the state file under /tmp/brightnessctl/backlight/. After this commit, brightnessctl -s succeeds the first time.
* -r/--restore requires root, same as setGravatar Miciah Masters2017-01-15
| | | | | | The -r/--restore flag requires root, the same as the set verb does, so print an error message if either the flag or the verb is used without running as root.
* Set dev_name to default device nameGravatar Miciah Masters2017-01-15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | If no device is specified with the --device flag, set dev_name to the id of the first device. Before, if the --device flag is not used to specify the default device, the dev pointer was set to first device found (see commit c9140d1e5070dae2746d3b70c0390075bd5380f6), but the dev_name pointer was left set to NULL. As a result, some error messages did not print the name of the default device: % brightnessctl -s Error saving device data: No such file or directory Could not save data for device '(null)'. Device 'intel_backlight' of class 'backlight': Current brightness: 1000 (20%) Max brightness: 4794 % brightnessctl -s -m Error saving device data: No such file or directory Could not save data for device '(null)'. intel_backlight,backlight,1000,20%,4794 % After this commit, all error messages have the correct name: % brightnessctl -s Error saving device data: No such file or directory Could not save data for device 'intel_backlight'. Device 'intel_backlight' of class 'backlight': Current brightness: 1000 (20%) Max brightness: 4794 % brightnessctl -s -m Error saving device data: No such file or directory Could not save data for device 'intel_backlight'. intel_backlight,backlight,1000,20%,4794 %
* Fix buffer overflow in cat_withGravatar Miciah Masters2017-01-09
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Account for separators when computing the buffer size in cat_width in order to avoid overflowing the buffer. Previously, cat_width only accounted for the lengths of the strings being catenated, but not the separators, which could result in buffer overflows. For example, trace the execution of the following invocation of cat_with: char s[5] = "xxxx"; cat_with(' ', s, s, s, s, s, s, s, s); cat_with initialises size and length and allocates an initial buffer: size = 32; /* size = 32 */ length = 0; /* length = 0 */ buf = calloc(1, size + 1); /* allocated 33 bytes for buf */ The first iteration of the main loop in cat_with catenates the first string and a separator but fails to account for the separator in length: length += strlen(curr); /* length = 4 */ while (length + 2 > size) /* 4 + 2 > 32 is false */ strcat(buf, curr); /* written 5 bytes to buf */ strcat(buf, split); /* written 6 bytes to buf */ Now we have written the string "xxxx " (6 bytes including NUL) to buf, but length only counts the 4 bytes "xxxx" (excluding NUL). In successive iterations, the discrepancy between the value in length and the actual length of the string in the buffer grows: length += strlen(curr); /* length = 8 */ while (length + 2 > size) /* 8 + 2 > 32 is false */ strcat(buf, curr); /* written 10 bytes to buf */ strcat(buf, split); /* written 11 bytes to buf */ Now we have written "xxxx xxxx " (11 bytes incl. NUL). length += strlen(curr); /* length = 12 */ while (length + 2 > size) /* 12 + 2 > 32 is false */ strcat(buf, curr); /* written 15 bytes to buf */ strcat(buf, split); /* written 16 bytes to buf */ Now we have written "xxxx xxxx xxxx " (16 bytes incl. NUL). length += strlen(curr); /* length = 16 */ while (length + 2 > size) /* 16 + 2 > 32 is false */ strcat(buf, curr); /* written 20 bytes to buf */ strcat(buf, split); /* written 21 bytes to buf */ Now we have written "xxxx xxxx xxxx xxxx " (21 bytes incl. NUL). length += strlen(curr); /* length = 20 */ while (length + 2 > size) /* 20 + 2 > 32 is false */ strcat(buf, curr); /* written 25 bytes to buf */ strcat(buf, split); /* written 26 bytes to buf */ Now we have written "xxxx xxxx xxxx xxxx xxxx " (26 bytes incl. NUL). length += strlen(curr); /* length = 24 */ while (length + 2 > size) /* 24 + 2 > 32 is false */ strcat(buf, curr); /* written 30 bytes to buf */ strcat(buf, split); /* written 31 bytes to buf */ Now we have written "xxxx xxxx xxxx xxxx xxxx xxxx " (31 bytes incl. NUL). Eventually, the string can grow beyond the buffer before length grows large enough to cause a re-allocation: length += strlen(curr); /* length = 28 */ while (length + 2 > size) /* 28 + 2 > 32 is false */ strcat(buf, curr); /* written 35 bytes to buf */ strcat(buf, split); /* written 36 bytes to buf */ Note that we have not increased size or re-allocated the buffer, and so we have written "xxxx xxxx xxxx xxxx xxxx xxxx xxxx" (35 bytes incl. NUL) to a buffer for which we have allocated only 33 bytes.
* Document prefix-sign supportGravatar Mykyta Holubakha2017-01-07
|
* Fix prefix-sign supportGravatar Mykyta Holubakha2017-01-07
|
* Support delta sign in prefixGravatar Hummer120072017-01-07
|
* Improve readme and helpGravatar Fabio Alessandro Locati2016-11-27
|
* do not write NUL to brightness fileGravatar Mykyta Holubakha2016-07-04
|
* refactored cat_withGravatar Mykyta Holubakha2016-07-04
|
* default device is the firstGravatar Mykyta Holubakha2016-06-22
|
* fix warnings, segfaultGravatar Mykyta Holubakha2016-06-22
|
* Code cleanupGravatar Mykyta Holubakha2016-04-26
|
* Close file handlesGravatar Mykyta Holubakha2016-04-07
|
* Addeed support for save/restore functionalityGravatar Mykyta Holubakha2016-04-07
|
* Initial commitGravatar Mykyta Holubakha2016-03-28