diff options
author | lawl <github@dumbinter.net> | 2022-01-06 10:44:13 +0200 |
---|---|---|
committer | lawl <github@dumbinter.net> | 2022-01-06 16:04:34 +0530 |
commit | 8c34658b64f1efeab501bef57d2bfa9579fe34e2 (patch) | |
tree | 3fef93871214bc85c89ffcd04c6782c8aa3862ce /vendor/gioui.org/io/router/clipboard.go | |
parent | 38787e4195f2a34d7ec4421caf17cb99bc31fa2b (diff) | |
download | noisetorch-8c34658b64f1efeab501bef57d2bfa9579fe34e2.tar.gz noisetorch-8c34658b64f1efeab501bef57d2bfa9579fe34e2.zip |
Chore: Upgrade nucular GUI dependency
Diffstat (limited to 'vendor/gioui.org/io/router/clipboard.go')
-rw-r--r-- | vendor/gioui.org/io/router/clipboard.go | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/vendor/gioui.org/io/router/clipboard.go b/vendor/gioui.org/io/router/clipboard.go new file mode 100644 index 0000000..5f1623c --- /dev/null +++ b/vendor/gioui.org/io/router/clipboard.go @@ -0,0 +1,57 @@ +// SPDX-License-Identifier: Unlicense OR MIT + +package router + +import ( + "gioui.org/io/event" +) + +type clipboardQueue struct { + receivers map[event.Tag]struct{} + // request avoid read clipboard every frame while waiting. + requested bool + text *string +} + +// WriteClipboard returns the most recent text to be copied +// to the clipboard, if any. +func (q *clipboardQueue) WriteClipboard() (string, bool) { + if q.text == nil { + return "", false + } + text := *q.text + q.text = nil + return text, true +} + +// ReadClipboard reports if any new handler is waiting +// to read the clipboard. +func (q *clipboardQueue) ReadClipboard() bool { + if len(q.receivers) == 0 || q.requested { + return false + } + q.requested = true + return true +} + +func (q *clipboardQueue) Push(e event.Event, events *handlerEvents) { + for r := range q.receivers { + events.Add(r, e) + delete(q.receivers, r) + } +} + +func (q *clipboardQueue) ProcessWriteClipboard(refs []interface{}) { + q.text = refs[0].(*string) +} + +func (q *clipboardQueue) ProcessReadClipboard(refs []interface{}) { + if q.receivers == nil { + q.receivers = make(map[event.Tag]struct{}) + } + tag := refs[0].(event.Tag) + if _, ok := q.receivers[tag]; !ok { + q.receivers[tag] = struct{}{} + q.requested = false + } +} |