From a084d66d7d1334b89a07d0022fa12049141cb119 Mon Sep 17 00:00:00 2001 From: johnclark456 Date: Sat, 3 Jan 2026 20:54:28 +0000 Subject: [PATCH] hyprscrolling: Allow follow_focus to honour fit_method (#571) This requries a debounce to prevent subsequent events triggering very quickly, resulting in scrolling right to the beginning or end of the row. --- hyprscrolling/README.md | 4 +++- hyprscrolling/Scrolling.cpp | 12 +++++++++++- hyprscrolling/main.cpp | 1 + 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/hyprscrolling/README.md b/hyprscrolling/README.md index 31c8338..1407c0a 100644 --- a/hyprscrolling/README.md +++ b/hyprscrolling/README.md @@ -9,6 +9,7 @@ Adds a scrolling layout to Hyprland. Make sure to set the `general:layout` to `scrolling` to use this layout. All config values can be set in your Hyprland config file, for example: + ``` plugin { hyprscrolling { @@ -25,7 +26,7 @@ plugin { | 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 | | follow_focus | when a window is focused, the layout will move to make it visible | bool | true | - +| follow_debounce_ms | time to debounce focus events for | int | 0 | ## Layout messages @@ -42,6 +43,7 @@ plugin { | togglefit | Toggle the focus_fit_method (center, fit) | none | Example key bindings for your Hyprland config: + ``` bind = $mainMod, period, layoutmsg, move +col bind = $mainMod, comma, layoutmsg, move -col diff --git a/hyprscrolling/Scrolling.cpp b/hyprscrolling/Scrolling.cpp index 0df981d..e29337a 100644 --- a/hyprscrolling/Scrolling.cpp +++ b/hyprscrolling/Scrolling.cpp @@ -4,6 +4,7 @@ #include #include +#include #include #include #include @@ -504,8 +505,17 @@ void CScrollingLayout::onEnable() { if (!DATA || !WINDOWDATA) return; - DATA->fitCol(WINDOWDATA->column.lock()); + static const auto PFOLLOW_DEBOUNCE_MS = CConfigValue("plugin:hyprscrolling:follow_debounce_ms"); + static CTimer debounceTimer; + if (debounceTimer.getMillis() < *PFOLLOW_DEBOUNCE_MS) + return; + static const auto PFITMETHOD = CConfigValue("plugin:hyprscrolling:focus_fit_method"); + if (*PFITMETHOD == 1) + DATA->fitCol(WINDOWDATA->column.lock()); + else + DATA->centerCol(WINDOWDATA->column.lock()); DATA->recalculate(); + debounceTimer.reset(); }); for (auto const& w : g_pCompositor->m_windows) { diff --git a/hyprscrolling/main.cpp b/hyprscrolling/main.cpp index 0f4f030..4f09173 100644 --- a/hyprscrolling/main.cpp +++ b/hyprscrolling/main.cpp @@ -48,6 +48,7 @@ APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) { 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:follow_focus", Hyprlang::INT{1}); + HyprlandAPI::addConfigValue(PHANDLE, "plugin:hyprscrolling:follow_debounce_ms", 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());