Scoop API

scoop:scoop.window:0.1.0

src/native/input/delivery.scoop

Selected production source · src/native/input/delivery.scoop

1package scoop.window
3/** Accepted attachment work can be discarded on shutdown; the application owns that cleanup. */
4internal class NativeInputDelivery(
5 val application: ApplicationOwner,
6 native: Ptr<Unit>,
7 val time: InputTime
8) {
9 var pointer: Ptr<Unit>? = Some(native)
10 fun close() {
11 val value = pointer ?: return
12 pointer = None
13 @Unsafe
14 {
15 nativeInputRelease(value)
16 }
17 for (index in 0L ..< application.pendingInputs.size)
18 if (application.pendingInputs[index] === this) {
19 application.pendingInputs.removeAt(index)
20 return
21 }
22 }
25internal struct NativeDelivery(val event: ApplicationEvent, val input: NativeInputDelivery?)
27internal fun ApplicationOwner.copyNativeInput(event: Ptr<Unit>): NativeInputDelivery? {
28 if (exiting)
29 return None
30 @Unsafe
31 {
32 val result = nativeInputCopy(event)
33 checkNativeStatus(result.error, "copy native window input")
34 when (result.pointer) {
35 case Some(val pointer) -> {
36 val input =
37 NativeInputDelivery(this, pointer, copyInputTime(nativeEventHeader(event)))
38 pendingInputs.add(input)
39 return Some(input)
40 }
41 case None -> return None
42 }
43 }
46@Extern(name = "scoop_window_input_copy")
47private fun nativeInputCopy(event: Ptr<Unit>): NativeCreateResult
49@Extern(name = "scoop_window_input_release")
50private fun nativeInputRelease(input: Ptr<Unit>)
52internal fun WindowOwner.keyboardRequestInput(): Ptr<Unit>? =
53 when (currentInput) {
54 case Some(val current) -> current.pointer
55 case None -> None
56 }