-
-
Notifications
You must be signed in to change notification settings - Fork 50
/
clipboard.go
66 lines (57 loc) · 1.9 KB
/
clipboard.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
package vz
/*
#cgo darwin CFLAGS: -mmacosx-version-min=11 -x objective-c -fno-objc-arc
#cgo darwin LDFLAGS: -lobjc -framework Foundation -framework Virtualization
# include "virtualization_13.h"
*/
import "C"
import (
"github.com/Code-Hex/vz/v3/internal/objc"
)
// SpiceAgentPortAttachment is an attachment point that enables
// the Spice clipboard sharing capability.
//
// see: https://developer.apple.com/documentation/virtualization/vzspiceagentportattachment?language=objc
type SpiceAgentPortAttachment struct {
*pointer
*baseSerialPortAttachment
enabledSharesClipboard bool
}
var _ SerialPortAttachment = (*SpiceAgentPortAttachment)(nil)
// NewSpiceAgentPortAttachment creates a new Spice agent port attachment.
//
// This is only supported on macOS 13 and newer, error will
// be returned on older versions.
func NewSpiceAgentPortAttachment() (*SpiceAgentPortAttachment, error) {
if err := macOSAvailable(13); err != nil {
return nil, err
}
spiceAgent := &SpiceAgentPortAttachment{
pointer: objc.NewPointer(
C.newVZSpiceAgentPortAttachment(),
),
enabledSharesClipboard: true,
}
objc.SetFinalizer(spiceAgent, func(self *SpiceAgentPortAttachment) {
objc.Release(self)
})
return spiceAgent, nil
}
// SetSharesClipboard sets enable the Spice agent clipboard sharing capability.
func (s *SpiceAgentPortAttachment) SetSharesClipboard(enable bool) {
C.setSharesClipboardVZSpiceAgentPortAttachment(
objc.Ptr(s),
C.bool(enable),
)
s.enabledSharesClipboard = enable
}
// SharesClipboard returns enable the Spice agent clipboard sharing capability.
func (s *SpiceAgentPortAttachment) SharesClipboard() bool { return s.enabledSharesClipboard }
// SpiceAgentPortAttachmentName returns the Spice agent port name.
func SpiceAgentPortAttachmentName() (string, error) {
if err := macOSAvailable(13); err != nil {
return "", err
}
cstring := (*char)(C.getSpiceAgentPortName())
return cstring.String(), nil
}