|
| 1 | +// Most of these are marked as MainThreadOnly automatically |
1 | 2 | data! {
|
| 3 | + // TODO: This should be one of MainThreadOnly or Immutable (+Send/Sync) |
| 4 | + class NSAppearance { |
| 5 | + unsafe -appearanceNamed; |
| 6 | + unsafe -bestMatchFromAppearancesWithNames; |
| 7 | + } |
| 8 | + |
| 9 | + class NSApplication { |
| 10 | + unsafe +sharedApplication; |
| 11 | + |
| 12 | + unsafe -currentEvent; |
| 13 | + unsafe -postEvent_atStart; |
| 14 | + unsafe -presentationOptions; |
| 15 | + unsafe -windows; |
| 16 | + unsafe -keyWindow; |
| 17 | + unsafe -setDelegate; |
| 18 | + unsafe -setPresentationOptions; |
| 19 | + unsafe -hide; |
| 20 | + unsafe -orderFrontCharacterPalette; |
| 21 | + unsafe -hideOtherApplications; |
| 22 | + unsafe -stop; |
| 23 | + unsafe -activateIgnoringOtherApps; |
| 24 | + unsafe -requestUserAttention; |
| 25 | + unsafe -setActivationPolicy; |
| 26 | + unsafe -setMainMenu; |
| 27 | + unsafe -effectiveAppearance; |
| 28 | + unsafe -setAppearance; |
| 29 | + |
| 30 | + // `run` cannot be safe, the user must ensure there is no re-entrancy. |
| 31 | + } |
| 32 | + |
| 33 | + // Documentation says: |
| 34 | + // > Color objects are immutable and thread-safe |
| 35 | + // |
| 36 | + // TODO: Send + Sync |
| 37 | + class NSColor: Immutable { |
| 38 | + unsafe -clear; |
| 39 | + } |
| 40 | + |
| 41 | + class NSControl { |
| 42 | + unsafe -isEnabled; |
| 43 | + unsafe -setEnabled; |
| 44 | + } |
| 45 | + |
| 46 | + // NSCursor is immutable, stated here: |
| 47 | + // https://developer.apple.com/documentation/appkit/nscursor/1527062-image?language=objc |
| 48 | + // |
| 49 | + // TODO: Send + Sync |
| 50 | + class NSCursor: Immutable { |
| 51 | + unsafe -initWithImage_hotSpot; |
| 52 | + |
| 53 | + unsafe -arrowCursor; |
| 54 | + unsafe -IBeamCursor; |
| 55 | + unsafe -pointingHandCursor; |
| 56 | + unsafe -closedHandCursor; |
| 57 | + unsafe -openHandCursor; |
| 58 | + unsafe -resizeLeftCursor; |
| 59 | + unsafe -resizeRightCursor; |
| 60 | + unsafe -resizeLeftRightCursor; |
| 61 | + unsafe -resizeUpCursor; |
| 62 | + unsafe -resizeDownCursor; |
| 63 | + unsafe -resizeUpDownCursor; |
| 64 | + unsafe -crosshairCursor; |
| 65 | + unsafe -disappearingItemCursor; |
| 66 | + unsafe -operationNotAllowedCursor; |
| 67 | + unsafe -dragLinkCursor; |
| 68 | + unsafe -dragCopyCursor; |
| 69 | + unsafe -contextualMenuCursor; |
| 70 | + unsafe -IBeamCursorForVerticalLayout; |
| 71 | + } |
| 72 | + |
| 73 | + // Since this is immutable, it _may_ be possible to make Send+Sync, but |
| 74 | + // let's refrain from doing so, because of: |
| 75 | + // > Safely handled only on the same thread, whether that be the main |
| 76 | + // > thread or a secondary thread; otherwise you run the risk of having |
| 77 | + // > events get out of sequence. |
| 78 | + // <https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/CocoaFundamentals/AddingBehaviortoaCocoaProgram/AddingBehaviorCocoa.html#//apple_ref/doc/uid/TP40002974-CH5-SW47> |
| 79 | + // <https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/Multithreading/ThreadSafetySummary/ThreadSafetySummary.html#//apple_ref/doc/uid/10000057i-CH12-123383> |
| 80 | + class NSEvent: Immutable { |
| 81 | + |
| 82 | + } |
| 83 | + |
| 84 | + // Documented Thread-Unsafe, but: |
| 85 | + // > One thread can create an NSImage object, draw to the image buffer, |
| 86 | + // > and pass it off to the main thread for drawing. The underlying image |
| 87 | + // > cache is shared among all threads. |
| 88 | + // <https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/Multithreading/ThreadSafetySummary/ThreadSafetySummary.html#//apple_ref/doc/uid/10000057i-CH12-126728> |
| 89 | + // |
| 90 | + // So really only unsafe to mutate on several threads. |
| 91 | + // |
| 92 | + // Unsure yet if it would be beneficial to mark this as `Mutable`, or if |
| 93 | + // we should just keep it as interiormutable? |
| 94 | + class NSImage { |
| 95 | + unsafe -initWithData; |
| 96 | + unsafe -initByReferencingFile; |
| 97 | + } |
| 98 | + |
| 99 | + class NSMenu: MainThreadOnly { |
| 100 | + unsafe -init; |
| 101 | + unsafe -addItem; |
| 102 | + } |
| 103 | + |
| 104 | + // Any modification of the target or the action has to remain `unsafe` |
| 105 | + class NSMenuItem: MainThreadOnly { |
| 106 | + unsafe -init; |
| 107 | + unsafe +separatorItem; |
| 108 | + unsafe -setKeyEquivalentModifierMask; |
| 109 | + unsafe -setSubmenu; |
| 110 | + } |
| 111 | + |
| 112 | + class NSPasteboard { |
| 113 | + unsafe -propertyListForType; |
| 114 | + } |
| 115 | + |
| 116 | + // Documented as "Thread-Unsafe" |
| 117 | + class NSResponder {} |
| 118 | + |
| 119 | + // Accesses the shared application, and hence is main thread only (even |
| 120 | + // though not marked so in Swift). |
| 121 | + class NSScreen: MainThreadOnly { |
| 122 | + unsafe +mainScreen; |
| 123 | + unsafe +screens; |
| 124 | + unsafe -frame; |
| 125 | + unsafe -visibleFrame; |
| 126 | + unsafe -deviceDescription; |
| 127 | + unsafe -backingScaleFactor; |
| 128 | + } |
| 129 | + |
| 130 | + class NSWindowTabGroup: MainThreadOnly { |
| 131 | + unsafe -windows; |
| 132 | + unsafe -setSelectedWindow; |
| 133 | + } |
| 134 | + |
| 135 | + class NSTextInputContext: MainThreadOnly { |
| 136 | + unsafe -invalidateCharacterCoordinates; |
| 137 | + unsafe -discardMarkedText; |
| 138 | + unsafe -selectedKeyboardInputSource; |
| 139 | + } |
| 140 | + |
2 | 141 | // Subclasses `NSMutableAttributedString`, though I think this should
|
3 | 142 | // actually be `InteriorMutable`?
|
4 | 143 | class NSTextStorage: Mutable {}
|
| 144 | + |
| 145 | + // Documented as "Main Thread Only". |
| 146 | + // > generally thread safe, although operations on views such as creating, |
| 147 | + // > resizing, and moving should happen on the main thread. |
| 148 | + // <https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/CocoaFundamentals/AddingBehaviortoaCocoaProgram/AddingBehaviorCocoa.html#//apple_ref/doc/uid/TP40002974-CH5-SW47> |
| 149 | + // |
| 150 | + // > If you want to use a thread to draw to a view, bracket all drawing code |
| 151 | + // > between the lockFocusIfCanDraw and unlockFocus methods of NSView. |
| 152 | + // <https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/Multithreading/ThreadSafetySummary/ThreadSafetySummary.html#//apple_ref/doc/uid/10000057i-CH12-123351-BBCFIIEB> |
| 153 | + class NSView { |
| 154 | + unsafe -frame; |
| 155 | + unsafe -bounds; |
| 156 | + unsafe -inputContext; |
| 157 | + unsafe -visibleRect; |
| 158 | + unsafe -hasMarkedText; |
| 159 | + unsafe -convertPoint_fromView; |
| 160 | + unsafe -window; |
| 161 | + |
| 162 | + unsafe -setWantsBestResolutionOpenGLSurface; |
| 163 | + unsafe -setWantsLayer; |
| 164 | + unsafe -setPostsFrameChangedNotifications; |
| 165 | + unsafe -removeTrackingRect; |
| 166 | + unsafe -addCursorRect_cursor; |
| 167 | + unsafe -setHidden; |
| 168 | + } |
| 169 | + |
| 170 | + // Documented as "Main Thread Only", but: |
| 171 | + // > Thread safe in that you can create and manage them on a secondary |
| 172 | + // > thread. |
| 173 | + // <https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/CocoaFundamentals/AddingBehaviortoaCocoaProgram/AddingBehaviorCocoa.html#//apple_ref/doc/uid/TP40002974-CH5-SW47> |
| 174 | + // <https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/Multithreading/ThreadSafetySummary/ThreadSafetySummary.html#//apple_ref/doc/uid/10000057i-CH12-123364> |
| 175 | + // |
| 176 | + // So could in theory be `Send`, and perhaps also `Sync` - but we would |
| 177 | + // like interior mutability on windows, since that's just much easier, and |
| 178 | + // in that case, they can't be! |
| 179 | + class NSWindow { |
| 180 | + // Initializers are not safe, since it is critical to memory safety |
| 181 | + // that `window.setReleasedWhenClosed(false)` is called. |
| 182 | + |
| 183 | + unsafe -frame; |
| 184 | + unsafe -backingScaleFactor; |
| 185 | + unsafe -contentView; |
| 186 | + unsafe -setContentView; |
| 187 | + unsafe -setInitialFirstResponder; |
| 188 | + unsafe -makeFirstResponder; |
| 189 | + unsafe -contentRectForFrameRect; |
| 190 | + unsafe -screen; |
| 191 | + unsafe -setContentSize; |
| 192 | + unsafe -setFrameTopLeftPoint; |
| 193 | + unsafe -setMinSize; |
| 194 | + unsafe -setMaxSize; |
| 195 | + unsafe -setResizeIncrements; |
| 196 | + unsafe -contentResizeIncrements; |
| 197 | + unsafe -setContentResizeIncrements; |
| 198 | + unsafe -setFrame_display; |
| 199 | + unsafe -setMovable; |
| 200 | + unsafe -setSharingType; |
| 201 | + unsafe -setTabbingMode; |
| 202 | + unsafe -setOpaque; |
| 203 | + unsafe -hasShadow; |
| 204 | + unsafe -setHasShadow; |
| 205 | + unsafe -setIgnoresMouseEvents; |
| 206 | + unsafe -setBackgroundColor; |
| 207 | + unsafe -styleMask; |
| 208 | + unsafe -setStyleMask; |
| 209 | + unsafe -registerForDraggedTypes; |
| 210 | + unsafe -makeKeyAndOrderFront; |
| 211 | + unsafe -orderFront; |
| 212 | + unsafe -miniaturize; |
| 213 | + unsafe -sender; |
| 214 | + unsafe -toggleFullScreen; |
| 215 | + unsafe -orderOut; |
| 216 | + unsafe -zoom; |
| 217 | + unsafe -selectNextKeyView; |
| 218 | + unsafe -selectPreviousKeyView; |
| 219 | + unsafe -firstResponder; |
| 220 | + unsafe -standardWindowButton; |
| 221 | + unsafe -setTitle; |
| 222 | + unsafe -title; |
| 223 | + unsafe -setAcceptsMouseMovedEvents; |
| 224 | + unsafe -setTitlebarAppearsTransparent; |
| 225 | + unsafe -setTitleVisibility; |
| 226 | + unsafe -setMovableByWindowBackground; |
| 227 | + unsafe -setLevel; |
| 228 | + unsafe -setAllowsAutomaticWindowTabbing; |
| 229 | + unsafe -setTabbingIdentifier; |
| 230 | + unsafe -setDocumentEdited; |
| 231 | + unsafe -occlusionState; |
| 232 | + unsafe -center; |
| 233 | + unsafe -isResizable; |
| 234 | + unsafe -isMiniaturizable; |
| 235 | + unsafe -hasCloseBox; |
| 236 | + unsafe -isMiniaturized; |
| 237 | + unsafe -isVisible; |
| 238 | + unsafe -isKeyWindow; |
| 239 | + unsafe -isZoomed; |
| 240 | + unsafe -allowsAutomaticWindowTabbing; |
| 241 | + unsafe -selectNextTab; |
| 242 | + unsafe -tabbingIdentifier; |
| 243 | + unsafe -tabGroup; |
| 244 | + unsafe -isDocumentEdited; |
| 245 | + unsafe -close; |
| 246 | + unsafe -performWindowDragWithEvent; |
| 247 | + unsafe -invalidateCursorRectsForView; |
| 248 | + unsafe -setDelegate; |
| 249 | + unsafe -sendEvent; |
| 250 | + |
| 251 | + // `addChildWindow:ordered:` is not safe, as cycles must be prevented |
| 252 | + } |
5 | 253 | }
|
0 commit comments