NSWindow - detect movement by drag vs animation - macos

I have an NSWindow on which I set movableByWindowBackground = YES so that it can be moved by dragging it's contents. I then implement it's windowDidMove delegate method so I can detect when it moves, but at times I'm also animating this window. I'd like to detect when the window is moved due to a mouse drag vs an animation. Is there an easy way to do this?

Related

How to drag window from an element inside WKWebView?

I want to create a "frameless" window (HiddenTitleBarWindowStyle). Inside this window there will a WKWebView spanning from edge to edge. Is there a way to have an element inside the webview to be the drag handle for the entire window?
Electron has something like this and I'm wondering how to implement it in SwiftUI.
https://www.electronjs.org/docs/latest/api/frameless-window#draggable-region
I tried making the window movable by the background (isMovableByWindowBackground = true). However, the WKWebView seems to stop the event propagation.

How to animate closing NSWindow to NSStatusItem?

When you minimize an NSWindow you get a nice animation to the Dock. How to achieve a similar animation for "minimizing" to an NSStatusItem in the menu bar?
I have it set up where the NSStatusItem appears when you close the NSWindow but there is no animation.
I've tried animating the window frame but due to various layout contraints it has a minimum size that gets in the way.
To animate the whole NSWindow is not the right way and will result in a rubbish looking animation. I would suggest to capture a snapshot of the window and adding it to a transparent full screen window to animate layer of the image view. This way its fare more smooth. To get an idea how it could be implemented please take a look at this project on git.
Hope this will help.

Strange behaviour of NSShadow for customized NSWindow

I subclass the NSWindow and use [self setHasShadow:YES] to set the shadow for window. But the shadow shows abnormally when:
Move the window a little out of the screen, then resize the window to a larger size, then when I drag back the whole window from outside the screen, I find that system does not draw shadow for those part covered by screen before.
the right part without shadow was covered by screen before
To get full shadow, I must resize the window again to let system redraw the shadow.
So is there a way to avoid this behaviour? Maybe it is more efficient to only the shadow for those parts in screen, but I hope it can redraw automatically when the whole window is in screen.

NSWindow resize indicator not visible

How do I show resize indicators for an NSWindow without Titlebar?
I created a new Xcode project(for Mac app) with storyboard. I just disabled the checkbox Title Bar in Appearance(It hides the Title bar of NSwindow).
The strange thing was, after disabling the TitleBar, NSWindow was not showing resize indicators while mouse was above the window edges. Although if I drag at edges it was resizing.
I guess this is a bug, because if the window can be resized by dragging the mouse over edges, it must show the resize indicators.
As it can be seen in the image, the resize indicators are seen after user drags the window, but many users would think that since there is no resize indicator, the window is not resizable.
I've fixed this issue by subclassing NSWindow and overriding canBecomeKeyWindow to return YES:
#import "MyWindow.h"
#implementation MyWindow
- (BOOL)canBecomeKeyWindow {
return YES;
}
#end
Not updating resize cursors in this case looks like Apple bug. Documentation states "The value of canBecomeKeyWindow property is YES if the window has a title bar or a resize bar, or NO otherwise.", so I expect that canBecomeKeyWindow will return YES for resizable window. But it doesn't.
UPD: Checked on 10.10.5. Hopefully, you will have same behaviour on 10.11.
I have not checked this, but you could set the resize indicators manually. I think I would add four NSTrackingAreas to the windows contentView subclass (one for each side of the window, only few pixels in height/width).
In the mouseEntered() method, create a new NSCursor object for the appropriate mouse position. Remember that the position could change, so use the mouseMoved() method as well.
On mouseExited() reset the cursor.
Again, I have not tried this, but it should work.
PS: Don't forget to file a radar on this ;)

How to set transparency to HUD Window

I am using standard HUD window (Drag and drop from IB Library). But I don't see any control to set the transparency of this HUD window.
I also tried to customize NSPanel to create HUD window . But whatever the alpha value I set. It takes default alpha value. One more problem in this approach is I think I need to draw tittle bar.
Any solution or alternate solution is appreciated.
This page has an example that subclasses NSPanel and draws an HUD Window completely from scratch. The background color/alpha can easily be changed from HUDWindow.m.

Resources