#include "power_profile.h" #include #include #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(); }