internal/cglfw: let functions return errors

Updates #2703
This commit is contained in:
Hajime Hoshi 2023-10-07 18:47:41 +09:00
parent ee1c179c83
commit 98dc59c89f
6 changed files with 449 additions and 292 deletions

View File

@ -19,33 +19,44 @@ import (
// Originally GLFW 3 passes a null pointer to detach the context. // Originally GLFW 3 passes a null pointer to detach the context.
// But since we're using receievers, DetachCurrentContext should // But since we're using receievers, DetachCurrentContext should
// be used instead. // be used instead.
func (w *Window) MakeContextCurrent() { func (w *Window) MakeContextCurrent() error {
C.glfwMakeContextCurrent(w.data) C.glfwMakeContextCurrent(w.data)
panicError() if err := fetchErrorIgnoringPlatformError(); err != nil {
return err
}
return nil
} }
// DetachCurrentContext detaches the current context. // DetachCurrentContext detaches the current context.
func DetachCurrentContext() { func DetachCurrentContext() error {
C.glfwMakeContextCurrent(nil) C.glfwMakeContextCurrent(nil)
panicError() if err := fetchErrorIgnoringPlatformError(); err != nil {
return err
}
return nil
} }
// GetCurrentContext returns the window whose context is current. // GetCurrentContext returns the window whose context is current.
func GetCurrentContext() *Window { func GetCurrentContext() (*Window, error) {
w := C.glfwGetCurrentContext() w := C.glfwGetCurrentContext()
panicError() if err := fetchErrorIgnoringPlatformError(); err != nil {
if w == nil { return nil, err
return nil
} }
return windows.get(w) if w == nil {
return nil, nil
}
return windows.get(w), nil
} }
// SwapBuffers swaps the front and back buffers of the window. If the // SwapBuffers swaps the front and back buffers of the window. If the
// swap interval is greater than zero, the GPU driver waits the specified number // swap interval is greater than zero, the GPU driver waits the specified number
// of screen updates before swapping the buffers. // of screen updates before swapping the buffers.
func (w *Window) SwapBuffers() { func (w *Window) SwapBuffers() error {
C.glfwSwapBuffers(w.data) C.glfwSwapBuffers(w.data)
panicError() if err := fetchErrorIgnoringPlatformError(); err != nil {
return err
}
return nil
} }
// SwapInterval sets the swap interval for the current context, i.e. the number // SwapInterval sets the swap interval for the current context, i.e. the number
@ -62,9 +73,12 @@ func (w *Window) SwapBuffers() {
// //
// Some GPU drivers do not honor the requested swap interval, either because of // Some GPU drivers do not honor the requested swap interval, either because of
// user settings that override the request or due to bugs in the driver. // user settings that override the request or due to bugs in the driver.
func SwapInterval(interval int) { func SwapInterval(interval int) error {
C.glfwSwapInterval(C.int(interval)) C.glfwSwapInterval(C.int(interval))
panicError() if err := fetchErrorIgnoringPlatformError(); err != nil {
return err
}
return nil
} }
// ExtensionSupported reports whether the specified OpenGL or context creation // ExtensionSupported reports whether the specified OpenGL or context creation
@ -75,12 +89,14 @@ func SwapInterval(interval int) {
// recommended that you cache its results if it's going to be used frequently. // recommended that you cache its results if it's going to be used frequently.
// The extension strings will not change during the lifetime of a context, so // The extension strings will not change during the lifetime of a context, so
// there is no danger in doing this. // there is no danger in doing this.
func ExtensionSupported(extension string) bool { func ExtensionSupported(extension string) (bool, error) {
e := C.CString(extension) e := C.CString(extension)
defer C.free(unsafe.Pointer(e)) defer C.free(unsafe.Pointer(e))
ret := C.glfwExtensionSupported(e) != 0 ret := C.glfwExtensionSupported(e) != 0
panicError() if err := fetchErrorIgnoringPlatformError(); err != nil {
return ret return false, err
}
return ret, nil
} }
// GetProcAddress returns the address of the specified OpenGL or OpenGL ES core // GetProcAddress returns the address of the specified OpenGL or OpenGL ES core
@ -91,10 +107,12 @@ func ExtensionSupported(extension string) bool {
// //
// This function is used to provide GL proc resolving capabilities to an // This function is used to provide GL proc resolving capabilities to an
// external C library. // external C library.
func GetProcAddress(procname string) unsafe.Pointer { func GetProcAddress(procname string) (unsafe.Pointer, error) {
p := C.CString(procname) p := C.CString(procname)
defer C.free(unsafe.Pointer(p)) defer C.free(unsafe.Pointer(p))
ret := unsafe.Pointer(C.glfwGetProcAddress(p)) ret := unsafe.Pointer(C.glfwGetProcAddress(p))
panicError() if err := fetchErrorIgnoringPlatformError(); err != nil {
return ret return nil, err
}
return ret, nil
} }

View File

@ -324,16 +324,21 @@ func goDropCB(window unsafe.Pointer, count C.int, names **C.char) { // TODO: The
} }
// GetInputMode returns the value of an input option of the window. // GetInputMode returns the value of an input option of the window.
func (w *Window) GetInputMode(mode InputMode) int { func (w *Window) GetInputMode(mode InputMode) (int, error) {
ret := int(C.glfwGetInputMode(w.data, C.int(mode))) ret := int(C.glfwGetInputMode(w.data, C.int(mode)))
panicError() if err := fetchErrorIgnoringPlatformError(); err != nil {
return ret return 0, err
}
return ret, nil
} }
// SetInputMode sets an input option for the window. // SetInputMode sets an input option for the window.
func (w *Window) SetInputMode(mode InputMode, value int) { func (w *Window) SetInputMode(mode InputMode, value int) error {
C.glfwSetInputMode(w.data, C.int(mode), C.int(value)) C.glfwSetInputMode(w.data, C.int(mode), C.int(value))
panicError() if err := fetchErrorIgnoringPlatformError(); err != nil {
return err
}
return nil
} }
// RawMouseMotionSupported returns whether raw mouse motion is supported on the // RawMouseMotionSupported returns whether raw mouse motion is supported on the
@ -372,19 +377,23 @@ func GetKeyScancode(key Key) int {
// The key functions deal with physical keys, with key tokens named after their // The key functions deal with physical keys, with key tokens named after their
// use on the standard US keyboard layout. If you want to input text, use the // use on the standard US keyboard layout. If you want to input text, use the
// Unicode character callback instead. // Unicode character callback instead.
func (w *Window) GetKey(key Key) Action { func (w *Window) GetKey(key Key) (Action, error) {
ret := Action(C.glfwGetKey(w.data, C.int(key))) ret := Action(C.glfwGetKey(w.data, C.int(key)))
panicError() if err := fetchErrorIgnoringPlatformError(); err != nil {
return ret return 0, err
}
return ret, nil
} }
// GetKeyName returns the localized name of the specified printable key. // GetKeyName returns the localized name of the specified printable key.
// //
// If the key is glfw.KeyUnknown, the scancode is used, otherwise the scancode is ignored. // If the key is glfw.KeyUnknown, the scancode is used, otherwise the scancode is ignored.
func GetKeyName(key Key, scancode int) string { func GetKeyName(key Key, scancode int) (string, error) {
ret := C.glfwGetKeyName(C.int(key), C.int(scancode)) ret := C.glfwGetKeyName(C.int(key), C.int(scancode))
panicError() if err := fetchErrorIgnoringPlatformError(); err != nil {
return C.GoString(ret) return "", err
}
return C.GoString(ret), nil
} }
// GetMouseButton returns the last state reported for the specified mouse button. // GetMouseButton returns the last state reported for the specified mouse button.
@ -392,10 +401,12 @@ func GetKeyName(key Key, scancode int) string {
// If the StickyMouseButtons input mode is enabled, this function returns Press // If the StickyMouseButtons input mode is enabled, this function returns Press
// the first time you call this function after a mouse button has been pressed, // the first time you call this function after a mouse button has been pressed,
// even if the mouse button has already been released. // even if the mouse button has already been released.
func (w *Window) GetMouseButton(button MouseButton) Action { func (w *Window) GetMouseButton(button MouseButton) (Action, error) {
ret := Action(C.glfwGetMouseButton(w.data, C.int(button))) ret := Action(C.glfwGetMouseButton(w.data, C.int(button)))
panicError() if err := fetchErrorIgnoringPlatformError(); err != nil {
return ret return 0, err
}
return ret, nil
} }
// GetCursorPos returns the last reported position of the cursor. // GetCursorPos returns the last reported position of the cursor.
@ -406,11 +417,13 @@ func (w *Window) GetMouseButton(button MouseButton) Action {
// The coordinate can be converted to their integer equivalents with the floor // The coordinate can be converted to their integer equivalents with the floor
// function. Casting directly to an integer type works for positive coordinates, // function. Casting directly to an integer type works for positive coordinates,
// but fails for negative ones. // but fails for negative ones.
func (w *Window) GetCursorPos() (x, y float64) { func (w *Window) GetCursorPos() (x, y float64, err error) {
var xpos, ypos C.double var xpos, ypos C.double
C.glfwGetCursorPos(w.data, &xpos, &ypos) C.glfwGetCursorPos(w.data, &xpos, &ypos)
panicError() if err := fetchErrorIgnoringPlatformError(); err != nil {
return float64(xpos), float64(ypos) return 0, 0, err
}
return float64(xpos), float64(ypos), nil
} }
// SetCursorPos sets the position of the cursor. The specified window must // SetCursorPos sets the position of the cursor. The specified window must
@ -419,9 +432,12 @@ func (w *Window) GetCursorPos() (x, y float64) {
// //
// If the cursor is disabled (with CursorDisabled) then the cursor position is // If the cursor is disabled (with CursorDisabled) then the cursor position is
// unbounded and limited only by the minimum and maximum values of a double. // unbounded and limited only by the minimum and maximum values of a double.
func (w *Window) SetCursorPos(xpos, ypos float64) { func (w *Window) SetCursorPos(xpos, ypos float64) error {
C.glfwSetCursorPos(w.data, C.double(xpos), C.double(ypos)) C.glfwSetCursorPos(w.data, C.double(xpos), C.double(ypos))
panicError() if err := fetchErrorIgnoringPlatformError(); err != nil {
return err
}
return nil
} }
// CreateCursor creates a new custom cursor image that can be set for a window with SetCursor. // CreateCursor creates a new custom cursor image that can be set for a window with SetCursor.
@ -435,7 +451,7 @@ func (w *Window) SetCursorPos(xpos, ypos float64) {
// //
// The cursor hotspot is specified in pixels, relative to the upper-left corner of the cursor image. // The cursor hotspot is specified in pixels, relative to the upper-left corner of the cursor image.
// Like all other coordinate systems in GLFW, the X-axis points to the right and the Y-axis points down. // Like all other coordinate systems in GLFW, the X-axis points to the right and the Y-axis points down.
func CreateCursor(img image.Image, xhot, yhot int) *Cursor { func CreateCursor(img image.Image, xhot, yhot int) (*Cursor, error) {
var imgC C.GLFWimage var imgC C.GLFWimage
var pixels []uint8 var pixels []uint8
b := img.Bounds() b := img.Bounds()
@ -458,24 +474,31 @@ func CreateCursor(img image.Image, xhot, yhot int) *Cursor {
c := C.glfwCreateCursor(&imgC, C.int(xhot), C.int(yhot)) c := C.glfwCreateCursor(&imgC, C.int(xhot), C.int(yhot))
free() free()
panicError() if err := fetchErrorIgnoringPlatformError(); err != nil {
return nil, err
}
return &Cursor{c} return &Cursor{c}, nil
} }
// CreateStandardCursor returns a cursor with a standard shape, // CreateStandardCursor returns a cursor with a standard shape,
// that can be set for a window with SetCursor. // that can be set for a window with SetCursor.
func CreateStandardCursor(shape StandardCursor) *Cursor { func CreateStandardCursor(shape StandardCursor) (*Cursor, error) {
c := C.glfwCreateStandardCursor(C.int(shape)) c := C.glfwCreateStandardCursor(C.int(shape))
panicError() if err := fetchErrorIgnoringPlatformError(); err != nil {
return &Cursor{c} return nil, err
}
return &Cursor{c}, nil
} }
// Destroy destroys a cursor previously created with CreateCursor. // Destroy destroys a cursor previously created with CreateCursor.
// Any remaining cursors will be destroyed by Terminate. // Any remaining cursors will be destroyed by Terminate.
func (c *Cursor) Destroy() { func (c *Cursor) Destroy() error {
C.glfwDestroyCursor(c.data) C.glfwDestroyCursor(c.data)
panicError() if err := fetchErrorIgnoringPlatformError(); err != nil {
return err
}
return nil
} }
// SetCursor sets the cursor image to be used when the cursor is over the client area // SetCursor sets the cursor image to be used when the cursor is over the client area
@ -483,13 +506,16 @@ func (c *Cursor) Destroy() {
// window is CursorNormal. // window is CursorNormal.
// //
// On some platforms, the set cursor may not be visible unless the window also has input focus. // On some platforms, the set cursor may not be visible unless the window also has input focus.
func (w *Window) SetCursor(c *Cursor) { func (w *Window) SetCursor(c *Cursor) error {
if c == nil { if c == nil {
C.glfwSetCursor(w.data, nil) C.glfwSetCursor(w.data, nil)
} else { } else {
C.glfwSetCursor(w.data, c.data) C.glfwSetCursor(w.data, c.data)
} }
panicError() if err := fetchErrorIgnoringPlatformError(); err != nil {
return err
}
return nil
} }
// KeyCallback is the key callback. // KeyCallback is the key callback.
@ -507,7 +533,7 @@ type KeyCallback func(w *Window, key Key, scancode int, action Action, mods Modi
// fact that the synthetic ones are generated after the window has lost focus, // fact that the synthetic ones are generated after the window has lost focus,
// i.e. Focused will be false and the focus callback will have already been // i.e. Focused will be false and the focus callback will have already been
// called. // called.
func (w *Window) SetKeyCallback(cbfun KeyCallback) (previous KeyCallback) { func (w *Window) SetKeyCallback(cbfun KeyCallback) (previous KeyCallback, err error) {
previous = w.fKeyHolder previous = w.fKeyHolder
w.fKeyHolder = cbfun w.fKeyHolder = cbfun
if cbfun == nil { if cbfun == nil {
@ -515,8 +541,10 @@ func (w *Window) SetKeyCallback(cbfun KeyCallback) (previous KeyCallback) {
} else { } else {
C.glfwSetKeyCallbackCB(w.data) C.glfwSetKeyCallbackCB(w.data)
} }
panicError() if err := fetchErrorIgnoringPlatformError(); err != nil {
return previous return nil, err
}
return previous, nil
} }
// CharCallback is the character callback. // CharCallback is the character callback.
@ -536,7 +564,7 @@ type CharCallback func(w *Window, char rune)
// not be called if modifier keys are held down that would prevent normal text // not be called if modifier keys are held down that would prevent normal text
// input on that platform, for example a Super (Command) key on OS X or Alt key // input on that platform, for example a Super (Command) key on OS X or Alt key
// on Windows. There is a character with modifiers callback that receives these events. // on Windows. There is a character with modifiers callback that receives these events.
func (w *Window) SetCharCallback(cbfun CharCallback) (previous CharCallback) { func (w *Window) SetCharCallback(cbfun CharCallback) (previous CharCallback, err error) {
previous = w.fCharHolder previous = w.fCharHolder
w.fCharHolder = cbfun w.fCharHolder = cbfun
if cbfun == nil { if cbfun == nil {
@ -544,8 +572,10 @@ func (w *Window) SetCharCallback(cbfun CharCallback) (previous CharCallback) {
} else { } else {
C.glfwSetCharCallbackCB(w.data) C.glfwSetCharCallbackCB(w.data)
} }
panicError() if err := fetchErrorIgnoringPlatformError(); err != nil {
return previous return nil, err
}
return previous, nil
} }
// CharModsCallback is the character with modifiers callback. // CharModsCallback is the character with modifiers callback.
@ -563,7 +593,7 @@ type CharModsCallback func(w *Window, char rune, mods ModifierKey)
// map 1:1 to physical keys, as a key may produce zero, one or more characters. // map 1:1 to physical keys, as a key may produce zero, one or more characters.
// If you want to know whether a specific physical key was pressed or released, // If you want to know whether a specific physical key was pressed or released,
// see the key callback instead. // see the key callback instead.
func (w *Window) SetCharModsCallback(cbfun CharModsCallback) (previous CharModsCallback) { func (w *Window) SetCharModsCallback(cbfun CharModsCallback) (previous CharModsCallback, err error) {
previous = w.fCharModsHolder previous = w.fCharModsHolder
w.fCharModsHolder = cbfun w.fCharModsHolder = cbfun
if cbfun == nil { if cbfun == nil {
@ -571,8 +601,10 @@ func (w *Window) SetCharModsCallback(cbfun CharModsCallback) (previous CharModsC
} else { } else {
C.glfwSetCharModsCallbackCB(w.data) C.glfwSetCharModsCallbackCB(w.data)
} }
panicError() if err := fetchErrorIgnoringPlatformError(); err != nil {
return previous return nil, err
}
return previous, nil
} }
// MouseButtonCallback is the mouse button callback. // MouseButtonCallback is the mouse button callback.
@ -586,7 +618,7 @@ type MouseButtonCallback func(w *Window, button MouseButton, action Action, mods
// user-generated events by the fact that the synthetic ones are generated after // user-generated events by the fact that the synthetic ones are generated after
// the window has lost focus, i.e. Focused will be false and the focus // the window has lost focus, i.e. Focused will be false and the focus
// callback will have already been called. // callback will have already been called.
func (w *Window) SetMouseButtonCallback(cbfun MouseButtonCallback) (previous MouseButtonCallback) { func (w *Window) SetMouseButtonCallback(cbfun MouseButtonCallback) (previous MouseButtonCallback, err error) {
previous = w.fMouseButtonHolder previous = w.fMouseButtonHolder
w.fMouseButtonHolder = cbfun w.fMouseButtonHolder = cbfun
if cbfun == nil { if cbfun == nil {
@ -594,8 +626,10 @@ func (w *Window) SetMouseButtonCallback(cbfun MouseButtonCallback) (previous Mou
} else { } else {
C.glfwSetMouseButtonCallbackCB(w.data) C.glfwSetMouseButtonCallbackCB(w.data)
} }
panicError() if err := fetchErrorIgnoringPlatformError(); err != nil {
return previous return nil, err
}
return previous, nil
} }
// CursorPosCallback the cursor position callback. // CursorPosCallback the cursor position callback.
@ -604,7 +638,7 @@ type CursorPosCallback func(w *Window, xpos float64, ypos float64)
// SetCursorPosCallback sets the cursor position callback which is called // SetCursorPosCallback sets the cursor position callback which is called
// when the cursor is moved. The callback is provided with the position relative // when the cursor is moved. The callback is provided with the position relative
// to the upper-left corner of the client area of the window. // to the upper-left corner of the client area of the window.
func (w *Window) SetCursorPosCallback(cbfun CursorPosCallback) (previous CursorPosCallback) { func (w *Window) SetCursorPosCallback(cbfun CursorPosCallback) (previous CursorPosCallback, err error) {
previous = w.fCursorPosHolder previous = w.fCursorPosHolder
w.fCursorPosHolder = cbfun w.fCursorPosHolder = cbfun
if cbfun == nil { if cbfun == nil {
@ -612,8 +646,10 @@ func (w *Window) SetCursorPosCallback(cbfun CursorPosCallback) (previous CursorP
} else { } else {
C.glfwSetCursorPosCallbackCB(w.data) C.glfwSetCursorPosCallbackCB(w.data)
} }
panicError() if err := fetchErrorIgnoringPlatformError(); err != nil {
return previous return nil, err
}
return previous, nil
} }
// CursorEnterCallback is the cursor boundary crossing callback. // CursorEnterCallback is the cursor boundary crossing callback.
@ -621,7 +657,7 @@ type CursorEnterCallback func(w *Window, entered bool)
// SetCursorEnterCallback the cursor boundary crossing callback which is called // SetCursorEnterCallback the cursor boundary crossing callback which is called
// when the cursor enters or leaves the client area of the window. // when the cursor enters or leaves the client area of the window.
func (w *Window) SetCursorEnterCallback(cbfun CursorEnterCallback) (previous CursorEnterCallback) { func (w *Window) SetCursorEnterCallback(cbfun CursorEnterCallback) (previous CursorEnterCallback, err error) {
previous = w.fCursorEnterHolder previous = w.fCursorEnterHolder
w.fCursorEnterHolder = cbfun w.fCursorEnterHolder = cbfun
if cbfun == nil { if cbfun == nil {
@ -629,8 +665,10 @@ func (w *Window) SetCursorEnterCallback(cbfun CursorEnterCallback) (previous Cur
} else { } else {
C.glfwSetCursorEnterCallbackCB(w.data) C.glfwSetCursorEnterCallbackCB(w.data)
} }
panicError() if err := fetchErrorIgnoringPlatformError(); err != nil {
return previous return nil, err
}
return previous, nil
} }
// ScrollCallback is the scroll callback. // ScrollCallback is the scroll callback.
@ -638,7 +676,7 @@ type ScrollCallback func(w *Window, xoff float64, yoff float64)
// SetScrollCallback sets the scroll callback which is called when a scrolling // SetScrollCallback sets the scroll callback which is called when a scrolling
// device is used, such as a mouse wheel or scrolling area of a touchpad. // device is used, such as a mouse wheel or scrolling area of a touchpad.
func (w *Window) SetScrollCallback(cbfun ScrollCallback) (previous ScrollCallback) { func (w *Window) SetScrollCallback(cbfun ScrollCallback) (previous ScrollCallback, err error) {
previous = w.fScrollHolder previous = w.fScrollHolder
w.fScrollHolder = cbfun w.fScrollHolder = cbfun
if cbfun == nil { if cbfun == nil {
@ -646,8 +684,10 @@ func (w *Window) SetScrollCallback(cbfun ScrollCallback) (previous ScrollCallbac
} else { } else {
C.glfwSetScrollCallbackCB(w.data) C.glfwSetScrollCallbackCB(w.data)
} }
panicError() if err := fetchErrorIgnoringPlatformError(); err != nil {
return previous return nil, err
}
return previous, nil
} }
// DropCallback is the drop callback. // DropCallback is the drop callback.
@ -655,7 +695,7 @@ type DropCallback func(w *Window, names []string)
// SetDropCallback sets the drop callback which is called when an object // SetDropCallback sets the drop callback which is called when an object
// is dropped over the window. // is dropped over the window.
func (w *Window) SetDropCallback(cbfun DropCallback) (previous DropCallback) { func (w *Window) SetDropCallback(cbfun DropCallback) (previous DropCallback, err error) {
previous = w.fDropHolder previous = w.fDropHolder
w.fDropHolder = cbfun w.fDropHolder = cbfun
if cbfun == nil { if cbfun == nil {
@ -663,6 +703,8 @@ func (w *Window) SetDropCallback(cbfun DropCallback) (previous DropCallback) {
} else { } else {
C.glfwSetDropCallbackCB(w.data) C.glfwSetDropCallbackCB(w.data)
} }
panicError() if err := fetchErrorIgnoringPlatformError(); err != nil {
return previous return nil, err
}
return previous, nil
} }

View File

@ -76,13 +76,15 @@ func goMonitorCB(monitor unsafe.Pointer, event C.int) {
} }
// GetMonitors returns a slice of handles for all currently connected monitors. // GetMonitors returns a slice of handles for all currently connected monitors.
func GetMonitors() []*Monitor { func GetMonitors() ([]*Monitor, error) {
var length int var length int
mC := C.glfwGetMonitors((*C.int)(unsafe.Pointer(&length))) mC := C.glfwGetMonitors((*C.int)(unsafe.Pointer(&length)))
panicError() if err := fetchErrorIgnoringPlatformError(); err != nil {
return nil, err
}
if mC == nil { if mC == nil {
return nil return nil, nil
} }
m := make([]*Monitor, length) m := make([]*Monitor, length)
@ -91,27 +93,31 @@ func GetMonitors() []*Monitor {
m[i] = &Monitor{C.GetMonitorAtIndex(mC, C.int(i))} m[i] = &Monitor{C.GetMonitorAtIndex(mC, C.int(i))}
} }
return m return m, nil
} }
// GetPrimaryMonitor returns the primary monitor. This is usually the monitor // GetPrimaryMonitor returns the primary monitor. This is usually the monitor
// where elements like the Windows task bar or the OS X menu bar is located. // where elements like the Windows task bar or the OS X menu bar is located.
func GetPrimaryMonitor() *Monitor { func GetPrimaryMonitor() (*Monitor, error) {
m := C.glfwGetPrimaryMonitor() m := C.glfwGetPrimaryMonitor()
panicError() if err := fetchErrorIgnoringPlatformError(); err != nil {
if m == nil { return nil, err
return nil
} }
return &Monitor{m} if m == nil {
return nil, nil
}
return &Monitor{m}, nil
} }
// GetPos returns the position, in screen coordinates, of the upper-left // GetPos returns the position, in screen coordinates, of the upper-left
// corner of the monitor. // corner of the monitor.
func (m *Monitor) GetPos() (x, y int) { func (m *Monitor) GetPos() (x, y int, err error) {
var xpos, ypos C.int var xpos, ypos C.int
C.glfwGetMonitorPos(m.data, &xpos, &ypos) C.glfwGetMonitorPos(m.data, &xpos, &ypos)
panicError() if err := fetchErrorIgnoringPlatformError(); err != nil {
return int(xpos), int(ypos) return 0, 0, err
}
return int(xpos), int(ypos), nil
} }
// GetWorkarea returns the position, in screen coordinates, of the upper-left // GetWorkarea returns the position, in screen coordinates, of the upper-left
@ -170,21 +176,25 @@ func (m *Monitor) GetUserPointer() unsafe.Pointer {
// Note: Some operating systems do not provide accurate information, either // Note: Some operating systems do not provide accurate information, either
// because the monitor's EDID data is incorrect, or because the driver does not // because the monitor's EDID data is incorrect, or because the driver does not
// report it accurately. // report it accurately.
func (m *Monitor) GetPhysicalSize() (width, height int) { func (m *Monitor) GetPhysicalSize() (width, height int, err error) {
var wi, h C.int var wi, h C.int
C.glfwGetMonitorPhysicalSize(m.data, &wi, &h) C.glfwGetMonitorPhysicalSize(m.data, &wi, &h)
panicError() if err := fetchErrorIgnoringPlatformError(); err != nil {
return int(wi), int(h) return 0, 0, err
}
return int(wi), int(h), nil
} }
// GetName returns a human-readable name of the monitor, encoded as UTF-8. // GetName returns a human-readable name of the monitor, encoded as UTF-8.
func (m *Monitor) GetName() string { func (m *Monitor) GetName() (string, error) {
mn := C.glfwGetMonitorName(m.data) mn := C.glfwGetMonitorName(m.data)
panicError() if err := fetchErrorIgnoringPlatformError(); err != nil {
if mn == nil { return "", err
return ""
} }
return C.GoString(mn) if mn == nil {
return "", nil
}
return C.GoString(mn), nil
} }
// MonitorCallback is the signature for monitor configuration callback // MonitorCallback is the signature for monitor configuration callback
@ -211,13 +221,15 @@ func SetMonitorCallback(cbfun MonitorCallback) MonitorCallback {
// The returned array is sorted in ascending order, first by color bit depth // The returned array is sorted in ascending order, first by color bit depth
// (the sum of all channel depths) and then by resolution area (the product of // (the sum of all channel depths) and then by resolution area (the product of
// width and height). // width and height).
func (m *Monitor) GetVideoModes() []*VidMode { func (m *Monitor) GetVideoModes() ([]*VidMode, error) {
var length int var length int
vC := C.glfwGetVideoModes(m.data, (*C.int)(unsafe.Pointer(&length))) vC := C.glfwGetVideoModes(m.data, (*C.int)(unsafe.Pointer(&length)))
panicError() if err := fetchErrorIgnoringPlatformError(); err != nil {
return nil, err
}
if vC == nil { if vC == nil {
return nil return nil, nil
} }
v := make([]*VidMode, length) v := make([]*VidMode, length)
@ -227,36 +239,43 @@ func (m *Monitor) GetVideoModes() []*VidMode {
v[i] = &VidMode{int(t.width), int(t.height), int(t.redBits), int(t.greenBits), int(t.blueBits), int(t.refreshRate)} v[i] = &VidMode{int(t.width), int(t.height), int(t.redBits), int(t.greenBits), int(t.blueBits), int(t.refreshRate)}
} }
return v return v, nil
} }
// GetVideoMode returns the current video mode of the monitor. If you // GetVideoMode returns the current video mode of the monitor. If you
// are using a full screen window, the return value will therefore depend on // are using a full screen window, the return value will therefore depend on
// whether it is focused. // whether it is focused.
func (m *Monitor) GetVideoMode() *VidMode { func (m *Monitor) GetVideoMode() (*VidMode, error) {
t := C.glfwGetVideoMode(m.data) t := C.glfwGetVideoMode(m.data)
if t == nil { if t == nil {
return nil return nil, nil
} }
panicError() if err := fetchErrorIgnoringPlatformError(); err != nil {
return &VidMode{int(t.width), int(t.height), int(t.redBits), int(t.greenBits), int(t.blueBits), int(t.refreshRate)} return nil, err
}
return &VidMode{int(t.width), int(t.height), int(t.redBits), int(t.greenBits), int(t.blueBits), int(t.refreshRate)}, nil
} }
// SetGamma generates a 256-element gamma ramp from the specified exponent and then calls // SetGamma generates a 256-element gamma ramp from the specified exponent and then calls
// SetGamma with it. // SetGamma with it.
func (m *Monitor) SetGamma(gamma float32) { func (m *Monitor) SetGamma(gamma float32) error {
C.glfwSetGamma(m.data, C.float(gamma)) C.glfwSetGamma(m.data, C.float(gamma))
panicError() if err := fetchErrorIgnoringPlatformError(); err != nil {
return err
}
return nil
} }
// GetGammaRamp retrieves the current gamma ramp of the monitor. // GetGammaRamp retrieves the current gamma ramp of the monitor.
func (m *Monitor) GetGammaRamp() *GammaRamp { func (m *Monitor) GetGammaRamp() (*GammaRamp, error) {
var ramp GammaRamp var ramp GammaRamp
rampC := C.glfwGetGammaRamp(m.data) rampC := C.glfwGetGammaRamp(m.data)
panicError() if err := fetchErrorIgnoringPlatformError(); err != nil {
return nil, err
}
if rampC == nil { if rampC == nil {
return nil return nil, nil
} }
length := int(rampC.size) length := int(rampC.size)
@ -270,11 +289,11 @@ func (m *Monitor) GetGammaRamp() *GammaRamp {
ramp.Blue[i] = uint16(C.GetGammaAtIndex(rampC.blue, C.int(i))) ramp.Blue[i] = uint16(C.GetGammaAtIndex(rampC.blue, C.int(i)))
} }
return &ramp return &ramp, nil
} }
// SetGammaRamp sets the current gamma ramp for the monitor. // SetGammaRamp sets the current gamma ramp for the monitor.
func (m *Monitor) SetGammaRamp(ramp *GammaRamp) { func (m *Monitor) SetGammaRamp(ramp *GammaRamp) error {
var rampC C.GLFWgammaramp var rampC C.GLFWgammaramp
length := len(ramp.Red) length := len(ramp.Red)
@ -286,5 +305,8 @@ func (m *Monitor) SetGammaRamp(ramp *GammaRamp) {
} }
C.glfwSetGammaRamp(m.data, &rampC) C.glfwSetGammaRamp(m.data, &rampC)
panicError() if err := fetchErrorIgnoringPlatformError(); err != nil {
return err
}
return nil
} }

View File

@ -302,9 +302,12 @@ func goWindowContentScaleCB(window unsafe.Pointer, x C.float, y C.float) {
// DefaultWindowHints resets all window hints to their default values. // DefaultWindowHints resets all window hints to their default values.
// //
// This function may only be called from the main thread. // This function may only be called from the main thread.
func DefaultWindowHints() { func DefaultWindowHints() error {
C.glfwDefaultWindowHints() C.glfwDefaultWindowHints()
panicError() if err := fetchErrorIgnoringPlatformError(); err != nil {
return err
}
return nil
} }
// WindowHint sets hints for the next call to CreateWindow. The hints, // WindowHint sets hints for the next call to CreateWindow. The hints,
@ -312,9 +315,12 @@ func DefaultWindowHints() {
// DefaultWindowHints, or until the library is terminated with Terminate. // DefaultWindowHints, or until the library is terminated with Terminate.
// //
// This function may only be called from the main thread. // This function may only be called from the main thread.
func WindowHint(target Hint, hint int) { func WindowHint(target Hint, hint int) error {
C.glfwWindowHint(C.int(target), C.int(hint)) C.glfwWindowHint(C.int(target), C.int(hint))
panicError() if err := fetchErrorIgnoringPlatformError(); err != nil {
return err
}
return nil
} }
// WindowHintString sets hints for the next call to CreateWindow. The hints, // WindowHintString sets hints for the next call to CreateWindow. The hints,
@ -401,39 +407,50 @@ func CreateWindow(width, height int, title string, monitor *Monitor, share *Wind
// function, no further callbacks will be called for that window. // function, no further callbacks will be called for that window.
// //
// This function may only be called from the main thread. // This function may only be called from the main thread.
func (w *Window) Destroy() { func (w *Window) Destroy() error {
windows.remove(w.data) windows.remove(w.data)
C.glfwDestroyWindow(w.data) C.glfwDestroyWindow(w.data)
panicError() if err := fetchErrorIgnoringPlatformError(); err != nil {
return err
}
return nil
} }
// ShouldClose reports the value of the close flag of the specified window. // ShouldClose reports the value of the close flag of the specified window.
func (w *Window) ShouldClose() bool { func (w *Window) ShouldClose() (bool, error) {
ret := C.glfwWindowShouldClose(w.data) != 0 ret := C.glfwWindowShouldClose(w.data) != 0
panicError() if err := fetchErrorIgnoringPlatformError(); err != nil {
return ret return false, err
}
return ret, nil
} }
// SetShouldClose sets the value of the close flag of the window. This can be // SetShouldClose sets the value of the close flag of the window. This can be
// used to override the user's attempt to close the window, or to signal that it // used to override the user's attempt to close the window, or to signal that it
// should be closed. // should be closed.
func (w *Window) SetShouldClose(value bool) { func (w *Window) SetShouldClose(value bool) error {
if !value { if !value {
C.glfwSetWindowShouldClose(w.data, C.int(False)) C.glfwSetWindowShouldClose(w.data, C.int(False))
} else { } else {
C.glfwSetWindowShouldClose(w.data, C.int(True)) C.glfwSetWindowShouldClose(w.data, C.int(True))
} }
panicError() if err := fetchErrorIgnoringPlatformError(); err != nil {
return err
}
return nil
} }
// SetTitle sets the window title, encoded as UTF-8, of the window. // SetTitle sets the window title, encoded as UTF-8, of the window.
// //
// This function may only be called from the main thread. // This function may only be called from the main thread.
func (w *Window) SetTitle(title string) { func (w *Window) SetTitle(title string) error {
t := C.CString(title) t := C.CString(title)
defer C.free(unsafe.Pointer(t)) defer C.free(unsafe.Pointer(t))
C.glfwSetWindowTitle(w.data, t) C.glfwSetWindowTitle(w.data, t)
panicError() if err := fetchErrorIgnoringPlatformError(); err != nil {
return err
}
return nil
} }
// SetIcon sets the icon of the specified window. If passed an array of candidate images, // SetIcon sets the icon of the specified window. If passed an array of candidate images,
@ -448,7 +465,7 @@ func (w *Window) SetTitle(title string) {
// //
// The desired image sizes varies depending on platform and system settings. The selected // The desired image sizes varies depending on platform and system settings. The selected
// images will be rescaled as needed. Good sizes include 16x16, 32x32 and 48x48. // images will be rescaled as needed. Good sizes include 16x16, 32x32 and 48x48.
func (w *Window) SetIcon(images []image.Image) { func (w *Window) SetIcon(images []image.Image) error {
count := len(images) count := len(images)
cimages := make([]C.GLFWimage, count) cimages := make([]C.GLFWimage, count)
freePixels := make([]func(), count) freePixels := make([]func(), count)
@ -484,16 +501,21 @@ func (w *Window) SetIcon(images []image.Image) {
v() v()
} }
panicError() if err := fetchErrorIgnoringPlatformError(); err != nil {
return err
}
return nil
} }
// GetPos returns the position, in screen coordinates, of the upper-left // GetPos returns the position, in screen coordinates, of the upper-left
// corner of the client area of the window. // corner of the client area of the window.
func (w *Window) GetPos() (x, y int) { func (w *Window) GetPos() (x, y int, err error) {
var xpos, ypos C.int var xpos, ypos C.int
C.glfwGetWindowPos(w.data, &xpos, &ypos) C.glfwGetWindowPos(w.data, &xpos, &ypos)
panicError() if err := fetchErrorIgnoringPlatformError(); err != nil {
return int(xpos), int(ypos) return 0, 0, err
}
return int(xpos), int(ypos), nil
} }
// SetPos sets the position, in screen coordinates, of the upper-left corner // SetPos sets the position, in screen coordinates, of the upper-left corner
@ -510,18 +532,23 @@ func (w *Window) GetPos() (x, y int) {
// The window manager may put limits on what positions are allowed. // The window manager may put limits on what positions are allowed.
// //
// This function may only be called from the main thread. // This function may only be called from the main thread.
func (w *Window) SetPos(xpos, ypos int) { func (w *Window) SetPos(xpos, ypos int) error {
C.glfwSetWindowPos(w.data, C.int(xpos), C.int(ypos)) C.glfwSetWindowPos(w.data, C.int(xpos), C.int(ypos))
panicError() if err := fetchErrorIgnoringPlatformError(); err != nil {
return err
}
return nil
} }
// GetSize returns the size, in screen coordinates, of the client area of the // GetSize returns the size, in screen coordinates, of the client area of the
// specified window. // specified window.
func (w *Window) GetSize() (width, height int) { func (w *Window) GetSize() (width, height int, err error) {
var wi, h C.int var wi, h C.int
C.glfwGetWindowSize(w.data, &wi, &h) C.glfwGetWindowSize(w.data, &wi, &h)
panicError() if err := fetchErrorIgnoringPlatformError(); err != nil {
return int(wi), int(h) return 0, 0, err
}
return int(wi), int(h), nil
} }
// SetSize sets the size, in screen coordinates, of the client area of the // SetSize sets the size, in screen coordinates, of the client area of the
@ -534,18 +561,24 @@ func (w *Window) GetSize() (width, height int) {
// The window manager may put limits on what window sizes are allowed. // The window manager may put limits on what window sizes are allowed.
// //
// This function may only be called from the main thread. // This function may only be called from the main thread.
func (w *Window) SetSize(width, height int) { func (w *Window) SetSize(width, height int) error {
C.glfwSetWindowSize(w.data, C.int(width), C.int(height)) C.glfwSetWindowSize(w.data, C.int(width), C.int(height))
panicError() if err := fetchErrorIgnoringPlatformError(); err != nil {
return err
}
return nil
} }
// SetSizeLimits sets the size limits of the client area of the specified window. // SetSizeLimits sets the size limits of the client area of the specified window.
// If the window is full screen or not resizable, this function does nothing. // If the window is full screen or not resizable, this function does nothing.
// //
// The size limits are applied immediately and may cause the window to be resized. // The size limits are applied immediately and may cause the window to be resized.
func (w *Window) SetSizeLimits(minw, minh, maxw, maxh int) { func (w *Window) SetSizeLimits(minw, minh, maxw, maxh int) error {
C.glfwSetWindowSizeLimits(w.data, C.int(minw), C.int(minh), C.int(maxw), C.int(maxh)) C.glfwSetWindowSizeLimits(w.data, C.int(minw), C.int(minh), C.int(maxw), C.int(maxh))
panicError() if err := fetchErrorIgnoringPlatformError(); err != nil {
return err
}
return nil
} }
// SetAspectRatio sets the required aspect ratio of the client area of the specified window. // SetAspectRatio sets the required aspect ratio of the client area of the specified window.
@ -557,18 +590,23 @@ func (w *Window) SetSizeLimits(minw, minh, maxw, maxh int) {
// If the numerator and denominator is set to glfw.DontCare then the aspect ratio limit is disabled. // If the numerator and denominator is set to glfw.DontCare then the aspect ratio limit is disabled.
// //
// The aspect ratio is applied immediately and may cause the window to be resized. // The aspect ratio is applied immediately and may cause the window to be resized.
func (w *Window) SetAspectRatio(numer, denom int) { func (w *Window) SetAspectRatio(numer, denom int) error {
C.glfwSetWindowAspectRatio(w.data, C.int(numer), C.int(denom)) C.glfwSetWindowAspectRatio(w.data, C.int(numer), C.int(denom))
panicError() if err := fetchErrorIgnoringPlatformError(); err != nil {
return err
}
return nil
} }
// GetFramebufferSize retrieves the size, in pixels, of the framebuffer of the // GetFramebufferSize retrieves the size, in pixels, of the framebuffer of the
// specified window. // specified window.
func (w *Window) GetFramebufferSize() (width, height int) { func (w *Window) GetFramebufferSize() (width, height int, err error) {
var wi, h C.int var wi, h C.int
C.glfwGetFramebufferSize(w.data, &wi, &h) C.glfwGetFramebufferSize(w.data, &wi, &h)
panicError() if err := fetchErrorIgnoringPlatformError(); err != nil {
return int(wi), int(h) return 0, 0, err
}
return int(wi), int(h), nil
} }
// GetFrameSize retrieves the size, in screen coordinates, of each edge of the frame // GetFrameSize retrieves the size, in screen coordinates, of each edge of the frame
@ -577,11 +615,13 @@ func (w *Window) GetFramebufferSize() (width, height int) {
// //
// Because this function retrieves the size of each window frame edge and not the offset // Because this function retrieves the size of each window frame edge and not the offset
// along a particular coordinate axis, the retrieved values will always be zero or positive. // along a particular coordinate axis, the retrieved values will always be zero or positive.
func (w *Window) GetFrameSize() (left, top, right, bottom int) { func (w *Window) GetFrameSize() (left, top, right, bottom int, err error) {
var l, t, r, b C.int var l, t, r, b C.int
C.glfwGetWindowFrameSize(w.data, &l, &t, &r, &b) C.glfwGetWindowFrameSize(w.data, &l, &t, &r, &b)
panicError() if err := fetchErrorIgnoringPlatformError(); err != nil {
return int(l), int(t), int(r), int(b) return 0, 0, 0, 0, err
}
return int(l), int(t), int(r), int(b), nil
} }
// GetContentScale function retrieves the content scale for the specified // GetContentScale function retrieves the content scale for the specified
@ -681,31 +721,39 @@ func (w *Window) Restore() {
// already visible or is in full screen mode, this function does nothing. // already visible or is in full screen mode, this function does nothing.
// //
// This function may only be called from the main thread. // This function may only be called from the main thread.
func (w *Window) Show() { func (w *Window) Show() error {
C.glfwShowWindow(w.data) C.glfwShowWindow(w.data)
panicError() if err := fetchErrorIgnoringPlatformError(); err != nil {
return err
}
return nil
} }
// Hide hides the window, if it was previously visible. If the window is already // Hide hides the window, if it was previously visible. If the window is already
// hidden or is in full screen mode, this function does nothing. // hidden or is in full screen mode, this function does nothing.
// //
// This function may only be called from the main thread. // This function may only be called from the main thread.
func (w *Window) Hide() { func (w *Window) Hide() error {
C.glfwHideWindow(w.data) C.glfwHideWindow(w.data)
panicError() if err := fetchErrorIgnoringPlatformError(); err != nil {
return err
}
return nil
} }
// GetMonitor returns the handle of the monitor that the window is in // GetMonitor returns the handle of the monitor that the window is in
// fullscreen on. // fullscreen on.
// //
// Returns nil if the window is in windowed mode. // Returns nil if the window is in windowed mode.
func (w *Window) GetMonitor() *Monitor { func (w *Window) GetMonitor() (*Monitor, error) {
m := C.glfwGetWindowMonitor(w.data) m := C.glfwGetWindowMonitor(w.data)
panicError() if err := fetchErrorIgnoringPlatformError(); err != nil {
if m == nil { return nil, err
return nil
} }
return &Monitor{m} if m == nil {
return nil, nil
}
return &Monitor{m}, nil
} }
// SetMonitor sets the monitor that the window uses for full screen mode or, // SetMonitor sets the monitor that the window uses for full screen mode or,
@ -723,7 +771,7 @@ func (w *Window) GetMonitor() *Monitor {
// When a window transitions from full screen to windowed mode, this function // When a window transitions from full screen to windowed mode, this function
// restores any previous window settings such as whether it is decorated, floating, // restores any previous window settings such as whether it is decorated, floating,
// resizable, has size or aspect ratio limits, etc.. // resizable, has size or aspect ratio limits, etc..
func (w *Window) SetMonitor(monitor *Monitor, xpos, ypos, width, height, refreshRate int) { func (w *Window) SetMonitor(monitor *Monitor, xpos, ypos, width, height, refreshRate int) error {
var m *C.GLFWmonitor var m *C.GLFWmonitor
if monitor == nil { if monitor == nil {
m = nil m = nil
@ -731,15 +779,20 @@ func (w *Window) SetMonitor(monitor *Monitor, xpos, ypos, width, height, refresh
m = monitor.data m = monitor.data
} }
C.glfwSetWindowMonitor(w.data, m, C.int(xpos), C.int(ypos), C.int(width), C.int(height), C.int(refreshRate)) C.glfwSetWindowMonitor(w.data, m, C.int(xpos), C.int(ypos), C.int(width), C.int(height), C.int(refreshRate))
panicError() if err := fetchErrorIgnoringPlatformError(); err != nil {
return err
}
return nil
} }
// GetAttrib returns an attribute of the window. There are many attributes, // GetAttrib returns an attribute of the window. There are many attributes,
// some related to the window and others to its context. // some related to the window and others to its context.
func (w *Window) GetAttrib(attrib Hint) int { func (w *Window) GetAttrib(attrib Hint) (int, error) {
ret := int(C.glfwGetWindowAttrib(w.data, C.int(attrib))) ret := int(C.glfwGetWindowAttrib(w.data, C.int(attrib)))
panicError() if err := fetchErrorIgnoringPlatformError(); err != nil {
return ret return 0, err
}
return ret, nil
} }
// SetAttrib function sets the value of an attribute of the specified window. // SetAttrib function sets the value of an attribute of the specified window.
@ -759,17 +812,22 @@ func (w *Window) SetAttrib(attrib Hint, value int) {
// SetUserPointer sets the user-defined pointer of the window. The current value // SetUserPointer sets the user-defined pointer of the window. The current value
// is retained until the window is destroyed. The initial value is nil. // is retained until the window is destroyed. The initial value is nil.
func (w *Window) SetUserPointer(pointer unsafe.Pointer) { func (w *Window) SetUserPointer(pointer unsafe.Pointer) error {
C.glfwSetWindowUserPointer(w.data, pointer) C.glfwSetWindowUserPointer(w.data, pointer)
panicError() if err := fetchErrorIgnoringPlatformError(); err != nil {
return err
}
return nil
} }
// GetUserPointer returns the current value of the user-defined pointer of the // GetUserPointer returns the current value of the user-defined pointer of the
// window. The initial value is nil. // window. The initial value is nil.
func (w *Window) GetUserPointer() unsafe.Pointer { func (w *Window) GetUserPointer() (unsafe.Pointer, error) {
ret := C.glfwGetWindowUserPointer(w.data) ret := C.glfwGetWindowUserPointer(w.data)
panicError() if err := fetchErrorIgnoringPlatformError(); err != nil {
return ret return nil, err
}
return ret, nil
} }
// PosCallback is the window position callback. // PosCallback is the window position callback.
@ -778,7 +836,7 @@ type PosCallback func(w *Window, xpos int, ypos int)
// SetPosCallback sets the position callback of the window, which is called // SetPosCallback sets the position callback of the window, which is called
// when the window is moved. The callback is provided with the screen position // when the window is moved. The callback is provided with the screen position
// of the upper-left corner of the client area of the window. // of the upper-left corner of the client area of the window.
func (w *Window) SetPosCallback(cbfun PosCallback) (previous PosCallback) { func (w *Window) SetPosCallback(cbfun PosCallback) (previous PosCallback, err error) {
previous = w.fPosHolder previous = w.fPosHolder
w.fPosHolder = cbfun w.fPosHolder = cbfun
if cbfun == nil { if cbfun == nil {
@ -786,8 +844,10 @@ func (w *Window) SetPosCallback(cbfun PosCallback) (previous PosCallback) {
} else { } else {
C.glfwSetWindowPosCallbackCB(w.data) C.glfwSetWindowPosCallbackCB(w.data)
} }
panicError() if err := fetchErrorIgnoringPlatformError(); err != nil {
return previous return nil, err
}
return previous, nil
} }
// SizeCallback is the window size callback. // SizeCallback is the window size callback.
@ -796,7 +856,7 @@ type SizeCallback func(w *Window, width int, height int)
// SetSizeCallback sets the size callback of the window, which is called when // SetSizeCallback sets the size callback of the window, which is called when
// the window is resized. The callback is provided with the size, in screen // the window is resized. The callback is provided with the size, in screen
// coordinates, of the client area of the window. // coordinates, of the client area of the window.
func (w *Window) SetSizeCallback(cbfun SizeCallback) (previous SizeCallback) { func (w *Window) SetSizeCallback(cbfun SizeCallback) (previous SizeCallback, err error) {
previous = w.fSizeHolder previous = w.fSizeHolder
w.fSizeHolder = cbfun w.fSizeHolder = cbfun
if cbfun == nil { if cbfun == nil {
@ -804,8 +864,10 @@ func (w *Window) SetSizeCallback(cbfun SizeCallback) (previous SizeCallback) {
} else { } else {
C.glfwSetWindowSizeCallbackCB(w.data) C.glfwSetWindowSizeCallbackCB(w.data)
} }
panicError() if err := fetchErrorIgnoringPlatformError(); err != nil {
return previous return nil, err
}
return previous, nil
} }
// FramebufferSizeCallback is the framebuffer size callback. // FramebufferSizeCallback is the framebuffer size callback.
@ -813,7 +875,7 @@ type FramebufferSizeCallback func(w *Window, width int, height int)
// SetFramebufferSizeCallback sets the framebuffer resize callback of the specified // SetFramebufferSizeCallback sets the framebuffer resize callback of the specified
// window, which is called when the framebuffer of the specified window is resized. // window, which is called when the framebuffer of the specified window is resized.
func (w *Window) SetFramebufferSizeCallback(cbfun FramebufferSizeCallback) (previous FramebufferSizeCallback) { func (w *Window) SetFramebufferSizeCallback(cbfun FramebufferSizeCallback) (previous FramebufferSizeCallback, err error) {
previous = w.fFramebufferSizeHolder previous = w.fFramebufferSizeHolder
w.fFramebufferSizeHolder = cbfun w.fFramebufferSizeHolder = cbfun
if cbfun == nil { if cbfun == nil {
@ -821,8 +883,10 @@ func (w *Window) SetFramebufferSizeCallback(cbfun FramebufferSizeCallback) (prev
} else { } else {
C.glfwSetFramebufferSizeCallbackCB(w.data) C.glfwSetFramebufferSizeCallbackCB(w.data)
} }
panicError() if err := fetchErrorIgnoringPlatformError(); err != nil {
return previous return nil, err
}
return previous, nil
} }
// CloseCallback is the window close callback. // CloseCallback is the window close callback.
@ -837,7 +901,7 @@ type CloseCallback func(w *Window)
// //
// Mac OS X: Selecting Quit from the application menu will trigger the close // Mac OS X: Selecting Quit from the application menu will trigger the close
// callback for all windows. // callback for all windows.
func (w *Window) SetCloseCallback(cbfun CloseCallback) (previous CloseCallback) { func (w *Window) SetCloseCallback(cbfun CloseCallback) (previous CloseCallback, err error) {
previous = w.fCloseHolder previous = w.fCloseHolder
w.fCloseHolder = cbfun w.fCloseHolder = cbfun
if cbfun == nil { if cbfun == nil {
@ -845,8 +909,10 @@ func (w *Window) SetCloseCallback(cbfun CloseCallback) (previous CloseCallback)
} else { } else {
C.glfwSetWindowCloseCallbackCB(w.data) C.glfwSetWindowCloseCallbackCB(w.data)
} }
panicError() if err := fetchErrorIgnoringPlatformError(); err != nil {
return previous return nil, err
}
return previous, nil
} }
// MaximizeCallback is the function signature for window maximize callback // MaximizeCallback is the function signature for window maximize callback
@ -877,7 +943,7 @@ type ContentScaleCallback func(w *Window, x float32, y float32)
// window changes. // window changes.
// //
// This function must only be called from the main thread. // This function must only be called from the main thread.
func (w *Window) SetContentScaleCallback(cbfun ContentScaleCallback) ContentScaleCallback { func (w *Window) SetContentScaleCallback(cbfun ContentScaleCallback) (ContentScaleCallback, error) {
previous := w.fContentScaleHolder previous := w.fContentScaleHolder
w.fContentScaleHolder = cbfun w.fContentScaleHolder = cbfun
if cbfun == nil { if cbfun == nil {
@ -885,7 +951,10 @@ func (w *Window) SetContentScaleCallback(cbfun ContentScaleCallback) ContentScal
} else { } else {
C.glfwSetWindowContentScaleCallbackCB(w.data) C.glfwSetWindowContentScaleCallbackCB(w.data)
} }
return previous if err := fetchErrorIgnoringPlatformError(); err != nil {
return nil, err
}
return previous, nil
} }
// RefreshCallback is the window refresh callback. // RefreshCallback is the window refresh callback.
@ -898,7 +967,7 @@ type RefreshCallback func(w *Window)
// On compositing window systems such as Aero, Compiz or Aqua, where the window // On compositing window systems such as Aero, Compiz or Aqua, where the window
// contents are saved off-screen, this callback may be called only very // contents are saved off-screen, this callback may be called only very
// infrequently or never at all. // infrequently or never at all.
func (w *Window) SetRefreshCallback(cbfun RefreshCallback) (previous RefreshCallback) { func (w *Window) SetRefreshCallback(cbfun RefreshCallback) (previous RefreshCallback, err error) {
previous = w.fRefreshHolder previous = w.fRefreshHolder
w.fRefreshHolder = cbfun w.fRefreshHolder = cbfun
if cbfun == nil { if cbfun == nil {
@ -906,8 +975,10 @@ func (w *Window) SetRefreshCallback(cbfun RefreshCallback) (previous RefreshCall
} else { } else {
C.glfwSetWindowRefreshCallbackCB(w.data) C.glfwSetWindowRefreshCallbackCB(w.data)
} }
panicError() if err := fetchErrorIgnoringPlatformError(); err != nil {
return previous return nil, err
}
return previous, nil
} }
// FocusCallback is the window focus callback. // FocusCallback is the window focus callback.
@ -919,7 +990,7 @@ type FocusCallback func(w *Window, focused bool)
// After the focus callback is called for a window that lost focus, synthetic key // After the focus callback is called for a window that lost focus, synthetic key
// and mouse button release events will be generated for all such that had been // and mouse button release events will be generated for all such that had been
// pressed. For more information, see SetKeyCallback and SetMouseButtonCallback. // pressed. For more information, see SetKeyCallback and SetMouseButtonCallback.
func (w *Window) SetFocusCallback(cbfun FocusCallback) (previous FocusCallback) { func (w *Window) SetFocusCallback(cbfun FocusCallback) (previous FocusCallback, err error) {
previous = w.fFocusHolder previous = w.fFocusHolder
w.fFocusHolder = cbfun w.fFocusHolder = cbfun
if cbfun == nil { if cbfun == nil {
@ -927,8 +998,10 @@ func (w *Window) SetFocusCallback(cbfun FocusCallback) (previous FocusCallback)
} else { } else {
C.glfwSetWindowFocusCallbackCB(w.data) C.glfwSetWindowFocusCallbackCB(w.data)
} }
panicError() if err := fetchErrorIgnoringPlatformError(); err != nil {
return previous return nil, err
}
return previous, nil
} }
// IconifyCallback is the window iconification callback. // IconifyCallback is the window iconification callback.
@ -936,7 +1009,7 @@ type IconifyCallback func(w *Window, iconified bool)
// SetIconifyCallback sets the iconification callback of the window, which is // SetIconifyCallback sets the iconification callback of the window, which is
// called when the window is iconified or restored. // called when the window is iconified or restored.
func (w *Window) SetIconifyCallback(cbfun IconifyCallback) (previous IconifyCallback) { func (w *Window) SetIconifyCallback(cbfun IconifyCallback) (previous IconifyCallback, err error) {
previous = w.fIconifyHolder previous = w.fIconifyHolder
w.fIconifyHolder = cbfun w.fIconifyHolder = cbfun
if cbfun == nil { if cbfun == nil {
@ -944,8 +1017,10 @@ func (w *Window) SetIconifyCallback(cbfun IconifyCallback) (previous IconifyCall
} else { } else {
C.glfwSetWindowIconifyCallbackCB(w.data) C.glfwSetWindowIconifyCallbackCB(w.data)
} }
panicError() if err := fetchErrorIgnoringPlatformError(); err != nil {
return previous return nil, err
}
return previous, nil
} }
// SetClipboardString sets the system clipboard to the specified UTF-8 encoded // SetClipboardString sets the system clipboard to the specified UTF-8 encoded
@ -955,11 +1030,14 @@ func (w *Window) SetIconifyCallback(cbfun IconifyCallback) (previous IconifyCall
// glfw.SetClipboardString(string) // glfw.SetClipboardString(string)
// //
// This function may only be called from the main thread. // This function may only be called from the main thread.
func (w *Window) SetClipboardString(str string) { func (w *Window) SetClipboardString(str string) error {
cp := C.CString(str) cp := C.CString(str)
defer C.free(unsafe.Pointer(cp)) defer C.free(unsafe.Pointer(cp))
C.glfwSetClipboardString(w.data, cp) C.glfwSetClipboardString(w.data, cp)
panicError() if err := fetchErrorIgnoringPlatformError(); err != nil {
return err
}
return nil
} }
// GetClipboardString returns the contents of the system clipboard, if it // GetClipboardString returns the contents of the system clipboard, if it
@ -978,21 +1056,6 @@ func (w *Window) GetClipboardString() string {
return C.GoString(cs) return C.GoString(cs)
} }
// panicErrorExceptForInvalidValue is the same as panicError but ignores
// invalidValue.
func panicErrorExceptForInvalidValue() {
// invalidValue can happen when specific joysticks are used. This issue
// will be fixed in GLFW 3.3.5. As a temporary fix, ignore this error.
// See go-gl/glfw#292, go-gl/glfw#324, and glfw/glfw#1763.
err := acceptError(invalidValue)
if e, ok := err.(*Error); ok && e.Code == invalidValue {
return
}
if err != nil {
panic(err)
}
}
// PollEvents processes only those events that have already been received and // PollEvents processes only those events that have already been received and
// then returns immediately. Processing events will cause the window and input // then returns immediately. Processing events will cause the window and input
// callbacks associated with those events to be called. // callbacks associated with those events to be called.
@ -1002,9 +1065,12 @@ func panicErrorExceptForInvalidValue() {
// This function may not be called from a callback. // This function may not be called from a callback.
// //
// This function may only be called from the main thread. // This function may only be called from the main thread.
func PollEvents() { func PollEvents() error {
C.glfwPollEvents() C.glfwPollEvents()
panicErrorExceptForInvalidValue() if err := fetchErrorIgnoringPlatformError(); err != nil {
return err
}
return nil
} }
// WaitEvents puts the calling thread to sleep until at least one event has been // WaitEvents puts the calling thread to sleep until at least one event has been
@ -1020,9 +1086,12 @@ func PollEvents() {
// This function may not be called from a callback. // This function may not be called from a callback.
// //
// This function may only be called from the main thread. // This function may only be called from the main thread.
func WaitEvents() { func WaitEvents() error {
C.glfwWaitEvents() C.glfwWaitEvents()
panicErrorExceptForInvalidValue() if err := fetchErrorIgnoringPlatformError(); err != nil {
return err
}
return nil
} }
// WaitEventsTimeout puts the calling thread to sleep until at least one event is available in the // WaitEventsTimeout puts the calling thread to sleep until at least one event is available in the
@ -1047,9 +1116,12 @@ func WaitEvents() {
// applications that do not create windows, use native Go primitives. // applications that do not create windows, use native Go primitives.
// //
// Event processing is not required for joystick input to work. // Event processing is not required for joystick input to work.
func WaitEventsTimeout(timeout float64) { func WaitEventsTimeout(timeout float64) error {
C.glfwWaitEventsTimeout(C.double(timeout)) C.glfwWaitEventsTimeout(C.double(timeout))
panicErrorExceptForInvalidValue() if err := fetchErrorIgnoringPlatformError(); err != nil {
return err
}
return nil
} }
// PostEmptyEvent posts an empty event from the current thread to the main // PostEmptyEvent posts an empty event from the current thread to the main
@ -1059,7 +1131,10 @@ func WaitEventsTimeout(timeout float64) {
// applications that do not create windows, use native Go primitives. // applications that do not create windows, use native Go primitives.
// //
// This function may be called from secondary threads. // This function may be called from secondary threads.
func PostEmptyEvent() { func PostEmptyEvent() error {
C.glfwPostEmptyEvent() C.glfwPostEmptyEvent()
panicError() if err := fetchErrorIgnoringPlatformError(); err != nil {
return err
}
return nil
} }

View File

@ -62,7 +62,10 @@ type Cursor struct {
} }
func CreateStandardCursor(shape StandardCursor) (*Cursor, error) { func CreateStandardCursor(shape StandardCursor) (*Cursor, error) {
c := cglfw.CreateStandardCursor(cglfw.StandardCursor(shape)) c, err := cglfw.CreateStandardCursor(cglfw.StandardCursor(shape))
if err != nil {
return nil, err
}
return &Cursor{c: c}, nil return &Cursor{c: c}, nil
} }
@ -76,12 +79,14 @@ func (m *Monitor) GetContentScale() (float32, float32, error) {
} }
func (m *Monitor) GetPos() (x, y int, err error) { func (m *Monitor) GetPos() (x, y int, err error) {
x, y = m.m.GetPos() return m.m.GetPos()
return
} }
func (m *Monitor) GetVideoMode() (*VidMode, error) { func (m *Monitor) GetVideoMode() (*VidMode, error) {
v := m.m.GetVideoMode() v, err := m.m.GetVideoMode()
if err != nil {
return nil, err
}
if v == nil { if v == nil {
return nil, nil return nil, nil
} }
@ -96,18 +101,19 @@ func (m *Monitor) GetVideoMode() (*VidMode, error) {
} }
func (m *Monitor) GetName() (string, error) { func (m *Monitor) GetName() (string, error) {
return m.m.GetName(), nil return m.m.GetName()
} }
type Window struct { type Window struct {
w *cglfw.Window w *cglfw.Window
prevSizeCallback SizeCallback
} }
func (w *Window) Destroy() { func (w *Window) Destroy() error {
w.w.Destroy() if err := w.w.Destroy(); err != nil {
return err
}
theWindows.remove(w.w) theWindows.remove(w.w)
return nil
} }
func (w *Window) Focus() error { func (w *Window) Focus() error {
@ -116,24 +122,30 @@ func (w *Window) Focus() error {
} }
func (w *Window) GetAttrib(attrib Hint) (int, error) { func (w *Window) GetAttrib(attrib Hint) (int, error) {
return w.w.GetAttrib(cglfw.Hint(attrib)), nil return w.w.GetAttrib(cglfw.Hint(attrib))
} }
func (w *Window) GetCursorPos() (x, y float64, err error) { func (w *Window) GetCursorPos() (x, y float64, err error) {
x, y = w.w.GetCursorPos() return w.w.GetCursorPos()
return
} }
func (w *Window) GetInputMode(mode InputMode) (int, error) { func (w *Window) GetInputMode(mode InputMode) (int, error) {
return w.w.GetInputMode(cglfw.InputMode(mode)), nil return w.w.GetInputMode(cglfw.InputMode(mode))
} }
func (w *Window) GetKey(key Key) (Action, error) { func (w *Window) GetKey(key Key) (Action, error) {
return Action(w.w.GetKey(cglfw.Key(key))), nil a, err := w.w.GetKey(cglfw.Key(key))
if err != nil {
return 0, err
}
return Action(a), nil
} }
func (w *Window) GetMonitor() (*Monitor, error) { func (w *Window) GetMonitor() (*Monitor, error) {
m := w.w.GetMonitor() m, err := w.w.GetMonitor()
if err != nil {
return nil, err
}
if m == nil { if m == nil {
return nil, nil return nil, nil
} }
@ -141,21 +153,23 @@ func (w *Window) GetMonitor() (*Monitor, error) {
} }
func (w *Window) GetMouseButton(button MouseButton) (Action, error) { func (w *Window) GetMouseButton(button MouseButton) (Action, error) {
return Action(w.w.GetMouseButton(cglfw.MouseButton(button))), nil a, err := w.w.GetMouseButton(cglfw.MouseButton(button))
if err != nil {
return 0, err
}
return Action(a), nil
} }
func (w *Window) GetPos() (x, y int, err error) { func (w *Window) GetPos() (x, y int, err error) {
x, y = w.w.GetPos() return w.w.GetPos()
return
} }
func (w *Window) GetSize() (width, height int, err error) { func (w *Window) GetSize() (width, height int, err error) {
width, height = w.w.GetSize() return w.w.GetSize()
return
} }
func (w *Window) Hide() { func (w *Window) Hide() error {
w.w.Hide() return w.w.Hide()
} }
func (w *Window) Iconify() error { func (w *Window) Iconify() error {
@ -164,8 +178,7 @@ func (w *Window) Iconify() error {
} }
func (w *Window) MakeContextCurrent() error { func (w *Window) MakeContextCurrent() error {
w.w.MakeContextCurrent() return w.w.MakeContextCurrent()
return nil
} }
func (w *Window) Maximize() error { func (w *Window) Maximize() error {
@ -184,13 +197,11 @@ func (w *Window) SetAttrib(attrib Hint, value int) error {
} }
func (w *Window) SetCharModsCallback(cbfun CharModsCallback) (previous CharModsCallback, err error) { func (w *Window) SetCharModsCallback(cbfun CharModsCallback) (previous CharModsCallback, err error) {
w.w.SetCharModsCallback(cbfun) return w.w.SetCharModsCallback(cbfun)
return ToCharModsCallback(nil), nil // TODO
} }
func (w *Window) SetCloseCallback(cbfun CloseCallback) (previous CloseCallback, err error) { func (w *Window) SetCloseCallback(cbfun CloseCallback) (previous CloseCallback, err error) {
w.w.SetCloseCallback(cbfun) return w.w.SetCloseCallback(cbfun)
return ToCloseCallback(nil), nil // TODO
} }
func (w *Window) SetCursor(cursor *Cursor) error { func (w *Window) SetCursor(cursor *Cursor) error {
@ -198,55 +209,43 @@ func (w *Window) SetCursor(cursor *Cursor) error {
if cursor != nil { if cursor != nil {
c = cursor.c c = cursor.c
} }
w.w.SetCursor(c) return w.w.SetCursor(c)
return nil
} }
func (w *Window) SetCursorPos(xpos, ypos float64) error { func (w *Window) SetCursorPos(xpos, ypos float64) error {
w.w.SetCursorPos(xpos, ypos) return w.w.SetCursorPos(xpos, ypos)
return nil
} }
func (w *Window) SetDropCallback(cbfun DropCallback) (previous DropCallback, err error) { func (w *Window) SetDropCallback(cbfun DropCallback) (previous DropCallback, err error) {
w.w.SetDropCallback(cbfun) return w.w.SetDropCallback(cbfun)
return ToDropCallback(nil), nil // TODO
} }
func (w *Window) SetFramebufferSizeCallback(cbfun FramebufferSizeCallback) (previous FramebufferSizeCallback, err error) { func (w *Window) SetFramebufferSizeCallback(cbfun FramebufferSizeCallback) (previous FramebufferSizeCallback, err error) {
w.w.SetFramebufferSizeCallback(cbfun) return w.w.SetFramebufferSizeCallback(cbfun)
return ToFramebufferSizeCallback(nil), nil // TODO
} }
func (w *Window) SetScrollCallback(cbfun ScrollCallback) (previous ScrollCallback, err error) { func (w *Window) SetScrollCallback(cbfun ScrollCallback) (previous ScrollCallback, err error) {
w.w.SetScrollCallback(cbfun) return w.w.SetScrollCallback(cbfun)
return ToScrollCallback(nil), nil // TODO
} }
func (w *Window) SetShouldClose(value bool) error { func (w *Window) SetShouldClose(value bool) error {
w.w.SetShouldClose(value) return w.w.SetShouldClose(value)
return nil
} }
func (w *Window) SetSizeCallback(cbfun SizeCallback) (previous SizeCallback, err error) { func (w *Window) SetSizeCallback(cbfun SizeCallback) (previous SizeCallback, err error) {
w.w.SetSizeCallback(cbfun) return w.w.SetSizeCallback(cbfun)
prev := w.prevSizeCallback
w.prevSizeCallback = cbfun
return prev, nil
} }
func (w *Window) SetSizeLimits(minw, minh, maxw, maxh int) error { func (w *Window) SetSizeLimits(minw, minh, maxw, maxh int) error {
w.w.SetSizeLimits(minw, minh, maxw, maxh) return w.w.SetSizeLimits(minw, minh, maxw, maxh)
return nil
} }
func (w *Window) SetIcon(images []image.Image) error { func (w *Window) SetIcon(images []image.Image) error {
w.w.SetIcon(images) return w.w.SetIcon(images)
return nil
} }
func (w *Window) SetInputMode(mode InputMode, value int) error { func (w *Window) SetInputMode(mode InputMode, value int) error {
w.w.SetInputMode(cglfw.InputMode(mode), value) return w.w.SetInputMode(cglfw.InputMode(mode), value)
return nil
} }
func (w *Window) SetMonitor(monitor *Monitor, xpos, ypos, width, height, refreshRate int) error { func (w *Window) SetMonitor(monitor *Monitor, xpos, ypos, width, height, refreshRate int) error {
@ -254,37 +253,34 @@ func (w *Window) SetMonitor(monitor *Monitor, xpos, ypos, width, height, refresh
if monitor != nil { if monitor != nil {
m = monitor.m m = monitor.m
} }
w.w.SetMonitor(m, xpos, ypos, width, height, refreshRate) if err := w.w.SetMonitor(m, xpos, ypos, width, height, refreshRate); err != nil {
return err
}
return nil return nil
} }
func (w *Window) SetPos(xpos, ypos int) error { func (w *Window) SetPos(xpos, ypos int) error {
w.w.SetPos(xpos, ypos) return w.w.SetPos(xpos, ypos)
return nil
} }
func (w *Window) SetSize(width, height int) error { func (w *Window) SetSize(width, height int) error {
w.w.SetSize(width, height) return w.w.SetSize(width, height)
return nil
} }
func (w *Window) SetTitle(title string) error { func (w *Window) SetTitle(title string) error {
w.w.SetTitle(title) return w.w.SetTitle(title)
return nil
} }
func (w *Window) ShouldClose() (bool, error) { func (w *Window) ShouldClose() (bool, error) {
return w.w.ShouldClose(), nil return w.w.ShouldClose()
} }
func (w *Window) Show() error { func (w *Window) Show() error {
w.w.Show() return w.w.Show()
return nil
} }
func (w *Window) SwapBuffers() error { func (w *Window) SwapBuffers() error {
w.w.SwapBuffers() return w.w.SwapBuffers()
return nil
} }
func CreateWindow(width, height int, title string, monitor *Monitor, share *Window) (*Window, error) { func CreateWindow(width, height int, title string, monitor *Monitor, share *Window) (*Window, error) {
@ -305,12 +301,16 @@ func CreateWindow(width, height int, title string, monitor *Monitor, share *Wind
} }
func GetKeyName(key Key, scancode int) (string, error) { func GetKeyName(key Key, scancode int) (string, error) {
return cglfw.GetKeyName(cglfw.Key(key), scancode), nil return cglfw.GetKeyName(cglfw.Key(key), scancode)
} }
func GetMonitors() ([]*Monitor, error) { func GetMonitors() ([]*Monitor, error) {
monitors, err := cglfw.GetMonitors()
if err != nil {
return nil, err
}
var ms []*Monitor var ms []*Monitor
for _, m := range cglfw.GetMonitors() { for _, m := range monitors {
if m != nil { if m != nil {
ms = append(ms, &Monitor{m}) ms = append(ms, &Monitor{m})
} else { } else {
@ -320,12 +320,15 @@ func GetMonitors() ([]*Monitor, error) {
return ms, nil return ms, nil
} }
func GetPrimaryMonitor() *Monitor { func GetPrimaryMonitor() (*Monitor, error) {
m := cglfw.GetPrimaryMonitor() m, err := cglfw.GetPrimaryMonitor()
if m == nil { if err != nil {
return nil return nil, err
} }
return &Monitor{m} if m == nil {
return nil, nil
}
return &Monitor{m}, nil
} }
func Init() error { func Init() error {
@ -333,13 +336,11 @@ func Init() error {
} }
func PollEvents() error { func PollEvents() error {
cglfw.PollEvents() return cglfw.PollEvents()
return nil
} }
func PostEmptyEvent() error { func PostEmptyEvent() error {
cglfw.PostEmptyEvent() return cglfw.PostEmptyEvent()
return nil
} }
func SetMonitorCallback(cbfun MonitorCallback) (MonitorCallback, error) { func SetMonitorCallback(cbfun MonitorCallback) (MonitorCallback, error) {
@ -348,8 +349,7 @@ func SetMonitorCallback(cbfun MonitorCallback) (MonitorCallback, error) {
} }
func SwapInterval(interval int) error { func SwapInterval(interval int) error {
cglfw.SwapInterval(interval) return cglfw.SwapInterval(interval)
return nil
} }
func Terminate() error { func Terminate() error {
@ -358,15 +358,13 @@ func Terminate() error {
} }
func WaitEvents() error { func WaitEvents() error {
cglfw.WaitEvents() return cglfw.WaitEvents()
return nil
} }
func WaitEventsTimeout(timeout float64) { func WaitEventsTimeout(timeout float64) error {
cglfw.WaitEventsTimeout(timeout) return cglfw.WaitEventsTimeout(timeout)
} }
func WindowHint(target Hint, hint int) error { func WindowHint(target Hint, hint int) error {
cglfw.WindowHint(cglfw.Hint(target), hint) return cglfw.WindowHint(cglfw.Hint(target), hint)
return nil
} }

View File

@ -322,7 +322,9 @@ func (u *userInterfaceImpl) isNativeFullscreenAvailable() bool {
func (u *userInterfaceImpl) setNativeFullscreen(fullscreen bool) error { func (u *userInterfaceImpl) setNativeFullscreen(fullscreen bool) error {
// Toggling fullscreen might ignore events like keyUp. Ensure that events are fired. // Toggling fullscreen might ignore events like keyUp. Ensure that events are fired.
glfw.WaitEventsTimeout(0.1) if err := glfw.WaitEventsTimeout(0.1); err != nil {
return err
}
w, err := u.window.GetCocoaWindow() w, err := u.window.GetCocoaWindow()
if err != nil { if err != nil {
return err return err