From 5ba33f846129f3e6c0505b19f94634b24505e828 Mon Sep 17 00:00:00 2001 From: Vaxry <43317083+vaxerski@users.noreply.github.com> Date: Sun, 26 Apr 2026 15:16:36 +0100 Subject: 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. --- src/config/lua/objects/LuaLayerSurface.cpp | 88 ++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 src/config/lua/objects/LuaLayerSurface.cpp (limited to 'src/config/lua/objects/LuaLayerSurface.cpp') diff --git a/src/config/lua/objects/LuaLayerSurface.cpp b/src/config/lua/objects/LuaLayerSurface.cpp new file mode 100644 index 00000000..99b22154 --- /dev/null +++ b/src/config/lua/objects/LuaLayerSurface.cpp @@ -0,0 +1,88 @@ +#include "LuaLayerSurface.hpp" +#include "LuaMonitor.hpp" +#include "LuaObjectHelpers.hpp" + +#include "../../../desktop/view/LayerSurface.hpp" + +#include +#include + +using namespace Config::Lua; + +static constexpr const char* MT = "HL.LayerSurface"; + +// +static int layerSurfaceEq(lua_State* L) { + const auto* lhs = sc(luaL_checkudata(L, 1, MT)); + const auto* rhs = sc(luaL_checkudata(L, 2, MT)); + + lua_pushboolean(L, lhs->lock() == rhs->lock()); + return 1; +} + +static int layerSurfaceToString(lua_State* L) { + const auto* ref = sc(luaL_checkudata(L, 1, MT)); + const auto ls = ref->lock(); + + if (!ls) + lua_pushstring(L, "HL.LayerSurface(expired)"); + else + lua_pushfstring(L, "HL.LayerSurface(%p)", ls.get()); + + return 1; +} + +static int layerSurfaceIndex(lua_State* L) { + auto* ref = sc(luaL_checkudata(L, 1, MT)); + const auto ls = ref->lock(); + if (!ls) { + Log::logger->log(Log::DEBUG, "[lua] Tried to access an expired object"); + lua_pushnil(L); + return 1; + } + + const std::string_view key = luaL_checkstring(L, 2); + + if (key == "address") + lua_pushstring(L, std::format("0x{:x}", reinterpret_cast(ls.get())).c_str()); + else if (key == "x") + lua_pushinteger(L, ls->m_geometry.x); + else if (key == "y") + lua_pushinteger(L, ls->m_geometry.y); + else if (key == "w") + lua_pushinteger(L, ls->m_geometry.width); + else if (key == "h") + lua_pushinteger(L, ls->m_geometry.height); + else if (key == "namespace") + lua_pushstring(L, ls->m_namespace.c_str()); + else if (key == "pid") + lua_pushinteger(L, sc(ls->getPID())); + else if (key == "monitor") { + const auto mon = ls->m_monitor.lock(); + if (mon) + Objects::CLuaMonitor::push(L, mon); + else + lua_pushnil(L); + } else if (key == "mapped") + lua_pushboolean(L, ls->m_mapped); + else if (key == "layer") + lua_pushinteger(L, sc(ls->m_layer)); + else if (key == "interactivity") + lua_pushinteger(L, sc(ls->m_interactivity)); + else if (key == "above_fullscreen") + lua_pushboolean(L, ls->m_aboveFullscreen); + else + lua_pushnil(L); + + return 1; +} + +void Objects::CLuaLayerSurface::setup(lua_State* L) { + registerMetatable(L, MT, layerSurfaceIndex, gcRef, layerSurfaceEq, layerSurfaceToString); +} + +void Objects::CLuaLayerSurface::push(lua_State* L, PHLLS ls) { + new (lua_newuserdata(L, sizeof(PHLLSREF))) PHLLSREF(ls ? ls->m_self : nullptr); + luaL_getmetatable(L, MT); + lua_setmetatable(L, -2); +} -- cgit v1.2.3