Can you redirect mouse input to the resizing border in Cocoa?

Viewed 27

I've been writing a system-wide utility application that does custom window resizing that, if a user is pressing a certain combination of modifier keys, does custom moving/sizing accordingly.

Think of the window divided into a 3x3 area with the center zone acting as 'move' and the surrounding eight other zones acting as oversized 'resize' grips.

The "problem" is I'm doing all of this manually... first getting the window bounds, then tracking the mouse and updating the bounds as desired via the accessibility APIs, and having to manually specify the cursor for all the independent zones.

However, I'm wondering if I'm doing more work than I need to. After all, Cocoa already supports all of these behaviors. It just requires redirecting the mouse to the titlebar or edge, or at least convincing the system that's where the mouse currently is.

This is easy in Windows because they have a NC_HITTEST message that you can intercept and return the corresponding 'zone' that you want the mouse to act as if it were in, but I'm not aware of any such thing on macOS.

I know this logic is in there as, for instance, if the view were in my own application, I can simply do this to drag the window by the client area, the same as if they had grabbed the titlebar. I'm trying to do the same thing but for all nine zones.

class DraggableView : NSView {

    override public func mouseDown(with event: NSEvent) {
        window?.performDrag(with: event)
    }
}

Again, this only handles 'move'-type events, not resize type events.

Is there a way to 'redirect' mouse input from the client area of a window to one of the eight 'resize' areas...

  • top
  • bottom
  • left
  • right
  • top-left
  • top-right
  • bottom-left
  • bottom-right

FWIW, I'd prefer Swift if possible, but can use Objective-C if required.

0 Answers
Related