diff --git a/hyprscrolling/README.md b/hyprscrolling/README.md index 49bbae0..e3de826 100644 --- a/hyprscrolling/README.md +++ b/hyprscrolling/README.md @@ -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 diff --git a/hyprscrolling/Scrolling.cpp b/hyprscrolling/Scrolling.cpp index e73c248..2c4ebc2 100644 --- a/hyprscrolling/Scrolling.cpp +++ b/hyprscrolling/Scrolling.cpp @@ -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 WS, const SP COL) -> void { + static const auto PFITMETHOD = CConfigValue("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; } diff --git a/hyprscrolling/main.cpp b/hyprscrolling/main.cpp index 2e23d89..d1d88e6 100644 --- a/hyprscrolling/main.cpp +++ b/hyprscrolling/main.cpp @@ -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());