Initial commit
This commit is contained in:
53
xbacklight
Normal file
53
xbacklight
Normal file
@@ -0,0 +1,53 @@
|
||||
#!/usr/bin/perl
|
||||
|
||||
my $arg = $ARGV[0];
|
||||
my $step = 10; # measured in percents
|
||||
|
||||
sub fsread($); # read 1-st line from file
|
||||
sub fswrite(@); # write string to file
|
||||
|
||||
my $brightnessfile = "/sys/class/backlight/acpi_video0/brightness";
|
||||
my $maxbrightness = fsread("/sys/class/backlight/acpi_video0/max_brightness");
|
||||
my $currbrightness = fsread($brightnessfile);
|
||||
|
||||
my $a = $maxbrightness / 100;
|
||||
$step = int($step * $a);
|
||||
|
||||
if ( $arg eq "up" ) {
|
||||
if ($currbrightness != $maxbrightness) {
|
||||
my $projectedbrightness = $currbrightness + $step;
|
||||
|
||||
if ($projectedbrightness > $maxbrightness) {
|
||||
$projectedbrightness = $maxbrightness;
|
||||
}
|
||||
|
||||
fswrite($projectedbrightness, $brightnessfile);
|
||||
}
|
||||
} elsif ( $arg eq "down" ) {
|
||||
if ($currbrightness != 0) {
|
||||
my $projectedbrightness = $currbrightness - $step;
|
||||
|
||||
if ($projectedbrightness < 0) {
|
||||
$projectedbrightness = 0;
|
||||
}
|
||||
|
||||
fswrite($projectedbrightness, $brightnessfile);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
sub fsread($) {
|
||||
my $fname = shift;
|
||||
open (F, $fname) || die;
|
||||
my $str = <F>;
|
||||
close F;
|
||||
return $str;
|
||||
}
|
||||
|
||||
sub fswrite (@) {
|
||||
my $str = shift;
|
||||
my $fname = shift;
|
||||
open(OF, ">", $fname) || die;
|
||||
print OF $str;
|
||||
close OF;
|
||||
}
|
||||
Reference in New Issue
Block a user