-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsignals.go
132 lines (121 loc) · 4.53 KB
/
signals.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
123
124
125
126
127
128
129
130
131
132
// Copyright (c) 2023 The Go-Curses Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package ctk
import (
"context"
"github.com/go-curses/cdk"
cenums "github.com/go-curses/cdk/lib/enums"
"github.com/go-curses/cdk/lib/sync"
)
const (
SignalAllocation cdk.Signal = "allocation"
SignalCancelEvent cdk.Signal = "cancel-event"
SignalCdkEvent cdk.Signal = "cdk-event"
SignalDraw cdk.Signal = cdk.SignalDraw
SignalError cdk.Signal = "error"
SignalEventKey cdk.Signal = "key-event"
SignalEventMouse cdk.Signal = "mouse-event"
SignalEventPaste cdk.Signal = "paste-event"
SignalGainedEventFocus cdk.Signal = "gained-event-focus"
SignalGainedFocus cdk.Signal = "gained-focus"
SignalGrabEventFocus cdk.Signal = "grab-event-focus"
SignalHomogeneous cdk.Signal = "homogeneous"
SignalInvalidate cdk.Signal = "invalidate"
SignalInvalidateChanged cdk.Signal = "invalidate-changed"
SignalLostEventFocus cdk.Signal = "lost-event-focus"
SignalLostFocus cdk.Signal = "lost-focus"
SignalName cdk.Signal = "name"
SignalOrigin cdk.Signal = "origin"
SignalPackEnd cdk.Signal = "pack-end"
SignalPackStart cdk.Signal = "pack-start"
SignalReleaseEventFocus cdk.Signal = "set-event-focus"
SignalReorderChild cdk.Signal = "reorder-child"
SignalReparent cdk.Signal = "reparent"
SignalResize cdk.Signal = "resize"
SignalSetEventFocus cdk.Signal = "set-event-focus"
SignalSetFlags cdk.Signal = "set-flags"
SignalSetParent cdk.Signal = "set-parent"
SignalSetProperty cdk.Signal = cdk.SignalSetProperty
SignalSetSensitive cdk.Signal = "set-sensitive"
SignalSetSizeRequest cdk.Signal = "set-size-request"
SignalSetState cdk.Signal = "set-state"
SignalSetTheme cdk.Signal = "set-theme"
SignalSetWindow cdk.Signal = "set-window"
SignalShowAll cdk.Signal = "show-all"
SignalSpacing cdk.Signal = "spacing"
SignalTextDirection cdk.Signal = "text-direction"
SignalUnparent cdk.Signal = "unparent"
SignalUnsetFlags cdk.Signal = "unset-flags"
SignalUnsetState cdk.Signal = "unset-state"
)
type SignalEventFn = func(object Object, event cdk.Event) cenums.EventFlag
func WithArgvNoneSignal(fn func(), eventFlag cenums.EventFlag) cdk.SignalListenerFn {
return func(_ []interface{}, _ ...interface{}) cenums.EventFlag {
fn()
return eventFlag
}
}
func WithArgvNoneWithFlagsSignal(fn func() cenums.EventFlag) cdk.SignalListenerFn {
return func(_ []interface{}, _ ...interface{}) cenums.EventFlag {
return fn()
}
}
func ArgvSignalEvent(argv ...interface{}) (object Object, event cdk.Event, ok bool) {
if len(argv) == 2 {
if object, ok = argv[0].(Object); ok {
if event, ok = argv[1].(cdk.Event); ok {
return
}
event = nil
}
object = nil
}
return
}
func WithArgvSignalEvent(fn SignalEventFn) cdk.SignalListenerFn {
return func(_ []interface{}, argv ...interface{}) cenums.EventFlag {
if widget, event, ok := ArgvSignalEvent(argv...); ok {
return fn(widget, event)
}
return cenums.EVENT_STOP
}
}
func ArgvApplicationSignalStartup(argv ...interface{}) (app Application, display cdk.Display, ctx context.Context, cancel context.CancelFunc, wg *sync.WaitGroup, ok bool) {
if len(argv) == 5 {
if app, ok = argv[0].(Application); ok {
if display, ok = argv[1].(cdk.Display); ok {
if ctx, ok = argv[2].(context.Context); ok {
if cancel, ok = argv[3].(context.CancelFunc); ok {
if wg, ok = argv[4].(*sync.WaitGroup); ok {
return
}
cancel = nil
}
ctx = nil
}
display = nil
}
app = nil
}
}
return
}
func WithArgvApplicationSignalStartup(startupFn ApplicationStartupFn) cdk.SignalListenerFn {
return func(_ []interface{}, argv ...interface{}) cenums.EventFlag {
if app, display, ctx, cancel, wg, ok := ArgvApplicationSignalStartup(argv...); ok {
return startupFn(app, display, ctx, cancel, wg)
}
return cenums.EVENT_STOP
}
}