scrolling: add follow_focus

fixes #401
This commit is contained in:
Vaxry 2025-07-11 18:59:49 +02:00
parent 3eaa665afe
commit 0748c1e296
Signed by: vaxry
GPG key ID: 665806380871D640
4 changed files with 27 additions and 0 deletions

View file

@ -14,6 +14,7 @@ Adds a scrolling layout to Hyprland.
| 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 |
| follow_focus | when a window is focused, the layout will move to make it visible | bool | true |
## Layout messages

View file

@ -431,6 +431,30 @@ void CScrollingLayout::onEnable() {
}
});
m_focusCallback = g_pHookSystem->hookDynamic("activeWindow", [this](void* hk, SCallbackInfo& info, std::any param) {
const auto PWINDOW = std::any_cast<PHLWINDOW>(param);
if (!PWINDOW)
return;
static const auto PFOLLOW_FOCUS = CConfigValue<Hyprlang::INT>("plugin:hyprscrolling:follow_focus");
if (!*PFOLLOW_FOCUS)
return;
if (!PWINDOW->m_workspace->isVisible())
return;
const auto DATA = dataFor(PWINDOW->m_workspace);
const auto WINDOWDATA = dataFor(PWINDOW);
if (!DATA || !WINDOWDATA)
return;
DATA->fitCol(WINDOWDATA->column.lock());
DATA->recalculate();
});
for (auto const& w : g_pCompositor->m_windows) {
if (w->m_isFloating || !w->m_isMapped || w->isHidden())
continue;

View file

@ -103,6 +103,7 @@ class CScrollingLayout : public IHyprLayout {
std::vector<SP<SWorkspaceData>> m_workspaceDatas;
SP<HOOK_CALLBACK_FN> m_configCallback;
SP<HOOK_CALLBACK_FN> m_focusCallback;
struct {
std::vector<float> configuredWidths;

View file

@ -46,6 +46,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:follow_focus", Hyprlang::INT{1});
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());