hyprscrolling: add preconfigured widths for resize

ref #348
This commit is contained in:
Vaxry 2025-05-18 21:18:38 +02:00
parent f7665af850
commit 4dea1029e8
Signed by: vaxry
GPG key ID: 665806380871D640
4 changed files with 62 additions and 5 deletions

View file

@ -12,6 +12,7 @@ Adds a scrolling layout to Hyprland.
| -- | -- | -- | -- |
| fullscreen_on_one_column | if there's only one column, should it be fullscreen | bool | false |
| column_width | default column width as a fraction of the monitor width | float [0 - 1] | 0.5 |
| explicit_column_widths | a comma-separated list of widths for columns to be used with `+conf` or `-conf` | string | `0.333, 0.5, 0.667, 1.0` |
## Layout messages
@ -19,5 +20,5 @@ Adds a scrolling layout to Hyprland.
| name | description | params |
| --- | --- | --- |
| move | move the layout horizontally, by either a relative logical px (`-200`, `+200`) or columns (`+col`, `-col`) | move data |
| colresize | resize the current column, to either a value or by a relative value e.g. `0.5`, `+0.2`, `-0.2` | relative float |
| colresize | resize the current column, to either a value or by a relative value e.g. `0.5`, `+0.2`, `-0.2` or cycle the preconfigured ones with `+conf` or `-conf` | relative float / relative conf |
| movewindowto | same as the movewindow dispatcher but supports promotion to the right at the end | direction |

View file

@ -5,6 +5,9 @@
#include <hyprland/src/config/ConfigValue.hpp>
#include <hyprland/src/render/Renderer.hpp>
#include <hyprutils/string/ConstVarList.hpp>
using namespace Hyprutils::String;
constexpr float MIN_COLUMN_WIDTH = 0.05F;
constexpr float MAX_COLUMN_WIDTH = 1.F;
constexpr float MIN_ROW_HEIGHT = 0.1F;
@ -336,6 +339,20 @@ void CScrollingLayout::applyNodeDataToWindow(SP<SScrollingWindowData> data, bool
}
void CScrollingLayout::onEnable() {
static const auto PCONFWIDTHS = CConfigValue<Hyprlang::STRING>("plugin:hyprscrolling:explicit_column_widths");
m_configCallback = g_pHookSystem->hookDynamic("configReloaded", [this](void* hk, SCallbackInfo& info, std::any param) {
// bitch ass
m_config.configuredWidths.clear();
CConstVarList widths(*PCONFWIDTHS, 0, ',');
for (auto& w : widths) {
try {
m_config.configuredWidths.emplace_back(std::stof(std::string{w}));
} catch (...) { Debug::log(ERR, "scrolling: Failed to parse width {} as float", w); }
}
});
for (auto const& w : g_pCompositor->m_windows) {
if (w->m_isFloating || !w->m_isMapped || w->isHidden())
continue;
@ -346,6 +363,7 @@ void CScrollingLayout::onEnable() {
void CScrollingLayout::onDisable() {
m_workspaceDatas.clear();
m_configCallback.reset();
}
void CScrollingLayout::onWindowCreatedTiling(PHLWINDOW window, eDirection direction) {
@ -592,6 +610,36 @@ std::any CScrollingLayout::layoutMessage(SLayoutMessageHeader header, std::strin
return {};
if (ARGS[1][0] == '+' || ARGS[1][0] == '-') {
if (ARGS[1] == "+conf") {
for (size_t i = 0; i < m_config.configuredWidths.size(); ++i) {
if (m_config.configuredWidths[i] < WDATA->column->columnWidth)
continue;
if (i == m_config.configuredWidths.size() - 1)
WDATA->column->columnWidth = m_config.configuredWidths[0];
else
WDATA->column->columnWidth = m_config.configuredWidths[i + 1];
break;
}
return {};
} else if (ARGS[1] == "-conf") {
for (size_t i = m_config.configuredWidths.size() - 1; i >= 0; --i) {
if (m_config.configuredWidths[i] > WDATA->column->columnWidth)
continue;
if (i == 0)
WDATA->column->columnWidth = m_config.configuredWidths[m_config.configuredWidths.size() - 1];
else
WDATA->column->columnWidth = m_config.configuredWidths[i - 1];
break;
}
return {};
}
const auto PLUSMINUS = getPlusMinusKeywordResult(ARGS[1], 0);
if (!PLUSMINUS.has_value())

View file

@ -3,6 +3,7 @@
#include <vector>
#include <hyprland/src/layout/IHyprLayout.hpp>
#include <hyprland/src/helpers/memory/Memory.hpp>
#include <hyprland/src/managers/HookSystemManager.hpp>
class CScrollingLayout;
struct SColumnData;
@ -94,11 +95,17 @@ class CScrollingLayout : public IHyprLayout {
private:
std::vector<SP<SWorkspaceData>> m_workspaceDatas;
SP<SWorkspaceData> dataFor(PHLWORKSPACE ws);
SP<SScrollingWindowData> dataFor(PHLWINDOW w);
SP<SWorkspaceData> currentWorkspaceData();
SP<HOOK_CALLBACK_FN> m_configCallback;
void applyNodeDataToWindow(SP<SScrollingWindowData> node, bool force);
struct {
std::vector<float> configuredWidths;
} m_config;
SP<SWorkspaceData> dataFor(PHLWORKSPACE ws);
SP<SScrollingWindowData> dataFor(PHLWINDOW w);
SP<SWorkspaceData> currentWorkspaceData();
void applyNodeDataToWindow(SP<SScrollingWindowData> node, bool force);
friend struct SWorkspaceData;
};

View file

@ -45,6 +45,7 @@ APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) {
HyprlandAPI::addConfigValue(PHANDLE, "plugin:hyprscrolling:fullscreen_on_one_column", Hyprlang::INT{0});
HyprlandAPI::addConfigValue(PHANDLE, "plugin:hyprscrolling:column_width", Hyprlang::FLOAT{0.5F});
HyprlandAPI::addConfigValue(PHANDLE, "plugin:hyprscrolling:explicit_column_widths", Hyprlang::STRING{"0.333, 0.5, 0.667, 1.0"});
HyprlandAPI::addLayout(PHANDLE, "scrolling", g_pScrollingLayout.get());
if (success) HyprlandAPI::addNotification(PHANDLE, "[hyprscrolling] Initialized successfully!", CHyprColor{0.2, 1.0, 0.2, 1.0}, 5000);