How to detect a click on any title bar of a window?

I would like to find a mouse in NSWindow. In fact, I want to add functionality to the whole system by detecting a click on any NSWindow header line. However, I don't see access to anything like a title bar or chrome in NSWindow. I suppose I could listen to any click and do the math to determine if there was a click in the title bar depending on the size and location of the window, but I wanted to know if there is a better way. Thanks!

+4
source share
1 answer

You need to listen for mouseDown events on the window frame. The window frame is hidden under [[window contentView] superview]. You can subclass NSWindow and create your own implementation of the NSView frame (I think this works a little) or try to replace only the mouseDown method with your own. Here http://parmanoir.com/Custom_NSThemeFrame shows how you can do something similar for the drawRect method. Hope this helps.

+1
source

Source: https://habr.com/ru/post/1368893/


All Articles