2024-10-16 14:38:57 +09:00
|
|
|
package system
|
2024-09-22 00:29:36 +09:00
|
|
|
|
|
|
|
type (
|
|
|
|
// Enablement represents an optional system resource
|
|
|
|
Enablement uint8
|
|
|
|
// Enablements represents optional system resources to share
|
|
|
|
Enablements uint64
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2024-10-16 14:38:57 +09:00
|
|
|
EWayland Enablement = iota
|
|
|
|
EX11
|
|
|
|
EDBus
|
|
|
|
EPulse
|
2024-09-22 00:29:36 +09:00
|
|
|
)
|
|
|
|
|
2024-10-16 14:38:57 +09:00
|
|
|
var enablementString = [...]string{
|
|
|
|
EWayland: "Wayland",
|
|
|
|
EX11: "X11",
|
|
|
|
EDBus: "D-Bus",
|
|
|
|
EPulse: "PulseAudio",
|
2024-09-22 00:29:36 +09:00
|
|
|
}
|
|
|
|
|
2024-10-16 14:38:57 +09:00
|
|
|
const ELen = len(enablementString)
|
|
|
|
|
2024-09-22 00:29:36 +09:00
|
|
|
func (e Enablement) String() string {
|
2024-10-17 14:31:13 +09:00
|
|
|
if int(e) >= ELen {
|
|
|
|
return "<invalid enablement>"
|
|
|
|
}
|
2024-09-22 00:29:36 +09:00
|
|
|
return enablementString[e]
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e Enablement) Mask() Enablements {
|
|
|
|
return 1 << e
|
|
|
|
}
|
|
|
|
|
|
|
|
// Has returns whether a feature is enabled
|
|
|
|
func (es *Enablements) Has(e Enablement) bool {
|
|
|
|
return *es&e.Mask() != 0
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set enables a feature
|
|
|
|
func (es *Enablements) Set(e Enablement) {
|
|
|
|
if es.Has(e) {
|
|
|
|
panic("enablement " + e.String() + " set twice")
|
|
|
|
}
|
|
|
|
|
|
|
|
*es |= e.Mask()
|
|
|
|
}
|