mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 18:58:54 +01:00
Bug fix: Use document.hidden (focus/blue event is not reliable when using <iframe>)
This commit is contained in:
parent
36a5bdf99a
commit
5dade52621
@ -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()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user