workspacerules: add back on-created-empty functionality (#5452)

* workspacerules: add back on-created-empty functionality

* clang format

* workspacerules: spawn on-created-empty window while initializing CWorkspace

* clang format

* configManager: fix typo

---------

Co-authored-by: Your Name <you@example.com>
This commit is contained in:
staz 2024-04-06 19:53:32 +05:00 committed by GitHub
parent 6cea710ac8
commit 1596e2d1f7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 12 additions and 9 deletions

View file

@ -1256,8 +1256,10 @@ PHLWORKSPACE CCompositor::getWorkspaceByID(const int& id) {
void CCompositor::sanityCheckWorkspaces() { void CCompositor::sanityCheckWorkspaces() {
auto it = m_vWorkspaces.begin(); auto it = m_vWorkspaces.begin();
while (it != m_vWorkspaces.end()) { while (it != m_vWorkspaces.end()) {
const auto& WORKSPACE = *it;
// If ref == 1, only the compositor holds a ref, which means it's inactive and has no mapped windows. // If ref == 1, only the compositor holds a ref, which means it's inactive and has no mapped windows.
if (!(*it)->m_bPersistent && it->use_count() == 1) { if (!WORKSPACE->m_bPersistent && WORKSPACE.use_count() == 1) {
it = m_vWorkspaces.erase(it); it = m_vWorkspaces.erase(it);
continue; continue;
} }

View file

@ -2237,8 +2237,8 @@ std::optional<std::string> CConfigManager::handleWorkspaceRules(const std::strin
// rules = value.substr(WORKSPACE_DELIM + 1); // rules = value.substr(WORKSPACE_DELIM + 1);
// } // }
const static std::string ruleOnCreatedEmtpy = "on-created-empty:"; const static std::string ruleOnCreatedEmpty = "on-created-empty:";
const static int ruleOnCreatedEmtpyLen = ruleOnCreatedEmtpy.length(); const static int ruleOnCreatedEmptyLen = ruleOnCreatedEmpty.length();
auto assignRule = [&](std::string rule) -> std::optional<std::string> { auto assignRule = [&](std::string rule) -> std::optional<std::string> {
size_t delim = std::string::npos; size_t delim = std::string::npos;
@ -2274,8 +2274,8 @@ std::optional<std::string> CConfigManager::handleWorkspaceRules(const std::strin
wsRule.isPersistent = configStringToInt(rule.substr(delim + 11)); wsRule.isPersistent = configStringToInt(rule.substr(delim + 11));
else if ((delim = rule.find("defaultName:")) != std::string::npos) else if ((delim = rule.find("defaultName:")) != std::string::npos)
wsRule.defaultName = rule.substr(delim + 12); wsRule.defaultName = rule.substr(delim + 12);
else if ((delim = rule.find(ruleOnCreatedEmtpy)) != std::string::npos) else if ((delim = rule.find(ruleOnCreatedEmpty)) != std::string::npos)
wsRule.onCreatedEmptyRunCmd = cleanCmdForWorkspace(name, rule.substr(delim + ruleOnCreatedEmtpyLen)); wsRule.onCreatedEmptyRunCmd = cleanCmdForWorkspace(name, rule.substr(delim + ruleOnCreatedEmptyLen));
else if ((delim = rule.find("layoutopt:")) != std::string::npos) { else if ((delim = rule.find("layoutopt:")) != std::string::npos) {
std::string opt = rule.substr(delim + 10); std::string opt = rule.substr(delim + 10);
if (!opt.contains(":")) { if (!opt.contains(":")) {

View file

@ -44,6 +44,9 @@ void CWorkspace::init(PHLWORKSPACE self) {
const auto WORKSPACERULE = g_pConfigManager->getWorkspaceRuleFor(self); const auto WORKSPACERULE = g_pConfigManager->getWorkspaceRuleFor(self);
m_bPersistent = WORKSPACERULE.isPersistent; m_bPersistent = WORKSPACERULE.isPersistent;
if (auto cmd = WORKSPACERULE.onCreatedEmptyRunCmd)
g_pKeybindManager->spawn(*cmd);
g_pEventManager->postEvent({"createworkspace", m_szName}); g_pEventManager->postEvent({"createworkspace", m_szName});
g_pEventManager->postEvent({"createworkspacev2", std::format("{},{}", m_iID, m_szName)}); g_pEventManager->postEvent({"createworkspacev2", std::format("{},{}", m_iID, m_szName)});
EMIT_HOOK_EVENT("createWorkspace", this); EMIT_HOOK_EVENT("createWorkspace", this);

View file

@ -58,9 +58,6 @@ class CWorkspace {
// last monitor (used on reconnect) // last monitor (used on reconnect)
std::string m_szLastMonitor = ""; std::string m_szLastMonitor = "";
// Whether the user configured command for on-created-empty has been executed, if any
bool m_bOnCreatedEmptyExecuted = false;
bool m_bPersistent = false; bool m_bPersistent = false;
// Inert: destroyed and invalid. If this is true, release the ptr you have. // Inert: destroyed and invalid. If this is true, release the ptr you have.

View file

@ -179,6 +179,7 @@ class CKeybindManager {
friend class CCompositor; friend class CCompositor;
friend class CInputManager; friend class CInputManager;
friend class CConfigManager; friend class CConfigManager;
friend class CWorkspace;
}; };
inline std::unique_ptr<CKeybindManager> g_pKeybindManager; inline std::unique_ptr<CKeybindManager> g_pKeybindManager;