-
-
Notifications
You must be signed in to change notification settings - Fork 46
/
screen.go
57 lines (46 loc) · 1.97 KB
/
screen.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package fynedesk
import (
"math"
"os"
"strconv"
"fyne.io/fyne/v2"
)
// ScreenList provides information about available physical screens for Fyne desktop
type ScreenList interface {
RefreshScreens() // RefreshScreens asks the ScreenList implementation to reload it's data
AddChangeListener(func()) // Add a change listener to be notified if the screens change
Screens() []*Screen // Screens returns a Screen type slice of each available physical screen
SetActive(*Screen) // Set the specified screen to be considered active
Active() *Screen // Active returns the screen index of the currently active screen
Primary() *Screen // Primary returns the screen index of the primary screen
ScreenForWindow(Window) *Screen // Return the screen that a window is located on
ScreenForGeometry(x, y, width, height int) *Screen // Return the screen that a geometry is located on
}
// Screen provides relative information about a single physical screen
type Screen struct {
Name string // Name is the randr provided name of the screen
X, Y, Width, Height int // Geometry of the screen
Scale float32 // Scale of this screen based on size and resolution
}
// CanvasScale calculates the scale for the contents of a desktop canvas on this screen
func (s *Screen) CanvasScale() float32 {
user := userScale()
return float32(math.Round(float64(s.Scale*user*10.0))) / 10.0
}
func userScale() float32 {
env := os.Getenv("FYNE_SCALE")
if env != "" && env != "auto" {
scale, err := strconv.ParseFloat(env, 32)
if err == nil && scale != 0 {
return float32(scale)
}
fyne.LogError("Error reading scale", err)
}
if env != "auto" {
setting := fyne.CurrentApp().Settings().Scale()
if setting != -1 && setting != 0.0 {
return setting
}
}
return 1.0
}