summaryrefslogtreecommitdiff
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
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.
-rw-r--r--todo.md3
-rw-r--r--uitask_windows.go53
2 files changed, 19 insertions, 37 deletions
diff --git a/todo.md b/todo.md
index 60ab2b8..917aa5a 100644
--- a/todo.md
+++ b/todo.md
@@ -2,8 +2,6 @@ so I don't forget:
- Window.SizeToFit() or WIndow.OptimalSize() (use: `Window.SetOptimalSize())`) for sizing a window to the control's interest
- Control.Show()/Control.Hide()
- Groupbox
-- see if we really need to track errors on a lot of places that report errors
- - it appears GTK+ and Cocoa both either don't provide a convenient way to grab errors or you're not supposed to; I assume you're supposed to just assume everything works... but on Windows we check errors for functions that return errors, and there's no guarantee that only certian errors will be returned...
- character-limited entry fields, numeric entry fields, multiline entry fields
- possible rename of LineEdit?
- especially for password fields - NewPasswordEntry()?
@@ -65,7 +63,6 @@ super ultra important things:
- the windows build appears to be unstable:
- 64-bit crashes in malloc in wine with heap corruption warnings aplenty during DLL loading; in windows 7 it works fine
- 32-bit: it works, but if I save the class name converted to UTF-16 beforehand, wine indicates that the class name is replaced with the window title, so something there is wrong...
-- handle in-library panics (internal errors) by reporting them to the user
- david wendt is telling me he's getting frequent crashes on his end with the GTK+ amd64 build...
TODO re-evaluate; I think I fixed them all ages ago now
- occasionally I get
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 {