diff --git a/power_console.fluid b/power_console.fluid index 210b83d..e0436eb 100644 --- a/power_console.fluid +++ b/power_console.fluid @@ -7,14 +7,14 @@ declblock {\#if 1} { extern void saverChosen(); extern void perfChosen();} open public map 1 after {\#endif} } { - decl {\#include "power_console_common.h"} {selected public global + decl {\#include "power_console_common.h"} {public global } } Function {make_window()} {open } { Fl_Window {} {open - xywh {506 191 177 183} type Double box GLEAM_UP_BOX visible + xywh {506 1271 177 183} type Double box GLEAM_UP_BOX visible } { Fl_Light_Button conserveButton { label {Conserve Battery} @@ -52,6 +52,7 @@ Function {make_window()} {open label Brightness callback adjustBrightness xywh {129 81 20 52} labelsize 12 + class MouseWheelSlider } } } diff --git a/power_console_common.h b/power_console_common.h index c59f9c0..1c2c2ea 100644 --- a/power_console_common.h +++ b/power_console_common.h @@ -1,5 +1,49 @@ #pragma once +#include +#include +#include + + void saverChosen(); void perfChosen(); void balChosen(); + +class MouseWheelSlider : public Fl_Value_Slider +{ + public: + explicit + MouseWheelSlider( const int x, const int y, const int w, const int h, + const char *const l= 0 ) + : Fl_Value_Slider( x, y, w, h, l ) + { + + step( 1 ); + } + + int + handle( const int event ) override + { + switch( event ) + { + case FL_MOUSEWHEEL: + { + // Negative, because I use this for the Brightness control. + const int dy= -Fl::event_dy(); + + value( value() - dy * step() ); + + do_callback(); + + return 1; + } + break; + + default: + { + return this->Fl_Value_Slider::handle( event ); + } + break; + } + } +}; diff --git a/power_console_main.cc b/power_console_main.cc index c61004b..4bcd1fb 100644 --- a/power_console_main.cc +++ b/power_console_main.cc @@ -6,6 +6,7 @@ #include #include #include +#include #include #include @@ -88,7 +89,7 @@ scheduledUpdate( void * ) int in; inf >> in; - brightness->value( 101 - 100 * in / max ); + brightness->value( 100 * in / max ); } // Since this requires launching bg processes, we only do it at startup and then every 30s. @@ -115,9 +116,9 @@ main( const int argcnt, char **argvec ) level->value( 0 ); level->label( battLevelString.c_str() ); - brightness->minimum( 1 ); - brightness->maximum( 100 ); - brightness->step( 1 ); + brightness->maximum( 1 ); + brightness->minimum( 100 ); + brightness->step( -1 ); w->hotspot( w ); @@ -203,9 +204,9 @@ namespace } void -adjustBrightness( Fl_Slider *, void * ) +adjustBrightness( MouseWheelSlider *, void * ) { - const int amount= 101 - brightness->value(); + const int amount= brightness->value(); std::cerr << "Adjusting brightness by " << amount << std::endl; - changeBrightness( amount ); + changeBrightness( std::clamp( amount, 1, 100 ) ); }