Allow click and dragging a view to drag the window itself?

d11wtq picture d11wtq · Dec 30, 2010 · Viewed 12.3k times · Source

I'm using a textured window that has a tab bar along the top of it, just below the title bar.

I've used -setContentBorderThickness:forEdge: on the window to make the gradient look right, and to make sure sheets slide out from the right position.

What's not working however, is dragging the window around. It works if I click and drag the area that's actually the title bar, but since the title bar gradient spills into a (potentially/often empty) tab bar, it's really easy to click too low and it feels really frustrating when you try to drag and realise the window is not moving.

I notice NSToolbar, while occupying roughly the same amount of space below the title bar, allows the window to be dragged around when the cursor is over it. How does one implement this?

Thanks.

Tab Bar

Answer

ArtOfWarfare picture ArtOfWarfare · Oct 20, 2013

I tried the mouseDownCanMoveWindow solution (https://stackoverflow.com/a/4564146/901641) but it didn't work for me. I got rid of that method and instead added this to my window subclass:

- (BOOL)isMovableByWindowBackground {
    return YES;
}

which worked like a charm.