summaryrefslogtreecommitdiff
path: root/src/config/lua/objects/LuaGroup.cpp
diff options
context:
space:
mode:
authorImperishableSecret <57067794+imperishableSecret@users.noreply.github.com>2026-04-30 02:43:15 +0530
committerGitHub <noreply@github.com>2026-04-29 22:13:15 +0100
commit56d7a43102b53f79a2311662783d5dd94cb2f1a5 (patch)
tree1c1c0427245abdca295801803329fa716952ca37 /src/config/lua/objects/LuaGroup.cpp
parent31e025dbe04dbe1836ea759f6b6e2ea09591fb23 (diff)
config/lua: expand properties in the workspace object (#14194)
Diffstat (limited to 'src/config/lua/objects/LuaGroup.cpp')
-rw-r--r--src/config/lua/objects/LuaGroup.cpp83
1 files changed, 83 insertions, 0 deletions
diff --git a/src/config/lua/objects/LuaGroup.cpp b/src/config/lua/objects/LuaGroup.cpp
new file mode 100644
index 00000000..551f8a91
--- /dev/null
+++ b/src/config/lua/objects/LuaGroup.cpp
@@ -0,0 +1,83 @@
+#include "LuaGroup.hpp"
+#include "LuaWindow.hpp"
+#include "LuaObjectHelpers.hpp"
+
+#include "../../../desktop/view/Group.hpp"
+
+#include <string_view>
+
+using namespace Config::Lua;
+
+static constexpr const char* MT = "HL.Group";
+
+static int groupEq(lua_State* L) {
+ const auto* lhs = sc<WP<Desktop::View::CGroup>*>(luaL_checkudata(L, 1, MT));
+ const auto* rhs = sc<WP<Desktop::View::CGroup>*>(luaL_checkudata(L, 2, MT));
+
+ lua_pushboolean(L, lhs->lock() == rhs->lock());
+ return 1;
+}
+
+static int groupToString(lua_State* L) {
+ const auto* ref = sc<WP<Desktop::View::CGroup>*>(luaL_checkudata(L, 1, MT));
+ const auto group = ref->lock();
+
+ if (!group)
+ lua_pushstring(L, "HL.Group(expired)");
+ else
+ lua_pushfstring(L, "HL.Group(%p)", group.get());
+
+ return 1;
+}
+
+static int groupIndex(lua_State* L) {
+ auto* ref = sc<WP<Desktop::View::CGroup>*>(luaL_checkudata(L, 1, MT));
+ const auto group = ref->lock();
+ if (!group) {
+ 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 == "locked")
+ lua_pushboolean(L, group->locked());
+ else if (key == "denied")
+ lua_pushboolean(L, group->denied());
+ else if (key == "size")
+ lua_pushinteger(L, sc<lua_Integer>(group->size()));
+ else if (key == "current_index")
+ lua_pushinteger(L, sc<lua_Integer>(group->getCurrentIdx()) + 1);
+ else if (key == "current") {
+ const auto current = group->current();
+ if (current)
+ Objects::CLuaWindow::push(L, current);
+ else
+ lua_pushnil(L);
+ } else if (key == "members") {
+ lua_newtable(L);
+ int i = 1;
+ for (const auto& grouped : group->windows()) {
+ const auto groupedWindow = grouped.lock();
+ if (!groupedWindow)
+ continue;
+
+ Objects::CLuaWindow::push(L, groupedWindow);
+ lua_rawseti(L, -2, i++);
+ }
+ } else
+ lua_pushnil(L);
+
+ return 1;
+}
+
+void Objects::CLuaGroup::setup(lua_State* L) {
+ registerMetatable(L, MT, groupIndex, gcRef<WP<Desktop::View::CGroup>>, groupEq, groupToString);
+}
+
+void Objects::CLuaGroup::push(lua_State* L, SP<Desktop::View::CGroup> group) {
+ new (lua_newuserdata(L, sizeof(WP<Desktop::View::CGroup>))) WP<Desktop::View::CGroup>(group);
+ luaL_getmetatable(L, MT);
+ lua_setmetatable(L, -2);
+}