diff --git a/input.go b/input.go index 118397f40..09ee4f918 100644 --- a/input.go +++ b/input.go @@ -52,13 +52,13 @@ func IsKeyPressed(key Key) bool { var keys []driver.Key switch key { case KeyAlt: - keys = append(keys, driver.KeyLeftAlt, driver.KeyRightAlt) + keys = []driver.Key{driver.KeyLeftAlt, driver.KeyRightAlt} case KeyControl: - keys = append(keys, driver.KeyLeftControl, driver.KeyRightControl) + keys = []driver.Key{driver.KeyLeftControl, driver.KeyRightControl} case KeyShift: - keys = append(keys, driver.KeyLeftShift, driver.KeyRightShift) + keys = []driver.Key{driver.KeyLeftShift, driver.KeyRightShift} default: - keys = append(keys, driver.Key(key)) + keys = []driver.Key{driver.Key(key)} } for _, k := range keys { if uiDriver().Input().IsKeyPressed(k) { diff --git a/internal/thread/thread.go b/internal/thread/thread.go index 4c9b4e537..a8faa6d8d 100644 --- a/internal/thread/thread.go +++ b/internal/thread/thread.go @@ -20,7 +20,8 @@ import ( // Thread represents an OS thread. type Thread struct { - funcs chan func() + funcs chan func() error + results chan error } // New creates a new thread. @@ -28,7 +29,8 @@ type Thread struct { // It is assumed that the OS thread is fixed by runtime.LockOSThread when New is called. func New() *Thread { return &Thread{ - funcs: make(chan func()), + funcs: make(chan func() error), + results: make(chan error), } } @@ -40,7 +42,7 @@ loop: for { select { case f := <-t.funcs: - f() + t.results <- f() case <-context.Done(): break loop } @@ -51,12 +53,6 @@ loop: // // Do not call this from the same thread. This would block forever. func (t *Thread) Call(f func() error) error { - ch := make(chan struct{}) - var err error - t.funcs <- func() { - err = f() - close(ch) - } - <-ch - return err + t.funcs <- f + return <-t.results }