Basic Brightness control.
This commit is contained in:
@ -50,5 +50,10 @@ Function {make_window()} {open
|
||||
label AC
|
||||
xywh {129 49 34 24} type Normal box PLASTIC_ROUND_DOWN_BOX when 0
|
||||
}
|
||||
Fl_Slider brightness {
|
||||
label Brightness
|
||||
callback adjustBrightness selected
|
||||
xywh {129 81 20 52} labelsize 12
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -77,6 +77,18 @@ scheduledUpdate( void * )
|
||||
acButton->value( ac );
|
||||
if( C::debugUpdate ) std::cerr << "AC state read as: " << ac << std::endl;
|
||||
|
||||
|
||||
std::ifstream i_max{ "/sys/class/backlight/intel_backlight/max_brightness" };
|
||||
|
||||
int max;
|
||||
i_max >> max;
|
||||
|
||||
|
||||
std::ifstream inf{ "/sys/class/backlight/intel_backlight/brightness" };
|
||||
int in;
|
||||
inf >> in;
|
||||
|
||||
brightness->value( 101 - 100 * in / max );
|
||||
}
|
||||
|
||||
// Since this requires launching bg processes, we only do it at startup and then every 30s.
|
||||
@ -103,6 +115,10 @@ main( const int argcnt, char **argvec )
|
||||
level->value( 0 );
|
||||
level->label( battLevelString.c_str() );
|
||||
|
||||
brightness->minimum( 1 );
|
||||
brightness->maximum( 100 );
|
||||
brightness->step( 1 );
|
||||
|
||||
|
||||
w->hotspot( w );
|
||||
w->show( argcnt, argvec );
|
||||
@ -155,3 +171,41 @@ perfChosen()
|
||||
{
|
||||
setPowerMode( "performance" );
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
void
|
||||
changeBrightness( int pct )
|
||||
{
|
||||
std::ifstream i_max{ "/sys/class/backlight/intel_backlight/max_brightness" };
|
||||
|
||||
int max;
|
||||
i_max >> max;
|
||||
|
||||
int adj= max * pct / 100;
|
||||
std::cerr << "Adjustment computed: " << adj << std::endl;
|
||||
|
||||
std::ofstream out{ "/sys/class/backlight/intel_backlight/brightness" };
|
||||
out << adj;
|
||||
}
|
||||
|
||||
void
|
||||
increaseBrightness( int pct )
|
||||
{
|
||||
changeBrightness( pct );
|
||||
}
|
||||
|
||||
void
|
||||
decreaseBrightness( int pct )
|
||||
{
|
||||
changeBrightness( -pct );
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
adjustBrightness( Fl_Slider *, void * )
|
||||
{
|
||||
const int amount= 101 - brightness->value();
|
||||
std::cerr << "Adjusting brightness by " << amount << std::endl;
|
||||
changeBrightness( amount );
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user