Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 notifications but it seems it does not do what I expected.

Do you have any idea how I can achieve this?

like image 211
AP. Avatar asked Jun 10 '10 19:06

AP.


People also ask

How do you align windows on a Mac?

macOS Catalina or laterHold your pointer over the full-screen button in the upper-left corner of a window. Or click and hold the button. Choose ”Tile Window to Left of Screen” or ”Tile Window to Right of Screen” from the menu. The window then fills that side of the screen.

How do I drag and resize a window on Mac?

Finally, another option is to grab any portion of the window you can and hold down OPTION+SHIFT keys and drag, which will resize the window in any direction.


2 Answers

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

like image 192
Carl Norum Avatar answered Sep 19 '22 23:09

Carl Norum


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.

like image 28
Joshua Nozzi Avatar answered Sep 21 '22 23:09

Joshua Nozzi