mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 15:45:38 +00:00
380f96b3fc
Before this change, every Event would be passed to the focused InputOp tag, making it impossible to implement, say, program-wide shortcuts. This change implements key.Event routing similar to how pointer.Events are routed: every InputOp describes the set of keys it can handle, and the router use that information to deliver an Event to the matching handler. This is an API change, because every InputOp must now include a filter matching the keys it wants to handle. Fixes: https://todo.sr.ht/~eliasnaur/gio/395 Signed-off-by: Elias Naur <mail@eliasnaur.com>
36 lines
1.1 KiB
Go
36 lines
1.1 KiB
Go
// SPDX-License-Identifier: Unlicense OR MIT
|
|
|
|
package key
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestKeySet(t *testing.T) {
|
|
const allMods = ModAlt | ModShift | ModSuper | ModCtrl | ModCommand
|
|
tests := []struct {
|
|
Set Set
|
|
Matches []Event
|
|
Mismatches []Event
|
|
}{
|
|
{"A", []Event{{Name: "A"}}, []Event{{Name: "A", Modifiers: ModShift}}},
|
|
{"[A,B,C]", []Event{{Name: "A"}, {Name: "B"}}, []Event{}},
|
|
{"Short-A", []Event{{Name: "A", Modifiers: ModShortcut}}, []Event{{Name: "A", Modifiers: ModShift}}},
|
|
{"(Ctrl)-A", []Event{{Name: "A", Modifiers: ModCtrl}, {Name: "A"}}, []Event{{Name: "A", Modifiers: ModShift}}},
|
|
{"Shift-[A,B,C]", []Event{{Name: "A", Modifiers: ModShift}}, []Event{{Name: "B", Modifiers: ModShift | ModCtrl}}},
|
|
{Set(allMods.String() + "-A"), []Event{{Name: "A", Modifiers: allMods}}, []Event{}},
|
|
}
|
|
for _, tst := range tests {
|
|
for _, e := range tst.Matches {
|
|
if !tst.Set.Contains(e.Name, e.Modifiers) {
|
|
t.Errorf("key set %q didn't contain %+v", tst.Set, e)
|
|
}
|
|
}
|
|
for _, e := range tst.Mismatches {
|
|
if tst.Set.Contains(e.Name, e.Modifiers) {
|
|
t.Errorf("key set %q contains %+v", tst.Set, e)
|
|
}
|
|
}
|
|
}
|
|
}
|