core: fix on-empty workspace being called too often (#6026)

This commit is contained in:
Brenno Lemos 2024-05-11 20:03:32 -03:00 committed by GitHub
parent 15072831cf
commit 33a7b7bb6b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 16 additions and 12 deletions

View file

@ -2492,7 +2492,7 @@ void CCompositor::forceReportSizesToWindowsOnWorkspace(const int& wid) {
}
}
PHLWORKSPACE CCompositor::createNewWorkspace(const int& id, const int& monid, const std::string& name) {
PHLWORKSPACE CCompositor::createNewWorkspace(const int& id, const int& monid, const std::string& name, bool isEmtpy) {
const auto NAME = name == "" ? std::to_string(id) : name;
auto monID = monid;
@ -2503,7 +2503,7 @@ PHLWORKSPACE CCompositor::createNewWorkspace(const int& id, const int& monid, co
const bool SPECIAL = id >= SPECIAL_WORKSPACE_START && id <= -2;
const auto PWORKSPACE = m_vWorkspaces.emplace_back(CWorkspace::create(id, monID, NAME, SPECIAL));
const auto PWORKSPACE = m_vWorkspaces.emplace_back(CWorkspace::create(id, monID, NAME, SPECIAL, isEmtpy));
PWORKSPACE->m_fAlpha.setValueAndWarp(0);

View file

@ -164,7 +164,7 @@ class CCompositor {
void closeWindow(PHLWINDOW);
Vector2D parseWindowVectorArgsRelative(const std::string&, const Vector2D&);
void forceReportSizesToWindowsOnWorkspace(const int&);
PHLWORKSPACE createNewWorkspace(const int&, const int&, const std::string& name = ""); // will be deleted next frame if left empty and unfocused!
PHLWORKSPACE createNewWorkspace(const int&, const int&, const std::string& name = "", bool isEmtpy = true); // will be deleted next frame if left empty and unfocused!
void renameWorkspace(const int&, const std::string& name = "");
void setActiveMonitor(CMonitor*);
bool isWorkspaceSpecial(const int&);

View file

@ -2,17 +2,18 @@
#include "../Compositor.hpp"
#include "../config/ConfigValue.hpp"
PHLWORKSPACE CWorkspace::create(int id, int monitorID, std::string name, bool special) {
PHLWORKSPACE workspace = makeShared<CWorkspace>(id, monitorID, name, special);
PHLWORKSPACE CWorkspace::create(int id, int monitorID, std::string name, bool special, bool isEmtpy) {
PHLWORKSPACE workspace = makeShared<CWorkspace>(id, monitorID, name, special, isEmtpy);
workspace->init(workspace);
return workspace;
}
CWorkspace::CWorkspace(int id, int monitorID, std::string name, bool special) {
CWorkspace::CWorkspace(int id, int monitorID, std::string name, bool special, bool isEmtpy) {
m_iMonitorID = monitorID;
m_iID = id;
m_szName = name;
m_bIsSpecialWorkspace = special;
m_bWasCreatedEmtpy = isEmtpy;
}
void CWorkspace::init(PHLWORKSPACE self) {
@ -44,8 +45,9 @@ void CWorkspace::init(PHLWORKSPACE self) {
const auto WORKSPACERULE = g_pConfigManager->getWorkspaceRuleFor(self);
m_bPersistent = WORKSPACERULE.isPersistent;
if (auto cmd = WORKSPACERULE.onCreatedEmptyRunCmd)
g_pKeybindManager->spawn(*cmd);
if (self->m_bWasCreatedEmtpy)
if (auto cmd = WORKSPACERULE.onCreatedEmptyRunCmd)
g_pKeybindManager->spawn(*cmd);
g_pEventManager->postEvent({"createworkspace", m_szName});
g_pEventManager->postEvent({"createworkspacev2", std::format("{},{}", m_iID, m_szName)});

View file

@ -15,9 +15,9 @@ class CWindow;
class CWorkspace {
public:
static PHLWORKSPACE create(int id, int monitorID, std::string name, bool special = false);
static PHLWORKSPACE create(int id, int monitorID, std::string name, bool special = false, bool isEmtpy = true);
// use create() don't use this
CWorkspace(int id, int monitorID, std::string name, bool special = false);
CWorkspace(int id, int monitorID, std::string name, bool special = false, bool isEmpty = true);
~CWorkspace();
// Workspaces ID-based have IDs > 0
@ -58,6 +58,8 @@ class CWorkspace {
// last monitor (used on reconnect)
std::string m_szLastMonitor = "";
bool m_bWasCreatedEmtpy = true;
bool m_bPersistent = false;
// Inert: destroyed and invalid. If this is true, release the ptr you have.

View file

@ -1102,7 +1102,7 @@ void CKeybindManager::moveActiveToWorkspace(std::string args) {
pMonitor = g_pCompositor->getMonitorFromID(pWorkspace->m_iMonitorID);
g_pCompositor->setActiveMonitor(pMonitor);
} else {
pWorkspace = g_pCompositor->createNewWorkspace(WORKSPACEID, PWINDOW->m_iMonitorID, workspaceName);
pWorkspace = g_pCompositor->createNewWorkspace(WORKSPACEID, PWINDOW->m_iMonitorID, workspaceName, false);
pMonitor = g_pCompositor->getMonitorFromID(pWorkspace->m_iMonitorID);
g_pCompositor->moveWindowToWorkspaceSafe(PWINDOW, pWorkspace);
}
@ -1158,7 +1158,7 @@ void CKeybindManager::moveActiveToWorkspaceSilent(std::string args) {
if (pWorkspace) {
g_pCompositor->moveWindowToWorkspaceSafe(PWINDOW, pWorkspace);
} else {
pWorkspace = g_pCompositor->createNewWorkspace(WORKSPACEID, PWINDOW->m_iMonitorID, workspaceName);
pWorkspace = g_pCompositor->createNewWorkspace(WORKSPACEID, PWINDOW->m_iMonitorID, workspaceName, false);
g_pCompositor->moveWindowToWorkspaceSafe(PWINDOW, pWorkspace);
}