summaryrefslogtreecommitdiff
path: root/hyprtester/plugin/src/main.cpp
diff options
context:
space:
mode:
authorVaxry <43317083+vaxerski@users.noreply.github.com>2026-04-26 15:16:36 +0100
committerGitHub <noreply@github.com>2026-04-26 15:16:36 +0100
commit5ba33f846129f3e6c0505b19f94634b24505e828 (patch)
treeaaacabe678006040c342935481a86607c66607fd /hyprtester/plugin/src/main.cpp
parent329b2b356dd92ac07f4e2aa69cbce82ee9ba9d19 (diff)
config/lua: init lua config manager, use lua if available (#13817)
Adds a new lua config manager, which will automatically be used if there is a lua config present.
Diffstat (limited to 'hyprtester/plugin/src/main.cpp')
-rw-r--r--hyprtester/plugin/src/main.cpp118
1 files changed, 91 insertions, 27 deletions
diff --git a/hyprtester/plugin/src/main.cpp b/hyprtester/plugin/src/main.cpp
index 35d2eea4..ac59119d 100644
--- a/hyprtester/plugin/src/main.cpp
+++ b/hyprtester/plugin/src/main.cpp
@@ -4,8 +4,6 @@
#include <any>
#define private public
-#include <src/config/legacy/ConfigManager.hpp>
-#include <src/config/supplementary/ConfigDescriptions.hpp>
#include <src/managers/input/InputManager.hpp>
#include <src/managers/PointerManager.hpp>
#include <src/managers/input/trackpad/TrackpadGestures.hpp>
@@ -23,6 +21,11 @@
using namespace Hyprutils::Utils;
using namespace Hyprutils::String;
+extern "C" {
+#include <lua.h>
+#include <lauxlib.h>
+}
+
#include "globals.hpp"
// Do NOT change this function.
@@ -31,18 +34,7 @@ APICALL EXPORT std::string PLUGIN_API_VERSION() {
}
static SDispatchResult test(std::string in) {
- bool success = true;
- std::string errors = "";
-
- if (Config::Legacy::mgr()->m_configValueNumber != Config::Supplementary::CONFIG_OPTIONS.size() + 1 /* autogenerated is special */) {
- errors += "config value number mismatches descriptions size\n";
- success = false;
- }
-
- return SDispatchResult{
- .success = success,
- .error = errors,
- };
+ return {.success = true};
}
// Trigger a snap move event for the active window
@@ -353,22 +345,94 @@ static SDispatchResult floatingFocusOnFullscreen(std::string in) {
return {};
}
+static int luaResult(lua_State* L, const SDispatchResult& result) {
+ if (result.success)
+ return 0;
+
+ lua_pushstring(L, result.error.empty() ? "plugin function failed" : result.error.c_str());
+ return lua_error(L);
+}
+
+static int luaTest(lua_State* L) {
+ return luaResult(L, ::test(""));
+}
+
+static int luaSnapMove(lua_State* L) {
+ return luaResult(L, ::snapMove(""));
+}
+
+static int luaVkb(lua_State* L) {
+ return luaResult(L, ::vkb(""));
+}
+
+static int luaAlt(lua_State* L) {
+ return luaResult(L, ::pressAlt(std::to_string((int)luaL_checkinteger(L, 1))));
+}
+
+static int luaGesture(lua_State* L) {
+ const auto direction = std::string{luaL_checkstring(L, 1)};
+ const auto fingers = (int)luaL_optinteger(L, 2, 3);
+ return luaResult(L, ::simulateGesture(std::format("{},{}", direction, fingers)));
+}
+
+static int luaScroll(lua_State* L) {
+ return luaResult(L, ::scroll(std::to_string((double)luaL_checknumber(L, 1))));
+}
+
+static int luaClick(lua_State* L) {
+ const auto button = (int)luaL_checkinteger(L, 1);
+ const auto pressed = (int)luaL_checkinteger(L, 2);
+ return luaResult(L, ::click(std::format("{},{}", button, pressed)));
+}
+
+static int luaKeybind(lua_State* L) {
+ const auto press = (int)luaL_checkinteger(L, 1);
+ const auto modifier = (int)luaL_checkinteger(L, 2);
+ const auto key = (int)luaL_checkinteger(L, 3);
+ return luaResult(L, ::keybind(std::format("{},{},{}", press, modifier, key)));
+}
+
+static int luaAddWindowRule(lua_State* L) {
+ return luaResult(L, ::addWindowRule(""));
+}
+
+static int luaCheckWindowRule(lua_State* L) {
+ return luaResult(L, ::checkWindowRule(""));
+}
+
+static int luaAddLayerRule(lua_State* L) {
+ return luaResult(L, ::addLayerRule(""));
+}
+
+static int luaCheckLayerRule(lua_State* L) {
+ return luaResult(L, ::checkLayerRule(""));
+}
+
+static int luaFloatingFocusOnFullscreen(lua_State* L) {
+ return luaResult(L, ::floatingFocusOnFullscreen(""));
+}
+
APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) {
PHANDLE = handle;
- HyprlandAPI::addDispatcherV2(PHANDLE, "plugin:test:test", ::test);
- HyprlandAPI::addDispatcherV2(PHANDLE, "plugin:test:snapmove", ::snapMove);
- HyprlandAPI::addDispatcherV2(PHANDLE, "plugin:test:vkb", ::vkb);
- HyprlandAPI::addDispatcherV2(PHANDLE, "plugin:test:alt", ::pressAlt);
- HyprlandAPI::addDispatcherV2(PHANDLE, "plugin:test:gesture", ::simulateGesture);
- HyprlandAPI::addDispatcherV2(PHANDLE, "plugin:test:scroll", ::scroll);
- HyprlandAPI::addDispatcherV2(PHANDLE, "plugin:test:click", ::click);
- HyprlandAPI::addDispatcherV2(PHANDLE, "plugin:test:keybind", ::keybind);
- HyprlandAPI::addDispatcherV2(PHANDLE, "plugin:test:add_window_rule", ::addWindowRule);
- HyprlandAPI::addDispatcherV2(PHANDLE, "plugin:test:check_window_rule", ::checkWindowRule);
- HyprlandAPI::addDispatcherV2(PHANDLE, "plugin:test:add_layer_rule", ::addLayerRule);
- HyprlandAPI::addDispatcherV2(PHANDLE, "plugin:test:check_layer_rule", ::checkLayerRule);
- HyprlandAPI::addDispatcherV2(PHANDLE, "plugin:test:floating_focus_on_fullscreen", ::floatingFocusOnFullscreen);
+ auto addLuaFn = [](const std::string& name, PLUGIN_LUA_FN fn) {
+ if (!HyprlandAPI::addLuaFunction(PHANDLE, "test", name, fn))
+ Log::logger->log(Log::ERR, "hyprtester plugin: failed to register hl.plugin.test.{}", name);
+ };
+
+ addLuaFn("test", ::luaTest);
+ addLuaFn("snapmove", ::luaSnapMove);
+ addLuaFn("vkb", ::luaVkb);
+ addLuaFn("alt", ::luaAlt);
+ addLuaFn("gesture", ::luaGesture);
+ addLuaFn("scroll", ::luaScroll);
+ addLuaFn("click", ::luaClick);
+ addLuaFn("keybind", ::luaKeybind);
+ addLuaFn("add_window_rule", ::luaAddWindowRule);
+ addLuaFn("check_window_rule", ::luaCheckWindowRule);
+ addLuaFn("add_layer_rule", ::luaAddLayerRule);
+ addLuaFn("check_layer_rule", ::luaCheckLayerRule);
+ addLuaFn("floating_focus_on_fullscreen", ::luaFloatingFocusOnFullscreen);
// init mouse
g_mouse = CTestMouse::create(false);