-
Notifications
You must be signed in to change notification settings - Fork 7
/
Modifier.go
34 lines (28 loc) · 1020 Bytes
/
Modifier.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
package input
// Modifier is a collection of currently pressed modifier keys.
type Modifier uint32
// Constants for common modifier.
const (
ModNone = Modifier(0x00000000)
ModShift = Modifier(0x00000001)
ModControl = Modifier(0x00000002)
ModAlt = Modifier(0x00000004)
ModSuper = Modifier(0x00000008)
)
// IsClear returns true if nothing is set.
func (mod Modifier) IsClear() bool {
return mod == ModNone
}
// With returns a combination of this modifier and the given one.
func (mod Modifier) With(other Modifier) Modifier {
return Modifier(uint32(mod) | uint32(other))
}
// Without returns the result of this modifier without the given one.
func (mod Modifier) Without(other Modifier) Modifier {
return Modifier(uint32(mod) & ^uint32(other))
}
// Has returns true if the given modifier is included in this set.
// This modifier can have more keys set than the requested and still return true.
func (mod Modifier) Has(other Modifier) bool {
return (uint32(mod) | uint32(other)) == uint32(mod)
}