diff --git a/internal/glfw/glfw_notwindows.go b/internal/glfw/glfw_notwindows.go index c736fa92e..4f8f5e810 100644 --- a/internal/glfw/glfw_notwindows.go +++ b/internal/glfw/glfw_notwindows.go @@ -62,6 +62,10 @@ type Monitor struct { m *glfw.Monitor } +func (m *Monitor) GetContentScale() (float32, float32) { + return m.m.GetContentScale() +} + func (m *Monitor) GetPos() (x, y int) { return m.m.GetPos() } diff --git a/internal/uidriver/glfw/ui_unix.go b/internal/uidriver/glfw/ui_unix.go index 05e821adb..a1f2ae514 100644 --- a/internal/uidriver/glfw/ui_unix.go +++ b/internal/uidriver/glfw/ui_unix.go @@ -29,17 +29,22 @@ func (u *UserInterface) fromGLFWMonitorPixel(x float64) float64 { // fromGLFWPixel must be called from the main thread. func (u *UserInterface) fromGLFWPixel(x float64) float64 { - return x + // deviceScaleFactor() is a scale by desktop environment (e.g., Cinnamon), while GetContentScale() is X's scale. + // They are different things and then need to be treated different ways (#1350). + s, _ := currentMonitor(u.window).GetContentScale() + return x / float64(s) } // toGLFWPixel must be called from the main thread. func (u *UserInterface) toGLFWPixel(x float64) float64 { - return x + s, _ := currentMonitor(u.window).GetContentScale() + return x * float64(s) } // toFramebufferPixel must be called from the main thread. func (u *UserInterface) toFramebufferPixel(x float64) float64 { - return x / u.deviceScaleFactor() + s, _ := currentMonitor(u.window).GetContentScale() + return x / u.deviceScaleFactor() * float64(s) } func (u *UserInterface) adjustWindowPosition(x, y int) (int, int) {