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
windowWidth int
height int
initMonitor *glfw.Monitor
scale float64
fullscreenScale float64
@ -73,6 +74,7 @@ var (
func init() {
runtime.LockOSThread()
hideConsoleWindowOnWindows()
if err := initialize(); err != nil {
panic(err)
}
@ -88,27 +90,18 @@ func initialize() error {
}
glfw.WindowHint(glfw.Visible, glfw.False)
glfw.WindowHint(glfw.Resizable, glfw.False)
glfw.WindowHint(glfw.ContextVersionMajor, 2)
glfw.WindowHint(glfw.ContextVersionMinor, 1)
decorated := glfw.False
if currentUI.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)
// Create a window to set the initial monitor.
w, err := glfw.CreateWindow(16, 16, "", nil, nil)
if err != nil {
return err
}
hideConsoleWindowOnWindows()
currentUI.window = window
// TODO: Fix this hack. currentMonitorImpl now requires u.window on POSIX.
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
}
@ -252,7 +245,7 @@ func ScreenSizeInFullscreen() (int, int) {
return nil
})
} else {
v = currentUI.currentMonitor().GetVideoMode()
v = currentUI.initMonitor.GetVideoMode()
s = glfwScale()
}
return int(float64(v.Width) / s), int(float64(v.Height) / s)
@ -513,10 +506,7 @@ func DeviceScaleFactor() float64 {
f := 0.0
u := currentUI
if !u.isRunning() {
// TODO: Unfortunately, this assumes that a window already exists.
// Can we fix this not depending on the window?
// This is related to SetWindowDecorated bug (#753).
return devicescale.GetAt(u.currentMonitor().GetPos())
return devicescale.GetAt(u.initMonitor.GetPos())
}
_ = 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 {
u := currentUI
_ = 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.
mode := glfw.CursorNormal
if !currentUI.isInitCursorVisible() {
if !u.isInitCursorVisible() {
mode = glfw.CursorHidden
}
u.window.SetInputMode(glfw.CursorMode, mode)
if i := currentUI.getInitIconImages(); i != nil {
currentUI.window.SetIcon(i)
if i := u.getInitIconImages(); i != nil {
u.window.SetIcon(i)
}
// Get the monitor before showing the window.