diff options
| author | Pietro Gagliardi <[email protected]> | 2014-06-28 10:49:23 -0400 |
|---|---|---|
| committer | Pietro Gagliardi <[email protected]> | 2014-06-28 10:49:23 -0400 |
| commit | 98e701cd3bb0123477af97927e4bb2a456a2301d (patch) | |
| tree | badcb6f5f91a48cd58b24fba5f99f1ad5c9f3efe | |
| parent | f7438c0e10d3552b17a28bf955a9aea220955284 (diff) | |
Migrated uitask_windows.go to the new API.
| -rw-r--r-- | init.go | 1 | ||||
| -rw-r--r-- | uitask_windows.go | 48 |
2 files changed, 26 insertions, 23 deletions
@@ -24,6 +24,7 @@ func Go() error { Ready <- struct{}{} close(Ready) ui() + return nil } // Ready is pulsed when Go() is ready to begin accepting requests to the safe methods. diff --git a/uitask_windows.go b/uitask_windows.go index 1075b5b..1eb44f4 100644 --- a/uitask_windows.go +++ b/uitask_windows.go @@ -46,10 +46,7 @@ var ( _postMessage = user32.NewProc("PostMessageW") ) -func ui(main func()) error { - runtime.LockOSThread() - - uitask = make(chan interface{}) +func uiinit() error { err := doWindowsInit() if err != nil { return fmt.Errorf("error doing general Windows initialization: %v", err) @@ -60,33 +57,38 @@ func ui(main func()) error { return fmt.Errorf("error making invisible window for handling events: %v", err) } + // do this only on success just to be safe + uitask = make(chan interface{}) + return nil +} + +func ui() { go func() { - for m := range uitask { - r1, _, err := _postMessage.Call( + for { + select { + case m := <-uitask: + r1, _, err := _postMessage.Call( + uintptr(hwnd), + msgRequested, + uintptr(0), + uintptr(unsafe.Pointer(&m))) + if r1 == 0 { // failure + panic("error sending message to message loop to call function: " + err.Error()) + } + case <-Stop: + r1, _, err := _postMessage.Call( uintptr(hwnd), - msgRequested, + msgQuit, uintptr(0), - uintptr(unsafe.Pointer(&m))) - if r1 == 0 { // failure - panic("error sending message to message loop to call function: " + err.Error()) + uintptr(0)) + if r1 == 0 { // failure + panic("error sending quit message to message loop: " + err.Error()) + } } } }() - go func() { - main() - r1, _, err := _postMessage.Call( - uintptr(hwnd), - msgQuit, - uintptr(0), - uintptr(0)) - if r1 == 0 { // failure - panic("error sending quit message to message loop: " + err.Error()) - } - }() - msgloop() - return nil } var ( |
