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.
39 lines
779 B
C++
39 lines
779 B
C++
#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();
|
|
}
|