I'm building a macOS app where my app's window should always stay below a specific window from another mac app, but I'm struggling with stopping my window coming forward.
My app window should remain interactive, be able to receive keyboard input and resize without it being brought to the front.
What I've tried:
1. Setting window order on mouseDown
events:
myWindow.order(.below, relativeTo: targetWindow.windowNumber)
- This works sometimes, but there's a noticeable flicker where my app window comes briefly to the front before being sent back down
- Other times it won't work on mouseDown events - I imagine this is due to race conditions
2. Using shouldDelayWindowOrdering
and preventWindowOrdering()
on subclassed view:
class CustomView: NSView {
override func acceptsFirstMouse(for event: NSEvent?) -> Bool {
true
}
override func shouldDelayWindowOrdering(for event: NSEvent) -> Bool {
return true
}
override func mouseDown(with event: NSEvent) {
NSApplication.shared.preventWindowOrdering()
super.mouseDown(with: event)
}
}
- This partially works - it prevents my window from coming forward when clicking inside the content area
- However, clicking the title bar or resizing the window still brings my window to the front, which breaks the expected behavior.
- Can I include the titlebar somehow?
Is there anyway to achieve the behaviour I'm looking for? I'm open to utilising private APIs, or a creative approach.
Any help would be greatly appreciated!
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744281883a4566608.html
评论列表(0条)