2022-03-19 15:59:53 +01:00
|
|
|
#include "LayoutManager.hpp"
|
|
|
|
|
2023-02-27 13:32:38 +01:00
|
|
|
CLayoutManager::CLayoutManager() {
|
|
|
|
m_vLayouts.emplace_back(std::make_pair<>("dwindle", &m_cDwindleLayout));
|
|
|
|
m_vLayouts.emplace_back(std::make_pair<>("master", &m_cMasterLayout));
|
|
|
|
}
|
2022-03-19 15:59:53 +01:00
|
|
|
|
2023-02-27 13:32:38 +01:00
|
|
|
IHyprLayout* CLayoutManager::getCurrentLayout() {
|
|
|
|
return m_vLayouts[m_iCurrentLayoutID].second;
|
2022-07-16 15:57:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CLayoutManager::switchToLayout(std::string layout) {
|
2023-02-27 13:32:38 +01:00
|
|
|
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)
|
2023-03-03 15:06:01 +01:00
|
|
|
return;
|
|
|
|
|
2022-07-16 15:57:31 +02:00
|
|
|
getCurrentLayout()->onDisable();
|
2023-02-27 13:32:38 +01:00
|
|
|
m_iCurrentLayoutID = i;
|
2022-07-16 15:57:31 +02:00
|
|
|
getCurrentLayout()->onEnable();
|
2023-02-27 13:32:38 +01:00
|
|
|
return;
|
2022-07-16 15:57:31 +02:00
|
|
|
}
|
|
|
|
}
|
2023-02-27 13:32:38 +01: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));
|
|
|
|
|
2023-09-06 21:45:37 +02:00
|
|
|
Debug::log(LOG, "Added new layout {} at {:x}", name, (uintptr_t)layout);
|
2023-02-27 13:32:38 +01:00
|
|
|
|
|
|
|
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())
|
2023-02-27 13:32:38 +01:00
|
|
|
switchToLayout("dwindle");
|
|
|
|
|
2023-09-06 21:45:37 +02:00
|
|
|
Debug::log(LOG, "Removed a layout {} at {:x}", IT->first, (uintptr_t)layout);
|
2023-02-27 13:32:38 +01:00
|
|
|
|
|
|
|
std::erase(m_vLayouts, *IT);
|
|
|
|
|
|
|
|
return true;
|
2022-09-25 20:07:48 +02:00
|
|
|
}
|