Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion siwin.nimble
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ when defined(android):
requires "https://github.com/yglukhov/android"

when defined(macosx):
requires "darwin >= 0.2.2"
requires "darwin >= 0.2.3"

feature "dev":
requires "opengl"
Expand Down
19 changes: 15 additions & 4 deletions src/siwin/platforms/cocoa/window.nim
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type
WindowCocoaObj* = object of Window
handle: NsWindow
trackingArea: NSTrackingArea
updatingTrackingAreas: bool
markedText: NSString
lastClickTime: array[MouseButton, Time]
lastDragStatus: DragStatus
Expand Down Expand Up @@ -985,7 +986,7 @@ method `icon=`*(window: WindowCocoa, _: nil.typeof) =
discard NSApplication.sharedApplication()
if NSApp == nil:
return
NSApplication.setApplicationIconImage(cast[NSImage](nil))
NSApp.setApplicationIconImage(cast[NSImage](nil))

method `icon=`*(window: WindowCocoa, v: PixelBuffer) =
if v.size.x * v.size.y == 0:
Expand Down Expand Up @@ -1017,7 +1018,7 @@ method `icon=`*(window: WindowCocoa, v: PixelBuffer) =
copyMem(rep.bitmapData, buffer.data, buffer.size.x * buffer.size.y * 4)
let img = NSImage.alloc().initWithSize(NSMakeSize(buffer.size.x.float64, buffer.size.y.float64))
img.addRepresentation(cast[NSImageRep](rep))
NSApplication.setApplicationIconImage(img)
NSApp.setApplicationIconImage(img)
rep.release()
img.release()

Expand Down Expand Up @@ -1328,6 +1329,16 @@ proc init =

addMethod "updateTrackingAreas", proc(self: Id, cmd: Sel): Id {.cdecl.} =
getWindow(self)

# AppKit may re-enter updateTrackingAreas while handling super; guard recursion.
# TODO(macOS): Move to a winit-style approach where we create one tracking area
# with NSTrackingInVisibleRect during view setup and avoid this override entirely.
# That should remove this re-entrancy hazard and reduce tracking-area churn.
if window.updatingTrackingAreas:
return
window.updatingTrackingAreas = true
defer:
window.updatingTrackingAreas = false

if window.trackingArea != nil:
cast[NSView](self).removeTrackingArea(window.trackingArea)
Expand All @@ -1342,8 +1353,8 @@ proc init =
)

cast[NSView](self).addTrackingArea(window.trackingArea)
callSuper(cast[NSObject](self), cmd)

callSuper(void, cast[NSObject](self), cmd)

addMethod "draggingEntered:", proc(
self: Id, cmd: Sel, sender: NSDraggingInfo
Expand Down
Loading