Search code examples
macosnsviewnswindow

How to drag a window by dragging its content area, similarly to dragging the title area


My macOS app's NSWindow has a bottom status area that has no interactive parts. I would like the user to be able to drag the entire window by dragging that status area with the mouse, just like the user can drag the window by its title area.

How do I accomplish that in a clean way?

I expect that I should be able to forward the drag operation of the status area's NSView to the code that handles dragging the entire window somehow.


Solution

  • Using NSWindow.isMovableByWindowBackground or call NSWindow.performDrag(with: NSEvent) from within your NSView.

    ObjC example:

    -(void)mouseDragged:(NSEvent *)event {
        [self.window performWindowDragWithEvent:event];
    }