Skip to content

Commit b7b79c3

Browse files
committed
Udate for issue #391 for GTK
1 parent e80fbb8 commit b7b79c3

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

lib/host/gtk3/base_view.cpp

+41-1
Original file line numberDiff line numberDiff line change
@@ -843,9 +843,49 @@ namespace cycfi { namespace elements
843843
}
844844
}
845845

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+
846872
point scroll_direction()
847873
{
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;
849888
}
889+
850890
}}
851891

0 commit comments

Comments
 (0)