ui: Bug fix: SetWindowDecorated didn't work

Fixes #753
This commit is contained in:
Hajime Hoshi 2018-12-19 01:01:16 +09:00
parent b3ce89aab1
commit 6ef5cc5857

View File

@ -40,6 +40,7 @@ type userInterface struct {
width int width int
windowWidth int windowWidth int
height int height int
initMonitor *glfw.Monitor
scale float64 scale float64
fullscreenScale float64 fullscreenScale float64
@ -73,6 +74,7 @@ var (
func init() { func init() {
runtime.LockOSThread() runtime.LockOSThread()
hideConsoleWindowOnWindows()
if err := initialize(); err != nil { if err := initialize(); err != nil {
panic(err) panic(err)
} }
@ -88,27 +90,18 @@ func initialize() error {
} }
glfw.WindowHint(glfw.Visible, glfw.False) glfw.WindowHint(glfw.Visible, glfw.False)
glfw.WindowHint(glfw.Resizable, glfw.False) glfw.WindowHint(glfw.Resizable, glfw.False)
glfw.WindowHint(glfw.ContextVersionMajor, 2)
glfw.WindowHint(glfw.ContextVersionMinor, 1)
decorated := glfw.False // Create a window to set the initial monitor.
if currentUI.isInitWindowDecorated() { w, err := glfw.CreateWindow(16, 16, "", nil, nil)
decorated = glfw.True
}
glfw.WindowHint(glfw.Decorated, decorated)
// As a start, create a window with temporary size to create OpenGL context thread.
window, err := glfw.CreateWindow(16, 16, "", nil, nil)
if err != nil { if err != nil {
return err return err
} }
hideConsoleWindowOnWindows() // TODO: Fix this hack. currentMonitorImpl now requires u.window on POSIX.
currentUI.window = window currentUI.window = w
currentUI.initMonitor = currentUI.currentMonitorImpl()
currentUI.window.Destroy()
currentUI.window = nil
currentUI.window.MakeContextCurrent()
currentUI.window.SetInputMode(glfw.StickyMouseButtonsMode, glfw.True)
currentUI.window.SetInputMode(glfw.StickyKeysMode, glfw.True)
return nil return nil
} }
@ -252,7 +245,7 @@ func ScreenSizeInFullscreen() (int, int) {
return nil return nil
}) })
} else { } else {
v = currentUI.currentMonitor().GetVideoMode() v = currentUI.initMonitor.GetVideoMode()
s = glfwScale() s = glfwScale()
} }
return int(float64(v.Width) / s), int(float64(v.Height) / s) return int(float64(v.Width) / s), int(float64(v.Height) / s)
@ -513,10 +506,7 @@ func DeviceScaleFactor() float64 {
f := 0.0 f := 0.0
u := currentUI u := currentUI
if !u.isRunning() { if !u.isRunning() {
// TODO: Unfortunately, this assumes that a window already exists. return devicescale.GetAt(u.initMonitor.GetPos())
// Can we fix this not depending on the window?
// This is related to SetWindowDecorated bug (#753).
return devicescale.GetAt(u.currentMonitor().GetPos())
} }
_ = mainthread.Run(func() error { _ = mainthread.Run(func() error {
@ -530,15 +520,37 @@ func DeviceScaleFactor() float64 {
func Run(width, height int, scale float64, title string, g GraphicsContext, mainloop bool) error { func Run(width, height int, scale float64, title string, g GraphicsContext, mainloop bool) error {
u := currentUI u := currentUI
_ = mainthread.Run(func() error { _ = mainthread.Run(func() error {
glfw.WindowHint(glfw.ContextVersionMajor, 2)
glfw.WindowHint(glfw.ContextVersionMinor, 1)
// 'decorated' must be solved before creating a window (#556).
decorated := glfw.False
if u.isInitWindowDecorated() {
decorated = glfw.True
}
glfw.WindowHint(glfw.Decorated, decorated)
// As a start, create a window with temporary size to create OpenGL context thread.
window, err := glfw.CreateWindow(16, 16, "", nil, nil)
if err != nil {
return err
}
u.window = window
u.window.MakeContextCurrent()
u.window.SetInputMode(glfw.StickyMouseButtonsMode, glfw.True)
u.window.SetInputMode(glfw.StickyKeysMode, glfw.True)
// Solve the initial properties of the window. // Solve the initial properties of the window.
mode := glfw.CursorNormal mode := glfw.CursorNormal
if !currentUI.isInitCursorVisible() { if !u.isInitCursorVisible() {
mode = glfw.CursorHidden mode = glfw.CursorHidden
} }
u.window.SetInputMode(glfw.CursorMode, mode) u.window.SetInputMode(glfw.CursorMode, mode)
if i := currentUI.getInitIconImages(); i != nil { if i := u.getInitIconImages(); i != nil {
currentUI.window.SetIcon(i) u.window.SetIcon(i)
} }
// Get the monitor before showing the window. // Get the monitor before showing the window.