scrolling: add focus_fit_method

fixes #363
This commit is contained in:
Vaxry 2025-06-08 10:36:22 +02:00
parent 66de9f58ae
commit eb42a53d17
3 changed files with 15 additions and 4 deletions

View file

@ -13,6 +13,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` |
| focus_fit_method | when a column is focused, what method to use to bring it into view. 0 - center, 1 - fit | int | 0 |
## Layout messages

View file

@ -689,6 +689,14 @@ void CScrollingLayout::fullscreenRequestForWindow(PHLWINDOW pWindow, const eFull
}
std::any CScrollingLayout::layoutMessage(SLayoutMessageHeader header, std::string message) {
static auto centerOrFit = [](const SP<SWorkspaceData> WS, const SP<SColumnData> COL) -> void {
static const auto PFITMETHOD = CConfigValue<Hyprlang::INT>("plugin:hyprscrolling:focus_fit_method");
if (*PFITMETHOD == 1)
WS->fitCol(COL);
else
WS->centerCol(COL);
};
const auto ARGS = CVarList(message, 0, ' ');
if (ARGS[0] == "move") {
const auto DATA = currentWorkspaceData();
@ -709,7 +717,7 @@ std::any CScrollingLayout::layoutMessage(SLayoutMessageHeader header, std::strin
return {};
}
DATA->centerCol(COL);
centerOrFit(DATA, COL);
DATA->recalculate();
g_pCompositor->focusWindow(COL->windowDatas.front()->window.lock());
@ -730,7 +738,8 @@ std::any CScrollingLayout::layoutMessage(SLayoutMessageHeader header, std::strin
const auto COL = DATA->prev(WDATA->column.lock());
if (!COL)
return {};
DATA->centerCol(COL);
centerOrFit(DATA, COL);
DATA->recalculate();
g_pCompositor->focusWindow(COL->windowDatas.back()->window.lock());
@ -994,7 +1003,7 @@ std::any CScrollingLayout::layoutMessage(SLayoutMessageHeader header, std::strin
PREV = WDATA->column->workspace->columns.back();
g_pCompositor->focusWindow(PREV->windowDatas.front()->window.lock());
WDATA->column->workspace->centerCol(PREV);
centerOrFit(WDATA->column->workspace.lock(), PREV);
WDATA->column->workspace->recalculate();
break;
}
@ -1005,7 +1014,7 @@ std::any CScrollingLayout::layoutMessage(SLayoutMessageHeader header, std::strin
NEXT = WDATA->column->workspace->columns.front();
g_pCompositor->focusWindow(NEXT->windowDatas.front()->window.lock());
WDATA->column->workspace->centerCol(NEXT);
centerOrFit(WDATA->column->workspace.lock(), NEXT);
WDATA->column->workspace->recalculate();
break;
}

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:focus_fit_method", Hyprlang::INT{0});
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());