-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
modifiers_darwin.go
87 lines (80 loc) · 1.92 KB
/
modifiers_darwin.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
// Copyright (c) 2021-2024 by Richard A. Wilkes. All rights reserved.
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, version 2.0. If a copy of the MPL was not distributed with
// this file, You can obtain one at http://mozilla.org/MPL/2.0/.
//
// This Source Code Form is "Incompatible With Secondary Licenses", as
// defined by the Mozilla Public License, version 2.0.
package unison
import (
"bytes"
"github.com/richardwilkes/unison/internal/ns"
)
// OSMenuCmdModifier returns the OS's standard menu command key modifier.
func OSMenuCmdModifier() Modifiers {
return CommandModifier
}
func (m Modifiers) platformString() string {
if m == 0 {
return ""
}
var buffer bytes.Buffer
if m.ControlDown() {
buffer.WriteRune('⌃')
}
if m.OptionDown() {
buffer.WriteRune('⌥')
}
if m.ShiftDown() {
buffer.WriteRune('⇧')
}
if m.CapsLockDown() {
buffer.WriteRune('⇪')
}
if m.NumLockDown() {
buffer.WriteRune('⇭')
}
if m.CommandDown() {
buffer.WriteRune('⌘')
}
return buffer.String()
}
func (m Modifiers) eventModifierFlags() ns.EventModifierFlags {
var mods ns.EventModifierFlags
if m.ShiftDown() {
mods |= ns.EventModifierFlagShift
}
if m.OptionDown() {
mods |= ns.EventModifierFlagOption
}
if m.CommandDown() {
mods |= ns.EventModifierFlagCommand
}
if m.ControlDown() {
mods |= ns.EventModifierFlagControl
}
if m.CapsLockDown() {
mods |= ns.EventModifierFlagCapsLock
}
return mods
}
func modifiersFromEventModifierFlags(flags ns.EventModifierFlags) Modifiers {
var mods Modifiers
if flags&ns.EventModifierFlagShift != 0 {
mods |= ShiftModifier
}
if flags&ns.EventModifierFlagOption != 0 {
mods |= OptionModifier
}
if flags&ns.EventModifierFlagCommand != 0 {
mods |= CommandModifier
}
if flags&ns.EventModifierFlagControl != 0 {
mods |= ControlModifier
}
if flags&ns.EventModifierFlagCapsLock != 0 {
mods |= CapsLockModifier
}
return mods
}