Sometimes when switching from steam to a different workspace and back only the outer window takes focus so some actions don't work. Tentative fix for that.

This commit is contained in:
Storm Dragon committed 2026-10-14 19:51:07 -04:00
1 parent 9205e7280a
commit 12c514aab0
19 files changed
+798 -30

No files matched your search

+41 -3
View File
@@ -15,6 +15,8 @@ import (
"time"
"git.stormux.org/storm/cthulhu/internal/atspi"
"git.stormux.org/storm/cthulhu/internal/input"
"git.stormux.org/storm/cthulhu/internal/platform/xorg"
)
func TestNativeAutomaticTitleDispatchLatency(t *testing.T) {
@@ -46,9 +48,22 @@ func TestNativeAutomaticTitleDispatchLatency(t *testing.T) {
t.Fatal(err)
}
defer adapter.Stop(context.Background())
listener := xorg.New()
if err = listener.Start(ctx); err != nil {
t.Fatal(err)
}
defer listener.Stop(context.Background())
queue := &fakeSpeechQueue{spoken: make(chan string, 8)}
inputDone := make(chan struct{})
go func() {
defer close(inputDone)
processInputEvents(ctx, slog.New(slog.DiscardHandler), queue, listener, input.EchoSettings{}, nil, nil)
}()
defer func() { cancel(); <-inputDone }()
completed := make(chan error, 1)
go func() { completed <- processEvents(ctx, slog.New(slog.DiscardHandler), queue, adapter, 0) }()
go func() {
completed <- processEventsWithInput(ctx, slog.New(slog.DiscardHandler), queue, adapter, nil, nil, 0, nil, listener, nil, nil)
}()
defer func() {
cancel()
if err := <-completed; err != nil {
@@ -60,9 +75,10 @@ func TestNativeAutomaticTitleDispatchLatency(t *testing.T) {
for {
select {
case got := <-queue.spoken:
if got == want {
return
if got != want {
t.Fatalf("title = %q, want %q", got, want)
}
return
case <-deadline:
t.Fatalf("title %q was not queued promptly", want)
case <-ctx.Done():
@@ -84,4 +100,26 @@ func TestNativeAutomaticTitleDispatchLatency(t *testing.T) {
wait(title, deadline)
t.Logf("X11 title update to speech queue: %s", time.Since(began))
}
// The switch chord must not suppress the destination's introduction. The
// fixture has no window manager, so activate each destination explicitly.
for _, destination := range []struct{ window, title string }{
{"unrelated", "Unrelated title"}, {"normal", "Status three"},
} {
if out, err := exec.CommandContext(ctx, "xdotool", "key", "--clearmodifiers", "alt+Tab").CombinedOutput(); err != nil {
t.Fatalf("switch keys: %v %s", err, out)
}
data, _ := json.Marshal(map[string]string{"action": "activate", "window": destination.window})
if _, err = stdin.Write(append(data, '\n')); err != nil {
t.Fatal(err)
}
if !scanner.Scan() || scanner.Text() != "ready" {
t.Fatal("fixture switch failed")
}
wait(destination.title, time.After(2*time.Second))
}
select {
case got := <-queue.spoken:
t.Fatalf("duplicate window title: %q", got)
case <-time.After(2 * windowTitleIntroductionDelay):
}
}