From 9f2684c26ed2478f794690c4a4e9a533381cd017 Mon Sep 17 00:00:00 2001 From: Justus Rossmeier Date: Tue, 23 Apr 2024 21:05:03 +0200 Subject: [PATCH] add click coordinates to script Allow the current relative mouse position {x} and {y} relative to the widget in percent to be used as an argument to custom scripts --- src/AModule.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/AModule.cpp b/src/AModule.cpp index c180b480..08656d72 100644 --- a/src/AModule.cpp +++ b/src/AModule.cpp @@ -1,5 +1,6 @@ #include "AModule.hpp" +#include #include #include @@ -181,7 +182,12 @@ bool AModule::handleUserEvent(GdkEventButton* const& e) { format.clear(); } if (!format.empty()) { - pid_.push_back(util::command::forkExec(format)); + const int width = gdk_window_get_width(e->window); + const int height = gdk_window_get_height(e->window); + const std::string cmd = + fmt::format(fmt::runtime(format), fmt::arg("x", (int)round(100. * e->x / width)), + fmt::arg("y", (int)round(100. * e->y / height))); + pid_.push_back(util::command::forkExec(cmd)); } dp.emit(); return true;