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:
1 parent
9205e7280a
commit
12c514aab0
19 files changed
+798
-30
No files matched your search
@@ -123,3 +123,9 @@ func (modifiers ModifierKeycodes) Contains(keycode uint8) bool {
|
||||
func ShouldInterruptSpeech(event Event) bool {
|
||||
return event.Pressed
|
||||
}
|
||||
|
||||
// Automatic titles survive held-key repeats, but fresh input and explicit
|
||||
// stop keys cancel both scheduled and already queued title speech.
|
||||
func ShouldInterruptTitle(event Event) bool {
|
||||
return event.Pressed && (!event.Repeat || event.Name == "Control_L" || event.Name == "Control_R" || event.Name == "Escape")
|
||||
}
|
||||
+21
-13
@@ -24,10 +24,13 @@ const (
|
||||
)
|
||||
|
||||
type Activity struct {
|
||||
Selecting bool
|
||||
Intent Intent
|
||||
Sequence uint64
|
||||
Clipboard ClipboardAction
|
||||
// Unlike presentation intent, this counter never expires. Deferred titles
|
||||
// may be waiting for application settings after ordinary input has aged out.
|
||||
TitleInterruptionSequence uint64
|
||||
Selecting bool
|
||||
Intent Intent
|
||||
Sequence uint64
|
||||
Clipboard ClipboardAction
|
||||
}
|
||||
|
||||
type ClipboardAction uint8
|
||||
@@ -40,13 +43,14 @@ const (
|
||||
)
|
||||
|
||||
type IntentTracker struct {
|
||||
sequence uint64
|
||||
mutex sync.Mutex
|
||||
held map[string]bool
|
||||
intent Intent
|
||||
clipboard ClipboardAction
|
||||
selecting bool
|
||||
at time.Time
|
||||
titleInterruptionSequence uint64
|
||||
sequence uint64
|
||||
mutex sync.Mutex
|
||||
held map[string]bool
|
||||
intent Intent
|
||||
clipboard ClipboardAction
|
||||
selecting bool
|
||||
at time.Time
|
||||
}
|
||||
|
||||
func (tracker *IntentTracker) Observe(event Event) {
|
||||
@@ -55,6 +59,9 @@ func (tracker *IntentTracker) Observe(event Event) {
|
||||
if event.Pressed {
|
||||
tracker.sequence++
|
||||
}
|
||||
if ShouldInterruptTitle(event) {
|
||||
tracker.titleInterruptionSequence++
|
||||
}
|
||||
if tracker.held == nil {
|
||||
tracker.held = make(map[string]bool)
|
||||
}
|
||||
@@ -129,7 +136,8 @@ func (tracker *IntentTracker) RecentInput() Activity {
|
||||
tracker.mutex.Lock()
|
||||
defer tracker.mutex.Unlock()
|
||||
if time.Since(tracker.at) > time.Second {
|
||||
return Activity{}
|
||||
return Activity{TitleInterruptionSequence: tracker.titleInterruptionSequence}
|
||||
}
|
||||
return Activity{Intent: tracker.intent, Sequence: tracker.sequence, Clipboard: tracker.clipboard, Selecting: tracker.selecting}
|
||||
return Activity{Intent: tracker.intent, Sequence: tracker.sequence, Clipboard: tracker.clipboard, Selecting: tracker.selecting,
|
||||
TitleInterruptionSequence: tracker.titleInterruptionSequence}
|
||||
}
|
||||
@@ -83,3 +83,33 @@ func TestSelectionIntentEndsWithPlainNavigation(t *testing.T) {
|
||||
t.Fatalf("Right = %+v", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTitleInterruptionTracksFreshPressesAndStopKeys(t *testing.T) {
|
||||
tracker := &IntentTracker{}
|
||||
for _, step := range []struct {
|
||||
name string
|
||||
pressed bool
|
||||
repeat bool
|
||||
want uint64
|
||||
}{
|
||||
{"a", true, false, 1}, {"a", false, false, 1},
|
||||
{"a", true, true, 1}, {"Down", true, false, 2},
|
||||
{"Down", true, true, 2}, {"Control_L", true, true, 3},
|
||||
{"Control_R", true, true, 4}, {"Escape", true, true, 5},
|
||||
} {
|
||||
event := NewKeyEvent(0, step.pressed, step.name)
|
||||
event.Repeat = step.repeat
|
||||
tracker.Observe(event)
|
||||
if got := tracker.RecentInput().TitleInterruptionSequence; got != step.want {
|
||||
t.Fatalf("%+v: title interruption sequence = %d", step, got)
|
||||
}
|
||||
}
|
||||
tracker.at = time.Now().Add(-2 * time.Second)
|
||||
if got := tracker.RecentInput(); got.Intent != NoIntent || got.TitleInterruptionSequence != 5 {
|
||||
t.Fatalf("expired activity = %+v", got)
|
||||
}
|
||||
tracker.Reset()
|
||||
if got := tracker.RecentInput().TitleInterruptionSequence; got != 5 {
|
||||
t.Fatalf("reset lost interruption history: %d", got)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user