-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathsysinfo.go
119 lines (102 loc) · 3.75 KB
/
sysinfo.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
/*
* Copyright (c) 2014-2017 MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the license is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package gowin32
import (
"syscall"
"unsafe"
"github.com/winlabs/gowin32/wrappers"
)
type ProcessorArchitecture uint16
const (
ProcessorArchitectureIntel ProcessorArchitecture = wrappers.PROCESSOR_ARCHITECTURE_INTEL
ProcessorArchitectureMIPS ProcessorArchitecture = wrappers.PROCESSOR_ARCHITECTURE_MIPS
ProcessorArchitectureAlpha ProcessorArchitecture = wrappers.PROCESSOR_ARCHITECTURE_ALPHA
ProcessorArchitecturePowerPC ProcessorArchitecture = wrappers.PROCESSOR_ARCHITECTURE_PPC
ProcessorArchitectureARM ProcessorArchitecture = wrappers.PROCESSOR_ARCHITECTURE_ARM
ProcessorArchitectureIA64 ProcessorArchitecture = wrappers.PROCESSOR_ARCHITECTURE_IA64
ProcessorArchitectureAMD64 ProcessorArchitecture = wrappers.PROCESSOR_ARCHITECTURE_AMD64
)
type DisplayDevice struct {
DeviceName string
DeviceString string
StateFlags DisplayDeviceStateFlags
DeviceID string
DeviceKey string
}
type DisplayDeviceStateFlags uint32
const (
DisplayDeviceActive DisplayDeviceStateFlags = wrappers.DISPLAY_DEVICE_ACTIVE
DisplayDevicePrimaryDevice DisplayDeviceStateFlags = wrappers.DISPLAY_DEVICE_PRIMARY_DEVICE
DisplayDeviceMirroringDriver DisplayDeviceStateFlags = wrappers.DISPLAY_DEVICE_MIRRORING_DRIVER
DisplayDeviceVGACompatible DisplayDeviceStateFlags = wrappers.DISPLAY_DEVICE_VGA_COMPATIBLE
DisplayDeviceRemovable DisplayDeviceStateFlags = wrappers.DISPLAY_DEVICE_REMOVABLE
DisplayDeviceModeSpruned DisplayDeviceStateFlags = wrappers.DISPLAY_DEVICE_MODESPRUNED
)
type DisplayMonitorInfo struct {
Handle syscall.Handle
DeviceContext syscall.Handle
Rectangle Rectangle
}
type ProcessorInfo struct {
ProcessorArchitecture ProcessorArchitecture
NumberOfProcessors uint
ProcessorLevel uint
ProcessorRevision uint
}
func GetAllDisplayDevices() []DisplayDevice {
result := make([]DisplayDevice, 0)
var device *uint16
var dd wrappers.DISPLAY_DEVICE
dd.Cb = uint32(unsafe.Sizeof(dd))
var i uint32
for i = 0; ; i++ {
if wrappers.EnumDisplayDevices(device, i, &dd, 0) {
result = append(result,
DisplayDevice{DeviceName: syscall.UTF16ToString(dd.DeviceName[:]),
DeviceString: syscall.UTF16ToString(dd.DeviceString[:]),
StateFlags: DisplayDeviceStateFlags(dd.StateFlags),
DeviceID: syscall.UTF16ToString(dd.DeviceID[:]),
DeviceKey: syscall.UTF16ToString(dd.DeviceKey[:]),
})
} else {
break
}
}
return result
}
func GetProcessorInfo() *ProcessorInfo {
var si wrappers.SYSTEM_INFO
wrappers.GetSystemInfo(&si)
return &ProcessorInfo{
ProcessorArchitecture: ProcessorArchitecture(si.ProcessorArchitecture),
NumberOfProcessors: uint(si.NumberOfProcessors),
ProcessorLevel: uint(si.ProcessorLevel),
ProcessorRevision: uint(si.ProcessorRevision),
}
}
func GetAllDisplayMonitors() []DisplayMonitorInfo {
result := []DisplayMonitorInfo{}
wrappers.EnumDisplayMonitors(
syscall.Handle(0),
nil,
func(hmonitor syscall.Handle, hdc syscall.Handle, rect *wrappers.RECT, lparam uintptr) int32 {
result = append(result, DisplayMonitorInfo{Handle: hmonitor, DeviceContext: hdc, Rectangle: rectToRectangle(*rect)})
return 1
},
uintptr(0),
)
return result
}