summaryrefslogtreecommitdiff
path: root/uitask_windows.go
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-04-01 15:14:57 -0400
committerPietro Gagliardi <[email protected]>2014-04-01 15:14:57 -0400
commitb2f0fe1956ae932e0630ba84a455d22e8580d5e7 (patch)
tree01fd4e8a924e85caef34c545796dd5b37fcf16ee /uitask_windows.go
parentacc0f72379b134bf293542aa1dbdf53a2e5f6a7c (diff)
Reordered each part of the Windows uitask so that it does things in the same order and with the same goroutine setup as the other platforms; this gets rid of a few channels. Also panics on more errors (gets rid of a few more channels) and removed some stray TODOs.
Diffstat (limited to 'uitask_windows.go')
-rw-r--r--uitask_windows.go53
1 files changed, 19 insertions, 34 deletions
diff --git a/uitask_windows.go b/uitask_windows.go
index 6216bc5..e536f17 100644
--- a/uitask_windows.go
+++ b/uitask_windows.go
@@ -35,6 +35,7 @@ const (
)
var (
+ _getCurrentThreadID = kernel32.NewProc("GetCurrentThreadId")
_postThreadMessage = user32.NewProc("PostThreadMessageW")
)
@@ -47,10 +48,20 @@ func ui(main func()) error {
return err
}
- threadIDReq := make(chan uintptr)
- msglooperrs := make(chan error)
- go msgloop(threadIDReq, msglooperrs)
- threadID := <-threadIDReq
+ threadID, _, _ := _getCurrentThreadID.Call()
+
+ go func() {
+ for m := range uitask {
+ r1, _, err := _postThreadMessage.Call(
+ threadID,
+ msgRequested,
+ uintptr(0),
+ uintptr(unsafe.Pointer(m)))
+ if r1 == 0 { // failure
+ panic("error sending message to message loop to call function: " + err.Error()) // TODO
+ }
+ }
+ }()
go func() {
main()
@@ -60,30 +71,11 @@ func ui(main func()) error {
uintptr(0),
uintptr(0))
if r1 == 0 { // failure
- panic("error sending quit message to message loop: " + err.Error()) // TODO
+ panic("error sending quit message to message loop: " + err.Error())
}
}()
- quit := false
- for !quit {
- select {
- case m := <-uitask:
- r1, _, err := _postThreadMessage.Call(
- threadID,
- msgRequested,
- uintptr(0),
- uintptr(unsafe.Pointer(m)))
- if r1 == 0 { // failure
- panic("error sending message to message loop to call function: " + err.Error()) // TODO
- }
- case err := <-msglooperrs:
- if err == nil { // WM_QUIT; no error
- quit = true
- } else {
- panic("unexpected return from message loop: " + err.Error()) // TODO
- }
- }
- }
+ msgloop()
doWindowsQuitStuff()
return nil
@@ -92,7 +84,6 @@ func ui(main func()) error {
var (
_dispatchMessage = user32.NewProc("DispatchMessageW")
_getMessage = user32.NewProc("GetMessageW")
- _getCurrentThreadID = kernel32.NewProc("GetCurrentThreadId")
_postQuitMessage = user32.NewProc("PostQuitMessage")
_sendMessage = user32.NewProc("SendMessageW")
_translateMessage = user32.NewProc("TranslateMessage")
@@ -100,9 +91,7 @@ var (
var getMessageFail = -1 // because Go doesn't let me
-func msgloop(threadID chan uintptr, errors chan error) {
- runtime.LockOSThread()
-
+func msgloop() {
var msg struct {
Hwnd _HWND
Message uint32
@@ -112,8 +101,6 @@ func msgloop(threadID chan uintptr, errors chan error) {
Pt _POINT
}
- r1, _, _ := _getCurrentThreadID.Call()
- threadID <- r1
for {
r1, _, err := _getMessage.Call(
uintptr(unsafe.Pointer(&msg)),
@@ -121,11 +108,9 @@ func msgloop(threadID chan uintptr, errors chan error) {
uintptr(0),
uintptr(0))
if r1 == uintptr(getMessageFail) { // error
- errors <- err
- return
+ panic("error getting message in message loop: " + err.Error())
}
if r1 == 0 { // WM_QUIT message
- errors <- nil
return
}
if msg.Message == msgRequested {