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:
2026-01-26 03:47:52 -05:00
parent 9fca970fc5
commit c368696cc2
11 changed files with 279 additions and 200 deletions

38
power_profile.cc Normal file
View File

@ -0,0 +1,38 @@
#include "power_profile.h"
#include <thread>
#include <map>
#include "power_console.h"
const std::map< std::string, Fl_Round_Button ** > powerMode=
{
{ "power-saver", &saver },
{ "balanced", &balance },
{ "performance", &perfButton },
};
// 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 );
}
void
setPowerMode( const std::string &mode )
{
( *powerMode.at( mode ) )->setonly();
std::thread bg{ [mode]{ system( ( "powerprofilesctl set " + mode ).c_str() ); } };
bg.detach();
}