-
Notifications
You must be signed in to change notification settings - Fork 22
/
screen.go
150 lines (140 loc) · 4.28 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
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
//----------------------------------------
//
// Copyright © yanghy. All Rights Reserved.
//
// Licensed under Apache License Version 2.0, January 2004
//
// https://www.apache.org/licenses/LICENSE-2.0
//
//----------------------------------------
package cef
import (
"github.com/energye/energy/v2/common"
"github.com/energye/golcl/lcl"
)
// IScreen
// Two ways to obtain screen information
// They are: 1. Using LCL, 2 Using CEF
type IScreen interface {
Primary() (info Display) // Returns the primary Display.
Count() int // Returns display count
Get(index int) (info Display) // Returns Obtain brief information about the specified screen
LCLScreen() *lcl.TScreen // Use this function when using the LCL window, If using ViewFramework window under Windows, this function can also be used
VFScreen() *display // Use this function when using the CEF ViewFramework
}
// Display
// Screen brief information
type Display struct {
ID int
WorkArea TCefRect
Bounds TCefRect
Rotation int32 // Currently, LCL has not been obtained
DeviceScaleFactor float32 // Currently, LCL has not been obtained
}
type Screen struct {
window IBrowserWindow
lclScreen *lcl.TScreen
}
// LCLScreen
// Use this function when using the LCL window
// If using VF windows under Windows, this function can also be used
func (m *Screen) LCLScreen() *lcl.TScreen {
if m.window == nil {
return nil
}
if m.window.IsLCL() {
if m.lclScreen == nil {
m.lclScreen = lcl.NewScreen(m.window.AsLCLBrowserWindow().BrowserWindow())
}
} else if m.window.IsViewsFramework() && common.IsWindows() {
// If using VF windows under Windows, this function can also be used
if m.lclScreen == nil {
m.lclScreen = lcl.NewScreen(m.window.AsViewsFrameworkBrowserWindow().WindowComponent())
}
}
return m.lclScreen
}
// VFScreen
// Use this function when using the CEF ViewFramework
func (m *Screen) VFScreen() *display {
if m.window == nil {
return nil
}
if m.window.IsViewsFramework() {
return &DisplayRef
}
return nil
}
// Count
// Returns all display count
func (m *Screen) Count() int {
if m.window == nil {
return 0
}
if m.window.IsLCL() {
return int(m.LCLScreen().MonitorCount())
} else if m.window.IsViewsFramework() {
return int(m.VFScreen().GetCount())
}
return 0
}
// Primary
// Returns the primary Display.
func (m *Screen) Primary() (info Display) {
if m.window.IsLCL() {
screen := m.LCLScreen()
monitor := screen.PrimaryMonitor()
if monitor == nil {
return
}
wkr := monitor.WorkareaRect()
bdr := monitor.BoundsRect()
info.ID = int(monitor.MonitorNum())
info.WorkArea = TCefRect{X: wkr.Left, Y: wkr.Top, Width: wkr.Width(), Height: wkr.Height()}
info.Bounds = TCefRect{X: bdr.Top, Y: bdr.Left, Width: bdr.Width(), Height: bdr.Height()}
screen.PrimaryMonitor()
} else if m.window.IsViewsFramework() {
screen := m.VFScreen()
monitor := screen.Primary()
if monitor == nil {
return
}
wkr := monitor.WorkArea()
bdr := monitor.Bounds()
info.ID = int(monitor.ID())
info.Rotation = monitor.Rotation()
info.DeviceScaleFactor = monitor.DeviceScaleFactor()
info.WorkArea = TCefRect{X: wkr.X, Y: wkr.Y, Width: wkr.Width, Height: wkr.Height}
info.Bounds = TCefRect{X: bdr.X, Y: bdr.Y, Width: bdr.Width, Height: bdr.Height}
}
return
}
func (m *Screen) Get(index int) (info Display) {
if m.window.IsLCL() {
screen := m.LCLScreen()
monitor := screen.Monitors(int32(index))
if monitor == nil {
return
}
wkr := monitor.WorkareaRect()
bdr := monitor.BoundsRect()
info.ID = int(monitor.MonitorNum())
info.WorkArea = TCefRect{X: wkr.Left, Y: wkr.Top, Width: wkr.Width(), Height: wkr.Height()}
info.Bounds = TCefRect{X: bdr.Top, Y: bdr.Left, Width: bdr.Width(), Height: bdr.Height()}
} else if m.window.IsViewsFramework() {
screen := m.VFScreen()
alls := screen.GetAlls()
monitor := alls.Get(uint32(index))
if monitor == nil {
return
}
wkr := monitor.WorkArea()
bdr := monitor.Bounds()
info.ID = int(monitor.ID())
info.Rotation = monitor.Rotation()
info.DeviceScaleFactor = monitor.DeviceScaleFactor()
info.WorkArea = TCefRect{X: wkr.X, Y: wkr.Y, Width: wkr.Width, Height: wkr.Height}
info.Bounds = TCefRect{X: bdr.X, Y: bdr.Y, Width: bdr.Width, Height: bdr.Height}
}
return
}