diff options
| author | ImperishableSecret <57067794+imperishableSecret@users.noreply.github.com> | 2026-04-30 02:43:15 +0530 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-04-29 22:13:15 +0100 |
| commit | 56d7a43102b53f79a2311662783d5dd94cb2f1a5 (patch) | |
| tree | 1c1c0427245abdca295801803329fa716952ca37 /src/config/lua/objects/LuaWorkspace.cpp | |
| parent | 31e025dbe04dbe1836ea759f6b6e2ea09591fb23 (diff) | |
config/lua: expand properties in the workspace object (#14194)
Diffstat (limited to 'src/config/lua/objects/LuaWorkspace.cpp')
| -rw-r--r-- | src/config/lua/objects/LuaWorkspace.cpp | 87 |
1 files changed, 87 insertions, 0 deletions
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 <algorithm> #include <string_view> 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<PHLWORKSPACEREF*>(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<PHLWORKSPACEREF*>(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<Desktop::View::CGroup*> 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<PHLWORKSPACEREF*>(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<lua_Integer>(ws->getGroups())); else lua_pushnil(L); |
