@@ -843,9 +843,49 @@ namespace cycfi { namespace elements
843
843
}
844
844
}
845
845
846
+ namespace
847
+ {
848
+ std::string exec (char const * cmd)
849
+ {
850
+ std::array<char , 128 > buffer;
851
+ std::string result;
852
+ std::unique_ptr<FILE, decltype (&pclose )> pipe (popen (cmd, " r" ), pclose );
853
+ if (!pipe )
854
+ throw std::runtime_error (" popen() failed!" );
855
+ while (fgets (buffer.data (), buffer.size (), pipe .get ()) != nullptr )
856
+ result += buffer.data ();
857
+ return result;
858
+ }
859
+
860
+ point get_scroll_direction ()
861
+ {
862
+ std::string output = exec (" gsettings get org.gnome.desktop.peripherals.touchpad natural-scroll" );
863
+ output.erase (remove (output.begin (), output.end (), ' \n ' ), output.end ());
864
+
865
+ if (output == " true" )
866
+ return {+1 .0f , +1 .0f }; // Assuming positive for natural scrolling
867
+ else
868
+ return {-1 .0f , -1 .0f }; // Assuming negative for traditional scrolling
869
+ }
870
+ }
871
+
846
872
point scroll_direction ()
847
873
{
848
- return {+1 .0f , +1 .0f };
874
+ using namespace std ::chrono;
875
+ static auto last_call = steady_clock::now () - seconds (10 );
876
+ static point dir = get_scroll_direction (); // Initial call
877
+
878
+ // In case the user changed the scroll direction settings, we will
879
+ // call get_scroll_direction() every 10 seconds.
880
+ auto now = steady_clock::now ();
881
+ if (duration_cast<seconds>(now - last_call) >= seconds (10 ))
882
+ {
883
+ dir = get_scroll_direction (); // Update the direction if 10 seconds have passed
884
+ last_call = now; // Update the last call time
885
+ }
886
+
887
+ return dir;
849
888
}
889
+
850
890
}}
851
891
0 commit comments