-
Notifications
You must be signed in to change notification settings - Fork 17
/
backend.go
74 lines (69 loc) · 1.82 KB
/
backend.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//go:build cgo
// +build cgo
package wallutils
// WMs contains all available backends for changing the wallpaper
// Some backends may require cgo (sway + x11)
var WMs = []WM{
&Hyprpaper{},
&Sway{},
&Deepin{},
&Xfce4{},
&Mate{},
&Cinnamon{},
&Plasma{},
&Gnome3{},
&Gnome2{},
&Pekwm{},
&SwayBG{},
&Weston{},
// xbg.New(), // X11
&Feh{}, // use feh for X11, for now
}
// Info returns a long info string that looks different for Wayland and for X.
// The string contains all available information about the connected monitors.
func Info() (string, error) {
if WaylandCanConnect() {
return WaylandInfo()
} else if XCanConnect() {
return XInfo()
}
return "", errNoWaylandNoX
}
// Monitors returns information about all monitors, regardless of if it's under
// Wayland or X11. Will use additional plugins, if available.
func Monitors() ([]Monitor, error) {
IDs, widths, heights, wDPIs, hDPIs := []uint{}, []uint{}, []uint{}, []uint{}, []uint{}
if WaylandCanConnect() {
if err := WaylandMonitors(&IDs, &widths, &heights, &wDPIs, &hDPIs); err != nil {
return []Monitor{}, err
}
} else if XCanConnect() {
if err := XMonitors(&IDs, &widths, &heights, &wDPIs, &hDPIs); err != nil {
return []Monitor{}, err
}
}
if len(IDs) == 0 {
return []Monitor{}, errNoWaylandNoX
}
// Build and return a []Monitor slice
monitors := []Monitor{}
for i, ID := range IDs {
monitors = append(monitors, Monitor{ID, widths[i], heights[i], wDPIs[i], hDPIs[i]})
}
return monitors, nil
}
// AverageResolution returns the average resolution for all connected monitors.
func AverageResolution() (*Res, error) {
monitors, err := Monitors()
if err != nil {
return nil, err
}
var ws, hs uint
for _, mon := range monitors {
ws += mon.Width
hs += mon.Height
}
ws /= uint(len(monitors))
hs /= uint(len(monitors))
return NewRes(ws, hs), nil
}