Skip to content

Commit

Permalink
Udate for issue #391 for GTK
Browse files Browse the repository at this point in the history
  • Loading branch information
djowel committed Apr 6, 2024
1 parent e80fbb8 commit b7b79c3
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion lib/host/gtk3/base_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -843,9 +843,49 @@ namespace cycfi { namespace elements
}
}

namespace
{
std::string exec(char const* cmd)
{
std::array<char, 128> buffer;
std::string result;
std::unique_ptr<FILE, decltype(&pclose)> pipe(popen(cmd, "r"), pclose);
if (!pipe)
throw std::runtime_error("popen() failed!");
while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr)
result += buffer.data();
return result;
}

point get_scroll_direction()
{
std::string output = exec("gsettings get org.gnome.desktop.peripherals.touchpad natural-scroll");
output.erase(remove(output.begin(), output.end(), '\n'), output.end());

if (output == "true")
return {+1.0f, +1.0f}; // Assuming positive for natural scrolling
else
return {-1.0f, -1.0f}; // Assuming negative for traditional scrolling
}
}

point scroll_direction()
{
return {+1.0f, +1.0f};
using namespace std::chrono;
static auto last_call = steady_clock::now() - seconds(10);
static point dir = get_scroll_direction(); // Initial call

// In case the user changed the scroll direction settings, we will
// call get_scroll_direction() every 10 seconds.
auto now = steady_clock::now();
if (duration_cast<seconds>(now - last_call) >= seconds(10))
{
dir = get_scroll_direction(); // Update the direction if 10 seconds have passed
last_call = now; // Update the last call time
}

return dir;
}

}}

0 comments on commit b7b79c3

Please sign in to comment.