From fc18ecc3d8076ce353769dcfbf15a8a4b1600656 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Thu, 12 Jun 2014 09:42:45 -0400 Subject: [PATCH] Added the scaffolding that will allow us to change uitask on Windows to take a func(). Right now it accepts both; this will allow me to do piecewise conversion. --- uitask_windows.go | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/uitask_windows.go b/uitask_windows.go index 28e9165..f4ce50d 100644 --- a/uitask_windows.go +++ b/uitask_windows.go @@ -22,7 +22,7 @@ the only recourse, and the one both Microsoft (http://support.microsoft.com/kb/1 yay. */ -var uitask chan *uimsg +var uitask chan interface{} type uimsg struct { call *syscall.LazyProc @@ -49,7 +49,7 @@ var ( func ui(main func()) error { runtime.LockOSThread() - uitask = make(chan *uimsg) + uitask = make(chan interface{}) err := doWindowsInit() if err != nil { return fmt.Errorf("error doing general Windows initialization: %v", err) @@ -66,7 +66,7 @@ func ui(main func()) error { uintptr(hwnd), msgRequested, uintptr(0), - uintptr(unsafe.Pointer(m))) + uintptr(unsafe.Pointer(&m))) if r1 == 0 { // failure panic("error sending message to message loop to call function: " + err.Error()) } @@ -168,11 +168,16 @@ func makeMessageHandler() (hwnd _HWND, err error) { func messageHandlerWndProc(hwnd _HWND, uMsg uint32, wParam _WPARAM, lParam _LPARAM) _LRESULT { switch uMsg { case msgRequested: - m := (*uimsg)(unsafe.Pointer(lParam)) - r1, _, err := m.call.Call(m.p...) - m.ret <- uiret{ - ret: r1, - err: err, + mt := (*interface{})(unsafe.Pointer(lParam)) + switch m := (*mt).(type) { + case *uimsg: + r1, _, err := m.call.Call(m.p...) + m.ret <- uiret{ + ret: r1, + err: err, + } + case func(): + m() } return 0 case msgQuit: