From 56d7a43102b53f79a2311662783d5dd94cb2f1a5 Mon Sep 17 00:00:00 2001 From: ImperishableSecret <57067794+imperishableSecret@users.noreply.github.com> Date: Thu, 30 Apr 2026 02:43:15 +0530 Subject: config/lua: expand properties in the workspace object (#14194) --- src/config/lua/objects/LuaWorkspace.cpp | 87 +++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) (limited to 'src/config/lua/objects/LuaWorkspace.cpp') diff --git a/src/config/lua/objects/LuaWorkspace.cpp b/src/config/lua/objects/LuaWorkspace.cpp index 84e4df0b..3f89b41a 100644 --- a/src/config/lua/objects/LuaWorkspace.cpp +++ b/src/config/lua/objects/LuaWorkspace.cpp @@ -1,10 +1,19 @@ #include "LuaWorkspace.hpp" #include "LuaMonitor.hpp" +#include "LuaWindow.hpp" +#include "LuaGroup.hpp" #include "LuaObjectHelpers.hpp" #include "../../../desktop/Workspace.hpp" +#include "../../../desktop/view/Group.hpp" #include "../../../helpers/Monitor.hpp" +#include "../../../layout/space/Space.hpp" +#include "../../../layout/algorithm/Algorithm.hpp" +#include "../../../layout/algorithm/TiledAlgorithm.hpp" +#include "../../../layout/supplementary/WorkspaceAlgoMatcher.hpp" +#include "../../../Compositor.hpp" +#include #include using namespace Config::Lua; @@ -32,6 +41,55 @@ static int workspaceToString(lua_State* L) { return 1; } +static int workspaceGetWindows(lua_State* L) { + auto* ref = sc(luaL_checkudata(L, 1, MT)); + const auto ws = ref->lock(); + if (!ws || ws->inert()) { + lua_newtable(L); + return 1; + } + + lua_newtable(L); + int idx = 1; + for (auto const& w : g_pCompositor->m_windows) { + if (w->m_workspace == ws) { + Objects::CLuaWindow::push(L, w); + lua_rawseti(L, -2, idx++); + } + } + return 1; +} + +static int workspaceGetGroups(lua_State* L) { + auto* ref = sc(luaL_checkudata(L, 1, MT)); + const auto ws = ref->lock(); + if (!ws || ws->inert()) { + lua_newtable(L); + return 1; + } + + lua_newtable(L); + int idx = 1; + + std::vector pushedGroups; + + for (auto const& w : g_pCompositor->m_windows) { + if (w->m_workspace != ws || !w->m_group) + continue; + + if (std::ranges::find(pushedGroups, w->m_group.get()) != pushedGroups.end()) + continue; + + pushedGroups.push_back(w->m_group.get()); + + Objects::CLuaGroup::push(L, w->m_group); + + lua_rawseti(L, -2, idx++); + } + + return 1; +} + static int workspaceIndex(lua_State* L) { auto* ref = sc(luaL_checkudata(L, 1, MT)); const auto ws = ref->lock(); @@ -70,6 +128,35 @@ static int workspaceIndex(lua_State* L) { lua_pushboolean(L, ws->m_hasFullscreenWindow); else if (key == "is_persistent") lua_pushboolean(L, ws->isPersistent()); + else if (key == "is_empty") + lua_pushboolean(L, ws->getWindows() == 0); + else if (key == "config_name") + lua_pushstring(L, ws->getConfigName().c_str()); + else if (key == "tiled_layout") { + std::string layoutName = "unknown"; + if (ws->m_space && ws->m_space->algorithm() && ws->m_space->algorithm()->tiledAlgo()) { + const auto& TILED_ALGO = ws->m_space->algorithm()->tiledAlgo(); + layoutName = Layout::Supplementary::algoMatcher()->getNameForTiledAlgo(&typeid(*TILED_ALGO.get())); + } + lua_pushstring(L, layoutName.c_str()); + } else if (key == "last_window") { + const auto lastWindow = ws->m_lastFocusedWindow.lock(); + if (lastWindow) + Objects::CLuaWindow::push(L, lastWindow); + else + lua_pushnil(L); + } else if (key == "fullscreen_window") { + const auto fsWindow = ws->getFullscreenWindow(); + if (fsWindow) + Objects::CLuaWindow::push(L, fsWindow); + else + lua_pushnil(L); + } else if (key == "get_windows") + lua_pushcfunction(L, workspaceGetWindows); + else if (key == "get_groups") + lua_pushcfunction(L, workspaceGetGroups); + else if (key == "groups") + lua_pushinteger(L, sc(ws->getGroups())); else lua_pushnil(L); -- cgit v1.2.3