How to pass click on NSView through to app window beneath it? - cocoa

My app has a NSView in a NSWindow which covers the screen and draws a semi-transparent shade on it, above that I've got another NSWindow which contains my app's UI, so the full screen view is designed to fade out background distraction of other windows.
How can I allow mouse clicks on the full screen view to go straight through to the underlying window, which will belong to another app, or even the desktop? Note that I don't want it to keep focus on my app.

Shady by Matt Gemmell does exactly the same, take a look at the source:
http://instinctivecode.com/shady/
It does this by sending the following message to the window:
[window setIgnoresMouseEvents:YES];

Related

How to make window content transparent just like [phw/peek]

I am new to swift and xcode, I want create a macos app just like peek (a screen GIF recorder).
Now I created a window with toolbar follow the tutorials. My question is, how to make the content area of the window be transparent, and ignore mouse event pass to the bottom of the window.
Thank you ^_^ !
This is the screenshot of peek:

NSWindow vs ViewController - OS X - Cocoa

I have been making iOS apps for a while now and I decided that I wanted to start working on making some of them for the Mac too.
The question I have is this: is there any need for an NSWindow, now that developing for the Mac is so similar to iOS??
So I made a simple cocoa application using Xcode and its comes with a storyboard called "Main", just like on iOS.
In that storyboard file, there is a NSWindow which then links to a NSViewController.
Can I get rid of that NSWindow? As I tried setting the NSViewController as the "Initial Controller" and the app still works fine. So whats the point of the NSWindow?
Also, what class links to the NSWindow? I was trying to blur that background of the NSWindow, but I have no way of linking code to the NSWindow.
Sorry for my stupid questions, but I am completely new to development for OS X.
Thanks for your time, Dan.
Those are many questions in one question:
Can I get rid of NSwindow? No, you need a window to show you views.
What is the point of the NSWindow? NSWindow is needed as the window in which the views are displayed and your events are going up the responder chain.
What class is linked to NSWindow? Obviously the NSWindow class, but that is not what you want to know. I think you want to know the delegate that controls NSWindow. This is NSWindowController, although for the MainMenu.xib it is NSAppDelegate.
Hope this gives you the answers you need. An example for working with views in a window is given in this question.
Please, see for further details the windows programming guide, which states:
The NSWindow class defines objects that manage and coordinate the
windows an application displays on the screen. A single NSWindow
object corresponds to at most one onscreen window. The two principal
functions of an NSWindow object are to provide an area in which NSView
objects can be placed and to accept and distribute, to the appropriate
views, events the user instigates through actions with the mouse and
keyboard.
For the question: Can I get rid of NSwindow? I have further comments. In most cases, You need a NSWindow to show view on screen; but in special case you don't, for example, a popup view when you click a NSStatusItem.
So my answer is whenever you need to respond window event such as min/max, you need NSWindow as the view container.

WebView blank after reopening NSWindow

I am using a WebView to display some incoming content to users in a single-window application.
There is a single window controller in the app delegate that I use to send -showWindow: on -applicationDidFinishLaunching: and -applicationShouldHandleReopen:hasVisibleWindows: notifications.
This works well until I close the window and click the dock icon to reopen the window.
At this point the web view is blank and no longer responds to mouse input, such as the scroll wheel. The scroll view still indicates the apparent size of the document.
The window is not released on close, according to IB.
Am I missing something with regards to keeping that content around?
According to the documentation WebView is closed with window. However, we can subclass WebView and override shouldCloseWithWindow and return NO.
- (BOOL)shouldCloseWithWindow

Cocoa Single View question

Is there a way to have a single full-screen picture load when the cocoa app is launched? What I mean by that is a full-screen picture, without the menus and stuff that cocoa automatically attaches to apps.( For example, I want to build an app that when the user clicks it - it brings up a picture of say, a zombie, completely full screen - kind of like the end of that maze game.)
While I'm not aware of any maze games that feature a zombie at the end (though I imagine it would be a great companion to Plants vs. Zombies), you can achieve your goal by using NSView's built-in full-screen method -enterFullScreenMode:withOptions: and exit with -exitFullScreenModeWithOptions:.
To enter full screen at launch, just use the NSApplicationDelegate method -applicationDidFinishLaunching:.
As for UI arrangement, I'd just open MainMenu.xib in Interface Builder and delete the window, then drag an NSView ("Custom View") or just a NSImageView into the IB document and open it up. Create an outlet to the view in your app delegate / app controller and connect it to the view.

Using Webkit to create Skinable custom windows on OSX

There are tutorials for using a webkit view inside a cocoa application to achieve skinnable contents, but what would I do if I wanted to use webkit to create custom, skinnable windows?
Examples would be dashboard widgets, or
BowTie
Beware, I'm a noob.
I've never tried it, but I think you'd just set a WebView as the content view of a transparent borderless window, and tell the WebView not to draw a background. That way, the content of the WebView would define the window boundary.
You create a borderless window by passing NSBorderlessWindowMask to the -initWithContentRect:styleMask:backing:defer: method of NSWindow, and you can set its background to transparent by calling [window setBackgroundColor:[NSColor clearColor]].
You'd have to handle dragging of the window etc yourself. It will probably get a bit messy.
To be honest, it's not something I'd attempt as a first Cocoa project.

Resources