diff --git a/internal/uidriver/glfw/ui.go b/internal/uidriver/glfw/ui.go index 29900ec43..03ddf439d 100644 --- a/internal/uidriver/glfw/ui.go +++ b/internal/uidriver/glfw/ui.go @@ -789,19 +789,20 @@ func (u *UserInterface) updateSize() { if sizeChanged { var w, h float64 _ = u.t.Call(func() error { - var ww, wh int if u.isFullscreen() { v := currentMonitor(u.window).GetVideoMode() - ww = v.Width - wh = v.Height + ww, wh := v.Width, v.Height + w = u.toDeviceIndependentPixel(float64(ww)) + h = u.toDeviceIndependentPixel(float64(wh)) } else { // Instead of u.windowWidth and u.windowHeight, use the actual window size here. // On Windows, the specified size at SetSize and the actual window size might not // match (#1163). - ww, wh = u.window.GetSize() + ww, wh := u.window.GetSize() + // TODO: Is this correct? + w = u.toDeviceIndependentPixel(float64(ww)) + h = u.toDeviceIndependentPixel(float64(wh)) } - w = u.toDeviceIndependentPixel(float64(ww)) - h = u.toDeviceIndependentPixel(float64(wh)) return nil }) u.context.Layout(w, h) diff --git a/internal/uidriver/glfw/ui_darwin.go b/internal/uidriver/glfw/ui_darwin.go index 7839b649e..436cd4578 100644 --- a/internal/uidriver/glfw/ui_darwin.go +++ b/internal/uidriver/glfw/ui_darwin.go @@ -49,6 +49,10 @@ func (u *UserInterface) toDeviceIndependentPixel(x float64) float64 { return x } +func (u *UserInterface) fromGLFWPixel(x float64) float64 { + return x +} + func (u *UserInterface) toGLFWPixel(x float64) float64 { return x } diff --git a/internal/uidriver/glfw/ui_unix.go b/internal/uidriver/glfw/ui_unix.go index da130a227..c9ff3c23d 100644 --- a/internal/uidriver/glfw/ui_unix.go +++ b/internal/uidriver/glfw/ui_unix.go @@ -27,6 +27,11 @@ func (u *UserInterface) toDeviceIndependentPixel(x float64) float64 { return x / u.deviceScaleFactor() } +// fromGLFWPixel must be called from the main thread. +func (u *UserInterface) fromGLFWPixel(x float64) float64 { + return x +} + // toGLFWPixel must be called from the main thread. func (u *UserInterface) toGLFWPixel(x float64) float64 { return x diff --git a/internal/uidriver/glfw/ui_windows.go b/internal/uidriver/glfw/ui_windows.go index d427ffa3e..2aeb4410f 100644 --- a/internal/uidriver/glfw/ui_windows.go +++ b/internal/uidriver/glfw/ui_windows.go @@ -104,6 +104,11 @@ func (u *UserInterface) toDeviceIndependentPixel(x float64) float64 { return x / u.deviceScaleFactor() } +// fromGLFWPixel must be called from the main thread. +func (u *UserInterface) fromGLFWPixel(x float64) float64 { + return x / u.deviceScaleFactor() +} + // toGLFWPixel must be called from the main thread. func (u *UserInterface) toGLFWPixel(x float64) float64 { return x * u.deviceScaleFactor() diff --git a/internal/uidriver/glfw/window.go b/internal/uidriver/glfw/window.go index 70f475a9a..365f5a6b2 100644 --- a/internal/uidriver/glfw/window.go +++ b/internal/uidriver/glfw/window.go @@ -192,8 +192,8 @@ func (w *window) Position() (int, int) { mx, my := currentMonitor(w.ui.window).GetPos() wx -= mx wy -= my - xf := w.ui.toDeviceIndependentPixel(float64(wx)) - yf := w.ui.toDeviceIndependentPixel(float64(wy)) + xf := w.ui.fromGLFWPixel(float64(wx)) + yf := w.ui.fromGLFWPixel(float64(wy)) x, y = int(xf), int(yf) return nil }) @@ -226,8 +226,8 @@ func (w *window) Size() (int, int) { if !w.ui.isRunning() { return w.ui.getInitWindowSize() } - ww := int(w.ui.toDeviceIndependentPixel(float64(w.ui.windowWidth))) - wh := int(w.ui.toDeviceIndependentPixel(float64(w.ui.windowHeight))) + ww := int(w.ui.fromGLFWPixel(float64(w.ui.windowWidth))) + wh := int(w.ui.fromGLFWPixel(float64(w.ui.windowHeight))) return ww, wh }