Hyprland/src/managers/LayoutManager.cpp

54 lines
1.7 KiB
C++
Raw Normal View History

#include "LayoutManager.hpp"
CLayoutManager::CLayoutManager() {
m_vLayouts.emplace_back(std::make_pair<>("dwindle", &m_cDwindleLayout));
m_vLayouts.emplace_back(std::make_pair<>("master", &m_cMasterLayout));
}
IHyprLayout* CLayoutManager::getCurrentLayout() {
return m_vLayouts[m_iCurrentLayoutID].second;
2022-07-16 15:57:31 +02:00
}
void CLayoutManager::switchToLayout(std::string layout) {
for (size_t i = 0; i < m_vLayouts.size(); ++i) {
if (m_vLayouts[i].first == layout) {
2023-03-04 01:53:39 +01:00
if (i == (size_t)m_iCurrentLayoutID)
return;
2022-07-16 15:57:31 +02:00
getCurrentLayout()->onDisable();
m_iCurrentLayoutID = i;
2022-07-16 15:57:31 +02:00
getCurrentLayout()->onEnable();
return;
2022-07-16 15:57:31 +02:00
}
}
Debug::log(ERR, "Unknown layout!");
}
bool CLayoutManager::addLayout(const std::string& name, IHyprLayout* layout) {
if (std::find_if(m_vLayouts.begin(), m_vLayouts.end(), [&](const auto& other) { return other.first == name || other.second == layout; }) != m_vLayouts.end())
return false;
m_vLayouts.emplace_back(std::make_pair<>(name, layout));
Debug::log(LOG, "Added new layout {} at {:x}", name, (uintptr_t)layout);
return true;
}
bool CLayoutManager::removeLayout(IHyprLayout* layout) {
const auto IT = std::find_if(m_vLayouts.begin(), m_vLayouts.end(), [&](const auto& other) { return other.second == layout; });
if (IT == m_vLayouts.end() || IT->first == "dwindle" || IT->first == "master")
return false;
2023-06-20 21:35:54 +02:00
if (m_iCurrentLayoutID == IT - m_vLayouts.begin())
switchToLayout("dwindle");
Debug::log(LOG, "Removed a layout {} at {:x}", IT->first, (uintptr_t)layout);
std::erase(m_vLayouts, *IT);
return true;
2022-09-25 20:07:48 +02:00
}