Scoop API

scoop:scoop.window:0.1.0

src/native/results.scoop

Selected production source · src/native/results.scoop

1package scoop.window
3@CLayout
4internal struct NativeCreateResult(val pointer: Ptr<Unit>?, val error: Long)
6internal fun checkNativeStatus(code: Long, operation: String) {
7 if (code == -1L) throw WindowException(operation, WindowErrorKind.Unsupported)
8 if (code == -2L) throw WindowException(operation, WindowErrorKind.Unavailable)
9 if (code == -3L) throw WindowException(operation, WindowErrorKind.Disconnected)
10 if (code == -4L) throw WindowException(operation, WindowErrorKind.InvalidState)
11 if (code == -5L) throw WindowException(operation, WindowErrorKind.ResourceBusy)
12 if (code != 0L)
13 throw WindowException(operation, WindowErrorKind.NativeFailure, nativeCode = Some(code))
16internal fun nativeRequestStatus(
17 code: Long,
18 operation: String,
19 success: RequestStatus = RequestStatus.Applied
20): RequestStatus {
21 if (code == -1L) return RequestStatus.Unsupported
22 checkNativeStatus(code, operation)
23 return success
26internal fun requireCreationStatus(status: RequestStatus, operation: String) {
27 if (status == RequestStatus.Unsupported)
28 throw WindowException(operation, WindowErrorKind.Unsupported)
31internal fun created(result: NativeCreateResult, operation: String): Ptr<Unit> {
32 when (result.pointer) {
33 case Some(val pointer) -> return pointer
35 case None -> {
36 checkNativeStatus(result.error, operation)
37 throw WindowException(operation, WindowErrorKind.NativeFailure)
38 }
39 }
42internal fun flag(value: Boolean): Int = if (value) 1 else 0