How to make an app without titlebar? - objective-c

I'm quite new to developing on the Mac, I've only done iPhone programming until now. I'm trying to make an app that doesn't have a titlebar. I'd still like to allow the user to move the window around by clicking anywhere within the window and dragging. Is this possible, and if so, how can I get started on something like this? Thanks!

You could make it a borderless window.
[myWindow setStyleMask:NSBorderlessWindowMask];

Related

Add NSWindow in front of fullscreen app

I want to have a window in front of all the others apps.
I want this window appear on keyword shortcut like "Alfred" app.
I try a lot of solution but nothing work for having NSWindow in front of fullscreen app on main or second screen.
I tried the classic :
[self.window setLevel:NSMainMenuWindowLevel + 1];
[self.window setCollectionBehavior:NSWindowCollectionBehaviorStationary|NSWindowCollectionBehaviorCanJoinAllSpaces|NSWindowCollectionBehaviorFullScreenAuxiliary];
[self.window setHidesOnDeactivate:NO];
It's work except with Fullscreen app.
It's work with NSPanel with [self.videoWindow setStyleMask:NSBorderlessWindowMask];
but only on main screen.
Anyone have a solution ? Alfred developper around ?
Alfred is implemented as an Agent. Agents can display Windows on spaces of fullscreen Apps. You should also make your App an Agent.
This can be achieved by adding the Application is Agent flag to the info.plist file of your App and setting the value to YES.
I managed to disdplay auxiliary window on top of full screen app via the following:
self.collectionBehavior = NSWindowCollectionBehaviorMoveToActiveSpace | NSWindowCollectionBehaviorFullScreenAuxiliary;
do not call [NSApp activateblabla];
make application LSUIElement, and do not display the Dock icon via TransformProcessType
However, don't know yet how to display it correctly for app which has the Dock icon. From the other side I do not know which app can do it while having the Dock icon.
It may depend on exactly how the application in question achieves fullscreen, but you likely just need to use a higher window level than NSMainMenuWindowLevel + 1 such as CGShieldingWindowLevel()+1
You can download Quartz Debug from Apples developer downloads (required free developer account)
Quartz Debug can tell you the level of any window and all you need to do is set your window to be higher than the one you are having problems with (assuming the app in question isnt doing something odd to be fullscreen).

NSPanel in "Non-Activating"-Mode does not always show correct cursors

I've created a simple Cocoa-Application in XCode 4.6 with an NSPanel instead of the default NSWindow. When I enable the Non-Activating
option and start the application everything works fine:
The panel is displayed in front of everything else and when
the mouse cursor hovers over the panel's edges it changes from a normal
arrow-cursor to the appropriate resize-cursor, so the user knows that he can resize
the panel.
This works fine as longs as I don't click on any other application
as for example Safari or Finder.
From the moment I once give focus to another application,
I can click on and hover over my panel as much as I want, the
cursor style will not change anymore - it always stays an arrow and it's not possible to return to the normal behavior.
The panel stays selectable and in the front, you still can move and resize it,
but the mouse cursor stays an arrow all the time. You then cannot even change it
manually using something like: [[NSCursor crosshairCursor] set].
So I need to find a way to create a NSPanel that keeps the normal
automatic-change-cursorstyle-when-hovering-over-panel-edges-behaviour
even when you give focus to another application.
I have already tried to use an customized NSPanel-class,
where I have overwritten the canBecomeKeyWindow and
canBecomeMainWindow methods, so that they return YES
but even when I make my Panel KeyWindow and MainWindow...
[myPanel makeKeyAndOrderFront:self];
[myPanel makeMainWindow];
...it doesn't solve the cursor issue.
Would be great if someone could help me here :)
PS.: the Base SDK and the Deployment Target are set to 10.8 in my project
So I found out that the described issue has nothing to to with the panel's window-state. It really doesn't matter if it is set to key or to main, instead the cursor-problem (stays arrow all the time)is related to the application's activation state.
Everything works fine as long as the application that owns the panel is active but if you click on another application my application is deactivated and does not get activated again - even if you click on the panel - because the "non-activating"-option is enabled.
The problem is that i need the "non activating"-option because I am creating a status-bar-screen-capturing app that should be displayed and operate in front of everything else but without deactivating any running application. I could solve the cursor problem by
[NSApp activateIgnoringOtherApps];
but then taking a screenshot of a fullscreen video running in Safari would deactivate Safari and minimize the video, which I don't want.
I don’t think it’s possible through normal APIs to change the cursor when your app isn’t active. I’m pretty sure the window system doesn’t allow it: it’d be a violation of the boundaries between apps—if you try to set a cursor from the background, and the foreground app also tries to set a cursor, who would win?
Of course the system can do it (like when you take a screenshot with ⌘⇧4), because that’s in the window system itself.

XCode - Create an application without a window and paint directly on screen

I'm searching now for a while but can't find an entrance…
The application should behave like a ruler app which is always in front of all apps and does not have a window. I want to draw things directly on the screen.
Would be great if someone could help me out with some keywords to search for or a concrete step into.
Thanks in advance.
Create a borderless transparent NSWindow and draw your content inside it. There are many examples for creating those around.
Use setLevel: to control how the window floats over other windows.

Fake NSWindow with a NSView inside a NSMenuItem

Before I start I should say I know this seems like a long shot, however I figured it was worth a try.
One app I am working on right now is a Mac Statusbar App. It has a NSStatusItem in the menubar and when clicked it will display a custom window with a popover appearance (like on iPad or like Fantastical has on the mac.) Anyway I started testing this by inserting a single nsmenu item in the status items menu. The view has set clear color for the background color on its window. However this still doesn't quite work as you can see in the pic below
There is still a small white thin line above and below the item
The clear area isn't clear, its like it has a blur filter on it
Other than that, it works fantastically great. I just didn't know if anybody else has ever attempted anything like this before and figured out how to overcome these 2 issues which seem to be the only thing preventing this from working.
If there is no way to do this I may have to resort to using a custom view for the NSStatusItem so I can get the coordinates on screen to position my own window below the NSStatusItem.
A fake window seems like a rather weird approach to this. Why not just pop up a regular window? I suggest MAAttachedWindow: http://mattgemmell.com/2007/10/03/maattachedwindow-nswindow-subclass

how to make an NSWindow blocking other Windows?

i'm looking for a way to have a NSWindow, which is able to block other NSWindows, like the menubar does. I mean: It is not possible to drag a Window over the menubar.
Is that kind of behavior realizable for my own NSWindow?
Thanks in advance
Bijan
NSWindow's dragging behavior automatically keeps windows from going under the menu bar — because they aren't supposed to. If you have some special case, you can override the standard dragging behavior. But think carefully before throwing away standard functionality prescribed by the HIG.
Also, it isn't possible to drag a window over the menu bar (rather than under) unless it's also over everything else, because the menu bar is normally above every other window.
I just stumbled on this question. There they say it is possible to move other windows using the Accessibility API or the Quartz Window Services.
Can't I just read out the other window's positions and move them, so that they do not collide with my window? Maybe triggered by a 0.1 sec. timer?