Scoop API

scoop:scoop.window:0.1.0

src/frame/window.scoop

Selected production source · src/frame/window.scoop

1package scoop.window
3/** Queries the native window decoration capabilities on the owner thread. */
4public val Window.frameCapabilities: WindowFrameCapabilities
5 get() {
6 owner.requireOpen()
7 return frameCapabilities()
8 }
10/** Changes before queued frame notifications when native region coordinates become stale. */
11public val Window.frameRevision: ULong get() {
12 owner.requireOpen()
13 @Unsafe
14 {
15 return nativeWindowFrameRevision(owner.pointer!!)
16 }
19public val Window.frameMetrics: WindowFrameMetrics? get() {
20 owner.requireOpen()
21 @Unsafe
22 {
23 val frame = nativeWindowFrameSnapshot(owner.pointer!!)
24 if (frame.ready == 0)
25 return None
26 val buttons = ArrayList<WindowSystemButtonBounds>()
27 for (
28 button in [
29 WindowSystemButton.Close,
30 WindowSystemButton.Minimize,
31 WindowSystemButton.Maximize
32 ]
33 ) {
34 when (nativeWindowFrameButton(owner.pointer!!, systemButtonCode(button)).logical()) {
35 case Some(val rect) -> buttons.add(WindowSystemButtonBounds(button, rect))
36 case None -> {}
37 }
38 }
39 return Some(
40 WindowFrameMetrics(
41 frameValue(frame.mode),
42 nativeWindowSnapshot(owner.pointer!!).metrics(),
43 frame.layout.logical(),
44 buttons.toArray(),
45 if (frame.border.isFinite() && frame.border >= 0.0)
46 Some(frame.border)
47 else
48 None
49 )
50 )
51 }
54public fun Window.setFrame(frame: WindowFrame): RequestStatus {
55 owner.requireOpen()
56 @Unsafe
57 {
58 val status =
59 nativeRequestStatus(nativeWindowFrame(owner.pointer!!, frameCode(frame)), "frame")
60 if (status == RequestStatus.Unsupported)
61 return status
62 }
63 setEnabledButtons(owner.buttons)
64 return RequestStatus.Applied
67public fun Window.setShadow(shadow: WindowShadow): RequestStatus {
68 owner.requireOpen()
69 @Unsafe
70 {
71 return nativeRequestStatus(
72 nativeWindowShadow(owner.pointer!!, flag(shadow == WindowShadow.System)),
73 "shadow"
74 )
75 }
78public fun Window.setWindowRegion(region: WindowRegion?): RequestStatus = setNativeRegion(0, region)
80public fun Window.setInputRegion(region: WindowRegion?): RequestStatus = setNativeRegion(1, region)
82public fun Window.setIgnoreMouse(ignore: Boolean): RequestStatus {
83 owner.requireOpen()
84 @Unsafe
85 {
86 return nativeRequestStatus(
87 nativeWindowIgnoreMouse(owner.pointer!!, flag(ignore)),
88 "ignore mouse"
89 )
90 }
93private fun Window.setNativeRegion(kind: Int, region: WindowRegion?): RequestStatus {
94 owner.requireOpen()
95 val rectangles = ArrayList<NativeFrameRect>()
96 var present = 0
97 when (region) {
98 case Some(val value) -> {
99 present = 1
100 for (rect in value.rectangles)
101 if (rect.size.width > 0.0 && rect.size.height > 0.0)
102 rectangles.add(nativeFrameRect(rect))
103 }
104 case None -> {}
105 }
106 val regionPresent = present
107 @Unsafe
108 {
109 return rectangles.toArray().withDataPointer {
110 data,
111 count -> @Unsafe
112 {
113 return@withDataPointer nativeRequestStatus(
114 nativeWindowRegion(owner.pointer!!, kind, regionPresent, data, count),
115 "region"
116 )
117 }
118 }
119 }
122/** Replaces the complete native snapshot; an empty array restores ordinary client input. */
123public fun Window.setHitRegions(regions: Array<WindowHitRegion>): RequestStatus {
124 owner.requireOpen()
125 val rectangles = ArrayList<NativeHitRect>()
126 for (item in regions)
127 for (rect in item.region.rectangles)
128 if (rect.size.width > 0.0 && rect.size.height > 0.0)
129 rectangles.add(NativeHitRect(nativeFrameRect(rect), hitRoleCode(item.role)))
130 @Unsafe
131 {
132 return rectangles.toArray().withDataPointer {
133 data,
134 count -> @Unsafe
135 {
136 return@withDataPointer nativeRequestStatus(
137 nativeWindowHitRegions(owner.pointer!!, data, count),
138 "hit regions"
139 )
140 }
141 }
142 }
145private fun nativeFrameRect(rect: LogicalRect): NativeFrameRect =
146 NativeFrameRect(rect.origin.x, rect.origin.y, rect.size.width, rect.size.height)
148internal fun frameCapabilities(): WindowFrameCapabilities {
149 @Unsafe
150 {
151 val bits = nativeFrameCapabilities()
152 return WindowFrameCapabilities(
153 bits.and(1) != 0,
154 bits.and(2) != 0,
155 bits.and(4) != 0,
156 bits.and(8) != 0,
157 bits.and(16) != 0,
158 bits.and(32) != 0,
159 bits.and(64) != 0,
160 bits.and(128) != 0,
161 bits.and(256) != 0,
162 bits.and(512) != 0,
163 bits.and(1024) != 0,
164 bits.and(2048) != 0
165 )
166 }