#include "backlight.h" #include #include #include #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 ); }