Skip to content

Commit

Permalink
uidriver/glfw: Bug fix: Treat X scale (HiDPI) correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
hajimehoshi committed Sep 18, 2020
1 parent 40e35fa commit 51f0613
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
4 changes: 4 additions & 0 deletions internal/glfw/glfw_notwindows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
11 changes: 8 additions & 3 deletions internal/uidriver/glfw/ui_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 51f0613

Please sign in to comment.