-
Notifications
You must be signed in to change notification settings - Fork 1
/
window.go
122 lines (102 loc) · 2.36 KB
/
window.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// SPDX-License-Identifier: Unlicense OR MIT
// package wm implements platform specific windows
// and GPU contexts.
package wm
import (
"errors"
"github.com/cybriq/p9/pkg/gel/gio/gpu"
"github.com/cybriq/p9/pkg/gel/gio/io/event"
"github.com/cybriq/p9/pkg/gel/gio/io/pointer"
"github.com/cybriq/p9/pkg/gel/gio/io/system"
"github.com/cybriq/p9/pkg/gel/gio/unit"
)
type Size struct {
Width unit.Value
Height unit.Value
}
type Options struct {
Size *Size
MinSize *Size
MaxSize *Size
Title *string
WindowMode *WindowMode
}
type WindowMode uint8
const (
Windowed WindowMode = iota
Fullscreen
)
type FrameEvent struct {
system.FrameEvent
Sync bool
}
type Callbacks interface {
SetDriver(d Driver)
Event(e event.Event)
}
type Context interface {
API() gpu.API
Present() error
MakeCurrent() error
Release()
Lock()
Unlock()
}
// ErrDeviceLost is returned from Context.Present when
// the underlying GPU device is gone and should be
// recreated.
var ErrDeviceLost = errors.New("GPU device lost")
// Driver is the interface for the platform implementation
// of a window.
type Driver interface {
// SetAnimating sets the animation flag. When the window is animating,
// FrameEvents are delivered as fast as the display can handle them.
SetAnimating(anim bool)
// ShowTextInput updates the virtual keyboard state.
ShowTextInput(show bool)
NewContext() (Context, error)
// ReadClipboard requests the clipboard content.
ReadClipboard()
// WriteClipboard requests a clipboard write.
WriteClipboard(s string)
// Option processes option changes.
Option(opts *Options)
// SetCursor updates the current cursor to name.
SetCursor(name pointer.CursorName)
// Close the window.
Close()
}
type windowRendezvous struct {
in chan windowAndOptions
out chan windowAndOptions
errs chan error
}
type windowAndOptions struct {
window Callbacks
opts *Options
}
func newWindowRendezvous() *windowRendezvous {
wr := &windowRendezvous{
in: make(chan windowAndOptions),
out: make(chan windowAndOptions),
errs: make(chan error),
}
go func() {
var main windowAndOptions
var out chan windowAndOptions
for {
select {
case w := <-wr.in:
var err error
if main.window != nil {
err = errors.New("multiple windows are not supported")
}
wr.errs <- err
main = w
out = wr.out
case out <- main:
}
}
}()
return wr
}