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.

This commit is contained in:
Pietro Gagliardi 2014-06-12 09:42:45 -04:00
parent b0ce712b0e
commit fc18ecc3d8
1 changed files with 13 additions and 8 deletions

View File

@ -22,7 +22,7 @@ the only recourse, and the one both Microsoft (http://support.microsoft.com/kb/1
yay. yay.
*/ */
var uitask chan *uimsg var uitask chan interface{}
type uimsg struct { type uimsg struct {
call *syscall.LazyProc call *syscall.LazyProc
@ -49,7 +49,7 @@ var (
func ui(main func()) error { func ui(main func()) error {
runtime.LockOSThread() runtime.LockOSThread()
uitask = make(chan *uimsg) uitask = make(chan interface{})
err := doWindowsInit() err := doWindowsInit()
if err != nil { if err != nil {
return fmt.Errorf("error doing general Windows initialization: %v", err) return fmt.Errorf("error doing general Windows initialization: %v", err)
@ -66,7 +66,7 @@ func ui(main func()) error {
uintptr(hwnd), uintptr(hwnd),
msgRequested, msgRequested,
uintptr(0), uintptr(0),
uintptr(unsafe.Pointer(m))) uintptr(unsafe.Pointer(&m)))
if r1 == 0 { // failure if r1 == 0 { // failure
panic("error sending message to message loop to call function: " + err.Error()) panic("error sending message to message loop to call function: " + err.Error())
} }
@ -168,12 +168,17 @@ func makeMessageHandler() (hwnd _HWND, err error) {
func messageHandlerWndProc(hwnd _HWND, uMsg uint32, wParam _WPARAM, lParam _LPARAM) _LRESULT { func messageHandlerWndProc(hwnd _HWND, uMsg uint32, wParam _WPARAM, lParam _LPARAM) _LRESULT {
switch uMsg { switch uMsg {
case msgRequested: case msgRequested:
m := (*uimsg)(unsafe.Pointer(lParam)) mt := (*interface{})(unsafe.Pointer(lParam))
switch m := (*mt).(type) {
case *uimsg:
r1, _, err := m.call.Call(m.p...) r1, _, err := m.call.Call(m.p...)
m.ret <- uiret{ m.ret <- uiret{
ret: r1, ret: r1,
err: err, err: err,
} }
case func():
m()
}
return 0 return 0
case msgQuit: case msgQuit:
// does not return a value according to MSDN // does not return a value according to MSDN