Post

Replies

Boosts

Views

Activity

Reply to only menu item Mac app
Turns out it has nothing to do with main.swift. I have a dictionary defined as dict : [ CGWindowID : NSWindow]. if you do dict.removeValue(forKey: key)?.close() this double deallocates the NSWindow if dict[key] was the last strong reference. Found this by instead of Run in Xcode, you do Profile and select Zombie and I found that this NSWindow reference count goes to -1. oops.
Topic: App & System Services SubTopic: Core OS Tags:
Jan ’23
Reply to only menu item Mac app
Should have said "Status menu item" instead of "menu item". Regardless, changed main.swift to this: import Cocoa let app = NSApplication.shared let delegate = AppDelegate() withExtendedLifetime(delegate, {         app.delegate = delegate         app.run()         app.delegate = nil   }) seems to fix the occasional crash. This just forces a hard link to AppDelegate() so it doesn't get deallocated, apparently.
Topic: App & System Services SubTopic: Core OS Tags:
Jan ’23
Reply to Enumerate the desktops (spaces) in each NSScreen
You can figure out which Desktops go with which Screens by comparing their CGRect (be careful, some CGRect has the vertical axis direction flipped- see https://entonos.com/index.php/2021/05/20/which-cgrect-was-that/). However, I have yet to figure out which Space corresponds to which Desktop (or vice versa). The best I've found is to ask CoreGraphics if a Desktop window is currently on screen. You then know that Desktop is on the current Space. Of course, you don't know which Space you're actually on.
Topic: UI Frameworks SubTopic: AppKit Tags:
May ’22
Reply to Window in all spaces
let window : NSWindow? = nil ... window?.collectionBehavior = .canJoinAllSpaces // window will be in all Spaces window?.collectionBehavior = .moveToActiveSpace // when window is activated, move to active Space window?.collectionBehavior = .stationary // Expose doesn't affect window, so it stays visible and stationary, like the Desktop window window?.collectionBehavior = .managed // window participates in Spaces and Expose (i.e. normal window). there are other options....
Topic: Programming Languages SubTopic: Swift Tags:
May ’22
Reply to only menu item Mac app
Turns out it has nothing to do with main.swift. I have a dictionary defined as dict : [ CGWindowID : NSWindow]. if you do dict.removeValue(forKey: key)?.close() this double deallocates the NSWindow if dict[key] was the last strong reference. Found this by instead of Run in Xcode, you do Profile and select Zombie and I found that this NSWindow reference count goes to -1. oops.
Topic: App & System Services SubTopic: Core OS Tags:
Replies
Boosts
Views
Activity
Jan ’23
Reply to only menu item Mac app
Should have said "Status menu item" instead of "menu item". Regardless, changed main.swift to this: import Cocoa let app = NSApplication.shared let delegate = AppDelegate() withExtendedLifetime(delegate, {         app.delegate = delegate         app.run()         app.delegate = nil   }) seems to fix the occasional crash. This just forces a hard link to AppDelegate() so it doesn't get deallocated, apparently.
Topic: App & System Services SubTopic: Core OS Tags:
Replies
Boosts
Views
Activity
Jan ’23
Reply to Enumerate the desktops (spaces) in each NSScreen
You can figure out which Desktops go with which Screens by comparing their CGRect (be careful, some CGRect has the vertical axis direction flipped- see https://entonos.com/index.php/2021/05/20/which-cgrect-was-that/). However, I have yet to figure out which Space corresponds to which Desktop (or vice versa). The best I've found is to ask CoreGraphics if a Desktop window is currently on screen. You then know that Desktop is on the current Space. Of course, you don't know which Space you're actually on.
Topic: UI Frameworks SubTopic: AppKit Tags:
Replies
Boosts
Views
Activity
May ’22
Reply to Window in all spaces
let window : NSWindow? = nil ... window?.collectionBehavior = .canJoinAllSpaces // window will be in all Spaces window?.collectionBehavior = .moveToActiveSpace // when window is activated, move to active Space window?.collectionBehavior = .stationary // Expose doesn't affect window, so it stays visible and stationary, like the Desktop window window?.collectionBehavior = .managed // window participates in Spaces and Expose (i.e. normal window). there are other options....
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
May ’22