-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoutput.go
129 lines (105 loc) · 2.74 KB
/
output.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package main
import (
"deedles.dev/wlr"
"deedles.dev/ximage/geom"
)
type Output struct {
Output wlr.Output
Layers [4][]LayerSurface
onFrameListener wlr.Listener
}
type OutputConfig struct {
Name string
X, Y int
Width, Height int
Scale float32
Transform wlr.OutputTransform
}
func (server *Server) outputAt(p geom.Point[float64]) *Output {
wout := server.outputLayout.OutputAt(p.X, p.Y)
for _, out := range server.outputs {
if out.Output == wout {
return out
}
}
return nil
}
func (server *Server) outputBounds(out *Output) geom.Rect[float64] {
x, y := server.outputLayout.OutputCoords(out.Output)
return geom.Rt(0, 0, float64(out.Output.Width()), float64(out.Output.Height())).Add(geom.Pt(x, y))
}
func (server *Server) outputTilingBounds(out *Output) geom.Rect[float64] {
b := server.outputBounds(out)
if out == server.statusBar.Output() {
return b.Pad(StatusBarHeight, 0, 0, 0)
}
return b
}
func (server *Server) statusBarBounds() geom.Rect[float64] {
b := server.outputBounds(server.statusBar.Output())
b.Max.Y = b.Min.Y + StatusBarHeight
return b
}
func (server *Server) onNewOutput(wout wlr.Output) {
out := Output{
Output: wout,
}
out.onFrameListener = wout.OnFrame(func(wout wlr.Output) {
server.onFrame(&out)
})
server.addOutput(&out)
if server.statusBar == nil {
server.statusBar = NewStatusBar(&out)
}
wout.InitRender(server.allocator, server.renderer)
wout.Commit()
wout.CreateGlobal()
}
func (server *Server) addOutput(out *Output) {
server.outputs = append(server.outputs, out)
for _, config := range server.OutputConfigs {
if config.Name != out.Output.Name() {
continue
}
server.configureOutput(out, &config)
return
}
server.configureOutput(out, nil)
}
func (server *Server) configureOutput(out *Output, config *OutputConfig) {
server.setOutputMode(out, config)
server.layoutOutput(out, config)
out.Output.Enable(true)
if config == nil {
return
}
if config.Scale != 0 {
out.Output.SetScale(config.Scale)
}
if config.Transform != 0 {
out.Output.SetTransform(config.Transform)
}
}
func (server *Server) layoutOutput(out *Output, config *OutputConfig) {
if (config == nil) || (config.X == -1) && (config.Y == -1) {
server.outputLayout.AddAuto(out.Output)
return
}
server.outputLayout.Add(out.Output, config.X, config.Y)
}
func (server *Server) setOutputMode(out *Output, config *OutputConfig) {
if (config == nil) || (config.Width == 0) || (config.Height == 0) {
return
}
modes := out.Output.Modes()
for mode := range modes {
if (mode.Width() == int32(config.Width)) && (mode.Height() == int32(config.Height)) {
out.Output.SetMode(mode)
return
}
}
mode := out.Output.PreferredMode()
if mode.Valid() {
out.Output.SetMode(mode)
}
}