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
This commit is contained in:
Justus Rossmeier
2024-09-07 13:14:13 +02:00
parent 5d184f74d8
commit 9f2684c26e
+7 -1
View File
@@ -1,5 +1,6 @@
#include "AModule.hpp" #include "AModule.hpp"
#include <fmt/core.h>
#include <fmt/format.h> #include <fmt/format.h>
#include <spdlog/spdlog.h> #include <spdlog/spdlog.h>
@@ -181,7 +182,12 @@ bool AModule::handleUserEvent(GdkEventButton* const& e) {
format.clear(); format.clear();
} }
if (!format.empty()) { 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(); dp.emit();
return true; return true;