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:
@ -12,6 +12,8 @@
|
||||
#include <filesystem>
|
||||
|
||||
#include "ConfigFile.h"
|
||||
#include "power_profile.h"
|
||||
#include "backlight.h"
|
||||
|
||||
namespace C
|
||||
{
|
||||
@ -43,17 +45,16 @@ const std::map< int, Fl_Color > levelColors=
|
||||
{ 100, FL_BLUE },
|
||||
};
|
||||
|
||||
const std::map< std::string, Fl_Round_Button ** > powerMode=
|
||||
{
|
||||
{ "power-saver", &saver },
|
||||
{ "balanced", &balance },
|
||||
{ "performance", &perfButton },
|
||||
};
|
||||
|
||||
|
||||
using Config::exports::ConfigFile;
|
||||
std::unique_ptr< ConfigFile > config;
|
||||
|
||||
std::filesystem::path
|
||||
getBacklightPath()
|
||||
{
|
||||
return config->get( "backlight_path" );
|
||||
}
|
||||
|
||||
std::string battLevelString= "UNKNOWN";
|
||||
|
||||
void
|
||||
@ -92,31 +93,9 @@ scheduledUpdate( void * )
|
||||
if( C::debugUpdate ) std::cerr << "AC state read as: " << ac << std::endl;
|
||||
|
||||
|
||||
std::ifstream i_max{ C::path / config->get( "backlight_path" ) / "max_brightness" };
|
||||
const auto backlightPercent= getBacklightPercent( config->get( "backlight_path" ) );
|
||||
|
||||
int max;
|
||||
i_max >> max;
|
||||
|
||||
|
||||
std::ifstream inf{ C::path / config->get( "backlight_path" ) / "brightness" };
|
||||
int in;
|
||||
inf >> in;
|
||||
|
||||
brightness->value( 100 * in / max );
|
||||
}
|
||||
|
||||
// Since this requires launching bg processes, we only do it at startup and then every 30s.
|
||||
void
|
||||
profileUpdate( void * )
|
||||
{
|
||||
FILE *prof= popen( "powerprofilesctl get", "r" );
|
||||
char buffer[ 1024 ]= "";
|
||||
fscanf( prof, "%s", buffer );
|
||||
pclose( prof );
|
||||
|
||||
( *powerMode.at( buffer ) )->setonly();
|
||||
|
||||
Fl::repeat_timeout( 30, profileUpdate, nullptr );
|
||||
brightness->value( backlightPercent );
|
||||
}
|
||||
|
||||
int
|
||||
@ -175,14 +154,6 @@ consClicked( Fl_Light_Button *, void * )
|
||||
std::cerr << "Tried to set new state to " << newState << std::endl;
|
||||
}
|
||||
|
||||
void
|
||||
setPowerMode( const std::string &mode )
|
||||
{
|
||||
( *powerMode.at( mode ) )->setonly();
|
||||
std::thread bg{ [mode]{ system( ( "powerprofilesctl set " + mode ).c_str() ); } };
|
||||
bg.detach();
|
||||
}
|
||||
|
||||
void
|
||||
saverChosen()
|
||||
{
|
||||
@ -200,42 +171,3 @@ perfChosen()
|
||||
{
|
||||
setPowerMode( "performance" );
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
void
|
||||
changeBrightness( int pct )
|
||||
{
|
||||
std::ifstream i_max{ C::path / config->get( "backlight_path" ) / "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{ C::path / config->get( "backlight_path" ) / "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