Last active
July 14, 2021 18:51
-
-
Save bjhomer/2a0035fa516dd8672fe7 to your computer and use it in GitHub Desktop.
Why not -[NSView mouseDownCanMoveWindow]?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// You might think that a view could trigger window movement by overriding -[NSView mouseDownCanMoveWindow] | |
@interface DraggyView : NSView | |
@end | |
@implementation DraggyView | |
- (BOOL)mouseDownCanMoveWindow { | |
return YES; | |
} | |
@end | |
// This probably doesn't do what you think it does, though. Specifically, it does not cause | |
// a mouseDragged: event to be turned into a window drag. The real API for allowing events to | |
// drag the window is this one: | |
@interface NSWindow : NSReponder | |
@property (getter=isMovableByWindowBackground) BOOL movableByWindowBackground; | |
@end | |
// This allows mouse events that propagate all the way up to the window (because they are | |
// not intercepted by some other view) to initiate a window drag. By default, opaque windows | |
// block mouse events from propagating up, and non-opaque views allow them to propagate. | |
// | |
// This is the behavior that is controlled by -mouseDownCanMoveWindow. If that returns YES | |
// (as it does by default from non-opaque views), then the mouse event will move up to the | |
// next view under the mouse. If NONE of the views that were under the mouse blocked it (by | |
// returning NO from -mouseDownCanMoveWindow), then the mouse event will reach the window | |
// background, and that can trigger dragging the window. | |
// | |
// However, note that this depends on every view in the view hierarchy cooperating to allow | |
// the event to propagate. If any view in the way handles those events for itself, then the | |
// event will not reach the window background, and the window drag will not be initiated. | |
// | |
// This is difficult in the Yosemite world where developers are allowed to create their own | |
// titlebar-like views (using NSVisualEffectMaterialTitlebar), because even though the view | |
// *looks* like a titlebar, it still propagates its events up the view hierarchy. There is | |
// no way for a view to say "I don't care what other views are under the mouse right now -- | |
// I just want this event to initiate a window drag." | |
// | |
// Or, at least, if such an API exists, I haven't found it. |
did you get a response, same issue right here
No response.
In case anyone finds this during a search like I did, NSWindow
now has an API for this (since 10.11):
- (void)performWindowDragWithEvent:(NSEvent *)event;
In case anyone finds this during a search like I did,
NSWindow
now has an API for this (since 10.11):- (void)performWindowDragWithEvent:(NSEvent *)event;
Thanks for this!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bug report filed: rdar://17850137