Files
fenrir/internal/console/live_modifiers_linux_test.go

63 lines
1.9 KiB
Go

// Copyright (c) 2026 Storm Dragon
// SPDX-License-Identifier: GPL-3.0-or-later
//go:build linux && cgo
package console
import (
"testing"
"git.stormux.org/storm/fenrir/internal/command"
"git.stormux.org/storm/fenrir/internal/input"
)
func TestConsoleModifierUpdateWaitsForCaptureAndHeldChord(t *testing.T) {
layout, _, err := input.Load_bindings([]string{"../../config/keyboard/laptop.toml"})
if err != nil {
t.Fatal(err)
}
router, err := input.New_router(layout)
if err != nil {
t.Fatal(err)
}
if err := router.Configure_modifiers([]string{"KEY_INSERT"}, []string{"KEY_COMPOSE"}); err != nil {
t.Fatal(err)
}
if err := router.Configure_scripts([]string{"KEY_COMPOSE"}, []input.ScriptBinding{{ID: "script:example", Keys: []string{"KEY_SCRIPT", "KEY_U"}}}); err != nil {
t.Fatal(err)
}
keys := &Keyboards{router: router}
update := func(want bool) {
t.Helper()
applied, err := keys.Update_modifiers([]string{"KEY_META"}, []string{"KEY_CAPSLOCK"})
if err != nil || applied != want {
t.Fatal(applied, err)
}
}
keys.router.Capture(true)
update(false)
keys.router.Capture(false)
keys.router.Key(1, input.KeyInsert, 1, false, false)
if got := keys.router.Key(1, 23, 1, false, false); got.Command != command.CurrentLine {
t.Fatal(got)
}
update(false)
keys.router.Key(1, input.KeyInsert, 0, false, false)
update(false)
if got := keys.router.Key(1, 23, 0, false, false); got.Forward {
t.Fatal("old chord release leaked", got)
}
update(true)
keys.router.Key(1, input.KeyMeta, 1, false, false)
if got := keys.router.Key(1, 23, 1, false, false); got.Command != command.CurrentLine {
t.Fatal("new reader key failed", got)
}
keys.router.Key(1, input.KeyMeta, 0, false, false)
keys.router.Key(1, 23, 0, false, false)
keys.router.Key(1, input.KeyCapsLock, 1, false, false)
if got := keys.router.Key(1, 22, 1, false, false); got.Command != "script:example" {
t.Fatal("script binding lost", got)
}
}