Scoop API

scoop:scoop.window:0.1.0

src/frame/operations.scoop

Selected production source · src/frame/operations.scoop

1package scoop.window
3/** Requests native dragging from this window's currently dispatched input. */
4public fun Window.beginMove(): RequestStatus = requestSystemOperation(0, 0)
6public fun Window.beginResize(edge: WindowResizeEdge): RequestStatus =
7 requestSystemOperation(1, resizeEdgeCode(edge))
9public fun Window.showWindowMenu(): RequestStatus = requestSystemOperation(2, 0)
11private fun Window.requestSystemOperation(kind: Int, edge: Int): RequestStatus {
12 owner.requireInteractive()
13 val input =
14 owner.currentInput ?:
15 throw WindowException("system window operation", WindowErrorKind.InvalidState)
16 val pointer =
17 input.pointer ?:
18 throw WindowException("system window operation", WindowErrorKind.InvalidState)
19 if (owner.systemOperationPending)
20 throw WindowException("system window operation", WindowErrorKind.ResourceBusy)
21 @Unsafe
22 {
23 val result = nativeSystemOperationPrepare(owner.pointer!!, pointer, kind, edge)
24 if (result.error == -1L)
25 return RequestStatus.Unsupported
26 if (result.error == -4L)
27 throw WindowException("system window input", WindowErrorKind.InvalidState)
28 val operation = created(result, "prepare system window operation")
29 owner.systemOperationPending = true
30 owner.systemOperationCancelled = false
31 owner.pendingSystemCancellation = Some(input.time)
32 owner.leases += 1L
33 owner.application.deferNativeOperation {
34 try {
35 if (
36 owner.phase ==
37 WindowState.Open &&
38 !owner.application.exiting &&
39 !owner.inputBlocked &&
40 !owner.systemOperationCancelled
41 ) {
42 @Unsafe
43 {
44 checkNativeStatus(
45 nativeSystemOperationRun(operation),
46 "system window operation"
47 )
48 }
49 }
50 } finally {
51 @Unsafe
52 {
53 nativeSystemOperationRelease(operation)
54 }
55 owner.systemOperationPending = false
56 owner.leases -= 1L
57 owner.application.mailbox.wake()
58 }
59 }
60 }
61 return RequestStatus.Requested
64@Extern(name = "scoop_window_system_operation_prepare")
65private fun nativeSystemOperationPrepare(
66 window: Ptr<Unit>,
67 input: Ptr<Unit>,
68 kind: Int,
69 edge: Int
70): NativeCreateResult
72@Extern(name = "scoop_window_system_operation_run")
73private fun nativeSystemOperationRun(operation: Ptr<Unit>): Long
75@Extern(name = "scoop_window_system_operation_release")
76private fun nativeSystemOperationRelease(operation: Ptr<Unit>)