Skip to content

Commit

Permalink
Skip FocusOut exit if focus was lost quickly after start (#8)
Browse files Browse the repository at this point in the history
* Skip FocusOut exit if focus was lost quickly after start

* Change startTime to Time object

* Remove TODO comment

* Fix formatting to follow gofmt styling
  • Loading branch information
Zachu committed Nov 1, 2022
1 parent 9c67a6d commit a081ee0
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ type engine struct {
history *history
historyPrefix string
historyIndex uint32

startTime time.Time
}

func (e *engine) exit() {
Expand Down Expand Up @@ -371,8 +373,12 @@ func (e *engine) FocusIn() *dbus.Error {
func (e *engine) FocusOut() *dbus.Error {
log.Printf("FocusOut()")

e.clearText()
e.exit()
if time.Since(e.startTime) < 250*time.Millisecond {
log.Printf("FocusOut was quickly after starting. Skipping exit")
} else {
e.clearText()
e.exit()
}

return nil
}
Expand Down Expand Up @@ -419,6 +425,8 @@ func (e *engine) CandidateClicked(index uint32, button uint32, state uint32) *db
func (e *engine) Enable() *dbus.Error {
log.Printf("Enable()")

e.startTime = time.Now()

return nil
}

Expand Down

0 comments on commit a081ee0

Please sign in to comment.