Partial go fmt. Will do the rest over the next few commits. While I'm not too happy about it, everyone else uses go fmt, and pull requests will be more convenient if I just do it. (Also do it now, because when I change the Windows backend things are going to change...)
This commit is contained in:
parent
7b2e6b7fa3
commit
43b3f1c2a8
|
@ -54,6 +54,6 @@ func initCocoa() (err error) {
|
||||||
|
|
||||||
//export appDelegate_uitask
|
//export appDelegate_uitask
|
||||||
func appDelegate_uitask(p unsafe.Pointer) {
|
func appDelegate_uitask(p unsafe.Pointer) {
|
||||||
f := (*func ())(unsafe.Pointer(p))
|
f := (*func())(unsafe.Pointer(p))
|
||||||
(*f)()
|
(*f)()
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,8 +30,8 @@ func ui(main func()) error {
|
||||||
for f := range uitask {
|
for f := range uitask {
|
||||||
done := make(chan struct{})
|
done := make(chan struct{})
|
||||||
gdk_threads_add_idle(>kIdleOp{
|
gdk_threads_add_idle(>kIdleOp{
|
||||||
what: f,
|
what: f,
|
||||||
done: done,
|
done: done,
|
||||||
})
|
})
|
||||||
<-done
|
<-done
|
||||||
close(done)
|
close(done)
|
||||||
|
|
|
@ -4,9 +4,9 @@ package ui
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"runtime"
|
||||||
"syscall"
|
"syscall"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
"runtime"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -25,18 +25,18 @@ yay.
|
||||||
var uitask chan *uimsg
|
var uitask chan *uimsg
|
||||||
|
|
||||||
type uimsg struct {
|
type uimsg struct {
|
||||||
call *syscall.LazyProc
|
call *syscall.LazyProc
|
||||||
p []uintptr
|
p []uintptr
|
||||||
ret chan uiret
|
ret chan uiret
|
||||||
}
|
}
|
||||||
|
|
||||||
type uiret struct {
|
type uiret struct {
|
||||||
ret uintptr
|
ret uintptr
|
||||||
err error
|
err error
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
msgRequested = _WM_APP + iota + 1 // + 1 just to be safe
|
msgRequested = _WM_APP + iota + 1 // + 1 just to be safe
|
||||||
msgQuit
|
msgQuit
|
||||||
msgSetAreaSize
|
msgSetAreaSize
|
||||||
msgRepaintAll
|
msgRepaintAll
|
||||||
|
@ -67,7 +67,7 @@ func ui(main func()) error {
|
||||||
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())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -80,7 +80,7 @@ func ui(main func()) error {
|
||||||
msgQuit,
|
msgQuit,
|
||||||
uintptr(0),
|
uintptr(0),
|
||||||
uintptr(0))
|
uintptr(0))
|
||||||
if r1 == 0 { // failure
|
if r1 == 0 { // failure
|
||||||
panic("error sending quit message to message loop: " + err.Error())
|
panic("error sending quit message to message loop: " + err.Error())
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
@ -90,21 +90,21 @@ func ui(main func()) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
_dispatchMessage = user32.NewProc("DispatchMessageW")
|
_dispatchMessage = user32.NewProc("DispatchMessageW")
|
||||||
_getMessage = user32.NewProc("GetMessageW")
|
_getMessage = user32.NewProc("GetMessageW")
|
||||||
_postQuitMessage = user32.NewProc("PostQuitMessage")
|
_postQuitMessage = user32.NewProc("PostQuitMessage")
|
||||||
_sendMessage = user32.NewProc("SendMessageW")
|
_sendMessage = user32.NewProc("SendMessageW")
|
||||||
_translateMessage = user32.NewProc("TranslateMessage")
|
_translateMessage = user32.NewProc("TranslateMessage")
|
||||||
)
|
)
|
||||||
|
|
||||||
func msgloop() {
|
func msgloop() {
|
||||||
var msg struct {
|
var msg struct {
|
||||||
hwnd _HWND
|
hwnd _HWND
|
||||||
message uint32
|
message uint32
|
||||||
wParam _WPARAM
|
wParam _WPARAM
|
||||||
lParam _LPARAM
|
lParam _LPARAM
|
||||||
time uint32
|
time uint32
|
||||||
pt _POINT
|
pt _POINT
|
||||||
}
|
}
|
||||||
|
|
||||||
for {
|
for {
|
||||||
|
@ -113,10 +113,10 @@ func msgloop() {
|
||||||
uintptr(_NULL),
|
uintptr(_NULL),
|
||||||
uintptr(0),
|
uintptr(0),
|
||||||
uintptr(0))
|
uintptr(0))
|
||||||
if r1 == negConst(-1) { // error
|
if r1 == negConst(-1) { // error
|
||||||
panic("error getting message in message loop: " + err.Error())
|
panic("error getting message in message loop: " + err.Error())
|
||||||
}
|
}
|
||||||
if r1 == 0 { // WM_QUIT message
|
if r1 == 0 { // WM_QUIT message
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
_translateMessage.Call(uintptr(unsafe.Pointer(&msg)))
|
_translateMessage.Call(uintptr(unsafe.Pointer(&msg)))
|
||||||
|
@ -131,16 +131,16 @@ var (
|
||||||
|
|
||||||
func makeMessageHandler() (hwnd _HWND, err error) {
|
func makeMessageHandler() (hwnd _HWND, err error) {
|
||||||
wc := &_WNDCLASS{
|
wc := &_WNDCLASS{
|
||||||
lpszClassName: utf16ToArg(msghandlerclass),
|
lpszClassName: utf16ToArg(msghandlerclass),
|
||||||
lpfnWndProc: syscall.NewCallback(messageHandlerWndProc),
|
lpfnWndProc: syscall.NewCallback(messageHandlerWndProc),
|
||||||
hInstance: hInstance,
|
hInstance: hInstance,
|
||||||
hIcon: icon,
|
hIcon: icon,
|
||||||
hCursor: cursor,
|
hCursor: cursor,
|
||||||
hbrBackground: _HBRUSH(_COLOR_BTNFACE + 1),
|
hbrBackground: _HBRUSH(_COLOR_BTNFACE + 1),
|
||||||
}
|
}
|
||||||
|
|
||||||
r1, _, err := _registerClass.Call(uintptr(unsafe.Pointer(wc)))
|
r1, _, err := _registerClass.Call(uintptr(unsafe.Pointer(wc)))
|
||||||
if r1 == 0 { // failure
|
if r1 == 0 { // failure
|
||||||
return _HWND(_NULL), fmt.Errorf("error registering the class of the invisible window for handling events: %v", err)
|
return _HWND(_NULL), fmt.Errorf("error registering the class of the invisible window for handling events: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -158,7 +158,7 @@ func makeMessageHandler() (hwnd _HWND, err error) {
|
||||||
uintptr(_NULL),
|
uintptr(_NULL),
|
||||||
uintptr(hInstance),
|
uintptr(hInstance),
|
||||||
uintptr(_NULL))
|
uintptr(_NULL))
|
||||||
if r1 == 0 { // failure
|
if r1 == 0 { // failure
|
||||||
return _HWND(_NULL), fmt.Errorf("error actually creating invisible window for handling events: %v", err)
|
return _HWND(_NULL), fmt.Errorf("error actually creating invisible window for handling events: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -171,8 +171,8 @@ func messageHandlerWndProc(hwnd _HWND, uMsg uint32, wParam _WPARAM, lParam _LPAR
|
||||||
m := (*uimsg)(unsafe.Pointer(lParam))
|
m := (*uimsg)(unsafe.Pointer(lParam))
|
||||||
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,
|
||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
case msgQuit:
|
case msgQuit:
|
||||||
|
|
26
window.go
26
window.go
|
@ -12,25 +12,25 @@ type Window struct {
|
||||||
// Closing gets a message when the user clicks the window's close button.
|
// Closing gets a message when the user clicks the window's close button.
|
||||||
// You cannot change it once the Window has been created.
|
// You cannot change it once the Window has been created.
|
||||||
// If you do not respond to this signal, nothing will happen; regardless of whether you handle the signal or not, the window will not be closed.
|
// If you do not respond to this signal, nothing will happen; regardless of whether you handle the signal or not, the window will not be closed.
|
||||||
Closing chan struct{}
|
Closing chan struct{}
|
||||||
|
|
||||||
lock sync.Mutex
|
lock sync.Mutex
|
||||||
created bool
|
created bool
|
||||||
sysData *sysData
|
sysData *sysData
|
||||||
initTitle string
|
initTitle string
|
||||||
initWidth int
|
initWidth int
|
||||||
initHeight int
|
initHeight int
|
||||||
shownOnce bool
|
shownOnce bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewWindow allocates a new Window with the given title and size. The window is not created until a call to Create() or Open().
|
// NewWindow allocates a new Window with the given title and size. The window is not created until a call to Create() or Open().
|
||||||
func NewWindow(title string, width int, height int) *Window {
|
func NewWindow(title string, width int, height int) *Window {
|
||||||
return &Window{
|
return &Window{
|
||||||
sysData: mksysdata(c_window),
|
sysData: mksysdata(c_window),
|
||||||
initTitle: title,
|
initTitle: title,
|
||||||
initWidth: width,
|
initWidth: width,
|
||||||
initHeight: height,
|
initHeight: height,
|
||||||
Closing: newEvent(),
|
Closing: newEvent(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue