Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions default/hypr/input.lua
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,19 @@ hl.config({
},
})

-- Scroll nicely in the terminal.
o.window("(Alacritty|kitty)", { scroll_touchpad = 1.5 })
-- Scroll nicely in the terminal. Omarchy runs TUIs and its own terminal windows
-- under app-ids of their own (org.omarchy.agent, TUI.float, ...), which don't
-- say which terminal they run in. The title the terminal opens them with does,
-- so those windows get the speed of the terminal behind them.
local function terminal_scroll(class, initial_title, scroll_touchpad)
o.window(class, { scroll_touchpad = scroll_touchpad })
o.window(
{ class = "(org\\.omarchy\\..*|TUI\\..*)", initial_title = initial_title },
{ scroll_touchpad = scroll_touchpad }
)
end

terminal_scroll("(Alacritty|kitty)", "(Alacritty|kitty)", 1.5)
-- foot only applies its scrollback multiplier to wheel clicks, not precise touchpad scrolling.
o.window("foot", { scroll_touchpad = 2.0 })
o.window("com.mitchellh.ghostty", { scroll_touchpad = 0.2 })
terminal_scroll("(foot|org\\.codeberg\\.dnkl\\.foot)", "foot", 2.0)
terminal_scroll("com.mitchellh.ghostty", "Ghostty", 0.2)
61 changes: 61 additions & 0 deletions test/shell.d/hyprland-terminal-scroll-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/bin/bash

source "$(dirname "${BASH_SOURCE[0]}")/base-test.sh"

require_command lua

tmpdir=$(mktemp -d)
trap 'rm -rf "$tmpdir"' EXIT

# The scroll_touchpad rules input.lua registers, one per line: class, initial
# title (any title when the rule doesn't match on it), and speed.
rules=$(HOME="$tmpdir" XDG_CONFIG_HOME="$tmpdir/.config" OMARCHY_PATH="$ROOT" lua <<'LUA'
package.path = os.getenv("OMARCHY_PATH") .. "/?.lua;" .. package.path

hl = {
config = function() end,
window_rule = function(rule)
if rule.scroll_touchpad then
print(("%s\t%s\t%s"):format(rule.match.class, rule.match.initial_title or ".*", rule.scroll_touchpad))
end
end,
}

require("default.hypr.helpers")
require("default.hypr.input")
LUA
) || fail "input.lua loads" "$rules"

# Hyprland matches a pattern against the whole value, and the last matching
# rule wins.
scroll_touchpad_for() {
local class="$1" initial_title="$2"
local rule_class rule_title speed result=""

while IFS=$'\t' read -r rule_class rule_title speed; do
[[ $class =~ ^($rule_class)$ ]] || continue
[[ $initial_title =~ ^($rule_title)$ ]] || continue
result=$speed
done <<<"$rules"

printf '%s\n' "$result"
}

assert_scroll_touchpad() {
local description="$1" class="$2" initial_title="$3" expected="$4"
local actual

actual=$(scroll_touchpad_for "$class" "$initial_title")
[[ $actual == "$expected" ]] || fail "$description" "expected '$expected', got '$actual'"
pass "$description"
}

assert_scroll_touchpad "foot windows scroll at foot's speed" "foot" "foot" "2.0"
assert_scroll_touchpad "foot's other app-id scrolls at foot's speed" "org.codeberg.dnkl.foot" "foot" "2.0"
assert_scroll_touchpad "an agent window in foot scrolls at foot's speed" "org.omarchy.agent" "foot" "2.0"
assert_scroll_touchpad "a TUI in kitty scrolls at kitty's speed" "org.omarchy.btop" "kitty" "1.5"
assert_scroll_touchpad "an installed TUI in Alacritty scrolls at Alacritty's speed" "TUI.float" "Alacritty" "1.5"
assert_scroll_touchpad "an agent window in Ghostty scrolls at Ghostty's speed" "org.omarchy.agent" "Ghostty" "0.2"
assert_scroll_touchpad "Ghostty windows scroll at Ghostty's speed" "com.mitchellh.ghostty" "Ghostty" "0.2"
assert_scroll_touchpad "other apps keep the global touchpad speed" "chromium" "foot" ""
Comment thread
isc marked this conversation as resolved.
Resolved
assert_scroll_touchpad "an Omarchy window whose title only starts with a terminal's name keeps the global touchpad speed" "org.omarchy.agent" "football" ""