internal/uidriver/glfw: Use the correct initial monitor on Linux/UNIX

Closes #1827
This commit is contained in:
Hajime Hoshi 2021-09-25 02:46:18 +09:00
parent 23566a7d2e
commit 77664ff057
6 changed files with 28 additions and 2 deletions

View File

@ -141,6 +141,10 @@ func (w *Window) GetSize() (width, height int) {
return w.w.GetSize() return w.w.GetSize()
} }
func (w *Window) Hide() {
w.w.Hide()
}
func (w *Window) Iconify() { func (w *Window) Iconify() {
w.w.Iconify() w.w.Iconify()
} }

View File

@ -182,6 +182,11 @@ func (w *Window) GetSize() (int, int) {
return int(width), int(height) return int(width), int(height)
} }
func (w *Window) Hide() {
glfwDLL.call("glfwHideWindow", w.w)
panicError()
}
func (w *Window) Iconify() { func (w *Window) Iconify() {
glfwDLL.call("glfwIconifyWindow", w.w) glfwDLL.call("glfwIconifyWindow", w.w)
panicError() panicError()

View File

@ -185,9 +185,8 @@ func initialize() error {
panic("glfw: glfw.CreateWindow must not return nil") panic("glfw: glfw.CreateWindow must not return nil")
} }
defer w.Destroy() defer w.Destroy()
initializeWindowAfterCreation(w)
// TODO: The first current monitor should be determined without a window.
// On Linux, the first window position is always (0, 0) and not reliable to detect a monitor.
m := currentMonitor(w) m := currentMonitor(w)
theUI.initMonitor = m theUI.initMonitor = m
v := m.GetVideoMode() v := m.GetVideoMode()
@ -753,6 +752,8 @@ func (u *UserInterface) createWindow() error {
if err != nil { if err != nil {
return err return err
} }
initializeWindowAfterCreation(window)
u.window = window u.window = window
if u.Graphics().IsGL() { if u.Graphics().IsGL() {
@ -890,6 +891,7 @@ func (u *UserInterface) init() error {
if err := u.createWindow(); err != nil { if err := u.createWindow(); err != nil {
return err return err
} }
u.setSizeCallbackEnabled = true u.setSizeCallbackEnabled = true
setSize := func() { setSize := func() {

View File

@ -193,3 +193,6 @@ func (u *UserInterface) adjustViewSize() {
} }
C.adjustViewSize(C.uintptr_t(u.window.GetCocoaWindow())) C.adjustViewSize(C.uintptr_t(u.window.GetCocoaWindow()))
} }
func initializeWindowAfterCreation(w *glfw.Window) {
}

View File

@ -164,3 +164,10 @@ func (u *UserInterface) setNativeFullscreen(fullscreen bool) {
func (u *UserInterface) adjustViewSize() { func (u *UserInterface) adjustViewSize() {
} }
func initializeWindowAfterCreation(w *glfw.Window) {
// Show the window once before getting the position of the window.
// On Linux/Unix, the window position is not reliable before showing.
w.Show()
w.Hide()
}

View File

@ -140,6 +140,8 @@ func (u *UserInterface) adjustWindowPosition(x, y int) (int, int) {
} }
func currentMonitorByOS(_ *glfw.Window) *glfw.Monitor { func currentMonitorByOS(_ *glfw.Window) *glfw.Monitor {
// TODO: Why not using the given window?
// TODO: Should we return nil here? // TODO: Should we return nil here?
w, err := getActiveWindow() w, err := getActiveWindow()
if err != nil { if err != nil {
@ -206,3 +208,6 @@ func (u *UserInterface) setNativeFullscreen(fullscreen bool) {
func (u *UserInterface) adjustViewSize() { func (u *UserInterface) adjustViewSize() {
} }
func initializeWindowAfterCreation(w *glfw.Window) {
}