Bug fix: Use document.hidden (focus/blue event is not reliable when using <iframe>)

This commit is contained in:
Hajime Hoshi 2015-01-08 11:56:03 +09:00
parent 36a5bdf99a
commit 5dade52621

View File

@ -26,18 +26,9 @@ import (
var canvas js.Object var canvas js.Object
var context *opengl.Context var context *opengl.Context
var windowIsFocused = true func shown() bool {
w := js.Global.Get("window").Get("top")
func init() { return !w.Get("document").Get("hidden").Bool()
// TODO: Check IE
window := js.Global.Get("window")
// Get the top window in case that this window is in an iframe.
window.Get("top").Call("addEventListener", "focus", func() {
windowIsFocused = true
})
window.Get("top").Call("addEventListener", "blur", func() {
windowIsFocused = false
})
} }
func Use(f func(*opengl.Context)) { func Use(f func(*opengl.Context)) {
@ -54,7 +45,7 @@ func vsync() {
func DoEvents() { func DoEvents() {
vsync() vsync()
for !windowIsFocused { for !shown() {
vsync() vsync()
} }
} }