From fb612a4b87f63a1e4635c9ee1d6b618e387c2064 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Wed, 19 Apr 2017 00:51:15 +0900 Subject: [PATCH] ui: Adjust window size in case when glfwGetVideoMode fails (#328) --- internal/ui/ui_glfw.go | 1 + internal/ui/ui_linux.go | 4 ++++ internal/ui/ui_mac.go | 4 ++++ internal/ui/ui_windows.go | 18 ++++++++++++++++++ 4 files changed, 27 insertions(+) diff --git a/internal/ui/ui_glfw.go b/internal/ui/ui_glfw.go index 9e5b5ec74..4f33ecdd4 100644 --- a/internal/ui/ui_glfw.go +++ b/internal/ui/ui_glfw.go @@ -194,6 +194,7 @@ func Run(width, height int, scale float64, title string, g GraphicsContext) erro w, h := u.glfwSize() x := (v.Width - w) / 2 y := (v.Height - h) / 3 + x, y = adjustWindowPosition(x, y) u.window.SetPos(x, y) return nil }); err != nil { diff --git a/internal/ui/ui_linux.go b/internal/ui/ui_linux.go index 036b10485..ef575744a 100644 --- a/internal/ui/ui_linux.go +++ b/internal/ui/ui_linux.go @@ -25,3 +25,7 @@ func deviceScale() float64 { func glfwScale() float64 { return deviceScale() } + +func adjustWindowPosition(x, y int) (int, int) { + return x, y +} diff --git a/internal/ui/ui_mac.go b/internal/ui/ui_mac.go index d486720ca..192f465f9 100644 --- a/internal/ui/ui_mac.go +++ b/internal/ui/ui_mac.go @@ -36,3 +36,7 @@ func deviceScale() float64 { func glfwScale() float64 { return 1 } + +func adjustWindowPosition(x, y int) (int, int) { + return x, y +} diff --git a/internal/ui/ui_windows.go b/internal/ui/ui_windows.go index 3e6196d2a..63dde538e 100644 --- a/internal/ui/ui_windows.go +++ b/internal/ui/ui_windows.go @@ -30,6 +30,11 @@ package ui // } // return ""; // } +// +// static int getCaptionHeight() { +// return GetSystemMetrics(SM_CYCAPTION); +// } +// import "C" func deviceScale() float64 { @@ -43,3 +48,16 @@ func deviceScale() float64 { func glfwScale() float64 { return deviceScale() } + +func adjustWindowPosition(x, y int) (int, int) { + // As the video width/height might be wrong, + // adjust x/y at least to enable to handle the window (#328) + if x < 0 { + x = 0 + } + t := int(C.getCaptionHeight()) + if y < t { + y = t + } + return x, y +}