layout: rethonk layouts from the ground up (#12890)

Rewrites layouts to be much smaller, and deal with much less annoying
BS. Improves the overall architecture, unifies handling of pseudotiling,
and various other improvements.
This commit is contained in:
Vaxry 2026-02-21 21:30:39 +00:00 committed by GitHub
parent 51f8849e54
commit 723870337f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
82 changed files with 8431 additions and 5527 deletions

View file

@ -3,10 +3,11 @@
#include "../debug/HyprCtl.hpp"
#include "../plugins/PluginSystem.hpp"
#include "../managers/HookSystemManager.hpp"
#include "../managers/LayoutManager.hpp"
#include "../managers/eventLoop/EventLoopManager.hpp"
#include "../config/ConfigManager.hpp"
#include "../debug/HyprNotificationOverlay.hpp"
#include "../layout/target/Target.hpp"
#include "../layout/supplementary/WorkspaceAlgoMatcher.hpp"
#include <dlfcn.h>
#include <filesystem>
@ -62,25 +63,44 @@ APICALL std::string HyprlandAPI::invokeHyprctlCommand(const std::string& call, c
}
APICALL bool HyprlandAPI::addLayout(HANDLE handle, const std::string& name, IHyprLayout* layout) {
auto* const PLUGIN = g_pPluginSystem->getPluginByHandle(handle);
if (!PLUGIN)
return false;
PLUGIN->m_registeredLayouts.push_back(layout);
return g_pLayoutManager->addLayout(name, layout);
return false;
}
APICALL bool HyprlandAPI::removeLayout(HANDLE handle, IHyprLayout* layout) {
return false;
}
APICALL bool HyprlandAPI::addTiledAlgo(HANDLE handle, const std::string& name, const std::type_info* typeInfo, std::function<UP<Layout::ITiledAlgorithm>()>&& factory) {
auto* const PLUGIN = g_pPluginSystem->getPluginByHandle(handle);
if (!PLUGIN)
return false;
std::erase(PLUGIN->m_registeredLayouts, layout);
PLUGIN->m_registeredAlgos.emplace_back(name);
return g_pLayoutManager->removeLayout(layout);
return Layout::Supplementary::algoMatcher()->registerTiledAlgo(name, typeInfo, std::move(factory));
}
APICALL bool HyprlandAPI::addFloatingAlgo(HANDLE handle, const std::string& name, const std::type_info* typeInfo, std::function<UP<Layout::IFloatingAlgorithm>()>&& factory) {
auto* const PLUGIN = g_pPluginSystem->getPluginByHandle(handle);
if (!PLUGIN)
return false;
PLUGIN->m_registeredAlgos.emplace_back(name);
return Layout::Supplementary::algoMatcher()->registerFloatingAlgo(name, typeInfo, std::move(factory));
}
APICALL bool HyprlandAPI::removeAlgo(HANDLE handle, const std::string& name) {
auto* const PLUGIN = g_pPluginSystem->getPluginByHandle(handle);
if (!PLUGIN)
return false;
std::erase(PLUGIN->m_registeredAlgos, name);
return Layout::Supplementary::algoMatcher()->unregisterAlgo(name);
}
APICALL bool HyprlandAPI::reloadConfig() {
@ -130,7 +150,7 @@ APICALL bool HyprlandAPI::addWindowDecoration(HANDLE handle, PHLWINDOW pWindow,
pWindow->addWindowDeco(std::move(pDecoration));
g_pLayoutManager->getCurrentLayout()->recalculateWindow(pWindow);
pWindow->layoutTarget()->recalc();
return true;
}

View file

@ -71,6 +71,11 @@ class IHyprLayout;
class IHyprWindowDecoration;
struct SConfigValue;
namespace Layout {
class ITiledAlgorithm;
class IFloatingAlgorithm;
};
/*
These methods are for the plugin to implement
Methods marked with REQUIRED are required.
@ -172,15 +177,26 @@ namespace HyprlandAPI {
Adds a layout to Hyprland.
returns: true on success. False otherwise.
deprecated: addTiledAlgo, addFloatingAlgo
*/
APICALL bool addLayout(HANDLE handle, const std::string& name, IHyprLayout* layout);
APICALL [[deprecated]] bool addLayout(HANDLE handle, const std::string& name, IHyprLayout* layout);
/*
Removes an added layout from Hyprland.
returns: true on success. False otherwise.
deprecated: V2 removeAlgo
*/
APICALL bool removeLayout(HANDLE handle, IHyprLayout* layout);
APICALL [[deprecated]] bool removeLayout(HANDLE handle, IHyprLayout* layout);
/*
Algorithm fns. Used for registering and removing. Return success.
*/
APICALL bool addTiledAlgo(HANDLE handle, const std::string& name, const std::type_info* typeInfo, std::function<UP<Layout::ITiledAlgorithm>()>&& factory);
APICALL bool addFloatingAlgo(HANDLE handle, const std::string& name, const std::type_info* typeInfo, std::function<UP<Layout::IFloatingAlgorithm>()>&& factory);
APICALL bool removeAlgo(HANDLE handle, const std::string& name);
/*
Queues a config reload. Does not take effect immediately.

View file

@ -4,11 +4,11 @@
#include <ranges>
#include "../config/ConfigManager.hpp"
#include "../debug/HyprCtl.hpp"
#include "../managers/LayoutManager.hpp"
#include "../managers/HookSystemManager.hpp"
#include "../managers/eventLoop/EventLoopManager.hpp"
#include "../managers/permissions/DynamicPermissionManager.hpp"
#include "../debug/HyprNotificationOverlay.hpp"
#include "../layout/supplementary/WorkspaceAlgoMatcher.hpp"
#include "../i18n/Engine.hpp"
CPluginSystem::CPluginSystem() {
@ -156,9 +156,9 @@ void CPluginSystem::unloadPlugin(const CPlugin* plugin, bool eject) {
g_pHookSystem->unhook(SHP);
}
const auto ls = plugin->m_registeredLayouts;
for (auto const& l : ls)
g_pLayoutManager->removeLayout(l);
for (const auto& l : plugin->m_registeredAlgos) {
Layout::Supplementary::algoMatcher()->unregisterAlgo(l);
}
g_pFunctionHookSystem->removeAllHooksFrom(plugin->m_handle);

View file

@ -23,11 +23,11 @@ class CPlugin {
HANDLE m_handle = nullptr;
std::vector<IHyprLayout*> m_registeredLayouts;
std::vector<IHyprWindowDecoration*> m_registeredDecorations;
std::vector<std::pair<std::string, WP<HOOK_CALLBACK_FN>>> m_registeredCallbacks;
std::vector<std::string> m_registeredDispatchers;
std::vector<WP<SHyprCtlCommand>> m_registeredHyprctlCommands;
std::vector<std::string> m_registeredAlgos;
};
class CPluginSystem {