Files
power-console/backlight.cc
ADAM David Alan Martin c368696cc2 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.
2026-01-26 03:47:52 -05:00

66 lines
1.1 KiB
C++

#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 );
}