Revert "ui: Add SetInitFocused"

This reverts commit bb04fc8a29.

Reason: glfw.Focused / glfw.FocusOnShow did not work

Updates #769
This commit is contained in:
Hajime Hoshi 2020-02-10 01:10:10 +09:00
parent bb04fc8a29
commit 099ce1b3b4
7 changed files with 1 additions and 66 deletions

View File

@ -58,7 +58,6 @@ var (
flagWindowPosition = flag.String("windowposition", "", "window position (e.g., 100,200)")
flagScreenTransparent = flag.Bool("screentransparent", false, "screen transparent")
flagAutoAdjusting = flag.Bool("autoadjusting", false, "make the game screen auto-adjusting")
flagInitFocused = flag.Bool("initfocused", true, "whether the window is focused on start")
)
func init() {
@ -371,11 +370,6 @@ func main() {
ebiten.SetWindowResizable(true)
}
ebiten.SetInitFocused(*flagInitFocused)
if !*flagInitFocused {
ebiten.SetRunnableInBackground(true)
}
const title = "Window Size (Ebiten Demo)"
if *flagLegacy {
if err := ebiten.Run(g.Update, g.width, g.height, initScreenScale, title); err != nil {

View File

@ -49,7 +49,6 @@ type UI interface {
SetRunnableInBackground(runnableInBackground bool)
SetVsyncEnabled(enabled bool)
SetScreenTransparent(transparent bool)
SetInitFocused(focused bool)
Input() Input
Window() Window

View File

@ -78,7 +78,6 @@ const (
ContextVersionMinor = Hint(0x00022003)
Decorated = Hint(0x00020005)
Focused = Hint(0x00020001)
FocusOnShow = Hint(0x0002000C)
Resizable = Hint(0x00020003)
TransparentFramebuffer = Hint(0x0002000A)
Visible = Hint(0x00020004)

View File

@ -68,7 +68,6 @@ type UserInterface struct {
initWindowHeightInDP int
initScreenTransparent bool
initIconImages []image.Image
initFocused bool
reqWidth int
reqHeight int
@ -96,7 +95,6 @@ var (
initWindowPositionYInDP: invalidPos,
initWindowWidthInDP: 640,
initWindowHeightInDP: 480,
initFocused: true,
vsync: true,
}
)
@ -336,19 +334,6 @@ func (u *UserInterface) setInitWindowSize(width, height int) {
u.m.Unlock()
}
func (u *UserInterface) isInitFocused() bool {
u.m.Lock()
v := u.initFocused
u.m.Unlock()
return v
}
func (u *UserInterface) setInitFocused(focused bool) {
u.m.Lock()
u.initFocused = focused
u.m.Unlock()
}
// toDeviceIndependentPixel must be called from the main thread.
func (u *UserInterface) toDeviceIndependentPixel(x float64) float64 {
return x / u.glfwScale()
@ -643,12 +628,6 @@ func (u *UserInterface) run(context driver.UIContext) error {
}
glfw.WindowHint(glfw.Resizable, resizable)
focused := glfw.False
if u.isInitFocused() {
focused = glfw.True
}
glfw.WindowHint(glfw.FocusOnShow, focused)
// Set the window visible explicitly or the application freezes on Wayland (#974).
if os.Getenv("WAYLAND_DISPLAY") != "" {
glfw.WindowHint(glfw.Visible, glfw.True)
@ -1036,13 +1015,6 @@ func (u *UserInterface) MonitorPosition() (int, int) {
return mx, my
}
func (u *UserInterface) SetInitFocused(focused bool) {
if u.isRunning() {
panic("ui: SetInitFocused must be called before the main loop")
}
u.setInitFocused(focused)
}
func (u *UserInterface) monitorPosition() (int, int) {
// TODO: toDeviceIndependentPixel might be required.
return u.currentMonitor().GetPos()

View File

@ -33,7 +33,6 @@ type UserInterface struct {
runnableInBackground bool
vsync bool
running bool
initFocused bool
sizeChanged bool
contextLost bool
@ -47,7 +46,6 @@ type UserInterface struct {
var theUI = &UserInterface{
sizeChanged: true,
vsync: true,
initFocused: true,
}
func init() {
@ -407,9 +405,7 @@ func init() {
}
func (u *UserInterface) Run(context driver.UIContext) error {
if u.initFocused {
canvas.Call("focus")
}
canvas.Call("focus")
u.running = true
ch := u.loop(context)
if runtime.GOARCH == "wasm" {
@ -464,13 +460,6 @@ func (u *UserInterface) MonitorPosition() (int, int) {
return 0, 0
}
func (u *UserInterface) SetInitFocused(focused bool) {
if u.running {
panic("ui: SetInitFocused must be called before the main loop")
}
u.initFocused = focused
}
func (u *UserInterface) Input() driver.Input {
return &u.input
}

View File

@ -420,10 +420,6 @@ func (u *UserInterface) MonitorPosition() (int, int) {
return 0, 0
}
func (u *UserInterface) SetInitFocused(focused bool) {
// Do nothing
}
func (u *UserInterface) Input() driver.Input {
return &u.input
}

14
run.go
View File

@ -486,17 +486,3 @@ func IsScreenTransparent() bool {
func SetScreenTransparent(transparent bool) {
uiDriver().SetScreenTransparent(transparent)
}
// SetInitFocused sets whether the application is focused on show.
// The default value is true, i.e., the application is focused.
// Note that the application does not proceed if this is not focused by default.
// This behavior can be changed by SetRunnableInBackground.
//
// SetInitFocused does nothing on mobile.
//
// SetInitFocused panics if this is called after the main loop.
//
// SetInitFocused is cuncurrent-safe.
func SetInitFocused(focused bool) {
uiDriver().SetInitFocused(focused)
}