开发者

Detect when a Mac OS X window is resized or moved

I am writing an application which must know when any window is resized or moved. I have looked at notifi开发者_运维技巧cations but it seems it does not do what I expected.

Do you have any idea how I can achieve this?


Give your window a delegate. The NSWindowDelegate protocol has windowWillResize:toSize: and windowWillMove: methods.


Given your response to Carl's answer, I'd suggest the Accessibility API, which can give you access (and I believe frame change notifications) for all windows, not just your app's.


If you want window size/ordering then take a look at CGWindow.h. CGWindowListCreateDescriptionFromArray() is probably what you want.

NSWindowList() is also useful for a list of windows.


If you need to manage MacOS Windows try using Accessibility.

AX very tricky (low level/ asyc) but these two githubs help a lot.

https://github.com/tmandry/Swindler

uses

https://github.com/tmandry/AXSwift

They provide callbacks for windows create and move etc.

Start with Swindler


In Swift my AppDelegate looked like this:

func applicationDidFinishLaunching(notification: NSNotification) {
    // Set NSWindowDelegate to respond to windowWillResize
    window.delegate = self
}

func windowWillResize(sender: NSWindow, toSize frameSize: NSSize) -> NSSize {
    println(frameSize)
    return frameSize
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜