I dunno that this makes it any easier...
I tried splitting up the sources to speed up some compiling... but it didn't help. I dunno that it's more readable this way. I'm checkpointing this just in case.
This commit is contained in:
65
backlight.cc
Normal file
65
backlight.cc
Normal file
@ -0,0 +1,65 @@
|
||||
#include "backlight.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <algorithm>
|
||||
|
||||
#include "power_console.h"
|
||||
|
||||
int
|
||||
getBacklightPercent( const std::filesystem::path &backlightPath )
|
||||
{
|
||||
std::ifstream i_max{ backlightPath / "max_brightness" };
|
||||
|
||||
int max;
|
||||
i_max >> max;
|
||||
|
||||
|
||||
std::ifstream inf{ backlightPath / "brightness" };
|
||||
int in;
|
||||
inf >> in;
|
||||
|
||||
return 100 * in / max;
|
||||
}
|
||||
|
||||
std::filesystem::path getBacklightPath();
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
void
|
||||
changeBrightness( int pct )
|
||||
{
|
||||
std::ifstream i_max{ getBacklightPath() / "max_brightness" };
|
||||
|
||||
int max;
|
||||
i_max >> max;
|
||||
|
||||
// Clamp to never hit 0 backlight or pass max.
|
||||
int adj= std::clamp( max * pct / 100, 1, max );
|
||||
std::cerr << "Adjustment computed: " << adj << std::endl;
|
||||
|
||||
std::ofstream out{ getBacklightPath() / "brightness" };
|
||||
out << adj;
|
||||
}
|
||||
|
||||
void
|
||||
increaseBrightness( int pct )
|
||||
{
|
||||
changeBrightness( pct );
|
||||
}
|
||||
|
||||
void
|
||||
decreaseBrightness( int pct )
|
||||
{
|
||||
changeBrightness( -pct );
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
adjustBrightness( MouseWheelSlider *, void * )
|
||||
{
|
||||
const int amount= brightness->value();
|
||||
std::cerr << "Adjusting brightness by " << amount << std::endl;
|
||||
changeBrightness( amount );
|
||||
}
|
||||
Reference in New Issue
Block a user