aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal/system/enablement.go
blob: f4435627f511dc3792b9b9f674dfd9f1da014ac1 (plain)
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
package system

type (
	// Enablement represents an optional system resource
	Enablement uint8
	// Enablements represents optional system resources to share
	Enablements uint64
)

const (
	EWayland Enablement = iota
	EX11
	EDBus
	EPulse
)

var enablementString = [...]string{
	EWayland: "Wayland",
	EX11:     "X11",
	EDBus:    "D-Bus",
	EPulse:   "PulseAudio",
}

const ELen = len(enablementString)

func (e Enablement) String() string {
	if int(e) >= ELen {
		return "<invalid enablement>"
	}
	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()
}