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:
38
power_profile.cc
Normal file
38
power_profile.cc
Normal 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();
|
||||
}
|
||||
Reference in New Issue
Block a user